app/testpmd: fix typo in setting Tx offload command
[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_PMD_SOFTNIC
73 #include <rte_eth_softnic.h>
74 #endif
75 #ifdef RTE_LIBRTE_BNXT_PMD
76 #include <rte_pmd_bnxt.h>
77 #endif
78 #include "testpmd.h"
79 #include "cmdline_mtr.h"
80 #include "cmdline_tm.h"
81 #include "bpf_cmd.h"
82
83 static struct cmdline *testpmd_cl;
84
85 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
86
87 /* *** Help command with introduction. *** */
88 struct cmd_help_brief_result {
89         cmdline_fixed_string_t help;
90 };
91
92 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
93                                   struct cmdline *cl,
94                                   __attribute__((unused)) void *data)
95 {
96         cmdline_printf(
97                 cl,
98                 "\n"
99                 "Help is available for the following sections:\n\n"
100                 "    help control    : Start and stop forwarding.\n"
101                 "    help display    : Displaying port, stats and config "
102                 "information.\n"
103                 "    help config     : Configuration information.\n"
104                 "    help ports      : Configuring ports.\n"
105                 "    help registers  : Reading and setting port registers.\n"
106                 "    help filters    : Filters configuration help.\n"
107                 "    help all        : All of the above sections.\n\n"
108         );
109
110 }
111
112 cmdline_parse_token_string_t cmd_help_brief_help =
113         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
114
115 cmdline_parse_inst_t cmd_help_brief = {
116         .f = cmd_help_brief_parsed,
117         .data = NULL,
118         .help_str = "help: Show help",
119         .tokens = {
120                 (void *)&cmd_help_brief_help,
121                 NULL,
122         },
123 };
124
125 /* *** Help command with help sections. *** */
126 struct cmd_help_long_result {
127         cmdline_fixed_string_t help;
128         cmdline_fixed_string_t section;
129 };
130
131 static void cmd_help_long_parsed(void *parsed_result,
132                                  struct cmdline *cl,
133                                  __attribute__((unused)) void *data)
134 {
135         int show_all = 0;
136         struct cmd_help_long_result *res = parsed_result;
137
138         if (!strcmp(res->section, "all"))
139                 show_all = 1;
140
141         if (show_all || !strcmp(res->section, "control")) {
142
143                 cmdline_printf(
144                         cl,
145                         "\n"
146                         "Control forwarding:\n"
147                         "-------------------\n\n"
148
149                         "start\n"
150                         "    Start packet forwarding with current configuration.\n\n"
151
152                         "start tx_first\n"
153                         "    Start packet forwarding with current config"
154                         " after sending one burst of packets.\n\n"
155
156                         "stop\n"
157                         "    Stop packet forwarding, and display accumulated"
158                         " statistics.\n\n"
159
160                         "quit\n"
161                         "    Quit to prompt.\n\n"
162                 );
163         }
164
165         if (show_all || !strcmp(res->section, "display")) {
166
167                 cmdline_printf(
168                         cl,
169                         "\n"
170                         "Display:\n"
171                         "--------\n\n"
172
173                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
174                         "    Display information for port_id, or all.\n\n"
175
176                         "show port X rss reta (size) (mask0,mask1,...)\n"
177                         "    Display the rss redirection table entry indicated"
178                         " by masks on port X. size is used to indicate the"
179                         " hardware supported reta size\n\n"
180
181                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
182                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
183                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
184                         "    Display the RSS hash functions and RSS hash key"
185                         " of port X\n\n"
186
187                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
188                         "    Clear information for port_id, or all.\n\n"
189
190                         "show (rxq|txq) info (port_id) (queue_id)\n"
191                         "    Display information for configured RX/TX queue.\n\n"
192
193                         "show config (rxtx|cores|fwd|txpkts)\n"
194                         "    Display the given configuration.\n\n"
195
196                         "read rxd (port_id) (queue_id) (rxd_id)\n"
197                         "    Display an RX descriptor of a port RX queue.\n\n"
198
199                         "read txd (port_id) (queue_id) (txd_id)\n"
200                         "    Display a TX descriptor of a port TX queue.\n\n"
201
202                         "ddp get list (port_id)\n"
203                         "    Get ddp profile info list\n\n"
204
205                         "ddp get info (profile_path)\n"
206                         "    Get ddp profile information.\n\n"
207
208                         "show vf stats (port_id) (vf_id)\n"
209                         "    Display a VF's statistics.\n\n"
210
211                         "clear vf stats (port_id) (vf_id)\n"
212                         "    Reset a VF's statistics.\n\n"
213
214                         "show port (port_id) pctype mapping\n"
215                         "    Get flow ptype to pctype mapping on a port\n\n"
216
217                         "show port meter stats (port_id) (meter_id) (clear)\n"
218                         "    Get meter stats on a port\n\n"
219                         "show port tm cap (port_id)\n"
220                         "       Display the port TM capability.\n\n"
221
222                         "show port tm level cap (port_id) (level_id)\n"
223                         "       Display the port TM hierarchical level capability.\n\n"
224
225                         "show port tm node cap (port_id) (node_id)\n"
226                         "       Display the port TM node capability.\n\n"
227
228                         "show port tm node type (port_id) (node_id)\n"
229                         "       Display the port TM node type.\n\n"
230
231                         "show port tm node stats (port_id) (node_id) (clear)\n"
232                         "       Display the port TM node stats.\n\n"
233
234                 );
235         }
236
237         if (show_all || !strcmp(res->section, "config")) {
238                 cmdline_printf(
239                         cl,
240                         "\n"
241                         "Configuration:\n"
242                         "--------------\n"
243                         "Configuration changes only become active when"
244                         " forwarding is started/restarted.\n\n"
245
246                         "set default\n"
247                         "    Reset forwarding to the default configuration.\n\n"
248
249                         "set verbose (level)\n"
250                         "    Set the debug verbosity level X.\n\n"
251
252                         "set log global|(type) (level)\n"
253                         "    Set the log level.\n\n"
254
255                         "set nbport (num)\n"
256                         "    Set number of ports.\n\n"
257
258                         "set nbcore (num)\n"
259                         "    Set number of cores.\n\n"
260
261                         "set coremask (mask)\n"
262                         "    Set the forwarding cores hexadecimal mask.\n\n"
263
264                         "set portmask (mask)\n"
265                         "    Set the forwarding ports hexadecimal mask.\n\n"
266
267                         "set burst (num)\n"
268                         "    Set number of packets per burst.\n\n"
269
270                         "set burst tx delay (microseconds) retry (num)\n"
271                         "    Set the transmit delay time and number of retries,"
272                         " effective when retry is enabled.\n\n"
273
274                         "set txpkts (x[,y]*)\n"
275                         "    Set the length of each segment of TXONLY"
276                         " and optionally CSUM packets.\n\n"
277
278                         "set txsplit (off|on|rand)\n"
279                         "    Set the split policy for the TX packets."
280                         " Right now only applicable for CSUM and TXONLY"
281                         " modes\n\n"
282
283                         "set corelist (x[,y]*)\n"
284                         "    Set the list of forwarding cores.\n\n"
285
286                         "set portlist (x[,y]*)\n"
287                         "    Set the list of forwarding ports.\n\n"
288
289                         "set tx loopback (port_id) (on|off)\n"
290                         "    Enable or disable tx loopback.\n\n"
291
292                         "set all queues drop (port_id) (on|off)\n"
293                         "    Set drop enable bit for all queues.\n\n"
294
295                         "set vf split drop (port_id) (vf_id) (on|off)\n"
296                         "    Set split drop enable bit for a VF from the PF.\n\n"
297
298                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
299                         "    Set MAC antispoof for a VF from the PF.\n\n"
300
301                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
302                         "    Enable MACsec offload.\n\n"
303
304                         "set macsec offload (port_id) off\n"
305                         "    Disable MACsec offload.\n\n"
306
307                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
308                         "    Configure MACsec secure connection (SC).\n\n"
309
310                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
311                         "    Configure MACsec secure association (SA).\n\n"
312
313                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
314                         "    Set VF broadcast for a VF from the PF.\n\n"
315
316                         "vlan set strip (on|off) (port_id)\n"
317                         "    Set the VLAN strip on a port.\n\n"
318
319                         "vlan set stripq (on|off) (port_id,queue_id)\n"
320                         "    Set the VLAN strip for a queue on a port.\n\n"
321
322                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
323                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
324
325                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
326                         "    Set VLAN insert for a VF from the PF.\n\n"
327
328                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN antispoof for a VF from the PF.\n\n"
330
331                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
332                         "    Set VLAN tag for a VF from the PF.\n\n"
333
334                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
335                         "    Set a VF's max bandwidth(Mbps).\n\n"
336
337                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
338                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
339
340                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
341                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
342
343                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
344                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
345
346                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
347                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
348
349                         "vlan set filter (on|off) (port_id)\n"
350                         "    Set the VLAN filter on a port.\n\n"
351
352                         "vlan set qinq (on|off) (port_id)\n"
353                         "    Set the VLAN QinQ (extended queue in queue)"
354                         " on a port.\n\n"
355
356                         "vlan set (inner|outer) tpid (value) (port_id)\n"
357                         "    Set the VLAN TPID for Packet Filtering on"
358                         " a port\n\n"
359
360                         "rx_vlan add (vlan_id|all) (port_id)\n"
361                         "    Add a vlan_id, or all identifiers, to the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan rm (vlan_id|all) (port_id)\n"
365                         "    Remove a vlan_id, or all identifiers, from the set"
366                         " of VLAN identifiers filtered by port_id.\n\n"
367
368                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Add a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
373                         "    Remove a vlan_id, to the set of VLAN identifiers"
374                         "filtered for VF(s) from port_id.\n\n"
375
376                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
377                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
378                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
379                         "   add a tunnel filter of a port.\n\n"
380
381                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
382                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
383                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
384                         "   remove a tunnel filter of a port.\n\n"
385
386                         "rx_vxlan_port add (udp_port) (port_id)\n"
387                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "rx_vxlan_port rm (udp_port) (port_id)\n"
390                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
391
392                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
393                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
394                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
395
396                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
397                         "    Set port based TX VLAN insertion.\n\n"
398
399                         "tx_vlan reset (port_id)\n"
400                         "    Disable hardware insertion of a VLAN header in"
401                         " packets sent on a port.\n\n"
402
403                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
404                         "    Select hardware or software calculation of the"
405                         " checksum when transmitting a packet using the"
406                         " csum forward engine.\n"
407                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
408                         "    outer-ip concerns the outer IP layer in"
409                         " case the packet is recognized as a tunnel packet by"
410                         " the forward engine (vxlan, gre and ipip are supported)\n"
411                         "    Please check the NIC datasheet for HW limits.\n\n"
412
413                         "csum parse-tunnel (on|off) (tx_port_id)\n"
414                         "    If disabled, treat tunnel packets as non-tunneled"
415                         " packets (treat inner headers as payload). The port\n"
416                         "    argument is the port used for TX in csum forward"
417                         " engine.\n\n"
418
419                         "csum show (port_id)\n"
420                         "    Display tx checksum offload configuration\n\n"
421
422                         "tso set (segsize) (portid)\n"
423                         "    Enable TCP Segmentation Offload in csum forward"
424                         " engine.\n"
425                         "    Please check the NIC datasheet for HW limits.\n\n"
426
427                         "tso show (portid)"
428                         "    Display the status of TCP Segmentation Offload.\n\n"
429
430                         "set port (port_id) gro on|off\n"
431                         "    Enable or disable Generic Receive Offload in"
432                         " csum forwarding engine.\n\n"
433
434                         "show port (port_id) gro\n"
435                         "    Display GRO configuration.\n\n"
436
437                         "set gro flush (cycles)\n"
438                         "    Set the cycle to flush GROed packets from"
439                         " reassembly tables.\n\n"
440
441                         "set port (port_id) gso (on|off)"
442                         "    Enable or disable Generic Segmentation Offload in"
443                         " csum forwarding engine.\n\n"
444
445                         "set gso segsz (length)\n"
446                         "    Set max packet length for output GSO segments,"
447                         " including packet header and payload.\n\n"
448
449                         "show port (port_id) gso\n"
450                         "    Show GSO configuration.\n\n"
451
452                         "set fwd (%s)\n"
453                         "    Set packet forwarding mode.\n\n"
454
455                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
456                         "    Add a MAC address on port_id.\n\n"
457
458                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
459                         "    Remove a MAC address from port_id.\n\n"
460
461                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
462                         "    Set the default MAC address for port_id.\n\n"
463
464                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
465                         "    Add a MAC address for a VF on the port.\n\n"
466
467                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Set the MAC address for a VF from the PF.\n\n"
469
470                         "set eth-peer (port_id) (peer_addr)\n"
471                         "    set the peer address for certain port.\n\n"
472
473                         "set port (port_id) uta (mac_address|all) (on|off)\n"
474                         "    Add/Remove a or all unicast hash filter(s)"
475                         "from port X.\n\n"
476
477                         "set promisc (port_id|all) (on|off)\n"
478                         "    Set the promiscuous mode on port_id, or all.\n\n"
479
480                         "set allmulti (port_id|all) (on|off)\n"
481                         "    Set the allmulti mode on port_id, or all.\n\n"
482
483                         "set vf promisc (port_id) (vf_id) (on|off)\n"
484                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
485
486                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
487                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
488
489                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
490                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
491                         " (on|off) autoneg (on|off) (port_id)\n"
492                         "set flow_ctrl rx (on|off) (portid)\n"
493                         "set flow_ctrl tx (on|off) (portid)\n"
494                         "set flow_ctrl high_water (high_water) (portid)\n"
495                         "set flow_ctrl low_water (low_water) (portid)\n"
496                         "set flow_ctrl pause_time (pause_time) (portid)\n"
497                         "set flow_ctrl send_xon (send_xon) (portid)\n"
498                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
499                         "set flow_ctrl autoneg (on|off) (port_id)\n"
500                         "    Set the link flow control parameter on a port.\n\n"
501
502                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
503                         " (low_water) (pause_time) (priority) (port_id)\n"
504                         "    Set the priority flow control parameter on a"
505                         " port.\n\n"
506
507                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
508                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
509                         " queue on port.\n"
510                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
511                         " on port 0 to mapping 5.\n\n"
512
513                         "set xstats-hide-zero on|off\n"
514                         "    Set the option to hide the zero values"
515                         " for xstats display.\n"
516
517                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
518                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
519
520                         "set port (port_id) vf (vf_id) (mac_addr)"
521                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
522                         "   Add/Remove unicast or multicast MAC addr filter"
523                         " for a VF.\n\n"
524
525                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
526                         "|MPE) (on|off)\n"
527                         "    AUPE:accepts untagged VLAN;"
528                         "ROPE:accept unicast hash\n\n"
529                         "    BAM:accepts broadcast packets;"
530                         "MPE:accepts all multicast packets\n\n"
531                         "    Enable/Disable a VF receive mode of a port\n\n"
532
533                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
534                         "    Set rate limit for a queue of a port\n\n"
535
536                         "set port (port_id) vf (vf_id) rate (rate_num) "
537                         "queue_mask (queue_mask_value)\n"
538                         "    Set rate limit for queues in VF of a port\n\n"
539
540                         "set port (port_id) mirror-rule (rule_id)"
541                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
542                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
543                         "   Set pool or vlan type mirror rule on a port.\n"
544                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
545                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
546                         " to pool 0.\n\n"
547
548                         "set port (port_id) mirror-rule (rule_id)"
549                         " (uplink-mirror|downlink-mirror) dst-pool"
550                         " (pool_id) (on|off)\n"
551                         "   Set uplink or downlink type mirror rule on a port.\n"
552                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
553                         " 0 on' enable mirror income traffic to pool 0.\n\n"
554
555                         "reset port (port_id) mirror-rule (rule_id)\n"
556                         "   Reset a mirror rule.\n\n"
557
558                         "set flush_rx (on|off)\n"
559                         "   Flush (default) or don't flush RX streams before"
560                         " forwarding. Mainly used with PCAP drivers.\n\n"
561
562                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
563                         "   Set the bypass mode for the lowest port on bypass enabled"
564                         " NIC.\n\n"
565
566                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
567                         "mode (normal|bypass|isolate) (port_id)\n"
568                         "   Set the event required to initiate specified bypass mode for"
569                         " the lowest port on a bypass enabled NIC where:\n"
570                         "       timeout   = enable bypass after watchdog timeout.\n"
571                         "       os_on     = enable bypass when OS/board is powered on.\n"
572                         "       os_off    = enable bypass when OS/board is powered off.\n"
573                         "       power_on  = enable bypass when power supply is turned on.\n"
574                         "       power_off = enable bypass when power supply is turned off."
575                         "\n\n"
576
577                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
578                         "   Set the bypass watchdog timeout to 'n' seconds"
579                         " where 0 = instant.\n\n"
580
581                         "show bypass config (port_id)\n"
582                         "   Show the bypass configuration for a bypass enabled NIC"
583                         " using the lowest port on the NIC.\n\n"
584
585 #ifdef RTE_LIBRTE_PMD_BOND
586                         "create bonded device (mode) (socket)\n"
587                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
588
589                         "add bonding slave (slave_id) (port_id)\n"
590                         "       Add a slave device to a bonded device.\n\n"
591
592                         "remove bonding slave (slave_id) (port_id)\n"
593                         "       Remove a slave device from a bonded device.\n\n"
594
595                         "set bonding mode (value) (port_id)\n"
596                         "       Set the bonding mode on a bonded device.\n\n"
597
598                         "set bonding primary (slave_id) (port_id)\n"
599                         "       Set the primary slave for a bonded device.\n\n"
600
601                         "show bonding config (port_id)\n"
602                         "       Show the bonding config for port_id.\n\n"
603
604                         "set bonding mac_addr (port_id) (address)\n"
605                         "       Set the MAC address of a bonded device.\n\n"
606
607                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
608                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
609
610                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
611                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
612
613                         "set bonding mon_period (port_id) (value)\n"
614                         "       Set the bonding link status monitoring polling period in ms.\n\n"
615
616                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
617                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
618
619 #endif
620                         "set link-up port (port_id)\n"
621                         "       Set link up for a port.\n\n"
622
623                         "set link-down port (port_id)\n"
624                         "       Set link down for a port.\n\n"
625
626                         "E-tag set insertion on port-tag-id (value)"
627                         " port (port_id) vf (vf_id)\n"
628                         "    Enable E-tag insertion for a VF on a port\n\n"
629
630                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
631                         "    Disable E-tag insertion for a VF on a port\n\n"
632
633                         "E-tag set stripping (on|off) port (port_id)\n"
634                         "    Enable/disable E-tag stripping on a port\n\n"
635
636                         "E-tag set forwarding (on|off) port (port_id)\n"
637                         "    Enable/disable E-tag based forwarding"
638                         " on a port\n\n"
639
640                         "E-tag set filter add e-tag-id (value) dst-pool"
641                         " (pool_id) port (port_id)\n"
642                         "    Add an E-tag forwarding filter on a port\n\n"
643
644                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
645                         "    Delete an E-tag forwarding filter on a port\n\n"
646
647 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
648                         "set port tm hierarchy default (port_id)\n"
649                         "       Set default traffic Management hierarchy on a port\n\n"
650
651 #endif
652                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
653                         "    Load a profile package on a port\n\n"
654
655                         "ddp del (port_id) (backup_profile_path)\n"
656                         "    Delete a profile package from a port\n\n"
657
658                         "ptype mapping get (port_id) (valid_only)\n"
659                         "    Get ptype mapping on a port\n\n"
660
661                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
662                         "    Replace target with the pkt_type in ptype mapping\n\n"
663
664                         "ptype mapping reset (port_id)\n"
665                         "    Reset ptype mapping on a port\n\n"
666
667                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
668                         "    Update a ptype mapping item on a port\n\n"
669
670                         "set port (port_id) queue-region region_id (value) "
671                         "queue_start_index (value) queue_num (value)\n"
672                         "    Set a queue region on a port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "flowtype (value)\n"
676                         "    Set a flowtype region index on a port\n\n"
677
678                         "set port (port_id) queue-region UP (value) region_id (value)\n"
679                         "    Set the mapping of User Priority to "
680                         "queue region on a port\n\n"
681
682                         "set port (port_id) queue-region flush (on|off)\n"
683                         "    flush all queue region related configuration\n\n"
684
685                         "show port meter cap (port_id)\n"
686                         "    Show port meter capability information\n\n"
687
688                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
689                         "    meter profile add - srtcm rfc 2697\n\n"
690
691                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
692                         "    meter profile add - trtcm rfc 2698\n\n"
693
694                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
695                         "    meter profile add - trtcm rfc 4115\n\n"
696
697                         "del port meter profile (port_id) (profile_id)\n"
698                         "    meter profile delete\n\n"
699
700                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
701                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
702                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
703                         "(dscp_tbl_entry63)]\n"
704                         "    meter create\n\n"
705
706                         "enable port meter (port_id) (mtr_id)\n"
707                         "    meter enable\n\n"
708
709                         "disable port meter (port_id) (mtr_id)\n"
710                         "    meter disable\n\n"
711
712                         "del port meter (port_id) (mtr_id)\n"
713                         "    meter delete\n\n"
714
715                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
716                         "    meter update meter profile\n\n"
717
718                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
719                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
720                         "    update meter dscp table entries\n\n"
721
722                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
723                         "(action0) [(action1) (action2)]\n"
724                         "    meter update policer action\n\n"
725
726                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
727                         "    meter update stats\n\n"
728
729                         "show port (port_id) queue-region\n"
730                         "    show all queue region related configuration info\n\n"
731
732                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
733                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
734                         "       Add port tm node private shaper profile.\n\n"
735
736                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
737                         "       Delete port tm node private shaper profile.\n\n"
738
739                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
740                         " (shaper_profile_id)\n"
741                         "       Add/update port tm node shared shaper.\n\n"
742
743                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
744                         "       Delete port tm node shared shaper.\n\n"
745
746                         "set port tm node shaper profile (port_id) (node_id)"
747                         " (shaper_profile_id)\n"
748                         "       Set port tm node shaper profile.\n\n"
749
750                         "add port tm node wred profile (port_id) (wred_profile_id)"
751                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
752                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
753                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
754                         "       Add port tm node wred profile.\n\n"
755
756                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
757                         "       Delete port tm node wred profile.\n\n"
758
759                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
760                         " (priority) (weight) (level_id) (shaper_profile_id)"
761                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
762                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
763                         "       Add port tm nonleaf node.\n\n"
764
765                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
766                         " (priority) (weight) (level_id) (shaper_profile_id)"
767                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
768                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
769                         "       Add port tm leaf node.\n\n"
770
771                         "del port tm node (port_id) (node_id)\n"
772                         "       Delete port tm node.\n\n"
773
774                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
775                         " (priority) (weight)\n"
776                         "       Set port tm node parent.\n\n"
777
778                         "suspend port tm node (port_id) (node_id)"
779                         "       Suspend tm node.\n\n"
780
781                         "resume port tm node (port_id) (node_id)"
782                         "       Resume tm node.\n\n"
783
784                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
785                         "       Commit tm hierarchy.\n\n"
786
787                         , list_pkt_forwarding_modes()
788                 );
789         }
790
791         if (show_all || !strcmp(res->section, "ports")) {
792
793                 cmdline_printf(
794                         cl,
795                         "\n"
796                         "Port Operations:\n"
797                         "----------------\n\n"
798
799                         "port start (port_id|all)\n"
800                         "    Start all ports or port_id.\n\n"
801
802                         "port stop (port_id|all)\n"
803                         "    Stop all ports or port_id.\n\n"
804
805                         "port close (port_id|all)\n"
806                         "    Close all ports or port_id.\n\n"
807
808                         "port attach (ident)\n"
809                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
810
811                         "port detach (port_id)\n"
812                         "    Detach physical or virtual dev by port_id\n\n"
813
814                         "port config (port_id|all)"
815                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
816                         " duplex (half|full|auto)\n"
817                         "    Set speed and duplex for all ports or port_id\n\n"
818
819                         "port config (port_id|all) loopback (mode)\n"
820                         "    Set loopback mode for all ports or port_id\n\n"
821
822                         "port config all (rxq|txq|rxd|txd) (value)\n"
823                         "    Set number for rxq/txq/rxd/txd.\n\n"
824
825                         "port config all max-pkt-len (value)\n"
826                         "    Set the max packet length.\n\n"
827
828                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
829                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
830                         " (on|off)\n"
831                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
832                         " for ports.\n\n"
833
834                         "port config all rss (all|default|ip|tcp|udp|sctp|"
835                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
836                         "    Set the RSS mode.\n\n"
837
838                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
839                         "    Set the RSS redirection table.\n\n"
840
841                         "port config (port_id) dcb vt (on|off) (traffic_class)"
842                         " pfc (on|off)\n"
843                         "    Set the DCB mode.\n\n"
844
845                         "port config all burst (value)\n"
846                         "    Set the number of packets per burst.\n\n"
847
848                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
849                         " (value)\n"
850                         "    Set the ring prefetch/host/writeback threshold"
851                         " for tx/rx queue.\n\n"
852
853                         "port config all (txfreet|txrst|rxfreet) (value)\n"
854                         "    Set free threshold for rx/tx, or set"
855                         " tx rs bit threshold.\n\n"
856                         "port config mtu X value\n"
857                         "    Set the MTU of port X to a given value\n\n"
858
859                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
860                         "    Set a rx/tx queue's ring size configuration, the new"
861                         " value will take effect after command that (re-)start the port"
862                         " or command that setup the specific queue\n\n"
863
864                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
865                         "    Start/stop a rx/tx queue of port X. Only take effect"
866                         " when port X is started\n\n"
867
868                         "port (port_id) (rxq|txq) (queue_id) setup\n"
869                         "    Setup a rx/tx queue of port X.\n\n"
870
871                         "port config (port_id|all) l2-tunnel E-tag ether-type"
872                         " (value)\n"
873                         "    Set the value of E-tag ether-type.\n\n"
874
875                         "port config (port_id|all) l2-tunnel E-tag"
876                         " (enable|disable)\n"
877                         "    Enable/disable the E-tag support.\n\n"
878
879                         "port config (port_id) pctype mapping reset\n"
880                         "    Reset flow type to pctype mapping on a port\n\n"
881
882                         "port config (port_id) pctype mapping update"
883                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
884                         "    Update a flow type to pctype mapping item on a port\n\n"
885
886                         "port config (port_id) pctype (pctype_id) hash_inset|"
887                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
888                         " (field_idx)\n"
889                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
890
891                         "port config (port_id) pctype (pctype_id) hash_inset|"
892                         "fdir_inset|fdir_flx_inset clear all"
893                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
894
895                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
896                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
897                 );
898         }
899
900         if (show_all || !strcmp(res->section, "registers")) {
901
902                 cmdline_printf(
903                         cl,
904                         "\n"
905                         "Registers:\n"
906                         "----------\n\n"
907
908                         "read reg (port_id) (address)\n"
909                         "    Display value of a port register.\n\n"
910
911                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
912                         "    Display a port register bit field.\n\n"
913
914                         "read regbit (port_id) (address) (bit_x)\n"
915                         "    Display a single port register bit.\n\n"
916
917                         "write reg (port_id) (address) (value)\n"
918                         "    Set value of a port register.\n\n"
919
920                         "write regfield (port_id) (address) (bit_x) (bit_y)"
921                         " (value)\n"
922                         "    Set bit field of a port register.\n\n"
923
924                         "write regbit (port_id) (address) (bit_x) (value)\n"
925                         "    Set single bit value of a port register.\n\n"
926                 );
927         }
928         if (show_all || !strcmp(res->section, "filters")) {
929
930                 cmdline_printf(
931                         cl,
932                         "\n"
933                         "filters:\n"
934                         "--------\n\n"
935
936                         "ethertype_filter (port_id) (add|del)"
937                         " (mac_addr|mac_ignr) (mac_address) ethertype"
938                         " (ether_type) (drop|fwd) queue (queue_id)\n"
939                         "    Add/Del an ethertype filter.\n\n"
940
941                         "2tuple_filter (port_id) (add|del)"
942                         " dst_port (dst_port_value) protocol (protocol_value)"
943                         " mask (mask_value) tcp_flags (tcp_flags_value)"
944                         " priority (prio_value) queue (queue_id)\n"
945                         "    Add/Del a 2tuple filter.\n\n"
946
947                         "5tuple_filter (port_id) (add|del)"
948                         " dst_ip (dst_address) src_ip (src_address)"
949                         " dst_port (dst_port_value) src_port (src_port_value)"
950                         " protocol (protocol_value)"
951                         " mask (mask_value) tcp_flags (tcp_flags_value)"
952                         " priority (prio_value) queue (queue_id)\n"
953                         "    Add/Del a 5tuple filter.\n\n"
954
955                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
956                         "    Add/Del syn filter.\n\n"
957
958                         "flex_filter (port_id) (add|del) len (len_value)"
959                         " bytes (bytes_value) mask (mask_value)"
960                         " priority (prio_value) queue (queue_id)\n"
961                         "    Add/Del a flex filter.\n\n"
962
963                         "flow_director_filter (port_id) mode IP (add|del|update)"
964                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
965                         " src (src_ip_address) dst (dst_ip_address)"
966                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
967                         " vlan (vlan_value) flexbytes (flexbytes_value)"
968                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
969                         " fd_id (fd_id_value)\n"
970                         "    Add/Del an IP type flow director filter.\n\n"
971
972                         "flow_director_filter (port_id) mode IP (add|del|update)"
973                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
974                         " src (src_ip_address) (src_port)"
975                         " dst (dst_ip_address) (dst_port)"
976                         " tos (tos_value) ttl (ttl_value)"
977                         " vlan (vlan_value) flexbytes (flexbytes_value)"
978                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
979                         " fd_id (fd_id_value)\n"
980                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
981
982                         "flow_director_filter (port_id) mode IP (add|del|update)"
983                         " flow (ipv4-sctp|ipv6-sctp)"
984                         " src (src_ip_address) (src_port)"
985                         " dst (dst_ip_address) (dst_port)"
986                         " tag (verification_tag) "
987                         " tos (tos_value) ttl (ttl_value)"
988                         " vlan (vlan_value)"
989                         " flexbytes (flexbytes_value) (drop|fwd)"
990                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
991                         "    Add/Del a SCTP type flow director filter.\n\n"
992
993                         "flow_director_filter (port_id) mode IP (add|del|update)"
994                         " flow l2_payload ether (ethertype)"
995                         " flexbytes (flexbytes_value) (drop|fwd)"
996                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
997                         "    Add/Del a l2 payload type flow director filter.\n\n"
998
999                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1000                         " mac (mac_address) vlan (vlan_value)"
1001                         " flexbytes (flexbytes_value) (drop|fwd)"
1002                         " queue (queue_id) fd_id (fd_id_value)\n"
1003                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1004
1005                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1006                         " mac (mac_address) vlan (vlan_value)"
1007                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1008                         " flexbytes (flexbytes_value) (drop|fwd)"
1009                         " queue (queue_id) fd_id (fd_id_value)\n"
1010                         "    Add/Del a Tunnel flow director filter.\n\n"
1011
1012                         "flow_director_filter (port_id) mode raw (add|del|update)"
1013                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1014                         " fd_id (fd_id_value) packet (packet file name)\n"
1015                         "    Add/Del a raw type flow director filter.\n\n"
1016
1017                         "flush_flow_director (port_id)\n"
1018                         "    Flush all flow director entries of a device.\n\n"
1019
1020                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1021                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1022                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1023                         "    Set flow director IP mask.\n\n"
1024
1025                         "flow_director_mask (port_id) mode MAC-VLAN"
1026                         " vlan (vlan_value)\n"
1027                         "    Set flow director MAC-VLAN mask.\n\n"
1028
1029                         "flow_director_mask (port_id) mode Tunnel"
1030                         " vlan (vlan_value) mac (mac_value)"
1031                         " tunnel-type (tunnel_type_value)"
1032                         " tunnel-id (tunnel_id_value)\n"
1033                         "    Set flow director Tunnel mask.\n\n"
1034
1035                         "flow_director_flex_mask (port_id)"
1036                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1037                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1038                         " (mask)\n"
1039                         "    Configure mask of flex payload.\n\n"
1040
1041                         "flow_director_flex_payload (port_id)"
1042                         " (raw|l2|l3|l4) (config)\n"
1043                         "    Configure flex payload selection.\n\n"
1044
1045                         "get_sym_hash_ena_per_port (port_id)\n"
1046                         "    get symmetric hash enable configuration per port.\n\n"
1047
1048                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1049                         "    set symmetric hash enable configuration per port"
1050                         " to enable or disable.\n\n"
1051
1052                         "get_hash_global_config (port_id)\n"
1053                         "    Get the global configurations of hash filters.\n\n"
1054
1055                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1056                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1057                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1058                         " (enable|disable)\n"
1059                         "    Set the global configurations of hash filters.\n\n"
1060
1061                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1062                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1063                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1064                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1065                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1066                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1067                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1068                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1069                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1070                         "fld-8th|none) (select|add)\n"
1071                         "    Set the input set for hash.\n\n"
1072
1073                         "set_fdir_input_set (port_id) "
1074                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1075                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1076                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1077                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1078                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1079                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1080                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1081                         " (select|add)\n"
1082                         "    Set the input set for FDir.\n\n"
1083
1084                         "flow validate {port_id}"
1085                         " [group {group_id}] [priority {level}]"
1086                         " [ingress] [egress]"
1087                         " pattern {item} [/ {item} [...]] / end"
1088                         " actions {action} [/ {action} [...]] / end\n"
1089                         "    Check whether a flow rule can be created.\n\n"
1090
1091                         "flow create {port_id}"
1092                         " [group {group_id}] [priority {level}]"
1093                         " [ingress] [egress]"
1094                         " pattern {item} [/ {item} [...]] / end"
1095                         " actions {action} [/ {action} [...]] / end\n"
1096                         "    Create a flow rule.\n\n"
1097
1098                         "flow destroy {port_id} rule {rule_id} [...]\n"
1099                         "    Destroy specific flow rules.\n\n"
1100
1101                         "flow flush {port_id}\n"
1102                         "    Destroy all flow rules.\n\n"
1103
1104                         "flow query {port_id} {rule_id} {action}\n"
1105                         "    Query an existing flow rule.\n\n"
1106
1107                         "flow list {port_id} [group {group_id}] [...]\n"
1108                         "    List existing flow rules sorted by priority,"
1109                         " filtered by group identifiers.\n\n"
1110
1111                         "flow isolate {port_id} {boolean}\n"
1112                         "    Restrict ingress traffic to the defined"
1113                         " flow rules\n\n"
1114                 );
1115         }
1116 }
1117
1118 cmdline_parse_token_string_t cmd_help_long_help =
1119         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1120
1121 cmdline_parse_token_string_t cmd_help_long_section =
1122         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1123                         "all#control#display#config#"
1124                         "ports#registers#filters");
1125
1126 cmdline_parse_inst_t cmd_help_long = {
1127         .f = cmd_help_long_parsed,
1128         .data = NULL,
1129         .help_str = "help all|control|display|config|ports|register|filters: "
1130                 "Show help",
1131         .tokens = {
1132                 (void *)&cmd_help_long_help,
1133                 (void *)&cmd_help_long_section,
1134                 NULL,
1135         },
1136 };
1137
1138
1139 /* *** start/stop/close all ports *** */
1140 struct cmd_operate_port_result {
1141         cmdline_fixed_string_t keyword;
1142         cmdline_fixed_string_t name;
1143         cmdline_fixed_string_t value;
1144 };
1145
1146 static void cmd_operate_port_parsed(void *parsed_result,
1147                                 __attribute__((unused)) struct cmdline *cl,
1148                                 __attribute__((unused)) void *data)
1149 {
1150         struct cmd_operate_port_result *res = parsed_result;
1151
1152         if (!strcmp(res->name, "start"))
1153                 start_port(RTE_PORT_ALL);
1154         else if (!strcmp(res->name, "stop"))
1155                 stop_port(RTE_PORT_ALL);
1156         else if (!strcmp(res->name, "close"))
1157                 close_port(RTE_PORT_ALL);
1158         else if (!strcmp(res->name, "reset"))
1159                 reset_port(RTE_PORT_ALL);
1160         else
1161                 printf("Unknown parameter\n");
1162 }
1163
1164 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1165         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1166                                                                 "port");
1167 cmdline_parse_token_string_t cmd_operate_port_all_port =
1168         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1169                                                 "start#stop#close#reset");
1170 cmdline_parse_token_string_t cmd_operate_port_all_all =
1171         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1172
1173 cmdline_parse_inst_t cmd_operate_port = {
1174         .f = cmd_operate_port_parsed,
1175         .data = NULL,
1176         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1177         .tokens = {
1178                 (void *)&cmd_operate_port_all_cmd,
1179                 (void *)&cmd_operate_port_all_port,
1180                 (void *)&cmd_operate_port_all_all,
1181                 NULL,
1182         },
1183 };
1184
1185 /* *** start/stop/close specific port *** */
1186 struct cmd_operate_specific_port_result {
1187         cmdline_fixed_string_t keyword;
1188         cmdline_fixed_string_t name;
1189         uint8_t value;
1190 };
1191
1192 static void cmd_operate_specific_port_parsed(void *parsed_result,
1193                         __attribute__((unused)) struct cmdline *cl,
1194                                 __attribute__((unused)) void *data)
1195 {
1196         struct cmd_operate_specific_port_result *res = parsed_result;
1197
1198         if (!strcmp(res->name, "start"))
1199                 start_port(res->value);
1200         else if (!strcmp(res->name, "stop"))
1201                 stop_port(res->value);
1202         else if (!strcmp(res->name, "close"))
1203                 close_port(res->value);
1204         else if (!strcmp(res->name, "reset"))
1205                 reset_port(res->value);
1206         else
1207                 printf("Unknown parameter\n");
1208 }
1209
1210 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1211         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1212                                                         keyword, "port");
1213 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1214         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1215                                                 name, "start#stop#close#reset");
1216 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1217         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1218                                                         value, UINT8);
1219
1220 cmdline_parse_inst_t cmd_operate_specific_port = {
1221         .f = cmd_operate_specific_port_parsed,
1222         .data = NULL,
1223         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1224         .tokens = {
1225                 (void *)&cmd_operate_specific_port_cmd,
1226                 (void *)&cmd_operate_specific_port_port,
1227                 (void *)&cmd_operate_specific_port_id,
1228                 NULL,
1229         },
1230 };
1231
1232 /* *** attach a specified port *** */
1233 struct cmd_operate_attach_port_result {
1234         cmdline_fixed_string_t port;
1235         cmdline_fixed_string_t keyword;
1236         cmdline_fixed_string_t identifier;
1237 };
1238
1239 static void cmd_operate_attach_port_parsed(void *parsed_result,
1240                                 __attribute__((unused)) struct cmdline *cl,
1241                                 __attribute__((unused)) void *data)
1242 {
1243         struct cmd_operate_attach_port_result *res = parsed_result;
1244
1245         if (!strcmp(res->keyword, "attach"))
1246                 attach_port(res->identifier);
1247         else
1248                 printf("Unknown parameter\n");
1249 }
1250
1251 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1252         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1253                         port, "port");
1254 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1255         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1256                         keyword, "attach");
1257 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1258         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1259                         identifier, NULL);
1260
1261 cmdline_parse_inst_t cmd_operate_attach_port = {
1262         .f = cmd_operate_attach_port_parsed,
1263         .data = NULL,
1264         .help_str = "port attach <identifier>: "
1265                 "(identifier: pci address or virtual dev name)",
1266         .tokens = {
1267                 (void *)&cmd_operate_attach_port_port,
1268                 (void *)&cmd_operate_attach_port_keyword,
1269                 (void *)&cmd_operate_attach_port_identifier,
1270                 NULL,
1271         },
1272 };
1273
1274 /* *** detach a specified port *** */
1275 struct cmd_operate_detach_port_result {
1276         cmdline_fixed_string_t port;
1277         cmdline_fixed_string_t keyword;
1278         portid_t port_id;
1279 };
1280
1281 static void cmd_operate_detach_port_parsed(void *parsed_result,
1282                                 __attribute__((unused)) struct cmdline *cl,
1283                                 __attribute__((unused)) void *data)
1284 {
1285         struct cmd_operate_detach_port_result *res = parsed_result;
1286
1287         if (!strcmp(res->keyword, "detach"))
1288                 detach_port(res->port_id);
1289         else
1290                 printf("Unknown parameter\n");
1291 }
1292
1293 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1294         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1295                         port, "port");
1296 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1297         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1298                         keyword, "detach");
1299 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1300         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1301                         port_id, UINT16);
1302
1303 cmdline_parse_inst_t cmd_operate_detach_port = {
1304         .f = cmd_operate_detach_port_parsed,
1305         .data = NULL,
1306         .help_str = "port detach <port_id>",
1307         .tokens = {
1308                 (void *)&cmd_operate_detach_port_port,
1309                 (void *)&cmd_operate_detach_port_keyword,
1310                 (void *)&cmd_operate_detach_port_port_id,
1311                 NULL,
1312         },
1313 };
1314
1315 /* *** configure speed for all ports *** */
1316 struct cmd_config_speed_all {
1317         cmdline_fixed_string_t port;
1318         cmdline_fixed_string_t keyword;
1319         cmdline_fixed_string_t all;
1320         cmdline_fixed_string_t item1;
1321         cmdline_fixed_string_t item2;
1322         cmdline_fixed_string_t value1;
1323         cmdline_fixed_string_t value2;
1324 };
1325
1326 static int
1327 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1328 {
1329
1330         int duplex;
1331
1332         if (!strcmp(duplexstr, "half")) {
1333                 duplex = ETH_LINK_HALF_DUPLEX;
1334         } else if (!strcmp(duplexstr, "full")) {
1335                 duplex = ETH_LINK_FULL_DUPLEX;
1336         } else if (!strcmp(duplexstr, "auto")) {
1337                 duplex = ETH_LINK_FULL_DUPLEX;
1338         } else {
1339                 printf("Unknown duplex parameter\n");
1340                 return -1;
1341         }
1342
1343         if (!strcmp(speedstr, "10")) {
1344                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1345                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1346         } else if (!strcmp(speedstr, "100")) {
1347                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1348                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1349         } else {
1350                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1351                         printf("Invalid speed/duplex parameters\n");
1352                         return -1;
1353                 }
1354                 if (!strcmp(speedstr, "1000")) {
1355                         *speed = ETH_LINK_SPEED_1G;
1356                 } else if (!strcmp(speedstr, "10000")) {
1357                         *speed = ETH_LINK_SPEED_10G;
1358                 } else if (!strcmp(speedstr, "25000")) {
1359                         *speed = ETH_LINK_SPEED_25G;
1360                 } else if (!strcmp(speedstr, "40000")) {
1361                         *speed = ETH_LINK_SPEED_40G;
1362                 } else if (!strcmp(speedstr, "50000")) {
1363                         *speed = ETH_LINK_SPEED_50G;
1364                 } else if (!strcmp(speedstr, "100000")) {
1365                         *speed = ETH_LINK_SPEED_100G;
1366                 } else if (!strcmp(speedstr, "auto")) {
1367                         *speed = ETH_LINK_SPEED_AUTONEG;
1368                 } else {
1369                         printf("Unknown speed parameter\n");
1370                         return -1;
1371                 }
1372         }
1373
1374         return 0;
1375 }
1376
1377 static void
1378 cmd_config_speed_all_parsed(void *parsed_result,
1379                         __attribute__((unused)) struct cmdline *cl,
1380                         __attribute__((unused)) void *data)
1381 {
1382         struct cmd_config_speed_all *res = parsed_result;
1383         uint32_t link_speed;
1384         portid_t pid;
1385
1386         if (!all_ports_stopped()) {
1387                 printf("Please stop all ports first\n");
1388                 return;
1389         }
1390
1391         if (parse_and_check_speed_duplex(res->value1, res->value2,
1392                         &link_speed) < 0)
1393                 return;
1394
1395         RTE_ETH_FOREACH_DEV(pid) {
1396                 ports[pid].dev_conf.link_speeds = link_speed;
1397         }
1398
1399         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1400 }
1401
1402 cmdline_parse_token_string_t cmd_config_speed_all_port =
1403         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1404 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1405         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1406                                                         "config");
1407 cmdline_parse_token_string_t cmd_config_speed_all_all =
1408         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1409 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1410         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1411 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1412         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1413                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1414 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1415         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1416 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1417         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1418                                                 "half#full#auto");
1419
1420 cmdline_parse_inst_t cmd_config_speed_all = {
1421         .f = cmd_config_speed_all_parsed,
1422         .data = NULL,
1423         .help_str = "port config all speed "
1424                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1425                                                         "half|full|auto",
1426         .tokens = {
1427                 (void *)&cmd_config_speed_all_port,
1428                 (void *)&cmd_config_speed_all_keyword,
1429                 (void *)&cmd_config_speed_all_all,
1430                 (void *)&cmd_config_speed_all_item1,
1431                 (void *)&cmd_config_speed_all_value1,
1432                 (void *)&cmd_config_speed_all_item2,
1433                 (void *)&cmd_config_speed_all_value2,
1434                 NULL,
1435         },
1436 };
1437
1438 /* *** configure speed for specific port *** */
1439 struct cmd_config_speed_specific {
1440         cmdline_fixed_string_t port;
1441         cmdline_fixed_string_t keyword;
1442         portid_t id;
1443         cmdline_fixed_string_t item1;
1444         cmdline_fixed_string_t item2;
1445         cmdline_fixed_string_t value1;
1446         cmdline_fixed_string_t value2;
1447 };
1448
1449 static void
1450 cmd_config_speed_specific_parsed(void *parsed_result,
1451                                 __attribute__((unused)) struct cmdline *cl,
1452                                 __attribute__((unused)) void *data)
1453 {
1454         struct cmd_config_speed_specific *res = parsed_result;
1455         uint32_t link_speed;
1456
1457         if (!all_ports_stopped()) {
1458                 printf("Please stop all ports first\n");
1459                 return;
1460         }
1461
1462         if (port_id_is_invalid(res->id, ENABLED_WARN))
1463                 return;
1464
1465         if (parse_and_check_speed_duplex(res->value1, res->value2,
1466                         &link_speed) < 0)
1467                 return;
1468
1469         ports[res->id].dev_conf.link_speeds = link_speed;
1470
1471         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1472 }
1473
1474
1475 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1476         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1477                                                                 "port");
1478 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1479         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1480                                                                 "config");
1481 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1482         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1483 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1484         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1485                                                                 "speed");
1486 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1487         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1488                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1489 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1490         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1491                                                                 "duplex");
1492 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1493         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1494                                                         "half#full#auto");
1495
1496 cmdline_parse_inst_t cmd_config_speed_specific = {
1497         .f = cmd_config_speed_specific_parsed,
1498         .data = NULL,
1499         .help_str = "port config <port_id> speed "
1500                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1501                                                         "half|full|auto",
1502         .tokens = {
1503                 (void *)&cmd_config_speed_specific_port,
1504                 (void *)&cmd_config_speed_specific_keyword,
1505                 (void *)&cmd_config_speed_specific_id,
1506                 (void *)&cmd_config_speed_specific_item1,
1507                 (void *)&cmd_config_speed_specific_value1,
1508                 (void *)&cmd_config_speed_specific_item2,
1509                 (void *)&cmd_config_speed_specific_value2,
1510                 NULL,
1511         },
1512 };
1513
1514 /* *** configure loopback for all ports *** */
1515 struct cmd_config_loopback_all {
1516         cmdline_fixed_string_t port;
1517         cmdline_fixed_string_t keyword;
1518         cmdline_fixed_string_t all;
1519         cmdline_fixed_string_t item;
1520         uint32_t mode;
1521 };
1522
1523 static void
1524 cmd_config_loopback_all_parsed(void *parsed_result,
1525                         __attribute__((unused)) struct cmdline *cl,
1526                         __attribute__((unused)) void *data)
1527 {
1528         struct cmd_config_loopback_all *res = parsed_result;
1529         portid_t pid;
1530
1531         if (!all_ports_stopped()) {
1532                 printf("Please stop all ports first\n");
1533                 return;
1534         }
1535
1536         RTE_ETH_FOREACH_DEV(pid) {
1537                 ports[pid].dev_conf.lpbk_mode = res->mode;
1538         }
1539
1540         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1541 }
1542
1543 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1544         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1545 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1546         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1547                                                         "config");
1548 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1549         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1550 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1551         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1552                                                         "loopback");
1553 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1554         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1555
1556 cmdline_parse_inst_t cmd_config_loopback_all = {
1557         .f = cmd_config_loopback_all_parsed,
1558         .data = NULL,
1559         .help_str = "port config all loopback <mode>",
1560         .tokens = {
1561                 (void *)&cmd_config_loopback_all_port,
1562                 (void *)&cmd_config_loopback_all_keyword,
1563                 (void *)&cmd_config_loopback_all_all,
1564                 (void *)&cmd_config_loopback_all_item,
1565                 (void *)&cmd_config_loopback_all_mode,
1566                 NULL,
1567         },
1568 };
1569
1570 /* *** configure loopback for specific port *** */
1571 struct cmd_config_loopback_specific {
1572         cmdline_fixed_string_t port;
1573         cmdline_fixed_string_t keyword;
1574         uint16_t port_id;
1575         cmdline_fixed_string_t item;
1576         uint32_t mode;
1577 };
1578
1579 static void
1580 cmd_config_loopback_specific_parsed(void *parsed_result,
1581                                 __attribute__((unused)) struct cmdline *cl,
1582                                 __attribute__((unused)) void *data)
1583 {
1584         struct cmd_config_loopback_specific *res = parsed_result;
1585
1586         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1587                 return;
1588
1589         if (!port_is_stopped(res->port_id)) {
1590                 printf("Please stop port %u first\n", res->port_id);
1591                 return;
1592         }
1593
1594         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1595
1596         cmd_reconfig_device_queue(res->port_id, 1, 1);
1597 }
1598
1599
1600 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1601         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1602                                                                 "port");
1603 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1604         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1605                                                                 "config");
1606 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1607         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1608                                                                 UINT16);
1609 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1610         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1611                                                                 "loopback");
1612 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1613         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1614                               UINT32);
1615
1616 cmdline_parse_inst_t cmd_config_loopback_specific = {
1617         .f = cmd_config_loopback_specific_parsed,
1618         .data = NULL,
1619         .help_str = "port config <port_id> loopback <mode>",
1620         .tokens = {
1621                 (void *)&cmd_config_loopback_specific_port,
1622                 (void *)&cmd_config_loopback_specific_keyword,
1623                 (void *)&cmd_config_loopback_specific_id,
1624                 (void *)&cmd_config_loopback_specific_item,
1625                 (void *)&cmd_config_loopback_specific_mode,
1626                 NULL,
1627         },
1628 };
1629
1630 /* *** configure txq/rxq, txd/rxd *** */
1631 struct cmd_config_rx_tx {
1632         cmdline_fixed_string_t port;
1633         cmdline_fixed_string_t keyword;
1634         cmdline_fixed_string_t all;
1635         cmdline_fixed_string_t name;
1636         uint16_t value;
1637 };
1638
1639 static void
1640 cmd_config_rx_tx_parsed(void *parsed_result,
1641                         __attribute__((unused)) struct cmdline *cl,
1642                         __attribute__((unused)) void *data)
1643 {
1644         struct cmd_config_rx_tx *res = parsed_result;
1645
1646         if (!all_ports_stopped()) {
1647                 printf("Please stop all ports first\n");
1648                 return;
1649         }
1650         if (!strcmp(res->name, "rxq")) {
1651                 if (!res->value && !nb_txq) {
1652                         printf("Warning: Either rx or tx queues should be non zero\n");
1653                         return;
1654                 }
1655                 if (check_nb_rxq(res->value) != 0)
1656                         return;
1657                 nb_rxq = res->value;
1658         }
1659         else if (!strcmp(res->name, "txq")) {
1660                 if (!res->value && !nb_rxq) {
1661                         printf("Warning: Either rx or tx queues should be non zero\n");
1662                         return;
1663                 }
1664                 if (check_nb_txq(res->value) != 0)
1665                         return;
1666                 nb_txq = res->value;
1667         }
1668         else if (!strcmp(res->name, "rxd")) {
1669                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1670                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1671                                         res->value, RTE_TEST_RX_DESC_MAX);
1672                         return;
1673                 }
1674                 nb_rxd = res->value;
1675         } else if (!strcmp(res->name, "txd")) {
1676                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1677                         printf("txd %d invalid - must be > 0 && <= %d\n",
1678                                         res->value, RTE_TEST_TX_DESC_MAX);
1679                         return;
1680                 }
1681                 nb_txd = res->value;
1682         } else {
1683                 printf("Unknown parameter\n");
1684                 return;
1685         }
1686
1687         fwd_config_setup();
1688
1689         init_port_config();
1690
1691         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1692 }
1693
1694 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1695         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1696 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1697         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1698 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1699         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1700 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1701         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1702                                                 "rxq#txq#rxd#txd");
1703 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1704         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1705
1706 cmdline_parse_inst_t cmd_config_rx_tx = {
1707         .f = cmd_config_rx_tx_parsed,
1708         .data = NULL,
1709         .help_str = "port config all rxq|txq|rxd|txd <value>",
1710         .tokens = {
1711                 (void *)&cmd_config_rx_tx_port,
1712                 (void *)&cmd_config_rx_tx_keyword,
1713                 (void *)&cmd_config_rx_tx_all,
1714                 (void *)&cmd_config_rx_tx_name,
1715                 (void *)&cmd_config_rx_tx_value,
1716                 NULL,
1717         },
1718 };
1719
1720 /* *** config max packet length *** */
1721 struct cmd_config_max_pkt_len_result {
1722         cmdline_fixed_string_t port;
1723         cmdline_fixed_string_t keyword;
1724         cmdline_fixed_string_t all;
1725         cmdline_fixed_string_t name;
1726         uint32_t value;
1727 };
1728
1729 static void
1730 cmd_config_max_pkt_len_parsed(void *parsed_result,
1731                                 __attribute__((unused)) struct cmdline *cl,
1732                                 __attribute__((unused)) void *data)
1733 {
1734         struct cmd_config_max_pkt_len_result *res = parsed_result;
1735         portid_t pid;
1736
1737         if (!all_ports_stopped()) {
1738                 printf("Please stop all ports first\n");
1739                 return;
1740         }
1741
1742         RTE_ETH_FOREACH_DEV(pid) {
1743                 struct rte_port *port = &ports[pid];
1744                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1745
1746                 if (!strcmp(res->name, "max-pkt-len")) {
1747                         if (res->value < ETHER_MIN_LEN) {
1748                                 printf("max-pkt-len can not be less than %d\n",
1749                                                 ETHER_MIN_LEN);
1750                                 return;
1751                         }
1752                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1753                                 return;
1754
1755                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1756                         if (res->value > ETHER_MAX_LEN)
1757                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1758                         else
1759                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1760                         port->dev_conf.rxmode.offloads = rx_offloads;
1761                 } else {
1762                         printf("Unknown parameter\n");
1763                         return;
1764                 }
1765         }
1766
1767         init_port_config();
1768
1769         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1770 }
1771
1772 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1773         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1774                                                                 "port");
1775 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1776         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1777                                                                 "config");
1778 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1779         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1780                                                                 "all");
1781 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1782         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1783                                                                 "max-pkt-len");
1784 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1785         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1786                                                                 UINT32);
1787
1788 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1789         .f = cmd_config_max_pkt_len_parsed,
1790         .data = NULL,
1791         .help_str = "port config all max-pkt-len <value>",
1792         .tokens = {
1793                 (void *)&cmd_config_max_pkt_len_port,
1794                 (void *)&cmd_config_max_pkt_len_keyword,
1795                 (void *)&cmd_config_max_pkt_len_all,
1796                 (void *)&cmd_config_max_pkt_len_name,
1797                 (void *)&cmd_config_max_pkt_len_value,
1798                 NULL,
1799         },
1800 };
1801
1802 /* *** configure port MTU *** */
1803 struct cmd_config_mtu_result {
1804         cmdline_fixed_string_t port;
1805         cmdline_fixed_string_t keyword;
1806         cmdline_fixed_string_t mtu;
1807         portid_t port_id;
1808         uint16_t value;
1809 };
1810
1811 static void
1812 cmd_config_mtu_parsed(void *parsed_result,
1813                       __attribute__((unused)) struct cmdline *cl,
1814                       __attribute__((unused)) void *data)
1815 {
1816         struct cmd_config_mtu_result *res = parsed_result;
1817
1818         if (res->value < ETHER_MIN_LEN) {
1819                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1820                 return;
1821         }
1822         port_mtu_set(res->port_id, res->value);
1823 }
1824
1825 cmdline_parse_token_string_t cmd_config_mtu_port =
1826         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1827                                  "port");
1828 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1829         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1830                                  "config");
1831 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1832         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1833                                  "mtu");
1834 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1835         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1836 cmdline_parse_token_num_t cmd_config_mtu_value =
1837         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1838
1839 cmdline_parse_inst_t cmd_config_mtu = {
1840         .f = cmd_config_mtu_parsed,
1841         .data = NULL,
1842         .help_str = "port config mtu <port_id> <value>",
1843         .tokens = {
1844                 (void *)&cmd_config_mtu_port,
1845                 (void *)&cmd_config_mtu_keyword,
1846                 (void *)&cmd_config_mtu_mtu,
1847                 (void *)&cmd_config_mtu_port_id,
1848                 (void *)&cmd_config_mtu_value,
1849                 NULL,
1850         },
1851 };
1852
1853 /* *** configure rx mode *** */
1854 struct cmd_config_rx_mode_flag {
1855         cmdline_fixed_string_t port;
1856         cmdline_fixed_string_t keyword;
1857         cmdline_fixed_string_t all;
1858         cmdline_fixed_string_t name;
1859         cmdline_fixed_string_t value;
1860 };
1861
1862 static void
1863 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1864                                 __attribute__((unused)) struct cmdline *cl,
1865                                 __attribute__((unused)) void *data)
1866 {
1867         struct cmd_config_rx_mode_flag *res = parsed_result;
1868         portid_t pid;
1869
1870         if (!all_ports_stopped()) {
1871                 printf("Please stop all ports first\n");
1872                 return;
1873         }
1874
1875         RTE_ETH_FOREACH_DEV(pid) {
1876                 struct rte_port *port;
1877                 uint64_t rx_offloads;
1878
1879                 port = &ports[pid];
1880                 rx_offloads = port->dev_conf.rxmode.offloads;
1881                 if (!strcmp(res->name, "crc-strip")) {
1882                         if (!strcmp(res->value, "on"))
1883                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1884                         else if (!strcmp(res->value, "off"))
1885                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1886                         else {
1887                                 printf("Unknown parameter\n");
1888                                 return;
1889                         }
1890                 } else if (!strcmp(res->name, "scatter")) {
1891                         if (!strcmp(res->value, "on")) {
1892                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1893                         } else if (!strcmp(res->value, "off")) {
1894                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1895                         } else {
1896                                 printf("Unknown parameter\n");
1897                                 return;
1898                         }
1899                 } else if (!strcmp(res->name, "rx-cksum")) {
1900                         if (!strcmp(res->value, "on"))
1901                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1902                         else if (!strcmp(res->value, "off"))
1903                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1904                         else {
1905                                 printf("Unknown parameter\n");
1906                                 return;
1907                         }
1908                 } else if (!strcmp(res->name, "rx-timestamp")) {
1909                         if (!strcmp(res->value, "on"))
1910                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1911                         else if (!strcmp(res->value, "off"))
1912                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1913                         else {
1914                                 printf("Unknown parameter\n");
1915                                 return;
1916                         }
1917                 } else if (!strcmp(res->name, "hw-vlan")) {
1918                         if (!strcmp(res->value, "on")) {
1919                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1920                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1921                         } else if (!strcmp(res->value, "off")) {
1922                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1923                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1924                         } else {
1925                                 printf("Unknown parameter\n");
1926                                 return;
1927                         }
1928                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1929                         if (!strcmp(res->value, "on"))
1930                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1931                         else if (!strcmp(res->value, "off"))
1932                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1933                         else {
1934                                 printf("Unknown parameter\n");
1935                                 return;
1936                         }
1937                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1938                         if (!strcmp(res->value, "on"))
1939                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1940                         else if (!strcmp(res->value, "off"))
1941                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1942                         else {
1943                                 printf("Unknown parameter\n");
1944                                 return;
1945                         }
1946                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1947                         if (!strcmp(res->value, "on"))
1948                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1949                         else if (!strcmp(res->value, "off"))
1950                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1951                         else {
1952                                 printf("Unknown parameter\n");
1953                                 return;
1954                         }
1955                 } else if (!strcmp(res->name, "drop-en")) {
1956                         if (!strcmp(res->value, "on"))
1957                                 rx_drop_en = 1;
1958                         else if (!strcmp(res->value, "off"))
1959                                 rx_drop_en = 0;
1960                         else {
1961                                 printf("Unknown parameter\n");
1962                                 return;
1963                         }
1964                 } else {
1965                         printf("Unknown parameter\n");
1966                         return;
1967                 }
1968                 port->dev_conf.rxmode.offloads = rx_offloads;
1969         }
1970
1971         init_port_config();
1972
1973         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1974 }
1975
1976 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1977         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1978 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1979         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1980                                                                 "config");
1981 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1982         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1983 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1984         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1985                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1986                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1987 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1988         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1989                                                         "on#off");
1990
1991 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1992         .f = cmd_config_rx_mode_flag_parsed,
1993         .data = NULL,
1994         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1995                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1996         .tokens = {
1997                 (void *)&cmd_config_rx_mode_flag_port,
1998                 (void *)&cmd_config_rx_mode_flag_keyword,
1999                 (void *)&cmd_config_rx_mode_flag_all,
2000                 (void *)&cmd_config_rx_mode_flag_name,
2001                 (void *)&cmd_config_rx_mode_flag_value,
2002                 NULL,
2003         },
2004 };
2005
2006 /* *** configure rss *** */
2007 struct cmd_config_rss {
2008         cmdline_fixed_string_t port;
2009         cmdline_fixed_string_t keyword;
2010         cmdline_fixed_string_t all;
2011         cmdline_fixed_string_t name;
2012         cmdline_fixed_string_t value;
2013 };
2014
2015 static void
2016 cmd_config_rss_parsed(void *parsed_result,
2017                         __attribute__((unused)) struct cmdline *cl,
2018                         __attribute__((unused)) void *data)
2019 {
2020         struct cmd_config_rss *res = parsed_result;
2021         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2022         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2023         int use_default = 0;
2024         int all_updated = 1;
2025         int diag;
2026         uint16_t i;
2027
2028         if (!strcmp(res->value, "all"))
2029                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2030                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2031                                         ETH_RSS_L2_PAYLOAD;
2032         else if (!strcmp(res->value, "ip"))
2033                 rss_conf.rss_hf = ETH_RSS_IP;
2034         else if (!strcmp(res->value, "udp"))
2035                 rss_conf.rss_hf = ETH_RSS_UDP;
2036         else if (!strcmp(res->value, "tcp"))
2037                 rss_conf.rss_hf = ETH_RSS_TCP;
2038         else if (!strcmp(res->value, "sctp"))
2039                 rss_conf.rss_hf = ETH_RSS_SCTP;
2040         else if (!strcmp(res->value, "ether"))
2041                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2042         else if (!strcmp(res->value, "port"))
2043                 rss_conf.rss_hf = ETH_RSS_PORT;
2044         else if (!strcmp(res->value, "vxlan"))
2045                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2046         else if (!strcmp(res->value, "geneve"))
2047                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2048         else if (!strcmp(res->value, "nvgre"))
2049                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2050         else if (!strcmp(res->value, "none"))
2051                 rss_conf.rss_hf = 0;
2052         else if (!strcmp(res->value, "default"))
2053                 use_default = 1;
2054         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2055                                                 atoi(res->value) < 64)
2056                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2057         else {
2058                 printf("Unknown parameter\n");
2059                 return;
2060         }
2061         rss_conf.rss_key = NULL;
2062         /* Update global configuration for RSS types. */
2063         RTE_ETH_FOREACH_DEV(i) {
2064                 struct rte_eth_rss_conf local_rss_conf;
2065
2066                 rte_eth_dev_info_get(i, &dev_info);
2067                 if (use_default)
2068                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2069
2070                 local_rss_conf = rss_conf;
2071                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2072                         dev_info.flow_type_rss_offloads;
2073                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2074                         printf("Port %u modified RSS hash function based on hardware support,"
2075                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2076                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2077                 }
2078                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2079                 if (diag < 0) {
2080                         all_updated = 0;
2081                         printf("Configuration of RSS hash at ethernet port %d "
2082                                 "failed with error (%d): %s.\n",
2083                                 i, -diag, strerror(-diag));
2084                 }
2085         }
2086         if (all_updated && !use_default)
2087                 rss_hf = rss_conf.rss_hf;
2088 }
2089
2090 cmdline_parse_token_string_t cmd_config_rss_port =
2091         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2092 cmdline_parse_token_string_t cmd_config_rss_keyword =
2093         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2094 cmdline_parse_token_string_t cmd_config_rss_all =
2095         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2096 cmdline_parse_token_string_t cmd_config_rss_name =
2097         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2098 cmdline_parse_token_string_t cmd_config_rss_value =
2099         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2100
2101 cmdline_parse_inst_t cmd_config_rss = {
2102         .f = cmd_config_rss_parsed,
2103         .data = NULL,
2104         .help_str = "port config all rss "
2105                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2106         .tokens = {
2107                 (void *)&cmd_config_rss_port,
2108                 (void *)&cmd_config_rss_keyword,
2109                 (void *)&cmd_config_rss_all,
2110                 (void *)&cmd_config_rss_name,
2111                 (void *)&cmd_config_rss_value,
2112                 NULL,
2113         },
2114 };
2115
2116 /* *** configure rss hash key *** */
2117 struct cmd_config_rss_hash_key {
2118         cmdline_fixed_string_t port;
2119         cmdline_fixed_string_t config;
2120         portid_t port_id;
2121         cmdline_fixed_string_t rss_hash_key;
2122         cmdline_fixed_string_t rss_type;
2123         cmdline_fixed_string_t key;
2124 };
2125
2126 static uint8_t
2127 hexa_digit_to_value(char hexa_digit)
2128 {
2129         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2130                 return (uint8_t) (hexa_digit - '0');
2131         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2132                 return (uint8_t) ((hexa_digit - 'a') + 10);
2133         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2134                 return (uint8_t) ((hexa_digit - 'A') + 10);
2135         /* Invalid hexa digit */
2136         return 0xFF;
2137 }
2138
2139 static uint8_t
2140 parse_and_check_key_hexa_digit(char *key, int idx)
2141 {
2142         uint8_t hexa_v;
2143
2144         hexa_v = hexa_digit_to_value(key[idx]);
2145         if (hexa_v == 0xFF)
2146                 printf("invalid key: character %c at position %d is not a "
2147                        "valid hexa digit\n", key[idx], idx);
2148         return hexa_v;
2149 }
2150
2151 static void
2152 cmd_config_rss_hash_key_parsed(void *parsed_result,
2153                                __attribute__((unused)) struct cmdline *cl,
2154                                __attribute__((unused)) void *data)
2155 {
2156         struct cmd_config_rss_hash_key *res = parsed_result;
2157         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2158         uint8_t xdgt0;
2159         uint8_t xdgt1;
2160         int i;
2161         struct rte_eth_dev_info dev_info;
2162         uint8_t hash_key_size;
2163         uint32_t key_len;
2164
2165         memset(&dev_info, 0, sizeof(dev_info));
2166         rte_eth_dev_info_get(res->port_id, &dev_info);
2167         if (dev_info.hash_key_size > 0 &&
2168                         dev_info.hash_key_size <= sizeof(hash_key))
2169                 hash_key_size = dev_info.hash_key_size;
2170         else {
2171                 printf("dev_info did not provide a valid hash key size\n");
2172                 return;
2173         }
2174         /* Check the length of the RSS hash key */
2175         key_len = strlen(res->key);
2176         if (key_len != (hash_key_size * 2)) {
2177                 printf("key length: %d invalid - key must be a string of %d"
2178                            " hexa-decimal numbers\n",
2179                            (int) key_len, hash_key_size * 2);
2180                 return;
2181         }
2182         /* Translate RSS hash key into binary representation */
2183         for (i = 0; i < hash_key_size; i++) {
2184                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2185                 if (xdgt0 == 0xFF)
2186                         return;
2187                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2188                 if (xdgt1 == 0xFF)
2189                         return;
2190                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2191         }
2192         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2193                         hash_key_size);
2194 }
2195
2196 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2197         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2198 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2199         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2200                                  "config");
2201 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2202         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2203 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2204         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2205                                  rss_hash_key, "rss-hash-key");
2206 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2207         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2208                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2209                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2210                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2211                                  "ipv6-tcp-ex#ipv6-udp-ex");
2212 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2213         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2214
2215 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2216         .f = cmd_config_rss_hash_key_parsed,
2217         .data = NULL,
2218         .help_str = "port config <port_id> rss-hash-key "
2219                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2220                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2221                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2222                 "<string of hex digits (variable length, NIC dependent)>",
2223         .tokens = {
2224                 (void *)&cmd_config_rss_hash_key_port,
2225                 (void *)&cmd_config_rss_hash_key_config,
2226                 (void *)&cmd_config_rss_hash_key_port_id,
2227                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2228                 (void *)&cmd_config_rss_hash_key_rss_type,
2229                 (void *)&cmd_config_rss_hash_key_value,
2230                 NULL,
2231         },
2232 };
2233
2234 /* *** configure port rxq/txq ring size *** */
2235 struct cmd_config_rxtx_ring_size {
2236         cmdline_fixed_string_t port;
2237         cmdline_fixed_string_t config;
2238         portid_t portid;
2239         cmdline_fixed_string_t rxtxq;
2240         uint16_t qid;
2241         cmdline_fixed_string_t rsize;
2242         uint16_t size;
2243 };
2244
2245 static void
2246 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2247                                  __attribute__((unused)) struct cmdline *cl,
2248                                  __attribute__((unused)) void *data)
2249 {
2250         struct cmd_config_rxtx_ring_size *res = parsed_result;
2251         struct rte_port *port;
2252         uint8_t isrx;
2253
2254         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2255                 return;
2256
2257         if (res->portid == (portid_t)RTE_PORT_ALL) {
2258                 printf("Invalid port id\n");
2259                 return;
2260         }
2261
2262         port = &ports[res->portid];
2263
2264         if (!strcmp(res->rxtxq, "rxq"))
2265                 isrx = 1;
2266         else if (!strcmp(res->rxtxq, "txq"))
2267                 isrx = 0;
2268         else {
2269                 printf("Unknown parameter\n");
2270                 return;
2271         }
2272
2273         if (isrx && rx_queue_id_is_invalid(res->qid))
2274                 return;
2275         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2276                 return;
2277
2278         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2279                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2280                        rx_free_thresh);
2281                 return;
2282         }
2283
2284         if (isrx)
2285                 port->nb_rx_desc[res->qid] = res->size;
2286         else
2287                 port->nb_tx_desc[res->qid] = res->size;
2288
2289         cmd_reconfig_device_queue(res->portid, 0, 1);
2290 }
2291
2292 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2293         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2294                                  port, "port");
2295 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2296         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2297                                  config, "config");
2298 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2299         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2300                                  portid, UINT16);
2301 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2302         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2303                                  rxtxq, "rxq#txq");
2304 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2305         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2306                               qid, UINT16);
2307 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2308         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2309                                  rsize, "ring_size");
2310 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2311         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2312                               size, UINT16);
2313
2314 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2315         .f = cmd_config_rxtx_ring_size_parsed,
2316         .data = NULL,
2317         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2318         .tokens = {
2319                 (void *)&cmd_config_rxtx_ring_size_port,
2320                 (void *)&cmd_config_rxtx_ring_size_config,
2321                 (void *)&cmd_config_rxtx_ring_size_portid,
2322                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2323                 (void *)&cmd_config_rxtx_ring_size_qid,
2324                 (void *)&cmd_config_rxtx_ring_size_rsize,
2325                 (void *)&cmd_config_rxtx_ring_size_size,
2326                 NULL,
2327         },
2328 };
2329
2330 /* *** configure port rxq/txq start/stop *** */
2331 struct cmd_config_rxtx_queue {
2332         cmdline_fixed_string_t port;
2333         portid_t portid;
2334         cmdline_fixed_string_t rxtxq;
2335         uint16_t qid;
2336         cmdline_fixed_string_t opname;
2337 };
2338
2339 static void
2340 cmd_config_rxtx_queue_parsed(void *parsed_result,
2341                         __attribute__((unused)) struct cmdline *cl,
2342                         __attribute__((unused)) void *data)
2343 {
2344         struct cmd_config_rxtx_queue *res = parsed_result;
2345         uint8_t isrx;
2346         uint8_t isstart;
2347         int ret = 0;
2348
2349         if (test_done == 0) {
2350                 printf("Please stop forwarding first\n");
2351                 return;
2352         }
2353
2354         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2355                 return;
2356
2357         if (port_is_started(res->portid) != 1) {
2358                 printf("Please start port %u first\n", res->portid);
2359                 return;
2360         }
2361
2362         if (!strcmp(res->rxtxq, "rxq"))
2363                 isrx = 1;
2364         else if (!strcmp(res->rxtxq, "txq"))
2365                 isrx = 0;
2366         else {
2367                 printf("Unknown parameter\n");
2368                 return;
2369         }
2370
2371         if (isrx && rx_queue_id_is_invalid(res->qid))
2372                 return;
2373         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2374                 return;
2375
2376         if (!strcmp(res->opname, "start"))
2377                 isstart = 1;
2378         else if (!strcmp(res->opname, "stop"))
2379                 isstart = 0;
2380         else {
2381                 printf("Unknown parameter\n");
2382                 return;
2383         }
2384
2385         if (isstart && isrx)
2386                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2387         else if (!isstart && isrx)
2388                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2389         else if (isstart && !isrx)
2390                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2391         else
2392                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2393
2394         if (ret == -ENOTSUP)
2395                 printf("Function not supported in PMD driver\n");
2396 }
2397
2398 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2399         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2400 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2401         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2402 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2403         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2404 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2405         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2406 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2407         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2408                                                 "start#stop");
2409
2410 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2411         .f = cmd_config_rxtx_queue_parsed,
2412         .data = NULL,
2413         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2414         .tokens = {
2415                 (void *)&cmd_config_rxtx_queue_port,
2416                 (void *)&cmd_config_rxtx_queue_portid,
2417                 (void *)&cmd_config_rxtx_queue_rxtxq,
2418                 (void *)&cmd_config_rxtx_queue_qid,
2419                 (void *)&cmd_config_rxtx_queue_opname,
2420                 NULL,
2421         },
2422 };
2423
2424 /* *** configure port rxq/txq setup *** */
2425 struct cmd_setup_rxtx_queue {
2426         cmdline_fixed_string_t port;
2427         portid_t portid;
2428         cmdline_fixed_string_t rxtxq;
2429         uint16_t qid;
2430         cmdline_fixed_string_t setup;
2431 };
2432
2433 /* Common CLI fields for queue setup */
2434 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2435         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2436 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2437         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2438 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2439         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2440 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2441         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2442 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2443         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2444
2445 static void
2446 cmd_setup_rxtx_queue_parsed(
2447         void *parsed_result,
2448         __attribute__((unused)) struct cmdline *cl,
2449         __attribute__((unused)) void *data)
2450 {
2451         struct cmd_setup_rxtx_queue *res = parsed_result;
2452         struct rte_port *port;
2453         struct rte_mempool *mp;
2454         unsigned int socket_id;
2455         uint8_t isrx = 0;
2456         int ret;
2457
2458         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2459                 return;
2460
2461         if (res->portid == (portid_t)RTE_PORT_ALL) {
2462                 printf("Invalid port id\n");
2463                 return;
2464         }
2465
2466         if (!strcmp(res->rxtxq, "rxq"))
2467                 isrx = 1;
2468         else if (!strcmp(res->rxtxq, "txq"))
2469                 isrx = 0;
2470         else {
2471                 printf("Unknown parameter\n");
2472                 return;
2473         }
2474
2475         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2476                 printf("Invalid rx queue\n");
2477                 return;
2478         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2479                 printf("Invalid tx queue\n");
2480                 return;
2481         }
2482
2483         port = &ports[res->portid];
2484         if (isrx) {
2485                 socket_id = rxring_numa[res->portid];
2486                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2487                         socket_id = port->socket_id;
2488
2489                 mp = mbuf_pool_find(socket_id);
2490                 if (mp == NULL) {
2491                         printf("Failed to setup RX queue: "
2492                                 "No mempool allocation"
2493                                 " on the socket %d\n",
2494                                 rxring_numa[res->portid]);
2495                         return;
2496                 }
2497                 ret = rte_eth_rx_queue_setup(res->portid,
2498                                              res->qid,
2499                                              port->nb_rx_desc[res->qid],
2500                                              socket_id,
2501                                              &port->rx_conf[res->qid],
2502                                              mp);
2503                 if (ret)
2504                         printf("Failed to setup RX queue\n");
2505         } else {
2506                 socket_id = txring_numa[res->portid];
2507                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2508                         socket_id = port->socket_id;
2509
2510                 ret = rte_eth_tx_queue_setup(res->portid,
2511                                              res->qid,
2512                                              port->nb_tx_desc[res->qid],
2513                                              socket_id,
2514                                              &port->tx_conf[res->qid]);
2515                 if (ret)
2516                         printf("Failed to setup TX queue\n");
2517         }
2518 }
2519
2520 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2521         .f = cmd_setup_rxtx_queue_parsed,
2522         .data = NULL,
2523         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2524         .tokens = {
2525                 (void *)&cmd_setup_rxtx_queue_port,
2526                 (void *)&cmd_setup_rxtx_queue_portid,
2527                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2528                 (void *)&cmd_setup_rxtx_queue_qid,
2529                 (void *)&cmd_setup_rxtx_queue_setup,
2530                 NULL,
2531         },
2532 };
2533
2534
2535 /* *** Configure RSS RETA *** */
2536 struct cmd_config_rss_reta {
2537         cmdline_fixed_string_t port;
2538         cmdline_fixed_string_t keyword;
2539         portid_t port_id;
2540         cmdline_fixed_string_t name;
2541         cmdline_fixed_string_t list_name;
2542         cmdline_fixed_string_t list_of_items;
2543 };
2544
2545 static int
2546 parse_reta_config(const char *str,
2547                   struct rte_eth_rss_reta_entry64 *reta_conf,
2548                   uint16_t nb_entries)
2549 {
2550         int i;
2551         unsigned size;
2552         uint16_t hash_index, idx, shift;
2553         uint16_t nb_queue;
2554         char s[256];
2555         const char *p, *p0 = str;
2556         char *end;
2557         enum fieldnames {
2558                 FLD_HASH_INDEX = 0,
2559                 FLD_QUEUE,
2560                 _NUM_FLD
2561         };
2562         unsigned long int_fld[_NUM_FLD];
2563         char *str_fld[_NUM_FLD];
2564
2565         while ((p = strchr(p0,'(')) != NULL) {
2566                 ++p;
2567                 if((p0 = strchr(p,')')) == NULL)
2568                         return -1;
2569
2570                 size = p0 - p;
2571                 if(size >= sizeof(s))
2572                         return -1;
2573
2574                 snprintf(s, sizeof(s), "%.*s", size, p);
2575                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2576                         return -1;
2577                 for (i = 0; i < _NUM_FLD; i++) {
2578                         errno = 0;
2579                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2580                         if (errno != 0 || end == str_fld[i] ||
2581                                         int_fld[i] > 65535)
2582                                 return -1;
2583                 }
2584
2585                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2586                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2587
2588                 if (hash_index >= nb_entries) {
2589                         printf("Invalid RETA hash index=%d\n", hash_index);
2590                         return -1;
2591                 }
2592
2593                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2594                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2595                 reta_conf[idx].mask |= (1ULL << shift);
2596                 reta_conf[idx].reta[shift] = nb_queue;
2597         }
2598
2599         return 0;
2600 }
2601
2602 static void
2603 cmd_set_rss_reta_parsed(void *parsed_result,
2604                         __attribute__((unused)) struct cmdline *cl,
2605                         __attribute__((unused)) void *data)
2606 {
2607         int ret;
2608         struct rte_eth_dev_info dev_info;
2609         struct rte_eth_rss_reta_entry64 reta_conf[8];
2610         struct cmd_config_rss_reta *res = parsed_result;
2611
2612         memset(&dev_info, 0, sizeof(dev_info));
2613         rte_eth_dev_info_get(res->port_id, &dev_info);
2614         if (dev_info.reta_size == 0) {
2615                 printf("Redirection table size is 0 which is "
2616                                         "invalid for RSS\n");
2617                 return;
2618         } else
2619                 printf("The reta size of port %d is %u\n",
2620                         res->port_id, dev_info.reta_size);
2621         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2622                 printf("Currently do not support more than %u entries of "
2623                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2624                 return;
2625         }
2626
2627         memset(reta_conf, 0, sizeof(reta_conf));
2628         if (!strcmp(res->list_name, "reta")) {
2629                 if (parse_reta_config(res->list_of_items, reta_conf,
2630                                                 dev_info.reta_size)) {
2631                         printf("Invalid RSS Redirection Table "
2632                                         "config entered\n");
2633                         return;
2634                 }
2635                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2636                                 reta_conf, dev_info.reta_size);
2637                 if (ret != 0)
2638                         printf("Bad redirection table parameter, "
2639                                         "return code = %d \n", ret);
2640         }
2641 }
2642
2643 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2644         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2645 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2646         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2647 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2648         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2649 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2650         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2651 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2652         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2653 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2654         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2655                                  NULL);
2656 cmdline_parse_inst_t cmd_config_rss_reta = {
2657         .f = cmd_set_rss_reta_parsed,
2658         .data = NULL,
2659         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2660         .tokens = {
2661                 (void *)&cmd_config_rss_reta_port,
2662                 (void *)&cmd_config_rss_reta_keyword,
2663                 (void *)&cmd_config_rss_reta_port_id,
2664                 (void *)&cmd_config_rss_reta_name,
2665                 (void *)&cmd_config_rss_reta_list_name,
2666                 (void *)&cmd_config_rss_reta_list_of_items,
2667                 NULL,
2668         },
2669 };
2670
2671 /* *** SHOW PORT RETA INFO *** */
2672 struct cmd_showport_reta {
2673         cmdline_fixed_string_t show;
2674         cmdline_fixed_string_t port;
2675         portid_t port_id;
2676         cmdline_fixed_string_t rss;
2677         cmdline_fixed_string_t reta;
2678         uint16_t size;
2679         cmdline_fixed_string_t list_of_items;
2680 };
2681
2682 static int
2683 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2684                            uint16_t nb_entries,
2685                            char *str)
2686 {
2687         uint32_t size;
2688         const char *p, *p0 = str;
2689         char s[256];
2690         char *end;
2691         char *str_fld[8];
2692         uint16_t i;
2693         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2694                         RTE_RETA_GROUP_SIZE;
2695         int ret;
2696
2697         p = strchr(p0, '(');
2698         if (p == NULL)
2699                 return -1;
2700         p++;
2701         p0 = strchr(p, ')');
2702         if (p0 == NULL)
2703                 return -1;
2704         size = p0 - p;
2705         if (size >= sizeof(s)) {
2706                 printf("The string size exceeds the internal buffer size\n");
2707                 return -1;
2708         }
2709         snprintf(s, sizeof(s), "%.*s", size, p);
2710         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2711         if (ret <= 0 || ret != num) {
2712                 printf("The bits of masks do not match the number of "
2713                                         "reta entries: %u\n", num);
2714                 return -1;
2715         }
2716         for (i = 0; i < ret; i++)
2717                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2718
2719         return 0;
2720 }
2721
2722 static void
2723 cmd_showport_reta_parsed(void *parsed_result,
2724                          __attribute__((unused)) struct cmdline *cl,
2725                          __attribute__((unused)) void *data)
2726 {
2727         struct cmd_showport_reta *res = parsed_result;
2728         struct rte_eth_rss_reta_entry64 reta_conf[8];
2729         struct rte_eth_dev_info dev_info;
2730         uint16_t max_reta_size;
2731
2732         memset(&dev_info, 0, sizeof(dev_info));
2733         rte_eth_dev_info_get(res->port_id, &dev_info);
2734         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2735         if (res->size == 0 || res->size > max_reta_size) {
2736                 printf("Invalid redirection table size: %u (1-%u)\n",
2737                         res->size, max_reta_size);
2738                 return;
2739         }
2740
2741         memset(reta_conf, 0, sizeof(reta_conf));
2742         if (showport_parse_reta_config(reta_conf, res->size,
2743                                 res->list_of_items) < 0) {
2744                 printf("Invalid string: %s for reta masks\n",
2745                                         res->list_of_items);
2746                 return;
2747         }
2748         port_rss_reta_info(res->port_id, reta_conf, res->size);
2749 }
2750
2751 cmdline_parse_token_string_t cmd_showport_reta_show =
2752         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2753 cmdline_parse_token_string_t cmd_showport_reta_port =
2754         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2755 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2756         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2757 cmdline_parse_token_string_t cmd_showport_reta_rss =
2758         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2759 cmdline_parse_token_string_t cmd_showport_reta_reta =
2760         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2761 cmdline_parse_token_num_t cmd_showport_reta_size =
2762         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2763 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2764         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2765                                         list_of_items, NULL);
2766
2767 cmdline_parse_inst_t cmd_showport_reta = {
2768         .f = cmd_showport_reta_parsed,
2769         .data = NULL,
2770         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2771         .tokens = {
2772                 (void *)&cmd_showport_reta_show,
2773                 (void *)&cmd_showport_reta_port,
2774                 (void *)&cmd_showport_reta_port_id,
2775                 (void *)&cmd_showport_reta_rss,
2776                 (void *)&cmd_showport_reta_reta,
2777                 (void *)&cmd_showport_reta_size,
2778                 (void *)&cmd_showport_reta_list_of_items,
2779                 NULL,
2780         },
2781 };
2782
2783 /* *** Show RSS hash configuration *** */
2784 struct cmd_showport_rss_hash {
2785         cmdline_fixed_string_t show;
2786         cmdline_fixed_string_t port;
2787         portid_t port_id;
2788         cmdline_fixed_string_t rss_hash;
2789         cmdline_fixed_string_t rss_type;
2790         cmdline_fixed_string_t key; /* optional argument */
2791 };
2792
2793 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2794                                 __attribute__((unused)) struct cmdline *cl,
2795                                 void *show_rss_key)
2796 {
2797         struct cmd_showport_rss_hash *res = parsed_result;
2798
2799         port_rss_hash_conf_show(res->port_id, res->rss_type,
2800                                 show_rss_key != NULL);
2801 }
2802
2803 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2804         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2805 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2806         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2807 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2808         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2809 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2810         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2811                                  "rss-hash");
2812 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2813         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2814                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2815                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2816                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2817                                  "ipv6-tcp-ex#ipv6-udp-ex");
2818 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2819         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2820
2821 cmdline_parse_inst_t cmd_showport_rss_hash = {
2822         .f = cmd_showport_rss_hash_parsed,
2823         .data = NULL,
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",
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                 NULL,
2835         },
2836 };
2837
2838 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2839         .f = cmd_showport_rss_hash_parsed,
2840         .data = (void *)1,
2841         .help_str = "show port <port_id> rss-hash "
2842                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2843                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2844                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2845         .tokens = {
2846                 (void *)&cmd_showport_rss_hash_show,
2847                 (void *)&cmd_showport_rss_hash_port,
2848                 (void *)&cmd_showport_rss_hash_port_id,
2849                 (void *)&cmd_showport_rss_hash_rss_hash,
2850                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2851                 (void *)&cmd_showport_rss_hash_rss_key,
2852                 NULL,
2853         },
2854 };
2855
2856 /* *** Configure DCB *** */
2857 struct cmd_config_dcb {
2858         cmdline_fixed_string_t port;
2859         cmdline_fixed_string_t config;
2860         portid_t port_id;
2861         cmdline_fixed_string_t dcb;
2862         cmdline_fixed_string_t vt;
2863         cmdline_fixed_string_t vt_en;
2864         uint8_t num_tcs;
2865         cmdline_fixed_string_t pfc;
2866         cmdline_fixed_string_t pfc_en;
2867 };
2868
2869 static void
2870 cmd_config_dcb_parsed(void *parsed_result,
2871                         __attribute__((unused)) struct cmdline *cl,
2872                         __attribute__((unused)) void *data)
2873 {
2874         struct cmd_config_dcb *res = parsed_result;
2875         portid_t port_id = res->port_id;
2876         struct rte_port *port;
2877         uint8_t pfc_en;
2878         int ret;
2879
2880         port = &ports[port_id];
2881         /** Check if the port is not started **/
2882         if (port->port_status != RTE_PORT_STOPPED) {
2883                 printf("Please stop port %d first\n", port_id);
2884                 return;
2885         }
2886
2887         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2888                 printf("The invalid number of traffic class,"
2889                         " only 4 or 8 allowed.\n");
2890                 return;
2891         }
2892
2893         if (nb_fwd_lcores < res->num_tcs) {
2894                 printf("nb_cores shouldn't be less than number of TCs.\n");
2895                 return;
2896         }
2897         if (!strncmp(res->pfc_en, "on", 2))
2898                 pfc_en = 1;
2899         else
2900                 pfc_en = 0;
2901
2902         /* DCB in VT mode */
2903         if (!strncmp(res->vt_en, "on", 2))
2904                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2905                                 (enum rte_eth_nb_tcs)res->num_tcs,
2906                                 pfc_en);
2907         else
2908                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2909                                 (enum rte_eth_nb_tcs)res->num_tcs,
2910                                 pfc_en);
2911
2912
2913         if (ret != 0) {
2914                 printf("Cannot initialize network ports.\n");
2915                 return;
2916         }
2917
2918         cmd_reconfig_device_queue(port_id, 1, 1);
2919 }
2920
2921 cmdline_parse_token_string_t cmd_config_dcb_port =
2922         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2923 cmdline_parse_token_string_t cmd_config_dcb_config =
2924         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2925 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2926         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2927 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2928         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2929 cmdline_parse_token_string_t cmd_config_dcb_vt =
2930         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2931 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2932         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2933 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2934         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2935 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2936         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2937 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2938         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2939
2940 cmdline_parse_inst_t cmd_config_dcb = {
2941         .f = cmd_config_dcb_parsed,
2942         .data = NULL,
2943         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2944         .tokens = {
2945                 (void *)&cmd_config_dcb_port,
2946                 (void *)&cmd_config_dcb_config,
2947                 (void *)&cmd_config_dcb_port_id,
2948                 (void *)&cmd_config_dcb_dcb,
2949                 (void *)&cmd_config_dcb_vt,
2950                 (void *)&cmd_config_dcb_vt_en,
2951                 (void *)&cmd_config_dcb_num_tcs,
2952                 (void *)&cmd_config_dcb_pfc,
2953                 (void *)&cmd_config_dcb_pfc_en,
2954                 NULL,
2955         },
2956 };
2957
2958 /* *** configure number of packets per burst *** */
2959 struct cmd_config_burst {
2960         cmdline_fixed_string_t port;
2961         cmdline_fixed_string_t keyword;
2962         cmdline_fixed_string_t all;
2963         cmdline_fixed_string_t name;
2964         uint16_t value;
2965 };
2966
2967 static void
2968 cmd_config_burst_parsed(void *parsed_result,
2969                         __attribute__((unused)) struct cmdline *cl,
2970                         __attribute__((unused)) void *data)
2971 {
2972         struct cmd_config_burst *res = parsed_result;
2973         struct rte_eth_dev_info dev_info;
2974         uint16_t rec_nb_pkts;
2975
2976         if (!all_ports_stopped()) {
2977                 printf("Please stop all ports first\n");
2978                 return;
2979         }
2980
2981         if (!strcmp(res->name, "burst")) {
2982                 if (res->value == 0) {
2983                         /* If user gives a value of zero, query the PMD for
2984                          * its recommended Rx burst size. Testpmd uses a single
2985                          * size for all ports, so assume all ports are the same
2986                          * NIC model and use the values from Port 0.
2987                          */
2988                         rte_eth_dev_info_get(0, &dev_info);
2989                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
2990
2991                         if (rec_nb_pkts == 0) {
2992                                 printf("PMD does not recommend a burst size.\n"
2993                                         "User provided value must be between"
2994                                         " 1 and %d\n", MAX_PKT_BURST);
2995                                 return;
2996                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
2997                                 printf("PMD recommended burst size of %d"
2998                                         " exceeds maximum value of %d\n",
2999                                         rec_nb_pkts, MAX_PKT_BURST);
3000                                 return;
3001                         }
3002                         printf("Using PMD-provided burst value of %d\n",
3003                                 rec_nb_pkts);
3004                         nb_pkt_per_burst = rec_nb_pkts;
3005                 } else if (res->value > MAX_PKT_BURST) {
3006                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3007                         return;
3008                 } else
3009                         nb_pkt_per_burst = res->value;
3010         } else {
3011                 printf("Unknown parameter\n");
3012                 return;
3013         }
3014
3015         init_port_config();
3016
3017         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3018 }
3019
3020 cmdline_parse_token_string_t cmd_config_burst_port =
3021         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3022 cmdline_parse_token_string_t cmd_config_burst_keyword =
3023         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3024 cmdline_parse_token_string_t cmd_config_burst_all =
3025         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3026 cmdline_parse_token_string_t cmd_config_burst_name =
3027         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3028 cmdline_parse_token_num_t cmd_config_burst_value =
3029         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3030
3031 cmdline_parse_inst_t cmd_config_burst = {
3032         .f = cmd_config_burst_parsed,
3033         .data = NULL,
3034         .help_str = "port config all burst <value>",
3035         .tokens = {
3036                 (void *)&cmd_config_burst_port,
3037                 (void *)&cmd_config_burst_keyword,
3038                 (void *)&cmd_config_burst_all,
3039                 (void *)&cmd_config_burst_name,
3040                 (void *)&cmd_config_burst_value,
3041                 NULL,
3042         },
3043 };
3044
3045 /* *** configure rx/tx queues *** */
3046 struct cmd_config_thresh {
3047         cmdline_fixed_string_t port;
3048         cmdline_fixed_string_t keyword;
3049         cmdline_fixed_string_t all;
3050         cmdline_fixed_string_t name;
3051         uint8_t value;
3052 };
3053
3054 static void
3055 cmd_config_thresh_parsed(void *parsed_result,
3056                         __attribute__((unused)) struct cmdline *cl,
3057                         __attribute__((unused)) void *data)
3058 {
3059         struct cmd_config_thresh *res = parsed_result;
3060
3061         if (!all_ports_stopped()) {
3062                 printf("Please stop all ports first\n");
3063                 return;
3064         }
3065
3066         if (!strcmp(res->name, "txpt"))
3067                 tx_pthresh = res->value;
3068         else if(!strcmp(res->name, "txht"))
3069                 tx_hthresh = res->value;
3070         else if(!strcmp(res->name, "txwt"))
3071                 tx_wthresh = res->value;
3072         else if(!strcmp(res->name, "rxpt"))
3073                 rx_pthresh = res->value;
3074         else if(!strcmp(res->name, "rxht"))
3075                 rx_hthresh = res->value;
3076         else if(!strcmp(res->name, "rxwt"))
3077                 rx_wthresh = res->value;
3078         else {
3079                 printf("Unknown parameter\n");
3080                 return;
3081         }
3082
3083         init_port_config();
3084
3085         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3086 }
3087
3088 cmdline_parse_token_string_t cmd_config_thresh_port =
3089         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3090 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3091         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3092 cmdline_parse_token_string_t cmd_config_thresh_all =
3093         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3094 cmdline_parse_token_string_t cmd_config_thresh_name =
3095         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3096                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3097 cmdline_parse_token_num_t cmd_config_thresh_value =
3098         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3099
3100 cmdline_parse_inst_t cmd_config_thresh = {
3101         .f = cmd_config_thresh_parsed,
3102         .data = NULL,
3103         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3104         .tokens = {
3105                 (void *)&cmd_config_thresh_port,
3106                 (void *)&cmd_config_thresh_keyword,
3107                 (void *)&cmd_config_thresh_all,
3108                 (void *)&cmd_config_thresh_name,
3109                 (void *)&cmd_config_thresh_value,
3110                 NULL,
3111         },
3112 };
3113
3114 /* *** configure free/rs threshold *** */
3115 struct cmd_config_threshold {
3116         cmdline_fixed_string_t port;
3117         cmdline_fixed_string_t keyword;
3118         cmdline_fixed_string_t all;
3119         cmdline_fixed_string_t name;
3120         uint16_t value;
3121 };
3122
3123 static void
3124 cmd_config_threshold_parsed(void *parsed_result,
3125                         __attribute__((unused)) struct cmdline *cl,
3126                         __attribute__((unused)) void *data)
3127 {
3128         struct cmd_config_threshold *res = parsed_result;
3129
3130         if (!all_ports_stopped()) {
3131                 printf("Please stop all ports first\n");
3132                 return;
3133         }
3134
3135         if (!strcmp(res->name, "txfreet"))
3136                 tx_free_thresh = res->value;
3137         else if (!strcmp(res->name, "txrst"))
3138                 tx_rs_thresh = res->value;
3139         else if (!strcmp(res->name, "rxfreet"))
3140                 rx_free_thresh = res->value;
3141         else {
3142                 printf("Unknown parameter\n");
3143                 return;
3144         }
3145
3146         init_port_config();
3147
3148         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3149 }
3150
3151 cmdline_parse_token_string_t cmd_config_threshold_port =
3152         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3153 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3154         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3155                                                                 "config");
3156 cmdline_parse_token_string_t cmd_config_threshold_all =
3157         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3158 cmdline_parse_token_string_t cmd_config_threshold_name =
3159         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3160                                                 "txfreet#txrst#rxfreet");
3161 cmdline_parse_token_num_t cmd_config_threshold_value =
3162         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3163
3164 cmdline_parse_inst_t cmd_config_threshold = {
3165         .f = cmd_config_threshold_parsed,
3166         .data = NULL,
3167         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3168         .tokens = {
3169                 (void *)&cmd_config_threshold_port,
3170                 (void *)&cmd_config_threshold_keyword,
3171                 (void *)&cmd_config_threshold_all,
3172                 (void *)&cmd_config_threshold_name,
3173                 (void *)&cmd_config_threshold_value,
3174                 NULL,
3175         },
3176 };
3177
3178 /* *** stop *** */
3179 struct cmd_stop_result {
3180         cmdline_fixed_string_t stop;
3181 };
3182
3183 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3184                             __attribute__((unused)) struct cmdline *cl,
3185                             __attribute__((unused)) void *data)
3186 {
3187         stop_packet_forwarding();
3188 }
3189
3190 cmdline_parse_token_string_t cmd_stop_stop =
3191         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3192
3193 cmdline_parse_inst_t cmd_stop = {
3194         .f = cmd_stop_parsed,
3195         .data = NULL,
3196         .help_str = "stop: Stop packet forwarding",
3197         .tokens = {
3198                 (void *)&cmd_stop_stop,
3199                 NULL,
3200         },
3201 };
3202
3203 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3204
3205 unsigned int
3206 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3207                 unsigned int *parsed_items, int check_unique_values)
3208 {
3209         unsigned int nb_item;
3210         unsigned int value;
3211         unsigned int i;
3212         unsigned int j;
3213         int value_ok;
3214         char c;
3215
3216         /*
3217          * First parse all items in the list and store their value.
3218          */
3219         value = 0;
3220         nb_item = 0;
3221         value_ok = 0;
3222         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3223                 c = str[i];
3224                 if ((c >= '0') && (c <= '9')) {
3225                         value = (unsigned int) (value * 10 + (c - '0'));
3226                         value_ok = 1;
3227                         continue;
3228                 }
3229                 if (c != ',') {
3230                         printf("character %c is not a decimal digit\n", c);
3231                         return 0;
3232                 }
3233                 if (! value_ok) {
3234                         printf("No valid value before comma\n");
3235                         return 0;
3236                 }
3237                 if (nb_item < max_items) {
3238                         parsed_items[nb_item] = value;
3239                         value_ok = 0;
3240                         value = 0;
3241                 }
3242                 nb_item++;
3243         }
3244         if (nb_item >= max_items) {
3245                 printf("Number of %s = %u > %u (maximum items)\n",
3246                        item_name, nb_item + 1, max_items);
3247                 return 0;
3248         }
3249         parsed_items[nb_item++] = value;
3250         if (! check_unique_values)
3251                 return nb_item;
3252
3253         /*
3254          * Then, check that all values in the list are differents.
3255          * No optimization here...
3256          */
3257         for (i = 0; i < nb_item; i++) {
3258                 for (j = i + 1; j < nb_item; j++) {
3259                         if (parsed_items[j] == parsed_items[i]) {
3260                                 printf("duplicated %s %u at index %u and %u\n",
3261                                        item_name, parsed_items[i], i, j);
3262                                 return 0;
3263                         }
3264                 }
3265         }
3266         return nb_item;
3267 }
3268
3269 struct cmd_set_list_result {
3270         cmdline_fixed_string_t cmd_keyword;
3271         cmdline_fixed_string_t list_name;
3272         cmdline_fixed_string_t list_of_items;
3273 };
3274
3275 static void cmd_set_list_parsed(void *parsed_result,
3276                                 __attribute__((unused)) struct cmdline *cl,
3277                                 __attribute__((unused)) void *data)
3278 {
3279         struct cmd_set_list_result *res;
3280         union {
3281                 unsigned int lcorelist[RTE_MAX_LCORE];
3282                 unsigned int portlist[RTE_MAX_ETHPORTS];
3283         } parsed_items;
3284         unsigned int nb_item;
3285
3286         if (test_done == 0) {
3287                 printf("Please stop forwarding first\n");
3288                 return;
3289         }
3290
3291         res = parsed_result;
3292         if (!strcmp(res->list_name, "corelist")) {
3293                 nb_item = parse_item_list(res->list_of_items, "core",
3294                                           RTE_MAX_LCORE,
3295                                           parsed_items.lcorelist, 1);
3296                 if (nb_item > 0) {
3297                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3298                         fwd_config_setup();
3299                 }
3300                 return;
3301         }
3302         if (!strcmp(res->list_name, "portlist")) {
3303                 nb_item = parse_item_list(res->list_of_items, "port",
3304                                           RTE_MAX_ETHPORTS,
3305                                           parsed_items.portlist, 1);
3306                 if (nb_item > 0) {
3307                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3308                         fwd_config_setup();
3309                 }
3310         }
3311 }
3312
3313 cmdline_parse_token_string_t cmd_set_list_keyword =
3314         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3315                                  "set");
3316 cmdline_parse_token_string_t cmd_set_list_name =
3317         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3318                                  "corelist#portlist");
3319 cmdline_parse_token_string_t cmd_set_list_of_items =
3320         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3321                                  NULL);
3322
3323 cmdline_parse_inst_t cmd_set_fwd_list = {
3324         .f = cmd_set_list_parsed,
3325         .data = NULL,
3326         .help_str = "set corelist|portlist <list0[,list1]*>",
3327         .tokens = {
3328                 (void *)&cmd_set_list_keyword,
3329                 (void *)&cmd_set_list_name,
3330                 (void *)&cmd_set_list_of_items,
3331                 NULL,
3332         },
3333 };
3334
3335 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3336
3337 struct cmd_setmask_result {
3338         cmdline_fixed_string_t set;
3339         cmdline_fixed_string_t mask;
3340         uint64_t hexavalue;
3341 };
3342
3343 static void cmd_set_mask_parsed(void *parsed_result,
3344                                 __attribute__((unused)) struct cmdline *cl,
3345                                 __attribute__((unused)) void *data)
3346 {
3347         struct cmd_setmask_result *res = parsed_result;
3348
3349         if (test_done == 0) {
3350                 printf("Please stop forwarding first\n");
3351                 return;
3352         }
3353         if (!strcmp(res->mask, "coremask")) {
3354                 set_fwd_lcores_mask(res->hexavalue);
3355                 fwd_config_setup();
3356         } else if (!strcmp(res->mask, "portmask")) {
3357                 set_fwd_ports_mask(res->hexavalue);
3358                 fwd_config_setup();
3359         }
3360 }
3361
3362 cmdline_parse_token_string_t cmd_setmask_set =
3363         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3364 cmdline_parse_token_string_t cmd_setmask_mask =
3365         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3366                                  "coremask#portmask");
3367 cmdline_parse_token_num_t cmd_setmask_value =
3368         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3369
3370 cmdline_parse_inst_t cmd_set_fwd_mask = {
3371         .f = cmd_set_mask_parsed,
3372         .data = NULL,
3373         .help_str = "set coremask|portmask <hexadecimal value>",
3374         .tokens = {
3375                 (void *)&cmd_setmask_set,
3376                 (void *)&cmd_setmask_mask,
3377                 (void *)&cmd_setmask_value,
3378                 NULL,
3379         },
3380 };
3381
3382 /*
3383  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3384  */
3385 struct cmd_set_result {
3386         cmdline_fixed_string_t set;
3387         cmdline_fixed_string_t what;
3388         uint16_t value;
3389 };
3390
3391 static void cmd_set_parsed(void *parsed_result,
3392                            __attribute__((unused)) struct cmdline *cl,
3393                            __attribute__((unused)) void *data)
3394 {
3395         struct cmd_set_result *res = parsed_result;
3396         if (!strcmp(res->what, "nbport")) {
3397                 set_fwd_ports_number(res->value);
3398                 fwd_config_setup();
3399         } else if (!strcmp(res->what, "nbcore")) {
3400                 set_fwd_lcores_number(res->value);
3401                 fwd_config_setup();
3402         } else if (!strcmp(res->what, "burst"))
3403                 set_nb_pkt_per_burst(res->value);
3404         else if (!strcmp(res->what, "verbose"))
3405                 set_verbose_level(res->value);
3406 }
3407
3408 cmdline_parse_token_string_t cmd_set_set =
3409         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3410 cmdline_parse_token_string_t cmd_set_what =
3411         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3412                                  "nbport#nbcore#burst#verbose");
3413 cmdline_parse_token_num_t cmd_set_value =
3414         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3415
3416 cmdline_parse_inst_t cmd_set_numbers = {
3417         .f = cmd_set_parsed,
3418         .data = NULL,
3419         .help_str = "set nbport|nbcore|burst|verbose <value>",
3420         .tokens = {
3421                 (void *)&cmd_set_set,
3422                 (void *)&cmd_set_what,
3423                 (void *)&cmd_set_value,
3424                 NULL,
3425         },
3426 };
3427
3428 /* *** SET LOG LEVEL CONFIGURATION *** */
3429
3430 struct cmd_set_log_result {
3431         cmdline_fixed_string_t set;
3432         cmdline_fixed_string_t log;
3433         cmdline_fixed_string_t type;
3434         uint32_t level;
3435 };
3436
3437 static void
3438 cmd_set_log_parsed(void *parsed_result,
3439                    __attribute__((unused)) struct cmdline *cl,
3440                    __attribute__((unused)) void *data)
3441 {
3442         struct cmd_set_log_result *res;
3443         int ret;
3444
3445         res = parsed_result;
3446         if (!strcmp(res->type, "global"))
3447                 rte_log_set_global_level(res->level);
3448         else {
3449                 ret = rte_log_set_level_regexp(res->type, res->level);
3450                 if (ret < 0)
3451                         printf("Unable to set log level\n");
3452         }
3453 }
3454
3455 cmdline_parse_token_string_t cmd_set_log_set =
3456         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3457 cmdline_parse_token_string_t cmd_set_log_log =
3458         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3459 cmdline_parse_token_string_t cmd_set_log_type =
3460         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3461 cmdline_parse_token_num_t cmd_set_log_level =
3462         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3463
3464 cmdline_parse_inst_t cmd_set_log = {
3465         .f = cmd_set_log_parsed,
3466         .data = NULL,
3467         .help_str = "set log global|<type> <level>",
3468         .tokens = {
3469                 (void *)&cmd_set_log_set,
3470                 (void *)&cmd_set_log_log,
3471                 (void *)&cmd_set_log_type,
3472                 (void *)&cmd_set_log_level,
3473                 NULL,
3474         },
3475 };
3476
3477 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3478
3479 struct cmd_set_txpkts_result {
3480         cmdline_fixed_string_t cmd_keyword;
3481         cmdline_fixed_string_t txpkts;
3482         cmdline_fixed_string_t seg_lengths;
3483 };
3484
3485 static void
3486 cmd_set_txpkts_parsed(void *parsed_result,
3487                       __attribute__((unused)) struct cmdline *cl,
3488                       __attribute__((unused)) void *data)
3489 {
3490         struct cmd_set_txpkts_result *res;
3491         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3492         unsigned int nb_segs;
3493
3494         res = parsed_result;
3495         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3496                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3497         if (nb_segs > 0)
3498                 set_tx_pkt_segments(seg_lengths, nb_segs);
3499 }
3500
3501 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3502         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3503                                  cmd_keyword, "set");
3504 cmdline_parse_token_string_t cmd_set_txpkts_name =
3505         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3506                                  txpkts, "txpkts");
3507 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3508         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3509                                  seg_lengths, NULL);
3510
3511 cmdline_parse_inst_t cmd_set_txpkts = {
3512         .f = cmd_set_txpkts_parsed,
3513         .data = NULL,
3514         .help_str = "set txpkts <len0[,len1]*>",
3515         .tokens = {
3516                 (void *)&cmd_set_txpkts_keyword,
3517                 (void *)&cmd_set_txpkts_name,
3518                 (void *)&cmd_set_txpkts_lengths,
3519                 NULL,
3520         },
3521 };
3522
3523 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3524
3525 struct cmd_set_txsplit_result {
3526         cmdline_fixed_string_t cmd_keyword;
3527         cmdline_fixed_string_t txsplit;
3528         cmdline_fixed_string_t mode;
3529 };
3530
3531 static void
3532 cmd_set_txsplit_parsed(void *parsed_result,
3533                       __attribute__((unused)) struct cmdline *cl,
3534                       __attribute__((unused)) void *data)
3535 {
3536         struct cmd_set_txsplit_result *res;
3537
3538         res = parsed_result;
3539         set_tx_pkt_split(res->mode);
3540 }
3541
3542 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3543         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3544                                  cmd_keyword, "set");
3545 cmdline_parse_token_string_t cmd_set_txsplit_name =
3546         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3547                                  txsplit, "txsplit");
3548 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3549         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3550                                  mode, NULL);
3551
3552 cmdline_parse_inst_t cmd_set_txsplit = {
3553         .f = cmd_set_txsplit_parsed,
3554         .data = NULL,
3555         .help_str = "set txsplit on|off|rand",
3556         .tokens = {
3557                 (void *)&cmd_set_txsplit_keyword,
3558                 (void *)&cmd_set_txsplit_name,
3559                 (void *)&cmd_set_txsplit_mode,
3560                 NULL,
3561         },
3562 };
3563
3564 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3565 struct cmd_rx_vlan_filter_all_result {
3566         cmdline_fixed_string_t rx_vlan;
3567         cmdline_fixed_string_t what;
3568         cmdline_fixed_string_t all;
3569         portid_t port_id;
3570 };
3571
3572 static void
3573 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3574                               __attribute__((unused)) struct cmdline *cl,
3575                               __attribute__((unused)) void *data)
3576 {
3577         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3578
3579         if (!strcmp(res->what, "add"))
3580                 rx_vlan_all_filter_set(res->port_id, 1);
3581         else
3582                 rx_vlan_all_filter_set(res->port_id, 0);
3583 }
3584
3585 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3586         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3587                                  rx_vlan, "rx_vlan");
3588 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3589         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3590                                  what, "add#rm");
3591 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3592         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3593                                  all, "all");
3594 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3595         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3596                               port_id, UINT16);
3597
3598 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3599         .f = cmd_rx_vlan_filter_all_parsed,
3600         .data = NULL,
3601         .help_str = "rx_vlan add|rm all <port_id>: "
3602                 "Add/Remove all identifiers to/from the set of VLAN "
3603                 "identifiers filtered by a port",
3604         .tokens = {
3605                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3606                 (void *)&cmd_rx_vlan_filter_all_what,
3607                 (void *)&cmd_rx_vlan_filter_all_all,
3608                 (void *)&cmd_rx_vlan_filter_all_portid,
3609                 NULL,
3610         },
3611 };
3612
3613 /* *** VLAN OFFLOAD SET ON A PORT *** */
3614 struct cmd_vlan_offload_result {
3615         cmdline_fixed_string_t vlan;
3616         cmdline_fixed_string_t set;
3617         cmdline_fixed_string_t vlan_type;
3618         cmdline_fixed_string_t what;
3619         cmdline_fixed_string_t on;
3620         cmdline_fixed_string_t port_id;
3621 };
3622
3623 static void
3624 cmd_vlan_offload_parsed(void *parsed_result,
3625                           __attribute__((unused)) struct cmdline *cl,
3626                           __attribute__((unused)) void *data)
3627 {
3628         int on;
3629         struct cmd_vlan_offload_result *res = parsed_result;
3630         char *str;
3631         int i, len = 0;
3632         portid_t port_id = 0;
3633         unsigned int tmp;
3634
3635         str = res->port_id;
3636         len = strnlen(str, STR_TOKEN_SIZE);
3637         i = 0;
3638         /* Get port_id first */
3639         while(i < len){
3640                 if(str[i] == ',')
3641                         break;
3642
3643                 i++;
3644         }
3645         str[i]='\0';
3646         tmp = strtoul(str, NULL, 0);
3647         /* If port_id greater that what portid_t can represent, return */
3648         if(tmp >= RTE_MAX_ETHPORTS)
3649                 return;
3650         port_id = (portid_t)tmp;
3651
3652         if (!strcmp(res->on, "on"))
3653                 on = 1;
3654         else
3655                 on = 0;
3656
3657         if (!strcmp(res->what, "strip"))
3658                 rx_vlan_strip_set(port_id,  on);
3659         else if(!strcmp(res->what, "stripq")){
3660                 uint16_t queue_id = 0;
3661
3662                 /* No queue_id, return */
3663                 if(i + 1 >= len) {
3664                         printf("must specify (port,queue_id)\n");
3665                         return;
3666                 }
3667                 tmp = strtoul(str + i + 1, NULL, 0);
3668                 /* If queue_id greater that what 16-bits can represent, return */
3669                 if(tmp > 0xffff)
3670                         return;
3671
3672                 queue_id = (uint16_t)tmp;
3673                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3674         }
3675         else if (!strcmp(res->what, "filter"))
3676                 rx_vlan_filter_set(port_id, on);
3677         else
3678                 vlan_extend_set(port_id, on);
3679
3680         return;
3681 }
3682
3683 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3684         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3685                                  vlan, "vlan");
3686 cmdline_parse_token_string_t cmd_vlan_offload_set =
3687         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3688                                  set, "set");
3689 cmdline_parse_token_string_t cmd_vlan_offload_what =
3690         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3691                                  what, "strip#filter#qinq#stripq");
3692 cmdline_parse_token_string_t cmd_vlan_offload_on =
3693         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3694                               on, "on#off");
3695 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3696         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3697                               port_id, NULL);
3698
3699 cmdline_parse_inst_t cmd_vlan_offload = {
3700         .f = cmd_vlan_offload_parsed,
3701         .data = NULL,
3702         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3703                 "<port_id[,queue_id]>: "
3704                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3705         .tokens = {
3706                 (void *)&cmd_vlan_offload_vlan,
3707                 (void *)&cmd_vlan_offload_set,
3708                 (void *)&cmd_vlan_offload_what,
3709                 (void *)&cmd_vlan_offload_on,
3710                 (void *)&cmd_vlan_offload_portid,
3711                 NULL,
3712         },
3713 };
3714
3715 /* *** VLAN TPID SET ON A PORT *** */
3716 struct cmd_vlan_tpid_result {
3717         cmdline_fixed_string_t vlan;
3718         cmdline_fixed_string_t set;
3719         cmdline_fixed_string_t vlan_type;
3720         cmdline_fixed_string_t what;
3721         uint16_t tp_id;
3722         portid_t port_id;
3723 };
3724
3725 static void
3726 cmd_vlan_tpid_parsed(void *parsed_result,
3727                           __attribute__((unused)) struct cmdline *cl,
3728                           __attribute__((unused)) void *data)
3729 {
3730         struct cmd_vlan_tpid_result *res = parsed_result;
3731         enum rte_vlan_type vlan_type;
3732
3733         if (!strcmp(res->vlan_type, "inner"))
3734                 vlan_type = ETH_VLAN_TYPE_INNER;
3735         else if (!strcmp(res->vlan_type, "outer"))
3736                 vlan_type = ETH_VLAN_TYPE_OUTER;
3737         else {
3738                 printf("Unknown vlan type\n");
3739                 return;
3740         }
3741         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3742 }
3743
3744 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3745         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3746                                  vlan, "vlan");
3747 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3748         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3749                                  set, "set");
3750 cmdline_parse_token_string_t cmd_vlan_type =
3751         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3752                                  vlan_type, "inner#outer");
3753 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3754         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3755                                  what, "tpid");
3756 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3757         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3758                               tp_id, UINT16);
3759 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3760         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3761                               port_id, UINT16);
3762
3763 cmdline_parse_inst_t cmd_vlan_tpid = {
3764         .f = cmd_vlan_tpid_parsed,
3765         .data = NULL,
3766         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3767                 "Set the VLAN Ether type",
3768         .tokens = {
3769                 (void *)&cmd_vlan_tpid_vlan,
3770                 (void *)&cmd_vlan_tpid_set,
3771                 (void *)&cmd_vlan_type,
3772                 (void *)&cmd_vlan_tpid_what,
3773                 (void *)&cmd_vlan_tpid_tpid,
3774                 (void *)&cmd_vlan_tpid_portid,
3775                 NULL,
3776         },
3777 };
3778
3779 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3780 struct cmd_rx_vlan_filter_result {
3781         cmdline_fixed_string_t rx_vlan;
3782         cmdline_fixed_string_t what;
3783         uint16_t vlan_id;
3784         portid_t port_id;
3785 };
3786
3787 static void
3788 cmd_rx_vlan_filter_parsed(void *parsed_result,
3789                           __attribute__((unused)) struct cmdline *cl,
3790                           __attribute__((unused)) void *data)
3791 {
3792         struct cmd_rx_vlan_filter_result *res = parsed_result;
3793
3794         if (!strcmp(res->what, "add"))
3795                 rx_vft_set(res->port_id, res->vlan_id, 1);
3796         else
3797                 rx_vft_set(res->port_id, res->vlan_id, 0);
3798 }
3799
3800 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3801         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3802                                  rx_vlan, "rx_vlan");
3803 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3804         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3805                                  what, "add#rm");
3806 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3807         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3808                               vlan_id, UINT16);
3809 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3810         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3811                               port_id, UINT16);
3812
3813 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3814         .f = cmd_rx_vlan_filter_parsed,
3815         .data = NULL,
3816         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3817                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3818                 "identifiers filtered by a port",
3819         .tokens = {
3820                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3821                 (void *)&cmd_rx_vlan_filter_what,
3822                 (void *)&cmd_rx_vlan_filter_vlanid,
3823                 (void *)&cmd_rx_vlan_filter_portid,
3824                 NULL,
3825         },
3826 };
3827
3828 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3829 struct cmd_tx_vlan_set_result {
3830         cmdline_fixed_string_t tx_vlan;
3831         cmdline_fixed_string_t set;
3832         portid_t port_id;
3833         uint16_t vlan_id;
3834 };
3835
3836 static void
3837 cmd_tx_vlan_set_parsed(void *parsed_result,
3838                        __attribute__((unused)) struct cmdline *cl,
3839                        __attribute__((unused)) void *data)
3840 {
3841         struct cmd_tx_vlan_set_result *res = parsed_result;
3842
3843         if (!port_is_stopped(res->port_id)) {
3844                 printf("Please stop port %d first\n", res->port_id);
3845                 return;
3846         }
3847
3848         tx_vlan_set(res->port_id, res->vlan_id);
3849
3850         cmd_reconfig_device_queue(res->port_id, 1, 1);
3851 }
3852
3853 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3854         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3855                                  tx_vlan, "tx_vlan");
3856 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3857         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3858                                  set, "set");
3859 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3860         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3861                               port_id, UINT16);
3862 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3863         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3864                               vlan_id, UINT16);
3865
3866 cmdline_parse_inst_t cmd_tx_vlan_set = {
3867         .f = cmd_tx_vlan_set_parsed,
3868         .data = NULL,
3869         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3870                 "Enable hardware insertion of a single VLAN header "
3871                 "with a given TAG Identifier in packets sent on a port",
3872         .tokens = {
3873                 (void *)&cmd_tx_vlan_set_tx_vlan,
3874                 (void *)&cmd_tx_vlan_set_set,
3875                 (void *)&cmd_tx_vlan_set_portid,
3876                 (void *)&cmd_tx_vlan_set_vlanid,
3877                 NULL,
3878         },
3879 };
3880
3881 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3882 struct cmd_tx_vlan_set_qinq_result {
3883         cmdline_fixed_string_t tx_vlan;
3884         cmdline_fixed_string_t set;
3885         portid_t port_id;
3886         uint16_t vlan_id;
3887         uint16_t vlan_id_outer;
3888 };
3889
3890 static void
3891 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3892                             __attribute__((unused)) struct cmdline *cl,
3893                             __attribute__((unused)) void *data)
3894 {
3895         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3896
3897         if (!port_is_stopped(res->port_id)) {
3898                 printf("Please stop port %d first\n", res->port_id);
3899                 return;
3900         }
3901
3902         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3903
3904         cmd_reconfig_device_queue(res->port_id, 1, 1);
3905 }
3906
3907 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3908         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3909                 tx_vlan, "tx_vlan");
3910 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3911         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3912                 set, "set");
3913 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3914         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3915                 port_id, UINT16);
3916 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3917         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3918                 vlan_id, UINT16);
3919 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3920         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3921                 vlan_id_outer, UINT16);
3922
3923 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3924         .f = cmd_tx_vlan_set_qinq_parsed,
3925         .data = NULL,
3926         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3927                 "Enable hardware insertion of double VLAN header "
3928                 "with given TAG Identifiers in packets sent on a port",
3929         .tokens = {
3930                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3931                 (void *)&cmd_tx_vlan_set_qinq_set,
3932                 (void *)&cmd_tx_vlan_set_qinq_portid,
3933                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3934                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3935                 NULL,
3936         },
3937 };
3938
3939 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3940 struct cmd_tx_vlan_set_pvid_result {
3941         cmdline_fixed_string_t tx_vlan;
3942         cmdline_fixed_string_t set;
3943         cmdline_fixed_string_t pvid;
3944         portid_t port_id;
3945         uint16_t vlan_id;
3946         cmdline_fixed_string_t mode;
3947 };
3948
3949 static void
3950 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3951                             __attribute__((unused)) struct cmdline *cl,
3952                             __attribute__((unused)) void *data)
3953 {
3954         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3955
3956         if (strcmp(res->mode, "on") == 0)
3957                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3958         else
3959                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3960 }
3961
3962 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3963         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3964                                  tx_vlan, "tx_vlan");
3965 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3966         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3967                                  set, "set");
3968 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3969         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3970                                  pvid, "pvid");
3971 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3972         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3973                              port_id, UINT16);
3974 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3975         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3976                               vlan_id, UINT16);
3977 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3978         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3979                                  mode, "on#off");
3980
3981 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3982         .f = cmd_tx_vlan_set_pvid_parsed,
3983         .data = NULL,
3984         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3985         .tokens = {
3986                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3987                 (void *)&cmd_tx_vlan_set_pvid_set,
3988                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3989                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3990                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3991                 (void *)&cmd_tx_vlan_set_pvid_mode,
3992                 NULL,
3993         },
3994 };
3995
3996 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3997 struct cmd_tx_vlan_reset_result {
3998         cmdline_fixed_string_t tx_vlan;
3999         cmdline_fixed_string_t reset;
4000         portid_t port_id;
4001 };
4002
4003 static void
4004 cmd_tx_vlan_reset_parsed(void *parsed_result,
4005                          __attribute__((unused)) struct cmdline *cl,
4006                          __attribute__((unused)) void *data)
4007 {
4008         struct cmd_tx_vlan_reset_result *res = parsed_result;
4009
4010         if (!port_is_stopped(res->port_id)) {
4011                 printf("Please stop port %d first\n", res->port_id);
4012                 return;
4013         }
4014
4015         tx_vlan_reset(res->port_id);
4016
4017         cmd_reconfig_device_queue(res->port_id, 1, 1);
4018 }
4019
4020 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4021         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4022                                  tx_vlan, "tx_vlan");
4023 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4024         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4025                                  reset, "reset");
4026 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4027         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4028                               port_id, UINT16);
4029
4030 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4031         .f = cmd_tx_vlan_reset_parsed,
4032         .data = NULL,
4033         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4034                 "VLAN header in packets sent on a port",
4035         .tokens = {
4036                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4037                 (void *)&cmd_tx_vlan_reset_reset,
4038                 (void *)&cmd_tx_vlan_reset_portid,
4039                 NULL,
4040         },
4041 };
4042
4043
4044 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4045 struct cmd_csum_result {
4046         cmdline_fixed_string_t csum;
4047         cmdline_fixed_string_t mode;
4048         cmdline_fixed_string_t proto;
4049         cmdline_fixed_string_t hwsw;
4050         portid_t port_id;
4051 };
4052
4053 static void
4054 csum_show(int port_id)
4055 {
4056         struct rte_eth_dev_info dev_info;
4057         uint64_t tx_offloads;
4058
4059         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4060         printf("Parse tunnel is %s\n",
4061                 (ports[port_id].parse_tunnel) ? "on" : "off");
4062         printf("IP checksum offload is %s\n",
4063                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4064         printf("UDP checksum offload is %s\n",
4065                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4066         printf("TCP checksum offload is %s\n",
4067                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4068         printf("SCTP checksum offload is %s\n",
4069                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4070         printf("Outer-Ip checksum offload is %s\n",
4071                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4072
4073         /* display warnings if configuration is not supported by the NIC */
4074         rte_eth_dev_info_get(port_id, &dev_info);
4075         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4076                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4077                 printf("Warning: hardware IP checksum enabled but not "
4078                         "supported by port %d\n", port_id);
4079         }
4080         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4081                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4082                 printf("Warning: hardware UDP checksum enabled but not "
4083                         "supported by port %d\n", port_id);
4084         }
4085         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4086                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4087                 printf("Warning: hardware TCP checksum enabled but not "
4088                         "supported by port %d\n", port_id);
4089         }
4090         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4091                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4092                 printf("Warning: hardware SCTP checksum enabled but not "
4093                         "supported by port %d\n", port_id);
4094         }
4095         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4096                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4097                 printf("Warning: hardware outer IP checksum enabled but not "
4098                         "supported by port %d\n", port_id);
4099         }
4100 }
4101
4102 static void
4103 cmd_csum_parsed(void *parsed_result,
4104                        __attribute__((unused)) struct cmdline *cl,
4105                        __attribute__((unused)) void *data)
4106 {
4107         struct cmd_csum_result *res = parsed_result;
4108         int hw = 0;
4109         uint64_t csum_offloads = 0;
4110         struct rte_eth_dev_info dev_info;
4111
4112         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4113                 printf("invalid port %d\n", res->port_id);
4114                 return;
4115         }
4116         if (!port_is_stopped(res->port_id)) {
4117                 printf("Please stop port %d first\n", res->port_id);
4118                 return;
4119         }
4120
4121         rte_eth_dev_info_get(res->port_id, &dev_info);
4122         if (!strcmp(res->mode, "set")) {
4123
4124                 if (!strcmp(res->hwsw, "hw"))
4125                         hw = 1;
4126
4127                 if (!strcmp(res->proto, "ip")) {
4128                         if (hw == 0 || (dev_info.tx_offload_capa &
4129                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4130                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4131                         } else {
4132                                 printf("IP checksum offload is not supported "
4133                                        "by port %u\n", res->port_id);
4134                         }
4135                 } else if (!strcmp(res->proto, "udp")) {
4136                         if (hw == 0 || (dev_info.tx_offload_capa &
4137                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4138                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4139                         } else {
4140                                 printf("UDP checksum offload is not supported "
4141                                        "by port %u\n", res->port_id);
4142                         }
4143                 } else if (!strcmp(res->proto, "tcp")) {
4144                         if (hw == 0 || (dev_info.tx_offload_capa &
4145                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4146                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4147                         } else {
4148                                 printf("TCP checksum offload is not supported "
4149                                        "by port %u\n", res->port_id);
4150                         }
4151                 } else if (!strcmp(res->proto, "sctp")) {
4152                         if (hw == 0 || (dev_info.tx_offload_capa &
4153                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4154                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4155                         } else {
4156                                 printf("SCTP checksum offload is not supported "
4157                                        "by port %u\n", res->port_id);
4158                         }
4159                 } else if (!strcmp(res->proto, "outer-ip")) {
4160                         if (hw == 0 || (dev_info.tx_offload_capa &
4161                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4162                                 csum_offloads |=
4163                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4164                         } else {
4165                                 printf("Outer IP checksum offload is not "
4166                                        "supported by port %u\n", res->port_id);
4167                         }
4168                 }
4169
4170                 if (hw) {
4171                         ports[res->port_id].dev_conf.txmode.offloads |=
4172                                                         csum_offloads;
4173                 } else {
4174                         ports[res->port_id].dev_conf.txmode.offloads &=
4175                                                         (~csum_offloads);
4176                 }
4177         }
4178         csum_show(res->port_id);
4179
4180         cmd_reconfig_device_queue(res->port_id, 1, 1);
4181 }
4182
4183 cmdline_parse_token_string_t cmd_csum_csum =
4184         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4185                                 csum, "csum");
4186 cmdline_parse_token_string_t cmd_csum_mode =
4187         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4188                                 mode, "set");
4189 cmdline_parse_token_string_t cmd_csum_proto =
4190         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4191                                 proto, "ip#tcp#udp#sctp#outer-ip");
4192 cmdline_parse_token_string_t cmd_csum_hwsw =
4193         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4194                                 hwsw, "hw#sw");
4195 cmdline_parse_token_num_t cmd_csum_portid =
4196         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4197                                 port_id, UINT16);
4198
4199 cmdline_parse_inst_t cmd_csum_set = {
4200         .f = cmd_csum_parsed,
4201         .data = NULL,
4202         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4203                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4204                 "using csum forward engine",
4205         .tokens = {
4206                 (void *)&cmd_csum_csum,
4207                 (void *)&cmd_csum_mode,
4208                 (void *)&cmd_csum_proto,
4209                 (void *)&cmd_csum_hwsw,
4210                 (void *)&cmd_csum_portid,
4211                 NULL,
4212         },
4213 };
4214
4215 cmdline_parse_token_string_t cmd_csum_mode_show =
4216         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4217                                 mode, "show");
4218
4219 cmdline_parse_inst_t cmd_csum_show = {
4220         .f = cmd_csum_parsed,
4221         .data = NULL,
4222         .help_str = "csum show <port_id>: Show checksum offload configuration",
4223         .tokens = {
4224                 (void *)&cmd_csum_csum,
4225                 (void *)&cmd_csum_mode_show,
4226                 (void *)&cmd_csum_portid,
4227                 NULL,
4228         },
4229 };
4230
4231 /* Enable/disable tunnel parsing */
4232 struct cmd_csum_tunnel_result {
4233         cmdline_fixed_string_t csum;
4234         cmdline_fixed_string_t parse;
4235         cmdline_fixed_string_t onoff;
4236         portid_t port_id;
4237 };
4238
4239 static void
4240 cmd_csum_tunnel_parsed(void *parsed_result,
4241                        __attribute__((unused)) struct cmdline *cl,
4242                        __attribute__((unused)) void *data)
4243 {
4244         struct cmd_csum_tunnel_result *res = parsed_result;
4245
4246         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4247                 return;
4248
4249         if (!strcmp(res->onoff, "on"))
4250                 ports[res->port_id].parse_tunnel = 1;
4251         else
4252                 ports[res->port_id].parse_tunnel = 0;
4253
4254         csum_show(res->port_id);
4255 }
4256
4257 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4258         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4259                                 csum, "csum");
4260 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4261         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4262                                 parse, "parse_tunnel");
4263 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4264         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4265                                 onoff, "on#off");
4266 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4267         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4268                                 port_id, UINT16);
4269
4270 cmdline_parse_inst_t cmd_csum_tunnel = {
4271         .f = cmd_csum_tunnel_parsed,
4272         .data = NULL,
4273         .help_str = "csum parse_tunnel on|off <port_id>: "
4274                 "Enable/Disable parsing of tunnels for csum engine",
4275         .tokens = {
4276                 (void *)&cmd_csum_tunnel_csum,
4277                 (void *)&cmd_csum_tunnel_parse,
4278                 (void *)&cmd_csum_tunnel_onoff,
4279                 (void *)&cmd_csum_tunnel_portid,
4280                 NULL,
4281         },
4282 };
4283
4284 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4285 struct cmd_tso_set_result {
4286         cmdline_fixed_string_t tso;
4287         cmdline_fixed_string_t mode;
4288         uint16_t tso_segsz;
4289         portid_t port_id;
4290 };
4291
4292 static void
4293 cmd_tso_set_parsed(void *parsed_result,
4294                        __attribute__((unused)) struct cmdline *cl,
4295                        __attribute__((unused)) void *data)
4296 {
4297         struct cmd_tso_set_result *res = parsed_result;
4298         struct rte_eth_dev_info dev_info;
4299
4300         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4301                 return;
4302         if (!port_is_stopped(res->port_id)) {
4303                 printf("Please stop port %d first\n", res->port_id);
4304                 return;
4305         }
4306
4307         if (!strcmp(res->mode, "set"))
4308                 ports[res->port_id].tso_segsz = res->tso_segsz;
4309
4310         rte_eth_dev_info_get(res->port_id, &dev_info);
4311         if ((ports[res->port_id].tso_segsz != 0) &&
4312                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4313                 printf("Error: TSO is not supported by port %d\n",
4314                        res->port_id);
4315                 return;
4316         }
4317
4318         if (ports[res->port_id].tso_segsz == 0) {
4319                 ports[res->port_id].dev_conf.txmode.offloads &=
4320                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4321                 printf("TSO for non-tunneled packets is disabled\n");
4322         } else {
4323                 ports[res->port_id].dev_conf.txmode.offloads |=
4324                                                 DEV_TX_OFFLOAD_TCP_TSO;
4325                 printf("TSO segment size for non-tunneled packets is %d\n",
4326                         ports[res->port_id].tso_segsz);
4327         }
4328
4329         /* display warnings if configuration is not supported by the NIC */
4330         rte_eth_dev_info_get(res->port_id, &dev_info);
4331         if ((ports[res->port_id].tso_segsz != 0) &&
4332                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4333                 printf("Warning: TSO enabled but not "
4334                         "supported by port %d\n", res->port_id);
4335         }
4336
4337         cmd_reconfig_device_queue(res->port_id, 1, 1);
4338 }
4339
4340 cmdline_parse_token_string_t cmd_tso_set_tso =
4341         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4342                                 tso, "tso");
4343 cmdline_parse_token_string_t cmd_tso_set_mode =
4344         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4345                                 mode, "set");
4346 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4347         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4348                                 tso_segsz, UINT16);
4349 cmdline_parse_token_num_t cmd_tso_set_portid =
4350         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4351                                 port_id, UINT16);
4352
4353 cmdline_parse_inst_t cmd_tso_set = {
4354         .f = cmd_tso_set_parsed,
4355         .data = NULL,
4356         .help_str = "tso set <tso_segsz> <port_id>: "
4357                 "Set TSO segment size of non-tunneled packets for csum engine "
4358                 "(0 to disable)",
4359         .tokens = {
4360                 (void *)&cmd_tso_set_tso,
4361                 (void *)&cmd_tso_set_mode,
4362                 (void *)&cmd_tso_set_tso_segsz,
4363                 (void *)&cmd_tso_set_portid,
4364                 NULL,
4365         },
4366 };
4367
4368 cmdline_parse_token_string_t cmd_tso_show_mode =
4369         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4370                                 mode, "show");
4371
4372
4373 cmdline_parse_inst_t cmd_tso_show = {
4374         .f = cmd_tso_set_parsed,
4375         .data = NULL,
4376         .help_str = "tso show <port_id>: "
4377                 "Show TSO segment size of non-tunneled packets for csum engine",
4378         .tokens = {
4379                 (void *)&cmd_tso_set_tso,
4380                 (void *)&cmd_tso_show_mode,
4381                 (void *)&cmd_tso_set_portid,
4382                 NULL,
4383         },
4384 };
4385
4386 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4387 struct cmd_tunnel_tso_set_result {
4388         cmdline_fixed_string_t tso;
4389         cmdline_fixed_string_t mode;
4390         uint16_t tso_segsz;
4391         portid_t port_id;
4392 };
4393
4394 static struct rte_eth_dev_info
4395 check_tunnel_tso_nic_support(portid_t port_id)
4396 {
4397         struct rte_eth_dev_info dev_info;
4398
4399         rte_eth_dev_info_get(port_id, &dev_info);
4400         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4401                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4402                        "not enabled for port %d\n", port_id);
4403         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4404                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4405                        "not enabled for port %d\n", port_id);
4406         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4407                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4408                        "not enabled for port %d\n", port_id);
4409         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4410                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4411                        "not enabled for port %d\n", port_id);
4412         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4413                 printf("Warning: IP TUNNEL TSO not supported therefore "
4414                        "not enabled for port %d\n", port_id);
4415         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4416                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4417                        "not enabled for port %d\n", port_id);
4418         return dev_info;
4419 }
4420
4421 static void
4422 cmd_tunnel_tso_set_parsed(void *parsed_result,
4423                           __attribute__((unused)) struct cmdline *cl,
4424                           __attribute__((unused)) void *data)
4425 {
4426         struct cmd_tunnel_tso_set_result *res = parsed_result;
4427         struct rte_eth_dev_info dev_info;
4428
4429         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4430                 return;
4431         if (!port_is_stopped(res->port_id)) {
4432                 printf("Please stop port %d first\n", res->port_id);
4433                 return;
4434         }
4435
4436         if (!strcmp(res->mode, "set"))
4437                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4438
4439         dev_info = check_tunnel_tso_nic_support(res->port_id);
4440         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4441                 ports[res->port_id].dev_conf.txmode.offloads &=
4442                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4443                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4444                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4445                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4446                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4447                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4448                 printf("TSO for tunneled packets is disabled\n");
4449         } else {
4450                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4451                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4452                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4453                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4454                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4455                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4456
4457                 ports[res->port_id].dev_conf.txmode.offloads |=
4458                         (tso_offloads & dev_info.tx_offload_capa);
4459                 printf("TSO segment size for tunneled packets is %d\n",
4460                         ports[res->port_id].tunnel_tso_segsz);
4461
4462                 /* Below conditions are needed to make it work:
4463                  * (1) tunnel TSO is supported by the NIC;
4464                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4465                  * are recognized;
4466                  * (3) for tunneled pkts with outer L3 of IPv4,
4467                  * "csum set outer-ip" must be set to hw, because after tso,
4468                  * total_len of outer IP header is changed, and the checksum
4469                  * of outer IP header calculated by sw should be wrong; that
4470                  * is not necessary for IPv6 tunneled pkts because there's no
4471                  * checksum in IP header anymore.
4472                  */
4473
4474                 if (!ports[res->port_id].parse_tunnel)
4475                         printf("Warning: csum parse_tunnel must be set "
4476                                 "so that tunneled packets are recognized\n");
4477                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4478                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4479                         printf("Warning: csum set outer-ip must be set to hw "
4480                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4481         }
4482
4483         cmd_reconfig_device_queue(res->port_id, 1, 1);
4484 }
4485
4486 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4487         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4488                                 tso, "tunnel_tso");
4489 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4490         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4491                                 mode, "set");
4492 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4493         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4494                                 tso_segsz, UINT16);
4495 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4496         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4497                                 port_id, UINT16);
4498
4499 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4500         .f = cmd_tunnel_tso_set_parsed,
4501         .data = NULL,
4502         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4503                 "Set TSO segment size of tunneled packets for csum engine "
4504                 "(0 to disable)",
4505         .tokens = {
4506                 (void *)&cmd_tunnel_tso_set_tso,
4507                 (void *)&cmd_tunnel_tso_set_mode,
4508                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4509                 (void *)&cmd_tunnel_tso_set_portid,
4510                 NULL,
4511         },
4512 };
4513
4514 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4515         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4516                                 mode, "show");
4517
4518
4519 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4520         .f = cmd_tunnel_tso_set_parsed,
4521         .data = NULL,
4522         .help_str = "tunnel_tso show <port_id> "
4523                 "Show TSO segment size of tunneled packets for csum engine",
4524         .tokens = {
4525                 (void *)&cmd_tunnel_tso_set_tso,
4526                 (void *)&cmd_tunnel_tso_show_mode,
4527                 (void *)&cmd_tunnel_tso_set_portid,
4528                 NULL,
4529         },
4530 };
4531
4532 /* *** SET GRO FOR A PORT *** */
4533 struct cmd_gro_enable_result {
4534         cmdline_fixed_string_t cmd_set;
4535         cmdline_fixed_string_t cmd_port;
4536         cmdline_fixed_string_t cmd_keyword;
4537         cmdline_fixed_string_t cmd_onoff;
4538         portid_t cmd_pid;
4539 };
4540
4541 static void
4542 cmd_gro_enable_parsed(void *parsed_result,
4543                 __attribute__((unused)) struct cmdline *cl,
4544                 __attribute__((unused)) void *data)
4545 {
4546         struct cmd_gro_enable_result *res;
4547
4548         res = parsed_result;
4549         if (!strcmp(res->cmd_keyword, "gro"))
4550                 setup_gro(res->cmd_onoff, res->cmd_pid);
4551 }
4552
4553 cmdline_parse_token_string_t cmd_gro_enable_set =
4554         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4555                         cmd_set, "set");
4556 cmdline_parse_token_string_t cmd_gro_enable_port =
4557         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4558                         cmd_keyword, "port");
4559 cmdline_parse_token_num_t cmd_gro_enable_pid =
4560         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4561                         cmd_pid, UINT16);
4562 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4563         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4564                         cmd_keyword, "gro");
4565 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4566         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4567                         cmd_onoff, "on#off");
4568
4569 cmdline_parse_inst_t cmd_gro_enable = {
4570         .f = cmd_gro_enable_parsed,
4571         .data = NULL,
4572         .help_str = "set port <port_id> gro on|off",
4573         .tokens = {
4574                 (void *)&cmd_gro_enable_set,
4575                 (void *)&cmd_gro_enable_port,
4576                 (void *)&cmd_gro_enable_pid,
4577                 (void *)&cmd_gro_enable_keyword,
4578                 (void *)&cmd_gro_enable_onoff,
4579                 NULL,
4580         },
4581 };
4582
4583 /* *** DISPLAY GRO CONFIGURATION *** */
4584 struct cmd_gro_show_result {
4585         cmdline_fixed_string_t cmd_show;
4586         cmdline_fixed_string_t cmd_port;
4587         cmdline_fixed_string_t cmd_keyword;
4588         portid_t cmd_pid;
4589 };
4590
4591 static void
4592 cmd_gro_show_parsed(void *parsed_result,
4593                 __attribute__((unused)) struct cmdline *cl,
4594                 __attribute__((unused)) void *data)
4595 {
4596         struct cmd_gro_show_result *res;
4597
4598         res = parsed_result;
4599         if (!strcmp(res->cmd_keyword, "gro"))
4600                 show_gro(res->cmd_pid);
4601 }
4602
4603 cmdline_parse_token_string_t cmd_gro_show_show =
4604         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4605                         cmd_show, "show");
4606 cmdline_parse_token_string_t cmd_gro_show_port =
4607         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4608                         cmd_port, "port");
4609 cmdline_parse_token_num_t cmd_gro_show_pid =
4610         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4611                         cmd_pid, UINT16);
4612 cmdline_parse_token_string_t cmd_gro_show_keyword =
4613         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4614                         cmd_keyword, "gro");
4615
4616 cmdline_parse_inst_t cmd_gro_show = {
4617         .f = cmd_gro_show_parsed,
4618         .data = NULL,
4619         .help_str = "show port <port_id> gro",
4620         .tokens = {
4621                 (void *)&cmd_gro_show_show,
4622                 (void *)&cmd_gro_show_port,
4623                 (void *)&cmd_gro_show_pid,
4624                 (void *)&cmd_gro_show_keyword,
4625                 NULL,
4626         },
4627 };
4628
4629 /* *** SET FLUSH CYCLES FOR GRO *** */
4630 struct cmd_gro_flush_result {
4631         cmdline_fixed_string_t cmd_set;
4632         cmdline_fixed_string_t cmd_keyword;
4633         cmdline_fixed_string_t cmd_flush;
4634         uint8_t cmd_cycles;
4635 };
4636
4637 static void
4638 cmd_gro_flush_parsed(void *parsed_result,
4639                 __attribute__((unused)) struct cmdline *cl,
4640                 __attribute__((unused)) void *data)
4641 {
4642         struct cmd_gro_flush_result *res;
4643
4644         res = parsed_result;
4645         if ((!strcmp(res->cmd_keyword, "gro")) &&
4646                         (!strcmp(res->cmd_flush, "flush")))
4647                 setup_gro_flush_cycles(res->cmd_cycles);
4648 }
4649
4650 cmdline_parse_token_string_t cmd_gro_flush_set =
4651         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4652                         cmd_set, "set");
4653 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4654         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4655                         cmd_keyword, "gro");
4656 cmdline_parse_token_string_t cmd_gro_flush_flush =
4657         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4658                         cmd_flush, "flush");
4659 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4660         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4661                         cmd_cycles, UINT8);
4662
4663 cmdline_parse_inst_t cmd_gro_flush = {
4664         .f = cmd_gro_flush_parsed,
4665         .data = NULL,
4666         .help_str = "set gro flush <cycles>",
4667         .tokens = {
4668                 (void *)&cmd_gro_flush_set,
4669                 (void *)&cmd_gro_flush_keyword,
4670                 (void *)&cmd_gro_flush_flush,
4671                 (void *)&cmd_gro_flush_cycles,
4672                 NULL,
4673         },
4674 };
4675
4676 /* *** ENABLE/DISABLE GSO *** */
4677 struct cmd_gso_enable_result {
4678         cmdline_fixed_string_t cmd_set;
4679         cmdline_fixed_string_t cmd_port;
4680         cmdline_fixed_string_t cmd_keyword;
4681         cmdline_fixed_string_t cmd_mode;
4682         portid_t cmd_pid;
4683 };
4684
4685 static void
4686 cmd_gso_enable_parsed(void *parsed_result,
4687                 __attribute__((unused)) struct cmdline *cl,
4688                 __attribute__((unused)) void *data)
4689 {
4690         struct cmd_gso_enable_result *res;
4691
4692         res = parsed_result;
4693         if (!strcmp(res->cmd_keyword, "gso"))
4694                 setup_gso(res->cmd_mode, res->cmd_pid);
4695 }
4696
4697 cmdline_parse_token_string_t cmd_gso_enable_set =
4698         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4699                         cmd_set, "set");
4700 cmdline_parse_token_string_t cmd_gso_enable_port =
4701         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4702                         cmd_port, "port");
4703 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4704         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4705                         cmd_keyword, "gso");
4706 cmdline_parse_token_string_t cmd_gso_enable_mode =
4707         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4708                         cmd_mode, "on#off");
4709 cmdline_parse_token_num_t cmd_gso_enable_pid =
4710         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4711                         cmd_pid, UINT16);
4712
4713 cmdline_parse_inst_t cmd_gso_enable = {
4714         .f = cmd_gso_enable_parsed,
4715         .data = NULL,
4716         .help_str = "set port <port_id> gso on|off",
4717         .tokens = {
4718                 (void *)&cmd_gso_enable_set,
4719                 (void *)&cmd_gso_enable_port,
4720                 (void *)&cmd_gso_enable_pid,
4721                 (void *)&cmd_gso_enable_keyword,
4722                 (void *)&cmd_gso_enable_mode,
4723                 NULL,
4724         },
4725 };
4726
4727 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4728 struct cmd_gso_size_result {
4729         cmdline_fixed_string_t cmd_set;
4730         cmdline_fixed_string_t cmd_keyword;
4731         cmdline_fixed_string_t cmd_segsz;
4732         uint16_t cmd_size;
4733 };
4734
4735 static void
4736 cmd_gso_size_parsed(void *parsed_result,
4737                        __attribute__((unused)) struct cmdline *cl,
4738                        __attribute__((unused)) void *data)
4739 {
4740         struct cmd_gso_size_result *res = parsed_result;
4741
4742         if (test_done == 0) {
4743                 printf("Before setting GSO segsz, please first"
4744                                 " stop fowarding\n");
4745                 return;
4746         }
4747
4748         if (!strcmp(res->cmd_keyword, "gso") &&
4749                         !strcmp(res->cmd_segsz, "segsz")) {
4750                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4751                         printf("gso_size should be larger than %zu."
4752                                         " Please input a legal value\n",
4753                                         RTE_GSO_SEG_SIZE_MIN);
4754                 else
4755                         gso_max_segment_size = res->cmd_size;
4756         }
4757 }
4758
4759 cmdline_parse_token_string_t cmd_gso_size_set =
4760         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4761                                 cmd_set, "set");
4762 cmdline_parse_token_string_t cmd_gso_size_keyword =
4763         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4764                                 cmd_keyword, "gso");
4765 cmdline_parse_token_string_t cmd_gso_size_segsz =
4766         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4767                                 cmd_segsz, "segsz");
4768 cmdline_parse_token_num_t cmd_gso_size_size =
4769         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4770                                 cmd_size, UINT16);
4771
4772 cmdline_parse_inst_t cmd_gso_size = {
4773         .f = cmd_gso_size_parsed,
4774         .data = NULL,
4775         .help_str = "set gso segsz <length>",
4776         .tokens = {
4777                 (void *)&cmd_gso_size_set,
4778                 (void *)&cmd_gso_size_keyword,
4779                 (void *)&cmd_gso_size_segsz,
4780                 (void *)&cmd_gso_size_size,
4781                 NULL,
4782         },
4783 };
4784
4785 /* *** SHOW GSO CONFIGURATION *** */
4786 struct cmd_gso_show_result {
4787         cmdline_fixed_string_t cmd_show;
4788         cmdline_fixed_string_t cmd_port;
4789         cmdline_fixed_string_t cmd_keyword;
4790         portid_t cmd_pid;
4791 };
4792
4793 static void
4794 cmd_gso_show_parsed(void *parsed_result,
4795                        __attribute__((unused)) struct cmdline *cl,
4796                        __attribute__((unused)) void *data)
4797 {
4798         struct cmd_gso_show_result *res = parsed_result;
4799
4800         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4801                 printf("invalid port id %u\n", res->cmd_pid);
4802                 return;
4803         }
4804         if (!strcmp(res->cmd_keyword, "gso")) {
4805                 if (gso_ports[res->cmd_pid].enable) {
4806                         printf("Max GSO'd packet size: %uB\n"
4807                                         "Supported GSO types: TCP/IPv4, "
4808                                         "UDP/IPv4, VxLAN with inner "
4809                                         "TCP/IPv4 packet, GRE with inner "
4810                                         "TCP/IPv4 packet\n",
4811                                         gso_max_segment_size);
4812                 } else
4813                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4814         }
4815 }
4816
4817 cmdline_parse_token_string_t cmd_gso_show_show =
4818 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4819                 cmd_show, "show");
4820 cmdline_parse_token_string_t cmd_gso_show_port =
4821 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4822                 cmd_port, "port");
4823 cmdline_parse_token_string_t cmd_gso_show_keyword =
4824         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4825                                 cmd_keyword, "gso");
4826 cmdline_parse_token_num_t cmd_gso_show_pid =
4827         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4828                                 cmd_pid, UINT16);
4829
4830 cmdline_parse_inst_t cmd_gso_show = {
4831         .f = cmd_gso_show_parsed,
4832         .data = NULL,
4833         .help_str = "show port <port_id> gso",
4834         .tokens = {
4835                 (void *)&cmd_gso_show_show,
4836                 (void *)&cmd_gso_show_port,
4837                 (void *)&cmd_gso_show_pid,
4838                 (void *)&cmd_gso_show_keyword,
4839                 NULL,
4840         },
4841 };
4842
4843 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4844 struct cmd_set_flush_rx {
4845         cmdline_fixed_string_t set;
4846         cmdline_fixed_string_t flush_rx;
4847         cmdline_fixed_string_t mode;
4848 };
4849
4850 static void
4851 cmd_set_flush_rx_parsed(void *parsed_result,
4852                 __attribute__((unused)) struct cmdline *cl,
4853                 __attribute__((unused)) void *data)
4854 {
4855         struct cmd_set_flush_rx *res = parsed_result;
4856         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4857 }
4858
4859 cmdline_parse_token_string_t cmd_setflushrx_set =
4860         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4861                         set, "set");
4862 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4863         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4864                         flush_rx, "flush_rx");
4865 cmdline_parse_token_string_t cmd_setflushrx_mode =
4866         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4867                         mode, "on#off");
4868
4869
4870 cmdline_parse_inst_t cmd_set_flush_rx = {
4871         .f = cmd_set_flush_rx_parsed,
4872         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4873         .data = NULL,
4874         .tokens = {
4875                 (void *)&cmd_setflushrx_set,
4876                 (void *)&cmd_setflushrx_flush_rx,
4877                 (void *)&cmd_setflushrx_mode,
4878                 NULL,
4879         },
4880 };
4881
4882 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4883 struct cmd_set_link_check {
4884         cmdline_fixed_string_t set;
4885         cmdline_fixed_string_t link_check;
4886         cmdline_fixed_string_t mode;
4887 };
4888
4889 static void
4890 cmd_set_link_check_parsed(void *parsed_result,
4891                 __attribute__((unused)) struct cmdline *cl,
4892                 __attribute__((unused)) void *data)
4893 {
4894         struct cmd_set_link_check *res = parsed_result;
4895         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4896 }
4897
4898 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4899         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4900                         set, "set");
4901 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4902         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4903                         link_check, "link_check");
4904 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4905         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4906                         mode, "on#off");
4907
4908
4909 cmdline_parse_inst_t cmd_set_link_check = {
4910         .f = cmd_set_link_check_parsed,
4911         .help_str = "set link_check on|off: Enable/Disable link status check "
4912                     "when starting/stopping a port",
4913         .data = NULL,
4914         .tokens = {
4915                 (void *)&cmd_setlinkcheck_set,
4916                 (void *)&cmd_setlinkcheck_link_check,
4917                 (void *)&cmd_setlinkcheck_mode,
4918                 NULL,
4919         },
4920 };
4921
4922 /* *** SET NIC BYPASS MODE *** */
4923 struct cmd_set_bypass_mode_result {
4924         cmdline_fixed_string_t set;
4925         cmdline_fixed_string_t bypass;
4926         cmdline_fixed_string_t mode;
4927         cmdline_fixed_string_t value;
4928         portid_t port_id;
4929 };
4930
4931 static void
4932 cmd_set_bypass_mode_parsed(void *parsed_result,
4933                 __attribute__((unused)) struct cmdline *cl,
4934                 __attribute__((unused)) void *data)
4935 {
4936         struct cmd_set_bypass_mode_result *res = parsed_result;
4937         portid_t port_id = res->port_id;
4938         int32_t rc = -EINVAL;
4939
4940 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4941         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4942
4943         if (!strcmp(res->value, "bypass"))
4944                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4945         else if (!strcmp(res->value, "isolate"))
4946                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4947         else
4948                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4949
4950         /* Set the bypass mode for the relevant port. */
4951         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4952 #endif
4953         if (rc != 0)
4954                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4955 }
4956
4957 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4958         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4959                         set, "set");
4960 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4961         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4962                         bypass, "bypass");
4963 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4964         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4965                         mode, "mode");
4966 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4967         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4968                         value, "normal#bypass#isolate");
4969 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4970         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4971                                 port_id, UINT16);
4972
4973 cmdline_parse_inst_t cmd_set_bypass_mode = {
4974         .f = cmd_set_bypass_mode_parsed,
4975         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4976                     "Set the NIC bypass mode for port_id",
4977         .data = NULL,
4978         .tokens = {
4979                 (void *)&cmd_setbypass_mode_set,
4980                 (void *)&cmd_setbypass_mode_bypass,
4981                 (void *)&cmd_setbypass_mode_mode,
4982                 (void *)&cmd_setbypass_mode_value,
4983                 (void *)&cmd_setbypass_mode_port,
4984                 NULL,
4985         },
4986 };
4987
4988 /* *** SET NIC BYPASS EVENT *** */
4989 struct cmd_set_bypass_event_result {
4990         cmdline_fixed_string_t set;
4991         cmdline_fixed_string_t bypass;
4992         cmdline_fixed_string_t event;
4993         cmdline_fixed_string_t event_value;
4994         cmdline_fixed_string_t mode;
4995         cmdline_fixed_string_t mode_value;
4996         portid_t port_id;
4997 };
4998
4999 static void
5000 cmd_set_bypass_event_parsed(void *parsed_result,
5001                 __attribute__((unused)) struct cmdline *cl,
5002                 __attribute__((unused)) void *data)
5003 {
5004         int32_t rc = -EINVAL;
5005         struct cmd_set_bypass_event_result *res = parsed_result;
5006         portid_t port_id = res->port_id;
5007
5008 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5009         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5010         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5011
5012         if (!strcmp(res->event_value, "timeout"))
5013                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5014         else if (!strcmp(res->event_value, "os_on"))
5015                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5016         else if (!strcmp(res->event_value, "os_off"))
5017                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5018         else if (!strcmp(res->event_value, "power_on"))
5019                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5020         else if (!strcmp(res->event_value, "power_off"))
5021                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5022         else
5023                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5024
5025         if (!strcmp(res->mode_value, "bypass"))
5026                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5027         else if (!strcmp(res->mode_value, "isolate"))
5028                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5029         else
5030                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5031
5032         /* Set the watchdog timeout. */
5033         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5034
5035                 rc = -EINVAL;
5036                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5037                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5038                                                            bypass_timeout);
5039                 }
5040                 if (rc != 0) {
5041                         printf("Failed to set timeout value %u "
5042                         "for port %d, errto code: %d.\n",
5043                         bypass_timeout, port_id, rc);
5044                 }
5045         }
5046
5047         /* Set the bypass event to transition to bypass mode. */
5048         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5049                                               bypass_mode);
5050 #endif
5051
5052         if (rc != 0)
5053                 printf("\t Failed to set bypass event for port = %d.\n",
5054                        port_id);
5055 }
5056
5057 cmdline_parse_token_string_t cmd_setbypass_event_set =
5058         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5059                         set, "set");
5060 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5061         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5062                         bypass, "bypass");
5063 cmdline_parse_token_string_t cmd_setbypass_event_event =
5064         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5065                         event, "event");
5066 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5067         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5068                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5069 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5070         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5071                         mode, "mode");
5072 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5073         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5074                         mode_value, "normal#bypass#isolate");
5075 cmdline_parse_token_num_t cmd_setbypass_event_port =
5076         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5077                                 port_id, UINT16);
5078
5079 cmdline_parse_inst_t cmd_set_bypass_event = {
5080         .f = cmd_set_bypass_event_parsed,
5081         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5082                 "power_off mode normal|bypass|isolate <port_id>: "
5083                 "Set the NIC bypass event mode for port_id",
5084         .data = NULL,
5085         .tokens = {
5086                 (void *)&cmd_setbypass_event_set,
5087                 (void *)&cmd_setbypass_event_bypass,
5088                 (void *)&cmd_setbypass_event_event,
5089                 (void *)&cmd_setbypass_event_event_value,
5090                 (void *)&cmd_setbypass_event_mode,
5091                 (void *)&cmd_setbypass_event_mode_value,
5092                 (void *)&cmd_setbypass_event_port,
5093                 NULL,
5094         },
5095 };
5096
5097
5098 /* *** SET NIC BYPASS TIMEOUT *** */
5099 struct cmd_set_bypass_timeout_result {
5100         cmdline_fixed_string_t set;
5101         cmdline_fixed_string_t bypass;
5102         cmdline_fixed_string_t timeout;
5103         cmdline_fixed_string_t value;
5104 };
5105
5106 static void
5107 cmd_set_bypass_timeout_parsed(void *parsed_result,
5108                 __attribute__((unused)) struct cmdline *cl,
5109                 __attribute__((unused)) void *data)
5110 {
5111         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5112
5113 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5114         if (!strcmp(res->value, "1.5"))
5115                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5116         else if (!strcmp(res->value, "2"))
5117                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5118         else if (!strcmp(res->value, "3"))
5119                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5120         else if (!strcmp(res->value, "4"))
5121                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5122         else if (!strcmp(res->value, "8"))
5123                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5124         else if (!strcmp(res->value, "16"))
5125                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5126         else if (!strcmp(res->value, "32"))
5127                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5128         else
5129                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5130 #endif
5131 }
5132
5133 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5134         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5135                         set, "set");
5136 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5137         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5138                         bypass, "bypass");
5139 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5140         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5141                         timeout, "timeout");
5142 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5143         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5144                         value, "0#1.5#2#3#4#8#16#32");
5145
5146 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5147         .f = cmd_set_bypass_timeout_parsed,
5148         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5149                 "Set the NIC bypass watchdog timeout in seconds",
5150         .data = NULL,
5151         .tokens = {
5152                 (void *)&cmd_setbypass_timeout_set,
5153                 (void *)&cmd_setbypass_timeout_bypass,
5154                 (void *)&cmd_setbypass_timeout_timeout,
5155                 (void *)&cmd_setbypass_timeout_value,
5156                 NULL,
5157         },
5158 };
5159
5160 /* *** SHOW NIC BYPASS MODE *** */
5161 struct cmd_show_bypass_config_result {
5162         cmdline_fixed_string_t show;
5163         cmdline_fixed_string_t bypass;
5164         cmdline_fixed_string_t config;
5165         portid_t port_id;
5166 };
5167
5168 static void
5169 cmd_show_bypass_config_parsed(void *parsed_result,
5170                 __attribute__((unused)) struct cmdline *cl,
5171                 __attribute__((unused)) void *data)
5172 {
5173         struct cmd_show_bypass_config_result *res = parsed_result;
5174         portid_t port_id = res->port_id;
5175         int rc = -EINVAL;
5176 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5177         uint32_t event_mode;
5178         uint32_t bypass_mode;
5179         uint32_t timeout = bypass_timeout;
5180         int i;
5181
5182         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5183                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5184         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5185                 {"UNKNOWN", "normal", "bypass", "isolate"};
5186         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5187                 "NONE",
5188                 "OS/board on",
5189                 "power supply on",
5190                 "OS/board off",
5191                 "power supply off",
5192                 "timeout"};
5193         int num_events = (sizeof events) / (sizeof events[0]);
5194
5195         /* Display the bypass mode.*/
5196         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5197                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5198                 return;
5199         }
5200         else {
5201                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5202                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5203
5204                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5205         }
5206
5207         /* Display the bypass timeout.*/
5208         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5209                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5210
5211         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5212
5213         /* Display the bypass events and associated modes. */
5214         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5215
5216                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5217                         printf("\tFailed to get bypass mode for event = %s\n",
5218                                 events[i]);
5219                 } else {
5220                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5221                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5222
5223                         printf("\tbypass event: %-16s = %s\n", events[i],
5224                                 modes[event_mode]);
5225                 }
5226         }
5227 #endif
5228         if (rc != 0)
5229                 printf("\tFailed to get bypass configuration for port = %d\n",
5230                        port_id);
5231 }
5232
5233 cmdline_parse_token_string_t cmd_showbypass_config_show =
5234         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5235                         show, "show");
5236 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5237         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5238                         bypass, "bypass");
5239 cmdline_parse_token_string_t cmd_showbypass_config_config =
5240         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5241                         config, "config");
5242 cmdline_parse_token_num_t cmd_showbypass_config_port =
5243         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5244                                 port_id, UINT16);
5245
5246 cmdline_parse_inst_t cmd_show_bypass_config = {
5247         .f = cmd_show_bypass_config_parsed,
5248         .help_str = "show bypass config <port_id>: "
5249                     "Show the NIC bypass config for port_id",
5250         .data = NULL,
5251         .tokens = {
5252                 (void *)&cmd_showbypass_config_show,
5253                 (void *)&cmd_showbypass_config_bypass,
5254                 (void *)&cmd_showbypass_config_config,
5255                 (void *)&cmd_showbypass_config_port,
5256                 NULL,
5257         },
5258 };
5259
5260 #ifdef RTE_LIBRTE_PMD_BOND
5261 /* *** SET BONDING MODE *** */
5262 struct cmd_set_bonding_mode_result {
5263         cmdline_fixed_string_t set;
5264         cmdline_fixed_string_t bonding;
5265         cmdline_fixed_string_t mode;
5266         uint8_t value;
5267         portid_t port_id;
5268 };
5269
5270 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5271                 __attribute__((unused))  struct cmdline *cl,
5272                 __attribute__((unused)) void *data)
5273 {
5274         struct cmd_set_bonding_mode_result *res = parsed_result;
5275         portid_t port_id = res->port_id;
5276
5277         /* Set the bonding mode for the relevant port. */
5278         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5279                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5280 }
5281
5282 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5283 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5284                 set, "set");
5285 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5286 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5287                 bonding, "bonding");
5288 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5289 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5290                 mode, "mode");
5291 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5292 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5293                 value, UINT8);
5294 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5295 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5296                 port_id, UINT16);
5297
5298 cmdline_parse_inst_t cmd_set_bonding_mode = {
5299                 .f = cmd_set_bonding_mode_parsed,
5300                 .help_str = "set bonding mode <mode_value> <port_id>: "
5301                         "Set the bonding mode for port_id",
5302                 .data = NULL,
5303                 .tokens = {
5304                                 (void *) &cmd_setbonding_mode_set,
5305                                 (void *) &cmd_setbonding_mode_bonding,
5306                                 (void *) &cmd_setbonding_mode_mode,
5307                                 (void *) &cmd_setbonding_mode_value,
5308                                 (void *) &cmd_setbonding_mode_port,
5309                                 NULL
5310                 }
5311 };
5312
5313 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5314 struct cmd_set_bonding_lacp_dedicated_queues_result {
5315         cmdline_fixed_string_t set;
5316         cmdline_fixed_string_t bonding;
5317         cmdline_fixed_string_t lacp;
5318         cmdline_fixed_string_t dedicated_queues;
5319         portid_t port_id;
5320         cmdline_fixed_string_t mode;
5321 };
5322
5323 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5324                 __attribute__((unused))  struct cmdline *cl,
5325                 __attribute__((unused)) void *data)
5326 {
5327         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5328         portid_t port_id = res->port_id;
5329         struct rte_port *port;
5330
5331         port = &ports[port_id];
5332
5333         /** Check if the port is not started **/
5334         if (port->port_status != RTE_PORT_STOPPED) {
5335                 printf("Please stop port %d first\n", port_id);
5336                 return;
5337         }
5338
5339         if (!strcmp(res->mode, "enable")) {
5340                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5341                         printf("Dedicate queues for LACP control packets"
5342                                         " enabled\n");
5343                 else
5344                         printf("Enabling dedicate queues for LACP control "
5345                                         "packets on port %d failed\n", port_id);
5346         } else if (!strcmp(res->mode, "disable")) {
5347                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5348                         printf("Dedicated queues for LACP control packets "
5349                                         "disabled\n");
5350                 else
5351                         printf("Disabling dedicated queues for LACP control "
5352                                         "traffic on port %d failed\n", port_id);
5353         }
5354 }
5355
5356 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5357 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5358                 set, "set");
5359 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5360 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5361                 bonding, "bonding");
5362 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5363 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5364                 lacp, "lacp");
5365 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5366 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5367                 dedicated_queues, "dedicated_queues");
5368 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5369 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5370                 port_id, UINT16);
5371 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5372 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5373                 mode, "enable#disable");
5374
5375 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5376                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5377                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5378                         "enable|disable: "
5379                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5380                 .data = NULL,
5381                 .tokens = {
5382                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5383                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5384                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5385                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5386                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5387                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5388                         NULL
5389                 }
5390 };
5391
5392 /* *** SET BALANCE XMIT POLICY *** */
5393 struct cmd_set_bonding_balance_xmit_policy_result {
5394         cmdline_fixed_string_t set;
5395         cmdline_fixed_string_t bonding;
5396         cmdline_fixed_string_t balance_xmit_policy;
5397         portid_t port_id;
5398         cmdline_fixed_string_t policy;
5399 };
5400
5401 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5402                 __attribute__((unused))  struct cmdline *cl,
5403                 __attribute__((unused)) void *data)
5404 {
5405         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5406         portid_t port_id = res->port_id;
5407         uint8_t policy;
5408
5409         if (!strcmp(res->policy, "l2")) {
5410                 policy = BALANCE_XMIT_POLICY_LAYER2;
5411         } else if (!strcmp(res->policy, "l23")) {
5412                 policy = BALANCE_XMIT_POLICY_LAYER23;
5413         } else if (!strcmp(res->policy, "l34")) {
5414                 policy = BALANCE_XMIT_POLICY_LAYER34;
5415         } else {
5416                 printf("\t Invalid xmit policy selection");
5417                 return;
5418         }
5419
5420         /* Set the bonding mode for the relevant port. */
5421         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5422                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5423                                 port_id);
5424         }
5425 }
5426
5427 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5428 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5429                 set, "set");
5430 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5431 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5432                 bonding, "bonding");
5433 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5434 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5435                 balance_xmit_policy, "balance_xmit_policy");
5436 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5437 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5438                 port_id, UINT16);
5439 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5440 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5441                 policy, "l2#l23#l34");
5442
5443 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5444                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5445                 .help_str = "set bonding balance_xmit_policy <port_id> "
5446                         "l2|l23|l34: "
5447                         "Set the bonding balance_xmit_policy for port_id",
5448                 .data = NULL,
5449                 .tokens = {
5450                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5451                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5452                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5453                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5454                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5455                                 NULL
5456                 }
5457 };
5458
5459 /* *** SHOW NIC BONDING CONFIGURATION *** */
5460 struct cmd_show_bonding_config_result {
5461         cmdline_fixed_string_t show;
5462         cmdline_fixed_string_t bonding;
5463         cmdline_fixed_string_t config;
5464         portid_t port_id;
5465 };
5466
5467 static void cmd_show_bonding_config_parsed(void *parsed_result,
5468                 __attribute__((unused))  struct cmdline *cl,
5469                 __attribute__((unused)) void *data)
5470 {
5471         struct cmd_show_bonding_config_result *res = parsed_result;
5472         int bonding_mode, agg_mode;
5473         portid_t slaves[RTE_MAX_ETHPORTS];
5474         int num_slaves, num_active_slaves;
5475         int primary_id;
5476         int i;
5477         portid_t port_id = res->port_id;
5478
5479         /* Display the bonding mode.*/
5480         bonding_mode = rte_eth_bond_mode_get(port_id);
5481         if (bonding_mode < 0) {
5482                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5483                 return;
5484         } else
5485                 printf("\tBonding mode: %d\n", bonding_mode);
5486
5487         if (bonding_mode == BONDING_MODE_BALANCE) {
5488                 int balance_xmit_policy;
5489
5490                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5491                 if (balance_xmit_policy < 0) {
5492                         printf("\tFailed to get balance xmit policy for port = %d\n",
5493                                         port_id);
5494                         return;
5495                 } else {
5496                         printf("\tBalance Xmit Policy: ");
5497
5498                         switch (balance_xmit_policy) {
5499                         case BALANCE_XMIT_POLICY_LAYER2:
5500                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5501                                 break;
5502                         case BALANCE_XMIT_POLICY_LAYER23:
5503                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5504                                 break;
5505                         case BALANCE_XMIT_POLICY_LAYER34:
5506                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5507                                 break;
5508                         }
5509                         printf("\n");
5510                 }
5511         }
5512
5513         if (bonding_mode == BONDING_MODE_8023AD) {
5514                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5515                 printf("\tIEEE802.3AD Aggregator Mode: ");
5516                 switch (agg_mode) {
5517                 case AGG_BANDWIDTH:
5518                         printf("bandwidth");
5519                         break;
5520                 case AGG_STABLE:
5521                         printf("stable");
5522                         break;
5523                 case AGG_COUNT:
5524                         printf("count");
5525                         break;
5526                 }
5527                 printf("\n");
5528         }
5529
5530         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5531
5532         if (num_slaves < 0) {
5533                 printf("\tFailed to get slave list for port = %d\n", port_id);
5534                 return;
5535         }
5536         if (num_slaves > 0) {
5537                 printf("\tSlaves (%d): [", num_slaves);
5538                 for (i = 0; i < num_slaves - 1; i++)
5539                         printf("%d ", slaves[i]);
5540
5541                 printf("%d]\n", slaves[num_slaves - 1]);
5542         } else {
5543                 printf("\tSlaves: []\n");
5544
5545         }
5546
5547         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5548                         RTE_MAX_ETHPORTS);
5549
5550         if (num_active_slaves < 0) {
5551                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5552                 return;
5553         }
5554         if (num_active_slaves > 0) {
5555                 printf("\tActive Slaves (%d): [", num_active_slaves);
5556                 for (i = 0; i < num_active_slaves - 1; i++)
5557                         printf("%d ", slaves[i]);
5558
5559                 printf("%d]\n", slaves[num_active_slaves - 1]);
5560
5561         } else {
5562                 printf("\tActive Slaves: []\n");
5563
5564         }
5565
5566         primary_id = rte_eth_bond_primary_get(port_id);
5567         if (primary_id < 0) {
5568                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5569                 return;
5570         } else
5571                 printf("\tPrimary: [%d]\n", primary_id);
5572
5573 }
5574
5575 cmdline_parse_token_string_t cmd_showbonding_config_show =
5576 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5577                 show, "show");
5578 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5579 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5580                 bonding, "bonding");
5581 cmdline_parse_token_string_t cmd_showbonding_config_config =
5582 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5583                 config, "config");
5584 cmdline_parse_token_num_t cmd_showbonding_config_port =
5585 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5586                 port_id, UINT16);
5587
5588 cmdline_parse_inst_t cmd_show_bonding_config = {
5589                 .f = cmd_show_bonding_config_parsed,
5590                 .help_str = "show bonding config <port_id>: "
5591                         "Show the bonding config for port_id",
5592                 .data = NULL,
5593                 .tokens = {
5594                                 (void *)&cmd_showbonding_config_show,
5595                                 (void *)&cmd_showbonding_config_bonding,
5596                                 (void *)&cmd_showbonding_config_config,
5597                                 (void *)&cmd_showbonding_config_port,
5598                                 NULL
5599                 }
5600 };
5601
5602 /* *** SET BONDING PRIMARY *** */
5603 struct cmd_set_bonding_primary_result {
5604         cmdline_fixed_string_t set;
5605         cmdline_fixed_string_t bonding;
5606         cmdline_fixed_string_t primary;
5607         portid_t slave_id;
5608         portid_t port_id;
5609 };
5610
5611 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5612                 __attribute__((unused))  struct cmdline *cl,
5613                 __attribute__((unused)) void *data)
5614 {
5615         struct cmd_set_bonding_primary_result *res = parsed_result;
5616         portid_t master_port_id = res->port_id;
5617         portid_t slave_port_id = res->slave_id;
5618
5619         /* Set the primary slave for a bonded device. */
5620         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5621                 printf("\t Failed to set primary slave for port = %d.\n",
5622                                 master_port_id);
5623                 return;
5624         }
5625         init_port_config();
5626 }
5627
5628 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5629 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5630                 set, "set");
5631 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5632 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5633                 bonding, "bonding");
5634 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5635 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5636                 primary, "primary");
5637 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5638 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5639                 slave_id, UINT16);
5640 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5641 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5642                 port_id, UINT16);
5643
5644 cmdline_parse_inst_t cmd_set_bonding_primary = {
5645                 .f = cmd_set_bonding_primary_parsed,
5646                 .help_str = "set bonding primary <slave_id> <port_id>: "
5647                         "Set the primary slave for port_id",
5648                 .data = NULL,
5649                 .tokens = {
5650                                 (void *)&cmd_setbonding_primary_set,
5651                                 (void *)&cmd_setbonding_primary_bonding,
5652                                 (void *)&cmd_setbonding_primary_primary,
5653                                 (void *)&cmd_setbonding_primary_slave,
5654                                 (void *)&cmd_setbonding_primary_port,
5655                                 NULL
5656                 }
5657 };
5658
5659 /* *** ADD SLAVE *** */
5660 struct cmd_add_bonding_slave_result {
5661         cmdline_fixed_string_t add;
5662         cmdline_fixed_string_t bonding;
5663         cmdline_fixed_string_t slave;
5664         portid_t slave_id;
5665         portid_t port_id;
5666 };
5667
5668 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5669                 __attribute__((unused))  struct cmdline *cl,
5670                 __attribute__((unused)) void *data)
5671 {
5672         struct cmd_add_bonding_slave_result *res = parsed_result;
5673         portid_t master_port_id = res->port_id;
5674         portid_t slave_port_id = res->slave_id;
5675
5676         /* add the slave for a bonded device. */
5677         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5678                 printf("\t Failed to add slave %d to master port = %d.\n",
5679                                 slave_port_id, master_port_id);
5680                 return;
5681         }
5682         init_port_config();
5683         set_port_slave_flag(slave_port_id);
5684 }
5685
5686 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5687 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5688                 add, "add");
5689 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5690 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5691                 bonding, "bonding");
5692 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5693 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5694                 slave, "slave");
5695 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5696 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5697                 slave_id, UINT16);
5698 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5699 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5700                 port_id, UINT16);
5701
5702 cmdline_parse_inst_t cmd_add_bonding_slave = {
5703                 .f = cmd_add_bonding_slave_parsed,
5704                 .help_str = "add bonding slave <slave_id> <port_id>: "
5705                         "Add a slave device to a bonded device",
5706                 .data = NULL,
5707                 .tokens = {
5708                                 (void *)&cmd_addbonding_slave_add,
5709                                 (void *)&cmd_addbonding_slave_bonding,
5710                                 (void *)&cmd_addbonding_slave_slave,
5711                                 (void *)&cmd_addbonding_slave_slaveid,
5712                                 (void *)&cmd_addbonding_slave_port,
5713                                 NULL
5714                 }
5715 };
5716
5717 /* *** REMOVE SLAVE *** */
5718 struct cmd_remove_bonding_slave_result {
5719         cmdline_fixed_string_t remove;
5720         cmdline_fixed_string_t bonding;
5721         cmdline_fixed_string_t slave;
5722         portid_t slave_id;
5723         portid_t port_id;
5724 };
5725
5726 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5727                 __attribute__((unused))  struct cmdline *cl,
5728                 __attribute__((unused)) void *data)
5729 {
5730         struct cmd_remove_bonding_slave_result *res = parsed_result;
5731         portid_t master_port_id = res->port_id;
5732         portid_t slave_port_id = res->slave_id;
5733
5734         /* remove the slave from a bonded device. */
5735         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5736                 printf("\t Failed to remove slave %d from master port = %d.\n",
5737                                 slave_port_id, master_port_id);
5738                 return;
5739         }
5740         init_port_config();
5741         clear_port_slave_flag(slave_port_id);
5742 }
5743
5744 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5745                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5746                                 remove, "remove");
5747 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5748                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5749                                 bonding, "bonding");
5750 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5751                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5752                                 slave, "slave");
5753 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5754                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5755                                 slave_id, UINT16);
5756 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5757                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5758                                 port_id, UINT16);
5759
5760 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5761                 .f = cmd_remove_bonding_slave_parsed,
5762                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5763                         "Remove a slave device from a bonded device",
5764                 .data = NULL,
5765                 .tokens = {
5766                                 (void *)&cmd_removebonding_slave_remove,
5767                                 (void *)&cmd_removebonding_slave_bonding,
5768                                 (void *)&cmd_removebonding_slave_slave,
5769                                 (void *)&cmd_removebonding_slave_slaveid,
5770                                 (void *)&cmd_removebonding_slave_port,
5771                                 NULL
5772                 }
5773 };
5774
5775 /* *** CREATE BONDED DEVICE *** */
5776 struct cmd_create_bonded_device_result {
5777         cmdline_fixed_string_t create;
5778         cmdline_fixed_string_t bonded;
5779         cmdline_fixed_string_t device;
5780         uint8_t mode;
5781         uint8_t socket;
5782 };
5783
5784 static int bond_dev_num = 0;
5785
5786 static void cmd_create_bonded_device_parsed(void *parsed_result,
5787                 __attribute__((unused))  struct cmdline *cl,
5788                 __attribute__((unused)) void *data)
5789 {
5790         struct cmd_create_bonded_device_result *res = parsed_result;
5791         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5792         int port_id;
5793
5794         if (test_done == 0) {
5795                 printf("Please stop forwarding first\n");
5796                 return;
5797         }
5798
5799         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5800                         bond_dev_num++);
5801
5802         /* Create a new bonded device. */
5803         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5804         if (port_id < 0) {
5805                 printf("\t Failed to create bonded device.\n");
5806                 return;
5807         } else {
5808                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5809                                 port_id);
5810
5811                 /* Update number of ports */
5812                 nb_ports = rte_eth_dev_count_avail();
5813                 reconfig(port_id, res->socket);
5814                 rte_eth_promiscuous_enable(port_id);
5815         }
5816
5817 }
5818
5819 cmdline_parse_token_string_t cmd_createbonded_device_create =
5820                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5821                                 create, "create");
5822 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5823                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5824                                 bonded, "bonded");
5825 cmdline_parse_token_string_t cmd_createbonded_device_device =
5826                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5827                                 device, "device");
5828 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5829                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5830                                 mode, UINT8);
5831 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5832                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5833                                 socket, UINT8);
5834
5835 cmdline_parse_inst_t cmd_create_bonded_device = {
5836                 .f = cmd_create_bonded_device_parsed,
5837                 .help_str = "create bonded device <mode> <socket>: "
5838                         "Create a new bonded device with specific bonding mode and socket",
5839                 .data = NULL,
5840                 .tokens = {
5841                                 (void *)&cmd_createbonded_device_create,
5842                                 (void *)&cmd_createbonded_device_bonded,
5843                                 (void *)&cmd_createbonded_device_device,
5844                                 (void *)&cmd_createbonded_device_mode,
5845                                 (void *)&cmd_createbonded_device_socket,
5846                                 NULL
5847                 }
5848 };
5849
5850 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5851 struct cmd_set_bond_mac_addr_result {
5852         cmdline_fixed_string_t set;
5853         cmdline_fixed_string_t bonding;
5854         cmdline_fixed_string_t mac_addr;
5855         uint16_t port_num;
5856         struct ether_addr address;
5857 };
5858
5859 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5860                 __attribute__((unused))  struct cmdline *cl,
5861                 __attribute__((unused)) void *data)
5862 {
5863         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5864         int ret;
5865
5866         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5867                 return;
5868
5869         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5870
5871         /* check the return value and print it if is < 0 */
5872         if (ret < 0)
5873                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5874 }
5875
5876 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5877                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5878 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5879                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5880                                 "bonding");
5881 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5882                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5883                                 "mac_addr");
5884 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5885                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5886                                 port_num, UINT16);
5887 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5888                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5889
5890 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5891                 .f = cmd_set_bond_mac_addr_parsed,
5892                 .data = (void *) 0,
5893                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5894                 .tokens = {
5895                                 (void *)&cmd_set_bond_mac_addr_set,
5896                                 (void *)&cmd_set_bond_mac_addr_bonding,
5897                                 (void *)&cmd_set_bond_mac_addr_mac,
5898                                 (void *)&cmd_set_bond_mac_addr_portnum,
5899                                 (void *)&cmd_set_bond_mac_addr_addr,
5900                                 NULL
5901                 }
5902 };
5903
5904
5905 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5906 struct cmd_set_bond_mon_period_result {
5907         cmdline_fixed_string_t set;
5908         cmdline_fixed_string_t bonding;
5909         cmdline_fixed_string_t mon_period;
5910         uint16_t port_num;
5911         uint32_t period_ms;
5912 };
5913
5914 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5915                 __attribute__((unused))  struct cmdline *cl,
5916                 __attribute__((unused)) void *data)
5917 {
5918         struct cmd_set_bond_mon_period_result *res = parsed_result;
5919         int ret;
5920
5921         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5922
5923         /* check the return value and print it if is < 0 */
5924         if (ret < 0)
5925                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5926 }
5927
5928 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5929                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5930                                 set, "set");
5931 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5932                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5933                                 bonding, "bonding");
5934 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5935                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5936                                 mon_period,     "mon_period");
5937 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5938                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5939                                 port_num, UINT16);
5940 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5941                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5942                                 period_ms, UINT32);
5943
5944 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5945                 .f = cmd_set_bond_mon_period_parsed,
5946                 .data = (void *) 0,
5947                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5948                 .tokens = {
5949                                 (void *)&cmd_set_bond_mon_period_set,
5950                                 (void *)&cmd_set_bond_mon_period_bonding,
5951                                 (void *)&cmd_set_bond_mon_period_mon_period,
5952                                 (void *)&cmd_set_bond_mon_period_portnum,
5953                                 (void *)&cmd_set_bond_mon_period_period_ms,
5954                                 NULL
5955                 }
5956 };
5957
5958
5959
5960 struct cmd_set_bonding_agg_mode_policy_result {
5961         cmdline_fixed_string_t set;
5962         cmdline_fixed_string_t bonding;
5963         cmdline_fixed_string_t agg_mode;
5964         uint16_t port_num;
5965         cmdline_fixed_string_t policy;
5966 };
5967
5968
5969 static void
5970 cmd_set_bonding_agg_mode(void *parsed_result,
5971                 __attribute__((unused)) struct cmdline *cl,
5972                 __attribute__((unused)) void *data)
5973 {
5974         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5975         uint8_t policy = AGG_BANDWIDTH;
5976
5977         if (!strcmp(res->policy, "bandwidth"))
5978                 policy = AGG_BANDWIDTH;
5979         else if (!strcmp(res->policy, "stable"))
5980                 policy = AGG_STABLE;
5981         else if (!strcmp(res->policy, "count"))
5982                 policy = AGG_COUNT;
5983
5984         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5985 }
5986
5987
5988 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5989         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5990                                 set, "set");
5991 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5992         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5993                                 bonding, "bonding");
5994
5995 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5996         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5997                                 agg_mode, "agg_mode");
5998
5999 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6000         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6001                                 port_num, UINT16);
6002
6003 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6004         TOKEN_STRING_INITIALIZER(
6005                         struct cmd_set_bonding_balance_xmit_policy_result,
6006                 policy, "stable#bandwidth#count");
6007
6008 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6009         .f = cmd_set_bonding_agg_mode,
6010         .data = (void *) 0,
6011         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6012         .tokens = {
6013                         (void *)&cmd_set_bonding_agg_mode_set,
6014                         (void *)&cmd_set_bonding_agg_mode_bonding,
6015                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6016                         (void *)&cmd_set_bonding_agg_mode_portnum,
6017                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6018                         NULL
6019                 }
6020 };
6021
6022
6023 #endif /* RTE_LIBRTE_PMD_BOND */
6024
6025 /* *** SET FORWARDING MODE *** */
6026 struct cmd_set_fwd_mode_result {
6027         cmdline_fixed_string_t set;
6028         cmdline_fixed_string_t fwd;
6029         cmdline_fixed_string_t mode;
6030 };
6031
6032 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6033                                     __attribute__((unused)) struct cmdline *cl,
6034                                     __attribute__((unused)) void *data)
6035 {
6036         struct cmd_set_fwd_mode_result *res = parsed_result;
6037
6038         retry_enabled = 0;
6039         set_pkt_forwarding_mode(res->mode);
6040 }
6041
6042 cmdline_parse_token_string_t cmd_setfwd_set =
6043         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6044 cmdline_parse_token_string_t cmd_setfwd_fwd =
6045         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6046 cmdline_parse_token_string_t cmd_setfwd_mode =
6047         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6048                 "" /* defined at init */);
6049
6050 cmdline_parse_inst_t cmd_set_fwd_mode = {
6051         .f = cmd_set_fwd_mode_parsed,
6052         .data = NULL,
6053         .help_str = NULL, /* defined at init */
6054         .tokens = {
6055                 (void *)&cmd_setfwd_set,
6056                 (void *)&cmd_setfwd_fwd,
6057                 (void *)&cmd_setfwd_mode,
6058                 NULL,
6059         },
6060 };
6061
6062 static void cmd_set_fwd_mode_init(void)
6063 {
6064         char *modes, *c;
6065         static char token[128];
6066         static char help[256];
6067         cmdline_parse_token_string_t *token_struct;
6068
6069         modes = list_pkt_forwarding_modes();
6070         snprintf(help, sizeof(help), "set fwd %s: "
6071                 "Set packet forwarding mode", modes);
6072         cmd_set_fwd_mode.help_str = help;
6073
6074         /* string token separator is # */
6075         for (c = token; *modes != '\0'; modes++)
6076                 if (*modes == '|')
6077                         *c++ = '#';
6078                 else
6079                         *c++ = *modes;
6080         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6081         token_struct->string_data.str = token;
6082 }
6083
6084 /* *** SET RETRY FORWARDING MODE *** */
6085 struct cmd_set_fwd_retry_mode_result {
6086         cmdline_fixed_string_t set;
6087         cmdline_fixed_string_t fwd;
6088         cmdline_fixed_string_t mode;
6089         cmdline_fixed_string_t retry;
6090 };
6091
6092 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6093                             __attribute__((unused)) struct cmdline *cl,
6094                             __attribute__((unused)) void *data)
6095 {
6096         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6097
6098         retry_enabled = 1;
6099         set_pkt_forwarding_mode(res->mode);
6100 }
6101
6102 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6103         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6104                         set, "set");
6105 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6106         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6107                         fwd, "fwd");
6108 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6109         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6110                         mode,
6111                 "" /* defined at init */);
6112 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6113         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6114                         retry, "retry");
6115
6116 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6117         .f = cmd_set_fwd_retry_mode_parsed,
6118         .data = NULL,
6119         .help_str = NULL, /* defined at init */
6120         .tokens = {
6121                 (void *)&cmd_setfwd_retry_set,
6122                 (void *)&cmd_setfwd_retry_fwd,
6123                 (void *)&cmd_setfwd_retry_mode,
6124                 (void *)&cmd_setfwd_retry_retry,
6125                 NULL,
6126         },
6127 };
6128
6129 static void cmd_set_fwd_retry_mode_init(void)
6130 {
6131         char *modes, *c;
6132         static char token[128];
6133         static char help[256];
6134         cmdline_parse_token_string_t *token_struct;
6135
6136         modes = list_pkt_forwarding_retry_modes();
6137         snprintf(help, sizeof(help), "set fwd %s retry: "
6138                 "Set packet forwarding mode with retry", modes);
6139         cmd_set_fwd_retry_mode.help_str = help;
6140
6141         /* string token separator is # */
6142         for (c = token; *modes != '\0'; modes++)
6143                 if (*modes == '|')
6144                         *c++ = '#';
6145                 else
6146                         *c++ = *modes;
6147         token_struct = (cmdline_parse_token_string_t *)
6148                 cmd_set_fwd_retry_mode.tokens[2];
6149         token_struct->string_data.str = token;
6150 }
6151
6152 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6153 struct cmd_set_burst_tx_retry_result {
6154         cmdline_fixed_string_t set;
6155         cmdline_fixed_string_t burst;
6156         cmdline_fixed_string_t tx;
6157         cmdline_fixed_string_t delay;
6158         uint32_t time;
6159         cmdline_fixed_string_t retry;
6160         uint32_t retry_num;
6161 };
6162
6163 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6164                                         __attribute__((unused)) struct cmdline *cl,
6165                                         __attribute__((unused)) void *data)
6166 {
6167         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6168
6169         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6170                 && !strcmp(res->tx, "tx")) {
6171                 if (!strcmp(res->delay, "delay"))
6172                         burst_tx_delay_time = res->time;
6173                 if (!strcmp(res->retry, "retry"))
6174                         burst_tx_retry_num = res->retry_num;
6175         }
6176
6177 }
6178
6179 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6180         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6181 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6182         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6183                                  "burst");
6184 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6185         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6186 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6187         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6188 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6189         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6190 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6191         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6192 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6193         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6194
6195 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6196         .f = cmd_set_burst_tx_retry_parsed,
6197         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6198         .tokens = {
6199                 (void *)&cmd_set_burst_tx_retry_set,
6200                 (void *)&cmd_set_burst_tx_retry_burst,
6201                 (void *)&cmd_set_burst_tx_retry_tx,
6202                 (void *)&cmd_set_burst_tx_retry_delay,
6203                 (void *)&cmd_set_burst_tx_retry_time,
6204                 (void *)&cmd_set_burst_tx_retry_retry,
6205                 (void *)&cmd_set_burst_tx_retry_retry_num,
6206                 NULL,
6207         },
6208 };
6209
6210 /* *** SET PROMISC MODE *** */
6211 struct cmd_set_promisc_mode_result {
6212         cmdline_fixed_string_t set;
6213         cmdline_fixed_string_t promisc;
6214         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6215         uint16_t port_num;               /* valid if "allports" argument == 0 */
6216         cmdline_fixed_string_t mode;
6217 };
6218
6219 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6220                                         __attribute__((unused)) struct cmdline *cl,
6221                                         void *allports)
6222 {
6223         struct cmd_set_promisc_mode_result *res = parsed_result;
6224         int enable;
6225         portid_t i;
6226
6227         if (!strcmp(res->mode, "on"))
6228                 enable = 1;
6229         else
6230                 enable = 0;
6231
6232         /* all ports */
6233         if (allports) {
6234                 RTE_ETH_FOREACH_DEV(i) {
6235                         if (enable)
6236                                 rte_eth_promiscuous_enable(i);
6237                         else
6238                                 rte_eth_promiscuous_disable(i);
6239                 }
6240         }
6241         else {
6242                 if (enable)
6243                         rte_eth_promiscuous_enable(res->port_num);
6244                 else
6245                         rte_eth_promiscuous_disable(res->port_num);
6246         }
6247 }
6248
6249 cmdline_parse_token_string_t cmd_setpromisc_set =
6250         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6251 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6252         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6253                                  "promisc");
6254 cmdline_parse_token_string_t cmd_setpromisc_portall =
6255         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6256                                  "all");
6257 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6258         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6259                               UINT16);
6260 cmdline_parse_token_string_t cmd_setpromisc_mode =
6261         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6262                                  "on#off");
6263
6264 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6265         .f = cmd_set_promisc_mode_parsed,
6266         .data = (void *)1,
6267         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6268         .tokens = {
6269                 (void *)&cmd_setpromisc_set,
6270                 (void *)&cmd_setpromisc_promisc,
6271                 (void *)&cmd_setpromisc_portall,
6272                 (void *)&cmd_setpromisc_mode,
6273                 NULL,
6274         },
6275 };
6276
6277 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6278         .f = cmd_set_promisc_mode_parsed,
6279         .data = (void *)0,
6280         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6281         .tokens = {
6282                 (void *)&cmd_setpromisc_set,
6283                 (void *)&cmd_setpromisc_promisc,
6284                 (void *)&cmd_setpromisc_portnum,
6285                 (void *)&cmd_setpromisc_mode,
6286                 NULL,
6287         },
6288 };
6289
6290 /* *** SET ALLMULTI MODE *** */
6291 struct cmd_set_allmulti_mode_result {
6292         cmdline_fixed_string_t set;
6293         cmdline_fixed_string_t allmulti;
6294         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6295         uint16_t port_num;               /* valid if "allports" argument == 0 */
6296         cmdline_fixed_string_t mode;
6297 };
6298
6299 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6300                                         __attribute__((unused)) struct cmdline *cl,
6301                                         void *allports)
6302 {
6303         struct cmd_set_allmulti_mode_result *res = parsed_result;
6304         int enable;
6305         portid_t i;
6306
6307         if (!strcmp(res->mode, "on"))
6308                 enable = 1;
6309         else
6310                 enable = 0;
6311
6312         /* all ports */
6313         if (allports) {
6314                 RTE_ETH_FOREACH_DEV(i) {
6315                         if (enable)
6316                                 rte_eth_allmulticast_enable(i);
6317                         else
6318                                 rte_eth_allmulticast_disable(i);
6319                 }
6320         }
6321         else {
6322                 if (enable)
6323                         rte_eth_allmulticast_enable(res->port_num);
6324                 else
6325                         rte_eth_allmulticast_disable(res->port_num);
6326         }
6327 }
6328
6329 cmdline_parse_token_string_t cmd_setallmulti_set =
6330         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6331 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6332         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6333                                  "allmulti");
6334 cmdline_parse_token_string_t cmd_setallmulti_portall =
6335         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6336                                  "all");
6337 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6338         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6339                               UINT16);
6340 cmdline_parse_token_string_t cmd_setallmulti_mode =
6341         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6342                                  "on#off");
6343
6344 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6345         .f = cmd_set_allmulti_mode_parsed,
6346         .data = (void *)1,
6347         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6348         .tokens = {
6349                 (void *)&cmd_setallmulti_set,
6350                 (void *)&cmd_setallmulti_allmulti,
6351                 (void *)&cmd_setallmulti_portall,
6352                 (void *)&cmd_setallmulti_mode,
6353                 NULL,
6354         },
6355 };
6356
6357 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6358         .f = cmd_set_allmulti_mode_parsed,
6359         .data = (void *)0,
6360         .help_str = "set allmulti <port_id> on|off: "
6361                 "Set allmulti mode on port_id",
6362         .tokens = {
6363                 (void *)&cmd_setallmulti_set,
6364                 (void *)&cmd_setallmulti_allmulti,
6365                 (void *)&cmd_setallmulti_portnum,
6366                 (void *)&cmd_setallmulti_mode,
6367                 NULL,
6368         },
6369 };
6370
6371 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6372 struct cmd_link_flow_ctrl_set_result {
6373         cmdline_fixed_string_t set;
6374         cmdline_fixed_string_t flow_ctrl;
6375         cmdline_fixed_string_t rx;
6376         cmdline_fixed_string_t rx_lfc_mode;
6377         cmdline_fixed_string_t tx;
6378         cmdline_fixed_string_t tx_lfc_mode;
6379         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6380         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6381         cmdline_fixed_string_t autoneg_str;
6382         cmdline_fixed_string_t autoneg;
6383         cmdline_fixed_string_t hw_str;
6384         uint32_t high_water;
6385         cmdline_fixed_string_t lw_str;
6386         uint32_t low_water;
6387         cmdline_fixed_string_t pt_str;
6388         uint16_t pause_time;
6389         cmdline_fixed_string_t xon_str;
6390         uint16_t send_xon;
6391         portid_t port_id;
6392 };
6393
6394 cmdline_parse_token_string_t cmd_lfc_set_set =
6395         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6396                                 set, "set");
6397 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6398         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6399                                 flow_ctrl, "flow_ctrl");
6400 cmdline_parse_token_string_t cmd_lfc_set_rx =
6401         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6402                                 rx, "rx");
6403 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6404         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6405                                 rx_lfc_mode, "on#off");
6406 cmdline_parse_token_string_t cmd_lfc_set_tx =
6407         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6408                                 tx, "tx");
6409 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6410         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6411                                 tx_lfc_mode, "on#off");
6412 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6413         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6414                                 hw_str, "high_water");
6415 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6416         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6417                                 high_water, UINT32);
6418 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6419         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6420                                 lw_str, "low_water");
6421 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6422         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6423                                 low_water, UINT32);
6424 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6425         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6426                                 pt_str, "pause_time");
6427 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6428         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6429                                 pause_time, UINT16);
6430 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6431         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6432                                 xon_str, "send_xon");
6433 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6434         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6435                                 send_xon, UINT16);
6436 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6437         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6438                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6439 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6440         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6441                                 mac_ctrl_frame_fwd_mode, "on#off");
6442 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6443         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6444                                 autoneg_str, "autoneg");
6445 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6446         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6447                                 autoneg, "on#off");
6448 cmdline_parse_token_num_t cmd_lfc_set_portid =
6449         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6450                                 port_id, UINT16);
6451
6452 /* forward declaration */
6453 static void
6454 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6455                               void *data);
6456
6457 cmdline_parse_inst_t cmd_link_flow_control_set = {
6458         .f = cmd_link_flow_ctrl_set_parsed,
6459         .data = NULL,
6460         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6461                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6462                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6463         .tokens = {
6464                 (void *)&cmd_lfc_set_set,
6465                 (void *)&cmd_lfc_set_flow_ctrl,
6466                 (void *)&cmd_lfc_set_rx,
6467                 (void *)&cmd_lfc_set_rx_mode,
6468                 (void *)&cmd_lfc_set_tx,
6469                 (void *)&cmd_lfc_set_tx_mode,
6470                 (void *)&cmd_lfc_set_high_water,
6471                 (void *)&cmd_lfc_set_low_water,
6472                 (void *)&cmd_lfc_set_pause_time,
6473                 (void *)&cmd_lfc_set_send_xon,
6474                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6475                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6476                 (void *)&cmd_lfc_set_autoneg_str,
6477                 (void *)&cmd_lfc_set_autoneg,
6478                 (void *)&cmd_lfc_set_portid,
6479                 NULL,
6480         },
6481 };
6482
6483 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6484         .f = cmd_link_flow_ctrl_set_parsed,
6485         .data = (void *)&cmd_link_flow_control_set_rx,
6486         .help_str = "set flow_ctrl rx on|off <port_id>: "
6487                 "Change rx flow control parameter",
6488         .tokens = {
6489                 (void *)&cmd_lfc_set_set,
6490                 (void *)&cmd_lfc_set_flow_ctrl,
6491                 (void *)&cmd_lfc_set_rx,
6492                 (void *)&cmd_lfc_set_rx_mode,
6493                 (void *)&cmd_lfc_set_portid,
6494                 NULL,
6495         },
6496 };
6497
6498 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6499         .f = cmd_link_flow_ctrl_set_parsed,
6500         .data = (void *)&cmd_link_flow_control_set_tx,
6501         .help_str = "set flow_ctrl tx on|off <port_id>: "
6502                 "Change tx flow control parameter",
6503         .tokens = {
6504                 (void *)&cmd_lfc_set_set,
6505                 (void *)&cmd_lfc_set_flow_ctrl,
6506                 (void *)&cmd_lfc_set_tx,
6507                 (void *)&cmd_lfc_set_tx_mode,
6508                 (void *)&cmd_lfc_set_portid,
6509                 NULL,
6510         },
6511 };
6512
6513 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6514         .f = cmd_link_flow_ctrl_set_parsed,
6515         .data = (void *)&cmd_link_flow_control_set_hw,
6516         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6517                 "Change high water flow control parameter",
6518         .tokens = {
6519                 (void *)&cmd_lfc_set_set,
6520                 (void *)&cmd_lfc_set_flow_ctrl,
6521                 (void *)&cmd_lfc_set_high_water_str,
6522                 (void *)&cmd_lfc_set_high_water,
6523                 (void *)&cmd_lfc_set_portid,
6524                 NULL,
6525         },
6526 };
6527
6528 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6529         .f = cmd_link_flow_ctrl_set_parsed,
6530         .data = (void *)&cmd_link_flow_control_set_lw,
6531         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6532                 "Change low water flow control parameter",
6533         .tokens = {
6534                 (void *)&cmd_lfc_set_set,
6535                 (void *)&cmd_lfc_set_flow_ctrl,
6536                 (void *)&cmd_lfc_set_low_water_str,
6537                 (void *)&cmd_lfc_set_low_water,
6538                 (void *)&cmd_lfc_set_portid,
6539                 NULL,
6540         },
6541 };
6542
6543 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6544         .f = cmd_link_flow_ctrl_set_parsed,
6545         .data = (void *)&cmd_link_flow_control_set_pt,
6546         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6547                 "Change pause time flow control parameter",
6548         .tokens = {
6549                 (void *)&cmd_lfc_set_set,
6550                 (void *)&cmd_lfc_set_flow_ctrl,
6551                 (void *)&cmd_lfc_set_pause_time_str,
6552                 (void *)&cmd_lfc_set_pause_time,
6553                 (void *)&cmd_lfc_set_portid,
6554                 NULL,
6555         },
6556 };
6557
6558 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6559         .f = cmd_link_flow_ctrl_set_parsed,
6560         .data = (void *)&cmd_link_flow_control_set_xon,
6561         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6562                 "Change send_xon flow control parameter",
6563         .tokens = {
6564                 (void *)&cmd_lfc_set_set,
6565                 (void *)&cmd_lfc_set_flow_ctrl,
6566                 (void *)&cmd_lfc_set_send_xon_str,
6567                 (void *)&cmd_lfc_set_send_xon,
6568                 (void *)&cmd_lfc_set_portid,
6569                 NULL,
6570         },
6571 };
6572
6573 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6574         .f = cmd_link_flow_ctrl_set_parsed,
6575         .data = (void *)&cmd_link_flow_control_set_macfwd,
6576         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6577                 "Change mac ctrl fwd flow control parameter",
6578         .tokens = {
6579                 (void *)&cmd_lfc_set_set,
6580                 (void *)&cmd_lfc_set_flow_ctrl,
6581                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6582                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6583                 (void *)&cmd_lfc_set_portid,
6584                 NULL,
6585         },
6586 };
6587
6588 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6589         .f = cmd_link_flow_ctrl_set_parsed,
6590         .data = (void *)&cmd_link_flow_control_set_autoneg,
6591         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6592                 "Change autoneg flow control parameter",
6593         .tokens = {
6594                 (void *)&cmd_lfc_set_set,
6595                 (void *)&cmd_lfc_set_flow_ctrl,
6596                 (void *)&cmd_lfc_set_autoneg_str,
6597                 (void *)&cmd_lfc_set_autoneg,
6598                 (void *)&cmd_lfc_set_portid,
6599                 NULL,
6600         },
6601 };
6602
6603 static void
6604 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6605                               __attribute__((unused)) struct cmdline *cl,
6606                               void *data)
6607 {
6608         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6609         cmdline_parse_inst_t *cmd = data;
6610         struct rte_eth_fc_conf fc_conf;
6611         int rx_fc_en = 0;
6612         int tx_fc_en = 0;
6613         int ret;
6614
6615         /*
6616          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6617          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6618          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6619          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6620          */
6621         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6622                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6623         };
6624
6625         /* Partial command line, retrieve current configuration */
6626         if (cmd) {
6627                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6628                 if (ret != 0) {
6629                         printf("cannot get current flow ctrl parameters, return"
6630                                "code = %d\n", ret);
6631                         return;
6632                 }
6633
6634                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6635                     (fc_conf.mode == RTE_FC_FULL))
6636                         rx_fc_en = 1;
6637                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6638                     (fc_conf.mode == RTE_FC_FULL))
6639                         tx_fc_en = 1;
6640         }
6641
6642         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6643                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6644
6645         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6646                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6647
6648         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6649
6650         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6651                 fc_conf.high_water = res->high_water;
6652
6653         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6654                 fc_conf.low_water = res->low_water;
6655
6656         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6657                 fc_conf.pause_time = res->pause_time;
6658
6659         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6660                 fc_conf.send_xon = res->send_xon;
6661
6662         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6663                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6664                         fc_conf.mac_ctrl_frame_fwd = 1;
6665                 else
6666                         fc_conf.mac_ctrl_frame_fwd = 0;
6667         }
6668
6669         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6670                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6671
6672         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6673         if (ret != 0)
6674                 printf("bad flow contrl parameter, return code = %d \n", ret);
6675 }
6676
6677 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6678 struct cmd_priority_flow_ctrl_set_result {
6679         cmdline_fixed_string_t set;
6680         cmdline_fixed_string_t pfc_ctrl;
6681         cmdline_fixed_string_t rx;
6682         cmdline_fixed_string_t rx_pfc_mode;
6683         cmdline_fixed_string_t tx;
6684         cmdline_fixed_string_t tx_pfc_mode;
6685         uint32_t high_water;
6686         uint32_t low_water;
6687         uint16_t pause_time;
6688         uint8_t  priority;
6689         portid_t port_id;
6690 };
6691
6692 static void
6693 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6694                        __attribute__((unused)) struct cmdline *cl,
6695                        __attribute__((unused)) void *data)
6696 {
6697         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6698         struct rte_eth_pfc_conf pfc_conf;
6699         int rx_fc_enable, tx_fc_enable;
6700         int ret;
6701
6702         /*
6703          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6704          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6705          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6706          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6707          */
6708         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6709                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6710         };
6711
6712         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6713         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6714         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6715         pfc_conf.fc.high_water = res->high_water;
6716         pfc_conf.fc.low_water  = res->low_water;
6717         pfc_conf.fc.pause_time = res->pause_time;
6718         pfc_conf.priority      = res->priority;
6719
6720         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6721         if (ret != 0)
6722                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6723 }
6724
6725 cmdline_parse_token_string_t cmd_pfc_set_set =
6726         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6727                                 set, "set");
6728 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6729         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6730                                 pfc_ctrl, "pfc_ctrl");
6731 cmdline_parse_token_string_t cmd_pfc_set_rx =
6732         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6733                                 rx, "rx");
6734 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6735         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6736                                 rx_pfc_mode, "on#off");
6737 cmdline_parse_token_string_t cmd_pfc_set_tx =
6738         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6739                                 tx, "tx");
6740 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6741         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6742                                 tx_pfc_mode, "on#off");
6743 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6744         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6745                                 high_water, UINT32);
6746 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6747         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6748                                 low_water, UINT32);
6749 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6750         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6751                                 pause_time, UINT16);
6752 cmdline_parse_token_num_t cmd_pfc_set_priority =
6753         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6754                                 priority, UINT8);
6755 cmdline_parse_token_num_t cmd_pfc_set_portid =
6756         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6757                                 port_id, UINT16);
6758
6759 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6760         .f = cmd_priority_flow_ctrl_set_parsed,
6761         .data = NULL,
6762         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6763                 "<pause_time> <priority> <port_id>: "
6764                 "Configure the Ethernet priority flow control",
6765         .tokens = {
6766                 (void *)&cmd_pfc_set_set,
6767                 (void *)&cmd_pfc_set_flow_ctrl,
6768                 (void *)&cmd_pfc_set_rx,
6769                 (void *)&cmd_pfc_set_rx_mode,
6770                 (void *)&cmd_pfc_set_tx,
6771                 (void *)&cmd_pfc_set_tx_mode,
6772                 (void *)&cmd_pfc_set_high_water,
6773                 (void *)&cmd_pfc_set_low_water,
6774                 (void *)&cmd_pfc_set_pause_time,
6775                 (void *)&cmd_pfc_set_priority,
6776                 (void *)&cmd_pfc_set_portid,
6777                 NULL,
6778         },
6779 };
6780
6781 /* *** RESET CONFIGURATION *** */
6782 struct cmd_reset_result {
6783         cmdline_fixed_string_t reset;
6784         cmdline_fixed_string_t def;
6785 };
6786
6787 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6788                              struct cmdline *cl,
6789                              __attribute__((unused)) void *data)
6790 {
6791         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6792         set_def_fwd_config();
6793 }
6794
6795 cmdline_parse_token_string_t cmd_reset_set =
6796         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6797 cmdline_parse_token_string_t cmd_reset_def =
6798         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6799                                  "default");
6800
6801 cmdline_parse_inst_t cmd_reset = {
6802         .f = cmd_reset_parsed,
6803         .data = NULL,
6804         .help_str = "set default: Reset default forwarding configuration",
6805         .tokens = {
6806                 (void *)&cmd_reset_set,
6807                 (void *)&cmd_reset_def,
6808                 NULL,
6809         },
6810 };
6811
6812 /* *** START FORWARDING *** */
6813 struct cmd_start_result {
6814         cmdline_fixed_string_t start;
6815 };
6816
6817 cmdline_parse_token_string_t cmd_start_start =
6818         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6819
6820 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6821                              __attribute__((unused)) struct cmdline *cl,
6822                              __attribute__((unused)) void *data)
6823 {
6824         start_packet_forwarding(0);
6825 }
6826
6827 cmdline_parse_inst_t cmd_start = {
6828         .f = cmd_start_parsed,
6829         .data = NULL,
6830         .help_str = "start: Start packet forwarding",
6831         .tokens = {
6832                 (void *)&cmd_start_start,
6833                 NULL,
6834         },
6835 };
6836
6837 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6838 struct cmd_start_tx_first_result {
6839         cmdline_fixed_string_t start;
6840         cmdline_fixed_string_t tx_first;
6841 };
6842
6843 static void
6844 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6845                           __attribute__((unused)) struct cmdline *cl,
6846                           __attribute__((unused)) void *data)
6847 {
6848         start_packet_forwarding(1);
6849 }
6850
6851 cmdline_parse_token_string_t cmd_start_tx_first_start =
6852         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6853                                  "start");
6854 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6855         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6856                                  tx_first, "tx_first");
6857
6858 cmdline_parse_inst_t cmd_start_tx_first = {
6859         .f = cmd_start_tx_first_parsed,
6860         .data = NULL,
6861         .help_str = "start tx_first: Start packet forwarding, "
6862                 "after sending 1 burst of packets",
6863         .tokens = {
6864                 (void *)&cmd_start_tx_first_start,
6865                 (void *)&cmd_start_tx_first_tx_first,
6866                 NULL,
6867         },
6868 };
6869
6870 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6871 struct cmd_start_tx_first_n_result {
6872         cmdline_fixed_string_t start;
6873         cmdline_fixed_string_t tx_first;
6874         uint32_t tx_num;
6875 };
6876
6877 static void
6878 cmd_start_tx_first_n_parsed(void *parsed_result,
6879                           __attribute__((unused)) struct cmdline *cl,
6880                           __attribute__((unused)) void *data)
6881 {
6882         struct cmd_start_tx_first_n_result *res = parsed_result;
6883
6884         start_packet_forwarding(res->tx_num);
6885 }
6886
6887 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6888         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6889                         start, "start");
6890 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6891         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6892                         tx_first, "tx_first");
6893 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6894         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6895                         tx_num, UINT32);
6896
6897 cmdline_parse_inst_t cmd_start_tx_first_n = {
6898         .f = cmd_start_tx_first_n_parsed,
6899         .data = NULL,
6900         .help_str = "start tx_first <num>: "
6901                 "packet forwarding, after sending <num> bursts of packets",
6902         .tokens = {
6903                 (void *)&cmd_start_tx_first_n_start,
6904                 (void *)&cmd_start_tx_first_n_tx_first,
6905                 (void *)&cmd_start_tx_first_n_tx_num,
6906                 NULL,
6907         },
6908 };
6909
6910 /* *** SET LINK UP *** */
6911 struct cmd_set_link_up_result {
6912         cmdline_fixed_string_t set;
6913         cmdline_fixed_string_t link_up;
6914         cmdline_fixed_string_t port;
6915         portid_t port_id;
6916 };
6917
6918 cmdline_parse_token_string_t cmd_set_link_up_set =
6919         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6920 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6921         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6922                                 "link-up");
6923 cmdline_parse_token_string_t cmd_set_link_up_port =
6924         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6925 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6926         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6927
6928 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6929                              __attribute__((unused)) struct cmdline *cl,
6930                              __attribute__((unused)) void *data)
6931 {
6932         struct cmd_set_link_up_result *res = parsed_result;
6933         dev_set_link_up(res->port_id);
6934 }
6935
6936 cmdline_parse_inst_t cmd_set_link_up = {
6937         .f = cmd_set_link_up_parsed,
6938         .data = NULL,
6939         .help_str = "set link-up port <port id>",
6940         .tokens = {
6941                 (void *)&cmd_set_link_up_set,
6942                 (void *)&cmd_set_link_up_link_up,
6943                 (void *)&cmd_set_link_up_port,
6944                 (void *)&cmd_set_link_up_port_id,
6945                 NULL,
6946         },
6947 };
6948
6949 /* *** SET LINK DOWN *** */
6950 struct cmd_set_link_down_result {
6951         cmdline_fixed_string_t set;
6952         cmdline_fixed_string_t link_down;
6953         cmdline_fixed_string_t port;
6954         portid_t port_id;
6955 };
6956
6957 cmdline_parse_token_string_t cmd_set_link_down_set =
6958         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6959 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6960         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6961                                 "link-down");
6962 cmdline_parse_token_string_t cmd_set_link_down_port =
6963         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6964 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6965         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6966
6967 static void cmd_set_link_down_parsed(
6968                                 __attribute__((unused)) void *parsed_result,
6969                                 __attribute__((unused)) struct cmdline *cl,
6970                                 __attribute__((unused)) void *data)
6971 {
6972         struct cmd_set_link_down_result *res = parsed_result;
6973         dev_set_link_down(res->port_id);
6974 }
6975
6976 cmdline_parse_inst_t cmd_set_link_down = {
6977         .f = cmd_set_link_down_parsed,
6978         .data = NULL,
6979         .help_str = "set link-down port <port id>",
6980         .tokens = {
6981                 (void *)&cmd_set_link_down_set,
6982                 (void *)&cmd_set_link_down_link_down,
6983                 (void *)&cmd_set_link_down_port,
6984                 (void *)&cmd_set_link_down_port_id,
6985                 NULL,
6986         },
6987 };
6988
6989 /* *** SHOW CFG *** */
6990 struct cmd_showcfg_result {
6991         cmdline_fixed_string_t show;
6992         cmdline_fixed_string_t cfg;
6993         cmdline_fixed_string_t what;
6994 };
6995
6996 static void cmd_showcfg_parsed(void *parsed_result,
6997                                __attribute__((unused)) struct cmdline *cl,
6998                                __attribute__((unused)) void *data)
6999 {
7000         struct cmd_showcfg_result *res = parsed_result;
7001         if (!strcmp(res->what, "rxtx"))
7002                 rxtx_config_display();
7003         else if (!strcmp(res->what, "cores"))
7004                 fwd_lcores_config_display();
7005         else if (!strcmp(res->what, "fwd"))
7006                 pkt_fwd_config_display(&cur_fwd_config);
7007         else if (!strcmp(res->what, "txpkts"))
7008                 show_tx_pkt_segments();
7009 }
7010
7011 cmdline_parse_token_string_t cmd_showcfg_show =
7012         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7013 cmdline_parse_token_string_t cmd_showcfg_port =
7014         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7015 cmdline_parse_token_string_t cmd_showcfg_what =
7016         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7017                                  "rxtx#cores#fwd#txpkts");
7018
7019 cmdline_parse_inst_t cmd_showcfg = {
7020         .f = cmd_showcfg_parsed,
7021         .data = NULL,
7022         .help_str = "show config rxtx|cores|fwd|txpkts",
7023         .tokens = {
7024                 (void *)&cmd_showcfg_show,
7025                 (void *)&cmd_showcfg_port,
7026                 (void *)&cmd_showcfg_what,
7027                 NULL,
7028         },
7029 };
7030
7031 /* *** SHOW ALL PORT INFO *** */
7032 struct cmd_showportall_result {
7033         cmdline_fixed_string_t show;
7034         cmdline_fixed_string_t port;
7035         cmdline_fixed_string_t what;
7036         cmdline_fixed_string_t all;
7037 };
7038
7039 static void cmd_showportall_parsed(void *parsed_result,
7040                                 __attribute__((unused)) struct cmdline *cl,
7041                                 __attribute__((unused)) void *data)
7042 {
7043         portid_t i;
7044
7045         struct cmd_showportall_result *res = parsed_result;
7046         if (!strcmp(res->show, "clear")) {
7047                 if (!strcmp(res->what, "stats"))
7048                         RTE_ETH_FOREACH_DEV(i)
7049                                 nic_stats_clear(i);
7050                 else if (!strcmp(res->what, "xstats"))
7051                         RTE_ETH_FOREACH_DEV(i)
7052                                 nic_xstats_clear(i);
7053         } else if (!strcmp(res->what, "info"))
7054                 RTE_ETH_FOREACH_DEV(i)
7055                         port_infos_display(i);
7056         else if (!strcmp(res->what, "stats"))
7057                 RTE_ETH_FOREACH_DEV(i)
7058                         nic_stats_display(i);
7059         else if (!strcmp(res->what, "xstats"))
7060                 RTE_ETH_FOREACH_DEV(i)
7061                         nic_xstats_display(i);
7062         else if (!strcmp(res->what, "fdir"))
7063                 RTE_ETH_FOREACH_DEV(i)
7064                         fdir_get_infos(i);
7065         else if (!strcmp(res->what, "stat_qmap"))
7066                 RTE_ETH_FOREACH_DEV(i)
7067                         nic_stats_mapping_display(i);
7068         else if (!strcmp(res->what, "dcb_tc"))
7069                 RTE_ETH_FOREACH_DEV(i)
7070                         port_dcb_info_display(i);
7071         else if (!strcmp(res->what, "cap"))
7072                 RTE_ETH_FOREACH_DEV(i)
7073                         port_offload_cap_display(i);
7074 }
7075
7076 cmdline_parse_token_string_t cmd_showportall_show =
7077         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7078                                  "show#clear");
7079 cmdline_parse_token_string_t cmd_showportall_port =
7080         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7081 cmdline_parse_token_string_t cmd_showportall_what =
7082         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7083                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7084 cmdline_parse_token_string_t cmd_showportall_all =
7085         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7086 cmdline_parse_inst_t cmd_showportall = {
7087         .f = cmd_showportall_parsed,
7088         .data = NULL,
7089         .help_str = "show|clear port "
7090                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7091         .tokens = {
7092                 (void *)&cmd_showportall_show,
7093                 (void *)&cmd_showportall_port,
7094                 (void *)&cmd_showportall_what,
7095                 (void *)&cmd_showportall_all,
7096                 NULL,
7097         },
7098 };
7099
7100 /* *** SHOW PORT INFO *** */
7101 struct cmd_showport_result {
7102         cmdline_fixed_string_t show;
7103         cmdline_fixed_string_t port;
7104         cmdline_fixed_string_t what;
7105         uint16_t portnum;
7106 };
7107
7108 static void cmd_showport_parsed(void *parsed_result,
7109                                 __attribute__((unused)) struct cmdline *cl,
7110                                 __attribute__((unused)) void *data)
7111 {
7112         struct cmd_showport_result *res = parsed_result;
7113         if (!strcmp(res->show, "clear")) {
7114                 if (!strcmp(res->what, "stats"))
7115                         nic_stats_clear(res->portnum);
7116                 else if (!strcmp(res->what, "xstats"))
7117                         nic_xstats_clear(res->portnum);
7118         } else if (!strcmp(res->what, "info"))
7119                 port_infos_display(res->portnum);
7120         else if (!strcmp(res->what, "stats"))
7121                 nic_stats_display(res->portnum);
7122         else if (!strcmp(res->what, "xstats"))
7123                 nic_xstats_display(res->portnum);
7124         else if (!strcmp(res->what, "fdir"))
7125                  fdir_get_infos(res->portnum);
7126         else if (!strcmp(res->what, "stat_qmap"))
7127                 nic_stats_mapping_display(res->portnum);
7128         else if (!strcmp(res->what, "dcb_tc"))
7129                 port_dcb_info_display(res->portnum);
7130         else if (!strcmp(res->what, "cap"))
7131                 port_offload_cap_display(res->portnum);
7132 }
7133
7134 cmdline_parse_token_string_t cmd_showport_show =
7135         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7136                                  "show#clear");
7137 cmdline_parse_token_string_t cmd_showport_port =
7138         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7139 cmdline_parse_token_string_t cmd_showport_what =
7140         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7141                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7142 cmdline_parse_token_num_t cmd_showport_portnum =
7143         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7144
7145 cmdline_parse_inst_t cmd_showport = {
7146         .f = cmd_showport_parsed,
7147         .data = NULL,
7148         .help_str = "show|clear port "
7149                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7150                 "<port_id>",
7151         .tokens = {
7152                 (void *)&cmd_showport_show,
7153                 (void *)&cmd_showport_port,
7154                 (void *)&cmd_showport_what,
7155                 (void *)&cmd_showport_portnum,
7156                 NULL,
7157         },
7158 };
7159
7160 /* *** SHOW QUEUE INFO *** */
7161 struct cmd_showqueue_result {
7162         cmdline_fixed_string_t show;
7163         cmdline_fixed_string_t type;
7164         cmdline_fixed_string_t what;
7165         uint16_t portnum;
7166         uint16_t queuenum;
7167 };
7168
7169 static void
7170 cmd_showqueue_parsed(void *parsed_result,
7171         __attribute__((unused)) struct cmdline *cl,
7172         __attribute__((unused)) void *data)
7173 {
7174         struct cmd_showqueue_result *res = parsed_result;
7175
7176         if (!strcmp(res->type, "rxq"))
7177                 rx_queue_infos_display(res->portnum, res->queuenum);
7178         else if (!strcmp(res->type, "txq"))
7179                 tx_queue_infos_display(res->portnum, res->queuenum);
7180 }
7181
7182 cmdline_parse_token_string_t cmd_showqueue_show =
7183         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7184 cmdline_parse_token_string_t cmd_showqueue_type =
7185         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7186 cmdline_parse_token_string_t cmd_showqueue_what =
7187         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7188 cmdline_parse_token_num_t cmd_showqueue_portnum =
7189         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7190 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7191         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7192
7193 cmdline_parse_inst_t cmd_showqueue = {
7194         .f = cmd_showqueue_parsed,
7195         .data = NULL,
7196         .help_str = "show rxq|txq info <port_id> <queue_id>",
7197         .tokens = {
7198                 (void *)&cmd_showqueue_show,
7199                 (void *)&cmd_showqueue_type,
7200                 (void *)&cmd_showqueue_what,
7201                 (void *)&cmd_showqueue_portnum,
7202                 (void *)&cmd_showqueue_queuenum,
7203                 NULL,
7204         },
7205 };
7206
7207 /* *** READ PORT REGISTER *** */
7208 struct cmd_read_reg_result {
7209         cmdline_fixed_string_t read;
7210         cmdline_fixed_string_t reg;
7211         portid_t port_id;
7212         uint32_t reg_off;
7213 };
7214
7215 static void
7216 cmd_read_reg_parsed(void *parsed_result,
7217                     __attribute__((unused)) struct cmdline *cl,
7218                     __attribute__((unused)) void *data)
7219 {
7220         struct cmd_read_reg_result *res = parsed_result;
7221         port_reg_display(res->port_id, res->reg_off);
7222 }
7223
7224 cmdline_parse_token_string_t cmd_read_reg_read =
7225         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7226 cmdline_parse_token_string_t cmd_read_reg_reg =
7227         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7228 cmdline_parse_token_num_t cmd_read_reg_port_id =
7229         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7230 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7231         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7232
7233 cmdline_parse_inst_t cmd_read_reg = {
7234         .f = cmd_read_reg_parsed,
7235         .data = NULL,
7236         .help_str = "read reg <port_id> <reg_off>",
7237         .tokens = {
7238                 (void *)&cmd_read_reg_read,
7239                 (void *)&cmd_read_reg_reg,
7240                 (void *)&cmd_read_reg_port_id,
7241                 (void *)&cmd_read_reg_reg_off,
7242                 NULL,
7243         },
7244 };
7245
7246 /* *** READ PORT REGISTER BIT FIELD *** */
7247 struct cmd_read_reg_bit_field_result {
7248         cmdline_fixed_string_t read;
7249         cmdline_fixed_string_t regfield;
7250         portid_t port_id;
7251         uint32_t reg_off;
7252         uint8_t bit1_pos;
7253         uint8_t bit2_pos;
7254 };
7255
7256 static void
7257 cmd_read_reg_bit_field_parsed(void *parsed_result,
7258                               __attribute__((unused)) struct cmdline *cl,
7259                               __attribute__((unused)) void *data)
7260 {
7261         struct cmd_read_reg_bit_field_result *res = parsed_result;
7262         port_reg_bit_field_display(res->port_id, res->reg_off,
7263                                    res->bit1_pos, res->bit2_pos);
7264 }
7265
7266 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7267         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7268                                  "read");
7269 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7270         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7271                                  regfield, "regfield");
7272 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7273         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7274                               UINT16);
7275 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7276         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7277                               UINT32);
7278 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7279         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7280                               UINT8);
7281 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7282         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7283                               UINT8);
7284
7285 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7286         .f = cmd_read_reg_bit_field_parsed,
7287         .data = NULL,
7288         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7289         "Read register bit field between bit_x and bit_y included",
7290         .tokens = {
7291                 (void *)&cmd_read_reg_bit_field_read,
7292                 (void *)&cmd_read_reg_bit_field_regfield,
7293                 (void *)&cmd_read_reg_bit_field_port_id,
7294                 (void *)&cmd_read_reg_bit_field_reg_off,
7295                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7296                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7297                 NULL,
7298         },
7299 };
7300
7301 /* *** READ PORT REGISTER BIT *** */
7302 struct cmd_read_reg_bit_result {
7303         cmdline_fixed_string_t read;
7304         cmdline_fixed_string_t regbit;
7305         portid_t port_id;
7306         uint32_t reg_off;
7307         uint8_t bit_pos;
7308 };
7309
7310 static void
7311 cmd_read_reg_bit_parsed(void *parsed_result,
7312                         __attribute__((unused)) struct cmdline *cl,
7313                         __attribute__((unused)) void *data)
7314 {
7315         struct cmd_read_reg_bit_result *res = parsed_result;
7316         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7317 }
7318
7319 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7320         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7321 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7322         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7323                                  regbit, "regbit");
7324 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7325         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7326 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7327         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7328 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7329         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7330
7331 cmdline_parse_inst_t cmd_read_reg_bit = {
7332         .f = cmd_read_reg_bit_parsed,
7333         .data = NULL,
7334         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7335         .tokens = {
7336                 (void *)&cmd_read_reg_bit_read,
7337                 (void *)&cmd_read_reg_bit_regbit,
7338                 (void *)&cmd_read_reg_bit_port_id,
7339                 (void *)&cmd_read_reg_bit_reg_off,
7340                 (void *)&cmd_read_reg_bit_bit_pos,
7341                 NULL,
7342         },
7343 };
7344
7345 /* *** WRITE PORT REGISTER *** */
7346 struct cmd_write_reg_result {
7347         cmdline_fixed_string_t write;
7348         cmdline_fixed_string_t reg;
7349         portid_t port_id;
7350         uint32_t reg_off;
7351         uint32_t value;
7352 };
7353
7354 static void
7355 cmd_write_reg_parsed(void *parsed_result,
7356                      __attribute__((unused)) struct cmdline *cl,
7357                      __attribute__((unused)) void *data)
7358 {
7359         struct cmd_write_reg_result *res = parsed_result;
7360         port_reg_set(res->port_id, res->reg_off, res->value);
7361 }
7362
7363 cmdline_parse_token_string_t cmd_write_reg_write =
7364         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7365 cmdline_parse_token_string_t cmd_write_reg_reg =
7366         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7367 cmdline_parse_token_num_t cmd_write_reg_port_id =
7368         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7369 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7370         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7371 cmdline_parse_token_num_t cmd_write_reg_value =
7372         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7373
7374 cmdline_parse_inst_t cmd_write_reg = {
7375         .f = cmd_write_reg_parsed,
7376         .data = NULL,
7377         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7378         .tokens = {
7379                 (void *)&cmd_write_reg_write,
7380                 (void *)&cmd_write_reg_reg,
7381                 (void *)&cmd_write_reg_port_id,
7382                 (void *)&cmd_write_reg_reg_off,
7383                 (void *)&cmd_write_reg_value,
7384                 NULL,
7385         },
7386 };
7387
7388 /* *** WRITE PORT REGISTER BIT FIELD *** */
7389 struct cmd_write_reg_bit_field_result {
7390         cmdline_fixed_string_t write;
7391         cmdline_fixed_string_t regfield;
7392         portid_t port_id;
7393         uint32_t reg_off;
7394         uint8_t bit1_pos;
7395         uint8_t bit2_pos;
7396         uint32_t value;
7397 };
7398
7399 static void
7400 cmd_write_reg_bit_field_parsed(void *parsed_result,
7401                                __attribute__((unused)) struct cmdline *cl,
7402                                __attribute__((unused)) void *data)
7403 {
7404         struct cmd_write_reg_bit_field_result *res = parsed_result;
7405         port_reg_bit_field_set(res->port_id, res->reg_off,
7406                           res->bit1_pos, res->bit2_pos, res->value);
7407 }
7408
7409 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7410         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7411                                  "write");
7412 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7413         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7414                                  regfield, "regfield");
7415 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7416         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7417                               UINT16);
7418 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7419         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7420                               UINT32);
7421 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7422         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7423                               UINT8);
7424 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7425         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7426                               UINT8);
7427 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7428         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7429                               UINT32);
7430
7431 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7432         .f = cmd_write_reg_bit_field_parsed,
7433         .data = NULL,
7434         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7435                 "<reg_value>: "
7436                 "Set register bit field between bit_x and bit_y included",
7437         .tokens = {
7438                 (void *)&cmd_write_reg_bit_field_write,
7439                 (void *)&cmd_write_reg_bit_field_regfield,
7440                 (void *)&cmd_write_reg_bit_field_port_id,
7441                 (void *)&cmd_write_reg_bit_field_reg_off,
7442                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7443                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7444                 (void *)&cmd_write_reg_bit_field_value,
7445                 NULL,
7446         },
7447 };
7448
7449 /* *** WRITE PORT REGISTER BIT *** */
7450 struct cmd_write_reg_bit_result {
7451         cmdline_fixed_string_t write;
7452         cmdline_fixed_string_t regbit;
7453         portid_t port_id;
7454         uint32_t reg_off;
7455         uint8_t bit_pos;
7456         uint8_t value;
7457 };
7458
7459 static void
7460 cmd_write_reg_bit_parsed(void *parsed_result,
7461                          __attribute__((unused)) struct cmdline *cl,
7462                          __attribute__((unused)) void *data)
7463 {
7464         struct cmd_write_reg_bit_result *res = parsed_result;
7465         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7466 }
7467
7468 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7469         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7470                                  "write");
7471 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7472         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7473                                  regbit, "regbit");
7474 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7475         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7476 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7477         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7478 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7479         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7480 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7481         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7482
7483 cmdline_parse_inst_t cmd_write_reg_bit = {
7484         .f = cmd_write_reg_bit_parsed,
7485         .data = NULL,
7486         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7487                 "0 <= bit_x <= 31",
7488         .tokens = {
7489                 (void *)&cmd_write_reg_bit_write,
7490                 (void *)&cmd_write_reg_bit_regbit,
7491                 (void *)&cmd_write_reg_bit_port_id,
7492                 (void *)&cmd_write_reg_bit_reg_off,
7493                 (void *)&cmd_write_reg_bit_bit_pos,
7494                 (void *)&cmd_write_reg_bit_value,
7495                 NULL,
7496         },
7497 };
7498
7499 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7500 struct cmd_read_rxd_txd_result {
7501         cmdline_fixed_string_t read;
7502         cmdline_fixed_string_t rxd_txd;
7503         portid_t port_id;
7504         uint16_t queue_id;
7505         uint16_t desc_id;
7506 };
7507
7508 static void
7509 cmd_read_rxd_txd_parsed(void *parsed_result,
7510                         __attribute__((unused)) struct cmdline *cl,
7511                         __attribute__((unused)) void *data)
7512 {
7513         struct cmd_read_rxd_txd_result *res = parsed_result;
7514
7515         if (!strcmp(res->rxd_txd, "rxd"))
7516                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7517         else if (!strcmp(res->rxd_txd, "txd"))
7518                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7519 }
7520
7521 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7522         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7523 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7524         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7525                                  "rxd#txd");
7526 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7527         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7528 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7529         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7530 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7531         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7532
7533 cmdline_parse_inst_t cmd_read_rxd_txd = {
7534         .f = cmd_read_rxd_txd_parsed,
7535         .data = NULL,
7536         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7537         .tokens = {
7538                 (void *)&cmd_read_rxd_txd_read,
7539                 (void *)&cmd_read_rxd_txd_rxd_txd,
7540                 (void *)&cmd_read_rxd_txd_port_id,
7541                 (void *)&cmd_read_rxd_txd_queue_id,
7542                 (void *)&cmd_read_rxd_txd_desc_id,
7543                 NULL,
7544         },
7545 };
7546
7547 /* *** QUIT *** */
7548 struct cmd_quit_result {
7549         cmdline_fixed_string_t quit;
7550 };
7551
7552 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7553                             struct cmdline *cl,
7554                             __attribute__((unused)) void *data)
7555 {
7556         pmd_test_exit();
7557         cmdline_quit(cl);
7558 }
7559
7560 cmdline_parse_token_string_t cmd_quit_quit =
7561         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7562
7563 cmdline_parse_inst_t cmd_quit = {
7564         .f = cmd_quit_parsed,
7565         .data = NULL,
7566         .help_str = "quit: Exit application",
7567         .tokens = {
7568                 (void *)&cmd_quit_quit,
7569                 NULL,
7570         },
7571 };
7572
7573 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7574 struct cmd_mac_addr_result {
7575         cmdline_fixed_string_t mac_addr_cmd;
7576         cmdline_fixed_string_t what;
7577         uint16_t port_num;
7578         struct ether_addr address;
7579 };
7580
7581 static void cmd_mac_addr_parsed(void *parsed_result,
7582                 __attribute__((unused)) struct cmdline *cl,
7583                 __attribute__((unused)) void *data)
7584 {
7585         struct cmd_mac_addr_result *res = parsed_result;
7586         int ret;
7587
7588         if (strcmp(res->what, "add") == 0)
7589                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7590         else if (strcmp(res->what, "set") == 0)
7591                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7592                                                        &res->address);
7593         else
7594                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7595
7596         /* check the return value and print it if is < 0 */
7597         if(ret < 0)
7598                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7599
7600 }
7601
7602 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7603         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7604                                 "mac_addr");
7605 cmdline_parse_token_string_t cmd_mac_addr_what =
7606         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7607                                 "add#remove#set");
7608 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7609                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7610                                         UINT16);
7611 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7612                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7613
7614 cmdline_parse_inst_t cmd_mac_addr = {
7615         .f = cmd_mac_addr_parsed,
7616         .data = (void *)0,
7617         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7618                         "Add/Remove/Set MAC address on port_id",
7619         .tokens = {
7620                 (void *)&cmd_mac_addr_cmd,
7621                 (void *)&cmd_mac_addr_what,
7622                 (void *)&cmd_mac_addr_portnum,
7623                 (void *)&cmd_mac_addr_addr,
7624                 NULL,
7625         },
7626 };
7627
7628 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7629 struct cmd_eth_peer_result {
7630         cmdline_fixed_string_t set;
7631         cmdline_fixed_string_t eth_peer;
7632         portid_t port_id;
7633         cmdline_fixed_string_t peer_addr;
7634 };
7635
7636 static void cmd_set_eth_peer_parsed(void *parsed_result,
7637                         __attribute__((unused)) struct cmdline *cl,
7638                         __attribute__((unused)) void *data)
7639 {
7640                 struct cmd_eth_peer_result *res = parsed_result;
7641
7642                 if (test_done == 0) {
7643                         printf("Please stop forwarding first\n");
7644                         return;
7645                 }
7646                 if (!strcmp(res->eth_peer, "eth-peer")) {
7647                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7648                         fwd_config_setup();
7649                 }
7650 }
7651 cmdline_parse_token_string_t cmd_eth_peer_set =
7652         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7653 cmdline_parse_token_string_t cmd_eth_peer =
7654         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7655 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7656         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7657 cmdline_parse_token_string_t cmd_eth_peer_addr =
7658         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7659
7660 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7661         .f = cmd_set_eth_peer_parsed,
7662         .data = NULL,
7663         .help_str = "set eth-peer <port_id> <peer_mac>",
7664         .tokens = {
7665                 (void *)&cmd_eth_peer_set,
7666                 (void *)&cmd_eth_peer,
7667                 (void *)&cmd_eth_peer_port_id,
7668                 (void *)&cmd_eth_peer_addr,
7669                 NULL,
7670         },
7671 };
7672
7673 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7674 struct cmd_set_qmap_result {
7675         cmdline_fixed_string_t set;
7676         cmdline_fixed_string_t qmap;
7677         cmdline_fixed_string_t what;
7678         portid_t port_id;
7679         uint16_t queue_id;
7680         uint8_t map_value;
7681 };
7682
7683 static void
7684 cmd_set_qmap_parsed(void *parsed_result,
7685                        __attribute__((unused)) struct cmdline *cl,
7686                        __attribute__((unused)) void *data)
7687 {
7688         struct cmd_set_qmap_result *res = parsed_result;
7689         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7690
7691         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7692 }
7693
7694 cmdline_parse_token_string_t cmd_setqmap_set =
7695         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7696                                  set, "set");
7697 cmdline_parse_token_string_t cmd_setqmap_qmap =
7698         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7699                                  qmap, "stat_qmap");
7700 cmdline_parse_token_string_t cmd_setqmap_what =
7701         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7702                                  what, "tx#rx");
7703 cmdline_parse_token_num_t cmd_setqmap_portid =
7704         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7705                               port_id, UINT16);
7706 cmdline_parse_token_num_t cmd_setqmap_queueid =
7707         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7708                               queue_id, UINT16);
7709 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7710         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7711                               map_value, UINT8);
7712
7713 cmdline_parse_inst_t cmd_set_qmap = {
7714         .f = cmd_set_qmap_parsed,
7715         .data = NULL,
7716         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7717                 "Set statistics mapping value on tx|rx queue_id of port_id",
7718         .tokens = {
7719                 (void *)&cmd_setqmap_set,
7720                 (void *)&cmd_setqmap_qmap,
7721                 (void *)&cmd_setqmap_what,
7722                 (void *)&cmd_setqmap_portid,
7723                 (void *)&cmd_setqmap_queueid,
7724                 (void *)&cmd_setqmap_mapvalue,
7725                 NULL,
7726         },
7727 };
7728
7729 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7730 struct cmd_set_xstats_hide_zero_result {
7731         cmdline_fixed_string_t keyword;
7732         cmdline_fixed_string_t name;
7733         cmdline_fixed_string_t on_off;
7734 };
7735
7736 static void
7737 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7738                         __attribute__((unused)) struct cmdline *cl,
7739                         __attribute__((unused)) void *data)
7740 {
7741         struct cmd_set_xstats_hide_zero_result *res;
7742         uint16_t on_off = 0;
7743
7744         res = parsed_result;
7745         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7746         set_xstats_hide_zero(on_off);
7747 }
7748
7749 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7750         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7751                                  keyword, "set");
7752 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7753         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7754                                  name, "xstats-hide-zero");
7755 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7756         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7757                                  on_off, "on#off");
7758
7759 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7760         .f = cmd_set_xstats_hide_zero_parsed,
7761         .data = NULL,
7762         .help_str = "set xstats-hide-zero on|off",
7763         .tokens = {
7764                 (void *)&cmd_set_xstats_hide_zero_keyword,
7765                 (void *)&cmd_set_xstats_hide_zero_name,
7766                 (void *)&cmd_set_xstats_hide_zero_on_off,
7767                 NULL,
7768         },
7769 };
7770
7771 /* *** CONFIGURE UNICAST HASH TABLE *** */
7772 struct cmd_set_uc_hash_table {
7773         cmdline_fixed_string_t set;
7774         cmdline_fixed_string_t port;
7775         portid_t port_id;
7776         cmdline_fixed_string_t what;
7777         struct ether_addr address;
7778         cmdline_fixed_string_t mode;
7779 };
7780
7781 static void
7782 cmd_set_uc_hash_parsed(void *parsed_result,
7783                        __attribute__((unused)) struct cmdline *cl,
7784                        __attribute__((unused)) void *data)
7785 {
7786         int ret=0;
7787         struct cmd_set_uc_hash_table *res = parsed_result;
7788
7789         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7790
7791         if (strcmp(res->what, "uta") == 0)
7792                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7793                                                 &res->address,(uint8_t)is_on);
7794         if (ret < 0)
7795                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7796
7797 }
7798
7799 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7800         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7801                                  set, "set");
7802 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7803         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7804                                  port, "port");
7805 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7806         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7807                               port_id, UINT16);
7808 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7809         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7810                                  what, "uta");
7811 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7812         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7813                                 address);
7814 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7815         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7816                                  mode, "on#off");
7817
7818 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7819         .f = cmd_set_uc_hash_parsed,
7820         .data = NULL,
7821         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7822         .tokens = {
7823                 (void *)&cmd_set_uc_hash_set,
7824                 (void *)&cmd_set_uc_hash_port,
7825                 (void *)&cmd_set_uc_hash_portid,
7826                 (void *)&cmd_set_uc_hash_what,
7827                 (void *)&cmd_set_uc_hash_mac,
7828                 (void *)&cmd_set_uc_hash_mode,
7829                 NULL,
7830         },
7831 };
7832
7833 struct cmd_set_uc_all_hash_table {
7834         cmdline_fixed_string_t set;
7835         cmdline_fixed_string_t port;
7836         portid_t port_id;
7837         cmdline_fixed_string_t what;
7838         cmdline_fixed_string_t value;
7839         cmdline_fixed_string_t mode;
7840 };
7841
7842 static void
7843 cmd_set_uc_all_hash_parsed(void *parsed_result,
7844                        __attribute__((unused)) struct cmdline *cl,
7845                        __attribute__((unused)) void *data)
7846 {
7847         int ret=0;
7848         struct cmd_set_uc_all_hash_table *res = parsed_result;
7849
7850         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7851
7852         if ((strcmp(res->what, "uta") == 0) &&
7853                 (strcmp(res->value, "all") == 0))
7854                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7855         if (ret < 0)
7856                 printf("bad unicast hash table parameter,"
7857                         "return code = %d \n", ret);
7858 }
7859
7860 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7861         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7862                                  set, "set");
7863 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7864         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7865                                  port, "port");
7866 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7867         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7868                               port_id, UINT16);
7869 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7870         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7871                                  what, "uta");
7872 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7873         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7874                                 value,"all");
7875 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7876         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7877                                  mode, "on#off");
7878
7879 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7880         .f = cmd_set_uc_all_hash_parsed,
7881         .data = NULL,
7882         .help_str = "set port <port_id> uta all on|off",
7883         .tokens = {
7884                 (void *)&cmd_set_uc_all_hash_set,
7885                 (void *)&cmd_set_uc_all_hash_port,
7886                 (void *)&cmd_set_uc_all_hash_portid,
7887                 (void *)&cmd_set_uc_all_hash_what,
7888                 (void *)&cmd_set_uc_all_hash_value,
7889                 (void *)&cmd_set_uc_all_hash_mode,
7890                 NULL,
7891         },
7892 };
7893
7894 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7895 struct cmd_set_vf_macvlan_filter {
7896         cmdline_fixed_string_t set;
7897         cmdline_fixed_string_t port;
7898         portid_t port_id;
7899         cmdline_fixed_string_t vf;
7900         uint8_t vf_id;
7901         struct ether_addr address;
7902         cmdline_fixed_string_t filter_type;
7903         cmdline_fixed_string_t mode;
7904 };
7905
7906 static void
7907 cmd_set_vf_macvlan_parsed(void *parsed_result,
7908                        __attribute__((unused)) struct cmdline *cl,
7909                        __attribute__((unused)) void *data)
7910 {
7911         int is_on, ret = 0;
7912         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7913         struct rte_eth_mac_filter filter;
7914
7915         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7916
7917         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7918
7919         /* set VF MAC filter */
7920         filter.is_vf = 1;
7921
7922         /* set VF ID */
7923         filter.dst_id = res->vf_id;
7924
7925         if (!strcmp(res->filter_type, "exact-mac"))
7926                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7927         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7928                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7929         else if (!strcmp(res->filter_type, "hashmac"))
7930                 filter.filter_type = RTE_MAC_HASH_MATCH;
7931         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7932                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7933
7934         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7935
7936         if (is_on)
7937                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7938                                         RTE_ETH_FILTER_MACVLAN,
7939                                         RTE_ETH_FILTER_ADD,
7940                                          &filter);
7941         else
7942                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7943                                         RTE_ETH_FILTER_MACVLAN,
7944                                         RTE_ETH_FILTER_DELETE,
7945                                         &filter);
7946
7947         if (ret < 0)
7948                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7949
7950 }
7951
7952 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7953         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7954                                  set, "set");
7955 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7956         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7957                                  port, "port");
7958 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7959         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7960                               port_id, UINT16);
7961 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7962         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7963                                  vf, "vf");
7964 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7965         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7966                                 vf_id, UINT8);
7967 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7968         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7969                                 address);
7970 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7971         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7972                                 filter_type, "exact-mac#exact-mac-vlan"
7973                                 "#hashmac#hashmac-vlan");
7974 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7975         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7976                                  mode, "on#off");
7977
7978 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7979         .f = cmd_set_vf_macvlan_parsed,
7980         .data = NULL,
7981         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7982                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7983                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7984                 "hash match rule: hash match of MAC and exact match of VLAN",
7985         .tokens = {
7986                 (void *)&cmd_set_vf_macvlan_set,
7987                 (void *)&cmd_set_vf_macvlan_port,
7988                 (void *)&cmd_set_vf_macvlan_portid,
7989                 (void *)&cmd_set_vf_macvlan_vf,
7990                 (void *)&cmd_set_vf_macvlan_vf_id,
7991                 (void *)&cmd_set_vf_macvlan_mac,
7992                 (void *)&cmd_set_vf_macvlan_filter_type,
7993                 (void *)&cmd_set_vf_macvlan_mode,
7994                 NULL,
7995         },
7996 };
7997
7998 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7999 struct cmd_set_vf_traffic {
8000         cmdline_fixed_string_t set;
8001         cmdline_fixed_string_t port;
8002         portid_t port_id;
8003         cmdline_fixed_string_t vf;
8004         uint8_t vf_id;
8005         cmdline_fixed_string_t what;
8006         cmdline_fixed_string_t mode;
8007 };
8008
8009 static void
8010 cmd_set_vf_traffic_parsed(void *parsed_result,
8011                        __attribute__((unused)) struct cmdline *cl,
8012                        __attribute__((unused)) void *data)
8013 {
8014         struct cmd_set_vf_traffic *res = parsed_result;
8015         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8016         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8017
8018         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8019 }
8020
8021 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8022         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8023                                  set, "set");
8024 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8025         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8026                                  port, "port");
8027 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8028         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8029                               port_id, UINT16);
8030 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8031         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8032                                  vf, "vf");
8033 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8034         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8035                               vf_id, UINT8);
8036 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8037         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8038                                  what, "tx#rx");
8039 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8040         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8041                                  mode, "on#off");
8042
8043 cmdline_parse_inst_t cmd_set_vf_traffic = {
8044         .f = cmd_set_vf_traffic_parsed,
8045         .data = NULL,
8046         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8047         .tokens = {
8048                 (void *)&cmd_setvf_traffic_set,
8049                 (void *)&cmd_setvf_traffic_port,
8050                 (void *)&cmd_setvf_traffic_portid,
8051                 (void *)&cmd_setvf_traffic_vf,
8052                 (void *)&cmd_setvf_traffic_vfid,
8053                 (void *)&cmd_setvf_traffic_what,
8054                 (void *)&cmd_setvf_traffic_mode,
8055                 NULL,
8056         },
8057 };
8058
8059 /* *** CONFIGURE VF RECEIVE MODE *** */
8060 struct cmd_set_vf_rxmode {
8061         cmdline_fixed_string_t set;
8062         cmdline_fixed_string_t port;
8063         portid_t port_id;
8064         cmdline_fixed_string_t vf;
8065         uint8_t vf_id;
8066         cmdline_fixed_string_t what;
8067         cmdline_fixed_string_t mode;
8068         cmdline_fixed_string_t on;
8069 };
8070
8071 static void
8072 cmd_set_vf_rxmode_parsed(void *parsed_result,
8073                        __attribute__((unused)) struct cmdline *cl,
8074                        __attribute__((unused)) void *data)
8075 {
8076         int ret = -ENOTSUP;
8077         uint16_t rx_mode = 0;
8078         struct cmd_set_vf_rxmode *res = parsed_result;
8079
8080         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8081         if (!strcmp(res->what,"rxmode")) {
8082                 if (!strcmp(res->mode, "AUPE"))
8083                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8084                 else if (!strcmp(res->mode, "ROPE"))
8085                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8086                 else if (!strcmp(res->mode, "BAM"))
8087                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8088                 else if (!strncmp(res->mode, "MPE",3))
8089                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8090         }
8091
8092         RTE_SET_USED(is_on);
8093
8094 #ifdef RTE_LIBRTE_IXGBE_PMD
8095         if (ret == -ENOTSUP)
8096                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8097                                                   rx_mode, (uint8_t)is_on);
8098 #endif
8099 #ifdef RTE_LIBRTE_BNXT_PMD
8100         if (ret == -ENOTSUP)
8101                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8102                                                  rx_mode, (uint8_t)is_on);
8103 #endif
8104         if (ret < 0)
8105                 printf("bad VF receive mode parameter, return code = %d \n",
8106                 ret);
8107 }
8108
8109 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8110         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8111                                  set, "set");
8112 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8113         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8114                                  port, "port");
8115 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8116         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8117                               port_id, UINT16);
8118 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8119         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8120                                  vf, "vf");
8121 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8122         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8123                               vf_id, UINT8);
8124 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8125         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8126                                  what, "rxmode");
8127 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8128         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8129                                  mode, "AUPE#ROPE#BAM#MPE");
8130 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8131         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8132                                  on, "on#off");
8133
8134 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8135         .f = cmd_set_vf_rxmode_parsed,
8136         .data = NULL,
8137         .help_str = "set port <port_id> vf <vf_id> rxmode "
8138                 "AUPE|ROPE|BAM|MPE on|off",
8139         .tokens = {
8140                 (void *)&cmd_set_vf_rxmode_set,
8141                 (void *)&cmd_set_vf_rxmode_port,
8142                 (void *)&cmd_set_vf_rxmode_portid,
8143                 (void *)&cmd_set_vf_rxmode_vf,
8144                 (void *)&cmd_set_vf_rxmode_vfid,
8145                 (void *)&cmd_set_vf_rxmode_what,
8146                 (void *)&cmd_set_vf_rxmode_mode,
8147                 (void *)&cmd_set_vf_rxmode_on,
8148                 NULL,
8149         },
8150 };
8151
8152 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8153 struct cmd_vf_mac_addr_result {
8154         cmdline_fixed_string_t mac_addr_cmd;
8155         cmdline_fixed_string_t what;
8156         cmdline_fixed_string_t port;
8157         uint16_t port_num;
8158         cmdline_fixed_string_t vf;
8159         uint8_t vf_num;
8160         struct ether_addr address;
8161 };
8162
8163 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8164                 __attribute__((unused)) struct cmdline *cl,
8165                 __attribute__((unused)) void *data)
8166 {
8167         struct cmd_vf_mac_addr_result *res = parsed_result;
8168         int ret = -ENOTSUP;
8169
8170         if (strcmp(res->what, "add") != 0)
8171                 return;
8172
8173 #ifdef RTE_LIBRTE_I40E_PMD
8174         if (ret == -ENOTSUP)
8175                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8176                                                    &res->address);
8177 #endif
8178 #ifdef RTE_LIBRTE_BNXT_PMD
8179         if (ret == -ENOTSUP)
8180                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8181                                                 res->vf_num);
8182 #endif
8183
8184         if(ret < 0)
8185                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8186
8187 }
8188
8189 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8190         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8191                                 mac_addr_cmd,"mac_addr");
8192 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8193         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8194                                 what,"add");
8195 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8196         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8197                                 port,"port");
8198 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8199         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8200                                 port_num, UINT16);
8201 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8202         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8203                                 vf,"vf");
8204 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8205         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8206                                 vf_num, UINT8);
8207 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8208         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8209                                 address);
8210
8211 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8212         .f = cmd_vf_mac_addr_parsed,
8213         .data = (void *)0,
8214         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8215                 "Add MAC address filtering for a VF on port_id",
8216         .tokens = {
8217                 (void *)&cmd_vf_mac_addr_cmd,
8218                 (void *)&cmd_vf_mac_addr_what,
8219                 (void *)&cmd_vf_mac_addr_port,
8220                 (void *)&cmd_vf_mac_addr_portnum,
8221                 (void *)&cmd_vf_mac_addr_vf,
8222                 (void *)&cmd_vf_mac_addr_vfnum,
8223                 (void *)&cmd_vf_mac_addr_addr,
8224                 NULL,
8225         },
8226 };
8227
8228 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8229 struct cmd_vf_rx_vlan_filter {
8230         cmdline_fixed_string_t rx_vlan;
8231         cmdline_fixed_string_t what;
8232         uint16_t vlan_id;
8233         cmdline_fixed_string_t port;
8234         portid_t port_id;
8235         cmdline_fixed_string_t vf;
8236         uint64_t vf_mask;
8237 };
8238
8239 static void
8240 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8241                           __attribute__((unused)) struct cmdline *cl,
8242                           __attribute__((unused)) void *data)
8243 {
8244         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8245         int ret = -ENOTSUP;
8246
8247         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8248
8249 #ifdef RTE_LIBRTE_IXGBE_PMD
8250         if (ret == -ENOTSUP)
8251                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8252                                 res->vlan_id, res->vf_mask, is_add);
8253 #endif
8254 #ifdef RTE_LIBRTE_I40E_PMD
8255         if (ret == -ENOTSUP)
8256                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8257                                 res->vlan_id, res->vf_mask, is_add);
8258 #endif
8259 #ifdef RTE_LIBRTE_BNXT_PMD
8260         if (ret == -ENOTSUP)
8261                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8262                                 res->vlan_id, res->vf_mask, is_add);
8263 #endif
8264
8265         switch (ret) {
8266         case 0:
8267                 break;
8268         case -EINVAL:
8269                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8270                                 res->vlan_id, res->vf_mask);
8271                 break;
8272         case -ENODEV:
8273                 printf("invalid port_id %d\n", res->port_id);
8274                 break;
8275         case -ENOTSUP:
8276                 printf("function not implemented or supported\n");
8277                 break;
8278         default:
8279                 printf("programming error: (%s)\n", strerror(-ret));
8280         }
8281 }
8282
8283 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8284         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8285                                  rx_vlan, "rx_vlan");
8286 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8287         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8288                                  what, "add#rm");
8289 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8290         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8291                               vlan_id, UINT16);
8292 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8293         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8294                                  port, "port");
8295 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8296         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8297                               port_id, UINT16);
8298 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8299         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8300                                  vf, "vf");
8301 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8302         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8303                               vf_mask, UINT64);
8304
8305 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8306         .f = cmd_vf_rx_vlan_filter_parsed,
8307         .data = NULL,
8308         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8309                 "(vf_mask = hexadecimal VF mask)",
8310         .tokens = {
8311                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8312                 (void *)&cmd_vf_rx_vlan_filter_what,
8313                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8314                 (void *)&cmd_vf_rx_vlan_filter_port,
8315                 (void *)&cmd_vf_rx_vlan_filter_portid,
8316                 (void *)&cmd_vf_rx_vlan_filter_vf,
8317                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8318                 NULL,
8319         },
8320 };
8321
8322 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8323 struct cmd_queue_rate_limit_result {
8324         cmdline_fixed_string_t set;
8325         cmdline_fixed_string_t port;
8326         uint16_t port_num;
8327         cmdline_fixed_string_t queue;
8328         uint8_t queue_num;
8329         cmdline_fixed_string_t rate;
8330         uint16_t rate_num;
8331 };
8332
8333 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8334                 __attribute__((unused)) struct cmdline *cl,
8335                 __attribute__((unused)) void *data)
8336 {
8337         struct cmd_queue_rate_limit_result *res = parsed_result;
8338         int ret = 0;
8339
8340         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8341                 && (strcmp(res->queue, "queue") == 0)
8342                 && (strcmp(res->rate, "rate") == 0))
8343                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8344                                         res->rate_num);
8345         if (ret < 0)
8346                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8347
8348 }
8349
8350 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8351         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8352                                 set, "set");
8353 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8354         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8355                                 port, "port");
8356 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8357         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8358                                 port_num, UINT16);
8359 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8360         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8361                                 queue, "queue");
8362 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8363         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8364                                 queue_num, UINT8);
8365 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8366         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8367                                 rate, "rate");
8368 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8369         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8370                                 rate_num, UINT16);
8371
8372 cmdline_parse_inst_t cmd_queue_rate_limit = {
8373         .f = cmd_queue_rate_limit_parsed,
8374         .data = (void *)0,
8375         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8376                 "Set rate limit for a queue on port_id",
8377         .tokens = {
8378                 (void *)&cmd_queue_rate_limit_set,
8379                 (void *)&cmd_queue_rate_limit_port,
8380                 (void *)&cmd_queue_rate_limit_portnum,
8381                 (void *)&cmd_queue_rate_limit_queue,
8382                 (void *)&cmd_queue_rate_limit_queuenum,
8383                 (void *)&cmd_queue_rate_limit_rate,
8384                 (void *)&cmd_queue_rate_limit_ratenum,
8385                 NULL,
8386         },
8387 };
8388
8389 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8390 struct cmd_vf_rate_limit_result {
8391         cmdline_fixed_string_t set;
8392         cmdline_fixed_string_t port;
8393         uint16_t port_num;
8394         cmdline_fixed_string_t vf;
8395         uint8_t vf_num;
8396         cmdline_fixed_string_t rate;
8397         uint16_t rate_num;
8398         cmdline_fixed_string_t q_msk;
8399         uint64_t q_msk_val;
8400 };
8401
8402 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8403                 __attribute__((unused)) struct cmdline *cl,
8404                 __attribute__((unused)) void *data)
8405 {
8406         struct cmd_vf_rate_limit_result *res = parsed_result;
8407         int ret = 0;
8408
8409         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8410                 && (strcmp(res->vf, "vf") == 0)
8411                 && (strcmp(res->rate, "rate") == 0)
8412                 && (strcmp(res->q_msk, "queue_mask") == 0))
8413                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8414                                         res->rate_num, res->q_msk_val);
8415         if (ret < 0)
8416                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8417
8418 }
8419
8420 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8421         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8422                                 set, "set");
8423 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8424         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8425                                 port, "port");
8426 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8427         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8428                                 port_num, UINT16);
8429 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8430         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8431                                 vf, "vf");
8432 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8433         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8434                                 vf_num, UINT8);
8435 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8436         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8437                                 rate, "rate");
8438 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8439         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8440                                 rate_num, UINT16);
8441 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8442         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8443                                 q_msk, "queue_mask");
8444 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8445         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8446                                 q_msk_val, UINT64);
8447
8448 cmdline_parse_inst_t cmd_vf_rate_limit = {
8449         .f = cmd_vf_rate_limit_parsed,
8450         .data = (void *)0,
8451         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8452                 "queue_mask <queue_mask_value>: "
8453                 "Set rate limit for queues of VF on port_id",
8454         .tokens = {
8455                 (void *)&cmd_vf_rate_limit_set,
8456                 (void *)&cmd_vf_rate_limit_port,
8457                 (void *)&cmd_vf_rate_limit_portnum,
8458                 (void *)&cmd_vf_rate_limit_vf,
8459                 (void *)&cmd_vf_rate_limit_vfnum,
8460                 (void *)&cmd_vf_rate_limit_rate,
8461                 (void *)&cmd_vf_rate_limit_ratenum,
8462                 (void *)&cmd_vf_rate_limit_q_msk,
8463                 (void *)&cmd_vf_rate_limit_q_msk_val,
8464                 NULL,
8465         },
8466 };
8467
8468 /* *** ADD TUNNEL FILTER OF A PORT *** */
8469 struct cmd_tunnel_filter_result {
8470         cmdline_fixed_string_t cmd;
8471         cmdline_fixed_string_t what;
8472         portid_t port_id;
8473         struct ether_addr outer_mac;
8474         struct ether_addr inner_mac;
8475         cmdline_ipaddr_t ip_value;
8476         uint16_t inner_vlan;
8477         cmdline_fixed_string_t tunnel_type;
8478         cmdline_fixed_string_t filter_type;
8479         uint32_t tenant_id;
8480         uint16_t queue_num;
8481 };
8482
8483 static void
8484 cmd_tunnel_filter_parsed(void *parsed_result,
8485                           __attribute__((unused)) struct cmdline *cl,
8486                           __attribute__((unused)) void *data)
8487 {
8488         struct cmd_tunnel_filter_result *res = parsed_result;
8489         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8490         int ret = 0;
8491
8492         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8493
8494         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8495         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8496         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8497
8498         if (res->ip_value.family == AF_INET) {
8499                 tunnel_filter_conf.ip_addr.ipv4_addr =
8500                         res->ip_value.addr.ipv4.s_addr;
8501                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8502         } else {
8503                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8504                         &(res->ip_value.addr.ipv6),
8505                         sizeof(struct in6_addr));
8506                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8507         }
8508
8509         if (!strcmp(res->filter_type, "imac-ivlan"))
8510                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8511         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8512                 tunnel_filter_conf.filter_type =
8513                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8514         else if (!strcmp(res->filter_type, "imac-tenid"))
8515                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8516         else if (!strcmp(res->filter_type, "imac"))
8517                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8518         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8519                 tunnel_filter_conf.filter_type =
8520                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8521         else if (!strcmp(res->filter_type, "oip"))
8522                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8523         else if (!strcmp(res->filter_type, "iip"))
8524                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8525         else {
8526                 printf("The filter type is not supported");
8527                 return;
8528         }
8529
8530         if (!strcmp(res->tunnel_type, "vxlan"))
8531                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8532         else if (!strcmp(res->tunnel_type, "nvgre"))
8533                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8534         else if (!strcmp(res->tunnel_type, "ipingre"))
8535                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8536         else {
8537                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8538                 return;
8539         }
8540
8541         tunnel_filter_conf.tenant_id = res->tenant_id;
8542         tunnel_filter_conf.queue_id = res->queue_num;
8543         if (!strcmp(res->what, "add"))
8544                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8545                                         RTE_ETH_FILTER_TUNNEL,
8546                                         RTE_ETH_FILTER_ADD,
8547                                         &tunnel_filter_conf);
8548         else
8549                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8550                                         RTE_ETH_FILTER_TUNNEL,
8551                                         RTE_ETH_FILTER_DELETE,
8552                                         &tunnel_filter_conf);
8553         if (ret < 0)
8554                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8555                                 strerror(-ret));
8556
8557 }
8558 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8559         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8560         cmd, "tunnel_filter");
8561 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8562         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8563         what, "add#rm");
8564 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8565         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8566         port_id, UINT16);
8567 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8568         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8569         outer_mac);
8570 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8571         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8572         inner_mac);
8573 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8574         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8575         inner_vlan, UINT16);
8576 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8577         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8578         ip_value);
8579 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8580         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8581         tunnel_type, "vxlan#nvgre#ipingre");
8582
8583 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8584         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8585         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8586                 "imac#omac-imac-tenid");
8587 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8588         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8589         tenant_id, UINT32);
8590 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8591         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8592         queue_num, UINT16);
8593
8594 cmdline_parse_inst_t cmd_tunnel_filter = {
8595         .f = cmd_tunnel_filter_parsed,
8596         .data = (void *)0,
8597         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8598                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8599                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8600                 "<queue_id>: Add/Rm tunnel filter of a port",
8601         .tokens = {
8602                 (void *)&cmd_tunnel_filter_cmd,
8603                 (void *)&cmd_tunnel_filter_what,
8604                 (void *)&cmd_tunnel_filter_port_id,
8605                 (void *)&cmd_tunnel_filter_outer_mac,
8606                 (void *)&cmd_tunnel_filter_inner_mac,
8607                 (void *)&cmd_tunnel_filter_ip_value,
8608                 (void *)&cmd_tunnel_filter_innner_vlan,
8609                 (void *)&cmd_tunnel_filter_tunnel_type,
8610                 (void *)&cmd_tunnel_filter_filter_type,
8611                 (void *)&cmd_tunnel_filter_tenant_id,
8612                 (void *)&cmd_tunnel_filter_queue_num,
8613                 NULL,
8614         },
8615 };
8616
8617 /* *** CONFIGURE TUNNEL UDP PORT *** */
8618 struct cmd_tunnel_udp_config {
8619         cmdline_fixed_string_t cmd;
8620         cmdline_fixed_string_t what;
8621         uint16_t udp_port;
8622         portid_t port_id;
8623 };
8624
8625 static void
8626 cmd_tunnel_udp_config_parsed(void *parsed_result,
8627                           __attribute__((unused)) struct cmdline *cl,
8628                           __attribute__((unused)) void *data)
8629 {
8630         struct cmd_tunnel_udp_config *res = parsed_result;
8631         struct rte_eth_udp_tunnel tunnel_udp;
8632         int ret;
8633
8634         tunnel_udp.udp_port = res->udp_port;
8635
8636         if (!strcmp(res->cmd, "rx_vxlan_port"))
8637                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8638
8639         if (!strcmp(res->what, "add"))
8640                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8641                                                       &tunnel_udp);
8642         else
8643                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8644                                                          &tunnel_udp);
8645
8646         if (ret < 0)
8647                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8648 }
8649
8650 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8651         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8652                                 cmd, "rx_vxlan_port");
8653 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8654         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8655                                 what, "add#rm");
8656 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8657         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8658                                 udp_port, UINT16);
8659 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8660         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8661                                 port_id, UINT16);
8662
8663 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8664         .f = cmd_tunnel_udp_config_parsed,
8665         .data = (void *)0,
8666         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8667                 "Add/Remove a tunneling UDP port filter",
8668         .tokens = {
8669                 (void *)&cmd_tunnel_udp_config_cmd,
8670                 (void *)&cmd_tunnel_udp_config_what,
8671                 (void *)&cmd_tunnel_udp_config_udp_port,
8672                 (void *)&cmd_tunnel_udp_config_port_id,
8673                 NULL,
8674         },
8675 };
8676
8677 struct cmd_config_tunnel_udp_port {
8678         cmdline_fixed_string_t port;
8679         cmdline_fixed_string_t config;
8680         portid_t port_id;
8681         cmdline_fixed_string_t udp_tunnel_port;
8682         cmdline_fixed_string_t action;
8683         cmdline_fixed_string_t tunnel_type;
8684         uint16_t udp_port;
8685 };
8686
8687 static void
8688 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8689                                __attribute__((unused)) struct cmdline *cl,
8690                                __attribute__((unused)) void *data)
8691 {
8692         struct cmd_config_tunnel_udp_port *res = parsed_result;
8693         struct rte_eth_udp_tunnel tunnel_udp;
8694         int ret = 0;
8695
8696         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8697                 return;
8698
8699         tunnel_udp.udp_port = res->udp_port;
8700
8701         if (!strcmp(res->tunnel_type, "vxlan")) {
8702                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8703         } else if (!strcmp(res->tunnel_type, "geneve")) {
8704                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8705         } else {
8706                 printf("Invalid tunnel type\n");
8707                 return;
8708         }
8709
8710         if (!strcmp(res->action, "add"))
8711                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8712                                                       &tunnel_udp);
8713         else
8714                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8715                                                          &tunnel_udp);
8716
8717         if (ret < 0)
8718                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8719 }
8720
8721 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8722         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8723                                  "port");
8724 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8725         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8726                                  "config");
8727 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8728         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8729                               UINT16);
8730 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8731         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8732                                  udp_tunnel_port,
8733                                  "udp_tunnel_port");
8734 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8735         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8736                                  "add#rm");
8737 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8738         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8739                                  "vxlan#geneve");
8740 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8741         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8742                               UINT16);
8743
8744 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8745         .f = cmd_cfg_tunnel_udp_port_parsed,
8746         .data = NULL,
8747         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8748         .tokens = {
8749                 (void *)&cmd_config_tunnel_udp_port_port,
8750                 (void *)&cmd_config_tunnel_udp_port_config,
8751                 (void *)&cmd_config_tunnel_udp_port_port_id,
8752                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8753                 (void *)&cmd_config_tunnel_udp_port_action,
8754                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8755                 (void *)&cmd_config_tunnel_udp_port_value,
8756                 NULL,
8757         },
8758 };
8759
8760 /* *** GLOBAL CONFIG *** */
8761 struct cmd_global_config_result {
8762         cmdline_fixed_string_t cmd;
8763         portid_t port_id;
8764         cmdline_fixed_string_t cfg_type;
8765         uint8_t len;
8766 };
8767
8768 static void
8769 cmd_global_config_parsed(void *parsed_result,
8770                          __attribute__((unused)) struct cmdline *cl,
8771                          __attribute__((unused)) void *data)
8772 {
8773         struct cmd_global_config_result *res = parsed_result;
8774         struct rte_eth_global_cfg conf;
8775         int ret;
8776
8777         memset(&conf, 0, sizeof(conf));
8778         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8779         conf.cfg.gre_key_len = res->len;
8780         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8781                                       RTE_ETH_FILTER_SET, &conf);
8782         if (ret != 0)
8783                 printf("Global config error\n");
8784 }
8785
8786 cmdline_parse_token_string_t cmd_global_config_cmd =
8787         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8788                 "global_config");
8789 cmdline_parse_token_num_t cmd_global_config_port_id =
8790         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8791                                UINT16);
8792 cmdline_parse_token_string_t cmd_global_config_type =
8793         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8794                 cfg_type, "gre-key-len");
8795 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8796         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8797                 len, UINT8);
8798
8799 cmdline_parse_inst_t cmd_global_config = {
8800         .f = cmd_global_config_parsed,
8801         .data = (void *)NULL,
8802         .help_str = "global_config <port_id> gre-key-len <key_len>",
8803         .tokens = {
8804                 (void *)&cmd_global_config_cmd,
8805                 (void *)&cmd_global_config_port_id,
8806                 (void *)&cmd_global_config_type,
8807                 (void *)&cmd_global_config_gre_key_len,
8808                 NULL,
8809         },
8810 };
8811
8812 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8813 struct cmd_set_mirror_mask_result {
8814         cmdline_fixed_string_t set;
8815         cmdline_fixed_string_t port;
8816         portid_t port_id;
8817         cmdline_fixed_string_t mirror;
8818         uint8_t rule_id;
8819         cmdline_fixed_string_t what;
8820         cmdline_fixed_string_t value;
8821         cmdline_fixed_string_t dstpool;
8822         uint8_t dstpool_id;
8823         cmdline_fixed_string_t on;
8824 };
8825
8826 cmdline_parse_token_string_t cmd_mirror_mask_set =
8827         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8828                                 set, "set");
8829 cmdline_parse_token_string_t cmd_mirror_mask_port =
8830         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8831                                 port, "port");
8832 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8833         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8834                                 port_id, UINT16);
8835 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8836         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8837                                 mirror, "mirror-rule");
8838 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8839         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8840                                 rule_id, UINT8);
8841 cmdline_parse_token_string_t cmd_mirror_mask_what =
8842         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8843                                 what, "pool-mirror-up#pool-mirror-down"
8844                                       "#vlan-mirror");
8845 cmdline_parse_token_string_t cmd_mirror_mask_value =
8846         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8847                                 value, NULL);
8848 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8849         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8850                                 dstpool, "dst-pool");
8851 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8852         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8853                                 dstpool_id, UINT8);
8854 cmdline_parse_token_string_t cmd_mirror_mask_on =
8855         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8856                                 on, "on#off");
8857
8858 static void
8859 cmd_set_mirror_mask_parsed(void *parsed_result,
8860                        __attribute__((unused)) struct cmdline *cl,
8861                        __attribute__((unused)) void *data)
8862 {
8863         int ret,nb_item,i;
8864         struct cmd_set_mirror_mask_result *res = parsed_result;
8865         struct rte_eth_mirror_conf mr_conf;
8866
8867         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8868
8869         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8870
8871         mr_conf.dst_pool = res->dstpool_id;
8872
8873         if (!strcmp(res->what, "pool-mirror-up")) {
8874                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8875                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8876         } else if (!strcmp(res->what, "pool-mirror-down")) {
8877                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8878                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8879         } else if (!strcmp(res->what, "vlan-mirror")) {
8880                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8881                 nb_item = parse_item_list(res->value, "vlan",
8882                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8883                 if (nb_item <= 0)
8884                         return;
8885
8886                 for (i = 0; i < nb_item; i++) {
8887                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8888                                 printf("Invalid vlan_id: must be < 4096\n");
8889                                 return;
8890                         }
8891
8892                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8893                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8894                 }
8895         }
8896
8897         if (!strcmp(res->on, "on"))
8898                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8899                                                 res->rule_id, 1);
8900         else
8901                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8902                                                 res->rule_id, 0);
8903         if (ret < 0)
8904                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8905 }
8906
8907 cmdline_parse_inst_t cmd_set_mirror_mask = {
8908                 .f = cmd_set_mirror_mask_parsed,
8909                 .data = NULL,
8910                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8911                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8912                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8913                 .tokens = {
8914                         (void *)&cmd_mirror_mask_set,
8915                         (void *)&cmd_mirror_mask_port,
8916                         (void *)&cmd_mirror_mask_portid,
8917                         (void *)&cmd_mirror_mask_mirror,
8918                         (void *)&cmd_mirror_mask_ruleid,
8919                         (void *)&cmd_mirror_mask_what,
8920                         (void *)&cmd_mirror_mask_value,
8921                         (void *)&cmd_mirror_mask_dstpool,
8922                         (void *)&cmd_mirror_mask_poolid,
8923                         (void *)&cmd_mirror_mask_on,
8924                         NULL,
8925                 },
8926 };
8927
8928 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8929 struct cmd_set_mirror_link_result {
8930         cmdline_fixed_string_t set;
8931         cmdline_fixed_string_t port;
8932         portid_t port_id;
8933         cmdline_fixed_string_t mirror;
8934         uint8_t rule_id;
8935         cmdline_fixed_string_t what;
8936         cmdline_fixed_string_t dstpool;
8937         uint8_t dstpool_id;
8938         cmdline_fixed_string_t on;
8939 };
8940
8941 cmdline_parse_token_string_t cmd_mirror_link_set =
8942         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8943                                  set, "set");
8944 cmdline_parse_token_string_t cmd_mirror_link_port =
8945         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8946                                 port, "port");
8947 cmdline_parse_token_num_t cmd_mirror_link_portid =
8948         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8949                                 port_id, UINT16);
8950 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8951         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8952                                 mirror, "mirror-rule");
8953 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8954         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8955                             rule_id, UINT8);
8956 cmdline_parse_token_string_t cmd_mirror_link_what =
8957         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8958                                 what, "uplink-mirror#downlink-mirror");
8959 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8960         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8961                                 dstpool, "dst-pool");
8962 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8963         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8964                                 dstpool_id, UINT8);
8965 cmdline_parse_token_string_t cmd_mirror_link_on =
8966         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8967                                 on, "on#off");
8968
8969 static void
8970 cmd_set_mirror_link_parsed(void *parsed_result,
8971                        __attribute__((unused)) struct cmdline *cl,
8972                        __attribute__((unused)) void *data)
8973 {
8974         int ret;
8975         struct cmd_set_mirror_link_result *res = parsed_result;
8976         struct rte_eth_mirror_conf mr_conf;
8977
8978         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8979         if (!strcmp(res->what, "uplink-mirror"))
8980                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8981         else
8982                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8983
8984         mr_conf.dst_pool = res->dstpool_id;
8985
8986         if (!strcmp(res->on, "on"))
8987                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8988                                                 res->rule_id, 1);
8989         else
8990                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8991                                                 res->rule_id, 0);
8992
8993         /* check the return value and print it if is < 0 */
8994         if (ret < 0)
8995                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8996
8997 }
8998
8999 cmdline_parse_inst_t cmd_set_mirror_link = {
9000                 .f = cmd_set_mirror_link_parsed,
9001                 .data = NULL,
9002                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9003                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9004                 .tokens = {
9005                         (void *)&cmd_mirror_link_set,
9006                         (void *)&cmd_mirror_link_port,
9007                         (void *)&cmd_mirror_link_portid,
9008                         (void *)&cmd_mirror_link_mirror,
9009                         (void *)&cmd_mirror_link_ruleid,
9010                         (void *)&cmd_mirror_link_what,
9011                         (void *)&cmd_mirror_link_dstpool,
9012                         (void *)&cmd_mirror_link_poolid,
9013                         (void *)&cmd_mirror_link_on,
9014                         NULL,
9015                 },
9016 };
9017
9018 /* *** RESET VM MIRROR RULE *** */
9019 struct cmd_rm_mirror_rule_result {
9020         cmdline_fixed_string_t reset;
9021         cmdline_fixed_string_t port;
9022         portid_t port_id;
9023         cmdline_fixed_string_t mirror;
9024         uint8_t rule_id;
9025 };
9026
9027 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9028         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9029                                  reset, "reset");
9030 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9031         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9032                                 port, "port");
9033 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9034         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9035                                 port_id, UINT16);
9036 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9037         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9038                                 mirror, "mirror-rule");
9039 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9040         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9041                                 rule_id, UINT8);
9042
9043 static void
9044 cmd_reset_mirror_rule_parsed(void *parsed_result,
9045                        __attribute__((unused)) struct cmdline *cl,
9046                        __attribute__((unused)) void *data)
9047 {
9048         int ret;
9049         struct cmd_set_mirror_link_result *res = parsed_result;
9050         /* check rule_id */
9051         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9052         if(ret < 0)
9053                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9054 }
9055
9056 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9057                 .f = cmd_reset_mirror_rule_parsed,
9058                 .data = NULL,
9059                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9060                 .tokens = {
9061                         (void *)&cmd_rm_mirror_rule_reset,
9062                         (void *)&cmd_rm_mirror_rule_port,
9063                         (void *)&cmd_rm_mirror_rule_portid,
9064                         (void *)&cmd_rm_mirror_rule_mirror,
9065                         (void *)&cmd_rm_mirror_rule_ruleid,
9066                         NULL,
9067                 },
9068 };
9069
9070 /* ******************************************************************************** */
9071
9072 struct cmd_dump_result {
9073         cmdline_fixed_string_t dump;
9074 };
9075
9076 static void
9077 dump_struct_sizes(void)
9078 {
9079 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9080         DUMP_SIZE(struct rte_mbuf);
9081         DUMP_SIZE(struct rte_mempool);
9082         DUMP_SIZE(struct rte_ring);
9083 #undef DUMP_SIZE
9084 }
9085
9086 static void cmd_dump_parsed(void *parsed_result,
9087                             __attribute__((unused)) struct cmdline *cl,
9088                             __attribute__((unused)) void *data)
9089 {
9090         struct cmd_dump_result *res = parsed_result;
9091
9092         if (!strcmp(res->dump, "dump_physmem"))
9093                 rte_dump_physmem_layout(stdout);
9094         else if (!strcmp(res->dump, "dump_memzone"))
9095                 rte_memzone_dump(stdout);
9096         else if (!strcmp(res->dump, "dump_struct_sizes"))
9097                 dump_struct_sizes();
9098         else if (!strcmp(res->dump, "dump_ring"))
9099                 rte_ring_list_dump(stdout);
9100         else if (!strcmp(res->dump, "dump_mempool"))
9101                 rte_mempool_list_dump(stdout);
9102         else if (!strcmp(res->dump, "dump_devargs"))
9103                 rte_devargs_dump(stdout);
9104         else if (!strcmp(res->dump, "dump_log_types"))
9105                 rte_log_dump(stdout);
9106 }
9107
9108 cmdline_parse_token_string_t cmd_dump_dump =
9109         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9110                 "dump_physmem#"
9111                 "dump_memzone#"
9112                 "dump_struct_sizes#"
9113                 "dump_ring#"
9114                 "dump_mempool#"
9115                 "dump_devargs#"
9116                 "dump_log_types");
9117
9118 cmdline_parse_inst_t cmd_dump = {
9119         .f = cmd_dump_parsed,  /* function to call */
9120         .data = NULL,      /* 2nd arg of func */
9121         .help_str = "Dump status",
9122         .tokens = {        /* token list, NULL terminated */
9123                 (void *)&cmd_dump_dump,
9124                 NULL,
9125         },
9126 };
9127
9128 /* ******************************************************************************** */
9129
9130 struct cmd_dump_one_result {
9131         cmdline_fixed_string_t dump;
9132         cmdline_fixed_string_t name;
9133 };
9134
9135 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9136                                 __attribute__((unused)) void *data)
9137 {
9138         struct cmd_dump_one_result *res = parsed_result;
9139
9140         if (!strcmp(res->dump, "dump_ring")) {
9141                 struct rte_ring *r;
9142                 r = rte_ring_lookup(res->name);
9143                 if (r == NULL) {
9144                         cmdline_printf(cl, "Cannot find ring\n");
9145                         return;
9146                 }
9147                 rte_ring_dump(stdout, r);
9148         } else if (!strcmp(res->dump, "dump_mempool")) {
9149                 struct rte_mempool *mp;
9150                 mp = rte_mempool_lookup(res->name);
9151                 if (mp == NULL) {
9152                         cmdline_printf(cl, "Cannot find mempool\n");
9153                         return;
9154                 }
9155                 rte_mempool_dump(stdout, mp);
9156         }
9157 }
9158
9159 cmdline_parse_token_string_t cmd_dump_one_dump =
9160         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9161                                  "dump_ring#dump_mempool");
9162
9163 cmdline_parse_token_string_t cmd_dump_one_name =
9164         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9165
9166 cmdline_parse_inst_t cmd_dump_one = {
9167         .f = cmd_dump_one_parsed,  /* function to call */
9168         .data = NULL,      /* 2nd arg of func */
9169         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9170         .tokens = {        /* token list, NULL terminated */
9171                 (void *)&cmd_dump_one_dump,
9172                 (void *)&cmd_dump_one_name,
9173                 NULL,
9174         },
9175 };
9176
9177 /* *** Add/Del syn filter *** */
9178 struct cmd_syn_filter_result {
9179         cmdline_fixed_string_t filter;
9180         portid_t port_id;
9181         cmdline_fixed_string_t ops;
9182         cmdline_fixed_string_t priority;
9183         cmdline_fixed_string_t high;
9184         cmdline_fixed_string_t queue;
9185         uint16_t queue_id;
9186 };
9187
9188 static void
9189 cmd_syn_filter_parsed(void *parsed_result,
9190                         __attribute__((unused)) struct cmdline *cl,
9191                         __attribute__((unused)) void *data)
9192 {
9193         struct cmd_syn_filter_result *res = parsed_result;
9194         struct rte_eth_syn_filter syn_filter;
9195         int ret = 0;
9196
9197         ret = rte_eth_dev_filter_supported(res->port_id,
9198                                         RTE_ETH_FILTER_SYN);
9199         if (ret < 0) {
9200                 printf("syn filter is not supported on port %u.\n",
9201                                 res->port_id);
9202                 return;
9203         }
9204
9205         memset(&syn_filter, 0, sizeof(syn_filter));
9206
9207         if (!strcmp(res->ops, "add")) {
9208                 if (!strcmp(res->high, "high"))
9209                         syn_filter.hig_pri = 1;
9210                 else
9211                         syn_filter.hig_pri = 0;
9212
9213                 syn_filter.queue = res->queue_id;
9214                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9215                                                 RTE_ETH_FILTER_SYN,
9216                                                 RTE_ETH_FILTER_ADD,
9217                                                 &syn_filter);
9218         } else
9219                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9220                                                 RTE_ETH_FILTER_SYN,
9221                                                 RTE_ETH_FILTER_DELETE,
9222                                                 &syn_filter);
9223
9224         if (ret < 0)
9225                 printf("syn filter programming error: (%s)\n",
9226                                 strerror(-ret));
9227 }
9228
9229 cmdline_parse_token_string_t cmd_syn_filter_filter =
9230         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9231         filter, "syn_filter");
9232 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9233         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9234         port_id, UINT16);
9235 cmdline_parse_token_string_t cmd_syn_filter_ops =
9236         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9237         ops, "add#del");
9238 cmdline_parse_token_string_t cmd_syn_filter_priority =
9239         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9240                                 priority, "priority");
9241 cmdline_parse_token_string_t cmd_syn_filter_high =
9242         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9243                                 high, "high#low");
9244 cmdline_parse_token_string_t cmd_syn_filter_queue =
9245         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9246                                 queue, "queue");
9247 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9248         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9249                                 queue_id, UINT16);
9250
9251 cmdline_parse_inst_t cmd_syn_filter = {
9252         .f = cmd_syn_filter_parsed,
9253         .data = NULL,
9254         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9255                 "<queue_id>: Add/Delete syn filter",
9256         .tokens = {
9257                 (void *)&cmd_syn_filter_filter,
9258                 (void *)&cmd_syn_filter_port_id,
9259                 (void *)&cmd_syn_filter_ops,
9260                 (void *)&cmd_syn_filter_priority,
9261                 (void *)&cmd_syn_filter_high,
9262                 (void *)&cmd_syn_filter_queue,
9263                 (void *)&cmd_syn_filter_queue_id,
9264                 NULL,
9265         },
9266 };
9267
9268 /* *** queue region set *** */
9269 struct cmd_queue_region_result {
9270         cmdline_fixed_string_t set;
9271         cmdline_fixed_string_t port;
9272         portid_t port_id;
9273         cmdline_fixed_string_t cmd;
9274         cmdline_fixed_string_t region;
9275         uint8_t  region_id;
9276         cmdline_fixed_string_t queue_start_index;
9277         uint8_t  queue_id;
9278         cmdline_fixed_string_t queue_num;
9279         uint8_t  queue_num_value;
9280 };
9281
9282 static void
9283 cmd_queue_region_parsed(void *parsed_result,
9284                         __attribute__((unused)) struct cmdline *cl,
9285                         __attribute__((unused)) void *data)
9286 {
9287         struct cmd_queue_region_result *res = parsed_result;
9288         int ret = -ENOTSUP;
9289 #ifdef RTE_LIBRTE_I40E_PMD
9290         struct rte_pmd_i40e_queue_region_conf region_conf;
9291         enum rte_pmd_i40e_queue_region_op op_type;
9292 #endif
9293
9294         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9295                 return;
9296
9297 #ifdef RTE_LIBRTE_I40E_PMD
9298         memset(&region_conf, 0, sizeof(region_conf));
9299         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9300         region_conf.region_id = res->region_id;
9301         region_conf.queue_num = res->queue_num_value;
9302         region_conf.queue_start_index = res->queue_id;
9303
9304         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9305                                 op_type, &region_conf);
9306 #endif
9307
9308         switch (ret) {
9309         case 0:
9310                 break;
9311         case -ENOTSUP:
9312                 printf("function not implemented or supported\n");
9313                 break;
9314         default:
9315                 printf("queue region config error: (%s)\n", strerror(-ret));
9316         }
9317 }
9318
9319 cmdline_parse_token_string_t cmd_queue_region_set =
9320 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9321                 set, "set");
9322 cmdline_parse_token_string_t cmd_queue_region_port =
9323         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9324 cmdline_parse_token_num_t cmd_queue_region_port_id =
9325         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9326                                 port_id, UINT16);
9327 cmdline_parse_token_string_t cmd_queue_region_cmd =
9328         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9329                                  cmd, "queue-region");
9330 cmdline_parse_token_string_t cmd_queue_region_id =
9331         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9332                                 region, "region_id");
9333 cmdline_parse_token_num_t cmd_queue_region_index =
9334         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9335                                 region_id, UINT8);
9336 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9337         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9338                                 queue_start_index, "queue_start_index");
9339 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9340         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9341                                 queue_id, UINT8);
9342 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9343         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9344                                 queue_num, "queue_num");
9345 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9346         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9347                                 queue_num_value, UINT8);
9348
9349 cmdline_parse_inst_t cmd_queue_region = {
9350         .f = cmd_queue_region_parsed,
9351         .data = NULL,
9352         .help_str = "set port <port_id> queue-region region_id <value> "
9353                 "queue_start_index <value> queue_num <value>: Set a queue region",
9354         .tokens = {
9355                 (void *)&cmd_queue_region_set,
9356                 (void *)&cmd_queue_region_port,
9357                 (void *)&cmd_queue_region_port_id,
9358                 (void *)&cmd_queue_region_cmd,
9359                 (void *)&cmd_queue_region_id,
9360                 (void *)&cmd_queue_region_index,
9361                 (void *)&cmd_queue_region_queue_start_index,
9362                 (void *)&cmd_queue_region_queue_id,
9363                 (void *)&cmd_queue_region_queue_num,
9364                 (void *)&cmd_queue_region_queue_num_value,
9365                 NULL,
9366         },
9367 };
9368
9369 /* *** queue region and flowtype set *** */
9370 struct cmd_region_flowtype_result {
9371         cmdline_fixed_string_t set;
9372         cmdline_fixed_string_t port;
9373         portid_t port_id;
9374         cmdline_fixed_string_t cmd;
9375         cmdline_fixed_string_t region;
9376         uint8_t  region_id;
9377         cmdline_fixed_string_t flowtype;
9378         uint8_t  flowtype_id;
9379 };
9380
9381 static void
9382 cmd_region_flowtype_parsed(void *parsed_result,
9383                         __attribute__((unused)) struct cmdline *cl,
9384                         __attribute__((unused)) void *data)
9385 {
9386         struct cmd_region_flowtype_result *res = parsed_result;
9387         int ret = -ENOTSUP;
9388 #ifdef RTE_LIBRTE_I40E_PMD
9389         struct rte_pmd_i40e_queue_region_conf region_conf;
9390         enum rte_pmd_i40e_queue_region_op op_type;
9391 #endif
9392
9393         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9394                 return;
9395
9396 #ifdef RTE_LIBRTE_I40E_PMD
9397         memset(&region_conf, 0, sizeof(region_conf));
9398
9399         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9400         region_conf.region_id = res->region_id;
9401         region_conf.hw_flowtype = res->flowtype_id;
9402
9403         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9404                         op_type, &region_conf);
9405 #endif
9406
9407         switch (ret) {
9408         case 0:
9409                 break;
9410         case -ENOTSUP:
9411                 printf("function not implemented or supported\n");
9412                 break;
9413         default:
9414                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9415         }
9416 }
9417
9418 cmdline_parse_token_string_t cmd_region_flowtype_set =
9419 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9420                                 set, "set");
9421 cmdline_parse_token_string_t cmd_region_flowtype_port =
9422         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9423                                 port, "port");
9424 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9425         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9426                                 port_id, UINT16);
9427 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9428         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9429                                 cmd, "queue-region");
9430 cmdline_parse_token_string_t cmd_region_flowtype_index =
9431         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9432                                 region, "region_id");
9433 cmdline_parse_token_num_t cmd_region_flowtype_id =
9434         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9435                                 region_id, UINT8);
9436 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9437         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9438                                 flowtype, "flowtype");
9439 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9440         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9441                                 flowtype_id, UINT8);
9442 cmdline_parse_inst_t cmd_region_flowtype = {
9443         .f = cmd_region_flowtype_parsed,
9444         .data = NULL,
9445         .help_str = "set port <port_id> queue-region region_id <value> "
9446                 "flowtype <value>: Set a flowtype region index",
9447         .tokens = {
9448                 (void *)&cmd_region_flowtype_set,
9449                 (void *)&cmd_region_flowtype_port,
9450                 (void *)&cmd_region_flowtype_port_index,
9451                 (void *)&cmd_region_flowtype_cmd,
9452                 (void *)&cmd_region_flowtype_index,
9453                 (void *)&cmd_region_flowtype_id,
9454                 (void *)&cmd_region_flowtype_flow_index,
9455                 (void *)&cmd_region_flowtype_flow_id,
9456                 NULL,
9457         },
9458 };
9459
9460 /* *** User Priority (UP) to queue region (region_id) set *** */
9461 struct cmd_user_priority_region_result {
9462         cmdline_fixed_string_t set;
9463         cmdline_fixed_string_t port;
9464         portid_t port_id;
9465         cmdline_fixed_string_t cmd;
9466         cmdline_fixed_string_t user_priority;
9467         uint8_t  user_priority_id;
9468         cmdline_fixed_string_t region;
9469         uint8_t  region_id;
9470 };
9471
9472 static void
9473 cmd_user_priority_region_parsed(void *parsed_result,
9474                         __attribute__((unused)) struct cmdline *cl,
9475                         __attribute__((unused)) void *data)
9476 {
9477         struct cmd_user_priority_region_result *res = parsed_result;
9478         int ret = -ENOTSUP;
9479 #ifdef RTE_LIBRTE_I40E_PMD
9480         struct rte_pmd_i40e_queue_region_conf region_conf;
9481         enum rte_pmd_i40e_queue_region_op op_type;
9482 #endif
9483
9484         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9485                 return;
9486
9487 #ifdef RTE_LIBRTE_I40E_PMD
9488         memset(&region_conf, 0, sizeof(region_conf));
9489         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9490         region_conf.user_priority = res->user_priority_id;
9491         region_conf.region_id = res->region_id;
9492
9493         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9494                                 op_type, &region_conf);
9495 #endif
9496
9497         switch (ret) {
9498         case 0:
9499                 break;
9500         case -ENOTSUP:
9501                 printf("function not implemented or supported\n");
9502                 break;
9503         default:
9504                 printf("user_priority region config error: (%s)\n",
9505                                 strerror(-ret));
9506         }
9507 }
9508
9509 cmdline_parse_token_string_t cmd_user_priority_region_set =
9510         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9511                                 set, "set");
9512 cmdline_parse_token_string_t cmd_user_priority_region_port =
9513         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9514                                 port, "port");
9515 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9516         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9517                                 port_id, UINT16);
9518 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9519         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9520                                 cmd, "queue-region");
9521 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9522         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9523                                 user_priority, "UP");
9524 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9525         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9526                                 user_priority_id, UINT8);
9527 cmdline_parse_token_string_t cmd_user_priority_region_region =
9528         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9529                                 region, "region_id");
9530 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9531         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9532                                 region_id, UINT8);
9533
9534 cmdline_parse_inst_t cmd_user_priority_region = {
9535         .f = cmd_user_priority_region_parsed,
9536         .data = NULL,
9537         .help_str = "set port <port_id> queue-region UP <value> "
9538                 "region_id <value>: Set the mapping of User Priority (UP) "
9539                 "to queue region (region_id) ",
9540         .tokens = {
9541                 (void *)&cmd_user_priority_region_set,
9542                 (void *)&cmd_user_priority_region_port,
9543                 (void *)&cmd_user_priority_region_port_index,
9544                 (void *)&cmd_user_priority_region_cmd,
9545                 (void *)&cmd_user_priority_region_UP,
9546                 (void *)&cmd_user_priority_region_UP_id,
9547                 (void *)&cmd_user_priority_region_region,
9548                 (void *)&cmd_user_priority_region_region_id,
9549                 NULL,
9550         },
9551 };
9552
9553 /* *** flush all queue region related configuration *** */
9554 struct cmd_flush_queue_region_result {
9555         cmdline_fixed_string_t set;
9556         cmdline_fixed_string_t port;
9557         portid_t port_id;
9558         cmdline_fixed_string_t cmd;
9559         cmdline_fixed_string_t flush;
9560         cmdline_fixed_string_t what;
9561 };
9562
9563 static void
9564 cmd_flush_queue_region_parsed(void *parsed_result,
9565                         __attribute__((unused)) struct cmdline *cl,
9566                         __attribute__((unused)) void *data)
9567 {
9568         struct cmd_flush_queue_region_result *res = parsed_result;
9569         int ret = -ENOTSUP;
9570 #ifdef RTE_LIBRTE_I40E_PMD
9571         struct rte_pmd_i40e_queue_region_conf region_conf;
9572         enum rte_pmd_i40e_queue_region_op op_type;
9573 #endif
9574
9575         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9576                 return;
9577
9578 #ifdef RTE_LIBRTE_I40E_PMD
9579         memset(&region_conf, 0, sizeof(region_conf));
9580
9581         if (strcmp(res->what, "on") == 0)
9582                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9583         else
9584                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9585
9586         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9587                                 op_type, &region_conf);
9588 #endif
9589
9590         switch (ret) {
9591         case 0:
9592                 break;
9593         case -ENOTSUP:
9594                 printf("function not implemented or supported\n");
9595                 break;
9596         default:
9597                 printf("queue region config flush error: (%s)\n",
9598                                 strerror(-ret));
9599         }
9600 }
9601
9602 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9603         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9604                                 set, "set");
9605 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9606         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9607                                 port, "port");
9608 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9609         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9610                                 port_id, UINT16);
9611 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9612         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9613                                 cmd, "queue-region");
9614 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9615         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9616                                 flush, "flush");
9617 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9618         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9619                                 what, "on#off");
9620
9621 cmdline_parse_inst_t cmd_flush_queue_region = {
9622         .f = cmd_flush_queue_region_parsed,
9623         .data = NULL,
9624         .help_str = "set port <port_id> queue-region flush on|off"
9625                 ": flush all queue region related configuration",
9626         .tokens = {
9627                 (void *)&cmd_flush_queue_region_set,
9628                 (void *)&cmd_flush_queue_region_port,
9629                 (void *)&cmd_flush_queue_region_port_index,
9630                 (void *)&cmd_flush_queue_region_cmd,
9631                 (void *)&cmd_flush_queue_region_flush,
9632                 (void *)&cmd_flush_queue_region_what,
9633                 NULL,
9634         },
9635 };
9636
9637 /* *** get all queue region related configuration info *** */
9638 struct cmd_show_queue_region_info {
9639         cmdline_fixed_string_t show;
9640         cmdline_fixed_string_t port;
9641         portid_t port_id;
9642         cmdline_fixed_string_t cmd;
9643 };
9644
9645 static void
9646 cmd_show_queue_region_info_parsed(void *parsed_result,
9647                         __attribute__((unused)) struct cmdline *cl,
9648                         __attribute__((unused)) void *data)
9649 {
9650         struct cmd_show_queue_region_info *res = parsed_result;
9651         int ret = -ENOTSUP;
9652 #ifdef RTE_LIBRTE_I40E_PMD
9653         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9654         enum rte_pmd_i40e_queue_region_op op_type;
9655 #endif
9656
9657         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9658                 return;
9659
9660 #ifdef RTE_LIBRTE_I40E_PMD
9661         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9662
9663         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9664
9665         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9666                                         op_type, &rte_pmd_regions);
9667
9668         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9669 #endif
9670
9671         switch (ret) {
9672         case 0:
9673                 break;
9674         case -ENOTSUP:
9675                 printf("function not implemented or supported\n");
9676                 break;
9677         default:
9678                 printf("queue region config info show error: (%s)\n",
9679                                 strerror(-ret));
9680         }
9681 }
9682
9683 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9684 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9685                                 show, "show");
9686 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9687         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9688                                 port, "port");
9689 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9690         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9691                                 port_id, UINT16);
9692 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9693         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9694                                 cmd, "queue-region");
9695
9696 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9697         .f = cmd_show_queue_region_info_parsed,
9698         .data = NULL,
9699         .help_str = "show port <port_id> queue-region"
9700                 ": show all queue region related configuration info",
9701         .tokens = {
9702                 (void *)&cmd_show_queue_region_info_get,
9703                 (void *)&cmd_show_queue_region_info_port,
9704                 (void *)&cmd_show_queue_region_info_port_index,
9705                 (void *)&cmd_show_queue_region_info_cmd,
9706                 NULL,
9707         },
9708 };
9709
9710 /* *** ADD/REMOVE A 2tuple FILTER *** */
9711 struct cmd_2tuple_filter_result {
9712         cmdline_fixed_string_t filter;
9713         portid_t port_id;
9714         cmdline_fixed_string_t ops;
9715         cmdline_fixed_string_t dst_port;
9716         uint16_t dst_port_value;
9717         cmdline_fixed_string_t protocol;
9718         uint8_t protocol_value;
9719         cmdline_fixed_string_t mask;
9720         uint8_t  mask_value;
9721         cmdline_fixed_string_t tcp_flags;
9722         uint8_t tcp_flags_value;
9723         cmdline_fixed_string_t priority;
9724         uint8_t  priority_value;
9725         cmdline_fixed_string_t queue;
9726         uint16_t  queue_id;
9727 };
9728
9729 static void
9730 cmd_2tuple_filter_parsed(void *parsed_result,
9731                         __attribute__((unused)) struct cmdline *cl,
9732                         __attribute__((unused)) void *data)
9733 {
9734         struct rte_eth_ntuple_filter filter;
9735         struct cmd_2tuple_filter_result *res = parsed_result;
9736         int ret = 0;
9737
9738         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9739         if (ret < 0) {
9740                 printf("ntuple filter is not supported on port %u.\n",
9741                         res->port_id);
9742                 return;
9743         }
9744
9745         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9746
9747         filter.flags = RTE_2TUPLE_FLAGS;
9748         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9749         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9750         filter.proto = res->protocol_value;
9751         filter.priority = res->priority_value;
9752         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9753                 printf("nonzero tcp_flags is only meaningful"
9754                         " when protocol is TCP.\n");
9755                 return;
9756         }
9757         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9758                 printf("invalid TCP flags.\n");
9759                 return;
9760         }
9761
9762         if (res->tcp_flags_value != 0) {
9763                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9764                 filter.tcp_flags = res->tcp_flags_value;
9765         }
9766
9767         /* need convert to big endian. */
9768         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9769         filter.queue = res->queue_id;
9770
9771         if (!strcmp(res->ops, "add"))
9772                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9773                                 RTE_ETH_FILTER_NTUPLE,
9774                                 RTE_ETH_FILTER_ADD,
9775                                 &filter);
9776         else
9777                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9778                                 RTE_ETH_FILTER_NTUPLE,
9779                                 RTE_ETH_FILTER_DELETE,
9780                                 &filter);
9781         if (ret < 0)
9782                 printf("2tuple filter programming error: (%s)\n",
9783                         strerror(-ret));
9784
9785 }
9786
9787 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9788         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9789                                  filter, "2tuple_filter");
9790 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9791         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9792                                 port_id, UINT16);
9793 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9794         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9795                                  ops, "add#del");
9796 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9797         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9798                                 dst_port, "dst_port");
9799 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9800         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9801                                 dst_port_value, UINT16);
9802 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9803         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9804                                 protocol, "protocol");
9805 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9806         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9807                                 protocol_value, UINT8);
9808 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9809         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9810                                 mask, "mask");
9811 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9812         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9813                                 mask_value, INT8);
9814 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9815         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9816                                 tcp_flags, "tcp_flags");
9817 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9818         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9819                                 tcp_flags_value, UINT8);
9820 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9821         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9822                                 priority, "priority");
9823 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9824         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9825                                 priority_value, UINT8);
9826 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9827         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9828                                 queue, "queue");
9829 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9830         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9831                                 queue_id, UINT16);
9832
9833 cmdline_parse_inst_t cmd_2tuple_filter = {
9834         .f = cmd_2tuple_filter_parsed,
9835         .data = NULL,
9836         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9837                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9838                 "<queue_id>: Add a 2tuple filter",
9839         .tokens = {
9840                 (void *)&cmd_2tuple_filter_filter,
9841                 (void *)&cmd_2tuple_filter_port_id,
9842                 (void *)&cmd_2tuple_filter_ops,
9843                 (void *)&cmd_2tuple_filter_dst_port,
9844                 (void *)&cmd_2tuple_filter_dst_port_value,
9845                 (void *)&cmd_2tuple_filter_protocol,
9846                 (void *)&cmd_2tuple_filter_protocol_value,
9847                 (void *)&cmd_2tuple_filter_mask,
9848                 (void *)&cmd_2tuple_filter_mask_value,
9849                 (void *)&cmd_2tuple_filter_tcp_flags,
9850                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9851                 (void *)&cmd_2tuple_filter_priority,
9852                 (void *)&cmd_2tuple_filter_priority_value,
9853                 (void *)&cmd_2tuple_filter_queue,
9854                 (void *)&cmd_2tuple_filter_queue_id,
9855                 NULL,
9856         },
9857 };
9858
9859 /* *** ADD/REMOVE A 5tuple FILTER *** */
9860 struct cmd_5tuple_filter_result {
9861         cmdline_fixed_string_t filter;
9862         portid_t port_id;
9863         cmdline_fixed_string_t ops;
9864         cmdline_fixed_string_t dst_ip;
9865         cmdline_ipaddr_t dst_ip_value;
9866         cmdline_fixed_string_t src_ip;
9867         cmdline_ipaddr_t src_ip_value;
9868         cmdline_fixed_string_t dst_port;
9869         uint16_t dst_port_value;
9870         cmdline_fixed_string_t src_port;
9871         uint16_t src_port_value;
9872         cmdline_fixed_string_t protocol;
9873         uint8_t protocol_value;
9874         cmdline_fixed_string_t mask;
9875         uint8_t  mask_value;
9876         cmdline_fixed_string_t tcp_flags;
9877         uint8_t tcp_flags_value;
9878         cmdline_fixed_string_t priority;
9879         uint8_t  priority_value;
9880         cmdline_fixed_string_t queue;
9881         uint16_t  queue_id;
9882 };
9883
9884 static void
9885 cmd_5tuple_filter_parsed(void *parsed_result,
9886                         __attribute__((unused)) struct cmdline *cl,
9887                         __attribute__((unused)) void *data)
9888 {
9889         struct rte_eth_ntuple_filter filter;
9890         struct cmd_5tuple_filter_result *res = parsed_result;
9891         int ret = 0;
9892
9893         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9894         if (ret < 0) {
9895                 printf("ntuple filter is not supported on port %u.\n",
9896                         res->port_id);
9897                 return;
9898         }
9899
9900         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9901
9902         filter.flags = RTE_5TUPLE_FLAGS;
9903         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9904         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9905         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9906         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9907         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9908         filter.proto = res->protocol_value;
9909         filter.priority = res->priority_value;
9910         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9911                 printf("nonzero tcp_flags is only meaningful"
9912                         " when protocol is TCP.\n");
9913                 return;
9914         }
9915         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9916                 printf("invalid TCP flags.\n");
9917                 return;
9918         }
9919
9920         if (res->tcp_flags_value != 0) {
9921                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9922                 filter.tcp_flags = res->tcp_flags_value;
9923         }
9924
9925         if (res->dst_ip_value.family == AF_INET)
9926                 /* no need to convert, already big endian. */
9927                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9928         else {
9929                 if (filter.dst_ip_mask == 0) {
9930                         printf("can not support ipv6 involved compare.\n");
9931                         return;
9932                 }
9933                 filter.dst_ip = 0;
9934         }
9935
9936         if (res->src_ip_value.family == AF_INET)
9937                 /* no need to convert, already big endian. */
9938                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9939         else {
9940                 if (filter.src_ip_mask == 0) {
9941                         printf("can not support ipv6 involved compare.\n");
9942                         return;
9943                 }
9944                 filter.src_ip = 0;
9945         }
9946         /* need convert to big endian. */
9947         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9948         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9949         filter.queue = res->queue_id;
9950
9951         if (!strcmp(res->ops, "add"))
9952                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9953                                 RTE_ETH_FILTER_NTUPLE,
9954                                 RTE_ETH_FILTER_ADD,
9955                                 &filter);
9956         else
9957                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9958                                 RTE_ETH_FILTER_NTUPLE,
9959                                 RTE_ETH_FILTER_DELETE,
9960                                 &filter);
9961         if (ret < 0)
9962                 printf("5tuple filter programming error: (%s)\n",
9963                         strerror(-ret));
9964 }
9965
9966 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9967         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9968                                  filter, "5tuple_filter");
9969 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9970         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9971                                 port_id, UINT16);
9972 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9973         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9974                                  ops, "add#del");
9975 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9976         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9977                                 dst_ip, "dst_ip");
9978 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9979         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9980                                 dst_ip_value);
9981 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9982         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9983                                 src_ip, "src_ip");
9984 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9985         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9986                                 src_ip_value);
9987 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9988         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9989                                 dst_port, "dst_port");
9990 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9991         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9992                                 dst_port_value, UINT16);
9993 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9994         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9995                                 src_port, "src_port");
9996 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9997         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9998                                 src_port_value, UINT16);
9999 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10000         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10001                                 protocol, "protocol");
10002 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10003         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10004                                 protocol_value, UINT8);
10005 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10006         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10007                                 mask, "mask");
10008 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10009         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10010                                 mask_value, INT8);
10011 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10012         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10013                                 tcp_flags, "tcp_flags");
10014 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10015         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10016                                 tcp_flags_value, UINT8);
10017 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10018         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10019                                 priority, "priority");
10020 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10021         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10022                                 priority_value, UINT8);
10023 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10024         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10025                                 queue, "queue");
10026 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10027         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10028                                 queue_id, UINT16);
10029
10030 cmdline_parse_inst_t cmd_5tuple_filter = {
10031         .f = cmd_5tuple_filter_parsed,
10032         .data = NULL,
10033         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10034                 "src_ip <value> dst_port <value> src_port <value> "
10035                 "protocol <value>  mask <value> tcp_flags <value> "
10036                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10037         .tokens = {
10038                 (void *)&cmd_5tuple_filter_filter,
10039                 (void *)&cmd_5tuple_filter_port_id,
10040                 (void *)&cmd_5tuple_filter_ops,
10041                 (void *)&cmd_5tuple_filter_dst_ip,
10042                 (void *)&cmd_5tuple_filter_dst_ip_value,
10043                 (void *)&cmd_5tuple_filter_src_ip,
10044                 (void *)&cmd_5tuple_filter_src_ip_value,
10045                 (void *)&cmd_5tuple_filter_dst_port,
10046                 (void *)&cmd_5tuple_filter_dst_port_value,
10047                 (void *)&cmd_5tuple_filter_src_port,
10048                 (void *)&cmd_5tuple_filter_src_port_value,
10049                 (void *)&cmd_5tuple_filter_protocol,
10050                 (void *)&cmd_5tuple_filter_protocol_value,
10051                 (void *)&cmd_5tuple_filter_mask,
10052                 (void *)&cmd_5tuple_filter_mask_value,
10053                 (void *)&cmd_5tuple_filter_tcp_flags,
10054                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10055                 (void *)&cmd_5tuple_filter_priority,
10056                 (void *)&cmd_5tuple_filter_priority_value,
10057                 (void *)&cmd_5tuple_filter_queue,
10058                 (void *)&cmd_5tuple_filter_queue_id,
10059                 NULL,
10060         },
10061 };
10062
10063 /* *** ADD/REMOVE A flex FILTER *** */
10064 struct cmd_flex_filter_result {
10065         cmdline_fixed_string_t filter;
10066         cmdline_fixed_string_t ops;
10067         portid_t port_id;
10068         cmdline_fixed_string_t len;
10069         uint8_t len_value;
10070         cmdline_fixed_string_t bytes;
10071         cmdline_fixed_string_t bytes_value;
10072         cmdline_fixed_string_t mask;
10073         cmdline_fixed_string_t mask_value;
10074         cmdline_fixed_string_t priority;
10075         uint8_t priority_value;
10076         cmdline_fixed_string_t queue;
10077         uint16_t queue_id;
10078 };
10079
10080 static int xdigit2val(unsigned char c)
10081 {
10082         int val;
10083         if (isdigit(c))
10084                 val = c - '0';
10085         else if (isupper(c))
10086                 val = c - 'A' + 10;
10087         else
10088                 val = c - 'a' + 10;
10089         return val;
10090 }
10091
10092 static void
10093 cmd_flex_filter_parsed(void *parsed_result,
10094                           __attribute__((unused)) struct cmdline *cl,
10095                           __attribute__((unused)) void *data)
10096 {
10097         int ret = 0;
10098         struct rte_eth_flex_filter filter;
10099         struct cmd_flex_filter_result *res = parsed_result;
10100         char *bytes_ptr, *mask_ptr;
10101         uint16_t len, i, j = 0;
10102         char c;
10103         int val;
10104         uint8_t byte = 0;
10105
10106         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10107                 printf("the len exceed the max length 128\n");
10108                 return;
10109         }
10110         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10111         filter.len = res->len_value;
10112         filter.priority = res->priority_value;
10113         filter.queue = res->queue_id;
10114         bytes_ptr = res->bytes_value;
10115         mask_ptr = res->mask_value;
10116
10117          /* translate bytes string to array. */
10118         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10119                 (bytes_ptr[1] == 'X')))
10120                 bytes_ptr += 2;
10121         len = strnlen(bytes_ptr, res->len_value * 2);
10122         if (len == 0 || (len % 8 != 0)) {
10123                 printf("please check len and bytes input\n");
10124                 return;
10125         }
10126         for (i = 0; i < len; i++) {
10127                 c = bytes_ptr[i];
10128                 if (isxdigit(c) == 0) {
10129                         /* invalid characters. */
10130                         printf("invalid input\n");
10131                         return;
10132                 }
10133                 val = xdigit2val(c);
10134                 if (i % 2) {
10135                         byte |= val;
10136                         filter.bytes[j] = byte;
10137                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10138                         j++;
10139                         byte = 0;
10140                 } else
10141                         byte |= val << 4;
10142         }
10143         printf("\n");
10144          /* translate mask string to uint8_t array. */
10145         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10146                 (mask_ptr[1] == 'X')))
10147                 mask_ptr += 2;
10148         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10149         if (len == 0) {
10150                 printf("invalid input\n");
10151                 return;
10152         }
10153         j = 0;
10154         byte = 0;
10155         for (i = 0; i < len; i++) {
10156                 c = mask_ptr[i];
10157                 if (isxdigit(c) == 0) {
10158                         /* invalid characters. */
10159                         printf("invalid input\n");
10160                         return;
10161                 }
10162                 val = xdigit2val(c);
10163                 if (i % 2) {
10164                         byte |= val;
10165                         filter.mask[j] = byte;
10166                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10167                         j++;
10168                         byte = 0;
10169                 } else
10170                         byte |= val << 4;
10171         }
10172         printf("\n");
10173
10174         if (!strcmp(res->ops, "add"))
10175                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10176                                 RTE_ETH_FILTER_FLEXIBLE,
10177                                 RTE_ETH_FILTER_ADD,
10178                                 &filter);
10179         else
10180                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10181                                 RTE_ETH_FILTER_FLEXIBLE,
10182                                 RTE_ETH_FILTER_DELETE,
10183                                 &filter);
10184
10185         if (ret < 0)
10186                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10187 }
10188
10189 cmdline_parse_token_string_t cmd_flex_filter_filter =
10190         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10191                                 filter, "flex_filter");
10192 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10193         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10194                                 port_id, UINT16);
10195 cmdline_parse_token_string_t cmd_flex_filter_ops =
10196         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10197                                 ops, "add#del");
10198 cmdline_parse_token_string_t cmd_flex_filter_len =
10199         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10200                                 len, "len");
10201 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10202         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10203                                 len_value, UINT8);
10204 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10205         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10206                                 bytes, "bytes");
10207 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10208         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10209                                 bytes_value, NULL);
10210 cmdline_parse_token_string_t cmd_flex_filter_mask =
10211         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10212                                 mask, "mask");
10213 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10214         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10215                                 mask_value, NULL);
10216 cmdline_parse_token_string_t cmd_flex_filter_priority =
10217         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10218                                 priority, "priority");
10219 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10220         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10221                                 priority_value, UINT8);
10222 cmdline_parse_token_string_t cmd_flex_filter_queue =
10223         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10224                                 queue, "queue");
10225 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10226         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10227                                 queue_id, UINT16);
10228 cmdline_parse_inst_t cmd_flex_filter = {
10229         .f = cmd_flex_filter_parsed,
10230         .data = NULL,
10231         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10232                 "<value> mask <value> priority <value> queue <queue_id>: "
10233                 "Add/Del a flex filter",
10234         .tokens = {
10235                 (void *)&cmd_flex_filter_filter,
10236                 (void *)&cmd_flex_filter_port_id,
10237                 (void *)&cmd_flex_filter_ops,
10238                 (void *)&cmd_flex_filter_len,
10239                 (void *)&cmd_flex_filter_len_value,
10240                 (void *)&cmd_flex_filter_bytes,
10241                 (void *)&cmd_flex_filter_bytes_value,
10242                 (void *)&cmd_flex_filter_mask,
10243                 (void *)&cmd_flex_filter_mask_value,
10244                 (void *)&cmd_flex_filter_priority,
10245                 (void *)&cmd_flex_filter_priority_value,
10246                 (void *)&cmd_flex_filter_queue,
10247                 (void *)&cmd_flex_filter_queue_id,
10248                 NULL,
10249         },
10250 };
10251
10252 /* *** Filters Control *** */
10253
10254 /* *** deal with ethertype filter *** */
10255 struct cmd_ethertype_filter_result {
10256         cmdline_fixed_string_t filter;
10257         portid_t port_id;
10258         cmdline_fixed_string_t ops;
10259         cmdline_fixed_string_t mac;
10260         struct ether_addr mac_addr;
10261         cmdline_fixed_string_t ethertype;
10262         uint16_t ethertype_value;
10263         cmdline_fixed_string_t drop;
10264         cmdline_fixed_string_t queue;
10265         uint16_t  queue_id;
10266 };
10267
10268 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10269         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10270                                  filter, "ethertype_filter");
10271 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10272         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10273                               port_id, UINT16);
10274 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10275         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10276                                  ops, "add#del");
10277 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10278         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10279                                  mac, "mac_addr#mac_ignr");
10280 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10281         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10282                                      mac_addr);
10283 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10284         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10285                                  ethertype, "ethertype");
10286 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10287         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10288                               ethertype_value, UINT16);
10289 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10290         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10291                                  drop, "drop#fwd");
10292 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10293         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10294                                  queue, "queue");
10295 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10296         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10297                               queue_id, UINT16);
10298
10299 static void
10300 cmd_ethertype_filter_parsed(void *parsed_result,
10301                           __attribute__((unused)) struct cmdline *cl,
10302                           __attribute__((unused)) void *data)
10303 {
10304         struct cmd_ethertype_filter_result *res = parsed_result;
10305         struct rte_eth_ethertype_filter filter;
10306         int ret = 0;
10307
10308         ret = rte_eth_dev_filter_supported(res->port_id,
10309                         RTE_ETH_FILTER_ETHERTYPE);
10310         if (ret < 0) {
10311                 printf("ethertype filter is not supported on port %u.\n",
10312                         res->port_id);
10313                 return;
10314         }
10315
10316         memset(&filter, 0, sizeof(filter));
10317         if (!strcmp(res->mac, "mac_addr")) {
10318                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10319                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10320                         sizeof(struct ether_addr));
10321         }
10322         if (!strcmp(res->drop, "drop"))
10323                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10324         filter.ether_type = res->ethertype_value;
10325         filter.queue = res->queue_id;
10326
10327         if (!strcmp(res->ops, "add"))
10328                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10329                                 RTE_ETH_FILTER_ETHERTYPE,
10330                                 RTE_ETH_FILTER_ADD,
10331                                 &filter);
10332         else
10333                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10334                                 RTE_ETH_FILTER_ETHERTYPE,
10335                                 RTE_ETH_FILTER_DELETE,
10336                                 &filter);
10337         if (ret < 0)
10338                 printf("ethertype filter programming error: (%s)\n",
10339                         strerror(-ret));
10340 }
10341
10342 cmdline_parse_inst_t cmd_ethertype_filter = {
10343         .f = cmd_ethertype_filter_parsed,
10344         .data = NULL,
10345         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10346                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10347                 "Add or delete an ethertype filter entry",
10348         .tokens = {
10349                 (void *)&cmd_ethertype_filter_filter,
10350                 (void *)&cmd_ethertype_filter_port_id,
10351                 (void *)&cmd_ethertype_filter_ops,
10352                 (void *)&cmd_ethertype_filter_mac,
10353                 (void *)&cmd_ethertype_filter_mac_addr,
10354                 (void *)&cmd_ethertype_filter_ethertype,
10355                 (void *)&cmd_ethertype_filter_ethertype_value,
10356                 (void *)&cmd_ethertype_filter_drop,
10357                 (void *)&cmd_ethertype_filter_queue,
10358                 (void *)&cmd_ethertype_filter_queue_id,
10359                 NULL,
10360         },
10361 };
10362
10363 /* *** deal with flow director filter *** */
10364 struct cmd_flow_director_result {
10365         cmdline_fixed_string_t flow_director_filter;
10366         portid_t port_id;
10367         cmdline_fixed_string_t mode;
10368         cmdline_fixed_string_t mode_value;
10369         cmdline_fixed_string_t ops;
10370         cmdline_fixed_string_t flow;
10371         cmdline_fixed_string_t flow_type;
10372         cmdline_fixed_string_t ether;
10373         uint16_t ether_type;
10374         cmdline_fixed_string_t src;
10375         cmdline_ipaddr_t ip_src;
10376         uint16_t port_src;
10377         cmdline_fixed_string_t dst;
10378         cmdline_ipaddr_t ip_dst;
10379         uint16_t port_dst;
10380         cmdline_fixed_string_t verify_tag;
10381         uint32_t verify_tag_value;
10382         cmdline_fixed_string_t tos;
10383         uint8_t tos_value;
10384         cmdline_fixed_string_t proto;
10385         uint8_t proto_value;
10386         cmdline_fixed_string_t ttl;
10387         uint8_t ttl_value;
10388         cmdline_fixed_string_t vlan;
10389         uint16_t vlan_value;
10390         cmdline_fixed_string_t flexbytes;
10391         cmdline_fixed_string_t flexbytes_value;
10392         cmdline_fixed_string_t pf_vf;
10393         cmdline_fixed_string_t drop;
10394         cmdline_fixed_string_t queue;
10395         uint16_t  queue_id;
10396         cmdline_fixed_string_t fd_id;
10397         uint32_t  fd_id_value;
10398         cmdline_fixed_string_t mac;
10399         struct ether_addr mac_addr;
10400         cmdline_fixed_string_t tunnel;
10401         cmdline_fixed_string_t tunnel_type;
10402         cmdline_fixed_string_t tunnel_id;
10403         uint32_t tunnel_id_value;
10404         cmdline_fixed_string_t packet;
10405         char filepath[];
10406 };
10407
10408 static inline int
10409 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10410 {
10411         char s[256];
10412         const char *p, *p0 = q_arg;
10413         char *end;
10414         unsigned long int_fld;
10415         char *str_fld[max_num];
10416         int i;
10417         unsigned size;
10418         int ret = -1;
10419
10420         p = strchr(p0, '(');
10421         if (p == NULL)
10422                 return -1;
10423         ++p;
10424         p0 = strchr(p, ')');
10425         if (p0 == NULL)
10426                 return -1;
10427
10428         size = p0 - p;
10429         if (size >= sizeof(s))
10430                 return -1;
10431
10432         snprintf(s, sizeof(s), "%.*s", size, p);
10433         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10434         if (ret < 0 || ret > max_num)
10435                 return -1;
10436         for (i = 0; i < ret; i++) {
10437                 errno = 0;
10438                 int_fld = strtoul(str_fld[i], &end, 0);
10439                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10440                         return -1;
10441                 flexbytes[i] = (uint8_t)int_fld;
10442         }
10443         return ret;
10444 }
10445
10446 static uint16_t
10447 str2flowtype(char *string)
10448 {
10449         uint8_t i = 0;
10450         static const struct {
10451                 char str[32];
10452                 uint16_t type;
10453         } flowtype_str[] = {
10454                 {"raw", RTE_ETH_FLOW_RAW},
10455                 {"ipv4", RTE_ETH_FLOW_IPV4},
10456                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10457                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10458                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10459                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10460                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10461                 {"ipv6", RTE_ETH_FLOW_IPV6},
10462                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10463                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10464                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10465                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10466                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10467                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10468         };
10469
10470         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10471                 if (!strcmp(flowtype_str[i].str, string))
10472                         return flowtype_str[i].type;
10473         }
10474
10475         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10476                 return (uint16_t)atoi(string);
10477
10478         return RTE_ETH_FLOW_UNKNOWN;
10479 }
10480
10481 static enum rte_eth_fdir_tunnel_type
10482 str2fdir_tunneltype(char *string)
10483 {
10484         uint8_t i = 0;
10485
10486         static const struct {
10487                 char str[32];
10488                 enum rte_eth_fdir_tunnel_type type;
10489         } tunneltype_str[] = {
10490                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10491                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10492         };
10493
10494         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10495                 if (!strcmp(tunneltype_str[i].str, string))
10496                         return tunneltype_str[i].type;
10497         }
10498         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10499 }
10500
10501 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10502 do { \
10503         if ((ip_addr).family == AF_INET) \
10504                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10505         else { \
10506                 printf("invalid parameter.\n"); \
10507                 return; \
10508         } \
10509 } while (0)
10510
10511 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10512 do { \
10513         if ((ip_addr).family == AF_INET6) \
10514                 rte_memcpy(&(ip), \
10515                                  &((ip_addr).addr.ipv6), \
10516                                  sizeof(struct in6_addr)); \
10517         else { \
10518                 printf("invalid parameter.\n"); \
10519                 return; \
10520         } \
10521 } while (0)
10522
10523 static void
10524 cmd_flow_director_filter_parsed(void *parsed_result,
10525                           __attribute__((unused)) struct cmdline *cl,
10526                           __attribute__((unused)) void *data)
10527 {
10528         struct cmd_flow_director_result *res = parsed_result;
10529         struct rte_eth_fdir_filter entry;
10530         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10531         char *end;
10532         unsigned long vf_id;
10533         int ret = 0;
10534
10535         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10536         if (ret < 0) {
10537                 printf("flow director is not supported on port %u.\n",
10538                         res->port_id);
10539                 return;
10540         }
10541         memset(flexbytes, 0, sizeof(flexbytes));
10542         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10543
10544         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10545                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10546                         printf("Please set mode to MAC-VLAN.\n");
10547                         return;
10548                 }
10549         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10550                 if (strcmp(res->mode_value, "Tunnel")) {
10551                         printf("Please set mode to Tunnel.\n");
10552                         return;
10553                 }
10554         } else {
10555                 if (!strcmp(res->mode_value, "raw")) {
10556 #ifdef RTE_LIBRTE_I40E_PMD
10557                         struct rte_pmd_i40e_flow_type_mapping
10558                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10559                         struct rte_pmd_i40e_pkt_template_conf conf;
10560                         uint16_t flow_type = str2flowtype(res->flow_type);
10561                         uint16_t i, port = res->port_id;
10562                         uint8_t add;
10563
10564                         memset(&conf, 0, sizeof(conf));
10565
10566                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10567                                 printf("Invalid flow type specified.\n");
10568                                 return;
10569                         }
10570                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10571                                                                  mapping);
10572                         if (ret)
10573                                 return;
10574                         if (mapping[flow_type].pctype == 0ULL) {
10575                                 printf("Invalid flow type specified.\n");
10576                                 return;
10577                         }
10578                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10579                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10580                                         conf.input.pctype = i;
10581                                         break;
10582                                 }
10583                         }
10584
10585                         conf.input.packet = open_file(res->filepath,
10586                                                 &conf.input.length);
10587                         if (!conf.input.packet)
10588                                 return;
10589                         if (!strcmp(res->drop, "drop"))
10590                                 conf.action.behavior =
10591                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10592                         else
10593                                 conf.action.behavior =
10594                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10595                         conf.action.report_status =
10596                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10597                         conf.action.rx_queue = res->queue_id;
10598                         conf.soft_id = res->fd_id_value;
10599                         add  = strcmp(res->ops, "del") ? 1 : 0;
10600                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10601                                                                         &conf,
10602                                                                         add);
10603                         if (ret < 0)
10604                                 printf("flow director config error: (%s)\n",
10605                                        strerror(-ret));
10606                         close_file(conf.input.packet);
10607 #endif
10608                         return;
10609                 } else if (strcmp(res->mode_value, "IP")) {
10610                         printf("Please set mode to IP or raw.\n");
10611                         return;
10612                 }
10613                 entry.input.flow_type = str2flowtype(res->flow_type);
10614         }
10615
10616         ret = parse_flexbytes(res->flexbytes_value,
10617                                         flexbytes,
10618                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10619         if (ret < 0) {
10620                 printf("error: Cannot parse flexbytes input.\n");
10621                 return;
10622         }
10623
10624         switch (entry.input.flow_type) {
10625         case RTE_ETH_FLOW_FRAG_IPV4:
10626         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10627                 entry.input.flow.ip4_flow.proto = res->proto_value;
10628                 /* fall-through */
10629         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10630         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10631                 IPV4_ADDR_TO_UINT(res->ip_dst,
10632                         entry.input.flow.ip4_flow.dst_ip);
10633                 IPV4_ADDR_TO_UINT(res->ip_src,
10634                         entry.input.flow.ip4_flow.src_ip);
10635                 entry.input.flow.ip4_flow.tos = res->tos_value;
10636                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10637                 /* need convert to big endian. */
10638                 entry.input.flow.udp4_flow.dst_port =
10639                                 rte_cpu_to_be_16(res->port_dst);
10640                 entry.input.flow.udp4_flow.src_port =
10641                                 rte_cpu_to_be_16(res->port_src);
10642                 break;
10643         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10644                 IPV4_ADDR_TO_UINT(res->ip_dst,
10645                         entry.input.flow.sctp4_flow.ip.dst_ip);
10646                 IPV4_ADDR_TO_UINT(res->ip_src,
10647                         entry.input.flow.sctp4_flow.ip.src_ip);
10648                 entry.input.flow.ip4_flow.tos = res->tos_value;
10649                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10650                 /* need convert to big endian. */
10651                 entry.input.flow.sctp4_flow.dst_port =
10652                                 rte_cpu_to_be_16(res->port_dst);
10653                 entry.input.flow.sctp4_flow.src_port =
10654                                 rte_cpu_to_be_16(res->port_src);
10655                 entry.input.flow.sctp4_flow.verify_tag =
10656                                 rte_cpu_to_be_32(res->verify_tag_value);
10657                 break;
10658         case RTE_ETH_FLOW_FRAG_IPV6:
10659         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10660                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10661                 /* fall-through */
10662         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10663         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10664                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10665                         entry.input.flow.ipv6_flow.dst_ip);
10666                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10667                         entry.input.flow.ipv6_flow.src_ip);
10668                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10669                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10670                 /* need convert to big endian. */
10671                 entry.input.flow.udp6_flow.dst_port =
10672                                 rte_cpu_to_be_16(res->port_dst);
10673                 entry.input.flow.udp6_flow.src_port =
10674                                 rte_cpu_to_be_16(res->port_src);
10675                 break;
10676         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10677                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10678                         entry.input.flow.sctp6_flow.ip.dst_ip);
10679                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10680                         entry.input.flow.sctp6_flow.ip.src_ip);
10681                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10682                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10683                 /* need convert to big endian. */
10684                 entry.input.flow.sctp6_flow.dst_port =
10685                                 rte_cpu_to_be_16(res->port_dst);
10686                 entry.input.flow.sctp6_flow.src_port =
10687                                 rte_cpu_to_be_16(res->port_src);
10688                 entry.input.flow.sctp6_flow.verify_tag =
10689                                 rte_cpu_to_be_32(res->verify_tag_value);
10690                 break;
10691         case RTE_ETH_FLOW_L2_PAYLOAD:
10692                 entry.input.flow.l2_flow.ether_type =
10693                         rte_cpu_to_be_16(res->ether_type);
10694                 break;
10695         default:
10696                 break;
10697         }
10698
10699         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10700                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10701                                  &res->mac_addr,
10702                                  sizeof(struct ether_addr));
10703
10704         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10705                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10706                                  &res->mac_addr,
10707                                  sizeof(struct ether_addr));
10708                 entry.input.flow.tunnel_flow.tunnel_type =
10709                         str2fdir_tunneltype(res->tunnel_type);
10710                 entry.input.flow.tunnel_flow.tunnel_id =
10711                         rte_cpu_to_be_32(res->tunnel_id_value);
10712         }
10713
10714         rte_memcpy(entry.input.flow_ext.flexbytes,
10715                    flexbytes,
10716                    RTE_ETH_FDIR_MAX_FLEXLEN);
10717
10718         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10719
10720         entry.action.flex_off = 0;  /*use 0 by default */
10721         if (!strcmp(res->drop, "drop"))
10722                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10723         else
10724                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10725
10726         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10727             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10728                 if (!strcmp(res->pf_vf, "pf"))
10729                         entry.input.flow_ext.is_vf = 0;
10730                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10731                         struct rte_eth_dev_info dev_info;
10732
10733                         memset(&dev_info, 0, sizeof(dev_info));
10734                         rte_eth_dev_info_get(res->port_id, &dev_info);
10735                         errno = 0;
10736                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10737                         if (errno != 0 || *end != '\0' ||
10738                             vf_id >= dev_info.max_vfs) {
10739                                 printf("invalid parameter %s.\n", res->pf_vf);
10740                                 return;
10741                         }
10742                         entry.input.flow_ext.is_vf = 1;
10743                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10744                 } else {
10745                         printf("invalid parameter %s.\n", res->pf_vf);
10746                         return;
10747                 }
10748         }
10749
10750         /* set to report FD ID by default */
10751         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10752         entry.action.rx_queue = res->queue_id;
10753         entry.soft_id = res->fd_id_value;
10754         if (!strcmp(res->ops, "add"))
10755                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10756                                              RTE_ETH_FILTER_ADD, &entry);
10757         else if (!strcmp(res->ops, "del"))
10758                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10759                                              RTE_ETH_FILTER_DELETE, &entry);
10760         else
10761                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10762                                              RTE_ETH_FILTER_UPDATE, &entry);
10763         if (ret < 0)
10764                 printf("flow director programming error: (%s)\n",
10765                         strerror(-ret));
10766 }
10767
10768 cmdline_parse_token_string_t cmd_flow_director_filter =
10769         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10770                                  flow_director_filter, "flow_director_filter");
10771 cmdline_parse_token_num_t cmd_flow_director_port_id =
10772         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10773                               port_id, UINT16);
10774 cmdline_parse_token_string_t cmd_flow_director_ops =
10775         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10776                                  ops, "add#del#update");
10777 cmdline_parse_token_string_t cmd_flow_director_flow =
10778         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10779                                  flow, "flow");
10780 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10781         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10782                 flow_type, NULL);
10783 cmdline_parse_token_string_t cmd_flow_director_ether =
10784         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10785                                  ether, "ether");
10786 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10787         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10788                               ether_type, UINT16);
10789 cmdline_parse_token_string_t cmd_flow_director_src =
10790         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10791                                  src, "src");
10792 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10793         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10794                                  ip_src);
10795 cmdline_parse_token_num_t cmd_flow_director_port_src =
10796         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10797                               port_src, UINT16);
10798 cmdline_parse_token_string_t cmd_flow_director_dst =
10799         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10800                                  dst, "dst");
10801 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10802         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10803                                  ip_dst);
10804 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10805         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10806                               port_dst, UINT16);
10807 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10808         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10809                                   verify_tag, "verify_tag");
10810 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10811         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10812                               verify_tag_value, UINT32);
10813 cmdline_parse_token_string_t cmd_flow_director_tos =
10814         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10815                                  tos, "tos");
10816 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10817         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10818                               tos_value, UINT8);
10819 cmdline_parse_token_string_t cmd_flow_director_proto =
10820         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10821                                  proto, "proto");
10822 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10823         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10824                               proto_value, UINT8);
10825 cmdline_parse_token_string_t cmd_flow_director_ttl =
10826         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10827                                  ttl, "ttl");
10828 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10829         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10830                               ttl_value, UINT8);
10831 cmdline_parse_token_string_t cmd_flow_director_vlan =
10832         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10833                                  vlan, "vlan");
10834 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10835         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10836                               vlan_value, UINT16);
10837 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10838         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10839                                  flexbytes, "flexbytes");
10840 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10841         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10842                               flexbytes_value, NULL);
10843 cmdline_parse_token_string_t cmd_flow_director_drop =
10844         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10845                                  drop, "drop#fwd");
10846 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10847         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10848                               pf_vf, NULL);
10849 cmdline_parse_token_string_t cmd_flow_director_queue =
10850         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10851                                  queue, "queue");
10852 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10853         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10854                               queue_id, UINT16);
10855 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10856         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10857                                  fd_id, "fd_id");
10858 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10859         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10860                               fd_id_value, UINT32);
10861
10862 cmdline_parse_token_string_t cmd_flow_director_mode =
10863         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10864                                  mode, "mode");
10865 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10866         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10867                                  mode_value, "IP");
10868 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10869         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10870                                  mode_value, "MAC-VLAN");
10871 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10872         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10873                                  mode_value, "Tunnel");
10874 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10875         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10876                                  mode_value, "raw");
10877 cmdline_parse_token_string_t cmd_flow_director_mac =
10878         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10879                                  mac, "mac");
10880 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10881         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10882                                     mac_addr);
10883 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10884         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10885                                  tunnel, "tunnel");
10886 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10887         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10888                                  tunnel_type, "NVGRE#VxLAN");
10889 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10890         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10891                                  tunnel_id, "tunnel-id");
10892 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10893         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10894                               tunnel_id_value, UINT32);
10895 cmdline_parse_token_string_t cmd_flow_director_packet =
10896         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10897                                  packet, "packet");
10898 cmdline_parse_token_string_t cmd_flow_director_filepath =
10899         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10900                                  filepath, NULL);
10901
10902 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10903         .f = cmd_flow_director_filter_parsed,
10904         .data = NULL,
10905         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10906                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10907                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10908                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10909                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10910                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10911                 "fd_id <fd_id_value>: "
10912                 "Add or delete an ip flow director entry on NIC",
10913         .tokens = {
10914                 (void *)&cmd_flow_director_filter,
10915                 (void *)&cmd_flow_director_port_id,
10916                 (void *)&cmd_flow_director_mode,
10917                 (void *)&cmd_flow_director_mode_ip,
10918                 (void *)&cmd_flow_director_ops,
10919                 (void *)&cmd_flow_director_flow,
10920                 (void *)&cmd_flow_director_flow_type,
10921                 (void *)&cmd_flow_director_src,
10922                 (void *)&cmd_flow_director_ip_src,
10923                 (void *)&cmd_flow_director_dst,
10924                 (void *)&cmd_flow_director_ip_dst,
10925                 (void *)&cmd_flow_director_tos,
10926                 (void *)&cmd_flow_director_tos_value,
10927                 (void *)&cmd_flow_director_proto,
10928                 (void *)&cmd_flow_director_proto_value,
10929                 (void *)&cmd_flow_director_ttl,
10930                 (void *)&cmd_flow_director_ttl_value,
10931                 (void *)&cmd_flow_director_vlan,
10932                 (void *)&cmd_flow_director_vlan_value,
10933                 (void *)&cmd_flow_director_flexbytes,
10934                 (void *)&cmd_flow_director_flexbytes_value,
10935                 (void *)&cmd_flow_director_drop,
10936                 (void *)&cmd_flow_director_pf_vf,
10937                 (void *)&cmd_flow_director_queue,
10938                 (void *)&cmd_flow_director_queue_id,
10939                 (void *)&cmd_flow_director_fd_id,
10940                 (void *)&cmd_flow_director_fd_id_value,
10941                 NULL,
10942         },
10943 };
10944
10945 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10946         .f = cmd_flow_director_filter_parsed,
10947         .data = NULL,
10948         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10949                 "director entry on NIC",
10950         .tokens = {
10951                 (void *)&cmd_flow_director_filter,
10952                 (void *)&cmd_flow_director_port_id,
10953                 (void *)&cmd_flow_director_mode,
10954                 (void *)&cmd_flow_director_mode_ip,
10955                 (void *)&cmd_flow_director_ops,
10956                 (void *)&cmd_flow_director_flow,
10957                 (void *)&cmd_flow_director_flow_type,
10958                 (void *)&cmd_flow_director_src,
10959                 (void *)&cmd_flow_director_ip_src,
10960                 (void *)&cmd_flow_director_port_src,
10961                 (void *)&cmd_flow_director_dst,
10962                 (void *)&cmd_flow_director_ip_dst,
10963                 (void *)&cmd_flow_director_port_dst,
10964                 (void *)&cmd_flow_director_tos,
10965                 (void *)&cmd_flow_director_tos_value,
10966                 (void *)&cmd_flow_director_ttl,
10967                 (void *)&cmd_flow_director_ttl_value,
10968                 (void *)&cmd_flow_director_vlan,
10969                 (void *)&cmd_flow_director_vlan_value,
10970                 (void *)&cmd_flow_director_flexbytes,
10971                 (void *)&cmd_flow_director_flexbytes_value,
10972                 (void *)&cmd_flow_director_drop,
10973                 (void *)&cmd_flow_director_pf_vf,
10974                 (void *)&cmd_flow_director_queue,
10975                 (void *)&cmd_flow_director_queue_id,
10976                 (void *)&cmd_flow_director_fd_id,
10977                 (void *)&cmd_flow_director_fd_id_value,
10978                 NULL,
10979         },
10980 };
10981
10982 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10983         .f = cmd_flow_director_filter_parsed,
10984         .data = NULL,
10985         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10986                 "director entry on NIC",
10987         .tokens = {
10988                 (void *)&cmd_flow_director_filter,
10989                 (void *)&cmd_flow_director_port_id,
10990                 (void *)&cmd_flow_director_mode,
10991                 (void *)&cmd_flow_director_mode_ip,
10992                 (void *)&cmd_flow_director_ops,
10993                 (void *)&cmd_flow_director_flow,
10994                 (void *)&cmd_flow_director_flow_type,
10995                 (void *)&cmd_flow_director_src,
10996                 (void *)&cmd_flow_director_ip_src,
10997                 (void *)&cmd_flow_director_port_src,
10998                 (void *)&cmd_flow_director_dst,
10999                 (void *)&cmd_flow_director_ip_dst,
11000                 (void *)&cmd_flow_director_port_dst,
11001                 (void *)&cmd_flow_director_verify_tag,
11002                 (void *)&cmd_flow_director_verify_tag_value,
11003                 (void *)&cmd_flow_director_tos,
11004                 (void *)&cmd_flow_director_tos_value,
11005                 (void *)&cmd_flow_director_ttl,
11006                 (void *)&cmd_flow_director_ttl_value,
11007                 (void *)&cmd_flow_director_vlan,
11008                 (void *)&cmd_flow_director_vlan_value,
11009                 (void *)&cmd_flow_director_flexbytes,
11010                 (void *)&cmd_flow_director_flexbytes_value,
11011                 (void *)&cmd_flow_director_drop,
11012                 (void *)&cmd_flow_director_pf_vf,
11013                 (void *)&cmd_flow_director_queue,
11014                 (void *)&cmd_flow_director_queue_id,
11015                 (void *)&cmd_flow_director_fd_id,
11016                 (void *)&cmd_flow_director_fd_id_value,
11017                 NULL,
11018         },
11019 };
11020
11021 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11022         .f = cmd_flow_director_filter_parsed,
11023         .data = NULL,
11024         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11025                 "director entry on NIC",
11026         .tokens = {
11027                 (void *)&cmd_flow_director_filter,
11028                 (void *)&cmd_flow_director_port_id,
11029                 (void *)&cmd_flow_director_mode,
11030                 (void *)&cmd_flow_director_mode_ip,
11031                 (void *)&cmd_flow_director_ops,
11032                 (void *)&cmd_flow_director_flow,
11033                 (void *)&cmd_flow_director_flow_type,
11034                 (void *)&cmd_flow_director_ether,
11035                 (void *)&cmd_flow_director_ether_type,
11036                 (void *)&cmd_flow_director_flexbytes,
11037                 (void *)&cmd_flow_director_flexbytes_value,
11038                 (void *)&cmd_flow_director_drop,
11039                 (void *)&cmd_flow_director_pf_vf,
11040                 (void *)&cmd_flow_director_queue,
11041                 (void *)&cmd_flow_director_queue_id,
11042                 (void *)&cmd_flow_director_fd_id,
11043                 (void *)&cmd_flow_director_fd_id_value,
11044                 NULL,
11045         },
11046 };
11047
11048 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11049         .f = cmd_flow_director_filter_parsed,
11050         .data = NULL,
11051         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11052                 "director entry on NIC",
11053         .tokens = {
11054                 (void *)&cmd_flow_director_filter,
11055                 (void *)&cmd_flow_director_port_id,
11056                 (void *)&cmd_flow_director_mode,
11057                 (void *)&cmd_flow_director_mode_mac_vlan,
11058                 (void *)&cmd_flow_director_ops,
11059                 (void *)&cmd_flow_director_mac,
11060                 (void *)&cmd_flow_director_mac_addr,
11061                 (void *)&cmd_flow_director_vlan,
11062                 (void *)&cmd_flow_director_vlan_value,
11063                 (void *)&cmd_flow_director_flexbytes,
11064                 (void *)&cmd_flow_director_flexbytes_value,
11065                 (void *)&cmd_flow_director_drop,
11066                 (void *)&cmd_flow_director_queue,
11067                 (void *)&cmd_flow_director_queue_id,
11068                 (void *)&cmd_flow_director_fd_id,
11069                 (void *)&cmd_flow_director_fd_id_value,
11070                 NULL,
11071         },
11072 };
11073
11074 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11075         .f = cmd_flow_director_filter_parsed,
11076         .data = NULL,
11077         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11078                 "director entry on NIC",
11079         .tokens = {
11080                 (void *)&cmd_flow_director_filter,
11081                 (void *)&cmd_flow_director_port_id,
11082                 (void *)&cmd_flow_director_mode,
11083                 (void *)&cmd_flow_director_mode_tunnel,
11084                 (void *)&cmd_flow_director_ops,
11085                 (void *)&cmd_flow_director_mac,
11086                 (void *)&cmd_flow_director_mac_addr,
11087                 (void *)&cmd_flow_director_vlan,
11088                 (void *)&cmd_flow_director_vlan_value,
11089                 (void *)&cmd_flow_director_tunnel,
11090                 (void *)&cmd_flow_director_tunnel_type,
11091                 (void *)&cmd_flow_director_tunnel_id,
11092                 (void *)&cmd_flow_director_tunnel_id_value,
11093                 (void *)&cmd_flow_director_flexbytes,
11094                 (void *)&cmd_flow_director_flexbytes_value,
11095                 (void *)&cmd_flow_director_drop,
11096                 (void *)&cmd_flow_director_queue,
11097                 (void *)&cmd_flow_director_queue_id,
11098                 (void *)&cmd_flow_director_fd_id,
11099                 (void *)&cmd_flow_director_fd_id_value,
11100                 NULL,
11101         },
11102 };
11103
11104 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11105         .f = cmd_flow_director_filter_parsed,
11106         .data = NULL,
11107         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11108                 "director entry on NIC",
11109         .tokens = {
11110                 (void *)&cmd_flow_director_filter,
11111                 (void *)&cmd_flow_director_port_id,
11112                 (void *)&cmd_flow_director_mode,
11113                 (void *)&cmd_flow_director_mode_raw,
11114                 (void *)&cmd_flow_director_ops,
11115                 (void *)&cmd_flow_director_flow,
11116                 (void *)&cmd_flow_director_flow_type,
11117                 (void *)&cmd_flow_director_drop,
11118                 (void *)&cmd_flow_director_queue,
11119                 (void *)&cmd_flow_director_queue_id,
11120                 (void *)&cmd_flow_director_fd_id,
11121                 (void *)&cmd_flow_director_fd_id_value,
11122                 (void *)&cmd_flow_director_packet,
11123                 (void *)&cmd_flow_director_filepath,
11124                 NULL,
11125         },
11126 };
11127
11128 struct cmd_flush_flow_director_result {
11129         cmdline_fixed_string_t flush_flow_director;
11130         portid_t port_id;
11131 };
11132
11133 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11134         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11135                                  flush_flow_director, "flush_flow_director");
11136 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11137         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11138                               port_id, UINT16);
11139
11140 static void
11141 cmd_flush_flow_director_parsed(void *parsed_result,
11142                           __attribute__((unused)) struct cmdline *cl,
11143                           __attribute__((unused)) void *data)
11144 {
11145         struct cmd_flow_director_result *res = parsed_result;
11146         int ret = 0;
11147
11148         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11149         if (ret < 0) {
11150                 printf("flow director is not supported on port %u.\n",
11151                         res->port_id);
11152                 return;
11153         }
11154
11155         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11156                         RTE_ETH_FILTER_FLUSH, NULL);
11157         if (ret < 0)
11158                 printf("flow director table flushing error: (%s)\n",
11159                         strerror(-ret));
11160 }
11161
11162 cmdline_parse_inst_t cmd_flush_flow_director = {
11163         .f = cmd_flush_flow_director_parsed,
11164         .data = NULL,
11165         .help_str = "flush_flow_director <port_id>: "
11166                 "Flush all flow director entries of a device on NIC",
11167         .tokens = {
11168                 (void *)&cmd_flush_flow_director_flush,
11169                 (void *)&cmd_flush_flow_director_port_id,
11170                 NULL,
11171         },
11172 };
11173
11174 /* *** deal with flow director mask *** */
11175 struct cmd_flow_director_mask_result {
11176         cmdline_fixed_string_t flow_director_mask;
11177         portid_t port_id;
11178         cmdline_fixed_string_t mode;
11179         cmdline_fixed_string_t mode_value;
11180         cmdline_fixed_string_t vlan;
11181         uint16_t vlan_mask;
11182         cmdline_fixed_string_t src_mask;
11183         cmdline_ipaddr_t ipv4_src;
11184         cmdline_ipaddr_t ipv6_src;
11185         uint16_t port_src;
11186         cmdline_fixed_string_t dst_mask;
11187         cmdline_ipaddr_t ipv4_dst;
11188         cmdline_ipaddr_t ipv6_dst;
11189         uint16_t port_dst;
11190         cmdline_fixed_string_t mac;
11191         uint8_t mac_addr_byte_mask;
11192         cmdline_fixed_string_t tunnel_id;
11193         uint32_t tunnel_id_mask;
11194         cmdline_fixed_string_t tunnel_type;
11195         uint8_t tunnel_type_mask;
11196 };
11197
11198 static void
11199 cmd_flow_director_mask_parsed(void *parsed_result,
11200                           __attribute__((unused)) struct cmdline *cl,
11201                           __attribute__((unused)) void *data)
11202 {
11203         struct cmd_flow_director_mask_result *res = parsed_result;
11204         struct rte_eth_fdir_masks *mask;
11205         struct rte_port *port;
11206
11207         port = &ports[res->port_id];
11208         /** Check if the port is not started **/
11209         if (port->port_status != RTE_PORT_STOPPED) {
11210                 printf("Please stop port %d first\n", res->port_id);
11211                 return;
11212         }
11213
11214         mask = &port->dev_conf.fdir_conf.mask;
11215
11216         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11217                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11218                         printf("Please set mode to MAC-VLAN.\n");
11219                         return;
11220                 }
11221
11222                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11223         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11224                 if (strcmp(res->mode_value, "Tunnel")) {
11225                         printf("Please set mode to Tunnel.\n");
11226                         return;
11227                 }
11228
11229                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11230                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11231                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11232                 mask->tunnel_type_mask = res->tunnel_type_mask;
11233         } else {
11234                 if (strcmp(res->mode_value, "IP")) {
11235                         printf("Please set mode to IP.\n");
11236                         return;
11237                 }
11238
11239                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11240                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11241                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11242                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11243                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11244                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11245                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11246         }
11247
11248         cmd_reconfig_device_queue(res->port_id, 1, 1);
11249 }
11250
11251 cmdline_parse_token_string_t cmd_flow_director_mask =
11252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11253                                  flow_director_mask, "flow_director_mask");
11254 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11255         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11256                               port_id, UINT16);
11257 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11258         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11259                                  vlan, "vlan");
11260 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11261         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11262                               vlan_mask, UINT16);
11263 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11264         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11265                                  src_mask, "src_mask");
11266 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11267         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11268                                  ipv4_src);
11269 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11270         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11271                                  ipv6_src);
11272 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11273         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11274                               port_src, UINT16);
11275 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11276         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11277                                  dst_mask, "dst_mask");
11278 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11279         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11280                                  ipv4_dst);
11281 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11282         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11283                                  ipv6_dst);
11284 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11285         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11286                               port_dst, UINT16);
11287
11288 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11289         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11290                                  mode, "mode");
11291 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11292         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11293                                  mode_value, "IP");
11294 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11295         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11296                                  mode_value, "MAC-VLAN");
11297 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11298         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11299                                  mode_value, "Tunnel");
11300 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11301         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11302                                  mac, "mac");
11303 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11304         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11305                               mac_addr_byte_mask, UINT8);
11306 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11307         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11308                                  tunnel_type, "tunnel-type");
11309 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11310         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11311                               tunnel_type_mask, UINT8);
11312 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11313         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11314                                  tunnel_id, "tunnel-id");
11315 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11316         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11317                               tunnel_id_mask, UINT32);
11318
11319 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11320         .f = cmd_flow_director_mask_parsed,
11321         .data = NULL,
11322         .help_str = "flow_director_mask ... : "
11323                 "Set IP mode flow director's mask on NIC",
11324         .tokens = {
11325                 (void *)&cmd_flow_director_mask,
11326                 (void *)&cmd_flow_director_mask_port_id,
11327                 (void *)&cmd_flow_director_mask_mode,
11328                 (void *)&cmd_flow_director_mask_mode_ip,
11329                 (void *)&cmd_flow_director_mask_vlan,
11330                 (void *)&cmd_flow_director_mask_vlan_value,
11331                 (void *)&cmd_flow_director_mask_src,
11332                 (void *)&cmd_flow_director_mask_ipv4_src,
11333                 (void *)&cmd_flow_director_mask_ipv6_src,
11334                 (void *)&cmd_flow_director_mask_port_src,
11335                 (void *)&cmd_flow_director_mask_dst,
11336                 (void *)&cmd_flow_director_mask_ipv4_dst,
11337                 (void *)&cmd_flow_director_mask_ipv6_dst,
11338                 (void *)&cmd_flow_director_mask_port_dst,
11339                 NULL,
11340         },
11341 };
11342
11343 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11344         .f = cmd_flow_director_mask_parsed,
11345         .data = NULL,
11346         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11347                 "flow director's mask on NIC",
11348         .tokens = {
11349                 (void *)&cmd_flow_director_mask,
11350                 (void *)&cmd_flow_director_mask_port_id,
11351                 (void *)&cmd_flow_director_mask_mode,
11352                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11353                 (void *)&cmd_flow_director_mask_vlan,
11354                 (void *)&cmd_flow_director_mask_vlan_value,
11355                 NULL,
11356         },
11357 };
11358
11359 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11360         .f = cmd_flow_director_mask_parsed,
11361         .data = NULL,
11362         .help_str = "flow_director_mask ... : Set tunnel mode "
11363                 "flow director's mask on NIC",
11364         .tokens = {
11365                 (void *)&cmd_flow_director_mask,
11366                 (void *)&cmd_flow_director_mask_port_id,
11367                 (void *)&cmd_flow_director_mask_mode,
11368                 (void *)&cmd_flow_director_mask_mode_tunnel,
11369                 (void *)&cmd_flow_director_mask_vlan,
11370                 (void *)&cmd_flow_director_mask_vlan_value,
11371                 (void *)&cmd_flow_director_mask_mac,
11372                 (void *)&cmd_flow_director_mask_mac_value,
11373                 (void *)&cmd_flow_director_mask_tunnel_type,
11374                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11375                 (void *)&cmd_flow_director_mask_tunnel_id,
11376                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11377                 NULL,
11378         },
11379 };
11380
11381 /* *** deal with flow director mask on flexible payload *** */
11382 struct cmd_flow_director_flex_mask_result {
11383         cmdline_fixed_string_t flow_director_flexmask;
11384         portid_t port_id;
11385         cmdline_fixed_string_t flow;
11386         cmdline_fixed_string_t flow_type;
11387         cmdline_fixed_string_t mask;
11388 };
11389
11390 static void
11391 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11392                           __attribute__((unused)) struct cmdline *cl,
11393                           __attribute__((unused)) void *data)
11394 {
11395         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11396         struct rte_eth_fdir_info fdir_info;
11397         struct rte_eth_fdir_flex_mask flex_mask;
11398         struct rte_port *port;
11399         uint64_t flow_type_mask;
11400         uint16_t i;
11401         int ret;
11402
11403         port = &ports[res->port_id];
11404         /** Check if the port is not started **/
11405         if (port->port_status != RTE_PORT_STOPPED) {
11406                 printf("Please stop port %d first\n", res->port_id);
11407                 return;
11408         }
11409
11410         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11411         ret = parse_flexbytes(res->mask,
11412                         flex_mask.mask,
11413                         RTE_ETH_FDIR_MAX_FLEXLEN);
11414         if (ret < 0) {
11415                 printf("error: Cannot parse mask input.\n");
11416                 return;
11417         }
11418
11419         memset(&fdir_info, 0, sizeof(fdir_info));
11420         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11421                                 RTE_ETH_FILTER_INFO, &fdir_info);
11422         if (ret < 0) {
11423                 printf("Cannot get FDir filter info\n");
11424                 return;
11425         }
11426
11427         if (!strcmp(res->flow_type, "none")) {
11428                 /* means don't specify the flow type */
11429                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11430                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11431                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11432                                0, sizeof(struct rte_eth_fdir_flex_mask));
11433                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11434                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11435                                  &flex_mask,
11436                                  sizeof(struct rte_eth_fdir_flex_mask));
11437                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11438                 return;
11439         }
11440         flow_type_mask = fdir_info.flow_types_mask[0];
11441         if (!strcmp(res->flow_type, "all")) {
11442                 if (!flow_type_mask) {
11443                         printf("No flow type supported\n");
11444                         return;
11445                 }
11446                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11447                         if (flow_type_mask & (1ULL << i)) {
11448                                 flex_mask.flow_type = i;
11449                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11450                         }
11451                 }
11452                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11453                 return;
11454         }
11455         flex_mask.flow_type = str2flowtype(res->flow_type);
11456         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11457                 printf("Flow type %s not supported on port %d\n",
11458                                 res->flow_type, res->port_id);
11459                 return;
11460         }
11461         fdir_set_flex_mask(res->port_id, &flex_mask);
11462         cmd_reconfig_device_queue(res->port_id, 1, 1);
11463 }
11464
11465 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11466         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11467                                  flow_director_flexmask,
11468                                  "flow_director_flex_mask");
11469 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11470         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11471                               port_id, UINT16);
11472 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11473         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11474                                  flow, "flow");
11475 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11476         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11477                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11478                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11479 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11480         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11481                                  mask, NULL);
11482
11483 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11484         .f = cmd_flow_director_flex_mask_parsed,
11485         .data = NULL,
11486         .help_str = "flow_director_flex_mask ... : "
11487                 "Set flow director's flex mask on NIC",
11488         .tokens = {
11489                 (void *)&cmd_flow_director_flexmask,
11490                 (void *)&cmd_flow_director_flexmask_port_id,
11491                 (void *)&cmd_flow_director_flexmask_flow,
11492                 (void *)&cmd_flow_director_flexmask_flow_type,
11493                 (void *)&cmd_flow_director_flexmask_mask,
11494                 NULL,
11495         },
11496 };
11497
11498 /* *** deal with flow director flexible payload configuration *** */
11499 struct cmd_flow_director_flexpayload_result {
11500         cmdline_fixed_string_t flow_director_flexpayload;
11501         portid_t port_id;
11502         cmdline_fixed_string_t payload_layer;
11503         cmdline_fixed_string_t payload_cfg;
11504 };
11505
11506 static inline int
11507 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11508 {
11509         char s[256];
11510         const char *p, *p0 = q_arg;
11511         char *end;
11512         unsigned long int_fld;
11513         char *str_fld[max_num];
11514         int i;
11515         unsigned size;
11516         int ret = -1;
11517
11518         p = strchr(p0, '(');
11519         if (p == NULL)
11520                 return -1;
11521         ++p;
11522         p0 = strchr(p, ')');
11523         if (p0 == NULL)
11524                 return -1;
11525
11526         size = p0 - p;
11527         if (size >= sizeof(s))
11528                 return -1;
11529
11530         snprintf(s, sizeof(s), "%.*s", size, p);
11531         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11532         if (ret < 0 || ret > max_num)
11533                 return -1;
11534         for (i = 0; i < ret; i++) {
11535                 errno = 0;
11536                 int_fld = strtoul(str_fld[i], &end, 0);
11537                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11538                         return -1;
11539                 offsets[i] = (uint16_t)int_fld;
11540         }
11541         return ret;
11542 }
11543
11544 static void
11545 cmd_flow_director_flxpld_parsed(void *parsed_result,
11546                           __attribute__((unused)) struct cmdline *cl,
11547                           __attribute__((unused)) void *data)
11548 {
11549         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11550         struct rte_eth_flex_payload_cfg flex_cfg;
11551         struct rte_port *port;
11552         int ret = 0;
11553
11554         port = &ports[res->port_id];
11555         /** Check if the port is not started **/
11556         if (port->port_status != RTE_PORT_STOPPED) {
11557                 printf("Please stop port %d first\n", res->port_id);
11558                 return;
11559         }
11560
11561         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11562
11563         if (!strcmp(res->payload_layer, "raw"))
11564                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11565         else if (!strcmp(res->payload_layer, "l2"))
11566                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11567         else if (!strcmp(res->payload_layer, "l3"))
11568                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11569         else if (!strcmp(res->payload_layer, "l4"))
11570                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11571
11572         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11573                             RTE_ETH_FDIR_MAX_FLEXLEN);
11574         if (ret < 0) {
11575                 printf("error: Cannot parse flex payload input.\n");
11576                 return;
11577         }
11578
11579         fdir_set_flex_payload(res->port_id, &flex_cfg);
11580         cmd_reconfig_device_queue(res->port_id, 1, 1);
11581 }
11582
11583 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11584         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11585                                  flow_director_flexpayload,
11586                                  "flow_director_flex_payload");
11587 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11588         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11589                               port_id, UINT16);
11590 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11591         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11592                                  payload_layer, "raw#l2#l3#l4");
11593 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11594         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11595                                  payload_cfg, NULL);
11596
11597 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11598         .f = cmd_flow_director_flxpld_parsed,
11599         .data = NULL,
11600         .help_str = "flow_director_flexpayload ... : "
11601                 "Set flow director's flex payload on NIC",
11602         .tokens = {
11603                 (void *)&cmd_flow_director_flexpayload,
11604                 (void *)&cmd_flow_director_flexpayload_port_id,
11605                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11606                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11607                 NULL,
11608         },
11609 };
11610
11611 /* Generic flow interface command. */
11612 extern cmdline_parse_inst_t cmd_flow;
11613
11614 /* *** Classification Filters Control *** */
11615 /* *** Get symmetric hash enable per port *** */
11616 struct cmd_get_sym_hash_ena_per_port_result {
11617         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11618         portid_t port_id;
11619 };
11620
11621 static void
11622 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11623                                  __rte_unused struct cmdline *cl,
11624                                  __rte_unused void *data)
11625 {
11626         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11627         struct rte_eth_hash_filter_info info;
11628         int ret;
11629
11630         if (rte_eth_dev_filter_supported(res->port_id,
11631                                 RTE_ETH_FILTER_HASH) < 0) {
11632                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11633                                                         res->port_id);
11634                 return;
11635         }
11636
11637         memset(&info, 0, sizeof(info));
11638         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11639         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11640                                                 RTE_ETH_FILTER_GET, &info);
11641
11642         if (ret < 0) {
11643                 printf("Cannot get symmetric hash enable per port "
11644                                         "on port %u\n", res->port_id);
11645                 return;
11646         }
11647
11648         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11649                                 "enabled" : "disabled", res->port_id);
11650 }
11651
11652 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11653         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11654                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11655 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11656         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11657                 port_id, UINT16);
11658
11659 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11660         .f = cmd_get_sym_hash_per_port_parsed,
11661         .data = NULL,
11662         .help_str = "get_sym_hash_ena_per_port <port_id>",
11663         .tokens = {
11664                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11665                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11666                 NULL,
11667         },
11668 };
11669
11670 /* *** Set symmetric hash enable per port *** */
11671 struct cmd_set_sym_hash_ena_per_port_result {
11672         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11673         cmdline_fixed_string_t enable;
11674         portid_t port_id;
11675 };
11676
11677 static void
11678 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11679                                  __rte_unused struct cmdline *cl,
11680                                  __rte_unused void *data)
11681 {
11682         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11683         struct rte_eth_hash_filter_info info;
11684         int ret;
11685
11686         if (rte_eth_dev_filter_supported(res->port_id,
11687                                 RTE_ETH_FILTER_HASH) < 0) {
11688                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11689                                                         res->port_id);
11690                 return;
11691         }
11692
11693         memset(&info, 0, sizeof(info));
11694         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11695         if (!strcmp(res->enable, "enable"))
11696                 info.info.enable = 1;
11697         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11698                                         RTE_ETH_FILTER_SET, &info);
11699         if (ret < 0) {
11700                 printf("Cannot set symmetric hash enable per port on "
11701                                         "port %u\n", res->port_id);
11702                 return;
11703         }
11704         printf("Symmetric hash has been set to %s on port %u\n",
11705                                         res->enable, res->port_id);
11706 }
11707
11708 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11709         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11710                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11711 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11712         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11713                 port_id, UINT16);
11714 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11715         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11716                 enable, "enable#disable");
11717
11718 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11719         .f = cmd_set_sym_hash_per_port_parsed,
11720         .data = NULL,
11721         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11722         .tokens = {
11723                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11724                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11725                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11726                 NULL,
11727         },
11728 };
11729
11730 /* Get global config of hash function */
11731 struct cmd_get_hash_global_config_result {
11732         cmdline_fixed_string_t get_hash_global_config;
11733         portid_t port_id;
11734 };
11735
11736 static char *
11737 flowtype_to_str(uint16_t ftype)
11738 {
11739         uint16_t i;
11740         static struct {
11741                 char str[16];
11742                 uint16_t ftype;
11743         } ftype_table[] = {
11744                 {"ipv4", RTE_ETH_FLOW_IPV4},
11745                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11746                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11747                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11748                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11749                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11750                 {"ipv6", RTE_ETH_FLOW_IPV6},
11751                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11752                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11753                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11754                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11755                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11756                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11757                 {"port", RTE_ETH_FLOW_PORT},
11758                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11759                 {"geneve", RTE_ETH_FLOW_GENEVE},
11760                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11761         };
11762
11763         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11764                 if (ftype_table[i].ftype == ftype)
11765                         return ftype_table[i].str;
11766         }
11767
11768         return NULL;
11769 }
11770
11771 static void
11772 cmd_get_hash_global_config_parsed(void *parsed_result,
11773                                   __rte_unused struct cmdline *cl,
11774                                   __rte_unused void *data)
11775 {
11776         struct cmd_get_hash_global_config_result *res = parsed_result;
11777         struct rte_eth_hash_filter_info info;
11778         uint32_t idx, offset;
11779         uint16_t i;
11780         char *str;
11781         int ret;
11782
11783         if (rte_eth_dev_filter_supported(res->port_id,
11784                         RTE_ETH_FILTER_HASH) < 0) {
11785                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11786                                                         res->port_id);
11787                 return;
11788         }
11789
11790         memset(&info, 0, sizeof(info));
11791         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11792         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11793                                         RTE_ETH_FILTER_GET, &info);
11794         if (ret < 0) {
11795                 printf("Cannot get hash global configurations by port %d\n",
11796                                                         res->port_id);
11797                 return;
11798         }
11799
11800         switch (info.info.global_conf.hash_func) {
11801         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11802                 printf("Hash function is Toeplitz\n");
11803                 break;
11804         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11805                 printf("Hash function is Simple XOR\n");
11806                 break;
11807         default:
11808                 printf("Unknown hash function\n");
11809                 break;
11810         }
11811
11812         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11813                 idx = i / UINT64_BIT;
11814                 offset = i % UINT64_BIT;
11815                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11816                                                 (1ULL << offset)))
11817                         continue;
11818                 str = flowtype_to_str(i);
11819                 if (!str)
11820                         continue;
11821                 printf("Symmetric hash is %s globally for flow type %s "
11822                                                         "by port %d\n",
11823                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11824                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11825                                                         res->port_id);
11826         }
11827 }
11828
11829 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11830         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11831                 get_hash_global_config, "get_hash_global_config");
11832 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11833         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11834                 port_id, UINT16);
11835
11836 cmdline_parse_inst_t cmd_get_hash_global_config = {
11837         .f = cmd_get_hash_global_config_parsed,
11838         .data = NULL,
11839         .help_str = "get_hash_global_config <port_id>",
11840         .tokens = {
11841                 (void *)&cmd_get_hash_global_config_all,
11842                 (void *)&cmd_get_hash_global_config_port_id,
11843                 NULL,
11844         },
11845 };
11846
11847 /* Set global config of hash function */
11848 struct cmd_set_hash_global_config_result {
11849         cmdline_fixed_string_t set_hash_global_config;
11850         portid_t port_id;
11851         cmdline_fixed_string_t hash_func;
11852         cmdline_fixed_string_t flow_type;
11853         cmdline_fixed_string_t enable;
11854 };
11855
11856 static void
11857 cmd_set_hash_global_config_parsed(void *parsed_result,
11858                                   __rte_unused struct cmdline *cl,
11859                                   __rte_unused void *data)
11860 {
11861         struct cmd_set_hash_global_config_result *res = parsed_result;
11862         struct rte_eth_hash_filter_info info;
11863         uint32_t ftype, idx, offset;
11864         int ret;
11865
11866         if (rte_eth_dev_filter_supported(res->port_id,
11867                                 RTE_ETH_FILTER_HASH) < 0) {
11868                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11869                                                         res->port_id);
11870                 return;
11871         }
11872         memset(&info, 0, sizeof(info));
11873         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11874         if (!strcmp(res->hash_func, "toeplitz"))
11875                 info.info.global_conf.hash_func =
11876                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11877         else if (!strcmp(res->hash_func, "simple_xor"))
11878                 info.info.global_conf.hash_func =
11879                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11880         else if (!strcmp(res->hash_func, "default"))
11881                 info.info.global_conf.hash_func =
11882                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11883
11884         ftype = str2flowtype(res->flow_type);
11885         idx = ftype / UINT64_BIT;
11886         offset = ftype % UINT64_BIT;
11887         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11888         if (!strcmp(res->enable, "enable"))
11889                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11890                                                 (1ULL << offset);
11891         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11892                                         RTE_ETH_FILTER_SET, &info);
11893         if (ret < 0)
11894                 printf("Cannot set global hash configurations by port %d\n",
11895                                                         res->port_id);
11896         else
11897                 printf("Global hash configurations have been set "
11898                         "succcessfully by port %d\n", res->port_id);
11899 }
11900
11901 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11902         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11903                 set_hash_global_config, "set_hash_global_config");
11904 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11905         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11906                 port_id, UINT16);
11907 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11908         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11909                 hash_func, "toeplitz#simple_xor#default");
11910 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11911         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11912                 flow_type,
11913                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11914                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11915 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11916         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11917                 enable, "enable#disable");
11918
11919 cmdline_parse_inst_t cmd_set_hash_global_config = {
11920         .f = cmd_set_hash_global_config_parsed,
11921         .data = NULL,
11922         .help_str = "set_hash_global_config <port_id> "
11923                 "toeplitz|simple_xor|default "
11924                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11925                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11926                 "l2_payload enable|disable",
11927         .tokens = {
11928                 (void *)&cmd_set_hash_global_config_all,
11929                 (void *)&cmd_set_hash_global_config_port_id,
11930                 (void *)&cmd_set_hash_global_config_hash_func,
11931                 (void *)&cmd_set_hash_global_config_flow_type,
11932                 (void *)&cmd_set_hash_global_config_enable,
11933                 NULL,
11934         },
11935 };
11936
11937 /* Set hash input set */
11938 struct cmd_set_hash_input_set_result {
11939         cmdline_fixed_string_t set_hash_input_set;
11940         portid_t port_id;
11941         cmdline_fixed_string_t flow_type;
11942         cmdline_fixed_string_t inset_field;
11943         cmdline_fixed_string_t select;
11944 };
11945
11946 static enum rte_eth_input_set_field
11947 str2inset(char *string)
11948 {
11949         uint16_t i;
11950
11951         static const struct {
11952                 char str[32];
11953                 enum rte_eth_input_set_field inset;
11954         } inset_table[] = {
11955                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11956                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11957                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11958                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11959                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11960                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11961                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11962                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11963                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11964                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11965                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11966                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11967                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11968                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11969                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11970                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11971                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11972                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11973                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11974                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11975                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11976                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11977                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11978                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11979                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11980                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11981                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11982                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11983                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11984                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11985                 {"none", RTE_ETH_INPUT_SET_NONE},
11986         };
11987
11988         for (i = 0; i < RTE_DIM(inset_table); i++) {
11989                 if (!strcmp(string, inset_table[i].str))
11990                         return inset_table[i].inset;
11991         }
11992
11993         return RTE_ETH_INPUT_SET_UNKNOWN;
11994 }
11995
11996 static void
11997 cmd_set_hash_input_set_parsed(void *parsed_result,
11998                               __rte_unused struct cmdline *cl,
11999                               __rte_unused void *data)
12000 {
12001         struct cmd_set_hash_input_set_result *res = parsed_result;
12002         struct rte_eth_hash_filter_info info;
12003
12004         memset(&info, 0, sizeof(info));
12005         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12006         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12007         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12008         info.info.input_set_conf.inset_size = 1;
12009         if (!strcmp(res->select, "select"))
12010                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12011         else if (!strcmp(res->select, "add"))
12012                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12013         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12014                                 RTE_ETH_FILTER_SET, &info);
12015 }
12016
12017 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12018         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12019                 set_hash_input_set, "set_hash_input_set");
12020 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12021         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12022                 port_id, UINT16);
12023 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12024         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12025                 flow_type, NULL);
12026 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12027         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12028                 inset_field,
12029                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12030                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12031                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12032                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12033                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12034                 "fld-8th#none");
12035 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12036         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12037                 select, "select#add");
12038
12039 cmdline_parse_inst_t cmd_set_hash_input_set = {
12040         .f = cmd_set_hash_input_set_parsed,
12041         .data = NULL,
12042         .help_str = "set_hash_input_set <port_id> "
12043         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12044         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12045         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12046         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12047         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12048         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12049         "fld-7th|fld-8th|none select|add",
12050         .tokens = {
12051                 (void *)&cmd_set_hash_input_set_cmd,
12052                 (void *)&cmd_set_hash_input_set_port_id,
12053                 (void *)&cmd_set_hash_input_set_flow_type,
12054                 (void *)&cmd_set_hash_input_set_field,
12055                 (void *)&cmd_set_hash_input_set_select,
12056                 NULL,
12057         },
12058 };
12059
12060 /* Set flow director input set */
12061 struct cmd_set_fdir_input_set_result {
12062         cmdline_fixed_string_t set_fdir_input_set;
12063         portid_t port_id;
12064         cmdline_fixed_string_t flow_type;
12065         cmdline_fixed_string_t inset_field;
12066         cmdline_fixed_string_t select;
12067 };
12068
12069 static void
12070 cmd_set_fdir_input_set_parsed(void *parsed_result,
12071         __rte_unused struct cmdline *cl,
12072         __rte_unused void *data)
12073 {
12074         struct cmd_set_fdir_input_set_result *res = parsed_result;
12075         struct rte_eth_fdir_filter_info info;
12076
12077         memset(&info, 0, sizeof(info));
12078         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12079         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12080         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12081         info.info.input_set_conf.inset_size = 1;
12082         if (!strcmp(res->select, "select"))
12083                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12084         else if (!strcmp(res->select, "add"))
12085                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12086         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12087                 RTE_ETH_FILTER_SET, &info);
12088 }
12089
12090 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12091         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12092         set_fdir_input_set, "set_fdir_input_set");
12093 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12094         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12095         port_id, UINT16);
12096 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12097         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12098         flow_type,
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 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12102         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12103         inset_field,
12104         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12105         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12106         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12107         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12108         "sctp-veri-tag#none");
12109 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12110         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12111         select, "select#add");
12112
12113 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12114         .f = cmd_set_fdir_input_set_parsed,
12115         .data = NULL,
12116         .help_str = "set_fdir_input_set <port_id> "
12117         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12118         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12119         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12120         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12121         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12122         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12123         "sctp-veri-tag|none select|add",
12124         .tokens = {
12125                 (void *)&cmd_set_fdir_input_set_cmd,
12126                 (void *)&cmd_set_fdir_input_set_port_id,
12127                 (void *)&cmd_set_fdir_input_set_flow_type,
12128                 (void *)&cmd_set_fdir_input_set_field,
12129                 (void *)&cmd_set_fdir_input_set_select,
12130                 NULL,
12131         },
12132 };
12133
12134 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12135 struct cmd_mcast_addr_result {
12136         cmdline_fixed_string_t mcast_addr_cmd;
12137         cmdline_fixed_string_t what;
12138         uint16_t port_num;
12139         struct ether_addr mc_addr;
12140 };
12141
12142 static void cmd_mcast_addr_parsed(void *parsed_result,
12143                 __attribute__((unused)) struct cmdline *cl,
12144                 __attribute__((unused)) void *data)
12145 {
12146         struct cmd_mcast_addr_result *res = parsed_result;
12147
12148         if (!is_multicast_ether_addr(&res->mc_addr)) {
12149                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12150                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12151                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12152                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12153                 return;
12154         }
12155         if (strcmp(res->what, "add") == 0)
12156                 mcast_addr_add(res->port_num, &res->mc_addr);
12157         else
12158                 mcast_addr_remove(res->port_num, &res->mc_addr);
12159 }
12160
12161 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12162         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12163                                  mcast_addr_cmd, "mcast_addr");
12164 cmdline_parse_token_string_t cmd_mcast_addr_what =
12165         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12166                                  "add#remove");
12167 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12168         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12169 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12170         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12171
12172 cmdline_parse_inst_t cmd_mcast_addr = {
12173         .f = cmd_mcast_addr_parsed,
12174         .data = (void *)0,
12175         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12176                 "Add/Remove multicast MAC address on port_id",
12177         .tokens = {
12178                 (void *)&cmd_mcast_addr_cmd,
12179                 (void *)&cmd_mcast_addr_what,
12180                 (void *)&cmd_mcast_addr_portnum,
12181                 (void *)&cmd_mcast_addr_addr,
12182                 NULL,
12183         },
12184 };
12185
12186 /* l2 tunnel config
12187  * only support E-tag now.
12188  */
12189
12190 /* Ether type config */
12191 struct cmd_config_l2_tunnel_eth_type_result {
12192         cmdline_fixed_string_t port;
12193         cmdline_fixed_string_t config;
12194         cmdline_fixed_string_t all;
12195         portid_t id;
12196         cmdline_fixed_string_t l2_tunnel;
12197         cmdline_fixed_string_t l2_tunnel_type;
12198         cmdline_fixed_string_t eth_type;
12199         uint16_t eth_type_val;
12200 };
12201
12202 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12203         TOKEN_STRING_INITIALIZER
12204                 (struct cmd_config_l2_tunnel_eth_type_result,
12205                  port, "port");
12206 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12207         TOKEN_STRING_INITIALIZER
12208                 (struct cmd_config_l2_tunnel_eth_type_result,
12209                  config, "config");
12210 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12211         TOKEN_STRING_INITIALIZER
12212                 (struct cmd_config_l2_tunnel_eth_type_result,
12213                  all, "all");
12214 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12215         TOKEN_NUM_INITIALIZER
12216                 (struct cmd_config_l2_tunnel_eth_type_result,
12217                  id, UINT16);
12218 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12219         TOKEN_STRING_INITIALIZER
12220                 (struct cmd_config_l2_tunnel_eth_type_result,
12221                  l2_tunnel, "l2-tunnel");
12222 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12223         TOKEN_STRING_INITIALIZER
12224                 (struct cmd_config_l2_tunnel_eth_type_result,
12225                  l2_tunnel_type, "E-tag");
12226 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12227         TOKEN_STRING_INITIALIZER
12228                 (struct cmd_config_l2_tunnel_eth_type_result,
12229                  eth_type, "ether-type");
12230 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12231         TOKEN_NUM_INITIALIZER
12232                 (struct cmd_config_l2_tunnel_eth_type_result,
12233                  eth_type_val, UINT16);
12234
12235 static enum rte_eth_tunnel_type
12236 str2fdir_l2_tunnel_type(char *string)
12237 {
12238         uint32_t i = 0;
12239
12240         static const struct {
12241                 char str[32];
12242                 enum rte_eth_tunnel_type type;
12243         } l2_tunnel_type_str[] = {
12244                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12245         };
12246
12247         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12248                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12249                         return l2_tunnel_type_str[i].type;
12250         }
12251         return RTE_TUNNEL_TYPE_NONE;
12252 }
12253
12254 /* ether type config for all ports */
12255 static void
12256 cmd_config_l2_tunnel_eth_type_all_parsed
12257         (void *parsed_result,
12258          __attribute__((unused)) struct cmdline *cl,
12259          __attribute__((unused)) void *data)
12260 {
12261         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12262         struct rte_eth_l2_tunnel_conf entry;
12263         portid_t pid;
12264
12265         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12266         entry.ether_type = res->eth_type_val;
12267
12268         RTE_ETH_FOREACH_DEV(pid) {
12269                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12270         }
12271 }
12272
12273 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12274         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12275         .data = NULL,
12276         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12277         .tokens = {
12278                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12279                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12280                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12281                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12282                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12283                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12284                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12285                 NULL,
12286         },
12287 };
12288
12289 /* ether type config for a specific port */
12290 static void
12291 cmd_config_l2_tunnel_eth_type_specific_parsed(
12292         void *parsed_result,
12293         __attribute__((unused)) struct cmdline *cl,
12294         __attribute__((unused)) void *data)
12295 {
12296         struct cmd_config_l2_tunnel_eth_type_result *res =
12297                  parsed_result;
12298         struct rte_eth_l2_tunnel_conf entry;
12299
12300         if (port_id_is_invalid(res->id, ENABLED_WARN))
12301                 return;
12302
12303         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12304         entry.ether_type = res->eth_type_val;
12305
12306         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12307 }
12308
12309 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12310         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12311         .data = NULL,
12312         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12313         .tokens = {
12314                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12315                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12316                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12317                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12318                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12319                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12320                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12321                 NULL,
12322         },
12323 };
12324
12325 /* Enable/disable l2 tunnel */
12326 struct cmd_config_l2_tunnel_en_dis_result {
12327         cmdline_fixed_string_t port;
12328         cmdline_fixed_string_t config;
12329         cmdline_fixed_string_t all;
12330         portid_t id;
12331         cmdline_fixed_string_t l2_tunnel;
12332         cmdline_fixed_string_t l2_tunnel_type;
12333         cmdline_fixed_string_t en_dis;
12334 };
12335
12336 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12337         TOKEN_STRING_INITIALIZER
12338                 (struct cmd_config_l2_tunnel_en_dis_result,
12339                  port, "port");
12340 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12341         TOKEN_STRING_INITIALIZER
12342                 (struct cmd_config_l2_tunnel_en_dis_result,
12343                  config, "config");
12344 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12345         TOKEN_STRING_INITIALIZER
12346                 (struct cmd_config_l2_tunnel_en_dis_result,
12347                  all, "all");
12348 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12349         TOKEN_NUM_INITIALIZER
12350                 (struct cmd_config_l2_tunnel_en_dis_result,
12351                  id, UINT16);
12352 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12353         TOKEN_STRING_INITIALIZER
12354                 (struct cmd_config_l2_tunnel_en_dis_result,
12355                  l2_tunnel, "l2-tunnel");
12356 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12357         TOKEN_STRING_INITIALIZER
12358                 (struct cmd_config_l2_tunnel_en_dis_result,
12359                  l2_tunnel_type, "E-tag");
12360 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12361         TOKEN_STRING_INITIALIZER
12362                 (struct cmd_config_l2_tunnel_en_dis_result,
12363                  en_dis, "enable#disable");
12364
12365 /* enable/disable l2 tunnel for all ports */
12366 static void
12367 cmd_config_l2_tunnel_en_dis_all_parsed(
12368         void *parsed_result,
12369         __attribute__((unused)) struct cmdline *cl,
12370         __attribute__((unused)) void *data)
12371 {
12372         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12373         struct rte_eth_l2_tunnel_conf entry;
12374         portid_t pid;
12375         uint8_t en;
12376
12377         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12378
12379         if (!strcmp("enable", res->en_dis))
12380                 en = 1;
12381         else
12382                 en = 0;
12383
12384         RTE_ETH_FOREACH_DEV(pid) {
12385                 rte_eth_dev_l2_tunnel_offload_set(pid,
12386                                                   &entry,
12387                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12388                                                   en);
12389         }
12390 }
12391
12392 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12393         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12394         .data = NULL,
12395         .help_str = "port config all l2-tunnel E-tag enable|disable",
12396         .tokens = {
12397                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12398                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12399                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12400                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12401                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12402                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12403                 NULL,
12404         },
12405 };
12406
12407 /* enable/disable l2 tunnel for a port */
12408 static void
12409 cmd_config_l2_tunnel_en_dis_specific_parsed(
12410         void *parsed_result,
12411         __attribute__((unused)) struct cmdline *cl,
12412         __attribute__((unused)) void *data)
12413 {
12414         struct cmd_config_l2_tunnel_en_dis_result *res =
12415                 parsed_result;
12416         struct rte_eth_l2_tunnel_conf entry;
12417
12418         if (port_id_is_invalid(res->id, ENABLED_WARN))
12419                 return;
12420
12421         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12422
12423         if (!strcmp("enable", res->en_dis))
12424                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12425                                                   &entry,
12426                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12427                                                   1);
12428         else
12429                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12430                                                   &entry,
12431                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12432                                                   0);
12433 }
12434
12435 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12436         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12437         .data = NULL,
12438         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12439         .tokens = {
12440                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12441                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12442                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12443                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12444                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12445                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12446                 NULL,
12447         },
12448 };
12449
12450 /* E-tag configuration */
12451
12452 /* Common result structure for all E-tag configuration */
12453 struct cmd_config_e_tag_result {
12454         cmdline_fixed_string_t e_tag;
12455         cmdline_fixed_string_t set;
12456         cmdline_fixed_string_t insertion;
12457         cmdline_fixed_string_t stripping;
12458         cmdline_fixed_string_t forwarding;
12459         cmdline_fixed_string_t filter;
12460         cmdline_fixed_string_t add;
12461         cmdline_fixed_string_t del;
12462         cmdline_fixed_string_t on;
12463         cmdline_fixed_string_t off;
12464         cmdline_fixed_string_t on_off;
12465         cmdline_fixed_string_t port_tag_id;
12466         uint32_t port_tag_id_val;
12467         cmdline_fixed_string_t e_tag_id;
12468         uint16_t e_tag_id_val;
12469         cmdline_fixed_string_t dst_pool;
12470         uint8_t dst_pool_val;
12471         cmdline_fixed_string_t port;
12472         portid_t port_id;
12473         cmdline_fixed_string_t vf;
12474         uint8_t vf_id;
12475 };
12476
12477 /* Common CLI fields for all E-tag configuration */
12478 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12479         TOKEN_STRING_INITIALIZER
12480                 (struct cmd_config_e_tag_result,
12481                  e_tag, "E-tag");
12482 cmdline_parse_token_string_t cmd_config_e_tag_set =
12483         TOKEN_STRING_INITIALIZER
12484                 (struct cmd_config_e_tag_result,
12485                  set, "set");
12486 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12487         TOKEN_STRING_INITIALIZER
12488                 (struct cmd_config_e_tag_result,
12489                  insertion, "insertion");
12490 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12491         TOKEN_STRING_INITIALIZER
12492                 (struct cmd_config_e_tag_result,
12493                  stripping, "stripping");
12494 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12495         TOKEN_STRING_INITIALIZER
12496                 (struct cmd_config_e_tag_result,
12497                  forwarding, "forwarding");
12498 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12499         TOKEN_STRING_INITIALIZER
12500                 (struct cmd_config_e_tag_result,
12501                  filter, "filter");
12502 cmdline_parse_token_string_t cmd_config_e_tag_add =
12503         TOKEN_STRING_INITIALIZER
12504                 (struct cmd_config_e_tag_result,
12505                  add, "add");
12506 cmdline_parse_token_string_t cmd_config_e_tag_del =
12507         TOKEN_STRING_INITIALIZER
12508                 (struct cmd_config_e_tag_result,
12509                  del, "del");
12510 cmdline_parse_token_string_t cmd_config_e_tag_on =
12511         TOKEN_STRING_INITIALIZER
12512                 (struct cmd_config_e_tag_result,
12513                  on, "on");
12514 cmdline_parse_token_string_t cmd_config_e_tag_off =
12515         TOKEN_STRING_INITIALIZER
12516                 (struct cmd_config_e_tag_result,
12517                  off, "off");
12518 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12519         TOKEN_STRING_INITIALIZER
12520                 (struct cmd_config_e_tag_result,
12521                  on_off, "on#off");
12522 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12523         TOKEN_STRING_INITIALIZER
12524                 (struct cmd_config_e_tag_result,
12525                  port_tag_id, "port-tag-id");
12526 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12527         TOKEN_NUM_INITIALIZER
12528                 (struct cmd_config_e_tag_result,
12529                  port_tag_id_val, UINT32);
12530 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12531         TOKEN_STRING_INITIALIZER
12532                 (struct cmd_config_e_tag_result,
12533                  e_tag_id, "e-tag-id");
12534 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12535         TOKEN_NUM_INITIALIZER
12536                 (struct cmd_config_e_tag_result,
12537                  e_tag_id_val, UINT16);
12538 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12539         TOKEN_STRING_INITIALIZER
12540                 (struct cmd_config_e_tag_result,
12541                  dst_pool, "dst-pool");
12542 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12543         TOKEN_NUM_INITIALIZER
12544                 (struct cmd_config_e_tag_result,
12545                  dst_pool_val, UINT8);
12546 cmdline_parse_token_string_t cmd_config_e_tag_port =
12547         TOKEN_STRING_INITIALIZER
12548                 (struct cmd_config_e_tag_result,
12549                  port, "port");
12550 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12551         TOKEN_NUM_INITIALIZER
12552                 (struct cmd_config_e_tag_result,
12553                  port_id, UINT16);
12554 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12555         TOKEN_STRING_INITIALIZER
12556                 (struct cmd_config_e_tag_result,
12557                  vf, "vf");
12558 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12559         TOKEN_NUM_INITIALIZER
12560                 (struct cmd_config_e_tag_result,
12561                  vf_id, UINT8);
12562
12563 /* E-tag insertion configuration */
12564 static void
12565 cmd_config_e_tag_insertion_en_parsed(
12566         void *parsed_result,
12567         __attribute__((unused)) struct cmdline *cl,
12568         __attribute__((unused)) void *data)
12569 {
12570         struct cmd_config_e_tag_result *res =
12571                 parsed_result;
12572         struct rte_eth_l2_tunnel_conf entry;
12573
12574         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12575                 return;
12576
12577         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12578         entry.tunnel_id = res->port_tag_id_val;
12579         entry.vf_id = res->vf_id;
12580         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12581                                           &entry,
12582                                           ETH_L2_TUNNEL_INSERTION_MASK,
12583                                           1);
12584 }
12585
12586 static void
12587 cmd_config_e_tag_insertion_dis_parsed(
12588         void *parsed_result,
12589         __attribute__((unused)) struct cmdline *cl,
12590         __attribute__((unused)) void *data)
12591 {
12592         struct cmd_config_e_tag_result *res =
12593                 parsed_result;
12594         struct rte_eth_l2_tunnel_conf entry;
12595
12596         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12597                 return;
12598
12599         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12600         entry.vf_id = res->vf_id;
12601
12602         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12603                                           &entry,
12604                                           ETH_L2_TUNNEL_INSERTION_MASK,
12605                                           0);
12606 }
12607
12608 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12609         .f = cmd_config_e_tag_insertion_en_parsed,
12610         .data = NULL,
12611         .help_str = "E-tag ... : E-tag insertion enable",
12612         .tokens = {
12613                 (void *)&cmd_config_e_tag_e_tag,
12614                 (void *)&cmd_config_e_tag_set,
12615                 (void *)&cmd_config_e_tag_insertion,
12616                 (void *)&cmd_config_e_tag_on,
12617                 (void *)&cmd_config_e_tag_port_tag_id,
12618                 (void *)&cmd_config_e_tag_port_tag_id_val,
12619                 (void *)&cmd_config_e_tag_port,
12620                 (void *)&cmd_config_e_tag_port_id,
12621                 (void *)&cmd_config_e_tag_vf,
12622                 (void *)&cmd_config_e_tag_vf_id,
12623                 NULL,
12624         },
12625 };
12626
12627 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12628         .f = cmd_config_e_tag_insertion_dis_parsed,
12629         .data = NULL,
12630         .help_str = "E-tag ... : E-tag insertion disable",
12631         .tokens = {
12632                 (void *)&cmd_config_e_tag_e_tag,
12633                 (void *)&cmd_config_e_tag_set,
12634                 (void *)&cmd_config_e_tag_insertion,
12635                 (void *)&cmd_config_e_tag_off,
12636                 (void *)&cmd_config_e_tag_port,
12637                 (void *)&cmd_config_e_tag_port_id,
12638                 (void *)&cmd_config_e_tag_vf,
12639                 (void *)&cmd_config_e_tag_vf_id,
12640                 NULL,
12641         },
12642 };
12643
12644 /* E-tag stripping configuration */
12645 static void
12646 cmd_config_e_tag_stripping_parsed(
12647         void *parsed_result,
12648         __attribute__((unused)) struct cmdline *cl,
12649         __attribute__((unused)) void *data)
12650 {
12651         struct cmd_config_e_tag_result *res =
12652                 parsed_result;
12653         struct rte_eth_l2_tunnel_conf entry;
12654
12655         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12656                 return;
12657
12658         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12659
12660         if (!strcmp(res->on_off, "on"))
12661                 rte_eth_dev_l2_tunnel_offload_set
12662                         (res->port_id,
12663                          &entry,
12664                          ETH_L2_TUNNEL_STRIPPING_MASK,
12665                          1);
12666         else
12667                 rte_eth_dev_l2_tunnel_offload_set
12668                         (res->port_id,
12669                          &entry,
12670                          ETH_L2_TUNNEL_STRIPPING_MASK,
12671                          0);
12672 }
12673
12674 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12675         .f = cmd_config_e_tag_stripping_parsed,
12676         .data = NULL,
12677         .help_str = "E-tag ... : E-tag stripping enable/disable",
12678         .tokens = {
12679                 (void *)&cmd_config_e_tag_e_tag,
12680                 (void *)&cmd_config_e_tag_set,
12681                 (void *)&cmd_config_e_tag_stripping,
12682                 (void *)&cmd_config_e_tag_on_off,
12683                 (void *)&cmd_config_e_tag_port,
12684                 (void *)&cmd_config_e_tag_port_id,
12685                 NULL,
12686         },
12687 };
12688
12689 /* E-tag forwarding configuration */
12690 static void
12691 cmd_config_e_tag_forwarding_parsed(
12692         void *parsed_result,
12693         __attribute__((unused)) struct cmdline *cl,
12694         __attribute__((unused)) void *data)
12695 {
12696         struct cmd_config_e_tag_result *res = parsed_result;
12697         struct rte_eth_l2_tunnel_conf entry;
12698
12699         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12700                 return;
12701
12702         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12703
12704         if (!strcmp(res->on_off, "on"))
12705                 rte_eth_dev_l2_tunnel_offload_set
12706                         (res->port_id,
12707                          &entry,
12708                          ETH_L2_TUNNEL_FORWARDING_MASK,
12709                          1);
12710         else
12711                 rte_eth_dev_l2_tunnel_offload_set
12712                         (res->port_id,
12713                          &entry,
12714                          ETH_L2_TUNNEL_FORWARDING_MASK,
12715                          0);
12716 }
12717
12718 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12719         .f = cmd_config_e_tag_forwarding_parsed,
12720         .data = NULL,
12721         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12722         .tokens = {
12723                 (void *)&cmd_config_e_tag_e_tag,
12724                 (void *)&cmd_config_e_tag_set,
12725                 (void *)&cmd_config_e_tag_forwarding,
12726                 (void *)&cmd_config_e_tag_on_off,
12727                 (void *)&cmd_config_e_tag_port,
12728                 (void *)&cmd_config_e_tag_port_id,
12729                 NULL,
12730         },
12731 };
12732
12733 /* E-tag filter configuration */
12734 static void
12735 cmd_config_e_tag_filter_add_parsed(
12736         void *parsed_result,
12737         __attribute__((unused)) struct cmdline *cl,
12738         __attribute__((unused)) void *data)
12739 {
12740         struct cmd_config_e_tag_result *res = parsed_result;
12741         struct rte_eth_l2_tunnel_conf entry;
12742         int ret = 0;
12743
12744         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12745                 return;
12746
12747         if (res->e_tag_id_val > 0x3fff) {
12748                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12749                 return;
12750         }
12751
12752         ret = rte_eth_dev_filter_supported(res->port_id,
12753                                            RTE_ETH_FILTER_L2_TUNNEL);
12754         if (ret < 0) {
12755                 printf("E-tag filter is not supported on port %u.\n",
12756                        res->port_id);
12757                 return;
12758         }
12759
12760         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12761         entry.tunnel_id = res->e_tag_id_val;
12762         entry.pool = res->dst_pool_val;
12763
12764         ret = rte_eth_dev_filter_ctrl(res->port_id,
12765                                       RTE_ETH_FILTER_L2_TUNNEL,
12766                                       RTE_ETH_FILTER_ADD,
12767                                       &entry);
12768         if (ret < 0)
12769                 printf("E-tag filter programming error: (%s)\n",
12770                        strerror(-ret));
12771 }
12772
12773 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12774         .f = cmd_config_e_tag_filter_add_parsed,
12775         .data = NULL,
12776         .help_str = "E-tag ... : E-tag filter add",
12777         .tokens = {
12778                 (void *)&cmd_config_e_tag_e_tag,
12779                 (void *)&cmd_config_e_tag_set,
12780                 (void *)&cmd_config_e_tag_filter,
12781                 (void *)&cmd_config_e_tag_add,
12782                 (void *)&cmd_config_e_tag_e_tag_id,
12783                 (void *)&cmd_config_e_tag_e_tag_id_val,
12784                 (void *)&cmd_config_e_tag_dst_pool,
12785                 (void *)&cmd_config_e_tag_dst_pool_val,
12786                 (void *)&cmd_config_e_tag_port,
12787                 (void *)&cmd_config_e_tag_port_id,
12788                 NULL,
12789         },
12790 };
12791
12792 static void
12793 cmd_config_e_tag_filter_del_parsed(
12794         void *parsed_result,
12795         __attribute__((unused)) struct cmdline *cl,
12796         __attribute__((unused)) void *data)
12797 {
12798         struct cmd_config_e_tag_result *res = parsed_result;
12799         struct rte_eth_l2_tunnel_conf entry;
12800         int ret = 0;
12801
12802         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12803                 return;
12804
12805         if (res->e_tag_id_val > 0x3fff) {
12806                 printf("e-tag-id must be less than 0x3fff.\n");
12807                 return;
12808         }
12809
12810         ret = rte_eth_dev_filter_supported(res->port_id,
12811                                            RTE_ETH_FILTER_L2_TUNNEL);
12812         if (ret < 0) {
12813                 printf("E-tag filter is not supported on port %u.\n",
12814                        res->port_id);
12815                 return;
12816         }
12817
12818         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12819         entry.tunnel_id = res->e_tag_id_val;
12820
12821         ret = rte_eth_dev_filter_ctrl(res->port_id,
12822                                       RTE_ETH_FILTER_L2_TUNNEL,
12823                                       RTE_ETH_FILTER_DELETE,
12824                                       &entry);
12825         if (ret < 0)
12826                 printf("E-tag filter programming error: (%s)\n",
12827                        strerror(-ret));
12828 }
12829
12830 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12831         .f = cmd_config_e_tag_filter_del_parsed,
12832         .data = NULL,
12833         .help_str = "E-tag ... : E-tag filter delete",
12834         .tokens = {
12835                 (void *)&cmd_config_e_tag_e_tag,
12836                 (void *)&cmd_config_e_tag_set,
12837                 (void *)&cmd_config_e_tag_filter,
12838                 (void *)&cmd_config_e_tag_del,
12839                 (void *)&cmd_config_e_tag_e_tag_id,
12840                 (void *)&cmd_config_e_tag_e_tag_id_val,
12841                 (void *)&cmd_config_e_tag_port,
12842                 (void *)&cmd_config_e_tag_port_id,
12843                 NULL,
12844         },
12845 };
12846
12847 /* vf vlan anti spoof configuration */
12848
12849 /* Common result structure for vf vlan anti spoof */
12850 struct cmd_vf_vlan_anti_spoof_result {
12851         cmdline_fixed_string_t set;
12852         cmdline_fixed_string_t vf;
12853         cmdline_fixed_string_t vlan;
12854         cmdline_fixed_string_t antispoof;
12855         portid_t port_id;
12856         uint32_t vf_id;
12857         cmdline_fixed_string_t on_off;
12858 };
12859
12860 /* Common CLI fields for vf vlan anti spoof enable disable */
12861 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12862         TOKEN_STRING_INITIALIZER
12863                 (struct cmd_vf_vlan_anti_spoof_result,
12864                  set, "set");
12865 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12866         TOKEN_STRING_INITIALIZER
12867                 (struct cmd_vf_vlan_anti_spoof_result,
12868                  vf, "vf");
12869 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12870         TOKEN_STRING_INITIALIZER
12871                 (struct cmd_vf_vlan_anti_spoof_result,
12872                  vlan, "vlan");
12873 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12874         TOKEN_STRING_INITIALIZER
12875                 (struct cmd_vf_vlan_anti_spoof_result,
12876                  antispoof, "antispoof");
12877 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12878         TOKEN_NUM_INITIALIZER
12879                 (struct cmd_vf_vlan_anti_spoof_result,
12880                  port_id, UINT16);
12881 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12882         TOKEN_NUM_INITIALIZER
12883                 (struct cmd_vf_vlan_anti_spoof_result,
12884                  vf_id, UINT32);
12885 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12886         TOKEN_STRING_INITIALIZER
12887                 (struct cmd_vf_vlan_anti_spoof_result,
12888                  on_off, "on#off");
12889
12890 static void
12891 cmd_set_vf_vlan_anti_spoof_parsed(
12892         void *parsed_result,
12893         __attribute__((unused)) struct cmdline *cl,
12894         __attribute__((unused)) void *data)
12895 {
12896         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12897         int ret = -ENOTSUP;
12898
12899         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12900
12901         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12902                 return;
12903
12904 #ifdef RTE_LIBRTE_IXGBE_PMD
12905         if (ret == -ENOTSUP)
12906                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12907                                 res->vf_id, is_on);
12908 #endif
12909 #ifdef RTE_LIBRTE_I40E_PMD
12910         if (ret == -ENOTSUP)
12911                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12912                                 res->vf_id, is_on);
12913 #endif
12914 #ifdef RTE_LIBRTE_BNXT_PMD
12915         if (ret == -ENOTSUP)
12916                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12917                                 res->vf_id, is_on);
12918 #endif
12919
12920         switch (ret) {
12921         case 0:
12922                 break;
12923         case -EINVAL:
12924                 printf("invalid vf_id %d\n", res->vf_id);
12925                 break;
12926         case -ENODEV:
12927                 printf("invalid port_id %d\n", res->port_id);
12928                 break;
12929         case -ENOTSUP:
12930                 printf("function not implemented\n");
12931                 break;
12932         default:
12933                 printf("programming error: (%s)\n", strerror(-ret));
12934         }
12935 }
12936
12937 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12938         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12939         .data = NULL,
12940         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12941         .tokens = {
12942                 (void *)&cmd_vf_vlan_anti_spoof_set,
12943                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12944                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12945                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12946                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12947                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12948                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12949                 NULL,
12950         },
12951 };
12952
12953 /* vf mac anti spoof configuration */
12954
12955 /* Common result structure for vf mac anti spoof */
12956 struct cmd_vf_mac_anti_spoof_result {
12957         cmdline_fixed_string_t set;
12958         cmdline_fixed_string_t vf;
12959         cmdline_fixed_string_t mac;
12960         cmdline_fixed_string_t antispoof;
12961         portid_t port_id;
12962         uint32_t vf_id;
12963         cmdline_fixed_string_t on_off;
12964 };
12965
12966 /* Common CLI fields for vf mac anti spoof enable disable */
12967 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12968         TOKEN_STRING_INITIALIZER
12969                 (struct cmd_vf_mac_anti_spoof_result,
12970                  set, "set");
12971 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12972         TOKEN_STRING_INITIALIZER
12973                 (struct cmd_vf_mac_anti_spoof_result,
12974                  vf, "vf");
12975 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12976         TOKEN_STRING_INITIALIZER
12977                 (struct cmd_vf_mac_anti_spoof_result,
12978                  mac, "mac");
12979 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12980         TOKEN_STRING_INITIALIZER
12981                 (struct cmd_vf_mac_anti_spoof_result,
12982                  antispoof, "antispoof");
12983 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12984         TOKEN_NUM_INITIALIZER
12985                 (struct cmd_vf_mac_anti_spoof_result,
12986                  port_id, UINT16);
12987 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12988         TOKEN_NUM_INITIALIZER
12989                 (struct cmd_vf_mac_anti_spoof_result,
12990                  vf_id, UINT32);
12991 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12992         TOKEN_STRING_INITIALIZER
12993                 (struct cmd_vf_mac_anti_spoof_result,
12994                  on_off, "on#off");
12995
12996 static void
12997 cmd_set_vf_mac_anti_spoof_parsed(
12998         void *parsed_result,
12999         __attribute__((unused)) struct cmdline *cl,
13000         __attribute__((unused)) void *data)
13001 {
13002         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13003         int ret = -ENOTSUP;
13004
13005         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13006
13007         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13008                 return;
13009
13010 #ifdef RTE_LIBRTE_IXGBE_PMD
13011         if (ret == -ENOTSUP)
13012                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13013                         res->vf_id, is_on);
13014 #endif
13015 #ifdef RTE_LIBRTE_I40E_PMD
13016         if (ret == -ENOTSUP)
13017                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13018                         res->vf_id, is_on);
13019 #endif
13020 #ifdef RTE_LIBRTE_BNXT_PMD
13021         if (ret == -ENOTSUP)
13022                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13023                         res->vf_id, is_on);
13024 #endif
13025
13026         switch (ret) {
13027         case 0:
13028                 break;
13029         case -EINVAL:
13030                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13031                 break;
13032         case -ENODEV:
13033                 printf("invalid port_id %d\n", res->port_id);
13034                 break;
13035         case -ENOTSUP:
13036                 printf("function not implemented\n");
13037                 break;
13038         default:
13039                 printf("programming error: (%s)\n", strerror(-ret));
13040         }
13041 }
13042
13043 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13044         .f = cmd_set_vf_mac_anti_spoof_parsed,
13045         .data = NULL,
13046         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13047         .tokens = {
13048                 (void *)&cmd_vf_mac_anti_spoof_set,
13049                 (void *)&cmd_vf_mac_anti_spoof_vf,
13050                 (void *)&cmd_vf_mac_anti_spoof_mac,
13051                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13052                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13053                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13054                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13055                 NULL,
13056         },
13057 };
13058
13059 /* vf vlan strip queue configuration */
13060
13061 /* Common result structure for vf mac anti spoof */
13062 struct cmd_vf_vlan_stripq_result {
13063         cmdline_fixed_string_t set;
13064         cmdline_fixed_string_t vf;
13065         cmdline_fixed_string_t vlan;
13066         cmdline_fixed_string_t stripq;
13067         portid_t port_id;
13068         uint16_t vf_id;
13069         cmdline_fixed_string_t on_off;
13070 };
13071
13072 /* Common CLI fields for vf vlan strip enable disable */
13073 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13074         TOKEN_STRING_INITIALIZER
13075                 (struct cmd_vf_vlan_stripq_result,
13076                  set, "set");
13077 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13078         TOKEN_STRING_INITIALIZER
13079                 (struct cmd_vf_vlan_stripq_result,
13080                  vf, "vf");
13081 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13082         TOKEN_STRING_INITIALIZER
13083                 (struct cmd_vf_vlan_stripq_result,
13084                  vlan, "vlan");
13085 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13086         TOKEN_STRING_INITIALIZER
13087                 (struct cmd_vf_vlan_stripq_result,
13088                  stripq, "stripq");
13089 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13090         TOKEN_NUM_INITIALIZER
13091                 (struct cmd_vf_vlan_stripq_result,
13092                  port_id, UINT16);
13093 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13094         TOKEN_NUM_INITIALIZER
13095                 (struct cmd_vf_vlan_stripq_result,
13096                  vf_id, UINT16);
13097 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13098         TOKEN_STRING_INITIALIZER
13099                 (struct cmd_vf_vlan_stripq_result,
13100                  on_off, "on#off");
13101
13102 static void
13103 cmd_set_vf_vlan_stripq_parsed(
13104         void *parsed_result,
13105         __attribute__((unused)) struct cmdline *cl,
13106         __attribute__((unused)) void *data)
13107 {
13108         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13109         int ret = -ENOTSUP;
13110
13111         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13112
13113         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13114                 return;
13115
13116 #ifdef RTE_LIBRTE_IXGBE_PMD
13117         if (ret == -ENOTSUP)
13118                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13119                         res->vf_id, is_on);
13120 #endif
13121 #ifdef RTE_LIBRTE_I40E_PMD
13122         if (ret == -ENOTSUP)
13123                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13124                         res->vf_id, is_on);
13125 #endif
13126 #ifdef RTE_LIBRTE_BNXT_PMD
13127         if (ret == -ENOTSUP)
13128                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13129                         res->vf_id, is_on);
13130 #endif
13131
13132         switch (ret) {
13133         case 0:
13134                 break;
13135         case -EINVAL:
13136                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13137                 break;
13138         case -ENODEV:
13139                 printf("invalid port_id %d\n", res->port_id);
13140                 break;
13141         case -ENOTSUP:
13142                 printf("function not implemented\n");
13143                 break;
13144         default:
13145                 printf("programming error: (%s)\n", strerror(-ret));
13146         }
13147 }
13148
13149 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13150         .f = cmd_set_vf_vlan_stripq_parsed,
13151         .data = NULL,
13152         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13153         .tokens = {
13154                 (void *)&cmd_vf_vlan_stripq_set,
13155                 (void *)&cmd_vf_vlan_stripq_vf,
13156                 (void *)&cmd_vf_vlan_stripq_vlan,
13157                 (void *)&cmd_vf_vlan_stripq_stripq,
13158                 (void *)&cmd_vf_vlan_stripq_port_id,
13159                 (void *)&cmd_vf_vlan_stripq_vf_id,
13160                 (void *)&cmd_vf_vlan_stripq_on_off,
13161                 NULL,
13162         },
13163 };
13164
13165 /* vf vlan insert configuration */
13166
13167 /* Common result structure for vf vlan insert */
13168 struct cmd_vf_vlan_insert_result {
13169         cmdline_fixed_string_t set;
13170         cmdline_fixed_string_t vf;
13171         cmdline_fixed_string_t vlan;
13172         cmdline_fixed_string_t insert;
13173         portid_t port_id;
13174         uint16_t vf_id;
13175         uint16_t vlan_id;
13176 };
13177
13178 /* Common CLI fields for vf vlan insert enable disable */
13179 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13180         TOKEN_STRING_INITIALIZER
13181                 (struct cmd_vf_vlan_insert_result,
13182                  set, "set");
13183 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13184         TOKEN_STRING_INITIALIZER
13185                 (struct cmd_vf_vlan_insert_result,
13186                  vf, "vf");
13187 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13188         TOKEN_STRING_INITIALIZER
13189                 (struct cmd_vf_vlan_insert_result,
13190                  vlan, "vlan");
13191 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13192         TOKEN_STRING_INITIALIZER
13193                 (struct cmd_vf_vlan_insert_result,
13194                  insert, "insert");
13195 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13196         TOKEN_NUM_INITIALIZER
13197                 (struct cmd_vf_vlan_insert_result,
13198                  port_id, UINT16);
13199 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13200         TOKEN_NUM_INITIALIZER
13201                 (struct cmd_vf_vlan_insert_result,
13202                  vf_id, UINT16);
13203 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13204         TOKEN_NUM_INITIALIZER
13205                 (struct cmd_vf_vlan_insert_result,
13206                  vlan_id, UINT16);
13207
13208 static void
13209 cmd_set_vf_vlan_insert_parsed(
13210         void *parsed_result,
13211         __attribute__((unused)) struct cmdline *cl,
13212         __attribute__((unused)) void *data)
13213 {
13214         struct cmd_vf_vlan_insert_result *res = parsed_result;
13215         int ret = -ENOTSUP;
13216
13217         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13218                 return;
13219
13220 #ifdef RTE_LIBRTE_IXGBE_PMD
13221         if (ret == -ENOTSUP)
13222                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13223                         res->vlan_id);
13224 #endif
13225 #ifdef RTE_LIBRTE_I40E_PMD
13226         if (ret == -ENOTSUP)
13227                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13228                         res->vlan_id);
13229 #endif
13230 #ifdef RTE_LIBRTE_BNXT_PMD
13231         if (ret == -ENOTSUP)
13232                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13233                         res->vlan_id);
13234 #endif
13235
13236         switch (ret) {
13237         case 0:
13238                 break;
13239         case -EINVAL:
13240                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13241                 break;
13242         case -ENODEV:
13243                 printf("invalid port_id %d\n", res->port_id);
13244                 break;
13245         case -ENOTSUP:
13246                 printf("function not implemented\n");
13247                 break;
13248         default:
13249                 printf("programming error: (%s)\n", strerror(-ret));
13250         }
13251 }
13252
13253 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13254         .f = cmd_set_vf_vlan_insert_parsed,
13255         .data = NULL,
13256         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13257         .tokens = {
13258                 (void *)&cmd_vf_vlan_insert_set,
13259                 (void *)&cmd_vf_vlan_insert_vf,
13260                 (void *)&cmd_vf_vlan_insert_vlan,
13261                 (void *)&cmd_vf_vlan_insert_insert,
13262                 (void *)&cmd_vf_vlan_insert_port_id,
13263                 (void *)&cmd_vf_vlan_insert_vf_id,
13264                 (void *)&cmd_vf_vlan_insert_vlan_id,
13265                 NULL,
13266         },
13267 };
13268
13269 /* tx loopback configuration */
13270
13271 /* Common result structure for tx loopback */
13272 struct cmd_tx_loopback_result {
13273         cmdline_fixed_string_t set;
13274         cmdline_fixed_string_t tx;
13275         cmdline_fixed_string_t loopback;
13276         portid_t port_id;
13277         cmdline_fixed_string_t on_off;
13278 };
13279
13280 /* Common CLI fields for tx loopback enable disable */
13281 cmdline_parse_token_string_t cmd_tx_loopback_set =
13282         TOKEN_STRING_INITIALIZER
13283                 (struct cmd_tx_loopback_result,
13284                  set, "set");
13285 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13286         TOKEN_STRING_INITIALIZER
13287                 (struct cmd_tx_loopback_result,
13288                  tx, "tx");
13289 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13290         TOKEN_STRING_INITIALIZER
13291                 (struct cmd_tx_loopback_result,
13292                  loopback, "loopback");
13293 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13294         TOKEN_NUM_INITIALIZER
13295                 (struct cmd_tx_loopback_result,
13296                  port_id, UINT16);
13297 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13298         TOKEN_STRING_INITIALIZER
13299                 (struct cmd_tx_loopback_result,
13300                  on_off, "on#off");
13301
13302 static void
13303 cmd_set_tx_loopback_parsed(
13304         void *parsed_result,
13305         __attribute__((unused)) struct cmdline *cl,
13306         __attribute__((unused)) void *data)
13307 {
13308         struct cmd_tx_loopback_result *res = parsed_result;
13309         int ret = -ENOTSUP;
13310
13311         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13312
13313         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13314                 return;
13315
13316 #ifdef RTE_LIBRTE_IXGBE_PMD
13317         if (ret == -ENOTSUP)
13318                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13319 #endif
13320 #ifdef RTE_LIBRTE_I40E_PMD
13321         if (ret == -ENOTSUP)
13322                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13323 #endif
13324 #ifdef RTE_LIBRTE_BNXT_PMD
13325         if (ret == -ENOTSUP)
13326                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13327 #endif
13328 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13329         if (ret == -ENOTSUP)
13330                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13331 #endif
13332
13333         switch (ret) {
13334         case 0:
13335                 break;
13336         case -EINVAL:
13337                 printf("invalid is_on %d\n", is_on);
13338                 break;
13339         case -ENODEV:
13340                 printf("invalid port_id %d\n", res->port_id);
13341                 break;
13342         case -ENOTSUP:
13343                 printf("function not implemented\n");
13344                 break;
13345         default:
13346                 printf("programming error: (%s)\n", strerror(-ret));
13347         }
13348 }
13349
13350 cmdline_parse_inst_t cmd_set_tx_loopback = {
13351         .f = cmd_set_tx_loopback_parsed,
13352         .data = NULL,
13353         .help_str = "set tx loopback <port_id> on|off",
13354         .tokens = {
13355                 (void *)&cmd_tx_loopback_set,
13356                 (void *)&cmd_tx_loopback_tx,
13357                 (void *)&cmd_tx_loopback_loopback,
13358                 (void *)&cmd_tx_loopback_port_id,
13359                 (void *)&cmd_tx_loopback_on_off,
13360                 NULL,
13361         },
13362 };
13363
13364 /* all queues drop enable configuration */
13365
13366 /* Common result structure for all queues drop enable */
13367 struct cmd_all_queues_drop_en_result {
13368         cmdline_fixed_string_t set;
13369         cmdline_fixed_string_t all;
13370         cmdline_fixed_string_t queues;
13371         cmdline_fixed_string_t drop;
13372         portid_t port_id;
13373         cmdline_fixed_string_t on_off;
13374 };
13375
13376 /* Common CLI fields for tx loopback enable disable */
13377 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13378         TOKEN_STRING_INITIALIZER
13379                 (struct cmd_all_queues_drop_en_result,
13380                  set, "set");
13381 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13382         TOKEN_STRING_INITIALIZER
13383                 (struct cmd_all_queues_drop_en_result,
13384                  all, "all");
13385 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13386         TOKEN_STRING_INITIALIZER
13387                 (struct cmd_all_queues_drop_en_result,
13388                  queues, "queues");
13389 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13390         TOKEN_STRING_INITIALIZER
13391                 (struct cmd_all_queues_drop_en_result,
13392                  drop, "drop");
13393 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13394         TOKEN_NUM_INITIALIZER
13395                 (struct cmd_all_queues_drop_en_result,
13396                  port_id, UINT16);
13397 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13398         TOKEN_STRING_INITIALIZER
13399                 (struct cmd_all_queues_drop_en_result,
13400                  on_off, "on#off");
13401
13402 static void
13403 cmd_set_all_queues_drop_en_parsed(
13404         void *parsed_result,
13405         __attribute__((unused)) struct cmdline *cl,
13406         __attribute__((unused)) void *data)
13407 {
13408         struct cmd_all_queues_drop_en_result *res = parsed_result;
13409         int ret = -ENOTSUP;
13410         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13411
13412         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13413                 return;
13414
13415 #ifdef RTE_LIBRTE_IXGBE_PMD
13416         if (ret == -ENOTSUP)
13417                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13418 #endif
13419 #ifdef RTE_LIBRTE_BNXT_PMD
13420         if (ret == -ENOTSUP)
13421                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13422 #endif
13423         switch (ret) {
13424         case 0:
13425                 break;
13426         case -EINVAL:
13427                 printf("invalid is_on %d\n", is_on);
13428                 break;
13429         case -ENODEV:
13430                 printf("invalid port_id %d\n", res->port_id);
13431                 break;
13432         case -ENOTSUP:
13433                 printf("function not implemented\n");
13434                 break;
13435         default:
13436                 printf("programming error: (%s)\n", strerror(-ret));
13437         }
13438 }
13439
13440 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13441         .f = cmd_set_all_queues_drop_en_parsed,
13442         .data = NULL,
13443         .help_str = "set all queues drop <port_id> on|off",
13444         .tokens = {
13445                 (void *)&cmd_all_queues_drop_en_set,
13446                 (void *)&cmd_all_queues_drop_en_all,
13447                 (void *)&cmd_all_queues_drop_en_queues,
13448                 (void *)&cmd_all_queues_drop_en_drop,
13449                 (void *)&cmd_all_queues_drop_en_port_id,
13450                 (void *)&cmd_all_queues_drop_en_on_off,
13451                 NULL,
13452         },
13453 };
13454
13455 /* vf split drop enable configuration */
13456
13457 /* Common result structure for vf split drop enable */
13458 struct cmd_vf_split_drop_en_result {
13459         cmdline_fixed_string_t set;
13460         cmdline_fixed_string_t vf;
13461         cmdline_fixed_string_t split;
13462         cmdline_fixed_string_t drop;
13463         portid_t port_id;
13464         uint16_t vf_id;
13465         cmdline_fixed_string_t on_off;
13466 };
13467
13468 /* Common CLI fields for vf split drop enable disable */
13469 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13470         TOKEN_STRING_INITIALIZER
13471                 (struct cmd_vf_split_drop_en_result,
13472                  set, "set");
13473 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13474         TOKEN_STRING_INITIALIZER
13475                 (struct cmd_vf_split_drop_en_result,
13476                  vf, "vf");
13477 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13478         TOKEN_STRING_INITIALIZER
13479                 (struct cmd_vf_split_drop_en_result,
13480                  split, "split");
13481 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13482         TOKEN_STRING_INITIALIZER
13483                 (struct cmd_vf_split_drop_en_result,
13484                  drop, "drop");
13485 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13486         TOKEN_NUM_INITIALIZER
13487                 (struct cmd_vf_split_drop_en_result,
13488                  port_id, UINT16);
13489 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13490         TOKEN_NUM_INITIALIZER
13491                 (struct cmd_vf_split_drop_en_result,
13492                  vf_id, UINT16);
13493 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13494         TOKEN_STRING_INITIALIZER
13495                 (struct cmd_vf_split_drop_en_result,
13496                  on_off, "on#off");
13497
13498 static void
13499 cmd_set_vf_split_drop_en_parsed(
13500         void *parsed_result,
13501         __attribute__((unused)) struct cmdline *cl,
13502         __attribute__((unused)) void *data)
13503 {
13504         struct cmd_vf_split_drop_en_result *res = parsed_result;
13505         int ret = -ENOTSUP;
13506         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13507
13508         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13509                 return;
13510
13511 #ifdef RTE_LIBRTE_IXGBE_PMD
13512         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13513                         is_on);
13514 #endif
13515         switch (ret) {
13516         case 0:
13517                 break;
13518         case -EINVAL:
13519                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13520                 break;
13521         case -ENODEV:
13522                 printf("invalid port_id %d\n", res->port_id);
13523                 break;
13524         case -ENOTSUP:
13525                 printf("not supported on port %d\n", res->port_id);
13526                 break;
13527         default:
13528                 printf("programming error: (%s)\n", strerror(-ret));
13529         }
13530 }
13531
13532 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13533         .f = cmd_set_vf_split_drop_en_parsed,
13534         .data = NULL,
13535         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13536         .tokens = {
13537                 (void *)&cmd_vf_split_drop_en_set,
13538                 (void *)&cmd_vf_split_drop_en_vf,
13539                 (void *)&cmd_vf_split_drop_en_split,
13540                 (void *)&cmd_vf_split_drop_en_drop,
13541                 (void *)&cmd_vf_split_drop_en_port_id,
13542                 (void *)&cmd_vf_split_drop_en_vf_id,
13543                 (void *)&cmd_vf_split_drop_en_on_off,
13544                 NULL,
13545         },
13546 };
13547
13548 /* vf mac address configuration */
13549
13550 /* Common result structure for vf mac address */
13551 struct cmd_set_vf_mac_addr_result {
13552         cmdline_fixed_string_t set;
13553         cmdline_fixed_string_t vf;
13554         cmdline_fixed_string_t mac;
13555         cmdline_fixed_string_t addr;
13556         portid_t port_id;
13557         uint16_t vf_id;
13558         struct ether_addr mac_addr;
13559
13560 };
13561
13562 /* Common CLI fields for vf split drop enable disable */
13563 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13564         TOKEN_STRING_INITIALIZER
13565                 (struct cmd_set_vf_mac_addr_result,
13566                  set, "set");
13567 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13568         TOKEN_STRING_INITIALIZER
13569                 (struct cmd_set_vf_mac_addr_result,
13570                  vf, "vf");
13571 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13572         TOKEN_STRING_INITIALIZER
13573                 (struct cmd_set_vf_mac_addr_result,
13574                  mac, "mac");
13575 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13576         TOKEN_STRING_INITIALIZER
13577                 (struct cmd_set_vf_mac_addr_result,
13578                  addr, "addr");
13579 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13580         TOKEN_NUM_INITIALIZER
13581                 (struct cmd_set_vf_mac_addr_result,
13582                  port_id, UINT16);
13583 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13584         TOKEN_NUM_INITIALIZER
13585                 (struct cmd_set_vf_mac_addr_result,
13586                  vf_id, UINT16);
13587 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13588         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13589                  mac_addr);
13590
13591 static void
13592 cmd_set_vf_mac_addr_parsed(
13593         void *parsed_result,
13594         __attribute__((unused)) struct cmdline *cl,
13595         __attribute__((unused)) void *data)
13596 {
13597         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13598         int ret = -ENOTSUP;
13599
13600         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13601                 return;
13602
13603 #ifdef RTE_LIBRTE_IXGBE_PMD
13604         if (ret == -ENOTSUP)
13605                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13606                                 &res->mac_addr);
13607 #endif
13608 #ifdef RTE_LIBRTE_I40E_PMD
13609         if (ret == -ENOTSUP)
13610                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13611                                 &res->mac_addr);
13612 #endif
13613 #ifdef RTE_LIBRTE_BNXT_PMD
13614         if (ret == -ENOTSUP)
13615                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13616                                 &res->mac_addr);
13617 #endif
13618
13619         switch (ret) {
13620         case 0:
13621                 break;
13622         case -EINVAL:
13623                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13624                 break;
13625         case -ENODEV:
13626                 printf("invalid port_id %d\n", res->port_id);
13627                 break;
13628         case -ENOTSUP:
13629                 printf("function not implemented\n");
13630                 break;
13631         default:
13632                 printf("programming error: (%s)\n", strerror(-ret));
13633         }
13634 }
13635
13636 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13637         .f = cmd_set_vf_mac_addr_parsed,
13638         .data = NULL,
13639         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13640         .tokens = {
13641                 (void *)&cmd_set_vf_mac_addr_set,
13642                 (void *)&cmd_set_vf_mac_addr_vf,
13643                 (void *)&cmd_set_vf_mac_addr_mac,
13644                 (void *)&cmd_set_vf_mac_addr_addr,
13645                 (void *)&cmd_set_vf_mac_addr_port_id,
13646                 (void *)&cmd_set_vf_mac_addr_vf_id,
13647                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13648                 NULL,
13649         },
13650 };
13651
13652 /* MACsec configuration */
13653
13654 /* Common result structure for MACsec offload enable */
13655 struct cmd_macsec_offload_on_result {
13656         cmdline_fixed_string_t set;
13657         cmdline_fixed_string_t macsec;
13658         cmdline_fixed_string_t offload;
13659         portid_t port_id;
13660         cmdline_fixed_string_t on;
13661         cmdline_fixed_string_t encrypt;
13662         cmdline_fixed_string_t en_on_off;
13663         cmdline_fixed_string_t replay_protect;
13664         cmdline_fixed_string_t rp_on_off;
13665 };
13666
13667 /* Common CLI fields for MACsec offload disable */
13668 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13669         TOKEN_STRING_INITIALIZER
13670                 (struct cmd_macsec_offload_on_result,
13671                  set, "set");
13672 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13673         TOKEN_STRING_INITIALIZER
13674                 (struct cmd_macsec_offload_on_result,
13675                  macsec, "macsec");
13676 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13677         TOKEN_STRING_INITIALIZER
13678                 (struct cmd_macsec_offload_on_result,
13679                  offload, "offload");
13680 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13681         TOKEN_NUM_INITIALIZER
13682                 (struct cmd_macsec_offload_on_result,
13683                  port_id, UINT16);
13684 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13685         TOKEN_STRING_INITIALIZER
13686                 (struct cmd_macsec_offload_on_result,
13687                  on, "on");
13688 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13689         TOKEN_STRING_INITIALIZER
13690                 (struct cmd_macsec_offload_on_result,
13691                  encrypt, "encrypt");
13692 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13693         TOKEN_STRING_INITIALIZER
13694                 (struct cmd_macsec_offload_on_result,
13695                  en_on_off, "on#off");
13696 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13697         TOKEN_STRING_INITIALIZER
13698                 (struct cmd_macsec_offload_on_result,
13699                  replay_protect, "replay-protect");
13700 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13701         TOKEN_STRING_INITIALIZER
13702                 (struct cmd_macsec_offload_on_result,
13703                  rp_on_off, "on#off");
13704
13705 static void
13706 cmd_set_macsec_offload_on_parsed(
13707         void *parsed_result,
13708         __attribute__((unused)) struct cmdline *cl,
13709         __attribute__((unused)) void *data)
13710 {
13711         struct cmd_macsec_offload_on_result *res = parsed_result;
13712         int ret = -ENOTSUP;
13713         portid_t port_id = res->port_id;
13714         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13715         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13716         struct rte_eth_dev_info dev_info;
13717
13718         if (port_id_is_invalid(port_id, ENABLED_WARN))
13719                 return;
13720         if (!port_is_stopped(port_id)) {
13721                 printf("Please stop port %d first\n", port_id);
13722                 return;
13723         }
13724
13725         rte_eth_dev_info_get(port_id, &dev_info);
13726         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13727 #ifdef RTE_LIBRTE_IXGBE_PMD
13728                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13729 #endif
13730         }
13731         RTE_SET_USED(en);
13732         RTE_SET_USED(rp);
13733
13734         switch (ret) {
13735         case 0:
13736                 ports[port_id].dev_conf.txmode.offloads |=
13737                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13738                 cmd_reconfig_device_queue(port_id, 1, 1);
13739                 break;
13740         case -ENODEV:
13741                 printf("invalid port_id %d\n", port_id);
13742                 break;
13743         case -ENOTSUP:
13744                 printf("not supported on port %d\n", port_id);
13745                 break;
13746         default:
13747                 printf("programming error: (%s)\n", strerror(-ret));
13748         }
13749 }
13750
13751 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13752         .f = cmd_set_macsec_offload_on_parsed,
13753         .data = NULL,
13754         .help_str = "set macsec offload <port_id> on "
13755                 "encrypt on|off replay-protect on|off",
13756         .tokens = {
13757                 (void *)&cmd_macsec_offload_on_set,
13758                 (void *)&cmd_macsec_offload_on_macsec,
13759                 (void *)&cmd_macsec_offload_on_offload,
13760                 (void *)&cmd_macsec_offload_on_port_id,
13761                 (void *)&cmd_macsec_offload_on_on,
13762                 (void *)&cmd_macsec_offload_on_encrypt,
13763                 (void *)&cmd_macsec_offload_on_en_on_off,
13764                 (void *)&cmd_macsec_offload_on_replay_protect,
13765                 (void *)&cmd_macsec_offload_on_rp_on_off,
13766                 NULL,
13767         },
13768 };
13769
13770 /* Common result structure for MACsec offload disable */
13771 struct cmd_macsec_offload_off_result {
13772         cmdline_fixed_string_t set;
13773         cmdline_fixed_string_t macsec;
13774         cmdline_fixed_string_t offload;
13775         portid_t port_id;
13776         cmdline_fixed_string_t off;
13777 };
13778
13779 /* Common CLI fields for MACsec offload disable */
13780 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13781         TOKEN_STRING_INITIALIZER
13782                 (struct cmd_macsec_offload_off_result,
13783                  set, "set");
13784 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13785         TOKEN_STRING_INITIALIZER
13786                 (struct cmd_macsec_offload_off_result,
13787                  macsec, "macsec");
13788 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13789         TOKEN_STRING_INITIALIZER
13790                 (struct cmd_macsec_offload_off_result,
13791                  offload, "offload");
13792 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13793         TOKEN_NUM_INITIALIZER
13794                 (struct cmd_macsec_offload_off_result,
13795                  port_id, UINT16);
13796 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13797         TOKEN_STRING_INITIALIZER
13798                 (struct cmd_macsec_offload_off_result,
13799                  off, "off");
13800
13801 static void
13802 cmd_set_macsec_offload_off_parsed(
13803         void *parsed_result,
13804         __attribute__((unused)) struct cmdline *cl,
13805         __attribute__((unused)) void *data)
13806 {
13807         struct cmd_macsec_offload_off_result *res = parsed_result;
13808         int ret = -ENOTSUP;
13809         struct rte_eth_dev_info dev_info;
13810         portid_t port_id = res->port_id;
13811
13812         if (port_id_is_invalid(port_id, ENABLED_WARN))
13813                 return;
13814         if (!port_is_stopped(port_id)) {
13815                 printf("Please stop port %d first\n", port_id);
13816                 return;
13817         }
13818
13819         rte_eth_dev_info_get(port_id, &dev_info);
13820         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13821 #ifdef RTE_LIBRTE_IXGBE_PMD
13822                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13823 #endif
13824         }
13825         switch (ret) {
13826         case 0:
13827                 ports[port_id].dev_conf.txmode.offloads &=
13828                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13829                 cmd_reconfig_device_queue(port_id, 1, 1);
13830                 break;
13831         case -ENODEV:
13832                 printf("invalid port_id %d\n", port_id);
13833                 break;
13834         case -ENOTSUP:
13835                 printf("not supported on port %d\n", port_id);
13836                 break;
13837         default:
13838                 printf("programming error: (%s)\n", strerror(-ret));
13839         }
13840 }
13841
13842 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13843         .f = cmd_set_macsec_offload_off_parsed,
13844         .data = NULL,
13845         .help_str = "set macsec offload <port_id> off",
13846         .tokens = {
13847                 (void *)&cmd_macsec_offload_off_set,
13848                 (void *)&cmd_macsec_offload_off_macsec,
13849                 (void *)&cmd_macsec_offload_off_offload,
13850                 (void *)&cmd_macsec_offload_off_port_id,
13851                 (void *)&cmd_macsec_offload_off_off,
13852                 NULL,
13853         },
13854 };
13855
13856 /* Common result structure for MACsec secure connection configure */
13857 struct cmd_macsec_sc_result {
13858         cmdline_fixed_string_t set;
13859         cmdline_fixed_string_t macsec;
13860         cmdline_fixed_string_t sc;
13861         cmdline_fixed_string_t tx_rx;
13862         portid_t port_id;
13863         struct ether_addr mac;
13864         uint16_t pi;
13865 };
13866
13867 /* Common CLI fields for MACsec secure connection configure */
13868 cmdline_parse_token_string_t cmd_macsec_sc_set =
13869         TOKEN_STRING_INITIALIZER
13870                 (struct cmd_macsec_sc_result,
13871                  set, "set");
13872 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13873         TOKEN_STRING_INITIALIZER
13874                 (struct cmd_macsec_sc_result,
13875                  macsec, "macsec");
13876 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13877         TOKEN_STRING_INITIALIZER
13878                 (struct cmd_macsec_sc_result,
13879                  sc, "sc");
13880 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13881         TOKEN_STRING_INITIALIZER
13882                 (struct cmd_macsec_sc_result,
13883                  tx_rx, "tx#rx");
13884 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13885         TOKEN_NUM_INITIALIZER
13886                 (struct cmd_macsec_sc_result,
13887                  port_id, UINT16);
13888 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13889         TOKEN_ETHERADDR_INITIALIZER
13890                 (struct cmd_macsec_sc_result,
13891                  mac);
13892 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13893         TOKEN_NUM_INITIALIZER
13894                 (struct cmd_macsec_sc_result,
13895                  pi, UINT16);
13896
13897 static void
13898 cmd_set_macsec_sc_parsed(
13899         void *parsed_result,
13900         __attribute__((unused)) struct cmdline *cl,
13901         __attribute__((unused)) void *data)
13902 {
13903         struct cmd_macsec_sc_result *res = parsed_result;
13904         int ret = -ENOTSUP;
13905         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13906
13907 #ifdef RTE_LIBRTE_IXGBE_PMD
13908         ret = is_tx ?
13909                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13910                                 res->mac.addr_bytes) :
13911                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13912                                 res->mac.addr_bytes, res->pi);
13913 #endif
13914         RTE_SET_USED(is_tx);
13915
13916         switch (ret) {
13917         case 0:
13918                 break;
13919         case -ENODEV:
13920                 printf("invalid port_id %d\n", res->port_id);
13921                 break;
13922         case -ENOTSUP:
13923                 printf("not supported on port %d\n", res->port_id);
13924                 break;
13925         default:
13926                 printf("programming error: (%s)\n", strerror(-ret));
13927         }
13928 }
13929
13930 cmdline_parse_inst_t cmd_set_macsec_sc = {
13931         .f = cmd_set_macsec_sc_parsed,
13932         .data = NULL,
13933         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13934         .tokens = {
13935                 (void *)&cmd_macsec_sc_set,
13936                 (void *)&cmd_macsec_sc_macsec,
13937                 (void *)&cmd_macsec_sc_sc,
13938                 (void *)&cmd_macsec_sc_tx_rx,
13939                 (void *)&cmd_macsec_sc_port_id,
13940                 (void *)&cmd_macsec_sc_mac,
13941                 (void *)&cmd_macsec_sc_pi,
13942                 NULL,
13943         },
13944 };
13945
13946 /* Common result structure for MACsec secure connection configure */
13947 struct cmd_macsec_sa_result {
13948         cmdline_fixed_string_t set;
13949         cmdline_fixed_string_t macsec;
13950         cmdline_fixed_string_t sa;
13951         cmdline_fixed_string_t tx_rx;
13952         portid_t port_id;
13953         uint8_t idx;
13954         uint8_t an;
13955         uint32_t pn;
13956         cmdline_fixed_string_t key;
13957 };
13958
13959 /* Common CLI fields for MACsec secure connection configure */
13960 cmdline_parse_token_string_t cmd_macsec_sa_set =
13961         TOKEN_STRING_INITIALIZER
13962                 (struct cmd_macsec_sa_result,
13963                  set, "set");
13964 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13965         TOKEN_STRING_INITIALIZER
13966                 (struct cmd_macsec_sa_result,
13967                  macsec, "macsec");
13968 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13969         TOKEN_STRING_INITIALIZER
13970                 (struct cmd_macsec_sa_result,
13971                  sa, "sa");
13972 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13973         TOKEN_STRING_INITIALIZER
13974                 (struct cmd_macsec_sa_result,
13975                  tx_rx, "tx#rx");
13976 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13977         TOKEN_NUM_INITIALIZER
13978                 (struct cmd_macsec_sa_result,
13979                  port_id, UINT16);
13980 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13981         TOKEN_NUM_INITIALIZER
13982                 (struct cmd_macsec_sa_result,
13983                  idx, UINT8);
13984 cmdline_parse_token_num_t cmd_macsec_sa_an =
13985         TOKEN_NUM_INITIALIZER
13986                 (struct cmd_macsec_sa_result,
13987                  an, UINT8);
13988 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13989         TOKEN_NUM_INITIALIZER
13990                 (struct cmd_macsec_sa_result,
13991                  pn, UINT32);
13992 cmdline_parse_token_string_t cmd_macsec_sa_key =
13993         TOKEN_STRING_INITIALIZER
13994                 (struct cmd_macsec_sa_result,
13995                  key, NULL);
13996
13997 static void
13998 cmd_set_macsec_sa_parsed(
13999         void *parsed_result,
14000         __attribute__((unused)) struct cmdline *cl,
14001         __attribute__((unused)) void *data)
14002 {
14003         struct cmd_macsec_sa_result *res = parsed_result;
14004         int ret = -ENOTSUP;
14005         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14006         uint8_t key[16] = { 0 };
14007         uint8_t xdgt0;
14008         uint8_t xdgt1;
14009         int key_len;
14010         int i;
14011
14012         key_len = strlen(res->key) / 2;
14013         if (key_len > 16)
14014                 key_len = 16;
14015
14016         for (i = 0; i < key_len; i++) {
14017                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14018                 if (xdgt0 == 0xFF)
14019                         return;
14020                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14021                 if (xdgt1 == 0xFF)
14022                         return;
14023                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14024         }
14025
14026 #ifdef RTE_LIBRTE_IXGBE_PMD
14027         ret = is_tx ?
14028                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14029                         res->idx, res->an, res->pn, key) :
14030                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14031                         res->idx, res->an, res->pn, key);
14032 #endif
14033         RTE_SET_USED(is_tx);
14034         RTE_SET_USED(key);
14035
14036         switch (ret) {
14037         case 0:
14038                 break;
14039         case -EINVAL:
14040                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14041                 break;
14042         case -ENODEV:
14043                 printf("invalid port_id %d\n", res->port_id);
14044                 break;
14045         case -ENOTSUP:
14046                 printf("not supported on port %d\n", res->port_id);
14047                 break;
14048         default:
14049                 printf("programming error: (%s)\n", strerror(-ret));
14050         }
14051 }
14052
14053 cmdline_parse_inst_t cmd_set_macsec_sa = {
14054         .f = cmd_set_macsec_sa_parsed,
14055         .data = NULL,
14056         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14057         .tokens = {
14058                 (void *)&cmd_macsec_sa_set,
14059                 (void *)&cmd_macsec_sa_macsec,
14060                 (void *)&cmd_macsec_sa_sa,
14061                 (void *)&cmd_macsec_sa_tx_rx,
14062                 (void *)&cmd_macsec_sa_port_id,
14063                 (void *)&cmd_macsec_sa_idx,
14064                 (void *)&cmd_macsec_sa_an,
14065                 (void *)&cmd_macsec_sa_pn,
14066                 (void *)&cmd_macsec_sa_key,
14067                 NULL,
14068         },
14069 };
14070
14071 /* VF unicast promiscuous mode configuration */
14072
14073 /* Common result structure for VF unicast promiscuous mode */
14074 struct cmd_vf_promisc_result {
14075         cmdline_fixed_string_t set;
14076         cmdline_fixed_string_t vf;
14077         cmdline_fixed_string_t promisc;
14078         portid_t port_id;
14079         uint32_t vf_id;
14080         cmdline_fixed_string_t on_off;
14081 };
14082
14083 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14084 cmdline_parse_token_string_t cmd_vf_promisc_set =
14085         TOKEN_STRING_INITIALIZER
14086                 (struct cmd_vf_promisc_result,
14087                  set, "set");
14088 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14089         TOKEN_STRING_INITIALIZER
14090                 (struct cmd_vf_promisc_result,
14091                  vf, "vf");
14092 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14093         TOKEN_STRING_INITIALIZER
14094                 (struct cmd_vf_promisc_result,
14095                  promisc, "promisc");
14096 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14097         TOKEN_NUM_INITIALIZER
14098                 (struct cmd_vf_promisc_result,
14099                  port_id, UINT16);
14100 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14101         TOKEN_NUM_INITIALIZER
14102                 (struct cmd_vf_promisc_result,
14103                  vf_id, UINT32);
14104 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14105         TOKEN_STRING_INITIALIZER
14106                 (struct cmd_vf_promisc_result,
14107                  on_off, "on#off");
14108
14109 static void
14110 cmd_set_vf_promisc_parsed(
14111         void *parsed_result,
14112         __attribute__((unused)) struct cmdline *cl,
14113         __attribute__((unused)) void *data)
14114 {
14115         struct cmd_vf_promisc_result *res = parsed_result;
14116         int ret = -ENOTSUP;
14117
14118         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14119
14120         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14121                 return;
14122
14123 #ifdef RTE_LIBRTE_I40E_PMD
14124         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14125                                                   res->vf_id, is_on);
14126 #endif
14127
14128         switch (ret) {
14129         case 0:
14130                 break;
14131         case -EINVAL:
14132                 printf("invalid vf_id %d\n", res->vf_id);
14133                 break;
14134         case -ENODEV:
14135                 printf("invalid port_id %d\n", res->port_id);
14136                 break;
14137         case -ENOTSUP:
14138                 printf("function not implemented\n");
14139                 break;
14140         default:
14141                 printf("programming error: (%s)\n", strerror(-ret));
14142         }
14143 }
14144
14145 cmdline_parse_inst_t cmd_set_vf_promisc = {
14146         .f = cmd_set_vf_promisc_parsed,
14147         .data = NULL,
14148         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14149                 "Set unicast promiscuous mode for a VF from the PF",
14150         .tokens = {
14151                 (void *)&cmd_vf_promisc_set,
14152                 (void *)&cmd_vf_promisc_vf,
14153                 (void *)&cmd_vf_promisc_promisc,
14154                 (void *)&cmd_vf_promisc_port_id,
14155                 (void *)&cmd_vf_promisc_vf_id,
14156                 (void *)&cmd_vf_promisc_on_off,
14157                 NULL,
14158         },
14159 };
14160
14161 /* VF multicast promiscuous mode configuration */
14162
14163 /* Common result structure for VF multicast promiscuous mode */
14164 struct cmd_vf_allmulti_result {
14165         cmdline_fixed_string_t set;
14166         cmdline_fixed_string_t vf;
14167         cmdline_fixed_string_t allmulti;
14168         portid_t port_id;
14169         uint32_t vf_id;
14170         cmdline_fixed_string_t on_off;
14171 };
14172
14173 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14174 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14175         TOKEN_STRING_INITIALIZER
14176                 (struct cmd_vf_allmulti_result,
14177                  set, "set");
14178 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14179         TOKEN_STRING_INITIALIZER
14180                 (struct cmd_vf_allmulti_result,
14181                  vf, "vf");
14182 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14183         TOKEN_STRING_INITIALIZER
14184                 (struct cmd_vf_allmulti_result,
14185                  allmulti, "allmulti");
14186 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14187         TOKEN_NUM_INITIALIZER
14188                 (struct cmd_vf_allmulti_result,
14189                  port_id, UINT16);
14190 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14191         TOKEN_NUM_INITIALIZER
14192                 (struct cmd_vf_allmulti_result,
14193                  vf_id, UINT32);
14194 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14195         TOKEN_STRING_INITIALIZER
14196                 (struct cmd_vf_allmulti_result,
14197                  on_off, "on#off");
14198
14199 static void
14200 cmd_set_vf_allmulti_parsed(
14201         void *parsed_result,
14202         __attribute__((unused)) struct cmdline *cl,
14203         __attribute__((unused)) void *data)
14204 {
14205         struct cmd_vf_allmulti_result *res = parsed_result;
14206         int ret = -ENOTSUP;
14207
14208         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14209
14210         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14211                 return;
14212
14213 #ifdef RTE_LIBRTE_I40E_PMD
14214         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14215                                                     res->vf_id, is_on);
14216 #endif
14217
14218         switch (ret) {
14219         case 0:
14220                 break;
14221         case -EINVAL:
14222                 printf("invalid vf_id %d\n", res->vf_id);
14223                 break;
14224         case -ENODEV:
14225                 printf("invalid port_id %d\n", res->port_id);
14226                 break;
14227         case -ENOTSUP:
14228                 printf("function not implemented\n");
14229                 break;
14230         default:
14231                 printf("programming error: (%s)\n", strerror(-ret));
14232         }
14233 }
14234
14235 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14236         .f = cmd_set_vf_allmulti_parsed,
14237         .data = NULL,
14238         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14239                 "Set multicast promiscuous mode for a VF from the PF",
14240         .tokens = {
14241                 (void *)&cmd_vf_allmulti_set,
14242                 (void *)&cmd_vf_allmulti_vf,
14243                 (void *)&cmd_vf_allmulti_allmulti,
14244                 (void *)&cmd_vf_allmulti_port_id,
14245                 (void *)&cmd_vf_allmulti_vf_id,
14246                 (void *)&cmd_vf_allmulti_on_off,
14247                 NULL,
14248         },
14249 };
14250
14251 /* vf broadcast mode configuration */
14252
14253 /* Common result structure for vf broadcast */
14254 struct cmd_set_vf_broadcast_result {
14255         cmdline_fixed_string_t set;
14256         cmdline_fixed_string_t vf;
14257         cmdline_fixed_string_t broadcast;
14258         portid_t port_id;
14259         uint16_t vf_id;
14260         cmdline_fixed_string_t on_off;
14261 };
14262
14263 /* Common CLI fields for vf broadcast enable disable */
14264 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14265         TOKEN_STRING_INITIALIZER
14266                 (struct cmd_set_vf_broadcast_result,
14267                  set, "set");
14268 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14269         TOKEN_STRING_INITIALIZER
14270                 (struct cmd_set_vf_broadcast_result,
14271                  vf, "vf");
14272 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14273         TOKEN_STRING_INITIALIZER
14274                 (struct cmd_set_vf_broadcast_result,
14275                  broadcast, "broadcast");
14276 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14277         TOKEN_NUM_INITIALIZER
14278                 (struct cmd_set_vf_broadcast_result,
14279                  port_id, UINT16);
14280 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14281         TOKEN_NUM_INITIALIZER
14282                 (struct cmd_set_vf_broadcast_result,
14283                  vf_id, UINT16);
14284 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14285         TOKEN_STRING_INITIALIZER
14286                 (struct cmd_set_vf_broadcast_result,
14287                  on_off, "on#off");
14288
14289 static void
14290 cmd_set_vf_broadcast_parsed(
14291         void *parsed_result,
14292         __attribute__((unused)) struct cmdline *cl,
14293         __attribute__((unused)) void *data)
14294 {
14295         struct cmd_set_vf_broadcast_result *res = parsed_result;
14296         int ret = -ENOTSUP;
14297
14298         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14299
14300         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14301                 return;
14302
14303 #ifdef RTE_LIBRTE_I40E_PMD
14304         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14305                                             res->vf_id, is_on);
14306 #endif
14307
14308         switch (ret) {
14309         case 0:
14310                 break;
14311         case -EINVAL:
14312                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14313                 break;
14314         case -ENODEV:
14315                 printf("invalid port_id %d\n", res->port_id);
14316                 break;
14317         case -ENOTSUP:
14318                 printf("function not implemented\n");
14319                 break;
14320         default:
14321                 printf("programming error: (%s)\n", strerror(-ret));
14322         }
14323 }
14324
14325 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14326         .f = cmd_set_vf_broadcast_parsed,
14327         .data = NULL,
14328         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14329         .tokens = {
14330                 (void *)&cmd_set_vf_broadcast_set,
14331                 (void *)&cmd_set_vf_broadcast_vf,
14332                 (void *)&cmd_set_vf_broadcast_broadcast,
14333                 (void *)&cmd_set_vf_broadcast_port_id,
14334                 (void *)&cmd_set_vf_broadcast_vf_id,
14335                 (void *)&cmd_set_vf_broadcast_on_off,
14336                 NULL,
14337         },
14338 };
14339
14340 /* vf vlan tag configuration */
14341
14342 /* Common result structure for vf vlan tag */
14343 struct cmd_set_vf_vlan_tag_result {
14344         cmdline_fixed_string_t set;
14345         cmdline_fixed_string_t vf;
14346         cmdline_fixed_string_t vlan;
14347         cmdline_fixed_string_t tag;
14348         portid_t port_id;
14349         uint16_t vf_id;
14350         cmdline_fixed_string_t on_off;
14351 };
14352
14353 /* Common CLI fields for vf vlan tag enable disable */
14354 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14355         TOKEN_STRING_INITIALIZER
14356                 (struct cmd_set_vf_vlan_tag_result,
14357                  set, "set");
14358 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14359         TOKEN_STRING_INITIALIZER
14360                 (struct cmd_set_vf_vlan_tag_result,
14361                  vf, "vf");
14362 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14363         TOKEN_STRING_INITIALIZER
14364                 (struct cmd_set_vf_vlan_tag_result,
14365                  vlan, "vlan");
14366 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14367         TOKEN_STRING_INITIALIZER
14368                 (struct cmd_set_vf_vlan_tag_result,
14369                  tag, "tag");
14370 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14371         TOKEN_NUM_INITIALIZER
14372                 (struct cmd_set_vf_vlan_tag_result,
14373                  port_id, UINT16);
14374 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14375         TOKEN_NUM_INITIALIZER
14376                 (struct cmd_set_vf_vlan_tag_result,
14377                  vf_id, UINT16);
14378 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14379         TOKEN_STRING_INITIALIZER
14380                 (struct cmd_set_vf_vlan_tag_result,
14381                  on_off, "on#off");
14382
14383 static void
14384 cmd_set_vf_vlan_tag_parsed(
14385         void *parsed_result,
14386         __attribute__((unused)) struct cmdline *cl,
14387         __attribute__((unused)) void *data)
14388 {
14389         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14390         int ret = -ENOTSUP;
14391
14392         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14393
14394         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14395                 return;
14396
14397 #ifdef RTE_LIBRTE_I40E_PMD
14398         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14399                                            res->vf_id, is_on);
14400 #endif
14401
14402         switch (ret) {
14403         case 0:
14404                 break;
14405         case -EINVAL:
14406                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14407                 break;
14408         case -ENODEV:
14409                 printf("invalid port_id %d\n", res->port_id);
14410                 break;
14411         case -ENOTSUP:
14412                 printf("function not implemented\n");
14413                 break;
14414         default:
14415                 printf("programming error: (%s)\n", strerror(-ret));
14416         }
14417 }
14418
14419 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14420         .f = cmd_set_vf_vlan_tag_parsed,
14421         .data = NULL,
14422         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14423         .tokens = {
14424                 (void *)&cmd_set_vf_vlan_tag_set,
14425                 (void *)&cmd_set_vf_vlan_tag_vf,
14426                 (void *)&cmd_set_vf_vlan_tag_vlan,
14427                 (void *)&cmd_set_vf_vlan_tag_tag,
14428                 (void *)&cmd_set_vf_vlan_tag_port_id,
14429                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14430                 (void *)&cmd_set_vf_vlan_tag_on_off,
14431                 NULL,
14432         },
14433 };
14434
14435 /* Common definition of VF and TC TX bandwidth configuration */
14436 struct cmd_vf_tc_bw_result {
14437         cmdline_fixed_string_t set;
14438         cmdline_fixed_string_t vf;
14439         cmdline_fixed_string_t tc;
14440         cmdline_fixed_string_t tx;
14441         cmdline_fixed_string_t min_bw;
14442         cmdline_fixed_string_t max_bw;
14443         cmdline_fixed_string_t strict_link_prio;
14444         portid_t port_id;
14445         uint16_t vf_id;
14446         uint8_t tc_no;
14447         uint32_t bw;
14448         cmdline_fixed_string_t bw_list;
14449         uint8_t tc_map;
14450 };
14451
14452 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14453         TOKEN_STRING_INITIALIZER
14454                 (struct cmd_vf_tc_bw_result,
14455                  set, "set");
14456 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14457         TOKEN_STRING_INITIALIZER
14458                 (struct cmd_vf_tc_bw_result,
14459                  vf, "vf");
14460 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14461         TOKEN_STRING_INITIALIZER
14462                 (struct cmd_vf_tc_bw_result,
14463                  tc, "tc");
14464 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14465         TOKEN_STRING_INITIALIZER
14466                 (struct cmd_vf_tc_bw_result,
14467                  tx, "tx");
14468 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14469         TOKEN_STRING_INITIALIZER
14470                 (struct cmd_vf_tc_bw_result,
14471                  strict_link_prio, "strict-link-priority");
14472 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14473         TOKEN_STRING_INITIALIZER
14474                 (struct cmd_vf_tc_bw_result,
14475                  min_bw, "min-bandwidth");
14476 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14477         TOKEN_STRING_INITIALIZER
14478                 (struct cmd_vf_tc_bw_result,
14479                  max_bw, "max-bandwidth");
14480 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14481         TOKEN_NUM_INITIALIZER
14482                 (struct cmd_vf_tc_bw_result,
14483                  port_id, UINT16);
14484 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14485         TOKEN_NUM_INITIALIZER
14486                 (struct cmd_vf_tc_bw_result,
14487                  vf_id, UINT16);
14488 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14489         TOKEN_NUM_INITIALIZER
14490                 (struct cmd_vf_tc_bw_result,
14491                  tc_no, UINT8);
14492 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14493         TOKEN_NUM_INITIALIZER
14494                 (struct cmd_vf_tc_bw_result,
14495                  bw, UINT32);
14496 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14497         TOKEN_STRING_INITIALIZER
14498                 (struct cmd_vf_tc_bw_result,
14499                  bw_list, NULL);
14500 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14501         TOKEN_NUM_INITIALIZER
14502                 (struct cmd_vf_tc_bw_result,
14503                  tc_map, UINT8);
14504
14505 /* VF max bandwidth setting */
14506 static void
14507 cmd_vf_max_bw_parsed(
14508         void *parsed_result,
14509         __attribute__((unused)) struct cmdline *cl,
14510         __attribute__((unused)) void *data)
14511 {
14512         struct cmd_vf_tc_bw_result *res = parsed_result;
14513         int ret = -ENOTSUP;
14514
14515         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14516                 return;
14517
14518 #ifdef RTE_LIBRTE_I40E_PMD
14519         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14520                                          res->vf_id, res->bw);
14521 #endif
14522
14523         switch (ret) {
14524         case 0:
14525                 break;
14526         case -EINVAL:
14527                 printf("invalid vf_id %d or bandwidth %d\n",
14528                        res->vf_id, res->bw);
14529                 break;
14530         case -ENODEV:
14531                 printf("invalid port_id %d\n", res->port_id);
14532                 break;
14533         case -ENOTSUP:
14534                 printf("function not implemented\n");
14535                 break;
14536         default:
14537                 printf("programming error: (%s)\n", strerror(-ret));
14538         }
14539 }
14540
14541 cmdline_parse_inst_t cmd_vf_max_bw = {
14542         .f = cmd_vf_max_bw_parsed,
14543         .data = NULL,
14544         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14545         .tokens = {
14546                 (void *)&cmd_vf_tc_bw_set,
14547                 (void *)&cmd_vf_tc_bw_vf,
14548                 (void *)&cmd_vf_tc_bw_tx,
14549                 (void *)&cmd_vf_tc_bw_max_bw,
14550                 (void *)&cmd_vf_tc_bw_port_id,
14551                 (void *)&cmd_vf_tc_bw_vf_id,
14552                 (void *)&cmd_vf_tc_bw_bw,
14553                 NULL,
14554         },
14555 };
14556
14557 static int
14558 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14559                            uint8_t *tc_num,
14560                            char *str)
14561 {
14562         uint32_t size;
14563         const char *p, *p0 = str;
14564         char s[256];
14565         char *end;
14566         char *str_fld[16];
14567         uint16_t i;
14568         int ret;
14569
14570         p = strchr(p0, '(');
14571         if (p == NULL) {
14572                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14573                 return -1;
14574         }
14575         p++;
14576         p0 = strchr(p, ')');
14577         if (p0 == NULL) {
14578                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14579                 return -1;
14580         }
14581         size = p0 - p;
14582         if (size >= sizeof(s)) {
14583                 printf("The string size exceeds the internal buffer size\n");
14584                 return -1;
14585         }
14586         snprintf(s, sizeof(s), "%.*s", size, p);
14587         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14588         if (ret <= 0) {
14589                 printf("Failed to get the bandwidth list. ");
14590                 return -1;
14591         }
14592         *tc_num = ret;
14593         for (i = 0; i < ret; i++)
14594                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14595
14596         return 0;
14597 }
14598
14599 /* TC min bandwidth setting */
14600 static void
14601 cmd_vf_tc_min_bw_parsed(
14602         void *parsed_result,
14603         __attribute__((unused)) struct cmdline *cl,
14604         __attribute__((unused)) void *data)
14605 {
14606         struct cmd_vf_tc_bw_result *res = parsed_result;
14607         uint8_t tc_num;
14608         uint8_t bw[16];
14609         int ret = -ENOTSUP;
14610
14611         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14612                 return;
14613
14614         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14615         if (ret)
14616                 return;
14617
14618 #ifdef RTE_LIBRTE_I40E_PMD
14619         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14620                                               tc_num, bw);
14621 #endif
14622
14623         switch (ret) {
14624         case 0:
14625                 break;
14626         case -EINVAL:
14627                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14628                 break;
14629         case -ENODEV:
14630                 printf("invalid port_id %d\n", res->port_id);
14631                 break;
14632         case -ENOTSUP:
14633                 printf("function not implemented\n");
14634                 break;
14635         default:
14636                 printf("programming error: (%s)\n", strerror(-ret));
14637         }
14638 }
14639
14640 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14641         .f = cmd_vf_tc_min_bw_parsed,
14642         .data = NULL,
14643         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14644                     " <bw1, bw2, ...>",
14645         .tokens = {
14646                 (void *)&cmd_vf_tc_bw_set,
14647                 (void *)&cmd_vf_tc_bw_vf,
14648                 (void *)&cmd_vf_tc_bw_tc,
14649                 (void *)&cmd_vf_tc_bw_tx,
14650                 (void *)&cmd_vf_tc_bw_min_bw,
14651                 (void *)&cmd_vf_tc_bw_port_id,
14652                 (void *)&cmd_vf_tc_bw_vf_id,
14653                 (void *)&cmd_vf_tc_bw_bw_list,
14654                 NULL,
14655         },
14656 };
14657
14658 static void
14659 cmd_tc_min_bw_parsed(
14660         void *parsed_result,
14661         __attribute__((unused)) struct cmdline *cl,
14662         __attribute__((unused)) void *data)
14663 {
14664         struct cmd_vf_tc_bw_result *res = parsed_result;
14665         struct rte_port *port;
14666         uint8_t tc_num;
14667         uint8_t bw[16];
14668         int ret = -ENOTSUP;
14669
14670         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14671                 return;
14672
14673         port = &ports[res->port_id];
14674         /** Check if the port is not started **/
14675         if (port->port_status != RTE_PORT_STOPPED) {
14676                 printf("Please stop port %d first\n", res->port_id);
14677                 return;
14678         }
14679
14680         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14681         if (ret)
14682                 return;
14683
14684 #ifdef RTE_LIBRTE_IXGBE_PMD
14685         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14686 #endif
14687
14688         switch (ret) {
14689         case 0:
14690                 break;
14691         case -EINVAL:
14692                 printf("invalid bandwidth\n");
14693                 break;
14694         case -ENODEV:
14695                 printf("invalid port_id %d\n", res->port_id);
14696                 break;
14697         case -ENOTSUP:
14698                 printf("function not implemented\n");
14699                 break;
14700         default:
14701                 printf("programming error: (%s)\n", strerror(-ret));
14702         }
14703 }
14704
14705 cmdline_parse_inst_t cmd_tc_min_bw = {
14706         .f = cmd_tc_min_bw_parsed,
14707         .data = NULL,
14708         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14709         .tokens = {
14710                 (void *)&cmd_vf_tc_bw_set,
14711                 (void *)&cmd_vf_tc_bw_tc,
14712                 (void *)&cmd_vf_tc_bw_tx,
14713                 (void *)&cmd_vf_tc_bw_min_bw,
14714                 (void *)&cmd_vf_tc_bw_port_id,
14715                 (void *)&cmd_vf_tc_bw_bw_list,
14716                 NULL,
14717         },
14718 };
14719
14720 /* TC max bandwidth setting */
14721 static void
14722 cmd_vf_tc_max_bw_parsed(
14723         void *parsed_result,
14724         __attribute__((unused)) struct cmdline *cl,
14725         __attribute__((unused)) void *data)
14726 {
14727         struct cmd_vf_tc_bw_result *res = parsed_result;
14728         int ret = -ENOTSUP;
14729
14730         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14731                 return;
14732
14733 #ifdef RTE_LIBRTE_I40E_PMD
14734         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14735                                             res->tc_no, res->bw);
14736 #endif
14737
14738         switch (ret) {
14739         case 0:
14740                 break;
14741         case -EINVAL:
14742                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14743                        res->vf_id, res->tc_no, res->bw);
14744                 break;
14745         case -ENODEV:
14746                 printf("invalid port_id %d\n", res->port_id);
14747                 break;
14748         case -ENOTSUP:
14749                 printf("function not implemented\n");
14750                 break;
14751         default:
14752                 printf("programming error: (%s)\n", strerror(-ret));
14753         }
14754 }
14755
14756 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14757         .f = cmd_vf_tc_max_bw_parsed,
14758         .data = NULL,
14759         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14760                     " <bandwidth>",
14761         .tokens = {
14762                 (void *)&cmd_vf_tc_bw_set,
14763                 (void *)&cmd_vf_tc_bw_vf,
14764                 (void *)&cmd_vf_tc_bw_tc,
14765                 (void *)&cmd_vf_tc_bw_tx,
14766                 (void *)&cmd_vf_tc_bw_max_bw,
14767                 (void *)&cmd_vf_tc_bw_port_id,
14768                 (void *)&cmd_vf_tc_bw_vf_id,
14769                 (void *)&cmd_vf_tc_bw_tc_no,
14770                 (void *)&cmd_vf_tc_bw_bw,
14771                 NULL,
14772         },
14773 };
14774
14775
14776 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14777
14778 /* *** Set Port default Traffic Management Hierarchy *** */
14779 struct cmd_set_port_tm_hierarchy_default_result {
14780         cmdline_fixed_string_t set;
14781         cmdline_fixed_string_t port;
14782         cmdline_fixed_string_t tm;
14783         cmdline_fixed_string_t hierarchy;
14784         cmdline_fixed_string_t def;
14785         portid_t port_id;
14786 };
14787
14788 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14789         TOKEN_STRING_INITIALIZER(
14790                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14791 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14792         TOKEN_STRING_INITIALIZER(
14793                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14794 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14795         TOKEN_STRING_INITIALIZER(
14796                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14797 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14798         TOKEN_STRING_INITIALIZER(
14799                 struct cmd_set_port_tm_hierarchy_default_result,
14800                         hierarchy, "hierarchy");
14801 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14802         TOKEN_STRING_INITIALIZER(
14803                 struct cmd_set_port_tm_hierarchy_default_result,
14804                         def, "default");
14805 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14806         TOKEN_NUM_INITIALIZER(
14807                 struct cmd_set_port_tm_hierarchy_default_result,
14808                         port_id, UINT16);
14809
14810 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14811         __attribute__((unused)) struct cmdline *cl,
14812         __attribute__((unused)) void *data)
14813 {
14814         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14815         struct rte_port *p;
14816         portid_t port_id = res->port_id;
14817
14818         if (port_id_is_invalid(port_id, ENABLED_WARN))
14819                 return;
14820
14821         p = &ports[port_id];
14822
14823         /* Forward mode: tm */
14824         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
14825                 printf("  softnicfwd mode not enabled(error)\n");
14826                 return;
14827         }
14828
14829         /* Set the default tm hierarchy */
14830         p->softport.default_tm_hierarchy_enable = 1;
14831 }
14832
14833 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14834         .f = cmd_set_port_tm_hierarchy_default_parsed,
14835         .data = NULL,
14836         .help_str = "set port tm hierarchy default <port_id>",
14837         .tokens = {
14838                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14839                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14840                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14841                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14842                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14843                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14844                 NULL,
14845         },
14846 };
14847 #endif
14848
14849 /* Strict link priority scheduling mode setting */
14850 static void
14851 cmd_strict_link_prio_parsed(
14852         void *parsed_result,
14853         __attribute__((unused)) struct cmdline *cl,
14854         __attribute__((unused)) void *data)
14855 {
14856         struct cmd_vf_tc_bw_result *res = parsed_result;
14857         int ret = -ENOTSUP;
14858
14859         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14860                 return;
14861
14862 #ifdef RTE_LIBRTE_I40E_PMD
14863         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14864 #endif
14865
14866         switch (ret) {
14867         case 0:
14868                 break;
14869         case -EINVAL:
14870                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14871                 break;
14872         case -ENODEV:
14873                 printf("invalid port_id %d\n", res->port_id);
14874                 break;
14875         case -ENOTSUP:
14876                 printf("function not implemented\n");
14877                 break;
14878         default:
14879                 printf("programming error: (%s)\n", strerror(-ret));
14880         }
14881 }
14882
14883 cmdline_parse_inst_t cmd_strict_link_prio = {
14884         .f = cmd_strict_link_prio_parsed,
14885         .data = NULL,
14886         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14887         .tokens = {
14888                 (void *)&cmd_vf_tc_bw_set,
14889                 (void *)&cmd_vf_tc_bw_tx,
14890                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14891                 (void *)&cmd_vf_tc_bw_port_id,
14892                 (void *)&cmd_vf_tc_bw_tc_map,
14893                 NULL,
14894         },
14895 };
14896
14897 /* Load dynamic device personalization*/
14898 struct cmd_ddp_add_result {
14899         cmdline_fixed_string_t ddp;
14900         cmdline_fixed_string_t add;
14901         portid_t port_id;
14902         char filepath[];
14903 };
14904
14905 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14906         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14907 cmdline_parse_token_string_t cmd_ddp_add_add =
14908         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14909 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14910         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14911 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14912         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14913
14914 static void
14915 cmd_ddp_add_parsed(
14916         void *parsed_result,
14917         __attribute__((unused)) struct cmdline *cl,
14918         __attribute__((unused)) void *data)
14919 {
14920         struct cmd_ddp_add_result *res = parsed_result;
14921         uint8_t *buff;
14922         uint32_t size;
14923         char *filepath;
14924         char *file_fld[2];
14925         int file_num;
14926         int ret = -ENOTSUP;
14927
14928         if (!all_ports_stopped()) {
14929                 printf("Please stop all ports first\n");
14930                 return;
14931         }
14932
14933         filepath = strdup(res->filepath);
14934         if (filepath == NULL) {
14935                 printf("Failed to allocate memory\n");
14936                 return;
14937         }
14938         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14939
14940         buff = open_file(file_fld[0], &size);
14941         if (!buff) {
14942                 free((void *)filepath);
14943                 return;
14944         }
14945
14946 #ifdef RTE_LIBRTE_I40E_PMD
14947         if (ret == -ENOTSUP)
14948                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14949                                                buff, size,
14950                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14951 #endif
14952
14953         if (ret == -EEXIST)
14954                 printf("Profile has already existed.\n");
14955         else if (ret < 0)
14956                 printf("Failed to load profile.\n");
14957         else if (file_num == 2)
14958                 save_file(file_fld[1], buff, size);
14959
14960         close_file(buff);
14961         free((void *)filepath);
14962 }
14963
14964 cmdline_parse_inst_t cmd_ddp_add = {
14965         .f = cmd_ddp_add_parsed,
14966         .data = NULL,
14967         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14968         .tokens = {
14969                 (void *)&cmd_ddp_add_ddp,
14970                 (void *)&cmd_ddp_add_add,
14971                 (void *)&cmd_ddp_add_port_id,
14972                 (void *)&cmd_ddp_add_filepath,
14973                 NULL,
14974         },
14975 };
14976
14977 /* Delete dynamic device personalization*/
14978 struct cmd_ddp_del_result {
14979         cmdline_fixed_string_t ddp;
14980         cmdline_fixed_string_t del;
14981         portid_t port_id;
14982         char filepath[];
14983 };
14984
14985 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14986         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14987 cmdline_parse_token_string_t cmd_ddp_del_del =
14988         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14989 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14990         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14991 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14992         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14993
14994 static void
14995 cmd_ddp_del_parsed(
14996         void *parsed_result,
14997         __attribute__((unused)) struct cmdline *cl,
14998         __attribute__((unused)) void *data)
14999 {
15000         struct cmd_ddp_del_result *res = parsed_result;
15001         uint8_t *buff;
15002         uint32_t size;
15003         int ret = -ENOTSUP;
15004
15005         if (!all_ports_stopped()) {
15006                 printf("Please stop all ports first\n");
15007                 return;
15008         }
15009
15010         buff = open_file(res->filepath, &size);
15011         if (!buff)
15012                 return;
15013
15014 #ifdef RTE_LIBRTE_I40E_PMD
15015         if (ret == -ENOTSUP)
15016                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15017                                                buff, size,
15018                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15019 #endif
15020
15021         if (ret == -EACCES)
15022                 printf("Profile does not exist.\n");
15023         else if (ret < 0)
15024                 printf("Failed to delete profile.\n");
15025
15026         close_file(buff);
15027 }
15028
15029 cmdline_parse_inst_t cmd_ddp_del = {
15030         .f = cmd_ddp_del_parsed,
15031         .data = NULL,
15032         .help_str = "ddp del <port_id> <backup_profile_path>",
15033         .tokens = {
15034                 (void *)&cmd_ddp_del_ddp,
15035                 (void *)&cmd_ddp_del_del,
15036                 (void *)&cmd_ddp_del_port_id,
15037                 (void *)&cmd_ddp_del_filepath,
15038                 NULL,
15039         },
15040 };
15041
15042 /* Get dynamic device personalization profile info */
15043 struct cmd_ddp_info_result {
15044         cmdline_fixed_string_t ddp;
15045         cmdline_fixed_string_t get;
15046         cmdline_fixed_string_t info;
15047         char filepath[];
15048 };
15049
15050 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15051         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15052 cmdline_parse_token_string_t cmd_ddp_info_get =
15053         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15054 cmdline_parse_token_string_t cmd_ddp_info_info =
15055         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15056 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15057         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15058
15059 static void
15060 cmd_ddp_info_parsed(
15061         void *parsed_result,
15062         __attribute__((unused)) struct cmdline *cl,
15063         __attribute__((unused)) void *data)
15064 {
15065         struct cmd_ddp_info_result *res = parsed_result;
15066         uint8_t *pkg;
15067         uint32_t pkg_size;
15068         int ret = -ENOTSUP;
15069 #ifdef RTE_LIBRTE_I40E_PMD
15070         uint32_t i, j, n;
15071         uint8_t *buff;
15072         uint32_t buff_size = 0;
15073         struct rte_pmd_i40e_profile_info info;
15074         uint32_t dev_num = 0;
15075         struct rte_pmd_i40e_ddp_device_id *devs;
15076         uint32_t proto_num = 0;
15077         struct rte_pmd_i40e_proto_info *proto = NULL;
15078         uint32_t pctype_num = 0;
15079         struct rte_pmd_i40e_ptype_info *pctype;
15080         uint32_t ptype_num = 0;
15081         struct rte_pmd_i40e_ptype_info *ptype;
15082         uint8_t proto_id;
15083
15084 #endif
15085
15086         pkg = open_file(res->filepath, &pkg_size);
15087         if (!pkg)
15088                 return;
15089
15090 #ifdef RTE_LIBRTE_I40E_PMD
15091         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15092                                 (uint8_t *)&info, sizeof(info),
15093                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15094         if (!ret) {
15095                 printf("Global Track id:       0x%x\n", info.track_id);
15096                 printf("Global Version:        %d.%d.%d.%d\n",
15097                         info.version.major,
15098                         info.version.minor,
15099                         info.version.update,
15100                         info.version.draft);
15101                 printf("Global Package name:   %s\n\n", info.name);
15102         }
15103
15104         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15105                                 (uint8_t *)&info, sizeof(info),
15106                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15107         if (!ret) {
15108                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15109                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15110                         info.version.major,
15111                         info.version.minor,
15112                         info.version.update,
15113                         info.version.draft);
15114                 printf("i40e Profile name:     %s\n\n", info.name);
15115         }
15116
15117         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15118                                 (uint8_t *)&buff_size, sizeof(buff_size),
15119                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15120         if (!ret && buff_size) {
15121                 buff = (uint8_t *)malloc(buff_size);
15122                 if (buff) {
15123                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15124                                                 buff, buff_size,
15125                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15126                         if (!ret)
15127                                 printf("Package Notes:\n%s\n\n", buff);
15128                         free(buff);
15129                 }
15130         }
15131
15132         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15133                                 (uint8_t *)&dev_num, sizeof(dev_num),
15134                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15135         if (!ret && dev_num) {
15136                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15137                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15138                 if (devs) {
15139                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15140                                                 (uint8_t *)devs, buff_size,
15141                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15142                         if (!ret) {
15143                                 printf("List of supported devices:\n");
15144                                 for (i = 0; i < dev_num; i++) {
15145                                         printf("  %04X:%04X %04X:%04X\n",
15146                                                 devs[i].vendor_dev_id >> 16,
15147                                                 devs[i].vendor_dev_id & 0xFFFF,
15148                                                 devs[i].sub_vendor_dev_id >> 16,
15149                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15150                                 }
15151                                 printf("\n");
15152                         }
15153                         free(devs);
15154                 }
15155         }
15156
15157         /* get information about protocols and packet types */
15158         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15159                 (uint8_t *)&proto_num, sizeof(proto_num),
15160                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15161         if (ret || !proto_num)
15162                 goto no_print_return;
15163
15164         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15165         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15166         if (!proto)
15167                 goto no_print_return;
15168
15169         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15170                                         buff_size,
15171                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15172         if (!ret) {
15173                 printf("List of used protocols:\n");
15174                 for (i = 0; i < proto_num; i++)
15175                         printf("  %2u: %s\n", proto[i].proto_id,
15176                                proto[i].name);
15177                 printf("\n");
15178         }
15179         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15180                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15181                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15182         if (ret || !pctype_num)
15183                 goto no_print_pctypes;
15184
15185         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15186         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15187         if (!pctype)
15188                 goto no_print_pctypes;
15189
15190         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15191                                         buff_size,
15192                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15193         if (ret) {
15194                 free(pctype);
15195                 goto no_print_pctypes;
15196         }
15197
15198         printf("List of defined packet classification types:\n");
15199         for (i = 0; i < pctype_num; i++) {
15200                 printf("  %2u:", pctype[i].ptype_id);
15201                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15202                         proto_id = pctype[i].protocols[j];
15203                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15204                                 for (n = 0; n < proto_num; n++) {
15205                                         if (proto[n].proto_id == proto_id) {
15206                                                 printf(" %s", proto[n].name);
15207                                                 break;
15208                                         }
15209                                 }
15210                         }
15211                 }
15212                 printf("\n");
15213         }
15214         printf("\n");
15215         free(pctype);
15216
15217 no_print_pctypes:
15218
15219         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15220                                         sizeof(ptype_num),
15221                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15222         if (ret || !ptype_num)
15223                 goto no_print_return;
15224
15225         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15226         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15227         if (!ptype)
15228                 goto no_print_return;
15229
15230         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15231                                         buff_size,
15232                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15233         if (ret) {
15234                 free(ptype);
15235                 goto no_print_return;
15236         }
15237         printf("List of defined packet types:\n");
15238         for (i = 0; i < ptype_num; i++) {
15239                 printf("  %2u:", ptype[i].ptype_id);
15240                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15241                         proto_id = ptype[i].protocols[j];
15242                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15243                                 for (n = 0; n < proto_num; n++) {
15244                                         if (proto[n].proto_id == proto_id) {
15245                                                 printf(" %s", proto[n].name);
15246                                                 break;
15247                                         }
15248                                 }
15249                         }
15250                 }
15251                 printf("\n");
15252         }
15253         free(ptype);
15254         printf("\n");
15255
15256         ret = 0;
15257 no_print_return:
15258         if (proto)
15259                 free(proto);
15260 #endif
15261         if (ret == -ENOTSUP)
15262                 printf("Function not supported in PMD driver\n");
15263         close_file(pkg);
15264 }
15265
15266 cmdline_parse_inst_t cmd_ddp_get_info = {
15267         .f = cmd_ddp_info_parsed,
15268         .data = NULL,
15269         .help_str = "ddp get info <profile_path>",
15270         .tokens = {
15271                 (void *)&cmd_ddp_info_ddp,
15272                 (void *)&cmd_ddp_info_get,
15273                 (void *)&cmd_ddp_info_info,
15274                 (void *)&cmd_ddp_info_filepath,
15275                 NULL,
15276         },
15277 };
15278
15279 /* Get dynamic device personalization profile info list*/
15280 #define PROFILE_INFO_SIZE 48
15281 #define MAX_PROFILE_NUM 16
15282
15283 struct cmd_ddp_get_list_result {
15284         cmdline_fixed_string_t ddp;
15285         cmdline_fixed_string_t get;
15286         cmdline_fixed_string_t list;
15287         portid_t port_id;
15288 };
15289
15290 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15291         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15292 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15293         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15294 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15295         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15296 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15297         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15298
15299 static void
15300 cmd_ddp_get_list_parsed(
15301         __attribute__((unused)) void *parsed_result,
15302         __attribute__((unused)) struct cmdline *cl,
15303         __attribute__((unused)) void *data)
15304 {
15305 #ifdef RTE_LIBRTE_I40E_PMD
15306         struct cmd_ddp_get_list_result *res = parsed_result;
15307         struct rte_pmd_i40e_profile_list *p_list;
15308         struct rte_pmd_i40e_profile_info *p_info;
15309         uint32_t p_num;
15310         uint32_t size;
15311         uint32_t i;
15312 #endif
15313         int ret = -ENOTSUP;
15314
15315 #ifdef RTE_LIBRTE_I40E_PMD
15316         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15317         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15318         if (!p_list)
15319                 printf("%s: Failed to malloc buffer\n", __func__);
15320
15321         if (ret == -ENOTSUP)
15322                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15323                                                 (uint8_t *)p_list, size);
15324
15325         if (!ret) {
15326                 p_num = p_list->p_count;
15327                 printf("Profile number is: %d\n\n", p_num);
15328
15329                 for (i = 0; i < p_num; i++) {
15330                         p_info = &p_list->p_info[i];
15331                         printf("Profile %d:\n", i);
15332                         printf("Track id:     0x%x\n", p_info->track_id);
15333                         printf("Version:      %d.%d.%d.%d\n",
15334                                p_info->version.major,
15335                                p_info->version.minor,
15336                                p_info->version.update,
15337                                p_info->version.draft);
15338                         printf("Profile name: %s\n\n", p_info->name);
15339                 }
15340         }
15341
15342         free(p_list);
15343 #endif
15344
15345         if (ret < 0)
15346                 printf("Failed to get ddp list\n");
15347 }
15348
15349 cmdline_parse_inst_t cmd_ddp_get_list = {
15350         .f = cmd_ddp_get_list_parsed,
15351         .data = NULL,
15352         .help_str = "ddp get list <port_id>",
15353         .tokens = {
15354                 (void *)&cmd_ddp_get_list_ddp,
15355                 (void *)&cmd_ddp_get_list_get,
15356                 (void *)&cmd_ddp_get_list_list,
15357                 (void *)&cmd_ddp_get_list_port_id,
15358                 NULL,
15359         },
15360 };
15361
15362 /* Configure input set */
15363 struct cmd_cfg_input_set_result {
15364         cmdline_fixed_string_t port;
15365         cmdline_fixed_string_t cfg;
15366         portid_t port_id;
15367         cmdline_fixed_string_t pctype;
15368         uint8_t pctype_id;
15369         cmdline_fixed_string_t inset_type;
15370         cmdline_fixed_string_t opt;
15371         cmdline_fixed_string_t field;
15372         uint8_t field_idx;
15373 };
15374
15375 static void
15376 cmd_cfg_input_set_parsed(
15377         __attribute__((unused)) void *parsed_result,
15378         __attribute__((unused)) struct cmdline *cl,
15379         __attribute__((unused)) void *data)
15380 {
15381 #ifdef RTE_LIBRTE_I40E_PMD
15382         struct cmd_cfg_input_set_result *res = parsed_result;
15383         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15384         struct rte_pmd_i40e_inset inset;
15385 #endif
15386         int ret = -ENOTSUP;
15387
15388         if (!all_ports_stopped()) {
15389                 printf("Please stop all ports first\n");
15390                 return;
15391         }
15392
15393 #ifdef RTE_LIBRTE_I40E_PMD
15394         if (!strcmp(res->inset_type, "hash_inset"))
15395                 inset_type = INSET_HASH;
15396         else if (!strcmp(res->inset_type, "fdir_inset"))
15397                 inset_type = INSET_FDIR;
15398         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15399                 inset_type = INSET_FDIR_FLX;
15400         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15401                                      &inset, inset_type);
15402         if (ret) {
15403                 printf("Failed to get input set.\n");
15404                 return;
15405         }
15406
15407         if (!strcmp(res->opt, "get")) {
15408                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15409                                                    res->field_idx);
15410                 if (ret)
15411                         printf("Field index %d is enabled.\n", res->field_idx);
15412                 else
15413                         printf("Field index %d is disabled.\n", res->field_idx);
15414                 return;
15415         } else if (!strcmp(res->opt, "set"))
15416                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15417                                                    res->field_idx);
15418         else if (!strcmp(res->opt, "clear"))
15419                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15420                                                      res->field_idx);
15421         if (ret) {
15422                 printf("Failed to configure input set field.\n");
15423                 return;
15424         }
15425
15426         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15427                                      &inset, inset_type);
15428         if (ret) {
15429                 printf("Failed to set input set.\n");
15430                 return;
15431         }
15432 #endif
15433
15434         if (ret == -ENOTSUP)
15435                 printf("Function not supported\n");
15436 }
15437
15438 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15439         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15440                                  port, "port");
15441 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15442         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15443                                  cfg, "config");
15444 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15445         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15446                               port_id, UINT16);
15447 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15448         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15449                                  pctype, "pctype");
15450 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15451         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15452                               pctype_id, UINT8);
15453 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15454         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15455                                  inset_type,
15456                                  "hash_inset#fdir_inset#fdir_flx_inset");
15457 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15458         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15459                                  opt, "get#set#clear");
15460 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15461         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15462                                  field, "field");
15463 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15464         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15465                               field_idx, UINT8);
15466
15467 cmdline_parse_inst_t cmd_cfg_input_set = {
15468         .f = cmd_cfg_input_set_parsed,
15469         .data = NULL,
15470         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15471                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15472         .tokens = {
15473                 (void *)&cmd_cfg_input_set_port,
15474                 (void *)&cmd_cfg_input_set_cfg,
15475                 (void *)&cmd_cfg_input_set_port_id,
15476                 (void *)&cmd_cfg_input_set_pctype,
15477                 (void *)&cmd_cfg_input_set_pctype_id,
15478                 (void *)&cmd_cfg_input_set_inset_type,
15479                 (void *)&cmd_cfg_input_set_opt,
15480                 (void *)&cmd_cfg_input_set_field,
15481                 (void *)&cmd_cfg_input_set_field_idx,
15482                 NULL,
15483         },
15484 };
15485
15486 /* Clear input set */
15487 struct cmd_clear_input_set_result {
15488         cmdline_fixed_string_t port;
15489         cmdline_fixed_string_t cfg;
15490         portid_t port_id;
15491         cmdline_fixed_string_t pctype;
15492         uint8_t pctype_id;
15493         cmdline_fixed_string_t inset_type;
15494         cmdline_fixed_string_t clear;
15495         cmdline_fixed_string_t all;
15496 };
15497
15498 static void
15499 cmd_clear_input_set_parsed(
15500         __attribute__((unused)) void *parsed_result,
15501         __attribute__((unused)) struct cmdline *cl,
15502         __attribute__((unused)) void *data)
15503 {
15504 #ifdef RTE_LIBRTE_I40E_PMD
15505         struct cmd_clear_input_set_result *res = parsed_result;
15506         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15507         struct rte_pmd_i40e_inset inset;
15508 #endif
15509         int ret = -ENOTSUP;
15510
15511         if (!all_ports_stopped()) {
15512                 printf("Please stop all ports first\n");
15513                 return;
15514         }
15515
15516 #ifdef RTE_LIBRTE_I40E_PMD
15517         if (!strcmp(res->inset_type, "hash_inset"))
15518                 inset_type = INSET_HASH;
15519         else if (!strcmp(res->inset_type, "fdir_inset"))
15520                 inset_type = INSET_FDIR;
15521         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15522                 inset_type = INSET_FDIR_FLX;
15523
15524         memset(&inset, 0, sizeof(inset));
15525
15526         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15527                                      &inset, inset_type);
15528         if (ret) {
15529                 printf("Failed to clear input set.\n");
15530                 return;
15531         }
15532
15533 #endif
15534
15535         if (ret == -ENOTSUP)
15536                 printf("Function not supported\n");
15537 }
15538
15539 cmdline_parse_token_string_t cmd_clear_input_set_port =
15540         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15541                                  port, "port");
15542 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15543         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15544                                  cfg, "config");
15545 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15546         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15547                               port_id, UINT16);
15548 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15549         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15550                                  pctype, "pctype");
15551 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15552         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15553                               pctype_id, UINT8);
15554 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15555         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15556                                  inset_type,
15557                                  "hash_inset#fdir_inset#fdir_flx_inset");
15558 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15559         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15560                                  clear, "clear");
15561 cmdline_parse_token_string_t cmd_clear_input_set_all =
15562         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15563                                  all, "all");
15564
15565 cmdline_parse_inst_t cmd_clear_input_set = {
15566         .f = cmd_clear_input_set_parsed,
15567         .data = NULL,
15568         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15569                     "fdir_inset|fdir_flx_inset clear all",
15570         .tokens = {
15571                 (void *)&cmd_clear_input_set_port,
15572                 (void *)&cmd_clear_input_set_cfg,
15573                 (void *)&cmd_clear_input_set_port_id,
15574                 (void *)&cmd_clear_input_set_pctype,
15575                 (void *)&cmd_clear_input_set_pctype_id,
15576                 (void *)&cmd_clear_input_set_inset_type,
15577                 (void *)&cmd_clear_input_set_clear,
15578                 (void *)&cmd_clear_input_set_all,
15579                 NULL,
15580         },
15581 };
15582
15583 /* show vf stats */
15584
15585 /* Common result structure for show vf stats */
15586 struct cmd_show_vf_stats_result {
15587         cmdline_fixed_string_t show;
15588         cmdline_fixed_string_t vf;
15589         cmdline_fixed_string_t stats;
15590         portid_t port_id;
15591         uint16_t vf_id;
15592 };
15593
15594 /* Common CLI fields show vf stats*/
15595 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15596         TOKEN_STRING_INITIALIZER
15597                 (struct cmd_show_vf_stats_result,
15598                  show, "show");
15599 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15600         TOKEN_STRING_INITIALIZER
15601                 (struct cmd_show_vf_stats_result,
15602                  vf, "vf");
15603 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15604         TOKEN_STRING_INITIALIZER
15605                 (struct cmd_show_vf_stats_result,
15606                  stats, "stats");
15607 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15608         TOKEN_NUM_INITIALIZER
15609                 (struct cmd_show_vf_stats_result,
15610                  port_id, UINT16);
15611 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15612         TOKEN_NUM_INITIALIZER
15613                 (struct cmd_show_vf_stats_result,
15614                  vf_id, UINT16);
15615
15616 static void
15617 cmd_show_vf_stats_parsed(
15618         void *parsed_result,
15619         __attribute__((unused)) struct cmdline *cl,
15620         __attribute__((unused)) void *data)
15621 {
15622         struct cmd_show_vf_stats_result *res = parsed_result;
15623         struct rte_eth_stats stats;
15624         int ret = -ENOTSUP;
15625         static const char *nic_stats_border = "########################";
15626
15627         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15628                 return;
15629
15630         memset(&stats, 0, sizeof(stats));
15631
15632 #ifdef RTE_LIBRTE_I40E_PMD
15633         if (ret == -ENOTSUP)
15634                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15635                                                 res->vf_id,
15636                                                 &stats);
15637 #endif
15638 #ifdef RTE_LIBRTE_BNXT_PMD
15639         if (ret == -ENOTSUP)
15640                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15641                                                 res->vf_id,
15642                                                 &stats);
15643 #endif
15644
15645         switch (ret) {
15646         case 0:
15647                 break;
15648         case -EINVAL:
15649                 printf("invalid vf_id %d\n", res->vf_id);
15650                 break;
15651         case -ENODEV:
15652                 printf("invalid port_id %d\n", res->port_id);
15653                 break;
15654         case -ENOTSUP:
15655                 printf("function not implemented\n");
15656                 break;
15657         default:
15658                 printf("programming error: (%s)\n", strerror(-ret));
15659         }
15660
15661         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15662                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15663
15664         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15665                "%-"PRIu64"\n",
15666                stats.ipackets, stats.imissed, stats.ibytes);
15667         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15668         printf("  RX-nombuf:  %-10"PRIu64"\n",
15669                stats.rx_nombuf);
15670         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15671                "%-"PRIu64"\n",
15672                stats.opackets, stats.oerrors, stats.obytes);
15673
15674         printf("  %s############################%s\n",
15675                                nic_stats_border, nic_stats_border);
15676 }
15677
15678 cmdline_parse_inst_t cmd_show_vf_stats = {
15679         .f = cmd_show_vf_stats_parsed,
15680         .data = NULL,
15681         .help_str = "show vf stats <port_id> <vf_id>",
15682         .tokens = {
15683                 (void *)&cmd_show_vf_stats_show,
15684                 (void *)&cmd_show_vf_stats_vf,
15685                 (void *)&cmd_show_vf_stats_stats,
15686                 (void *)&cmd_show_vf_stats_port_id,
15687                 (void *)&cmd_show_vf_stats_vf_id,
15688                 NULL,
15689         },
15690 };
15691
15692 /* clear vf stats */
15693
15694 /* Common result structure for clear vf stats */
15695 struct cmd_clear_vf_stats_result {
15696         cmdline_fixed_string_t clear;
15697         cmdline_fixed_string_t vf;
15698         cmdline_fixed_string_t stats;
15699         portid_t port_id;
15700         uint16_t vf_id;
15701 };
15702
15703 /* Common CLI fields clear vf stats*/
15704 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15705         TOKEN_STRING_INITIALIZER
15706                 (struct cmd_clear_vf_stats_result,
15707                  clear, "clear");
15708 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15709         TOKEN_STRING_INITIALIZER
15710                 (struct cmd_clear_vf_stats_result,
15711                  vf, "vf");
15712 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15713         TOKEN_STRING_INITIALIZER
15714                 (struct cmd_clear_vf_stats_result,
15715                  stats, "stats");
15716 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15717         TOKEN_NUM_INITIALIZER
15718                 (struct cmd_clear_vf_stats_result,
15719                  port_id, UINT16);
15720 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15721         TOKEN_NUM_INITIALIZER
15722                 (struct cmd_clear_vf_stats_result,
15723                  vf_id, UINT16);
15724
15725 static void
15726 cmd_clear_vf_stats_parsed(
15727         void *parsed_result,
15728         __attribute__((unused)) struct cmdline *cl,
15729         __attribute__((unused)) void *data)
15730 {
15731         struct cmd_clear_vf_stats_result *res = parsed_result;
15732         int ret = -ENOTSUP;
15733
15734         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15735                 return;
15736
15737 #ifdef RTE_LIBRTE_I40E_PMD
15738         if (ret == -ENOTSUP)
15739                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15740                                                   res->vf_id);
15741 #endif
15742 #ifdef RTE_LIBRTE_BNXT_PMD
15743         if (ret == -ENOTSUP)
15744                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15745                                                   res->vf_id);
15746 #endif
15747
15748         switch (ret) {
15749         case 0:
15750                 break;
15751         case -EINVAL:
15752                 printf("invalid vf_id %d\n", res->vf_id);
15753                 break;
15754         case -ENODEV:
15755                 printf("invalid port_id %d\n", res->port_id);
15756                 break;
15757         case -ENOTSUP:
15758                 printf("function not implemented\n");
15759                 break;
15760         default:
15761                 printf("programming error: (%s)\n", strerror(-ret));
15762         }
15763 }
15764
15765 cmdline_parse_inst_t cmd_clear_vf_stats = {
15766         .f = cmd_clear_vf_stats_parsed,
15767         .data = NULL,
15768         .help_str = "clear vf stats <port_id> <vf_id>",
15769         .tokens = {
15770                 (void *)&cmd_clear_vf_stats_clear,
15771                 (void *)&cmd_clear_vf_stats_vf,
15772                 (void *)&cmd_clear_vf_stats_stats,
15773                 (void *)&cmd_clear_vf_stats_port_id,
15774                 (void *)&cmd_clear_vf_stats_vf_id,
15775                 NULL,
15776         },
15777 };
15778
15779 /* port config pctype mapping reset */
15780
15781 /* Common result structure for port config pctype mapping reset */
15782 struct cmd_pctype_mapping_reset_result {
15783         cmdline_fixed_string_t port;
15784         cmdline_fixed_string_t config;
15785         portid_t port_id;
15786         cmdline_fixed_string_t pctype;
15787         cmdline_fixed_string_t mapping;
15788         cmdline_fixed_string_t reset;
15789 };
15790
15791 /* Common CLI fields for port config pctype mapping reset*/
15792 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15793         TOKEN_STRING_INITIALIZER
15794                 (struct cmd_pctype_mapping_reset_result,
15795                  port, "port");
15796 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15797         TOKEN_STRING_INITIALIZER
15798                 (struct cmd_pctype_mapping_reset_result,
15799                  config, "config");
15800 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15801         TOKEN_NUM_INITIALIZER
15802                 (struct cmd_pctype_mapping_reset_result,
15803                  port_id, UINT16);
15804 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15805         TOKEN_STRING_INITIALIZER
15806                 (struct cmd_pctype_mapping_reset_result,
15807                  pctype, "pctype");
15808 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15809         TOKEN_STRING_INITIALIZER
15810                 (struct cmd_pctype_mapping_reset_result,
15811                  mapping, "mapping");
15812 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15813         TOKEN_STRING_INITIALIZER
15814                 (struct cmd_pctype_mapping_reset_result,
15815                  reset, "reset");
15816
15817 static void
15818 cmd_pctype_mapping_reset_parsed(
15819         void *parsed_result,
15820         __attribute__((unused)) struct cmdline *cl,
15821         __attribute__((unused)) void *data)
15822 {
15823         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15824         int ret = -ENOTSUP;
15825
15826         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15827                 return;
15828
15829 #ifdef RTE_LIBRTE_I40E_PMD
15830         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15831 #endif
15832
15833         switch (ret) {
15834         case 0:
15835                 break;
15836         case -ENODEV:
15837                 printf("invalid port_id %d\n", res->port_id);
15838                 break;
15839         case -ENOTSUP:
15840                 printf("function not implemented\n");
15841                 break;
15842         default:
15843                 printf("programming error: (%s)\n", strerror(-ret));
15844         }
15845 }
15846
15847 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15848         .f = cmd_pctype_mapping_reset_parsed,
15849         .data = NULL,
15850         .help_str = "port config <port_id> pctype mapping reset",
15851         .tokens = {
15852                 (void *)&cmd_pctype_mapping_reset_port,
15853                 (void *)&cmd_pctype_mapping_reset_config,
15854                 (void *)&cmd_pctype_mapping_reset_port_id,
15855                 (void *)&cmd_pctype_mapping_reset_pctype,
15856                 (void *)&cmd_pctype_mapping_reset_mapping,
15857                 (void *)&cmd_pctype_mapping_reset_reset,
15858                 NULL,
15859         },
15860 };
15861
15862 /* show port pctype mapping */
15863
15864 /* Common result structure for show port pctype mapping */
15865 struct cmd_pctype_mapping_get_result {
15866         cmdline_fixed_string_t show;
15867         cmdline_fixed_string_t port;
15868         portid_t port_id;
15869         cmdline_fixed_string_t pctype;
15870         cmdline_fixed_string_t mapping;
15871 };
15872
15873 /* Common CLI fields for pctype mapping get */
15874 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15875         TOKEN_STRING_INITIALIZER
15876                 (struct cmd_pctype_mapping_get_result,
15877                  show, "show");
15878 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15879         TOKEN_STRING_INITIALIZER
15880                 (struct cmd_pctype_mapping_get_result,
15881                  port, "port");
15882 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15883         TOKEN_NUM_INITIALIZER
15884                 (struct cmd_pctype_mapping_get_result,
15885                  port_id, UINT16);
15886 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15887         TOKEN_STRING_INITIALIZER
15888                 (struct cmd_pctype_mapping_get_result,
15889                  pctype, "pctype");
15890 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15891         TOKEN_STRING_INITIALIZER
15892                 (struct cmd_pctype_mapping_get_result,
15893                  mapping, "mapping");
15894
15895 static void
15896 cmd_pctype_mapping_get_parsed(
15897         void *parsed_result,
15898         __attribute__((unused)) struct cmdline *cl,
15899         __attribute__((unused)) void *data)
15900 {
15901         struct cmd_pctype_mapping_get_result *res = parsed_result;
15902         int ret = -ENOTSUP;
15903 #ifdef RTE_LIBRTE_I40E_PMD
15904         struct rte_pmd_i40e_flow_type_mapping
15905                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15906         int i, j, first_pctype;
15907 #endif
15908
15909         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15910                 return;
15911
15912 #ifdef RTE_LIBRTE_I40E_PMD
15913         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15914 #endif
15915
15916         switch (ret) {
15917         case 0:
15918                 break;
15919         case -ENODEV:
15920                 printf("invalid port_id %d\n", res->port_id);
15921                 return;
15922         case -ENOTSUP:
15923                 printf("function not implemented\n");
15924                 return;
15925         default:
15926                 printf("programming error: (%s)\n", strerror(-ret));
15927                 return;
15928         }
15929
15930 #ifdef RTE_LIBRTE_I40E_PMD
15931         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15932                 if (mapping[i].pctype != 0ULL) {
15933                         first_pctype = 1;
15934
15935                         printf("pctype: ");
15936                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15937                                 if (mapping[i].pctype & (1ULL << j)) {
15938                                         printf(first_pctype ?
15939                                                "%02d" : ",%02d", j);
15940                                         first_pctype = 0;
15941                                 }
15942                         }
15943                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15944                 }
15945         }
15946 #endif
15947 }
15948
15949 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15950         .f = cmd_pctype_mapping_get_parsed,
15951         .data = NULL,
15952         .help_str = "show port <port_id> pctype mapping",
15953         .tokens = {
15954                 (void *)&cmd_pctype_mapping_get_show,
15955                 (void *)&cmd_pctype_mapping_get_port,
15956                 (void *)&cmd_pctype_mapping_get_port_id,
15957                 (void *)&cmd_pctype_mapping_get_pctype,
15958                 (void *)&cmd_pctype_mapping_get_mapping,
15959                 NULL,
15960         },
15961 };
15962
15963 /* port config pctype mapping update */
15964
15965 /* Common result structure for port config pctype mapping update */
15966 struct cmd_pctype_mapping_update_result {
15967         cmdline_fixed_string_t port;
15968         cmdline_fixed_string_t config;
15969         portid_t port_id;
15970         cmdline_fixed_string_t pctype;
15971         cmdline_fixed_string_t mapping;
15972         cmdline_fixed_string_t update;
15973         cmdline_fixed_string_t pctype_list;
15974         uint16_t flow_type;
15975 };
15976
15977 /* Common CLI fields for pctype mapping update*/
15978 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15979         TOKEN_STRING_INITIALIZER
15980                 (struct cmd_pctype_mapping_update_result,
15981                  port, "port");
15982 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15983         TOKEN_STRING_INITIALIZER
15984                 (struct cmd_pctype_mapping_update_result,
15985                  config, "config");
15986 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15987         TOKEN_NUM_INITIALIZER
15988                 (struct cmd_pctype_mapping_update_result,
15989                  port_id, UINT16);
15990 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15991         TOKEN_STRING_INITIALIZER
15992                 (struct cmd_pctype_mapping_update_result,
15993                  pctype, "pctype");
15994 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15995         TOKEN_STRING_INITIALIZER
15996                 (struct cmd_pctype_mapping_update_result,
15997                  mapping, "mapping");
15998 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15999         TOKEN_STRING_INITIALIZER
16000                 (struct cmd_pctype_mapping_update_result,
16001                  update, "update");
16002 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
16003         TOKEN_STRING_INITIALIZER
16004                 (struct cmd_pctype_mapping_update_result,
16005                  pctype_list, NULL);
16006 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
16007         TOKEN_NUM_INITIALIZER
16008                 (struct cmd_pctype_mapping_update_result,
16009                  flow_type, UINT16);
16010
16011 static void
16012 cmd_pctype_mapping_update_parsed(
16013         void *parsed_result,
16014         __attribute__((unused)) struct cmdline *cl,
16015         __attribute__((unused)) void *data)
16016 {
16017         struct cmd_pctype_mapping_update_result *res = parsed_result;
16018         int ret = -ENOTSUP;
16019 #ifdef RTE_LIBRTE_I40E_PMD
16020         struct rte_pmd_i40e_flow_type_mapping mapping;
16021         unsigned int i;
16022         unsigned int nb_item;
16023         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16024 #endif
16025
16026         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16027                 return;
16028
16029 #ifdef RTE_LIBRTE_I40E_PMD
16030         nb_item = parse_item_list(res->pctype_list, "pctypes",
16031                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16032         mapping.flow_type = res->flow_type;
16033         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16034                 mapping.pctype |= (1ULL << pctype_list[i]);
16035         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16036                                                 &mapping,
16037                                                 1,
16038                                                 0);
16039 #endif
16040
16041         switch (ret) {
16042         case 0:
16043                 break;
16044         case -EINVAL:
16045                 printf("invalid pctype or flow type\n");
16046                 break;
16047         case -ENODEV:
16048                 printf("invalid port_id %d\n", res->port_id);
16049                 break;
16050         case -ENOTSUP:
16051                 printf("function not implemented\n");
16052                 break;
16053         default:
16054                 printf("programming error: (%s)\n", strerror(-ret));
16055         }
16056 }
16057
16058 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16059         .f = cmd_pctype_mapping_update_parsed,
16060         .data = NULL,
16061         .help_str = "port config <port_id> pctype mapping update"
16062         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16063         .tokens = {
16064                 (void *)&cmd_pctype_mapping_update_port,
16065                 (void *)&cmd_pctype_mapping_update_config,
16066                 (void *)&cmd_pctype_mapping_update_port_id,
16067                 (void *)&cmd_pctype_mapping_update_pctype,
16068                 (void *)&cmd_pctype_mapping_update_mapping,
16069                 (void *)&cmd_pctype_mapping_update_update,
16070                 (void *)&cmd_pctype_mapping_update_pc_type,
16071                 (void *)&cmd_pctype_mapping_update_flow_type,
16072                 NULL,
16073         },
16074 };
16075
16076 /* ptype mapping get */
16077
16078 /* Common result structure for ptype mapping get */
16079 struct cmd_ptype_mapping_get_result {
16080         cmdline_fixed_string_t ptype;
16081         cmdline_fixed_string_t mapping;
16082         cmdline_fixed_string_t get;
16083         portid_t port_id;
16084         uint8_t valid_only;
16085 };
16086
16087 /* Common CLI fields for ptype mapping get */
16088 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16089         TOKEN_STRING_INITIALIZER
16090                 (struct cmd_ptype_mapping_get_result,
16091                  ptype, "ptype");
16092 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16093         TOKEN_STRING_INITIALIZER
16094                 (struct cmd_ptype_mapping_get_result,
16095                  mapping, "mapping");
16096 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16097         TOKEN_STRING_INITIALIZER
16098                 (struct cmd_ptype_mapping_get_result,
16099                  get, "get");
16100 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16101         TOKEN_NUM_INITIALIZER
16102                 (struct cmd_ptype_mapping_get_result,
16103                  port_id, UINT16);
16104 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16105         TOKEN_NUM_INITIALIZER
16106                 (struct cmd_ptype_mapping_get_result,
16107                  valid_only, UINT8);
16108
16109 static void
16110 cmd_ptype_mapping_get_parsed(
16111         void *parsed_result,
16112         __attribute__((unused)) struct cmdline *cl,
16113         __attribute__((unused)) void *data)
16114 {
16115         struct cmd_ptype_mapping_get_result *res = parsed_result;
16116         int ret = -ENOTSUP;
16117 #ifdef RTE_LIBRTE_I40E_PMD
16118         int max_ptype_num = 256;
16119         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16120         uint16_t count;
16121         int i;
16122 #endif
16123
16124         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16125                 return;
16126
16127 #ifdef RTE_LIBRTE_I40E_PMD
16128         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16129                                         mapping,
16130                                         max_ptype_num,
16131                                         &count,
16132                                         res->valid_only);
16133 #endif
16134
16135         switch (ret) {
16136         case 0:
16137                 break;
16138         case -ENODEV:
16139                 printf("invalid port_id %d\n", res->port_id);
16140                 break;
16141         case -ENOTSUP:
16142                 printf("function not implemented\n");
16143                 break;
16144         default:
16145                 printf("programming error: (%s)\n", strerror(-ret));
16146         }
16147
16148 #ifdef RTE_LIBRTE_I40E_PMD
16149         if (!ret) {
16150                 for (i = 0; i < count; i++)
16151                         printf("%3d\t0x%08x\n",
16152                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16153         }
16154 #endif
16155 }
16156
16157 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16158         .f = cmd_ptype_mapping_get_parsed,
16159         .data = NULL,
16160         .help_str = "ptype mapping get <port_id> <valid_only>",
16161         .tokens = {
16162                 (void *)&cmd_ptype_mapping_get_ptype,
16163                 (void *)&cmd_ptype_mapping_get_mapping,
16164                 (void *)&cmd_ptype_mapping_get_get,
16165                 (void *)&cmd_ptype_mapping_get_port_id,
16166                 (void *)&cmd_ptype_mapping_get_valid_only,
16167                 NULL,
16168         },
16169 };
16170
16171 /* ptype mapping replace */
16172
16173 /* Common result structure for ptype mapping replace */
16174 struct cmd_ptype_mapping_replace_result {
16175         cmdline_fixed_string_t ptype;
16176         cmdline_fixed_string_t mapping;
16177         cmdline_fixed_string_t replace;
16178         portid_t port_id;
16179         uint32_t target;
16180         uint8_t mask;
16181         uint32_t pkt_type;
16182 };
16183
16184 /* Common CLI fields for ptype mapping replace */
16185 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16186         TOKEN_STRING_INITIALIZER
16187                 (struct cmd_ptype_mapping_replace_result,
16188                  ptype, "ptype");
16189 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16190         TOKEN_STRING_INITIALIZER
16191                 (struct cmd_ptype_mapping_replace_result,
16192                  mapping, "mapping");
16193 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16194         TOKEN_STRING_INITIALIZER
16195                 (struct cmd_ptype_mapping_replace_result,
16196                  replace, "replace");
16197 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16198         TOKEN_NUM_INITIALIZER
16199                 (struct cmd_ptype_mapping_replace_result,
16200                  port_id, UINT16);
16201 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16202         TOKEN_NUM_INITIALIZER
16203                 (struct cmd_ptype_mapping_replace_result,
16204                  target, UINT32);
16205 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16206         TOKEN_NUM_INITIALIZER
16207                 (struct cmd_ptype_mapping_replace_result,
16208                  mask, UINT8);
16209 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16210         TOKEN_NUM_INITIALIZER
16211                 (struct cmd_ptype_mapping_replace_result,
16212                  pkt_type, UINT32);
16213
16214 static void
16215 cmd_ptype_mapping_replace_parsed(
16216         void *parsed_result,
16217         __attribute__((unused)) struct cmdline *cl,
16218         __attribute__((unused)) void *data)
16219 {
16220         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16221         int ret = -ENOTSUP;
16222
16223         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16224                 return;
16225
16226 #ifdef RTE_LIBRTE_I40E_PMD
16227         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16228                                         res->target,
16229                                         res->mask,
16230                                         res->pkt_type);
16231 #endif
16232
16233         switch (ret) {
16234         case 0:
16235                 break;
16236         case -EINVAL:
16237                 printf("invalid ptype 0x%8x or 0x%8x\n",
16238                                 res->target, res->pkt_type);
16239                 break;
16240         case -ENODEV:
16241                 printf("invalid port_id %d\n", res->port_id);
16242                 break;
16243         case -ENOTSUP:
16244                 printf("function not implemented\n");
16245                 break;
16246         default:
16247                 printf("programming error: (%s)\n", strerror(-ret));
16248         }
16249 }
16250
16251 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16252         .f = cmd_ptype_mapping_replace_parsed,
16253         .data = NULL,
16254         .help_str =
16255                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16256         .tokens = {
16257                 (void *)&cmd_ptype_mapping_replace_ptype,
16258                 (void *)&cmd_ptype_mapping_replace_mapping,
16259                 (void *)&cmd_ptype_mapping_replace_replace,
16260                 (void *)&cmd_ptype_mapping_replace_port_id,
16261                 (void *)&cmd_ptype_mapping_replace_target,
16262                 (void *)&cmd_ptype_mapping_replace_mask,
16263                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16264                 NULL,
16265         },
16266 };
16267
16268 /* ptype mapping reset */
16269
16270 /* Common result structure for ptype mapping reset */
16271 struct cmd_ptype_mapping_reset_result {
16272         cmdline_fixed_string_t ptype;
16273         cmdline_fixed_string_t mapping;
16274         cmdline_fixed_string_t reset;
16275         portid_t port_id;
16276 };
16277
16278 /* Common CLI fields for ptype mapping reset*/
16279 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16280         TOKEN_STRING_INITIALIZER
16281                 (struct cmd_ptype_mapping_reset_result,
16282                  ptype, "ptype");
16283 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16284         TOKEN_STRING_INITIALIZER
16285                 (struct cmd_ptype_mapping_reset_result,
16286                  mapping, "mapping");
16287 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16288         TOKEN_STRING_INITIALIZER
16289                 (struct cmd_ptype_mapping_reset_result,
16290                  reset, "reset");
16291 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16292         TOKEN_NUM_INITIALIZER
16293                 (struct cmd_ptype_mapping_reset_result,
16294                  port_id, UINT16);
16295
16296 static void
16297 cmd_ptype_mapping_reset_parsed(
16298         void *parsed_result,
16299         __attribute__((unused)) struct cmdline *cl,
16300         __attribute__((unused)) void *data)
16301 {
16302         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16303         int ret = -ENOTSUP;
16304
16305         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16306                 return;
16307
16308 #ifdef RTE_LIBRTE_I40E_PMD
16309         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16310 #endif
16311
16312         switch (ret) {
16313         case 0:
16314                 break;
16315         case -ENODEV:
16316                 printf("invalid port_id %d\n", res->port_id);
16317                 break;
16318         case -ENOTSUP:
16319                 printf("function not implemented\n");
16320                 break;
16321         default:
16322                 printf("programming error: (%s)\n", strerror(-ret));
16323         }
16324 }
16325
16326 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16327         .f = cmd_ptype_mapping_reset_parsed,
16328         .data = NULL,
16329         .help_str = "ptype mapping reset <port_id>",
16330         .tokens = {
16331                 (void *)&cmd_ptype_mapping_reset_ptype,
16332                 (void *)&cmd_ptype_mapping_reset_mapping,
16333                 (void *)&cmd_ptype_mapping_reset_reset,
16334                 (void *)&cmd_ptype_mapping_reset_port_id,
16335                 NULL,
16336         },
16337 };
16338
16339 /* ptype mapping update */
16340
16341 /* Common result structure for ptype mapping update */
16342 struct cmd_ptype_mapping_update_result {
16343         cmdline_fixed_string_t ptype;
16344         cmdline_fixed_string_t mapping;
16345         cmdline_fixed_string_t reset;
16346         portid_t port_id;
16347         uint8_t hw_ptype;
16348         uint32_t sw_ptype;
16349 };
16350
16351 /* Common CLI fields for ptype mapping update*/
16352 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16353         TOKEN_STRING_INITIALIZER
16354                 (struct cmd_ptype_mapping_update_result,
16355                  ptype, "ptype");
16356 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16357         TOKEN_STRING_INITIALIZER
16358                 (struct cmd_ptype_mapping_update_result,
16359                  mapping, "mapping");
16360 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16361         TOKEN_STRING_INITIALIZER
16362                 (struct cmd_ptype_mapping_update_result,
16363                  reset, "update");
16364 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16365         TOKEN_NUM_INITIALIZER
16366                 (struct cmd_ptype_mapping_update_result,
16367                  port_id, UINT16);
16368 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16369         TOKEN_NUM_INITIALIZER
16370                 (struct cmd_ptype_mapping_update_result,
16371                  hw_ptype, UINT8);
16372 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16373         TOKEN_NUM_INITIALIZER
16374                 (struct cmd_ptype_mapping_update_result,
16375                  sw_ptype, UINT32);
16376
16377 static void
16378 cmd_ptype_mapping_update_parsed(
16379         void *parsed_result,
16380         __attribute__((unused)) struct cmdline *cl,
16381         __attribute__((unused)) void *data)
16382 {
16383         struct cmd_ptype_mapping_update_result *res = parsed_result;
16384         int ret = -ENOTSUP;
16385 #ifdef RTE_LIBRTE_I40E_PMD
16386         struct rte_pmd_i40e_ptype_mapping mapping;
16387 #endif
16388         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16389                 return;
16390
16391 #ifdef RTE_LIBRTE_I40E_PMD
16392         mapping.hw_ptype = res->hw_ptype;
16393         mapping.sw_ptype = res->sw_ptype;
16394         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16395                                                 &mapping,
16396                                                 1,
16397                                                 0);
16398 #endif
16399
16400         switch (ret) {
16401         case 0:
16402                 break;
16403         case -EINVAL:
16404                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16405                 break;
16406         case -ENODEV:
16407                 printf("invalid port_id %d\n", res->port_id);
16408                 break;
16409         case -ENOTSUP:
16410                 printf("function not implemented\n");
16411                 break;
16412         default:
16413                 printf("programming error: (%s)\n", strerror(-ret));
16414         }
16415 }
16416
16417 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16418         .f = cmd_ptype_mapping_update_parsed,
16419         .data = NULL,
16420         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16421         .tokens = {
16422                 (void *)&cmd_ptype_mapping_update_ptype,
16423                 (void *)&cmd_ptype_mapping_update_mapping,
16424                 (void *)&cmd_ptype_mapping_update_update,
16425                 (void *)&cmd_ptype_mapping_update_port_id,
16426                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16427                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16428                 NULL,
16429         },
16430 };
16431
16432 /* Common result structure for file commands */
16433 struct cmd_cmdfile_result {
16434         cmdline_fixed_string_t load;
16435         cmdline_fixed_string_t filename;
16436 };
16437
16438 /* Common CLI fields for file commands */
16439 cmdline_parse_token_string_t cmd_load_cmdfile =
16440         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16441 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16442         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16443
16444 static void
16445 cmd_load_from_file_parsed(
16446         void *parsed_result,
16447         __attribute__((unused)) struct cmdline *cl,
16448         __attribute__((unused)) void *data)
16449 {
16450         struct cmd_cmdfile_result *res = parsed_result;
16451
16452         cmdline_read_from_file(res->filename);
16453 }
16454
16455 cmdline_parse_inst_t cmd_load_from_file = {
16456         .f = cmd_load_from_file_parsed,
16457         .data = NULL,
16458         .help_str = "load <filename>",
16459         .tokens = {
16460                 (void *)&cmd_load_cmdfile,
16461                 (void *)&cmd_load_cmdfile_filename,
16462                 NULL,
16463         },
16464 };
16465
16466 /* Get Rx offloads capabilities */
16467 struct cmd_rx_offload_get_capa_result {
16468         cmdline_fixed_string_t show;
16469         cmdline_fixed_string_t port;
16470         portid_t port_id;
16471         cmdline_fixed_string_t rx_offload;
16472         cmdline_fixed_string_t capabilities;
16473 };
16474
16475 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16476         TOKEN_STRING_INITIALIZER
16477                 (struct cmd_rx_offload_get_capa_result,
16478                  show, "show");
16479 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16480         TOKEN_STRING_INITIALIZER
16481                 (struct cmd_rx_offload_get_capa_result,
16482                  port, "port");
16483 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16484         TOKEN_NUM_INITIALIZER
16485                 (struct cmd_rx_offload_get_capa_result,
16486                  port_id, UINT16);
16487 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16488         TOKEN_STRING_INITIALIZER
16489                 (struct cmd_rx_offload_get_capa_result,
16490                  rx_offload, "rx_offload");
16491 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16492         TOKEN_STRING_INITIALIZER
16493                 (struct cmd_rx_offload_get_capa_result,
16494                  capabilities, "capabilities");
16495
16496 static void
16497 print_rx_offloads(uint64_t offloads)
16498 {
16499         uint64_t single_offload;
16500         int begin;
16501         int end;
16502         int bit;
16503
16504         if (offloads == 0)
16505                 return;
16506
16507         begin = __builtin_ctzll(offloads);
16508         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16509
16510         single_offload = 1 << begin;
16511         for (bit = begin; bit < end; bit++) {
16512                 if (offloads & single_offload)
16513                         printf(" %s",
16514                                rte_eth_dev_rx_offload_name(single_offload));
16515                 single_offload <<= 1;
16516         }
16517 }
16518
16519 static void
16520 cmd_rx_offload_get_capa_parsed(
16521         void *parsed_result,
16522         __attribute__((unused)) struct cmdline *cl,
16523         __attribute__((unused)) void *data)
16524 {
16525         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16526         struct rte_eth_dev_info dev_info;
16527         portid_t port_id = res->port_id;
16528         uint64_t queue_offloads;
16529         uint64_t port_offloads;
16530
16531         rte_eth_dev_info_get(port_id, &dev_info);
16532         queue_offloads = dev_info.rx_queue_offload_capa;
16533         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16534
16535         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16536         printf("  Per Queue :");
16537         print_rx_offloads(queue_offloads);
16538
16539         printf("\n");
16540         printf("  Per Port  :");
16541         print_rx_offloads(port_offloads);
16542         printf("\n\n");
16543 }
16544
16545 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16546         .f = cmd_rx_offload_get_capa_parsed,
16547         .data = NULL,
16548         .help_str = "show port <port_id> rx_offload capabilities",
16549         .tokens = {
16550                 (void *)&cmd_rx_offload_get_capa_show,
16551                 (void *)&cmd_rx_offload_get_capa_port,
16552                 (void *)&cmd_rx_offload_get_capa_port_id,
16553                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16554                 (void *)&cmd_rx_offload_get_capa_capabilities,
16555                 NULL,
16556         }
16557 };
16558
16559 /* Get Rx offloads configuration */
16560 struct cmd_rx_offload_get_configuration_result {
16561         cmdline_fixed_string_t show;
16562         cmdline_fixed_string_t port;
16563         portid_t port_id;
16564         cmdline_fixed_string_t rx_offload;
16565         cmdline_fixed_string_t configuration;
16566 };
16567
16568 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16569         TOKEN_STRING_INITIALIZER
16570                 (struct cmd_rx_offload_get_configuration_result,
16571                  show, "show");
16572 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16573         TOKEN_STRING_INITIALIZER
16574                 (struct cmd_rx_offload_get_configuration_result,
16575                  port, "port");
16576 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16577         TOKEN_NUM_INITIALIZER
16578                 (struct cmd_rx_offload_get_configuration_result,
16579                  port_id, UINT16);
16580 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16581         TOKEN_STRING_INITIALIZER
16582                 (struct cmd_rx_offload_get_configuration_result,
16583                  rx_offload, "rx_offload");
16584 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16585         TOKEN_STRING_INITIALIZER
16586                 (struct cmd_rx_offload_get_configuration_result,
16587                  configuration, "configuration");
16588
16589 static void
16590 cmd_rx_offload_get_configuration_parsed(
16591         void *parsed_result,
16592         __attribute__((unused)) struct cmdline *cl,
16593         __attribute__((unused)) void *data)
16594 {
16595         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16596         struct rte_eth_dev_info dev_info;
16597         portid_t port_id = res->port_id;
16598         struct rte_port *port = &ports[port_id];
16599         uint64_t port_offloads;
16600         uint64_t queue_offloads;
16601         uint16_t nb_rx_queues;
16602         int q;
16603
16604         printf("Rx Offloading Configuration of port %d :\n", port_id);
16605
16606         port_offloads = port->dev_conf.rxmode.offloads;
16607         printf("  Port :");
16608         print_rx_offloads(port_offloads);
16609         printf("\n");
16610
16611         rte_eth_dev_info_get(port_id, &dev_info);
16612         nb_rx_queues = dev_info.nb_rx_queues;
16613         for (q = 0; q < nb_rx_queues; q++) {
16614                 queue_offloads = port->rx_conf[q].offloads;
16615                 printf("  Queue[%2d] :", q);
16616                 print_rx_offloads(queue_offloads);
16617                 printf("\n");
16618         }
16619         printf("\n");
16620 }
16621
16622 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16623         .f = cmd_rx_offload_get_configuration_parsed,
16624         .data = NULL,
16625         .help_str = "show port <port_id> rx_offload configuration",
16626         .tokens = {
16627                 (void *)&cmd_rx_offload_get_configuration_show,
16628                 (void *)&cmd_rx_offload_get_configuration_port,
16629                 (void *)&cmd_rx_offload_get_configuration_port_id,
16630                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16631                 (void *)&cmd_rx_offload_get_configuration_configuration,
16632                 NULL,
16633         }
16634 };
16635
16636 /* Enable/Disable a per port offloading */
16637 struct cmd_config_per_port_rx_offload_result {
16638         cmdline_fixed_string_t port;
16639         cmdline_fixed_string_t config;
16640         portid_t port_id;
16641         cmdline_fixed_string_t rx_offload;
16642         cmdline_fixed_string_t offload;
16643         cmdline_fixed_string_t on_off;
16644 };
16645
16646 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16647         TOKEN_STRING_INITIALIZER
16648                 (struct cmd_config_per_port_rx_offload_result,
16649                  port, "port");
16650 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16651         TOKEN_STRING_INITIALIZER
16652                 (struct cmd_config_per_port_rx_offload_result,
16653                  config, "config");
16654 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16655         TOKEN_NUM_INITIALIZER
16656                 (struct cmd_config_per_port_rx_offload_result,
16657                  port_id, UINT16);
16658 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16659         TOKEN_STRING_INITIALIZER
16660                 (struct cmd_config_per_port_rx_offload_result,
16661                  rx_offload, "rx_offload");
16662 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16663         TOKEN_STRING_INITIALIZER
16664                 (struct cmd_config_per_port_rx_offload_result,
16665                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16666                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16667                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16668                            "crc_strip#scatter#timestamp#security");
16669 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16670         TOKEN_STRING_INITIALIZER
16671                 (struct cmd_config_per_port_rx_offload_result,
16672                  on_off, "on#off");
16673
16674 static uint64_t
16675 search_rx_offload(const char *name)
16676 {
16677         uint64_t single_offload;
16678         const char *single_name;
16679         int found = 0;
16680         unsigned int bit;
16681
16682         single_offload = 1;
16683         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16684                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16685                 if (!strcasecmp(single_name, name)) {
16686                         found = 1;
16687                         break;
16688                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16689                         break;
16690                 else if (single_name == NULL)
16691                         break;
16692                 single_offload <<= 1;
16693         }
16694
16695         if (found)
16696                 return single_offload;
16697
16698         return 0;
16699 }
16700
16701 static void
16702 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16703                                 __attribute__((unused)) struct cmdline *cl,
16704                                 __attribute__((unused)) void *data)
16705 {
16706         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16707         portid_t port_id = res->port_id;
16708         struct rte_eth_dev_info dev_info;
16709         struct rte_port *port = &ports[port_id];
16710         uint64_t single_offload;
16711         uint16_t nb_rx_queues;
16712         int q;
16713
16714         if (port->port_status != RTE_PORT_STOPPED) {
16715                 printf("Error: Can't config offload when Port %d "
16716                        "is not stopped\n", port_id);
16717                 return;
16718         }
16719
16720         single_offload = search_rx_offload(res->offload);
16721         if (single_offload == 0) {
16722                 printf("Unknown offload name: %s\n", res->offload);
16723                 return;
16724         }
16725
16726         rte_eth_dev_info_get(port_id, &dev_info);
16727         nb_rx_queues = dev_info.nb_rx_queues;
16728         if (!strcmp(res->on_off, "on")) {
16729                 port->dev_conf.rxmode.offloads |= single_offload;
16730                 for (q = 0; q < nb_rx_queues; q++)
16731                         port->rx_conf[q].offloads |= single_offload;
16732         } else {
16733                 port->dev_conf.rxmode.offloads &= ~single_offload;
16734                 for (q = 0; q < nb_rx_queues; q++)
16735                         port->rx_conf[q].offloads &= ~single_offload;
16736         }
16737
16738         cmd_reconfig_device_queue(port_id, 1, 1);
16739 }
16740
16741 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16742         .f = cmd_config_per_port_rx_offload_parsed,
16743         .data = NULL,
16744         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16745                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16746                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16747                     "jumbo_frame|crc_strip|scatter|timestamp|security "
16748                     "on|off",
16749         .tokens = {
16750                 (void *)&cmd_config_per_port_rx_offload_result_port,
16751                 (void *)&cmd_config_per_port_rx_offload_result_config,
16752                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16753                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16754                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16755                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16756                 NULL,
16757         }
16758 };
16759
16760 /* Enable/Disable a per queue offloading */
16761 struct cmd_config_per_queue_rx_offload_result {
16762         cmdline_fixed_string_t port;
16763         portid_t port_id;
16764         cmdline_fixed_string_t rxq;
16765         uint16_t queue_id;
16766         cmdline_fixed_string_t rx_offload;
16767         cmdline_fixed_string_t offload;
16768         cmdline_fixed_string_t on_off;
16769 };
16770
16771 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16772         TOKEN_STRING_INITIALIZER
16773                 (struct cmd_config_per_queue_rx_offload_result,
16774                  port, "port");
16775 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16776         TOKEN_NUM_INITIALIZER
16777                 (struct cmd_config_per_queue_rx_offload_result,
16778                  port_id, UINT16);
16779 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16780         TOKEN_STRING_INITIALIZER
16781                 (struct cmd_config_per_queue_rx_offload_result,
16782                  rxq, "rxq");
16783 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16784         TOKEN_NUM_INITIALIZER
16785                 (struct cmd_config_per_queue_rx_offload_result,
16786                  queue_id, UINT16);
16787 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16788         TOKEN_STRING_INITIALIZER
16789                 (struct cmd_config_per_queue_rx_offload_result,
16790                  rx_offload, "rx_offload");
16791 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16792         TOKEN_STRING_INITIALIZER
16793                 (struct cmd_config_per_queue_rx_offload_result,
16794                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16795                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16796                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16797                            "crc_strip#scatter#timestamp#security");
16798 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16799         TOKEN_STRING_INITIALIZER
16800                 (struct cmd_config_per_queue_rx_offload_result,
16801                  on_off, "on#off");
16802
16803 static void
16804 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16805                                 __attribute__((unused)) struct cmdline *cl,
16806                                 __attribute__((unused)) void *data)
16807 {
16808         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16809         struct rte_eth_dev_info dev_info;
16810         portid_t port_id = res->port_id;
16811         uint16_t queue_id = res->queue_id;
16812         struct rte_port *port = &ports[port_id];
16813         uint64_t single_offload;
16814
16815         if (port->port_status != RTE_PORT_STOPPED) {
16816                 printf("Error: Can't config offload when Port %d "
16817                        "is not stopped\n", port_id);
16818                 return;
16819         }
16820
16821         rte_eth_dev_info_get(port_id, &dev_info);
16822         if (queue_id >= dev_info.nb_rx_queues) {
16823                 printf("Error: input queue_id should be 0 ... "
16824                        "%d\n", dev_info.nb_rx_queues - 1);
16825                 return;
16826         }
16827
16828         single_offload = search_rx_offload(res->offload);
16829         if (single_offload == 0) {
16830                 printf("Unknown offload name: %s\n", res->offload);
16831                 return;
16832         }
16833
16834         if (!strcmp(res->on_off, "on"))
16835                 port->rx_conf[queue_id].offloads |= single_offload;
16836         else
16837                 port->rx_conf[queue_id].offloads &= ~single_offload;
16838
16839         cmd_reconfig_device_queue(port_id, 1, 1);
16840 }
16841
16842 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16843         .f = cmd_config_per_queue_rx_offload_parsed,
16844         .data = NULL,
16845         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16846                     "vlan_strip|ipv4_cksum|"
16847                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16848                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16849                     "jumbo_frame|crc_strip|scatter|timestamp|security "
16850                     "on|off",
16851         .tokens = {
16852                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16853                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16854                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16855                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16856                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16857                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16858                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16859                 NULL,
16860         }
16861 };
16862
16863 /* Get Tx offloads capabilities */
16864 struct cmd_tx_offload_get_capa_result {
16865         cmdline_fixed_string_t show;
16866         cmdline_fixed_string_t port;
16867         portid_t port_id;
16868         cmdline_fixed_string_t tx_offload;
16869         cmdline_fixed_string_t capabilities;
16870 };
16871
16872 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16873         TOKEN_STRING_INITIALIZER
16874                 (struct cmd_tx_offload_get_capa_result,
16875                  show, "show");
16876 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16877         TOKEN_STRING_INITIALIZER
16878                 (struct cmd_tx_offload_get_capa_result,
16879                  port, "port");
16880 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16881         TOKEN_NUM_INITIALIZER
16882                 (struct cmd_tx_offload_get_capa_result,
16883                  port_id, UINT16);
16884 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16885         TOKEN_STRING_INITIALIZER
16886                 (struct cmd_tx_offload_get_capa_result,
16887                  tx_offload, "tx_offload");
16888 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16889         TOKEN_STRING_INITIALIZER
16890                 (struct cmd_tx_offload_get_capa_result,
16891                  capabilities, "capabilities");
16892
16893 static void
16894 print_tx_offloads(uint64_t offloads)
16895 {
16896         uint64_t single_offload;
16897         int begin;
16898         int end;
16899         int bit;
16900
16901         if (offloads == 0)
16902                 return;
16903
16904         begin = __builtin_ctzll(offloads);
16905         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16906
16907         single_offload = 1 << begin;
16908         for (bit = begin; bit < end; bit++) {
16909                 if (offloads & single_offload)
16910                         printf(" %s",
16911                                rte_eth_dev_tx_offload_name(single_offload));
16912                 single_offload <<= 1;
16913         }
16914 }
16915
16916 static void
16917 cmd_tx_offload_get_capa_parsed(
16918         void *parsed_result,
16919         __attribute__((unused)) struct cmdline *cl,
16920         __attribute__((unused)) void *data)
16921 {
16922         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16923         struct rte_eth_dev_info dev_info;
16924         portid_t port_id = res->port_id;
16925         uint64_t queue_offloads;
16926         uint64_t port_offloads;
16927
16928         rte_eth_dev_info_get(port_id, &dev_info);
16929         queue_offloads = dev_info.tx_queue_offload_capa;
16930         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16931
16932         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16933         printf("  Per Queue :");
16934         print_tx_offloads(queue_offloads);
16935
16936         printf("\n");
16937         printf("  Per Port  :");
16938         print_tx_offloads(port_offloads);
16939         printf("\n\n");
16940 }
16941
16942 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16943         .f = cmd_tx_offload_get_capa_parsed,
16944         .data = NULL,
16945         .help_str = "show port <port_id> tx_offload capabilities",
16946         .tokens = {
16947                 (void *)&cmd_tx_offload_get_capa_show,
16948                 (void *)&cmd_tx_offload_get_capa_port,
16949                 (void *)&cmd_tx_offload_get_capa_port_id,
16950                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16951                 (void *)&cmd_tx_offload_get_capa_capabilities,
16952                 NULL,
16953         }
16954 };
16955
16956 /* Get Tx offloads configuration */
16957 struct cmd_tx_offload_get_configuration_result {
16958         cmdline_fixed_string_t show;
16959         cmdline_fixed_string_t port;
16960         portid_t port_id;
16961         cmdline_fixed_string_t tx_offload;
16962         cmdline_fixed_string_t configuration;
16963 };
16964
16965 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16966         TOKEN_STRING_INITIALIZER
16967                 (struct cmd_tx_offload_get_configuration_result,
16968                  show, "show");
16969 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16970         TOKEN_STRING_INITIALIZER
16971                 (struct cmd_tx_offload_get_configuration_result,
16972                  port, "port");
16973 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16974         TOKEN_NUM_INITIALIZER
16975                 (struct cmd_tx_offload_get_configuration_result,
16976                  port_id, UINT16);
16977 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16978         TOKEN_STRING_INITIALIZER
16979                 (struct cmd_tx_offload_get_configuration_result,
16980                  tx_offload, "tx_offload");
16981 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16982         TOKEN_STRING_INITIALIZER
16983                 (struct cmd_tx_offload_get_configuration_result,
16984                  configuration, "configuration");
16985
16986 static void
16987 cmd_tx_offload_get_configuration_parsed(
16988         void *parsed_result,
16989         __attribute__((unused)) struct cmdline *cl,
16990         __attribute__((unused)) void *data)
16991 {
16992         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16993         struct rte_eth_dev_info dev_info;
16994         portid_t port_id = res->port_id;
16995         struct rte_port *port = &ports[port_id];
16996         uint64_t port_offloads;
16997         uint64_t queue_offloads;
16998         uint16_t nb_tx_queues;
16999         int q;
17000
17001         printf("Tx Offloading Configuration of port %d :\n", port_id);
17002
17003         port_offloads = port->dev_conf.txmode.offloads;
17004         printf("  Port :");
17005         print_tx_offloads(port_offloads);
17006         printf("\n");
17007
17008         rte_eth_dev_info_get(port_id, &dev_info);
17009         nb_tx_queues = dev_info.nb_tx_queues;
17010         for (q = 0; q < nb_tx_queues; q++) {
17011                 queue_offloads = port->tx_conf[q].offloads;
17012                 printf("  Queue[%2d] :", q);
17013                 print_tx_offloads(queue_offloads);
17014                 printf("\n");
17015         }
17016         printf("\n");
17017 }
17018
17019 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17020         .f = cmd_tx_offload_get_configuration_parsed,
17021         .data = NULL,
17022         .help_str = "show port <port_id> tx_offload configuration",
17023         .tokens = {
17024                 (void *)&cmd_tx_offload_get_configuration_show,
17025                 (void *)&cmd_tx_offload_get_configuration_port,
17026                 (void *)&cmd_tx_offload_get_configuration_port_id,
17027                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17028                 (void *)&cmd_tx_offload_get_configuration_configuration,
17029                 NULL,
17030         }
17031 };
17032
17033 /* Enable/Disable a per port offloading */
17034 struct cmd_config_per_port_tx_offload_result {
17035         cmdline_fixed_string_t port;
17036         cmdline_fixed_string_t config;
17037         portid_t port_id;
17038         cmdline_fixed_string_t tx_offload;
17039         cmdline_fixed_string_t offload;
17040         cmdline_fixed_string_t on_off;
17041 };
17042
17043 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17044         TOKEN_STRING_INITIALIZER
17045                 (struct cmd_config_per_port_tx_offload_result,
17046                  port, "port");
17047 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17048         TOKEN_STRING_INITIALIZER
17049                 (struct cmd_config_per_port_tx_offload_result,
17050                  config, "config");
17051 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17052         TOKEN_NUM_INITIALIZER
17053                 (struct cmd_config_per_port_tx_offload_result,
17054                  port_id, UINT16);
17055 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17056         TOKEN_STRING_INITIALIZER
17057                 (struct cmd_config_per_port_tx_offload_result,
17058                  tx_offload, "tx_offload");
17059 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17060         TOKEN_STRING_INITIALIZER
17061                 (struct cmd_config_per_port_tx_offload_result,
17062                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17063                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17064                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17065                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17066                           "mt_lockfree#multi_segs#fast_free#security");
17067 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17068         TOKEN_STRING_INITIALIZER
17069                 (struct cmd_config_per_port_tx_offload_result,
17070                  on_off, "on#off");
17071
17072 static uint64_t
17073 search_tx_offload(const char *name)
17074 {
17075         uint64_t single_offload;
17076         const char *single_name;
17077         int found = 0;
17078         unsigned int bit;
17079
17080         single_offload = 1;
17081         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17082                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17083                 if (!strcasecmp(single_name, name)) {
17084                         found = 1;
17085                         break;
17086                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17087                         break;
17088                 else if (single_name == NULL)
17089                         break;
17090                 single_offload <<= 1;
17091         }
17092
17093         if (found)
17094                 return single_offload;
17095
17096         return 0;
17097 }
17098
17099 static void
17100 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17101                                 __attribute__((unused)) struct cmdline *cl,
17102                                 __attribute__((unused)) void *data)
17103 {
17104         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17105         portid_t port_id = res->port_id;
17106         struct rte_eth_dev_info dev_info;
17107         struct rte_port *port = &ports[port_id];
17108         uint64_t single_offload;
17109         uint16_t nb_tx_queues;
17110         int q;
17111
17112         if (port->port_status != RTE_PORT_STOPPED) {
17113                 printf("Error: Can't config offload when Port %d "
17114                        "is not stopped\n", port_id);
17115                 return;
17116         }
17117
17118         single_offload = search_tx_offload(res->offload);
17119         if (single_offload == 0) {
17120                 printf("Unknown offload name: %s\n", res->offload);
17121                 return;
17122         }
17123
17124         rte_eth_dev_info_get(port_id, &dev_info);
17125         nb_tx_queues = dev_info.nb_tx_queues;
17126         if (!strcmp(res->on_off, "on")) {
17127                 port->dev_conf.txmode.offloads |= single_offload;
17128                 for (q = 0; q < nb_tx_queues; q++)
17129                         port->tx_conf[q].offloads |= single_offload;
17130         } else {
17131                 port->dev_conf.txmode.offloads &= ~single_offload;
17132                 for (q = 0; q < nb_tx_queues; q++)
17133                         port->tx_conf[q].offloads &= ~single_offload;
17134         }
17135
17136         cmd_reconfig_device_queue(port_id, 1, 1);
17137 }
17138
17139 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17140         .f = cmd_config_per_port_tx_offload_parsed,
17141         .data = NULL,
17142         .help_str = "port config <port_id> tx_offload "
17143                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17144                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17145                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17146                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17147                     "mt_lockfree|multi_segs|fast_free|security "
17148                     "on|off",
17149         .tokens = {
17150                 (void *)&cmd_config_per_port_tx_offload_result_port,
17151                 (void *)&cmd_config_per_port_tx_offload_result_config,
17152                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17153                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17154                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17155                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17156                 NULL,
17157         }
17158 };
17159
17160 /* Enable/Disable a per queue offloading */
17161 struct cmd_config_per_queue_tx_offload_result {
17162         cmdline_fixed_string_t port;
17163         portid_t port_id;
17164         cmdline_fixed_string_t txq;
17165         uint16_t queue_id;
17166         cmdline_fixed_string_t tx_offload;
17167         cmdline_fixed_string_t offload;
17168         cmdline_fixed_string_t on_off;
17169 };
17170
17171 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17172         TOKEN_STRING_INITIALIZER
17173                 (struct cmd_config_per_queue_tx_offload_result,
17174                  port, "port");
17175 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17176         TOKEN_NUM_INITIALIZER
17177                 (struct cmd_config_per_queue_tx_offload_result,
17178                  port_id, UINT16);
17179 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17180         TOKEN_STRING_INITIALIZER
17181                 (struct cmd_config_per_queue_tx_offload_result,
17182                  txq, "txq");
17183 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17184         TOKEN_NUM_INITIALIZER
17185                 (struct cmd_config_per_queue_tx_offload_result,
17186                  queue_id, UINT16);
17187 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17188         TOKEN_STRING_INITIALIZER
17189                 (struct cmd_config_per_queue_tx_offload_result,
17190                  tx_offload, "tx_offload");
17191 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17192         TOKEN_STRING_INITIALIZER
17193                 (struct cmd_config_per_queue_tx_offload_result,
17194                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17195                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17196                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17197                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17198                           "mt_lockfree#multi_segs#fast_free#security");
17199 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17200         TOKEN_STRING_INITIALIZER
17201                 (struct cmd_config_per_queue_tx_offload_result,
17202                  on_off, "on#off");
17203
17204 static void
17205 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17206                                 __attribute__((unused)) struct cmdline *cl,
17207                                 __attribute__((unused)) void *data)
17208 {
17209         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17210         struct rte_eth_dev_info dev_info;
17211         portid_t port_id = res->port_id;
17212         uint16_t queue_id = res->queue_id;
17213         struct rte_port *port = &ports[port_id];
17214         uint64_t single_offload;
17215
17216         if (port->port_status != RTE_PORT_STOPPED) {
17217                 printf("Error: Can't config offload when Port %d "
17218                        "is not stopped\n", port_id);
17219                 return;
17220         }
17221
17222         rte_eth_dev_info_get(port_id, &dev_info);
17223         if (queue_id >= dev_info.nb_tx_queues) {
17224                 printf("Error: input queue_id should be 0 ... "
17225                        "%d\n", dev_info.nb_tx_queues - 1);
17226                 return;
17227         }
17228
17229         single_offload = search_tx_offload(res->offload);
17230         if (single_offload == 0) {
17231                 printf("Unknown offload name: %s\n", res->offload);
17232                 return;
17233         }
17234
17235         if (!strcmp(res->on_off, "on"))
17236                 port->tx_conf[queue_id].offloads |= single_offload;
17237         else
17238                 port->tx_conf[queue_id].offloads &= ~single_offload;
17239
17240         cmd_reconfig_device_queue(port_id, 1, 1);
17241 }
17242
17243 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17244         .f = cmd_config_per_queue_tx_offload_parsed,
17245         .data = NULL,
17246         .help_str = "port <port_id> txq <queue_id> tx_offload "
17247                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17248                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17249                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17250                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17251                     "mt_lockfree|multi_segs|fast_free|security "
17252                     "on|off",
17253         .tokens = {
17254                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17255                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17256                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17257                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17258                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17259                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17260                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17261                 NULL,
17262         }
17263 };
17264
17265 /* ******************************************************************************** */
17266
17267 /* list of instructions */
17268 cmdline_parse_ctx_t main_ctx[] = {
17269         (cmdline_parse_inst_t *)&cmd_help_brief,
17270         (cmdline_parse_inst_t *)&cmd_help_long,
17271         (cmdline_parse_inst_t *)&cmd_quit,
17272         (cmdline_parse_inst_t *)&cmd_load_from_file,
17273         (cmdline_parse_inst_t *)&cmd_showport,
17274         (cmdline_parse_inst_t *)&cmd_showqueue,
17275         (cmdline_parse_inst_t *)&cmd_showportall,
17276         (cmdline_parse_inst_t *)&cmd_showcfg,
17277         (cmdline_parse_inst_t *)&cmd_start,
17278         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17279         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17280         (cmdline_parse_inst_t *)&cmd_set_link_up,
17281         (cmdline_parse_inst_t *)&cmd_set_link_down,
17282         (cmdline_parse_inst_t *)&cmd_reset,
17283         (cmdline_parse_inst_t *)&cmd_set_numbers,
17284         (cmdline_parse_inst_t *)&cmd_set_log,
17285         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17286         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17287         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17288         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17289         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17290         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17291         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17292         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17293         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17294         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17295         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17296         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17297         (cmdline_parse_inst_t *)&cmd_set_link_check,
17298         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17299         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17300         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17301         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17302 #ifdef RTE_LIBRTE_PMD_BOND
17303         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17304         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17305         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17306         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17307         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17308         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17309         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17310         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17311         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17312         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17313         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17314 #endif
17315         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17316         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17317         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17318         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17319         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17320         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17321         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17322         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17323         (cmdline_parse_inst_t *)&cmd_csum_set,
17324         (cmdline_parse_inst_t *)&cmd_csum_show,
17325         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17326         (cmdline_parse_inst_t *)&cmd_tso_set,
17327         (cmdline_parse_inst_t *)&cmd_tso_show,
17328         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17329         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17330         (cmdline_parse_inst_t *)&cmd_gro_enable,
17331         (cmdline_parse_inst_t *)&cmd_gro_flush,
17332         (cmdline_parse_inst_t *)&cmd_gro_show,
17333         (cmdline_parse_inst_t *)&cmd_gso_enable,
17334         (cmdline_parse_inst_t *)&cmd_gso_size,
17335         (cmdline_parse_inst_t *)&cmd_gso_show,
17336         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17337         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17338         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17339         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17340         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17341         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17342         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17343         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17344         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17345         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17346         (cmdline_parse_inst_t *)&cmd_config_dcb,
17347         (cmdline_parse_inst_t *)&cmd_read_reg,
17348         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17349         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17350         (cmdline_parse_inst_t *)&cmd_write_reg,
17351         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17352         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17353         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17354         (cmdline_parse_inst_t *)&cmd_stop,
17355         (cmdline_parse_inst_t *)&cmd_mac_addr,
17356         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17357         (cmdline_parse_inst_t *)&cmd_set_qmap,
17358         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17359         (cmdline_parse_inst_t *)&cmd_operate_port,
17360         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17361         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17362         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17363         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17364         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17365         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17366         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17367         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17368         (cmdline_parse_inst_t *)&cmd_config_mtu,
17369         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17370         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17371         (cmdline_parse_inst_t *)&cmd_config_rss,
17372         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17373         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17374         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17375         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17376         (cmdline_parse_inst_t *)&cmd_showport_reta,
17377         (cmdline_parse_inst_t *)&cmd_config_burst,
17378         (cmdline_parse_inst_t *)&cmd_config_thresh,
17379         (cmdline_parse_inst_t *)&cmd_config_threshold,
17380         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17381         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17382         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17383         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
17384         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17385         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
17386         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17387         (cmdline_parse_inst_t *)&cmd_global_config,
17388         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17389         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17390         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17391         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17392         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17393         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17394         (cmdline_parse_inst_t *)&cmd_dump,
17395         (cmdline_parse_inst_t *)&cmd_dump_one,
17396         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
17397         (cmdline_parse_inst_t *)&cmd_syn_filter,
17398         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
17399         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
17400         (cmdline_parse_inst_t *)&cmd_flex_filter,
17401         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
17402         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
17403         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
17404         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
17405         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
17406         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
17407         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17408         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
17409         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17410         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17411         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17412         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
17413         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17414         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
17415         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
17416         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
17417         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
17418         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
17419         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
17420         (cmdline_parse_inst_t *)&cmd_flow,
17421         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17422         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17423         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17424         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17425         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17426         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17427         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17428         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17429         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17430         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17431         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17432         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17433         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17434         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17435         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
17436         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
17437         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
17438         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
17439         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
17440         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
17441         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
17442         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
17443         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
17444         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
17445         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17446         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17447         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17448         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17449         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17450         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17451         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17452         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17453         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17454         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17455         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17456         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17457         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17458         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17459         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17460         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17461         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17462         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17463         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17464         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17465         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17466         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17467         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17468         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17469         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17470 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
17471         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
17472 #endif
17473         (cmdline_parse_inst_t *)&cmd_ddp_add,
17474         (cmdline_parse_inst_t *)&cmd_ddp_del,
17475         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17476         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17477         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17478         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17479         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17480         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17481         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17482         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17483         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17484         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17485
17486         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17487         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17488         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17489         (cmdline_parse_inst_t *)&cmd_queue_region,
17490         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17491         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17492         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17493         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17494         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17495         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17496         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17497         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17498         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17499         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17500         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17501         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17502         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17503         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17504         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17505         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17506         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17507         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17508         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17509         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17510         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17511         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17512         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17513         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17514         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17515         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17516         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17517         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17518         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17519         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17520         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17521         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17522 #ifdef RTE_LIBRTE_BPF
17523         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17524         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17525 #endif
17526         NULL,
17527 };
17528
17529 /* read cmdline commands from file */
17530 void
17531 cmdline_read_from_file(const char *filename)
17532 {
17533         struct cmdline *cl;
17534
17535         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17536         if (cl == NULL) {
17537                 printf("Failed to create file based cmdline context: %s\n",
17538                        filename);
17539                 return;
17540         }
17541
17542         cmdline_interact(cl);
17543         cmdline_quit(cl);
17544
17545         cmdline_free(cl);
17546
17547         printf("Read CLI commands from %s\n", filename);
17548 }
17549
17550 /* prompt function, called from main on MASTER lcore */
17551 void
17552 prompt(void)
17553 {
17554         int status;
17555
17556         /* initialize non-constant commands */
17557         cmd_set_fwd_mode_init();
17558         cmd_set_fwd_retry_mode_init();
17559
17560 #if defined RTE_LIBRTE_PMD_SOFTNIC
17561         portid_t softnic_portid, pid;
17562         uint8_t softnic_enable = 0;
17563
17564         if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
17565                 RTE_ETH_FOREACH_DEV(pid) {
17566                         struct rte_port *port = &ports[pid];
17567                         const char *driver = port->dev_info.driver_name;
17568
17569                         if (strcmp(driver, "net_softnic") == 0) {
17570                                 softnic_portid = pid;
17571                                 softnic_enable = 1;
17572                                 break;
17573                         }
17574                 }
17575         }
17576 #endif
17577
17578         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17579         if (testpmd_cl == NULL)
17580                 return;
17581
17582         for (;;) {
17583                 status = cmdline_poll(testpmd_cl);
17584                 if (status < 0)
17585                         rte_panic("CLI poll error (%" PRId32 ")\n", status);
17586                 else if (status == RDLINE_EXITED) {
17587                         cmdline_stdin_exit(testpmd_cl);
17588                         rte_exit(0, "\n");
17589                 }
17590
17591 #if defined RTE_LIBRTE_PMD_SOFTNIC
17592
17593         if ((softnic_enable == 1) &&
17594                 (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0))
17595                 rte_pmd_softnic_manage(softnic_portid);
17596 #endif
17597         }
17598 }
17599
17600 void
17601 prompt_exit(void)
17602 {
17603         if (testpmd_cl != NULL)
17604                 cmdline_quit(testpmd_cl);
17605 }
17606
17607 static void
17608 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17609 {
17610         if (id == (portid_t)RTE_PORT_ALL) {
17611                 portid_t pid;
17612
17613                 RTE_ETH_FOREACH_DEV(pid) {
17614                         /* check if need_reconfig has been set to 1 */
17615                         if (ports[pid].need_reconfig == 0)
17616                                 ports[pid].need_reconfig = dev;
17617                         /* check if need_reconfig_queues has been set to 1 */
17618                         if (ports[pid].need_reconfig_queues == 0)
17619                                 ports[pid].need_reconfig_queues = queue;
17620                 }
17621         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17622                 /* check if need_reconfig has been set to 1 */
17623                 if (ports[id].need_reconfig == 0)
17624                         ports[id].need_reconfig = dev;
17625                 /* check if need_reconfig_queues has been set to 1 */
17626                 if (ports[id].need_reconfig_queues == 0)
17627                         ports[id].need_reconfig_queues = queue;
17628         }
17629 }