app/testpmd: support hairpin
[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 #ifdef RTE_EXEC_ENV_FREEBSD
15 #include <sys/socket.h>
16 #endif
17 #include <netinet/in.h>
18
19 #include <sys/queue.h>
20
21 #include <rte_common.h>
22 #include <rte_byteorder.h>
23 #include <rte_log.h>
24 #include <rte_debug.h>
25 #include <rte_cycles.h>
26 #include <rte_memory.h>
27 #include <rte_memzone.h>
28 #include <rte_malloc.h>
29 #include <rte_launch.h>
30 #include <rte_eal.h>
31 #include <rte_per_lcore.h>
32 #include <rte_lcore.h>
33 #include <rte_atomic.h>
34 #include <rte_branch_prediction.h>
35 #include <rte_ring.h>
36 #include <rte_mempool.h>
37 #include <rte_interrupts.h>
38 #include <rte_pci.h>
39 #include <rte_ether.h>
40 #include <rte_ethdev.h>
41 #include <rte_string_fns.h>
42 #include <rte_devargs.h>
43 #include <rte_flow.h>
44 #include <rte_gro.h>
45
46 #include <cmdline_rdline.h>
47 #include <cmdline_parse.h>
48 #include <cmdline_parse_num.h>
49 #include <cmdline_parse_string.h>
50 #include <cmdline_parse_ipaddr.h>
51 #include <cmdline_parse_etheraddr.h>
52 #include <cmdline_socket.h>
53 #include <cmdline.h>
54 #ifdef RTE_LIBRTE_PMD_BOND
55 #include <rte_eth_bond.h>
56 #include <rte_eth_bond_8023ad.h>
57 #endif
58 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
59 #include <rte_pmd_dpaa.h>
60 #endif
61 #ifdef RTE_LIBRTE_IXGBE_PMD
62 #include <rte_pmd_ixgbe.h>
63 #endif
64 #ifdef RTE_LIBRTE_I40E_PMD
65 #include <rte_pmd_i40e.h>
66 #endif
67 #ifdef RTE_LIBRTE_BNXT_PMD
68 #include <rte_pmd_bnxt.h>
69 #endif
70 #include "testpmd.h"
71 #include "cmdline_mtr.h"
72 #include "cmdline_tm.h"
73 #include "bpf_cmd.h"
74
75 static struct cmdline *testpmd_cl;
76
77 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
78
79 /* *** Help command with introduction. *** */
80 struct cmd_help_brief_result {
81         cmdline_fixed_string_t help;
82 };
83
84 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
85                                   struct cmdline *cl,
86                                   __attribute__((unused)) void *data)
87 {
88         cmdline_printf(
89                 cl,
90                 "\n"
91                 "Help is available for the following sections:\n\n"
92                 "    help control                    : Start and stop forwarding.\n"
93                 "    help display                    : Displaying port, stats and config "
94                 "information.\n"
95                 "    help config                     : Configuration information.\n"
96                 "    help ports                      : Configuring ports.\n"
97                 "    help registers                  : Reading and setting port registers.\n"
98                 "    help filters                    : Filters configuration help.\n"
99                 "    help traffic_management         : Traffic Management commmands.\n"
100                 "    help devices                    : Device related cmds.\n"
101                 "    help all                        : All of the above sections.\n\n"
102         );
103
104 }
105
106 cmdline_parse_token_string_t cmd_help_brief_help =
107         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
108
109 cmdline_parse_inst_t cmd_help_brief = {
110         .f = cmd_help_brief_parsed,
111         .data = NULL,
112         .help_str = "help: Show help",
113         .tokens = {
114                 (void *)&cmd_help_brief_help,
115                 NULL,
116         },
117 };
118
119 /* *** Help command with help sections. *** */
120 struct cmd_help_long_result {
121         cmdline_fixed_string_t help;
122         cmdline_fixed_string_t section;
123 };
124
125 static void cmd_help_long_parsed(void *parsed_result,
126                                  struct cmdline *cl,
127                                  __attribute__((unused)) void *data)
128 {
129         int show_all = 0;
130         struct cmd_help_long_result *res = parsed_result;
131
132         if (!strcmp(res->section, "all"))
133                 show_all = 1;
134
135         if (show_all || !strcmp(res->section, "control")) {
136
137                 cmdline_printf(
138                         cl,
139                         "\n"
140                         "Control forwarding:\n"
141                         "-------------------\n\n"
142
143                         "start\n"
144                         "    Start packet forwarding with current configuration.\n\n"
145
146                         "start tx_first\n"
147                         "    Start packet forwarding with current config"
148                         " after sending one burst of packets.\n\n"
149
150                         "stop\n"
151                         "    Stop packet forwarding, and display accumulated"
152                         " statistics.\n\n"
153
154                         "quit\n"
155                         "    Quit to prompt.\n\n"
156                 );
157         }
158
159         if (show_all || !strcmp(res->section, "display")) {
160
161                 cmdline_printf(
162                         cl,
163                         "\n"
164                         "Display:\n"
165                         "--------\n\n"
166
167                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
168                         "    Display information for port_id, or all.\n\n"
169
170                         "show port X rss reta (size) (mask0,mask1,...)\n"
171                         "    Display the rss redirection table entry indicated"
172                         " by masks on port X. size is used to indicate the"
173                         " hardware supported reta size\n\n"
174
175                         "show port (port_id) rss-hash [key]\n"
176                         "    Display the RSS hash functions and RSS hash key of port\n\n"
177
178                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
179                         "    Clear information for port_id, or all.\n\n"
180
181                         "show (rxq|txq) info (port_id) (queue_id)\n"
182                         "    Display information for configured RX/TX queue.\n\n"
183
184                         "show config (rxtx|cores|fwd|txpkts)\n"
185                         "    Display the given configuration.\n\n"
186
187                         "read rxd (port_id) (queue_id) (rxd_id)\n"
188                         "    Display an RX descriptor of a port RX queue.\n\n"
189
190                         "read txd (port_id) (queue_id) (txd_id)\n"
191                         "    Display a TX descriptor of a port TX queue.\n\n"
192
193                         "ddp get list (port_id)\n"
194                         "    Get ddp profile info list\n\n"
195
196                         "ddp get info (profile_path)\n"
197                         "    Get ddp profile information.\n\n"
198
199                         "show vf stats (port_id) (vf_id)\n"
200                         "    Display a VF's statistics.\n\n"
201
202                         "clear vf stats (port_id) (vf_id)\n"
203                         "    Reset a VF's statistics.\n\n"
204
205                         "show port (port_id) pctype mapping\n"
206                         "    Get flow ptype to pctype mapping on a port\n\n"
207
208                         "show port meter stats (port_id) (meter_id) (clear)\n"
209                         "    Get meter stats on a port\n\n"
210
211                         "show fwd stats all\n"
212                         "    Display statistics for all fwd engines.\n\n"
213
214                         "clear fwd stats all\n"
215                         "    Clear statistics for all fwd engines.\n\n"
216
217                         "show port (port_id) rx_offload capabilities\n"
218                         "    List all per queue and per port Rx offloading"
219                         " capabilities of a port\n\n"
220
221                         "show port (port_id) rx_offload configuration\n"
222                         "    List port level and all queue level"
223                         " Rx offloading configuration\n\n"
224
225                         "show port (port_id) tx_offload capabilities\n"
226                         "    List all per queue and per port"
227                         " Tx offloading capabilities of a port\n\n"
228
229                         "show port (port_id) tx_offload configuration\n"
230                         "    List port level and all queue level"
231                         " Tx offloading configuration\n\n"
232
233                         "show port (port_id) tx_metadata\n"
234                         "    Show Tx metadata value set"
235                         " for a specific port\n\n"
236
237                         "show port (port_id) ptypes\n"
238                         "    Show port supported ptypes"
239                         " for a specific port\n\n"
240
241                         "show device info (<identifier>|all)"
242                         "       Show general information about devices probed.\n\n"
243
244                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
245                         "       Show status of rx|tx descriptor.\n\n"
246                 );
247         }
248
249         if (show_all || !strcmp(res->section, "config")) {
250                 cmdline_printf(
251                         cl,
252                         "\n"
253                         "Configuration:\n"
254                         "--------------\n"
255                         "Configuration changes only become active when"
256                         " forwarding is started/restarted.\n\n"
257
258                         "set default\n"
259                         "    Reset forwarding to the default configuration.\n\n"
260
261                         "set verbose (level)\n"
262                         "    Set the debug verbosity level X.\n\n"
263
264                         "set log global|(type) (level)\n"
265                         "    Set the log level.\n\n"
266
267                         "set nbport (num)\n"
268                         "    Set number of ports.\n\n"
269
270                         "set nbcore (num)\n"
271                         "    Set number of cores.\n\n"
272
273                         "set coremask (mask)\n"
274                         "    Set the forwarding cores hexadecimal mask.\n\n"
275
276                         "set portmask (mask)\n"
277                         "    Set the forwarding ports hexadecimal mask.\n\n"
278
279                         "set burst (num)\n"
280                         "    Set number of packets per burst.\n\n"
281
282                         "set burst tx delay (microseconds) retry (num)\n"
283                         "    Set the transmit delay time and number of retries,"
284                         " effective when retry is enabled.\n\n"
285
286                         "set txpkts (x[,y]*)\n"
287                         "    Set the length of each segment of TXONLY"
288                         " and optionally CSUM packets.\n\n"
289
290                         "set txsplit (off|on|rand)\n"
291                         "    Set the split policy for the TX packets."
292                         " Right now only applicable for CSUM and TXONLY"
293                         " modes\n\n"
294
295                         "set corelist (x[,y]*)\n"
296                         "    Set the list of forwarding cores.\n\n"
297
298                         "set portlist (x[,y]*)\n"
299                         "    Set the list of forwarding ports.\n\n"
300
301                         "set port setup on (iterator|event)\n"
302                         "    Select how attached port is retrieved for setup.\n\n"
303
304                         "set tx loopback (port_id) (on|off)\n"
305                         "    Enable or disable tx loopback.\n\n"
306
307                         "set all queues drop (port_id) (on|off)\n"
308                         "    Set drop enable bit for all queues.\n\n"
309
310                         "set vf split drop (port_id) (vf_id) (on|off)\n"
311                         "    Set split drop enable bit for a VF from the PF.\n\n"
312
313                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
314                         "    Set MAC antispoof for a VF from the PF.\n\n"
315
316                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
317                         "    Enable MACsec offload.\n\n"
318
319                         "set macsec offload (port_id) off\n"
320                         "    Disable MACsec offload.\n\n"
321
322                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
323                         "    Configure MACsec secure connection (SC).\n\n"
324
325                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
326                         "    Configure MACsec secure association (SA).\n\n"
327
328                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
329                         "    Set VF broadcast for a VF from the PF.\n\n"
330
331                         "vlan set stripq (on|off) (port_id,queue_id)\n"
332                         "    Set the VLAN strip for a queue on a port.\n\n"
333
334                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
335                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
336
337                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
338                         "    Set VLAN insert for a VF from the PF.\n\n"
339
340                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
341                         "    Set VLAN antispoof for a VF from the PF.\n\n"
342
343                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
344                         "    Set VLAN tag for a VF from the PF.\n\n"
345
346                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
347                         "    Set a VF's max bandwidth(Mbps).\n\n"
348
349                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
350                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
351
352                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
353                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
354
355                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
356                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
357
358                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
359                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
360
361                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
362                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
363
364                         "vlan set (inner|outer) tpid (value) (port_id)\n"
365                         "    Set the VLAN TPID for Packet Filtering on"
366                         " a port\n\n"
367
368                         "rx_vlan add (vlan_id|all) (port_id)\n"
369                         "    Add a vlan_id, or all identifiers, to the set"
370                         " of VLAN identifiers filtered by port_id.\n\n"
371
372                         "rx_vlan rm (vlan_id|all) (port_id)\n"
373                         "    Remove a vlan_id, or all identifiers, from the set"
374                         " of VLAN identifiers filtered by port_id.\n\n"
375
376                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
377                         "    Add a vlan_id, to the set of VLAN identifiers"
378                         "filtered for VF(s) from port_id.\n\n"
379
380                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
381                         "    Remove a vlan_id, to the set of VLAN identifiers"
382                         "filtered for VF(s) from port_id.\n\n"
383
384                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
385                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
386                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
387                         "   add a tunnel filter of a port.\n\n"
388
389                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
390                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
391                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
392                         "   remove a tunnel filter of a port.\n\n"
393
394                         "rx_vxlan_port add (udp_port) (port_id)\n"
395                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
396
397                         "rx_vxlan_port rm (udp_port) (port_id)\n"
398                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
399
400                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
401                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
402                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
403
404                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
405                         "    Set port based TX VLAN insertion.\n\n"
406
407                         "tx_vlan reset (port_id)\n"
408                         "    Disable hardware insertion of a VLAN header in"
409                         " packets sent on a port.\n\n"
410
411                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
412                         "    Select hardware or software calculation of the"
413                         " checksum when transmitting a packet using the"
414                         " csum forward engine.\n"
415                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
416                         "    outer-ip concerns the outer IP layer in"
417                         "    outer-udp concerns the outer UDP layer in"
418                         " case the packet is recognized as a tunnel packet by"
419                         " the forward engine (vxlan, gre and ipip are supported)\n"
420                         "    Please check the NIC datasheet for HW limits.\n\n"
421
422                         "csum parse-tunnel (on|off) (tx_port_id)\n"
423                         "    If disabled, treat tunnel packets as non-tunneled"
424                         " packets (treat inner headers as payload). The port\n"
425                         "    argument is the port used for TX in csum forward"
426                         " engine.\n\n"
427
428                         "csum show (port_id)\n"
429                         "    Display tx checksum offload configuration\n\n"
430
431                         "tso set (segsize) (portid)\n"
432                         "    Enable TCP Segmentation Offload in csum forward"
433                         " engine.\n"
434                         "    Please check the NIC datasheet for HW limits.\n\n"
435
436                         "tso show (portid)"
437                         "    Display the status of TCP Segmentation Offload.\n\n"
438
439                         "set port (port_id) gro on|off\n"
440                         "    Enable or disable Generic Receive Offload in"
441                         " csum forwarding engine.\n\n"
442
443                         "show port (port_id) gro\n"
444                         "    Display GRO configuration.\n\n"
445
446                         "set gro flush (cycles)\n"
447                         "    Set the cycle to flush GROed packets from"
448                         " reassembly tables.\n\n"
449
450                         "set port (port_id) gso (on|off)"
451                         "    Enable or disable Generic Segmentation Offload in"
452                         " csum forwarding engine.\n\n"
453
454                         "set gso segsz (length)\n"
455                         "    Set max packet length for output GSO segments,"
456                         " including packet header and payload.\n\n"
457
458                         "show port (port_id) gso\n"
459                         "    Show GSO configuration.\n\n"
460
461                         "set fwd (%s)\n"
462                         "    Set packet forwarding mode.\n\n"
463
464                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
465                         "    Add a MAC address on port_id.\n\n"
466
467                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Remove a MAC address from port_id.\n\n"
469
470                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
471                         "    Set the default MAC address for port_id.\n\n"
472
473                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
474                         "    Add a MAC address for a VF on the port.\n\n"
475
476                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
477                         "    Set the MAC address for a VF from the PF.\n\n"
478
479                         "set eth-peer (port_id) (peer_addr)\n"
480                         "    set the peer address for certain port.\n\n"
481
482                         "set port (port_id) uta (mac_address|all) (on|off)\n"
483                         "    Add/Remove a or all unicast hash filter(s)"
484                         "from port X.\n\n"
485
486                         "set promisc (port_id|all) (on|off)\n"
487                         "    Set the promiscuous mode on port_id, or all.\n\n"
488
489                         "set allmulti (port_id|all) (on|off)\n"
490                         "    Set the allmulti mode on port_id, or all.\n\n"
491
492                         "set vf promisc (port_id) (vf_id) (on|off)\n"
493                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
494
495                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
496                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
497
498                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
499                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
500                         " (on|off) autoneg (on|off) (port_id)\n"
501                         "set flow_ctrl rx (on|off) (portid)\n"
502                         "set flow_ctrl tx (on|off) (portid)\n"
503                         "set flow_ctrl high_water (high_water) (portid)\n"
504                         "set flow_ctrl low_water (low_water) (portid)\n"
505                         "set flow_ctrl pause_time (pause_time) (portid)\n"
506                         "set flow_ctrl send_xon (send_xon) (portid)\n"
507                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
508                         "set flow_ctrl autoneg (on|off) (port_id)\n"
509                         "    Set the link flow control parameter on a port.\n\n"
510
511                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
512                         " (low_water) (pause_time) (priority) (port_id)\n"
513                         "    Set the priority flow control parameter on a"
514                         " port.\n\n"
515
516                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
517                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
518                         " queue on port.\n"
519                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
520                         " on port 0 to mapping 5.\n\n"
521
522                         "set xstats-hide-zero on|off\n"
523                         "    Set the option to hide the zero values"
524                         " for xstats display.\n"
525
526                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
527                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
528
529                         "set port (port_id) vf (vf_id) (mac_addr)"
530                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
531                         "   Add/Remove unicast or multicast MAC addr filter"
532                         " for a VF.\n\n"
533
534                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
535                         "|MPE) (on|off)\n"
536                         "    AUPE:accepts untagged VLAN;"
537                         "ROPE:accept unicast hash\n\n"
538                         "    BAM:accepts broadcast packets;"
539                         "MPE:accepts all multicast packets\n\n"
540                         "    Enable/Disable a VF receive mode of a port\n\n"
541
542                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
543                         "    Set rate limit for a queue of a port\n\n"
544
545                         "set port (port_id) vf (vf_id) rate (rate_num) "
546                         "queue_mask (queue_mask_value)\n"
547                         "    Set rate limit for queues in VF of a port\n\n"
548
549                         "set port (port_id) mirror-rule (rule_id)"
550                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
551                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
552                         "   Set pool or vlan type mirror rule on a port.\n"
553                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
554                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
555                         " to pool 0.\n\n"
556
557                         "set port (port_id) mirror-rule (rule_id)"
558                         " (uplink-mirror|downlink-mirror) dst-pool"
559                         " (pool_id) (on|off)\n"
560                         "   Set uplink or downlink type mirror rule on a port.\n"
561                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
562                         " 0 on' enable mirror income traffic to pool 0.\n\n"
563
564                         "reset port (port_id) mirror-rule (rule_id)\n"
565                         "   Reset a mirror rule.\n\n"
566
567                         "set flush_rx (on|off)\n"
568                         "   Flush (default) or don't flush RX streams before"
569                         " forwarding. Mainly used with PCAP drivers.\n\n"
570
571                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
572                         "   Set the bypass mode for the lowest port on bypass enabled"
573                         " NIC.\n\n"
574
575                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
576                         "mode (normal|bypass|isolate) (port_id)\n"
577                         "   Set the event required to initiate specified bypass mode for"
578                         " the lowest port on a bypass enabled NIC where:\n"
579                         "       timeout   = enable bypass after watchdog timeout.\n"
580                         "       os_on     = enable bypass when OS/board is powered on.\n"
581                         "       os_off    = enable bypass when OS/board is powered off.\n"
582                         "       power_on  = enable bypass when power supply is turned on.\n"
583                         "       power_off = enable bypass when power supply is turned off."
584                         "\n\n"
585
586                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
587                         "   Set the bypass watchdog timeout to 'n' seconds"
588                         " where 0 = instant.\n\n"
589
590                         "show bypass config (port_id)\n"
591                         "   Show the bypass configuration for a bypass enabled NIC"
592                         " using the lowest port on the NIC.\n\n"
593
594 #ifdef RTE_LIBRTE_PMD_BOND
595                         "create bonded device (mode) (socket)\n"
596                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
597
598                         "add bonding slave (slave_id) (port_id)\n"
599                         "       Add a slave device to a bonded device.\n\n"
600
601                         "remove bonding slave (slave_id) (port_id)\n"
602                         "       Remove a slave device from a bonded device.\n\n"
603
604                         "set bonding mode (value) (port_id)\n"
605                         "       Set the bonding mode on a bonded device.\n\n"
606
607                         "set bonding primary (slave_id) (port_id)\n"
608                         "       Set the primary slave for a bonded device.\n\n"
609
610                         "show bonding config (port_id)\n"
611                         "       Show the bonding config for port_id.\n\n"
612
613                         "set bonding mac_addr (port_id) (address)\n"
614                         "       Set the MAC address of a bonded device.\n\n"
615
616                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
617                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
618
619                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
620                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
621
622                         "set bonding mon_period (port_id) (value)\n"
623                         "       Set the bonding link status monitoring polling period in ms.\n\n"
624
625                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
626                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
627
628 #endif
629                         "set link-up port (port_id)\n"
630                         "       Set link up for a port.\n\n"
631
632                         "set link-down port (port_id)\n"
633                         "       Set link down for a port.\n\n"
634
635                         "E-tag set insertion on port-tag-id (value)"
636                         " port (port_id) vf (vf_id)\n"
637                         "    Enable E-tag insertion for a VF on a port\n\n"
638
639                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
640                         "    Disable E-tag insertion for a VF on a port\n\n"
641
642                         "E-tag set stripping (on|off) port (port_id)\n"
643                         "    Enable/disable E-tag stripping on a port\n\n"
644
645                         "E-tag set forwarding (on|off) port (port_id)\n"
646                         "    Enable/disable E-tag based forwarding"
647                         " on a port\n\n"
648
649                         "E-tag set filter add e-tag-id (value) dst-pool"
650                         " (pool_id) port (port_id)\n"
651                         "    Add an E-tag forwarding filter on a port\n\n"
652
653                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
654                         "    Delete an E-tag forwarding filter on a port\n\n"
655
656                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
657                         "    Load a profile package on a port\n\n"
658
659                         "ddp del (port_id) (backup_profile_path)\n"
660                         "    Delete a profile package from a port\n\n"
661
662                         "ptype mapping get (port_id) (valid_only)\n"
663                         "    Get ptype mapping on a port\n\n"
664
665                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
666                         "    Replace target with the pkt_type in ptype mapping\n\n"
667
668                         "ptype mapping reset (port_id)\n"
669                         "    Reset ptype mapping on a port\n\n"
670
671                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
672                         "    Update a ptype mapping item on a port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "queue_start_index (value) queue_num (value)\n"
676                         "    Set a queue region on a port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "flowtype (value)\n"
680                         "    Set a flowtype region index on a port\n\n"
681
682                         "set port (port_id) queue-region UP (value) region_id (value)\n"
683                         "    Set the mapping of User Priority to "
684                         "queue region on a port\n\n"
685
686                         "set port (port_id) queue-region flush (on|off)\n"
687                         "    flush all queue region related configuration\n\n"
688
689                         "show port meter cap (port_id)\n"
690                         "    Show port meter capability information\n\n"
691
692                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
693                         "    meter profile add - srtcm rfc 2697\n\n"
694
695                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
696                         "    meter profile add - trtcm rfc 2698\n\n"
697
698                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
699                         "    meter profile add - trtcm rfc 4115\n\n"
700
701                         "del port meter profile (port_id) (profile_id)\n"
702                         "    meter profile delete\n\n"
703
704                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
705                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
706                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
707                         "(dscp_tbl_entry63)]\n"
708                         "    meter create\n\n"
709
710                         "enable port meter (port_id) (mtr_id)\n"
711                         "    meter enable\n\n"
712
713                         "disable port meter (port_id) (mtr_id)\n"
714                         "    meter disable\n\n"
715
716                         "del port meter (port_id) (mtr_id)\n"
717                         "    meter delete\n\n"
718
719                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
720                         "    meter update meter profile\n\n"
721
722                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
723                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
724                         "    update meter dscp table entries\n\n"
725
726                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
727                         "(action0) [(action1) (action2)]\n"
728                         "    meter update policer action\n\n"
729
730                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
731                         "    meter update stats\n\n"
732
733                         "show port (port_id) queue-region\n"
734                         "    show all queue region related configuration info\n\n"
735
736                         , list_pkt_forwarding_modes()
737                 );
738         }
739
740         if (show_all || !strcmp(res->section, "ports")) {
741
742                 cmdline_printf(
743                         cl,
744                         "\n"
745                         "Port Operations:\n"
746                         "----------------\n\n"
747
748                         "port start (port_id|all)\n"
749                         "    Start all ports or port_id.\n\n"
750
751                         "port stop (port_id|all)\n"
752                         "    Stop all ports or port_id.\n\n"
753
754                         "port close (port_id|all)\n"
755                         "    Close all ports or port_id.\n\n"
756
757                         "port reset (port_id|all)\n"
758                         "    Reset all ports or port_id.\n\n"
759
760                         "port attach (ident)\n"
761                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
762
763                         "port detach (port_id)\n"
764                         "    Detach physical or virtual dev by port_id\n\n"
765
766                         "port config (port_id|all)"
767                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
768                         " duplex (half|full|auto)\n"
769                         "    Set speed and duplex for all ports or port_id\n\n"
770
771                         "port config (port_id|all) loopback (mode)\n"
772                         "    Set loopback mode for all ports or port_id\n\n"
773
774                         "port config all (rxq|txq|rxd|txd) (value)\n"
775                         "    Set number for rxq/txq/rxd/txd.\n\n"
776
777                         "port config all max-pkt-len (value)\n"
778                         "    Set the max packet length.\n\n"
779
780                         "port config all drop-en (on|off)\n"
781                         "    Enable or disable packet drop on all RX queues of all ports when no "
782                         "receive buffers available.\n\n"
783
784                         "port config all rss (all|default|ip|tcp|udp|sctp|"
785                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
786                         "    Set the RSS mode.\n\n"
787
788                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
789                         "    Set the RSS redirection table.\n\n"
790
791                         "port config (port_id) dcb vt (on|off) (traffic_class)"
792                         " pfc (on|off)\n"
793                         "    Set the DCB mode.\n\n"
794
795                         "port config all burst (value)\n"
796                         "    Set the number of packets per burst.\n\n"
797
798                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
799                         " (value)\n"
800                         "    Set the ring prefetch/host/writeback threshold"
801                         " for tx/rx queue.\n\n"
802
803                         "port config all (txfreet|txrst|rxfreet) (value)\n"
804                         "    Set free threshold for rx/tx, or set"
805                         " tx rs bit threshold.\n\n"
806                         "port config mtu X value\n"
807                         "    Set the MTU of port X to a given value\n\n"
808
809                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
810                         "    Set a rx/tx queue's ring size configuration, the new"
811                         " value will take effect after command that (re-)start the port"
812                         " or command that setup the specific queue\n\n"
813
814                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
815                         "    Start/stop a rx/tx queue of port X. Only take effect"
816                         " when port X is started\n\n"
817
818                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
819                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
820                         " take effect when port X is stopped.\n\n"
821
822                         "port (port_id) (rxq|txq) (queue_id) setup\n"
823                         "    Setup a rx/tx queue of port X.\n\n"
824
825                         "port config (port_id|all) l2-tunnel E-tag ether-type"
826                         " (value)\n"
827                         "    Set the value of E-tag ether-type.\n\n"
828
829                         "port config (port_id|all) l2-tunnel E-tag"
830                         " (enable|disable)\n"
831                         "    Enable/disable the E-tag support.\n\n"
832
833                         "port config (port_id) pctype mapping reset\n"
834                         "    Reset flow type to pctype mapping on a port\n\n"
835
836                         "port config (port_id) pctype mapping update"
837                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
838                         "    Update a flow type to pctype mapping item on a port\n\n"
839
840                         "port config (port_id) pctype (pctype_id) hash_inset|"
841                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
842                         " (field_idx)\n"
843                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
844
845                         "port config (port_id) pctype (pctype_id) hash_inset|"
846                         "fdir_inset|fdir_flx_inset clear all"
847                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
848
849                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
850                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
851
852                         "port config <port_id> rx_offload vlan_strip|"
853                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
854                         "outer_ipv4_cksum|macsec_strip|header_split|"
855                         "vlan_filter|vlan_extend|jumbo_frame|"
856                         "scatter|timestamp|security|keep_crc on|off\n"
857                         "     Enable or disable a per port Rx offloading"
858                         " on all Rx queues of a port\n\n"
859
860                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
861                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
862                         "outer_ipv4_cksum|macsec_strip|header_split|"
863                         "vlan_filter|vlan_extend|jumbo_frame|"
864                         "scatter|timestamp|security|keep_crc on|off\n"
865                         "    Enable or disable a per queue Rx offloading"
866                         " only on a specific Rx queue\n\n"
867
868                         "port config (port_id) tx_offload vlan_insert|"
869                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
870                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
871                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
872                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
873                         "security|match_metadata on|off\n"
874                         "    Enable or disable a per port Tx offloading"
875                         " on all Tx queues of a port\n\n"
876
877                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
878                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
879                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
880                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
881                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
882                         " on|off\n"
883                         "    Enable or disable a per queue Tx offloading"
884                         " only on a specific Tx queue\n\n"
885
886                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
887                         "    Load an eBPF program as a callback"
888                         " for particular RX/TX queue\n\n"
889
890                         "bpf-unload rx|tx (port) (queue)\n"
891                         "    Unload previously loaded eBPF program"
892                         " for particular RX/TX queue\n\n"
893
894                         "port config (port_id) tx_metadata (value)\n"
895                         "    Set Tx metadata value per port. Testpmd will add this value"
896                         " to any Tx packet sent from this port\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|symmetric_toeplitz|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                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1116                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1117                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1118                         "       Configure the VXLAN encapsulation for flows.\n\n"
1119
1120                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1121                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1122                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1123                         " eth-dst (eth-dst)\n"
1124                         "       Configure the VXLAN encapsulation for flows.\n\n"
1125
1126                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1127                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1128                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1129                         " eth-dst (eth-dst)\n"
1130                         "       Configure the VXLAN encapsulation for flows.\n\n"
1131
1132                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1133                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1134                         " (eth-dst)\n"
1135                         "       Configure the NVGRE encapsulation for flows.\n\n"
1136
1137                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1138                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1139                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1140                         "       Configure the NVGRE encapsulation for flows.\n\n"
1141
1142                         "set raw_encap {flow items}\n"
1143                         "       Configure the encapsulation with raw data.\n\n"
1144
1145                         "set raw_decap {flow items}\n"
1146                         "       Configure the decapsulation with raw data.\n\n"
1147
1148                 );
1149         }
1150
1151         if (show_all || !strcmp(res->section, "traffic_management")) {
1152                 cmdline_printf(
1153                         cl,
1154                         "\n"
1155                         "Traffic Management:\n"
1156                         "--------------\n"
1157                         "show port tm cap (port_id)\n"
1158                         "       Display the port TM capability.\n\n"
1159
1160                         "show port tm level cap (port_id) (level_id)\n"
1161                         "       Display the port TM hierarchical level capability.\n\n"
1162
1163                         "show port tm node cap (port_id) (node_id)\n"
1164                         "       Display the port TM node capability.\n\n"
1165
1166                         "show port tm node type (port_id) (node_id)\n"
1167                         "       Display the port TM node type.\n\n"
1168
1169                         "show port tm node stats (port_id) (node_id) (clear)\n"
1170                         "       Display the port TM node stats.\n\n"
1171
1172 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1173                         "set port tm hierarchy default (port_id)\n"
1174                         "       Set default traffic Management hierarchy on a port\n\n"
1175 #endif
1176
1177                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1178                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1179                         " (packet_length_adjust)\n"
1180                         "       Add port tm node private shaper profile.\n\n"
1181
1182                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1183                         "       Delete port tm node private shaper profile.\n\n"
1184
1185                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1186                         " (shaper_profile_id)\n"
1187                         "       Add/update port tm node shared shaper.\n\n"
1188
1189                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1190                         "       Delete port tm node shared shaper.\n\n"
1191
1192                         "set port tm node shaper profile (port_id) (node_id)"
1193                         " (shaper_profile_id)\n"
1194                         "       Set port tm node shaper profile.\n\n"
1195
1196                         "add port tm node wred profile (port_id) (wred_profile_id)"
1197                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1198                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1199                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1200                         "       Add port tm node wred profile.\n\n"
1201
1202                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1203                         "       Delete port tm node wred profile.\n\n"
1204
1205                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1206                         " (priority) (weight) (level_id) (shaper_profile_id)"
1207                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1208                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1209                         "       Add port tm nonleaf node.\n\n"
1210
1211                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1212                         " (priority) (weight) (level_id) (shaper_profile_id)"
1213                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1214                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1215                         "       Add port tm leaf node.\n\n"
1216
1217                         "del port tm node (port_id) (node_id)\n"
1218                         "       Delete port tm node.\n\n"
1219
1220                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1221                         " (priority) (weight)\n"
1222                         "       Set port tm node parent.\n\n"
1223
1224                         "suspend port tm node (port_id) (node_id)"
1225                         "       Suspend tm node.\n\n"
1226
1227                         "resume port tm node (port_id) (node_id)"
1228                         "       Resume tm node.\n\n"
1229
1230                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1231                         "       Commit tm hierarchy.\n\n"
1232
1233                         "set port tm mark ip_ecn (port) (green) (yellow)"
1234                         " (red)\n"
1235                         "    Enables/Disables the traffic management marking"
1236                         " for IP ECN (Explicit Congestion Notification)"
1237                         " packets on a given port\n\n"
1238
1239                         "set port tm mark ip_dscp (port) (green) (yellow)"
1240                         " (red)\n"
1241                         "    Enables/Disables the traffic management marking"
1242                         " on the port for IP dscp packets\n\n"
1243
1244                         "set port tm mark vlan_dei (port) (green) (yellow)"
1245                         " (red)\n"
1246                         "    Enables/Disables the traffic management marking"
1247                         " on the port for VLAN packets with DEI enabled\n\n"
1248                 );
1249         }
1250
1251         if (show_all || !strcmp(res->section, "devices")) {
1252                 cmdline_printf(
1253                         cl,
1254                         "\n"
1255                         "Device Operations:\n"
1256                         "--------------\n"
1257                         "device detach (identifier)\n"
1258                         "       Detach device by identifier.\n\n"
1259                 );
1260         }
1261
1262 }
1263
1264 cmdline_parse_token_string_t cmd_help_long_help =
1265         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1266
1267 cmdline_parse_token_string_t cmd_help_long_section =
1268         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1269                         "all#control#display#config#"
1270                         "ports#registers#filters#traffic_management#devices");
1271
1272 cmdline_parse_inst_t cmd_help_long = {
1273         .f = cmd_help_long_parsed,
1274         .data = NULL,
1275         .help_str = "help all|control|display|config|ports|register|"
1276                 "filters|traffic_management|devices: "
1277                 "Show help",
1278         .tokens = {
1279                 (void *)&cmd_help_long_help,
1280                 (void *)&cmd_help_long_section,
1281                 NULL,
1282         },
1283 };
1284
1285
1286 /* *** start/stop/close all ports *** */
1287 struct cmd_operate_port_result {
1288         cmdline_fixed_string_t keyword;
1289         cmdline_fixed_string_t name;
1290         cmdline_fixed_string_t value;
1291 };
1292
1293 static void cmd_operate_port_parsed(void *parsed_result,
1294                                 __attribute__((unused)) struct cmdline *cl,
1295                                 __attribute__((unused)) void *data)
1296 {
1297         struct cmd_operate_port_result *res = parsed_result;
1298
1299         if (!strcmp(res->name, "start"))
1300                 start_port(RTE_PORT_ALL);
1301         else if (!strcmp(res->name, "stop"))
1302                 stop_port(RTE_PORT_ALL);
1303         else if (!strcmp(res->name, "close"))
1304                 close_port(RTE_PORT_ALL);
1305         else if (!strcmp(res->name, "reset"))
1306                 reset_port(RTE_PORT_ALL);
1307         else
1308                 printf("Unknown parameter\n");
1309 }
1310
1311 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1312         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1313                                                                 "port");
1314 cmdline_parse_token_string_t cmd_operate_port_all_port =
1315         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1316                                                 "start#stop#close#reset");
1317 cmdline_parse_token_string_t cmd_operate_port_all_all =
1318         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1319
1320 cmdline_parse_inst_t cmd_operate_port = {
1321         .f = cmd_operate_port_parsed,
1322         .data = NULL,
1323         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1324         .tokens = {
1325                 (void *)&cmd_operate_port_all_cmd,
1326                 (void *)&cmd_operate_port_all_port,
1327                 (void *)&cmd_operate_port_all_all,
1328                 NULL,
1329         },
1330 };
1331
1332 /* *** start/stop/close specific port *** */
1333 struct cmd_operate_specific_port_result {
1334         cmdline_fixed_string_t keyword;
1335         cmdline_fixed_string_t name;
1336         uint8_t value;
1337 };
1338
1339 static void cmd_operate_specific_port_parsed(void *parsed_result,
1340                         __attribute__((unused)) struct cmdline *cl,
1341                                 __attribute__((unused)) void *data)
1342 {
1343         struct cmd_operate_specific_port_result *res = parsed_result;
1344
1345         if (!strcmp(res->name, "start"))
1346                 start_port(res->value);
1347         else if (!strcmp(res->name, "stop"))
1348                 stop_port(res->value);
1349         else if (!strcmp(res->name, "close"))
1350                 close_port(res->value);
1351         else if (!strcmp(res->name, "reset"))
1352                 reset_port(res->value);
1353         else
1354                 printf("Unknown parameter\n");
1355 }
1356
1357 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1358         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1359                                                         keyword, "port");
1360 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1361         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1362                                                 name, "start#stop#close#reset");
1363 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1364         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1365                                                         value, UINT8);
1366
1367 cmdline_parse_inst_t cmd_operate_specific_port = {
1368         .f = cmd_operate_specific_port_parsed,
1369         .data = NULL,
1370         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1371         .tokens = {
1372                 (void *)&cmd_operate_specific_port_cmd,
1373                 (void *)&cmd_operate_specific_port_port,
1374                 (void *)&cmd_operate_specific_port_id,
1375                 NULL,
1376         },
1377 };
1378
1379 /* *** enable port setup (after attach) via iterator or event *** */
1380 struct cmd_set_port_setup_on_result {
1381         cmdline_fixed_string_t set;
1382         cmdline_fixed_string_t port;
1383         cmdline_fixed_string_t setup;
1384         cmdline_fixed_string_t on;
1385         cmdline_fixed_string_t mode;
1386 };
1387
1388 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1389                                 __attribute__((unused)) struct cmdline *cl,
1390                                 __attribute__((unused)) void *data)
1391 {
1392         struct cmd_set_port_setup_on_result *res = parsed_result;
1393
1394         if (strcmp(res->mode, "event") == 0)
1395                 setup_on_probe_event = true;
1396         else if (strcmp(res->mode, "iterator") == 0)
1397                 setup_on_probe_event = false;
1398         else
1399                 printf("Unknown mode\n");
1400 }
1401
1402 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1403         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1404                         set, "set");
1405 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1406         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1407                         port, "port");
1408 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1409         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1410                         setup, "setup");
1411 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1412         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1413                         on, "on");
1414 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1415         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1416                         mode, "iterator#event");
1417
1418 cmdline_parse_inst_t cmd_set_port_setup_on = {
1419         .f = cmd_set_port_setup_on_parsed,
1420         .data = NULL,
1421         .help_str = "set port setup on iterator|event",
1422         .tokens = {
1423                 (void *)&cmd_set_port_setup_on_set,
1424                 (void *)&cmd_set_port_setup_on_port,
1425                 (void *)&cmd_set_port_setup_on_setup,
1426                 (void *)&cmd_set_port_setup_on_on,
1427                 (void *)&cmd_set_port_setup_on_mode,
1428                 NULL,
1429         },
1430 };
1431
1432 /* *** attach a specified port *** */
1433 struct cmd_operate_attach_port_result {
1434         cmdline_fixed_string_t port;
1435         cmdline_fixed_string_t keyword;
1436         cmdline_fixed_string_t identifier;
1437 };
1438
1439 static void cmd_operate_attach_port_parsed(void *parsed_result,
1440                                 __attribute__((unused)) struct cmdline *cl,
1441                                 __attribute__((unused)) void *data)
1442 {
1443         struct cmd_operate_attach_port_result *res = parsed_result;
1444
1445         if (!strcmp(res->keyword, "attach"))
1446                 attach_port(res->identifier);
1447         else
1448                 printf("Unknown parameter\n");
1449 }
1450
1451 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1452         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1453                         port, "port");
1454 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1455         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1456                         keyword, "attach");
1457 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1458         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1459                         identifier, NULL);
1460
1461 cmdline_parse_inst_t cmd_operate_attach_port = {
1462         .f = cmd_operate_attach_port_parsed,
1463         .data = NULL,
1464         .help_str = "port attach <identifier>: "
1465                 "(identifier: pci address or virtual dev name)",
1466         .tokens = {
1467                 (void *)&cmd_operate_attach_port_port,
1468                 (void *)&cmd_operate_attach_port_keyword,
1469                 (void *)&cmd_operate_attach_port_identifier,
1470                 NULL,
1471         },
1472 };
1473
1474 /* *** detach a specified port *** */
1475 struct cmd_operate_detach_port_result {
1476         cmdline_fixed_string_t port;
1477         cmdline_fixed_string_t keyword;
1478         portid_t port_id;
1479 };
1480
1481 static void cmd_operate_detach_port_parsed(void *parsed_result,
1482                                 __attribute__((unused)) struct cmdline *cl,
1483                                 __attribute__((unused)) void *data)
1484 {
1485         struct cmd_operate_detach_port_result *res = parsed_result;
1486
1487         if (!strcmp(res->keyword, "detach"))
1488                 detach_port_device(res->port_id);
1489         else
1490                 printf("Unknown parameter\n");
1491 }
1492
1493 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1494         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1495                         port, "port");
1496 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1497         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1498                         keyword, "detach");
1499 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1500         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1501                         port_id, UINT16);
1502
1503 cmdline_parse_inst_t cmd_operate_detach_port = {
1504         .f = cmd_operate_detach_port_parsed,
1505         .data = NULL,
1506         .help_str = "port detach <port_id>",
1507         .tokens = {
1508                 (void *)&cmd_operate_detach_port_port,
1509                 (void *)&cmd_operate_detach_port_keyword,
1510                 (void *)&cmd_operate_detach_port_port_id,
1511                 NULL,
1512         },
1513 };
1514
1515 /* *** detach device by identifier *** */
1516 struct cmd_operate_detach_device_result {
1517         cmdline_fixed_string_t device;
1518         cmdline_fixed_string_t keyword;
1519         cmdline_fixed_string_t identifier;
1520 };
1521
1522 static void cmd_operate_detach_device_parsed(void *parsed_result,
1523                                 __attribute__((unused)) struct cmdline *cl,
1524                                 __attribute__((unused)) void *data)
1525 {
1526         struct cmd_operate_detach_device_result *res = parsed_result;
1527
1528         if (!strcmp(res->keyword, "detach"))
1529                 detach_device(res->identifier);
1530         else
1531                 printf("Unknown parameter\n");
1532 }
1533
1534 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1535         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1536                         device, "device");
1537 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1538         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1539                         keyword, "detach");
1540 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1541         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1542                         identifier, NULL);
1543
1544 cmdline_parse_inst_t cmd_operate_detach_device = {
1545         .f = cmd_operate_detach_device_parsed,
1546         .data = NULL,
1547         .help_str = "device detach <identifier>:"
1548                 "(identifier: pci address or virtual dev name)",
1549         .tokens = {
1550                 (void *)&cmd_operate_detach_device_device,
1551                 (void *)&cmd_operate_detach_device_keyword,
1552                 (void *)&cmd_operate_detach_device_identifier,
1553                 NULL,
1554         },
1555 };
1556 /* *** configure speed for all ports *** */
1557 struct cmd_config_speed_all {
1558         cmdline_fixed_string_t port;
1559         cmdline_fixed_string_t keyword;
1560         cmdline_fixed_string_t all;
1561         cmdline_fixed_string_t item1;
1562         cmdline_fixed_string_t item2;
1563         cmdline_fixed_string_t value1;
1564         cmdline_fixed_string_t value2;
1565 };
1566
1567 static int
1568 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1569 {
1570
1571         int duplex;
1572
1573         if (!strcmp(duplexstr, "half")) {
1574                 duplex = ETH_LINK_HALF_DUPLEX;
1575         } else if (!strcmp(duplexstr, "full")) {
1576                 duplex = ETH_LINK_FULL_DUPLEX;
1577         } else if (!strcmp(duplexstr, "auto")) {
1578                 duplex = ETH_LINK_FULL_DUPLEX;
1579         } else {
1580                 printf("Unknown duplex parameter\n");
1581                 return -1;
1582         }
1583
1584         if (!strcmp(speedstr, "10")) {
1585                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1586                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1587         } else if (!strcmp(speedstr, "100")) {
1588                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1589                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1590         } else {
1591                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1592                         printf("Invalid speed/duplex parameters\n");
1593                         return -1;
1594                 }
1595                 if (!strcmp(speedstr, "1000")) {
1596                         *speed = ETH_LINK_SPEED_1G;
1597                 } else if (!strcmp(speedstr, "10000")) {
1598                         *speed = ETH_LINK_SPEED_10G;
1599                 } else if (!strcmp(speedstr, "25000")) {
1600                         *speed = ETH_LINK_SPEED_25G;
1601                 } else if (!strcmp(speedstr, "40000")) {
1602                         *speed = ETH_LINK_SPEED_40G;
1603                 } else if (!strcmp(speedstr, "50000")) {
1604                         *speed = ETH_LINK_SPEED_50G;
1605                 } else if (!strcmp(speedstr, "100000")) {
1606                         *speed = ETH_LINK_SPEED_100G;
1607                 } else if (!strcmp(speedstr, "auto")) {
1608                         *speed = ETH_LINK_SPEED_AUTONEG;
1609                 } else {
1610                         printf("Unknown speed parameter\n");
1611                         return -1;
1612                 }
1613         }
1614
1615         return 0;
1616 }
1617
1618 static void
1619 cmd_config_speed_all_parsed(void *parsed_result,
1620                         __attribute__((unused)) struct cmdline *cl,
1621                         __attribute__((unused)) void *data)
1622 {
1623         struct cmd_config_speed_all *res = parsed_result;
1624         uint32_t link_speed;
1625         portid_t pid;
1626
1627         if (!all_ports_stopped()) {
1628                 printf("Please stop all ports first\n");
1629                 return;
1630         }
1631
1632         if (parse_and_check_speed_duplex(res->value1, res->value2,
1633                         &link_speed) < 0)
1634                 return;
1635
1636         RTE_ETH_FOREACH_DEV(pid) {
1637                 ports[pid].dev_conf.link_speeds = link_speed;
1638         }
1639
1640         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1641 }
1642
1643 cmdline_parse_token_string_t cmd_config_speed_all_port =
1644         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1645 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1646         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1647                                                         "config");
1648 cmdline_parse_token_string_t cmd_config_speed_all_all =
1649         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1650 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1651         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1652 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1653         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1654                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1655 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1657 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1658         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1659                                                 "half#full#auto");
1660
1661 cmdline_parse_inst_t cmd_config_speed_all = {
1662         .f = cmd_config_speed_all_parsed,
1663         .data = NULL,
1664         .help_str = "port config all speed "
1665                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1666                                                         "half|full|auto",
1667         .tokens = {
1668                 (void *)&cmd_config_speed_all_port,
1669                 (void *)&cmd_config_speed_all_keyword,
1670                 (void *)&cmd_config_speed_all_all,
1671                 (void *)&cmd_config_speed_all_item1,
1672                 (void *)&cmd_config_speed_all_value1,
1673                 (void *)&cmd_config_speed_all_item2,
1674                 (void *)&cmd_config_speed_all_value2,
1675                 NULL,
1676         },
1677 };
1678
1679 /* *** configure speed for specific port *** */
1680 struct cmd_config_speed_specific {
1681         cmdline_fixed_string_t port;
1682         cmdline_fixed_string_t keyword;
1683         portid_t id;
1684         cmdline_fixed_string_t item1;
1685         cmdline_fixed_string_t item2;
1686         cmdline_fixed_string_t value1;
1687         cmdline_fixed_string_t value2;
1688 };
1689
1690 static void
1691 cmd_config_speed_specific_parsed(void *parsed_result,
1692                                 __attribute__((unused)) struct cmdline *cl,
1693                                 __attribute__((unused)) void *data)
1694 {
1695         struct cmd_config_speed_specific *res = parsed_result;
1696         uint32_t link_speed;
1697
1698         if (!all_ports_stopped()) {
1699                 printf("Please stop all ports first\n");
1700                 return;
1701         }
1702
1703         if (port_id_is_invalid(res->id, ENABLED_WARN))
1704                 return;
1705
1706         if (parse_and_check_speed_duplex(res->value1, res->value2,
1707                         &link_speed) < 0)
1708                 return;
1709
1710         ports[res->id].dev_conf.link_speeds = link_speed;
1711
1712         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1713 }
1714
1715
1716 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1717         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1718                                                                 "port");
1719 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1720         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1721                                                                 "config");
1722 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1723         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1724 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1725         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1726                                                                 "speed");
1727 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1728         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1729                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1730 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1731         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1732                                                                 "duplex");
1733 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1734         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1735                                                         "half#full#auto");
1736
1737 cmdline_parse_inst_t cmd_config_speed_specific = {
1738         .f = cmd_config_speed_specific_parsed,
1739         .data = NULL,
1740         .help_str = "port config <port_id> speed "
1741                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1742                                                         "half|full|auto",
1743         .tokens = {
1744                 (void *)&cmd_config_speed_specific_port,
1745                 (void *)&cmd_config_speed_specific_keyword,
1746                 (void *)&cmd_config_speed_specific_id,
1747                 (void *)&cmd_config_speed_specific_item1,
1748                 (void *)&cmd_config_speed_specific_value1,
1749                 (void *)&cmd_config_speed_specific_item2,
1750                 (void *)&cmd_config_speed_specific_value2,
1751                 NULL,
1752         },
1753 };
1754
1755 /* *** configure loopback for all ports *** */
1756 struct cmd_config_loopback_all {
1757         cmdline_fixed_string_t port;
1758         cmdline_fixed_string_t keyword;
1759         cmdline_fixed_string_t all;
1760         cmdline_fixed_string_t item;
1761         uint32_t mode;
1762 };
1763
1764 static void
1765 cmd_config_loopback_all_parsed(void *parsed_result,
1766                         __attribute__((unused)) struct cmdline *cl,
1767                         __attribute__((unused)) void *data)
1768 {
1769         struct cmd_config_loopback_all *res = parsed_result;
1770         portid_t pid;
1771
1772         if (!all_ports_stopped()) {
1773                 printf("Please stop all ports first\n");
1774                 return;
1775         }
1776
1777         RTE_ETH_FOREACH_DEV(pid) {
1778                 ports[pid].dev_conf.lpbk_mode = res->mode;
1779         }
1780
1781         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1782 }
1783
1784 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1785         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1786 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1787         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1788                                                         "config");
1789 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1790         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1791 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1792         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1793                                                         "loopback");
1794 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1795         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1796
1797 cmdline_parse_inst_t cmd_config_loopback_all = {
1798         .f = cmd_config_loopback_all_parsed,
1799         .data = NULL,
1800         .help_str = "port config all loopback <mode>",
1801         .tokens = {
1802                 (void *)&cmd_config_loopback_all_port,
1803                 (void *)&cmd_config_loopback_all_keyword,
1804                 (void *)&cmd_config_loopback_all_all,
1805                 (void *)&cmd_config_loopback_all_item,
1806                 (void *)&cmd_config_loopback_all_mode,
1807                 NULL,
1808         },
1809 };
1810
1811 /* *** configure loopback for specific port *** */
1812 struct cmd_config_loopback_specific {
1813         cmdline_fixed_string_t port;
1814         cmdline_fixed_string_t keyword;
1815         uint16_t port_id;
1816         cmdline_fixed_string_t item;
1817         uint32_t mode;
1818 };
1819
1820 static void
1821 cmd_config_loopback_specific_parsed(void *parsed_result,
1822                                 __attribute__((unused)) struct cmdline *cl,
1823                                 __attribute__((unused)) void *data)
1824 {
1825         struct cmd_config_loopback_specific *res = parsed_result;
1826
1827         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1828                 return;
1829
1830         if (!port_is_stopped(res->port_id)) {
1831                 printf("Please stop port %u first\n", res->port_id);
1832                 return;
1833         }
1834
1835         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1836
1837         cmd_reconfig_device_queue(res->port_id, 1, 1);
1838 }
1839
1840
1841 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1842         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1843                                                                 "port");
1844 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1845         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1846                                                                 "config");
1847 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1848         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1849                                                                 UINT16);
1850 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1851         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1852                                                                 "loopback");
1853 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1854         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1855                               UINT32);
1856
1857 cmdline_parse_inst_t cmd_config_loopback_specific = {
1858         .f = cmd_config_loopback_specific_parsed,
1859         .data = NULL,
1860         .help_str = "port config <port_id> loopback <mode>",
1861         .tokens = {
1862                 (void *)&cmd_config_loopback_specific_port,
1863                 (void *)&cmd_config_loopback_specific_keyword,
1864                 (void *)&cmd_config_loopback_specific_id,
1865                 (void *)&cmd_config_loopback_specific_item,
1866                 (void *)&cmd_config_loopback_specific_mode,
1867                 NULL,
1868         },
1869 };
1870
1871 /* *** configure txq/rxq, txd/rxd *** */
1872 struct cmd_config_rx_tx {
1873         cmdline_fixed_string_t port;
1874         cmdline_fixed_string_t keyword;
1875         cmdline_fixed_string_t all;
1876         cmdline_fixed_string_t name;
1877         uint16_t value;
1878 };
1879
1880 static void
1881 cmd_config_rx_tx_parsed(void *parsed_result,
1882                         __attribute__((unused)) struct cmdline *cl,
1883                         __attribute__((unused)) void *data)
1884 {
1885         struct cmd_config_rx_tx *res = parsed_result;
1886
1887         if (!all_ports_stopped()) {
1888                 printf("Please stop all ports first\n");
1889                 return;
1890         }
1891         if (!strcmp(res->name, "rxq")) {
1892                 if (!res->value && !nb_txq) {
1893                         printf("Warning: Either rx or tx queues should be non zero\n");
1894                         return;
1895                 }
1896                 if (check_nb_rxq(res->value) != 0)
1897                         return;
1898                 nb_rxq = res->value;
1899         }
1900         else if (!strcmp(res->name, "txq")) {
1901                 if (!res->value && !nb_rxq) {
1902                         printf("Warning: Either rx or tx queues should be non zero\n");
1903                         return;
1904                 }
1905                 if (check_nb_txq(res->value) != 0)
1906                         return;
1907                 nb_txq = res->value;
1908         }
1909         else if (!strcmp(res->name, "rxd")) {
1910                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1911                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1912                                         res->value, RTE_TEST_RX_DESC_MAX);
1913                         return;
1914                 }
1915                 nb_rxd = res->value;
1916         } else if (!strcmp(res->name, "txd")) {
1917                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1918                         printf("txd %d invalid - must be > 0 && <= %d\n",
1919                                         res->value, RTE_TEST_TX_DESC_MAX);
1920                         return;
1921                 }
1922                 nb_txd = res->value;
1923         } else {
1924                 printf("Unknown parameter\n");
1925                 return;
1926         }
1927
1928         fwd_config_setup();
1929
1930         init_port_config();
1931
1932         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1933 }
1934
1935 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1936         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1937 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1938         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1939 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1940         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1941 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1942         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1943                                                 "rxq#txq#rxd#txd");
1944 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1945         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1946
1947 cmdline_parse_inst_t cmd_config_rx_tx = {
1948         .f = cmd_config_rx_tx_parsed,
1949         .data = NULL,
1950         .help_str = "port config all rxq|txq|rxd|txd <value>",
1951         .tokens = {
1952                 (void *)&cmd_config_rx_tx_port,
1953                 (void *)&cmd_config_rx_tx_keyword,
1954                 (void *)&cmd_config_rx_tx_all,
1955                 (void *)&cmd_config_rx_tx_name,
1956                 (void *)&cmd_config_rx_tx_value,
1957                 NULL,
1958         },
1959 };
1960
1961 /* *** config max packet length *** */
1962 struct cmd_config_max_pkt_len_result {
1963         cmdline_fixed_string_t port;
1964         cmdline_fixed_string_t keyword;
1965         cmdline_fixed_string_t all;
1966         cmdline_fixed_string_t name;
1967         uint32_t value;
1968 };
1969
1970 static void
1971 cmd_config_max_pkt_len_parsed(void *parsed_result,
1972                                 __attribute__((unused)) struct cmdline *cl,
1973                                 __attribute__((unused)) void *data)
1974 {
1975         struct cmd_config_max_pkt_len_result *res = parsed_result;
1976         portid_t pid;
1977
1978         if (!all_ports_stopped()) {
1979                 printf("Please stop all ports first\n");
1980                 return;
1981         }
1982
1983         RTE_ETH_FOREACH_DEV(pid) {
1984                 struct rte_port *port = &ports[pid];
1985                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1986
1987                 if (!strcmp(res->name, "max-pkt-len")) {
1988                         if (res->value < RTE_ETHER_MIN_LEN) {
1989                                 printf("max-pkt-len can not be less than %d\n",
1990                                                 RTE_ETHER_MIN_LEN);
1991                                 return;
1992                         }
1993                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1994                                 return;
1995
1996                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1997                         if (res->value > RTE_ETHER_MAX_LEN)
1998                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1999                         else
2000                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2001                         port->dev_conf.rxmode.offloads = rx_offloads;
2002                 } else {
2003                         printf("Unknown parameter\n");
2004                         return;
2005                 }
2006         }
2007
2008         init_port_config();
2009
2010         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2011 }
2012
2013 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2014         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2015                                                                 "port");
2016 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2017         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2018                                                                 "config");
2019 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2020         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2021                                                                 "all");
2022 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2023         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2024                                                                 "max-pkt-len");
2025 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2026         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2027                                                                 UINT32);
2028
2029 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2030         .f = cmd_config_max_pkt_len_parsed,
2031         .data = NULL,
2032         .help_str = "port config all max-pkt-len <value>",
2033         .tokens = {
2034                 (void *)&cmd_config_max_pkt_len_port,
2035                 (void *)&cmd_config_max_pkt_len_keyword,
2036                 (void *)&cmd_config_max_pkt_len_all,
2037                 (void *)&cmd_config_max_pkt_len_name,
2038                 (void *)&cmd_config_max_pkt_len_value,
2039                 NULL,
2040         },
2041 };
2042
2043 /* *** configure port MTU *** */
2044 struct cmd_config_mtu_result {
2045         cmdline_fixed_string_t port;
2046         cmdline_fixed_string_t keyword;
2047         cmdline_fixed_string_t mtu;
2048         portid_t port_id;
2049         uint16_t value;
2050 };
2051
2052 static void
2053 cmd_config_mtu_parsed(void *parsed_result,
2054                       __attribute__((unused)) struct cmdline *cl,
2055                       __attribute__((unused)) void *data)
2056 {
2057         struct cmd_config_mtu_result *res = parsed_result;
2058
2059         if (res->value < RTE_ETHER_MIN_LEN) {
2060                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2061                 return;
2062         }
2063         port_mtu_set(res->port_id, res->value);
2064 }
2065
2066 cmdline_parse_token_string_t cmd_config_mtu_port =
2067         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2068                                  "port");
2069 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2070         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2071                                  "config");
2072 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2073         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2074                                  "mtu");
2075 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2076         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2077 cmdline_parse_token_num_t cmd_config_mtu_value =
2078         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2079
2080 cmdline_parse_inst_t cmd_config_mtu = {
2081         .f = cmd_config_mtu_parsed,
2082         .data = NULL,
2083         .help_str = "port config mtu <port_id> <value>",
2084         .tokens = {
2085                 (void *)&cmd_config_mtu_port,
2086                 (void *)&cmd_config_mtu_keyword,
2087                 (void *)&cmd_config_mtu_mtu,
2088                 (void *)&cmd_config_mtu_port_id,
2089                 (void *)&cmd_config_mtu_value,
2090                 NULL,
2091         },
2092 };
2093
2094 /* *** configure rx mode *** */
2095 struct cmd_config_rx_mode_flag {
2096         cmdline_fixed_string_t port;
2097         cmdline_fixed_string_t keyword;
2098         cmdline_fixed_string_t all;
2099         cmdline_fixed_string_t name;
2100         cmdline_fixed_string_t value;
2101 };
2102
2103 static void
2104 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2105                                 __attribute__((unused)) struct cmdline *cl,
2106                                 __attribute__((unused)) void *data)
2107 {
2108         struct cmd_config_rx_mode_flag *res = parsed_result;
2109
2110         if (!all_ports_stopped()) {
2111                 printf("Please stop all ports first\n");
2112                 return;
2113         }
2114
2115         if (!strcmp(res->name, "drop-en")) {
2116                 if (!strcmp(res->value, "on"))
2117                         rx_drop_en = 1;
2118                 else if (!strcmp(res->value, "off"))
2119                         rx_drop_en = 0;
2120                 else {
2121                         printf("Unknown parameter\n");
2122                         return;
2123                 }
2124         } else {
2125                 printf("Unknown parameter\n");
2126                 return;
2127         }
2128
2129         init_port_config();
2130
2131         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2132 }
2133
2134 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2135         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2136 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2137         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2138                                                                 "config");
2139 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2140         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2141 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2142         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2143                                         "drop-en");
2144 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2145         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2146                                                         "on#off");
2147
2148 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2149         .f = cmd_config_rx_mode_flag_parsed,
2150         .data = NULL,
2151         .help_str = "port config all drop-en on|off",
2152         .tokens = {
2153                 (void *)&cmd_config_rx_mode_flag_port,
2154                 (void *)&cmd_config_rx_mode_flag_keyword,
2155                 (void *)&cmd_config_rx_mode_flag_all,
2156                 (void *)&cmd_config_rx_mode_flag_name,
2157                 (void *)&cmd_config_rx_mode_flag_value,
2158                 NULL,
2159         },
2160 };
2161
2162 /* *** configure rss *** */
2163 struct cmd_config_rss {
2164         cmdline_fixed_string_t port;
2165         cmdline_fixed_string_t keyword;
2166         cmdline_fixed_string_t all;
2167         cmdline_fixed_string_t name;
2168         cmdline_fixed_string_t value;
2169 };
2170
2171 static void
2172 cmd_config_rss_parsed(void *parsed_result,
2173                         __attribute__((unused)) struct cmdline *cl,
2174                         __attribute__((unused)) void *data)
2175 {
2176         struct cmd_config_rss *res = parsed_result;
2177         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2178         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2179         int use_default = 0;
2180         int all_updated = 1;
2181         int diag;
2182         uint16_t i;
2183         int ret;
2184
2185         if (!strcmp(res->value, "all"))
2186                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2187                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2188                                         ETH_RSS_L2_PAYLOAD;
2189         else if (!strcmp(res->value, "ip"))
2190                 rss_conf.rss_hf = ETH_RSS_IP;
2191         else if (!strcmp(res->value, "udp"))
2192                 rss_conf.rss_hf = ETH_RSS_UDP;
2193         else if (!strcmp(res->value, "tcp"))
2194                 rss_conf.rss_hf = ETH_RSS_TCP;
2195         else if (!strcmp(res->value, "sctp"))
2196                 rss_conf.rss_hf = ETH_RSS_SCTP;
2197         else if (!strcmp(res->value, "ether"))
2198                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2199         else if (!strcmp(res->value, "port"))
2200                 rss_conf.rss_hf = ETH_RSS_PORT;
2201         else if (!strcmp(res->value, "vxlan"))
2202                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2203         else if (!strcmp(res->value, "geneve"))
2204                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2205         else if (!strcmp(res->value, "nvgre"))
2206                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2207         else if (!strcmp(res->value, "l3-src-only"))
2208                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2209         else if (!strcmp(res->value, "l3-dst-only"))
2210                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2211         else if (!strcmp(res->value, "l4-src-only"))
2212                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2213         else if (!strcmp(res->value, "l4-dst-only"))
2214                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2215         else if (!strcmp(res->value, "none"))
2216                 rss_conf.rss_hf = 0;
2217         else if (!strcmp(res->value, "default"))
2218                 use_default = 1;
2219         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2220                                                 atoi(res->value) < 64)
2221                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2222         else {
2223                 printf("Unknown parameter\n");
2224                 return;
2225         }
2226         rss_conf.rss_key = NULL;
2227         /* Update global configuration for RSS types. */
2228         RTE_ETH_FOREACH_DEV(i) {
2229                 struct rte_eth_rss_conf local_rss_conf;
2230
2231                 ret = eth_dev_info_get_print_err(i, &dev_info);
2232                 if (ret != 0)
2233                         return;
2234
2235                 if (use_default)
2236                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2237
2238                 local_rss_conf = rss_conf;
2239                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2240                         dev_info.flow_type_rss_offloads;
2241                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2242                         printf("Port %u modified RSS hash function based on hardware support,"
2243                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2244                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2245                 }
2246                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2247                 if (diag < 0) {
2248                         all_updated = 0;
2249                         printf("Configuration of RSS hash at ethernet port %d "
2250                                 "failed with error (%d): %s.\n",
2251                                 i, -diag, strerror(-diag));
2252                 }
2253         }
2254         if (all_updated && !use_default)
2255                 rss_hf = rss_conf.rss_hf;
2256 }
2257
2258 cmdline_parse_token_string_t cmd_config_rss_port =
2259         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2260 cmdline_parse_token_string_t cmd_config_rss_keyword =
2261         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2262 cmdline_parse_token_string_t cmd_config_rss_all =
2263         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2264 cmdline_parse_token_string_t cmd_config_rss_name =
2265         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2266 cmdline_parse_token_string_t cmd_config_rss_value =
2267         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2268
2269 cmdline_parse_inst_t cmd_config_rss = {
2270         .f = cmd_config_rss_parsed,
2271         .data = NULL,
2272         .help_str = "port config all rss "
2273                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2274         .tokens = {
2275                 (void *)&cmd_config_rss_port,
2276                 (void *)&cmd_config_rss_keyword,
2277                 (void *)&cmd_config_rss_all,
2278                 (void *)&cmd_config_rss_name,
2279                 (void *)&cmd_config_rss_value,
2280                 NULL,
2281         },
2282 };
2283
2284 /* *** configure rss hash key *** */
2285 struct cmd_config_rss_hash_key {
2286         cmdline_fixed_string_t port;
2287         cmdline_fixed_string_t config;
2288         portid_t port_id;
2289         cmdline_fixed_string_t rss_hash_key;
2290         cmdline_fixed_string_t rss_type;
2291         cmdline_fixed_string_t key;
2292 };
2293
2294 static uint8_t
2295 hexa_digit_to_value(char hexa_digit)
2296 {
2297         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2298                 return (uint8_t) (hexa_digit - '0');
2299         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2300                 return (uint8_t) ((hexa_digit - 'a') + 10);
2301         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2302                 return (uint8_t) ((hexa_digit - 'A') + 10);
2303         /* Invalid hexa digit */
2304         return 0xFF;
2305 }
2306
2307 static uint8_t
2308 parse_and_check_key_hexa_digit(char *key, int idx)
2309 {
2310         uint8_t hexa_v;
2311
2312         hexa_v = hexa_digit_to_value(key[idx]);
2313         if (hexa_v == 0xFF)
2314                 printf("invalid key: character %c at position %d is not a "
2315                        "valid hexa digit\n", key[idx], idx);
2316         return hexa_v;
2317 }
2318
2319 static void
2320 cmd_config_rss_hash_key_parsed(void *parsed_result,
2321                                __attribute__((unused)) struct cmdline *cl,
2322                                __attribute__((unused)) void *data)
2323 {
2324         struct cmd_config_rss_hash_key *res = parsed_result;
2325         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2326         uint8_t xdgt0;
2327         uint8_t xdgt1;
2328         int i;
2329         struct rte_eth_dev_info dev_info;
2330         uint8_t hash_key_size;
2331         uint32_t key_len;
2332         int ret;
2333
2334         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2335         if (ret != 0)
2336                 return;
2337
2338         if (dev_info.hash_key_size > 0 &&
2339                         dev_info.hash_key_size <= sizeof(hash_key))
2340                 hash_key_size = dev_info.hash_key_size;
2341         else {
2342                 printf("dev_info did not provide a valid hash key size\n");
2343                 return;
2344         }
2345         /* Check the length of the RSS hash key */
2346         key_len = strlen(res->key);
2347         if (key_len != (hash_key_size * 2)) {
2348                 printf("key length: %d invalid - key must be a string of %d"
2349                            " hexa-decimal numbers\n",
2350                            (int) key_len, hash_key_size * 2);
2351                 return;
2352         }
2353         /* Translate RSS hash key into binary representation */
2354         for (i = 0; i < hash_key_size; i++) {
2355                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2356                 if (xdgt0 == 0xFF)
2357                         return;
2358                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2359                 if (xdgt1 == 0xFF)
2360                         return;
2361                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2362         }
2363         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2364                         hash_key_size);
2365 }
2366
2367 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2368         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2369 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2370         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2371                                  "config");
2372 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2373         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2374 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2375         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2376                                  rss_hash_key, "rss-hash-key");
2377 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2378         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2379                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2380                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2381                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2382                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2383                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only");
2384 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2385         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2386
2387 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2388         .f = cmd_config_rss_hash_key_parsed,
2389         .data = NULL,
2390         .help_str = "port config <port_id> rss-hash-key "
2391                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2392                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2393                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2394                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only "
2395                 "<string of hex digits (variable length, NIC dependent)>",
2396         .tokens = {
2397                 (void *)&cmd_config_rss_hash_key_port,
2398                 (void *)&cmd_config_rss_hash_key_config,
2399                 (void *)&cmd_config_rss_hash_key_port_id,
2400                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2401                 (void *)&cmd_config_rss_hash_key_rss_type,
2402                 (void *)&cmd_config_rss_hash_key_value,
2403                 NULL,
2404         },
2405 };
2406
2407 /* *** configure port rxq/txq ring size *** */
2408 struct cmd_config_rxtx_ring_size {
2409         cmdline_fixed_string_t port;
2410         cmdline_fixed_string_t config;
2411         portid_t portid;
2412         cmdline_fixed_string_t rxtxq;
2413         uint16_t qid;
2414         cmdline_fixed_string_t rsize;
2415         uint16_t size;
2416 };
2417
2418 static void
2419 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2420                                  __attribute__((unused)) struct cmdline *cl,
2421                                  __attribute__((unused)) void *data)
2422 {
2423         struct cmd_config_rxtx_ring_size *res = parsed_result;
2424         struct rte_port *port;
2425         uint8_t isrx;
2426
2427         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2428                 return;
2429
2430         if (res->portid == (portid_t)RTE_PORT_ALL) {
2431                 printf("Invalid port id\n");
2432                 return;
2433         }
2434
2435         port = &ports[res->portid];
2436
2437         if (!strcmp(res->rxtxq, "rxq"))
2438                 isrx = 1;
2439         else if (!strcmp(res->rxtxq, "txq"))
2440                 isrx = 0;
2441         else {
2442                 printf("Unknown parameter\n");
2443                 return;
2444         }
2445
2446         if (isrx && rx_queue_id_is_invalid(res->qid))
2447                 return;
2448         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2449                 return;
2450
2451         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2452                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2453                        rx_free_thresh);
2454                 return;
2455         }
2456
2457         if (isrx)
2458                 port->nb_rx_desc[res->qid] = res->size;
2459         else
2460                 port->nb_tx_desc[res->qid] = res->size;
2461
2462         cmd_reconfig_device_queue(res->portid, 0, 1);
2463 }
2464
2465 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2466         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2467                                  port, "port");
2468 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2469         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2470                                  config, "config");
2471 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2472         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2473                                  portid, UINT16);
2474 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2475         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2476                                  rxtxq, "rxq#txq");
2477 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2478         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2479                               qid, UINT16);
2480 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2481         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2482                                  rsize, "ring_size");
2483 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2484         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2485                               size, UINT16);
2486
2487 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2488         .f = cmd_config_rxtx_ring_size_parsed,
2489         .data = NULL,
2490         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2491         .tokens = {
2492                 (void *)&cmd_config_rxtx_ring_size_port,
2493                 (void *)&cmd_config_rxtx_ring_size_config,
2494                 (void *)&cmd_config_rxtx_ring_size_portid,
2495                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2496                 (void *)&cmd_config_rxtx_ring_size_qid,
2497                 (void *)&cmd_config_rxtx_ring_size_rsize,
2498                 (void *)&cmd_config_rxtx_ring_size_size,
2499                 NULL,
2500         },
2501 };
2502
2503 /* *** configure port rxq/txq start/stop *** */
2504 struct cmd_config_rxtx_queue {
2505         cmdline_fixed_string_t port;
2506         portid_t portid;
2507         cmdline_fixed_string_t rxtxq;
2508         uint16_t qid;
2509         cmdline_fixed_string_t opname;
2510 };
2511
2512 static void
2513 cmd_config_rxtx_queue_parsed(void *parsed_result,
2514                         __attribute__((unused)) struct cmdline *cl,
2515                         __attribute__((unused)) void *data)
2516 {
2517         struct cmd_config_rxtx_queue *res = parsed_result;
2518         uint8_t isrx;
2519         uint8_t isstart;
2520         int ret = 0;
2521
2522         if (test_done == 0) {
2523                 printf("Please stop forwarding first\n");
2524                 return;
2525         }
2526
2527         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2528                 return;
2529
2530         if (port_is_started(res->portid) != 1) {
2531                 printf("Please start port %u first\n", res->portid);
2532                 return;
2533         }
2534
2535         if (!strcmp(res->rxtxq, "rxq"))
2536                 isrx = 1;
2537         else if (!strcmp(res->rxtxq, "txq"))
2538                 isrx = 0;
2539         else {
2540                 printf("Unknown parameter\n");
2541                 return;
2542         }
2543
2544         if (isrx && rx_queue_id_is_invalid(res->qid))
2545                 return;
2546         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2547                 return;
2548
2549         if (!strcmp(res->opname, "start"))
2550                 isstart = 1;
2551         else if (!strcmp(res->opname, "stop"))
2552                 isstart = 0;
2553         else {
2554                 printf("Unknown parameter\n");
2555                 return;
2556         }
2557
2558         if (isstart && isrx)
2559                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2560         else if (!isstart && isrx)
2561                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2562         else if (isstart && !isrx)
2563                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2564         else
2565                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2566
2567         if (ret == -ENOTSUP)
2568                 printf("Function not supported in PMD driver\n");
2569 }
2570
2571 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2572         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2573 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2574         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2575 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2576         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2577 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2578         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2579 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2580         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2581                                                 "start#stop");
2582
2583 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2584         .f = cmd_config_rxtx_queue_parsed,
2585         .data = NULL,
2586         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2587         .tokens = {
2588                 (void *)&cmd_config_rxtx_queue_port,
2589                 (void *)&cmd_config_rxtx_queue_portid,
2590                 (void *)&cmd_config_rxtx_queue_rxtxq,
2591                 (void *)&cmd_config_rxtx_queue_qid,
2592                 (void *)&cmd_config_rxtx_queue_opname,
2593                 NULL,
2594         },
2595 };
2596
2597 /* *** configure port rxq/txq deferred start on/off *** */
2598 struct cmd_config_deferred_start_rxtx_queue {
2599         cmdline_fixed_string_t port;
2600         portid_t port_id;
2601         cmdline_fixed_string_t rxtxq;
2602         uint16_t qid;
2603         cmdline_fixed_string_t opname;
2604         cmdline_fixed_string_t state;
2605 };
2606
2607 static void
2608 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2609                         __attribute__((unused)) struct cmdline *cl,
2610                         __attribute__((unused)) void *data)
2611 {
2612         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2613         struct rte_port *port;
2614         uint8_t isrx;
2615         uint8_t ison;
2616         uint8_t needreconfig = 0;
2617
2618         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2619                 return;
2620
2621         if (port_is_started(res->port_id) != 0) {
2622                 printf("Please stop port %u first\n", res->port_id);
2623                 return;
2624         }
2625
2626         port = &ports[res->port_id];
2627
2628         isrx = !strcmp(res->rxtxq, "rxq");
2629
2630         if (isrx && rx_queue_id_is_invalid(res->qid))
2631                 return;
2632         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2633                 return;
2634
2635         ison = !strcmp(res->state, "on");
2636
2637         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2638                 port->rx_conf[res->qid].rx_deferred_start = ison;
2639                 needreconfig = 1;
2640         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2641                 port->tx_conf[res->qid].tx_deferred_start = ison;
2642                 needreconfig = 1;
2643         }
2644
2645         if (needreconfig)
2646                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2647 }
2648
2649 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2650         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2651                                                 port, "port");
2652 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2653         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2654                                                 port_id, UINT16);
2655 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2656         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2657                                                 rxtxq, "rxq#txq");
2658 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2659         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2660                                                 qid, UINT16);
2661 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2662         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2663                                                 opname, "deferred_start");
2664 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2665         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2666                                                 state, "on#off");
2667
2668 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2669         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2670         .data = NULL,
2671         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2672         .tokens = {
2673                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2674                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2675                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2676                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2677                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2678                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2679                 NULL,
2680         },
2681 };
2682
2683 /* *** configure port rxq/txq setup *** */
2684 struct cmd_setup_rxtx_queue {
2685         cmdline_fixed_string_t port;
2686         portid_t portid;
2687         cmdline_fixed_string_t rxtxq;
2688         uint16_t qid;
2689         cmdline_fixed_string_t setup;
2690 };
2691
2692 /* Common CLI fields for queue setup */
2693 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2694         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2695 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2696         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2697 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2698         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2699 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2700         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2701 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2702         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2703
2704 static void
2705 cmd_setup_rxtx_queue_parsed(
2706         void *parsed_result,
2707         __attribute__((unused)) struct cmdline *cl,
2708         __attribute__((unused)) void *data)
2709 {
2710         struct cmd_setup_rxtx_queue *res = parsed_result;
2711         struct rte_port *port;
2712         struct rte_mempool *mp;
2713         unsigned int socket_id;
2714         uint8_t isrx = 0;
2715         int ret;
2716
2717         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2718                 return;
2719
2720         if (res->portid == (portid_t)RTE_PORT_ALL) {
2721                 printf("Invalid port id\n");
2722                 return;
2723         }
2724
2725         if (!strcmp(res->rxtxq, "rxq"))
2726                 isrx = 1;
2727         else if (!strcmp(res->rxtxq, "txq"))
2728                 isrx = 0;
2729         else {
2730                 printf("Unknown parameter\n");
2731                 return;
2732         }
2733
2734         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2735                 printf("Invalid rx queue\n");
2736                 return;
2737         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2738                 printf("Invalid tx queue\n");
2739                 return;
2740         }
2741
2742         port = &ports[res->portid];
2743         if (isrx) {
2744                 socket_id = rxring_numa[res->portid];
2745                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2746                         socket_id = port->socket_id;
2747
2748                 mp = mbuf_pool_find(socket_id);
2749                 if (mp == NULL) {
2750                         printf("Failed to setup RX queue: "
2751                                 "No mempool allocation"
2752                                 " on the socket %d\n",
2753                                 rxring_numa[res->portid]);
2754                         return;
2755                 }
2756                 ret = rte_eth_rx_queue_setup(res->portid,
2757                                              res->qid,
2758                                              port->nb_rx_desc[res->qid],
2759                                              socket_id,
2760                                              &port->rx_conf[res->qid],
2761                                              mp);
2762                 if (ret)
2763                         printf("Failed to setup RX queue\n");
2764         } else {
2765                 socket_id = txring_numa[res->portid];
2766                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2767                         socket_id = port->socket_id;
2768
2769                 ret = rte_eth_tx_queue_setup(res->portid,
2770                                              res->qid,
2771                                              port->nb_tx_desc[res->qid],
2772                                              socket_id,
2773                                              &port->tx_conf[res->qid]);
2774                 if (ret)
2775                         printf("Failed to setup TX queue\n");
2776         }
2777 }
2778
2779 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2780         .f = cmd_setup_rxtx_queue_parsed,
2781         .data = NULL,
2782         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2783         .tokens = {
2784                 (void *)&cmd_setup_rxtx_queue_port,
2785                 (void *)&cmd_setup_rxtx_queue_portid,
2786                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2787                 (void *)&cmd_setup_rxtx_queue_qid,
2788                 (void *)&cmd_setup_rxtx_queue_setup,
2789                 NULL,
2790         },
2791 };
2792
2793
2794 /* *** Configure RSS RETA *** */
2795 struct cmd_config_rss_reta {
2796         cmdline_fixed_string_t port;
2797         cmdline_fixed_string_t keyword;
2798         portid_t port_id;
2799         cmdline_fixed_string_t name;
2800         cmdline_fixed_string_t list_name;
2801         cmdline_fixed_string_t list_of_items;
2802 };
2803
2804 static int
2805 parse_reta_config(const char *str,
2806                   struct rte_eth_rss_reta_entry64 *reta_conf,
2807                   uint16_t nb_entries)
2808 {
2809         int i;
2810         unsigned size;
2811         uint16_t hash_index, idx, shift;
2812         uint16_t nb_queue;
2813         char s[256];
2814         const char *p, *p0 = str;
2815         char *end;
2816         enum fieldnames {
2817                 FLD_HASH_INDEX = 0,
2818                 FLD_QUEUE,
2819                 _NUM_FLD
2820         };
2821         unsigned long int_fld[_NUM_FLD];
2822         char *str_fld[_NUM_FLD];
2823
2824         while ((p = strchr(p0,'(')) != NULL) {
2825                 ++p;
2826                 if((p0 = strchr(p,')')) == NULL)
2827                         return -1;
2828
2829                 size = p0 - p;
2830                 if(size >= sizeof(s))
2831                         return -1;
2832
2833                 snprintf(s, sizeof(s), "%.*s", size, p);
2834                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2835                         return -1;
2836                 for (i = 0; i < _NUM_FLD; i++) {
2837                         errno = 0;
2838                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2839                         if (errno != 0 || end == str_fld[i] ||
2840                                         int_fld[i] > 65535)
2841                                 return -1;
2842                 }
2843
2844                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2845                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2846
2847                 if (hash_index >= nb_entries) {
2848                         printf("Invalid RETA hash index=%d\n", hash_index);
2849                         return -1;
2850                 }
2851
2852                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2853                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2854                 reta_conf[idx].mask |= (1ULL << shift);
2855                 reta_conf[idx].reta[shift] = nb_queue;
2856         }
2857
2858         return 0;
2859 }
2860
2861 static void
2862 cmd_set_rss_reta_parsed(void *parsed_result,
2863                         __attribute__((unused)) struct cmdline *cl,
2864                         __attribute__((unused)) void *data)
2865 {
2866         int ret;
2867         struct rte_eth_dev_info dev_info;
2868         struct rte_eth_rss_reta_entry64 reta_conf[8];
2869         struct cmd_config_rss_reta *res = parsed_result;
2870
2871         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2872         if (ret != 0)
2873                 return;
2874
2875         if (dev_info.reta_size == 0) {
2876                 printf("Redirection table size is 0 which is "
2877                                         "invalid for RSS\n");
2878                 return;
2879         } else
2880                 printf("The reta size of port %d is %u\n",
2881                         res->port_id, dev_info.reta_size);
2882         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2883                 printf("Currently do not support more than %u entries of "
2884                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2885                 return;
2886         }
2887
2888         memset(reta_conf, 0, sizeof(reta_conf));
2889         if (!strcmp(res->list_name, "reta")) {
2890                 if (parse_reta_config(res->list_of_items, reta_conf,
2891                                                 dev_info.reta_size)) {
2892                         printf("Invalid RSS Redirection Table "
2893                                         "config entered\n");
2894                         return;
2895                 }
2896                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2897                                 reta_conf, dev_info.reta_size);
2898                 if (ret != 0)
2899                         printf("Bad redirection table parameter, "
2900                                         "return code = %d \n", ret);
2901         }
2902 }
2903
2904 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2905         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2906 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2907         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2908 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2909         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2910 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2911         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2912 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2913         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2914 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2915         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2916                                  NULL);
2917 cmdline_parse_inst_t cmd_config_rss_reta = {
2918         .f = cmd_set_rss_reta_parsed,
2919         .data = NULL,
2920         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2921         .tokens = {
2922                 (void *)&cmd_config_rss_reta_port,
2923                 (void *)&cmd_config_rss_reta_keyword,
2924                 (void *)&cmd_config_rss_reta_port_id,
2925                 (void *)&cmd_config_rss_reta_name,
2926                 (void *)&cmd_config_rss_reta_list_name,
2927                 (void *)&cmd_config_rss_reta_list_of_items,
2928                 NULL,
2929         },
2930 };
2931
2932 /* *** SHOW PORT RETA INFO *** */
2933 struct cmd_showport_reta {
2934         cmdline_fixed_string_t show;
2935         cmdline_fixed_string_t port;
2936         portid_t port_id;
2937         cmdline_fixed_string_t rss;
2938         cmdline_fixed_string_t reta;
2939         uint16_t size;
2940         cmdline_fixed_string_t list_of_items;
2941 };
2942
2943 static int
2944 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2945                            uint16_t nb_entries,
2946                            char *str)
2947 {
2948         uint32_t size;
2949         const char *p, *p0 = str;
2950         char s[256];
2951         char *end;
2952         char *str_fld[8];
2953         uint16_t i;
2954         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2955                         RTE_RETA_GROUP_SIZE;
2956         int ret;
2957
2958         p = strchr(p0, '(');
2959         if (p == NULL)
2960                 return -1;
2961         p++;
2962         p0 = strchr(p, ')');
2963         if (p0 == NULL)
2964                 return -1;
2965         size = p0 - p;
2966         if (size >= sizeof(s)) {
2967                 printf("The string size exceeds the internal buffer size\n");
2968                 return -1;
2969         }
2970         snprintf(s, sizeof(s), "%.*s", size, p);
2971         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2972         if (ret <= 0 || ret != num) {
2973                 printf("The bits of masks do not match the number of "
2974                                         "reta entries: %u\n", num);
2975                 return -1;
2976         }
2977         for (i = 0; i < ret; i++)
2978                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2979
2980         return 0;
2981 }
2982
2983 static void
2984 cmd_showport_reta_parsed(void *parsed_result,
2985                          __attribute__((unused)) struct cmdline *cl,
2986                          __attribute__((unused)) void *data)
2987 {
2988         struct cmd_showport_reta *res = parsed_result;
2989         struct rte_eth_rss_reta_entry64 reta_conf[8];
2990         struct rte_eth_dev_info dev_info;
2991         uint16_t max_reta_size;
2992         int ret;
2993
2994         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2995         if (ret != 0)
2996                 return;
2997
2998         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2999         if (res->size == 0 || res->size > max_reta_size) {
3000                 printf("Invalid redirection table size: %u (1-%u)\n",
3001                         res->size, max_reta_size);
3002                 return;
3003         }
3004
3005         memset(reta_conf, 0, sizeof(reta_conf));
3006         if (showport_parse_reta_config(reta_conf, res->size,
3007                                 res->list_of_items) < 0) {
3008                 printf("Invalid string: %s for reta masks\n",
3009                                         res->list_of_items);
3010                 return;
3011         }
3012         port_rss_reta_info(res->port_id, reta_conf, res->size);
3013 }
3014
3015 cmdline_parse_token_string_t cmd_showport_reta_show =
3016         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3017 cmdline_parse_token_string_t cmd_showport_reta_port =
3018         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3019 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3020         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3021 cmdline_parse_token_string_t cmd_showport_reta_rss =
3022         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3023 cmdline_parse_token_string_t cmd_showport_reta_reta =
3024         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3025 cmdline_parse_token_num_t cmd_showport_reta_size =
3026         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3027 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3028         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3029                                         list_of_items, NULL);
3030
3031 cmdline_parse_inst_t cmd_showport_reta = {
3032         .f = cmd_showport_reta_parsed,
3033         .data = NULL,
3034         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3035         .tokens = {
3036                 (void *)&cmd_showport_reta_show,
3037                 (void *)&cmd_showport_reta_port,
3038                 (void *)&cmd_showport_reta_port_id,
3039                 (void *)&cmd_showport_reta_rss,
3040                 (void *)&cmd_showport_reta_reta,
3041                 (void *)&cmd_showport_reta_size,
3042                 (void *)&cmd_showport_reta_list_of_items,
3043                 NULL,
3044         },
3045 };
3046
3047 /* *** Show RSS hash configuration *** */
3048 struct cmd_showport_rss_hash {
3049         cmdline_fixed_string_t show;
3050         cmdline_fixed_string_t port;
3051         portid_t port_id;
3052         cmdline_fixed_string_t rss_hash;
3053         cmdline_fixed_string_t rss_type;
3054         cmdline_fixed_string_t key; /* optional argument */
3055 };
3056
3057 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3058                                 __attribute__((unused)) struct cmdline *cl,
3059                                 void *show_rss_key)
3060 {
3061         struct cmd_showport_rss_hash *res = parsed_result;
3062
3063         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3064 }
3065
3066 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3067         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3068 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3069         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3070 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3071         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3072 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3073         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3074                                  "rss-hash");
3075 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3076         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3077
3078 cmdline_parse_inst_t cmd_showport_rss_hash = {
3079         .f = cmd_showport_rss_hash_parsed,
3080         .data = NULL,
3081         .help_str = "show port <port_id> rss-hash",
3082         .tokens = {
3083                 (void *)&cmd_showport_rss_hash_show,
3084                 (void *)&cmd_showport_rss_hash_port,
3085                 (void *)&cmd_showport_rss_hash_port_id,
3086                 (void *)&cmd_showport_rss_hash_rss_hash,
3087                 NULL,
3088         },
3089 };
3090
3091 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3092         .f = cmd_showport_rss_hash_parsed,
3093         .data = (void *)1,
3094         .help_str = "show port <port_id> rss-hash key",
3095         .tokens = {
3096                 (void *)&cmd_showport_rss_hash_show,
3097                 (void *)&cmd_showport_rss_hash_port,
3098                 (void *)&cmd_showport_rss_hash_port_id,
3099                 (void *)&cmd_showport_rss_hash_rss_hash,
3100                 (void *)&cmd_showport_rss_hash_rss_key,
3101                 NULL,
3102         },
3103 };
3104
3105 /* *** Configure DCB *** */
3106 struct cmd_config_dcb {
3107         cmdline_fixed_string_t port;
3108         cmdline_fixed_string_t config;
3109         portid_t port_id;
3110         cmdline_fixed_string_t dcb;
3111         cmdline_fixed_string_t vt;
3112         cmdline_fixed_string_t vt_en;
3113         uint8_t num_tcs;
3114         cmdline_fixed_string_t pfc;
3115         cmdline_fixed_string_t pfc_en;
3116 };
3117
3118 static void
3119 cmd_config_dcb_parsed(void *parsed_result,
3120                         __attribute__((unused)) struct cmdline *cl,
3121                         __attribute__((unused)) void *data)
3122 {
3123         struct cmd_config_dcb *res = parsed_result;
3124         portid_t port_id = res->port_id;
3125         struct rte_port *port;
3126         uint8_t pfc_en;
3127         int ret;
3128
3129         port = &ports[port_id];
3130         /** Check if the port is not started **/
3131         if (port->port_status != RTE_PORT_STOPPED) {
3132                 printf("Please stop port %d first\n", port_id);
3133                 return;
3134         }
3135
3136         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3137                 printf("The invalid number of traffic class,"
3138                         " only 4 or 8 allowed.\n");
3139                 return;
3140         }
3141
3142         if (nb_fwd_lcores < res->num_tcs) {
3143                 printf("nb_cores shouldn't be less than number of TCs.\n");
3144                 return;
3145         }
3146         if (!strncmp(res->pfc_en, "on", 2))
3147                 pfc_en = 1;
3148         else
3149                 pfc_en = 0;
3150
3151         /* DCB in VT mode */
3152         if (!strncmp(res->vt_en, "on", 2))
3153                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3154                                 (enum rte_eth_nb_tcs)res->num_tcs,
3155                                 pfc_en);
3156         else
3157                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3158                                 (enum rte_eth_nb_tcs)res->num_tcs,
3159                                 pfc_en);
3160
3161
3162         if (ret != 0) {
3163                 printf("Cannot initialize network ports.\n");
3164                 return;
3165         }
3166
3167         cmd_reconfig_device_queue(port_id, 1, 1);
3168 }
3169
3170 cmdline_parse_token_string_t cmd_config_dcb_port =
3171         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3172 cmdline_parse_token_string_t cmd_config_dcb_config =
3173         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3174 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3175         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3176 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3177         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3178 cmdline_parse_token_string_t cmd_config_dcb_vt =
3179         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3180 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3181         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3182 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3183         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3184 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3185         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3186 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3187         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3188
3189 cmdline_parse_inst_t cmd_config_dcb = {
3190         .f = cmd_config_dcb_parsed,
3191         .data = NULL,
3192         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3193         .tokens = {
3194                 (void *)&cmd_config_dcb_port,
3195                 (void *)&cmd_config_dcb_config,
3196                 (void *)&cmd_config_dcb_port_id,
3197                 (void *)&cmd_config_dcb_dcb,
3198                 (void *)&cmd_config_dcb_vt,
3199                 (void *)&cmd_config_dcb_vt_en,
3200                 (void *)&cmd_config_dcb_num_tcs,
3201                 (void *)&cmd_config_dcb_pfc,
3202                 (void *)&cmd_config_dcb_pfc_en,
3203                 NULL,
3204         },
3205 };
3206
3207 /* *** configure number of packets per burst *** */
3208 struct cmd_config_burst {
3209         cmdline_fixed_string_t port;
3210         cmdline_fixed_string_t keyword;
3211         cmdline_fixed_string_t all;
3212         cmdline_fixed_string_t name;
3213         uint16_t value;
3214 };
3215
3216 static void
3217 cmd_config_burst_parsed(void *parsed_result,
3218                         __attribute__((unused)) struct cmdline *cl,
3219                         __attribute__((unused)) void *data)
3220 {
3221         struct cmd_config_burst *res = parsed_result;
3222         struct rte_eth_dev_info dev_info;
3223         uint16_t rec_nb_pkts;
3224         int ret;
3225
3226         if (!all_ports_stopped()) {
3227                 printf("Please stop all ports first\n");
3228                 return;
3229         }
3230
3231         if (!strcmp(res->name, "burst")) {
3232                 if (res->value == 0) {
3233                         /* If user gives a value of zero, query the PMD for
3234                          * its recommended Rx burst size. Testpmd uses a single
3235                          * size for all ports, so assume all ports are the same
3236                          * NIC model and use the values from Port 0.
3237                          */
3238                         ret = eth_dev_info_get_print_err(0, &dev_info);
3239                         if (ret != 0)
3240                                 return;
3241
3242                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3243
3244                         if (rec_nb_pkts == 0) {
3245                                 printf("PMD does not recommend a burst size.\n"
3246                                         "User provided value must be between"
3247                                         " 1 and %d\n", MAX_PKT_BURST);
3248                                 return;
3249                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3250                                 printf("PMD recommended burst size of %d"
3251                                         " exceeds maximum value of %d\n",
3252                                         rec_nb_pkts, MAX_PKT_BURST);
3253                                 return;
3254                         }
3255                         printf("Using PMD-provided burst value of %d\n",
3256                                 rec_nb_pkts);
3257                         nb_pkt_per_burst = rec_nb_pkts;
3258                 } else if (res->value > MAX_PKT_BURST) {
3259                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3260                         return;
3261                 } else
3262                         nb_pkt_per_burst = res->value;
3263         } else {
3264                 printf("Unknown parameter\n");
3265                 return;
3266         }
3267
3268         init_port_config();
3269
3270         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3271 }
3272
3273 cmdline_parse_token_string_t cmd_config_burst_port =
3274         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3275 cmdline_parse_token_string_t cmd_config_burst_keyword =
3276         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3277 cmdline_parse_token_string_t cmd_config_burst_all =
3278         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3279 cmdline_parse_token_string_t cmd_config_burst_name =
3280         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3281 cmdline_parse_token_num_t cmd_config_burst_value =
3282         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3283
3284 cmdline_parse_inst_t cmd_config_burst = {
3285         .f = cmd_config_burst_parsed,
3286         .data = NULL,
3287         .help_str = "port config all burst <value>",
3288         .tokens = {
3289                 (void *)&cmd_config_burst_port,
3290                 (void *)&cmd_config_burst_keyword,
3291                 (void *)&cmd_config_burst_all,
3292                 (void *)&cmd_config_burst_name,
3293                 (void *)&cmd_config_burst_value,
3294                 NULL,
3295         },
3296 };
3297
3298 /* *** configure rx/tx queues *** */
3299 struct cmd_config_thresh {
3300         cmdline_fixed_string_t port;
3301         cmdline_fixed_string_t keyword;
3302         cmdline_fixed_string_t all;
3303         cmdline_fixed_string_t name;
3304         uint8_t value;
3305 };
3306
3307 static void
3308 cmd_config_thresh_parsed(void *parsed_result,
3309                         __attribute__((unused)) struct cmdline *cl,
3310                         __attribute__((unused)) void *data)
3311 {
3312         struct cmd_config_thresh *res = parsed_result;
3313
3314         if (!all_ports_stopped()) {
3315                 printf("Please stop all ports first\n");
3316                 return;
3317         }
3318
3319         if (!strcmp(res->name, "txpt"))
3320                 tx_pthresh = res->value;
3321         else if(!strcmp(res->name, "txht"))
3322                 tx_hthresh = res->value;
3323         else if(!strcmp(res->name, "txwt"))
3324                 tx_wthresh = res->value;
3325         else if(!strcmp(res->name, "rxpt"))
3326                 rx_pthresh = res->value;
3327         else if(!strcmp(res->name, "rxht"))
3328                 rx_hthresh = res->value;
3329         else if(!strcmp(res->name, "rxwt"))
3330                 rx_wthresh = res->value;
3331         else {
3332                 printf("Unknown parameter\n");
3333                 return;
3334         }
3335
3336         init_port_config();
3337
3338         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3339 }
3340
3341 cmdline_parse_token_string_t cmd_config_thresh_port =
3342         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3343 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3344         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3345 cmdline_parse_token_string_t cmd_config_thresh_all =
3346         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3347 cmdline_parse_token_string_t cmd_config_thresh_name =
3348         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3349                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3350 cmdline_parse_token_num_t cmd_config_thresh_value =
3351         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3352
3353 cmdline_parse_inst_t cmd_config_thresh = {
3354         .f = cmd_config_thresh_parsed,
3355         .data = NULL,
3356         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3357         .tokens = {
3358                 (void *)&cmd_config_thresh_port,
3359                 (void *)&cmd_config_thresh_keyword,
3360                 (void *)&cmd_config_thresh_all,
3361                 (void *)&cmd_config_thresh_name,
3362                 (void *)&cmd_config_thresh_value,
3363                 NULL,
3364         },
3365 };
3366
3367 /* *** configure free/rs threshold *** */
3368 struct cmd_config_threshold {
3369         cmdline_fixed_string_t port;
3370         cmdline_fixed_string_t keyword;
3371         cmdline_fixed_string_t all;
3372         cmdline_fixed_string_t name;
3373         uint16_t value;
3374 };
3375
3376 static void
3377 cmd_config_threshold_parsed(void *parsed_result,
3378                         __attribute__((unused)) struct cmdline *cl,
3379                         __attribute__((unused)) void *data)
3380 {
3381         struct cmd_config_threshold *res = parsed_result;
3382
3383         if (!all_ports_stopped()) {
3384                 printf("Please stop all ports first\n");
3385                 return;
3386         }
3387
3388         if (!strcmp(res->name, "txfreet"))
3389                 tx_free_thresh = res->value;
3390         else if (!strcmp(res->name, "txrst"))
3391                 tx_rs_thresh = res->value;
3392         else if (!strcmp(res->name, "rxfreet"))
3393                 rx_free_thresh = res->value;
3394         else {
3395                 printf("Unknown parameter\n");
3396                 return;
3397         }
3398
3399         init_port_config();
3400
3401         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3402 }
3403
3404 cmdline_parse_token_string_t cmd_config_threshold_port =
3405         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3406 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3407         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3408                                                                 "config");
3409 cmdline_parse_token_string_t cmd_config_threshold_all =
3410         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3411 cmdline_parse_token_string_t cmd_config_threshold_name =
3412         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3413                                                 "txfreet#txrst#rxfreet");
3414 cmdline_parse_token_num_t cmd_config_threshold_value =
3415         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3416
3417 cmdline_parse_inst_t cmd_config_threshold = {
3418         .f = cmd_config_threshold_parsed,
3419         .data = NULL,
3420         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3421         .tokens = {
3422                 (void *)&cmd_config_threshold_port,
3423                 (void *)&cmd_config_threshold_keyword,
3424                 (void *)&cmd_config_threshold_all,
3425                 (void *)&cmd_config_threshold_name,
3426                 (void *)&cmd_config_threshold_value,
3427                 NULL,
3428         },
3429 };
3430
3431 /* *** stop *** */
3432 struct cmd_stop_result {
3433         cmdline_fixed_string_t stop;
3434 };
3435
3436 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3437                             __attribute__((unused)) struct cmdline *cl,
3438                             __attribute__((unused)) void *data)
3439 {
3440         stop_packet_forwarding();
3441 }
3442
3443 cmdline_parse_token_string_t cmd_stop_stop =
3444         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3445
3446 cmdline_parse_inst_t cmd_stop = {
3447         .f = cmd_stop_parsed,
3448         .data = NULL,
3449         .help_str = "stop: Stop packet forwarding",
3450         .tokens = {
3451                 (void *)&cmd_stop_stop,
3452                 NULL,
3453         },
3454 };
3455
3456 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3457
3458 unsigned int
3459 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3460                 unsigned int *parsed_items, int check_unique_values)
3461 {
3462         unsigned int nb_item;
3463         unsigned int value;
3464         unsigned int i;
3465         unsigned int j;
3466         int value_ok;
3467         char c;
3468
3469         /*
3470          * First parse all items in the list and store their value.
3471          */
3472         value = 0;
3473         nb_item = 0;
3474         value_ok = 0;
3475         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3476                 c = str[i];
3477                 if ((c >= '0') && (c <= '9')) {
3478                         value = (unsigned int) (value * 10 + (c - '0'));
3479                         value_ok = 1;
3480                         continue;
3481                 }
3482                 if (c != ',') {
3483                         printf("character %c is not a decimal digit\n", c);
3484                         return 0;
3485                 }
3486                 if (! value_ok) {
3487                         printf("No valid value before comma\n");
3488                         return 0;
3489                 }
3490                 if (nb_item < max_items) {
3491                         parsed_items[nb_item] = value;
3492                         value_ok = 0;
3493                         value = 0;
3494                 }
3495                 nb_item++;
3496         }
3497         if (nb_item >= max_items) {
3498                 printf("Number of %s = %u > %u (maximum items)\n",
3499                        item_name, nb_item + 1, max_items);
3500                 return 0;
3501         }
3502         parsed_items[nb_item++] = value;
3503         if (! check_unique_values)
3504                 return nb_item;
3505
3506         /*
3507          * Then, check that all values in the list are differents.
3508          * No optimization here...
3509          */
3510         for (i = 0; i < nb_item; i++) {
3511                 for (j = i + 1; j < nb_item; j++) {
3512                         if (parsed_items[j] == parsed_items[i]) {
3513                                 printf("duplicated %s %u at index %u and %u\n",
3514                                        item_name, parsed_items[i], i, j);
3515                                 return 0;
3516                         }
3517                 }
3518         }
3519         return nb_item;
3520 }
3521
3522 struct cmd_set_list_result {
3523         cmdline_fixed_string_t cmd_keyword;
3524         cmdline_fixed_string_t list_name;
3525         cmdline_fixed_string_t list_of_items;
3526 };
3527
3528 static void cmd_set_list_parsed(void *parsed_result,
3529                                 __attribute__((unused)) struct cmdline *cl,
3530                                 __attribute__((unused)) void *data)
3531 {
3532         struct cmd_set_list_result *res;
3533         union {
3534                 unsigned int lcorelist[RTE_MAX_LCORE];
3535                 unsigned int portlist[RTE_MAX_ETHPORTS];
3536         } parsed_items;
3537         unsigned int nb_item;
3538
3539         if (test_done == 0) {
3540                 printf("Please stop forwarding first\n");
3541                 return;
3542         }
3543
3544         res = parsed_result;
3545         if (!strcmp(res->list_name, "corelist")) {
3546                 nb_item = parse_item_list(res->list_of_items, "core",
3547                                           RTE_MAX_LCORE,
3548                                           parsed_items.lcorelist, 1);
3549                 if (nb_item > 0) {
3550                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3551                         fwd_config_setup();
3552                 }
3553                 return;
3554         }
3555         if (!strcmp(res->list_name, "portlist")) {
3556                 nb_item = parse_item_list(res->list_of_items, "port",
3557                                           RTE_MAX_ETHPORTS,
3558                                           parsed_items.portlist, 1);
3559                 if (nb_item > 0) {
3560                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3561                         fwd_config_setup();
3562                 }
3563         }
3564 }
3565
3566 cmdline_parse_token_string_t cmd_set_list_keyword =
3567         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3568                                  "set");
3569 cmdline_parse_token_string_t cmd_set_list_name =
3570         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3571                                  "corelist#portlist");
3572 cmdline_parse_token_string_t cmd_set_list_of_items =
3573         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3574                                  NULL);
3575
3576 cmdline_parse_inst_t cmd_set_fwd_list = {
3577         .f = cmd_set_list_parsed,
3578         .data = NULL,
3579         .help_str = "set corelist|portlist <list0[,list1]*>",
3580         .tokens = {
3581                 (void *)&cmd_set_list_keyword,
3582                 (void *)&cmd_set_list_name,
3583                 (void *)&cmd_set_list_of_items,
3584                 NULL,
3585         },
3586 };
3587
3588 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3589
3590 struct cmd_setmask_result {
3591         cmdline_fixed_string_t set;
3592         cmdline_fixed_string_t mask;
3593         uint64_t hexavalue;
3594 };
3595
3596 static void cmd_set_mask_parsed(void *parsed_result,
3597                                 __attribute__((unused)) struct cmdline *cl,
3598                                 __attribute__((unused)) void *data)
3599 {
3600         struct cmd_setmask_result *res = parsed_result;
3601
3602         if (test_done == 0) {
3603                 printf("Please stop forwarding first\n");
3604                 return;
3605         }
3606         if (!strcmp(res->mask, "coremask")) {
3607                 set_fwd_lcores_mask(res->hexavalue);
3608                 fwd_config_setup();
3609         } else if (!strcmp(res->mask, "portmask")) {
3610                 set_fwd_ports_mask(res->hexavalue);
3611                 fwd_config_setup();
3612         }
3613 }
3614
3615 cmdline_parse_token_string_t cmd_setmask_set =
3616         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3617 cmdline_parse_token_string_t cmd_setmask_mask =
3618         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3619                                  "coremask#portmask");
3620 cmdline_parse_token_num_t cmd_setmask_value =
3621         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3622
3623 cmdline_parse_inst_t cmd_set_fwd_mask = {
3624         .f = cmd_set_mask_parsed,
3625         .data = NULL,
3626         .help_str = "set coremask|portmask <hexadecimal value>",
3627         .tokens = {
3628                 (void *)&cmd_setmask_set,
3629                 (void *)&cmd_setmask_mask,
3630                 (void *)&cmd_setmask_value,
3631                 NULL,
3632         },
3633 };
3634
3635 /*
3636  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3637  */
3638 struct cmd_set_result {
3639         cmdline_fixed_string_t set;
3640         cmdline_fixed_string_t what;
3641         uint16_t value;
3642 };
3643
3644 static void cmd_set_parsed(void *parsed_result,
3645                            __attribute__((unused)) struct cmdline *cl,
3646                            __attribute__((unused)) void *data)
3647 {
3648         struct cmd_set_result *res = parsed_result;
3649         if (!strcmp(res->what, "nbport")) {
3650                 set_fwd_ports_number(res->value);
3651                 fwd_config_setup();
3652         } else if (!strcmp(res->what, "nbcore")) {
3653                 set_fwd_lcores_number(res->value);
3654                 fwd_config_setup();
3655         } else if (!strcmp(res->what, "burst"))
3656                 set_nb_pkt_per_burst(res->value);
3657         else if (!strcmp(res->what, "verbose"))
3658                 set_verbose_level(res->value);
3659 }
3660
3661 cmdline_parse_token_string_t cmd_set_set =
3662         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3663 cmdline_parse_token_string_t cmd_set_what =
3664         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3665                                  "nbport#nbcore#burst#verbose");
3666 cmdline_parse_token_num_t cmd_set_value =
3667         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3668
3669 cmdline_parse_inst_t cmd_set_numbers = {
3670         .f = cmd_set_parsed,
3671         .data = NULL,
3672         .help_str = "set nbport|nbcore|burst|verbose <value>",
3673         .tokens = {
3674                 (void *)&cmd_set_set,
3675                 (void *)&cmd_set_what,
3676                 (void *)&cmd_set_value,
3677                 NULL,
3678         },
3679 };
3680
3681 /* *** SET LOG LEVEL CONFIGURATION *** */
3682
3683 struct cmd_set_log_result {
3684         cmdline_fixed_string_t set;
3685         cmdline_fixed_string_t log;
3686         cmdline_fixed_string_t type;
3687         uint32_t level;
3688 };
3689
3690 static void
3691 cmd_set_log_parsed(void *parsed_result,
3692                    __attribute__((unused)) struct cmdline *cl,
3693                    __attribute__((unused)) void *data)
3694 {
3695         struct cmd_set_log_result *res;
3696         int ret;
3697
3698         res = parsed_result;
3699         if (!strcmp(res->type, "global"))
3700                 rte_log_set_global_level(res->level);
3701         else {
3702                 ret = rte_log_set_level_regexp(res->type, res->level);
3703                 if (ret < 0)
3704                         printf("Unable to set log level\n");
3705         }
3706 }
3707
3708 cmdline_parse_token_string_t cmd_set_log_set =
3709         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3710 cmdline_parse_token_string_t cmd_set_log_log =
3711         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3712 cmdline_parse_token_string_t cmd_set_log_type =
3713         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3714 cmdline_parse_token_num_t cmd_set_log_level =
3715         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3716
3717 cmdline_parse_inst_t cmd_set_log = {
3718         .f = cmd_set_log_parsed,
3719         .data = NULL,
3720         .help_str = "set log global|<type> <level>",
3721         .tokens = {
3722                 (void *)&cmd_set_log_set,
3723                 (void *)&cmd_set_log_log,
3724                 (void *)&cmd_set_log_type,
3725                 (void *)&cmd_set_log_level,
3726                 NULL,
3727         },
3728 };
3729
3730 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3731
3732 struct cmd_set_txpkts_result {
3733         cmdline_fixed_string_t cmd_keyword;
3734         cmdline_fixed_string_t txpkts;
3735         cmdline_fixed_string_t seg_lengths;
3736 };
3737
3738 static void
3739 cmd_set_txpkts_parsed(void *parsed_result,
3740                       __attribute__((unused)) struct cmdline *cl,
3741                       __attribute__((unused)) void *data)
3742 {
3743         struct cmd_set_txpkts_result *res;
3744         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3745         unsigned int nb_segs;
3746
3747         res = parsed_result;
3748         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3749                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3750         if (nb_segs > 0)
3751                 set_tx_pkt_segments(seg_lengths, nb_segs);
3752 }
3753
3754 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3755         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3756                                  cmd_keyword, "set");
3757 cmdline_parse_token_string_t cmd_set_txpkts_name =
3758         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3759                                  txpkts, "txpkts");
3760 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3761         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3762                                  seg_lengths, NULL);
3763
3764 cmdline_parse_inst_t cmd_set_txpkts = {
3765         .f = cmd_set_txpkts_parsed,
3766         .data = NULL,
3767         .help_str = "set txpkts <len0[,len1]*>",
3768         .tokens = {
3769                 (void *)&cmd_set_txpkts_keyword,
3770                 (void *)&cmd_set_txpkts_name,
3771                 (void *)&cmd_set_txpkts_lengths,
3772                 NULL,
3773         },
3774 };
3775
3776 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3777
3778 struct cmd_set_txsplit_result {
3779         cmdline_fixed_string_t cmd_keyword;
3780         cmdline_fixed_string_t txsplit;
3781         cmdline_fixed_string_t mode;
3782 };
3783
3784 static void
3785 cmd_set_txsplit_parsed(void *parsed_result,
3786                       __attribute__((unused)) struct cmdline *cl,
3787                       __attribute__((unused)) void *data)
3788 {
3789         struct cmd_set_txsplit_result *res;
3790
3791         res = parsed_result;
3792         set_tx_pkt_split(res->mode);
3793 }
3794
3795 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3796         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3797                                  cmd_keyword, "set");
3798 cmdline_parse_token_string_t cmd_set_txsplit_name =
3799         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3800                                  txsplit, "txsplit");
3801 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3802         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3803                                  mode, NULL);
3804
3805 cmdline_parse_inst_t cmd_set_txsplit = {
3806         .f = cmd_set_txsplit_parsed,
3807         .data = NULL,
3808         .help_str = "set txsplit on|off|rand",
3809         .tokens = {
3810                 (void *)&cmd_set_txsplit_keyword,
3811                 (void *)&cmd_set_txsplit_name,
3812                 (void *)&cmd_set_txsplit_mode,
3813                 NULL,
3814         },
3815 };
3816
3817 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3818 struct cmd_rx_vlan_filter_all_result {
3819         cmdline_fixed_string_t rx_vlan;
3820         cmdline_fixed_string_t what;
3821         cmdline_fixed_string_t all;
3822         portid_t port_id;
3823 };
3824
3825 static void
3826 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3827                               __attribute__((unused)) struct cmdline *cl,
3828                               __attribute__((unused)) void *data)
3829 {
3830         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3831
3832         if (!strcmp(res->what, "add"))
3833                 rx_vlan_all_filter_set(res->port_id, 1);
3834         else
3835                 rx_vlan_all_filter_set(res->port_id, 0);
3836 }
3837
3838 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3839         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3840                                  rx_vlan, "rx_vlan");
3841 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3842         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3843                                  what, "add#rm");
3844 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3845         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3846                                  all, "all");
3847 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3848         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3849                               port_id, UINT16);
3850
3851 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3852         .f = cmd_rx_vlan_filter_all_parsed,
3853         .data = NULL,
3854         .help_str = "rx_vlan add|rm all <port_id>: "
3855                 "Add/Remove all identifiers to/from the set of VLAN "
3856                 "identifiers filtered by a port",
3857         .tokens = {
3858                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3859                 (void *)&cmd_rx_vlan_filter_all_what,
3860                 (void *)&cmd_rx_vlan_filter_all_all,
3861                 (void *)&cmd_rx_vlan_filter_all_portid,
3862                 NULL,
3863         },
3864 };
3865
3866 /* *** VLAN OFFLOAD SET ON A PORT *** */
3867 struct cmd_vlan_offload_result {
3868         cmdline_fixed_string_t vlan;
3869         cmdline_fixed_string_t set;
3870         cmdline_fixed_string_t vlan_type;
3871         cmdline_fixed_string_t what;
3872         cmdline_fixed_string_t on;
3873         cmdline_fixed_string_t port_id;
3874 };
3875
3876 static void
3877 cmd_vlan_offload_parsed(void *parsed_result,
3878                           __attribute__((unused)) struct cmdline *cl,
3879                           __attribute__((unused)) void *data)
3880 {
3881         int on;
3882         struct cmd_vlan_offload_result *res = parsed_result;
3883         char *str;
3884         int i, len = 0;
3885         portid_t port_id = 0;
3886         unsigned int tmp;
3887
3888         str = res->port_id;
3889         len = strnlen(str, STR_TOKEN_SIZE);
3890         i = 0;
3891         /* Get port_id first */
3892         while(i < len){
3893                 if(str[i] == ',')
3894                         break;
3895
3896                 i++;
3897         }
3898         str[i]='\0';
3899         tmp = strtoul(str, NULL, 0);
3900         /* If port_id greater that what portid_t can represent, return */
3901         if(tmp >= RTE_MAX_ETHPORTS)
3902                 return;
3903         port_id = (portid_t)tmp;
3904
3905         if (!strcmp(res->on, "on"))
3906                 on = 1;
3907         else
3908                 on = 0;
3909
3910         if (!strcmp(res->what, "strip"))
3911                 rx_vlan_strip_set(port_id,  on);
3912         else if(!strcmp(res->what, "stripq")){
3913                 uint16_t queue_id = 0;
3914
3915                 /* No queue_id, return */
3916                 if(i + 1 >= len) {
3917                         printf("must specify (port,queue_id)\n");
3918                         return;
3919                 }
3920                 tmp = strtoul(str + i + 1, NULL, 0);
3921                 /* If queue_id greater that what 16-bits can represent, return */
3922                 if(tmp > 0xffff)
3923                         return;
3924
3925                 queue_id = (uint16_t)tmp;
3926                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3927         }
3928         else if (!strcmp(res->what, "filter"))
3929                 rx_vlan_filter_set(port_id, on);
3930         else if (!strcmp(res->what, "qinq_strip"))
3931                 rx_vlan_qinq_strip_set(port_id, on);
3932         else
3933                 vlan_extend_set(port_id, on);
3934
3935         return;
3936 }
3937
3938 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3939         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3940                                  vlan, "vlan");
3941 cmdline_parse_token_string_t cmd_vlan_offload_set =
3942         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3943                                  set, "set");
3944 cmdline_parse_token_string_t cmd_vlan_offload_what =
3945         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3946                                 what, "strip#filter#qinq_strip#extend#stripq");
3947 cmdline_parse_token_string_t cmd_vlan_offload_on =
3948         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3949                               on, "on#off");
3950 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3951         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3952                               port_id, NULL);
3953
3954 cmdline_parse_inst_t cmd_vlan_offload = {
3955         .f = cmd_vlan_offload_parsed,
3956         .data = NULL,
3957         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
3958                 "<port_id[,queue_id]>: "
3959                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
3960         .tokens = {
3961                 (void *)&cmd_vlan_offload_vlan,
3962                 (void *)&cmd_vlan_offload_set,
3963                 (void *)&cmd_vlan_offload_what,
3964                 (void *)&cmd_vlan_offload_on,
3965                 (void *)&cmd_vlan_offload_portid,
3966                 NULL,
3967         },
3968 };
3969
3970 /* *** VLAN TPID SET ON A PORT *** */
3971 struct cmd_vlan_tpid_result {
3972         cmdline_fixed_string_t vlan;
3973         cmdline_fixed_string_t set;
3974         cmdline_fixed_string_t vlan_type;
3975         cmdline_fixed_string_t what;
3976         uint16_t tp_id;
3977         portid_t port_id;
3978 };
3979
3980 static void
3981 cmd_vlan_tpid_parsed(void *parsed_result,
3982                           __attribute__((unused)) struct cmdline *cl,
3983                           __attribute__((unused)) void *data)
3984 {
3985         struct cmd_vlan_tpid_result *res = parsed_result;
3986         enum rte_vlan_type vlan_type;
3987
3988         if (!strcmp(res->vlan_type, "inner"))
3989                 vlan_type = ETH_VLAN_TYPE_INNER;
3990         else if (!strcmp(res->vlan_type, "outer"))
3991                 vlan_type = ETH_VLAN_TYPE_OUTER;
3992         else {
3993                 printf("Unknown vlan type\n");
3994                 return;
3995         }
3996         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3997 }
3998
3999 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4000         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4001                                  vlan, "vlan");
4002 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4003         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4004                                  set, "set");
4005 cmdline_parse_token_string_t cmd_vlan_type =
4006         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4007                                  vlan_type, "inner#outer");
4008 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4009         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4010                                  what, "tpid");
4011 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4012         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4013                               tp_id, UINT16);
4014 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4015         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4016                               port_id, UINT16);
4017
4018 cmdline_parse_inst_t cmd_vlan_tpid = {
4019         .f = cmd_vlan_tpid_parsed,
4020         .data = NULL,
4021         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4022                 "Set the VLAN Ether type",
4023         .tokens = {
4024                 (void *)&cmd_vlan_tpid_vlan,
4025                 (void *)&cmd_vlan_tpid_set,
4026                 (void *)&cmd_vlan_type,
4027                 (void *)&cmd_vlan_tpid_what,
4028                 (void *)&cmd_vlan_tpid_tpid,
4029                 (void *)&cmd_vlan_tpid_portid,
4030                 NULL,
4031         },
4032 };
4033
4034 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4035 struct cmd_rx_vlan_filter_result {
4036         cmdline_fixed_string_t rx_vlan;
4037         cmdline_fixed_string_t what;
4038         uint16_t vlan_id;
4039         portid_t port_id;
4040 };
4041
4042 static void
4043 cmd_rx_vlan_filter_parsed(void *parsed_result,
4044                           __attribute__((unused)) struct cmdline *cl,
4045                           __attribute__((unused)) void *data)
4046 {
4047         struct cmd_rx_vlan_filter_result *res = parsed_result;
4048
4049         if (!strcmp(res->what, "add"))
4050                 rx_vft_set(res->port_id, res->vlan_id, 1);
4051         else
4052                 rx_vft_set(res->port_id, res->vlan_id, 0);
4053 }
4054
4055 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4056         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4057                                  rx_vlan, "rx_vlan");
4058 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4059         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4060                                  what, "add#rm");
4061 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4062         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4063                               vlan_id, UINT16);
4064 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4065         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4066                               port_id, UINT16);
4067
4068 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4069         .f = cmd_rx_vlan_filter_parsed,
4070         .data = NULL,
4071         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4072                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4073                 "identifiers filtered by a port",
4074         .tokens = {
4075                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4076                 (void *)&cmd_rx_vlan_filter_what,
4077                 (void *)&cmd_rx_vlan_filter_vlanid,
4078                 (void *)&cmd_rx_vlan_filter_portid,
4079                 NULL,
4080         },
4081 };
4082
4083 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4084 struct cmd_tx_vlan_set_result {
4085         cmdline_fixed_string_t tx_vlan;
4086         cmdline_fixed_string_t set;
4087         portid_t port_id;
4088         uint16_t vlan_id;
4089 };
4090
4091 static void
4092 cmd_tx_vlan_set_parsed(void *parsed_result,
4093                        __attribute__((unused)) struct cmdline *cl,
4094                        __attribute__((unused)) void *data)
4095 {
4096         struct cmd_tx_vlan_set_result *res = parsed_result;
4097
4098         if (!port_is_stopped(res->port_id)) {
4099                 printf("Please stop port %d first\n", res->port_id);
4100                 return;
4101         }
4102
4103         tx_vlan_set(res->port_id, res->vlan_id);
4104
4105         cmd_reconfig_device_queue(res->port_id, 1, 1);
4106 }
4107
4108 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4109         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4110                                  tx_vlan, "tx_vlan");
4111 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4112         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4113                                  set, "set");
4114 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4115         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4116                               port_id, UINT16);
4117 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4118         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4119                               vlan_id, UINT16);
4120
4121 cmdline_parse_inst_t cmd_tx_vlan_set = {
4122         .f = cmd_tx_vlan_set_parsed,
4123         .data = NULL,
4124         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4125                 "Enable hardware insertion of a single VLAN header "
4126                 "with a given TAG Identifier in packets sent on a port",
4127         .tokens = {
4128                 (void *)&cmd_tx_vlan_set_tx_vlan,
4129                 (void *)&cmd_tx_vlan_set_set,
4130                 (void *)&cmd_tx_vlan_set_portid,
4131                 (void *)&cmd_tx_vlan_set_vlanid,
4132                 NULL,
4133         },
4134 };
4135
4136 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4137 struct cmd_tx_vlan_set_qinq_result {
4138         cmdline_fixed_string_t tx_vlan;
4139         cmdline_fixed_string_t set;
4140         portid_t port_id;
4141         uint16_t vlan_id;
4142         uint16_t vlan_id_outer;
4143 };
4144
4145 static void
4146 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4147                             __attribute__((unused)) struct cmdline *cl,
4148                             __attribute__((unused)) void *data)
4149 {
4150         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4151
4152         if (!port_is_stopped(res->port_id)) {
4153                 printf("Please stop port %d first\n", res->port_id);
4154                 return;
4155         }
4156
4157         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4158
4159         cmd_reconfig_device_queue(res->port_id, 1, 1);
4160 }
4161
4162 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4163         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4164                 tx_vlan, "tx_vlan");
4165 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4166         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4167                 set, "set");
4168 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4169         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4170                 port_id, UINT16);
4171 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4172         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4173                 vlan_id, UINT16);
4174 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4175         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4176                 vlan_id_outer, UINT16);
4177
4178 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4179         .f = cmd_tx_vlan_set_qinq_parsed,
4180         .data = NULL,
4181         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4182                 "Enable hardware insertion of double VLAN header "
4183                 "with given TAG Identifiers in packets sent on a port",
4184         .tokens = {
4185                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4186                 (void *)&cmd_tx_vlan_set_qinq_set,
4187                 (void *)&cmd_tx_vlan_set_qinq_portid,
4188                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4189                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4190                 NULL,
4191         },
4192 };
4193
4194 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4195 struct cmd_tx_vlan_set_pvid_result {
4196         cmdline_fixed_string_t tx_vlan;
4197         cmdline_fixed_string_t set;
4198         cmdline_fixed_string_t pvid;
4199         portid_t port_id;
4200         uint16_t vlan_id;
4201         cmdline_fixed_string_t mode;
4202 };
4203
4204 static void
4205 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4206                             __attribute__((unused)) struct cmdline *cl,
4207                             __attribute__((unused)) void *data)
4208 {
4209         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4210
4211         if (strcmp(res->mode, "on") == 0)
4212                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4213         else
4214                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4215 }
4216
4217 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4218         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4219                                  tx_vlan, "tx_vlan");
4220 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4221         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4222                                  set, "set");
4223 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4224         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4225                                  pvid, "pvid");
4226 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4227         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4228                              port_id, UINT16);
4229 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4230         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4231                               vlan_id, UINT16);
4232 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4233         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4234                                  mode, "on#off");
4235
4236 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4237         .f = cmd_tx_vlan_set_pvid_parsed,
4238         .data = NULL,
4239         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4240         .tokens = {
4241                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4242                 (void *)&cmd_tx_vlan_set_pvid_set,
4243                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4244                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4245                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4246                 (void *)&cmd_tx_vlan_set_pvid_mode,
4247                 NULL,
4248         },
4249 };
4250
4251 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4252 struct cmd_tx_vlan_reset_result {
4253         cmdline_fixed_string_t tx_vlan;
4254         cmdline_fixed_string_t reset;
4255         portid_t port_id;
4256 };
4257
4258 static void
4259 cmd_tx_vlan_reset_parsed(void *parsed_result,
4260                          __attribute__((unused)) struct cmdline *cl,
4261                          __attribute__((unused)) void *data)
4262 {
4263         struct cmd_tx_vlan_reset_result *res = parsed_result;
4264
4265         if (!port_is_stopped(res->port_id)) {
4266                 printf("Please stop port %d first\n", res->port_id);
4267                 return;
4268         }
4269
4270         tx_vlan_reset(res->port_id);
4271
4272         cmd_reconfig_device_queue(res->port_id, 1, 1);
4273 }
4274
4275 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4276         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4277                                  tx_vlan, "tx_vlan");
4278 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4279         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4280                                  reset, "reset");
4281 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4282         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4283                               port_id, UINT16);
4284
4285 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4286         .f = cmd_tx_vlan_reset_parsed,
4287         .data = NULL,
4288         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4289                 "VLAN header in packets sent on a port",
4290         .tokens = {
4291                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4292                 (void *)&cmd_tx_vlan_reset_reset,
4293                 (void *)&cmd_tx_vlan_reset_portid,
4294                 NULL,
4295         },
4296 };
4297
4298
4299 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4300 struct cmd_csum_result {
4301         cmdline_fixed_string_t csum;
4302         cmdline_fixed_string_t mode;
4303         cmdline_fixed_string_t proto;
4304         cmdline_fixed_string_t hwsw;
4305         portid_t port_id;
4306 };
4307
4308 static void
4309 csum_show(int port_id)
4310 {
4311         struct rte_eth_dev_info dev_info;
4312         uint64_t tx_offloads;
4313         int ret;
4314
4315         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4316         printf("Parse tunnel is %s\n",
4317                 (ports[port_id].parse_tunnel) ? "on" : "off");
4318         printf("IP checksum offload is %s\n",
4319                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4320         printf("UDP checksum offload is %s\n",
4321                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4322         printf("TCP checksum offload is %s\n",
4323                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4324         printf("SCTP checksum offload is %s\n",
4325                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4326         printf("Outer-Ip checksum offload is %s\n",
4327                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4328         printf("Outer-Udp checksum offload is %s\n",
4329                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4330
4331         /* display warnings if configuration is not supported by the NIC */
4332         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4333         if (ret != 0)
4334                 return;
4335
4336         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4337                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4338                 printf("Warning: hardware IP checksum enabled but not "
4339                         "supported by port %d\n", port_id);
4340         }
4341         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4342                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4343                 printf("Warning: hardware UDP checksum enabled but not "
4344                         "supported by port %d\n", port_id);
4345         }
4346         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4347                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4348                 printf("Warning: hardware TCP checksum enabled but not "
4349                         "supported by port %d\n", port_id);
4350         }
4351         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4352                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4353                 printf("Warning: hardware SCTP checksum enabled but not "
4354                         "supported by port %d\n", port_id);
4355         }
4356         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4357                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4358                 printf("Warning: hardware outer IP checksum enabled but not "
4359                         "supported by port %d\n", port_id);
4360         }
4361         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4362                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4363                         == 0) {
4364                 printf("Warning: hardware outer UDP checksum enabled but not "
4365                         "supported by port %d\n", port_id);
4366         }
4367 }
4368
4369 static void
4370 cmd_config_queue_tx_offloads(struct rte_port *port)
4371 {
4372         int k;
4373
4374         /* Apply queue tx offloads configuration */
4375         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4376                 port->tx_conf[k].offloads =
4377                         port->dev_conf.txmode.offloads;
4378 }
4379
4380 static void
4381 cmd_csum_parsed(void *parsed_result,
4382                        __attribute__((unused)) struct cmdline *cl,
4383                        __attribute__((unused)) void *data)
4384 {
4385         struct cmd_csum_result *res = parsed_result;
4386         int hw = 0;
4387         uint64_t csum_offloads = 0;
4388         struct rte_eth_dev_info dev_info;
4389         int ret;
4390
4391         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4392                 printf("invalid port %d\n", res->port_id);
4393                 return;
4394         }
4395         if (!port_is_stopped(res->port_id)) {
4396                 printf("Please stop port %d first\n", res->port_id);
4397                 return;
4398         }
4399
4400         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4401         if (ret != 0)
4402                 return;
4403
4404         if (!strcmp(res->mode, "set")) {
4405
4406                 if (!strcmp(res->hwsw, "hw"))
4407                         hw = 1;
4408
4409                 if (!strcmp(res->proto, "ip")) {
4410                         if (hw == 0 || (dev_info.tx_offload_capa &
4411                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4412                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4413                         } else {
4414                                 printf("IP checksum offload is not supported "
4415                                        "by port %u\n", res->port_id);
4416                         }
4417                 } else if (!strcmp(res->proto, "udp")) {
4418                         if (hw == 0 || (dev_info.tx_offload_capa &
4419                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4420                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4421                         } else {
4422                                 printf("UDP checksum offload is not supported "
4423                                        "by port %u\n", res->port_id);
4424                         }
4425                 } else if (!strcmp(res->proto, "tcp")) {
4426                         if (hw == 0 || (dev_info.tx_offload_capa &
4427                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4428                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4429                         } else {
4430                                 printf("TCP checksum offload is not supported "
4431                                        "by port %u\n", res->port_id);
4432                         }
4433                 } else if (!strcmp(res->proto, "sctp")) {
4434                         if (hw == 0 || (dev_info.tx_offload_capa &
4435                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4436                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4437                         } else {
4438                                 printf("SCTP checksum offload is not supported "
4439                                        "by port %u\n", res->port_id);
4440                         }
4441                 } else if (!strcmp(res->proto, "outer-ip")) {
4442                         if (hw == 0 || (dev_info.tx_offload_capa &
4443                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4444                                 csum_offloads |=
4445                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4446                         } else {
4447                                 printf("Outer IP checksum offload is not "
4448                                        "supported by port %u\n", res->port_id);
4449                         }
4450                 } else if (!strcmp(res->proto, "outer-udp")) {
4451                         if (hw == 0 || (dev_info.tx_offload_capa &
4452                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4453                                 csum_offloads |=
4454                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4455                         } else {
4456                                 printf("Outer UDP checksum offload is not "
4457                                        "supported by port %u\n", res->port_id);
4458                         }
4459                 }
4460
4461                 if (hw) {
4462                         ports[res->port_id].dev_conf.txmode.offloads |=
4463                                                         csum_offloads;
4464                 } else {
4465                         ports[res->port_id].dev_conf.txmode.offloads &=
4466                                                         (~csum_offloads);
4467                 }
4468                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4469         }
4470         csum_show(res->port_id);
4471
4472         cmd_reconfig_device_queue(res->port_id, 1, 1);
4473 }
4474
4475 cmdline_parse_token_string_t cmd_csum_csum =
4476         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4477                                 csum, "csum");
4478 cmdline_parse_token_string_t cmd_csum_mode =
4479         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4480                                 mode, "set");
4481 cmdline_parse_token_string_t cmd_csum_proto =
4482         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4483                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4484 cmdline_parse_token_string_t cmd_csum_hwsw =
4485         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4486                                 hwsw, "hw#sw");
4487 cmdline_parse_token_num_t cmd_csum_portid =
4488         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4489                                 port_id, UINT16);
4490
4491 cmdline_parse_inst_t cmd_csum_set = {
4492         .f = cmd_csum_parsed,
4493         .data = NULL,
4494         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4495                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4496                 "using csum forward engine",
4497         .tokens = {
4498                 (void *)&cmd_csum_csum,
4499                 (void *)&cmd_csum_mode,
4500                 (void *)&cmd_csum_proto,
4501                 (void *)&cmd_csum_hwsw,
4502                 (void *)&cmd_csum_portid,
4503                 NULL,
4504         },
4505 };
4506
4507 cmdline_parse_token_string_t cmd_csum_mode_show =
4508         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4509                                 mode, "show");
4510
4511 cmdline_parse_inst_t cmd_csum_show = {
4512         .f = cmd_csum_parsed,
4513         .data = NULL,
4514         .help_str = "csum show <port_id>: Show checksum offload configuration",
4515         .tokens = {
4516                 (void *)&cmd_csum_csum,
4517                 (void *)&cmd_csum_mode_show,
4518                 (void *)&cmd_csum_portid,
4519                 NULL,
4520         },
4521 };
4522
4523 /* Enable/disable tunnel parsing */
4524 struct cmd_csum_tunnel_result {
4525         cmdline_fixed_string_t csum;
4526         cmdline_fixed_string_t parse;
4527         cmdline_fixed_string_t onoff;
4528         portid_t port_id;
4529 };
4530
4531 static void
4532 cmd_csum_tunnel_parsed(void *parsed_result,
4533                        __attribute__((unused)) struct cmdline *cl,
4534                        __attribute__((unused)) void *data)
4535 {
4536         struct cmd_csum_tunnel_result *res = parsed_result;
4537
4538         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4539                 return;
4540
4541         if (!strcmp(res->onoff, "on"))
4542                 ports[res->port_id].parse_tunnel = 1;
4543         else
4544                 ports[res->port_id].parse_tunnel = 0;
4545
4546         csum_show(res->port_id);
4547 }
4548
4549 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4550         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4551                                 csum, "csum");
4552 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4553         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4554                                 parse, "parse-tunnel");
4555 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4556         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4557                                 onoff, "on#off");
4558 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4559         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4560                                 port_id, UINT16);
4561
4562 cmdline_parse_inst_t cmd_csum_tunnel = {
4563         .f = cmd_csum_tunnel_parsed,
4564         .data = NULL,
4565         .help_str = "csum parse-tunnel on|off <port_id>: "
4566                 "Enable/Disable parsing of tunnels for csum engine",
4567         .tokens = {
4568                 (void *)&cmd_csum_tunnel_csum,
4569                 (void *)&cmd_csum_tunnel_parse,
4570                 (void *)&cmd_csum_tunnel_onoff,
4571                 (void *)&cmd_csum_tunnel_portid,
4572                 NULL,
4573         },
4574 };
4575
4576 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4577 struct cmd_tso_set_result {
4578         cmdline_fixed_string_t tso;
4579         cmdline_fixed_string_t mode;
4580         uint16_t tso_segsz;
4581         portid_t port_id;
4582 };
4583
4584 static void
4585 cmd_tso_set_parsed(void *parsed_result,
4586                        __attribute__((unused)) struct cmdline *cl,
4587                        __attribute__((unused)) void *data)
4588 {
4589         struct cmd_tso_set_result *res = parsed_result;
4590         struct rte_eth_dev_info dev_info;
4591         int ret;
4592
4593         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4594                 return;
4595         if (!port_is_stopped(res->port_id)) {
4596                 printf("Please stop port %d first\n", res->port_id);
4597                 return;
4598         }
4599
4600         if (!strcmp(res->mode, "set"))
4601                 ports[res->port_id].tso_segsz = res->tso_segsz;
4602
4603         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4604         if (ret != 0)
4605                 return;
4606
4607         if ((ports[res->port_id].tso_segsz != 0) &&
4608                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4609                 printf("Error: TSO is not supported by port %d\n",
4610                        res->port_id);
4611                 return;
4612         }
4613
4614         if (ports[res->port_id].tso_segsz == 0) {
4615                 ports[res->port_id].dev_conf.txmode.offloads &=
4616                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4617                 printf("TSO for non-tunneled packets is disabled\n");
4618         } else {
4619                 ports[res->port_id].dev_conf.txmode.offloads |=
4620                                                 DEV_TX_OFFLOAD_TCP_TSO;
4621                 printf("TSO segment size for non-tunneled packets is %d\n",
4622                         ports[res->port_id].tso_segsz);
4623         }
4624         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4625
4626         /* display warnings if configuration is not supported by the NIC */
4627         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4628         if (ret != 0)
4629                 return;
4630
4631         if ((ports[res->port_id].tso_segsz != 0) &&
4632                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4633                 printf("Warning: TSO enabled but not "
4634                         "supported by port %d\n", res->port_id);
4635         }
4636
4637         cmd_reconfig_device_queue(res->port_id, 1, 1);
4638 }
4639
4640 cmdline_parse_token_string_t cmd_tso_set_tso =
4641         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4642                                 tso, "tso");
4643 cmdline_parse_token_string_t cmd_tso_set_mode =
4644         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4645                                 mode, "set");
4646 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4647         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4648                                 tso_segsz, UINT16);
4649 cmdline_parse_token_num_t cmd_tso_set_portid =
4650         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4651                                 port_id, UINT16);
4652
4653 cmdline_parse_inst_t cmd_tso_set = {
4654         .f = cmd_tso_set_parsed,
4655         .data = NULL,
4656         .help_str = "tso set <tso_segsz> <port_id>: "
4657                 "Set TSO segment size of non-tunneled packets for csum engine "
4658                 "(0 to disable)",
4659         .tokens = {
4660                 (void *)&cmd_tso_set_tso,
4661                 (void *)&cmd_tso_set_mode,
4662                 (void *)&cmd_tso_set_tso_segsz,
4663                 (void *)&cmd_tso_set_portid,
4664                 NULL,
4665         },
4666 };
4667
4668 cmdline_parse_token_string_t cmd_tso_show_mode =
4669         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4670                                 mode, "show");
4671
4672
4673 cmdline_parse_inst_t cmd_tso_show = {
4674         .f = cmd_tso_set_parsed,
4675         .data = NULL,
4676         .help_str = "tso show <port_id>: "
4677                 "Show TSO segment size of non-tunneled packets for csum engine",
4678         .tokens = {
4679                 (void *)&cmd_tso_set_tso,
4680                 (void *)&cmd_tso_show_mode,
4681                 (void *)&cmd_tso_set_portid,
4682                 NULL,
4683         },
4684 };
4685
4686 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4687 struct cmd_tunnel_tso_set_result {
4688         cmdline_fixed_string_t tso;
4689         cmdline_fixed_string_t mode;
4690         uint16_t tso_segsz;
4691         portid_t port_id;
4692 };
4693
4694 static struct rte_eth_dev_info
4695 check_tunnel_tso_nic_support(portid_t port_id)
4696 {
4697         struct rte_eth_dev_info dev_info;
4698
4699         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4700                 return dev_info;
4701
4702         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4703                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4704                        "not enabled for port %d\n", port_id);
4705         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4706                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4707                        "not enabled for port %d\n", port_id);
4708         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4709                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4710                        "not enabled for port %d\n", port_id);
4711         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4712                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4713                        "not enabled for port %d\n", port_id);
4714         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4715                 printf("Warning: IP TUNNEL TSO not supported therefore "
4716                        "not enabled for port %d\n", port_id);
4717         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4718                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4719                        "not enabled for port %d\n", port_id);
4720         return dev_info;
4721 }
4722
4723 static void
4724 cmd_tunnel_tso_set_parsed(void *parsed_result,
4725                           __attribute__((unused)) struct cmdline *cl,
4726                           __attribute__((unused)) void *data)
4727 {
4728         struct cmd_tunnel_tso_set_result *res = parsed_result;
4729         struct rte_eth_dev_info dev_info;
4730
4731         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4732                 return;
4733         if (!port_is_stopped(res->port_id)) {
4734                 printf("Please stop port %d first\n", res->port_id);
4735                 return;
4736         }
4737
4738         if (!strcmp(res->mode, "set"))
4739                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4740
4741         dev_info = check_tunnel_tso_nic_support(res->port_id);
4742         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4743                 ports[res->port_id].dev_conf.txmode.offloads &=
4744                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4745                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4746                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4747                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4748                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4749                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4750                 printf("TSO for tunneled packets is disabled\n");
4751         } else {
4752                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4753                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4754                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4755                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4756                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4757                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4758
4759                 ports[res->port_id].dev_conf.txmode.offloads |=
4760                         (tso_offloads & dev_info.tx_offload_capa);
4761                 printf("TSO segment size for tunneled packets is %d\n",
4762                         ports[res->port_id].tunnel_tso_segsz);
4763
4764                 /* Below conditions are needed to make it work:
4765                  * (1) tunnel TSO is supported by the NIC;
4766                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4767                  * are recognized;
4768                  * (3) for tunneled pkts with outer L3 of IPv4,
4769                  * "csum set outer-ip" must be set to hw, because after tso,
4770                  * total_len of outer IP header is changed, and the checksum
4771                  * of outer IP header calculated by sw should be wrong; that
4772                  * is not necessary for IPv6 tunneled pkts because there's no
4773                  * checksum in IP header anymore.
4774                  */
4775
4776                 if (!ports[res->port_id].parse_tunnel)
4777                         printf("Warning: csum parse_tunnel must be set "
4778                                 "so that tunneled packets are recognized\n");
4779                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4780                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4781                         printf("Warning: csum set outer-ip must be set to hw "
4782                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4783         }
4784
4785         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4786         cmd_reconfig_device_queue(res->port_id, 1, 1);
4787 }
4788
4789 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4790         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4791                                 tso, "tunnel_tso");
4792 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4793         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4794                                 mode, "set");
4795 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4796         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4797                                 tso_segsz, UINT16);
4798 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4799         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4800                                 port_id, UINT16);
4801
4802 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4803         .f = cmd_tunnel_tso_set_parsed,
4804         .data = NULL,
4805         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4806                 "Set TSO segment size of tunneled packets for csum engine "
4807                 "(0 to disable)",
4808         .tokens = {
4809                 (void *)&cmd_tunnel_tso_set_tso,
4810                 (void *)&cmd_tunnel_tso_set_mode,
4811                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4812                 (void *)&cmd_tunnel_tso_set_portid,
4813                 NULL,
4814         },
4815 };
4816
4817 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4818         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4819                                 mode, "show");
4820
4821
4822 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4823         .f = cmd_tunnel_tso_set_parsed,
4824         .data = NULL,
4825         .help_str = "tunnel_tso show <port_id> "
4826                 "Show TSO segment size of tunneled packets for csum engine",
4827         .tokens = {
4828                 (void *)&cmd_tunnel_tso_set_tso,
4829                 (void *)&cmd_tunnel_tso_show_mode,
4830                 (void *)&cmd_tunnel_tso_set_portid,
4831                 NULL,
4832         },
4833 };
4834
4835 /* *** SET GRO FOR A PORT *** */
4836 struct cmd_gro_enable_result {
4837         cmdline_fixed_string_t cmd_set;
4838         cmdline_fixed_string_t cmd_port;
4839         cmdline_fixed_string_t cmd_keyword;
4840         cmdline_fixed_string_t cmd_onoff;
4841         portid_t cmd_pid;
4842 };
4843
4844 static void
4845 cmd_gro_enable_parsed(void *parsed_result,
4846                 __attribute__((unused)) struct cmdline *cl,
4847                 __attribute__((unused)) void *data)
4848 {
4849         struct cmd_gro_enable_result *res;
4850
4851         res = parsed_result;
4852         if (!strcmp(res->cmd_keyword, "gro"))
4853                 setup_gro(res->cmd_onoff, res->cmd_pid);
4854 }
4855
4856 cmdline_parse_token_string_t cmd_gro_enable_set =
4857         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4858                         cmd_set, "set");
4859 cmdline_parse_token_string_t cmd_gro_enable_port =
4860         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4861                         cmd_keyword, "port");
4862 cmdline_parse_token_num_t cmd_gro_enable_pid =
4863         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4864                         cmd_pid, UINT16);
4865 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4866         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4867                         cmd_keyword, "gro");
4868 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4869         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4870                         cmd_onoff, "on#off");
4871
4872 cmdline_parse_inst_t cmd_gro_enable = {
4873         .f = cmd_gro_enable_parsed,
4874         .data = NULL,
4875         .help_str = "set port <port_id> gro on|off",
4876         .tokens = {
4877                 (void *)&cmd_gro_enable_set,
4878                 (void *)&cmd_gro_enable_port,
4879                 (void *)&cmd_gro_enable_pid,
4880                 (void *)&cmd_gro_enable_keyword,
4881                 (void *)&cmd_gro_enable_onoff,
4882                 NULL,
4883         },
4884 };
4885
4886 /* *** DISPLAY GRO CONFIGURATION *** */
4887 struct cmd_gro_show_result {
4888         cmdline_fixed_string_t cmd_show;
4889         cmdline_fixed_string_t cmd_port;
4890         cmdline_fixed_string_t cmd_keyword;
4891         portid_t cmd_pid;
4892 };
4893
4894 static void
4895 cmd_gro_show_parsed(void *parsed_result,
4896                 __attribute__((unused)) struct cmdline *cl,
4897                 __attribute__((unused)) void *data)
4898 {
4899         struct cmd_gro_show_result *res;
4900
4901         res = parsed_result;
4902         if (!strcmp(res->cmd_keyword, "gro"))
4903                 show_gro(res->cmd_pid);
4904 }
4905
4906 cmdline_parse_token_string_t cmd_gro_show_show =
4907         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4908                         cmd_show, "show");
4909 cmdline_parse_token_string_t cmd_gro_show_port =
4910         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4911                         cmd_port, "port");
4912 cmdline_parse_token_num_t cmd_gro_show_pid =
4913         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4914                         cmd_pid, UINT16);
4915 cmdline_parse_token_string_t cmd_gro_show_keyword =
4916         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4917                         cmd_keyword, "gro");
4918
4919 cmdline_parse_inst_t cmd_gro_show = {
4920         .f = cmd_gro_show_parsed,
4921         .data = NULL,
4922         .help_str = "show port <port_id> gro",
4923         .tokens = {
4924                 (void *)&cmd_gro_show_show,
4925                 (void *)&cmd_gro_show_port,
4926                 (void *)&cmd_gro_show_pid,
4927                 (void *)&cmd_gro_show_keyword,
4928                 NULL,
4929         },
4930 };
4931
4932 /* *** SET FLUSH CYCLES FOR GRO *** */
4933 struct cmd_gro_flush_result {
4934         cmdline_fixed_string_t cmd_set;
4935         cmdline_fixed_string_t cmd_keyword;
4936         cmdline_fixed_string_t cmd_flush;
4937         uint8_t cmd_cycles;
4938 };
4939
4940 static void
4941 cmd_gro_flush_parsed(void *parsed_result,
4942                 __attribute__((unused)) struct cmdline *cl,
4943                 __attribute__((unused)) void *data)
4944 {
4945         struct cmd_gro_flush_result *res;
4946
4947         res = parsed_result;
4948         if ((!strcmp(res->cmd_keyword, "gro")) &&
4949                         (!strcmp(res->cmd_flush, "flush")))
4950                 setup_gro_flush_cycles(res->cmd_cycles);
4951 }
4952
4953 cmdline_parse_token_string_t cmd_gro_flush_set =
4954         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4955                         cmd_set, "set");
4956 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4957         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4958                         cmd_keyword, "gro");
4959 cmdline_parse_token_string_t cmd_gro_flush_flush =
4960         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4961                         cmd_flush, "flush");
4962 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4963         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4964                         cmd_cycles, UINT8);
4965
4966 cmdline_parse_inst_t cmd_gro_flush = {
4967         .f = cmd_gro_flush_parsed,
4968         .data = NULL,
4969         .help_str = "set gro flush <cycles>",
4970         .tokens = {
4971                 (void *)&cmd_gro_flush_set,
4972                 (void *)&cmd_gro_flush_keyword,
4973                 (void *)&cmd_gro_flush_flush,
4974                 (void *)&cmd_gro_flush_cycles,
4975                 NULL,
4976         },
4977 };
4978
4979 /* *** ENABLE/DISABLE GSO *** */
4980 struct cmd_gso_enable_result {
4981         cmdline_fixed_string_t cmd_set;
4982         cmdline_fixed_string_t cmd_port;
4983         cmdline_fixed_string_t cmd_keyword;
4984         cmdline_fixed_string_t cmd_mode;
4985         portid_t cmd_pid;
4986 };
4987
4988 static void
4989 cmd_gso_enable_parsed(void *parsed_result,
4990                 __attribute__((unused)) struct cmdline *cl,
4991                 __attribute__((unused)) void *data)
4992 {
4993         struct cmd_gso_enable_result *res;
4994
4995         res = parsed_result;
4996         if (!strcmp(res->cmd_keyword, "gso"))
4997                 setup_gso(res->cmd_mode, res->cmd_pid);
4998 }
4999
5000 cmdline_parse_token_string_t cmd_gso_enable_set =
5001         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5002                         cmd_set, "set");
5003 cmdline_parse_token_string_t cmd_gso_enable_port =
5004         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5005                         cmd_port, "port");
5006 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5007         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5008                         cmd_keyword, "gso");
5009 cmdline_parse_token_string_t cmd_gso_enable_mode =
5010         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5011                         cmd_mode, "on#off");
5012 cmdline_parse_token_num_t cmd_gso_enable_pid =
5013         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5014                         cmd_pid, UINT16);
5015
5016 cmdline_parse_inst_t cmd_gso_enable = {
5017         .f = cmd_gso_enable_parsed,
5018         .data = NULL,
5019         .help_str = "set port <port_id> gso on|off",
5020         .tokens = {
5021                 (void *)&cmd_gso_enable_set,
5022                 (void *)&cmd_gso_enable_port,
5023                 (void *)&cmd_gso_enable_pid,
5024                 (void *)&cmd_gso_enable_keyword,
5025                 (void *)&cmd_gso_enable_mode,
5026                 NULL,
5027         },
5028 };
5029
5030 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5031 struct cmd_gso_size_result {
5032         cmdline_fixed_string_t cmd_set;
5033         cmdline_fixed_string_t cmd_keyword;
5034         cmdline_fixed_string_t cmd_segsz;
5035         uint16_t cmd_size;
5036 };
5037
5038 static void
5039 cmd_gso_size_parsed(void *parsed_result,
5040                        __attribute__((unused)) struct cmdline *cl,
5041                        __attribute__((unused)) void *data)
5042 {
5043         struct cmd_gso_size_result *res = parsed_result;
5044
5045         if (test_done == 0) {
5046                 printf("Before setting GSO segsz, please first"
5047                                 " stop fowarding\n");
5048                 return;
5049         }
5050
5051         if (!strcmp(res->cmd_keyword, "gso") &&
5052                         !strcmp(res->cmd_segsz, "segsz")) {
5053                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5054                         printf("gso_size should be larger than %zu."
5055                                         " Please input a legal value\n",
5056                                         RTE_GSO_SEG_SIZE_MIN);
5057                 else
5058                         gso_max_segment_size = res->cmd_size;
5059         }
5060 }
5061
5062 cmdline_parse_token_string_t cmd_gso_size_set =
5063         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5064                                 cmd_set, "set");
5065 cmdline_parse_token_string_t cmd_gso_size_keyword =
5066         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5067                                 cmd_keyword, "gso");
5068 cmdline_parse_token_string_t cmd_gso_size_segsz =
5069         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5070                                 cmd_segsz, "segsz");
5071 cmdline_parse_token_num_t cmd_gso_size_size =
5072         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5073                                 cmd_size, UINT16);
5074
5075 cmdline_parse_inst_t cmd_gso_size = {
5076         .f = cmd_gso_size_parsed,
5077         .data = NULL,
5078         .help_str = "set gso segsz <length>",
5079         .tokens = {
5080                 (void *)&cmd_gso_size_set,
5081                 (void *)&cmd_gso_size_keyword,
5082                 (void *)&cmd_gso_size_segsz,
5083                 (void *)&cmd_gso_size_size,
5084                 NULL,
5085         },
5086 };
5087
5088 /* *** SHOW GSO CONFIGURATION *** */
5089 struct cmd_gso_show_result {
5090         cmdline_fixed_string_t cmd_show;
5091         cmdline_fixed_string_t cmd_port;
5092         cmdline_fixed_string_t cmd_keyword;
5093         portid_t cmd_pid;
5094 };
5095
5096 static void
5097 cmd_gso_show_parsed(void *parsed_result,
5098                        __attribute__((unused)) struct cmdline *cl,
5099                        __attribute__((unused)) void *data)
5100 {
5101         struct cmd_gso_show_result *res = parsed_result;
5102
5103         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5104                 printf("invalid port id %u\n", res->cmd_pid);
5105                 return;
5106         }
5107         if (!strcmp(res->cmd_keyword, "gso")) {
5108                 if (gso_ports[res->cmd_pid].enable) {
5109                         printf("Max GSO'd packet size: %uB\n"
5110                                         "Supported GSO types: TCP/IPv4, "
5111                                         "UDP/IPv4, VxLAN with inner "
5112                                         "TCP/IPv4 packet, GRE with inner "
5113                                         "TCP/IPv4 packet\n",
5114                                         gso_max_segment_size);
5115                 } else
5116                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5117         }
5118 }
5119
5120 cmdline_parse_token_string_t cmd_gso_show_show =
5121 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5122                 cmd_show, "show");
5123 cmdline_parse_token_string_t cmd_gso_show_port =
5124 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5125                 cmd_port, "port");
5126 cmdline_parse_token_string_t cmd_gso_show_keyword =
5127         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5128                                 cmd_keyword, "gso");
5129 cmdline_parse_token_num_t cmd_gso_show_pid =
5130         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5131                                 cmd_pid, UINT16);
5132
5133 cmdline_parse_inst_t cmd_gso_show = {
5134         .f = cmd_gso_show_parsed,
5135         .data = NULL,
5136         .help_str = "show port <port_id> gso",
5137         .tokens = {
5138                 (void *)&cmd_gso_show_show,
5139                 (void *)&cmd_gso_show_port,
5140                 (void *)&cmd_gso_show_pid,
5141                 (void *)&cmd_gso_show_keyword,
5142                 NULL,
5143         },
5144 };
5145
5146 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5147 struct cmd_set_flush_rx {
5148         cmdline_fixed_string_t set;
5149         cmdline_fixed_string_t flush_rx;
5150         cmdline_fixed_string_t mode;
5151 };
5152
5153 static void
5154 cmd_set_flush_rx_parsed(void *parsed_result,
5155                 __attribute__((unused)) struct cmdline *cl,
5156                 __attribute__((unused)) void *data)
5157 {
5158         struct cmd_set_flush_rx *res = parsed_result;
5159         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5160 }
5161
5162 cmdline_parse_token_string_t cmd_setflushrx_set =
5163         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5164                         set, "set");
5165 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5166         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5167                         flush_rx, "flush_rx");
5168 cmdline_parse_token_string_t cmd_setflushrx_mode =
5169         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5170                         mode, "on#off");
5171
5172
5173 cmdline_parse_inst_t cmd_set_flush_rx = {
5174         .f = cmd_set_flush_rx_parsed,
5175         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5176         .data = NULL,
5177         .tokens = {
5178                 (void *)&cmd_setflushrx_set,
5179                 (void *)&cmd_setflushrx_flush_rx,
5180                 (void *)&cmd_setflushrx_mode,
5181                 NULL,
5182         },
5183 };
5184
5185 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5186 struct cmd_set_link_check {
5187         cmdline_fixed_string_t set;
5188         cmdline_fixed_string_t link_check;
5189         cmdline_fixed_string_t mode;
5190 };
5191
5192 static void
5193 cmd_set_link_check_parsed(void *parsed_result,
5194                 __attribute__((unused)) struct cmdline *cl,
5195                 __attribute__((unused)) void *data)
5196 {
5197         struct cmd_set_link_check *res = parsed_result;
5198         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5199 }
5200
5201 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5202         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5203                         set, "set");
5204 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5205         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5206                         link_check, "link_check");
5207 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5208         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5209                         mode, "on#off");
5210
5211
5212 cmdline_parse_inst_t cmd_set_link_check = {
5213         .f = cmd_set_link_check_parsed,
5214         .help_str = "set link_check on|off: Enable/Disable link status check "
5215                     "when starting/stopping a port",
5216         .data = NULL,
5217         .tokens = {
5218                 (void *)&cmd_setlinkcheck_set,
5219                 (void *)&cmd_setlinkcheck_link_check,
5220                 (void *)&cmd_setlinkcheck_mode,
5221                 NULL,
5222         },
5223 };
5224
5225 /* *** SET NIC BYPASS MODE *** */
5226 struct cmd_set_bypass_mode_result {
5227         cmdline_fixed_string_t set;
5228         cmdline_fixed_string_t bypass;
5229         cmdline_fixed_string_t mode;
5230         cmdline_fixed_string_t value;
5231         portid_t port_id;
5232 };
5233
5234 static void
5235 cmd_set_bypass_mode_parsed(void *parsed_result,
5236                 __attribute__((unused)) struct cmdline *cl,
5237                 __attribute__((unused)) void *data)
5238 {
5239         struct cmd_set_bypass_mode_result *res = parsed_result;
5240         portid_t port_id = res->port_id;
5241         int32_t rc = -EINVAL;
5242
5243 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5244         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5245
5246         if (!strcmp(res->value, "bypass"))
5247                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5248         else if (!strcmp(res->value, "isolate"))
5249                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5250         else
5251                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5252
5253         /* Set the bypass mode for the relevant port. */
5254         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5255 #endif
5256         if (rc != 0)
5257                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5258 }
5259
5260 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5261         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5262                         set, "set");
5263 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5264         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5265                         bypass, "bypass");
5266 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5267         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5268                         mode, "mode");
5269 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5270         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5271                         value, "normal#bypass#isolate");
5272 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5273         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5274                                 port_id, UINT16);
5275
5276 cmdline_parse_inst_t cmd_set_bypass_mode = {
5277         .f = cmd_set_bypass_mode_parsed,
5278         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5279                     "Set the NIC bypass mode for port_id",
5280         .data = NULL,
5281         .tokens = {
5282                 (void *)&cmd_setbypass_mode_set,
5283                 (void *)&cmd_setbypass_mode_bypass,
5284                 (void *)&cmd_setbypass_mode_mode,
5285                 (void *)&cmd_setbypass_mode_value,
5286                 (void *)&cmd_setbypass_mode_port,
5287                 NULL,
5288         },
5289 };
5290
5291 /* *** SET NIC BYPASS EVENT *** */
5292 struct cmd_set_bypass_event_result {
5293         cmdline_fixed_string_t set;
5294         cmdline_fixed_string_t bypass;
5295         cmdline_fixed_string_t event;
5296         cmdline_fixed_string_t event_value;
5297         cmdline_fixed_string_t mode;
5298         cmdline_fixed_string_t mode_value;
5299         portid_t port_id;
5300 };
5301
5302 static void
5303 cmd_set_bypass_event_parsed(void *parsed_result,
5304                 __attribute__((unused)) struct cmdline *cl,
5305                 __attribute__((unused)) void *data)
5306 {
5307         int32_t rc = -EINVAL;
5308         struct cmd_set_bypass_event_result *res = parsed_result;
5309         portid_t port_id = res->port_id;
5310
5311 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5312         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5313         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5314
5315         if (!strcmp(res->event_value, "timeout"))
5316                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5317         else if (!strcmp(res->event_value, "os_on"))
5318                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5319         else if (!strcmp(res->event_value, "os_off"))
5320                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5321         else if (!strcmp(res->event_value, "power_on"))
5322                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5323         else if (!strcmp(res->event_value, "power_off"))
5324                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5325         else
5326                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5327
5328         if (!strcmp(res->mode_value, "bypass"))
5329                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5330         else if (!strcmp(res->mode_value, "isolate"))
5331                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5332         else
5333                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5334
5335         /* Set the watchdog timeout. */
5336         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5337
5338                 rc = -EINVAL;
5339                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5340                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5341                                                            bypass_timeout);
5342                 }
5343                 if (rc != 0) {
5344                         printf("Failed to set timeout value %u "
5345                         "for port %d, errto code: %d.\n",
5346                         bypass_timeout, port_id, rc);
5347                 }
5348         }
5349
5350         /* Set the bypass event to transition to bypass mode. */
5351         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5352                                               bypass_mode);
5353 #endif
5354
5355         if (rc != 0)
5356                 printf("\t Failed to set bypass event for port = %d.\n",
5357                        port_id);
5358 }
5359
5360 cmdline_parse_token_string_t cmd_setbypass_event_set =
5361         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5362                         set, "set");
5363 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5364         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5365                         bypass, "bypass");
5366 cmdline_parse_token_string_t cmd_setbypass_event_event =
5367         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5368                         event, "event");
5369 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5370         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5371                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5372 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5373         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5374                         mode, "mode");
5375 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5376         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5377                         mode_value, "normal#bypass#isolate");
5378 cmdline_parse_token_num_t cmd_setbypass_event_port =
5379         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5380                                 port_id, UINT16);
5381
5382 cmdline_parse_inst_t cmd_set_bypass_event = {
5383         .f = cmd_set_bypass_event_parsed,
5384         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5385                 "power_off mode normal|bypass|isolate <port_id>: "
5386                 "Set the NIC bypass event mode for port_id",
5387         .data = NULL,
5388         .tokens = {
5389                 (void *)&cmd_setbypass_event_set,
5390                 (void *)&cmd_setbypass_event_bypass,
5391                 (void *)&cmd_setbypass_event_event,
5392                 (void *)&cmd_setbypass_event_event_value,
5393                 (void *)&cmd_setbypass_event_mode,
5394                 (void *)&cmd_setbypass_event_mode_value,
5395                 (void *)&cmd_setbypass_event_port,
5396                 NULL,
5397         },
5398 };
5399
5400
5401 /* *** SET NIC BYPASS TIMEOUT *** */
5402 struct cmd_set_bypass_timeout_result {
5403         cmdline_fixed_string_t set;
5404         cmdline_fixed_string_t bypass;
5405         cmdline_fixed_string_t timeout;
5406         cmdline_fixed_string_t value;
5407 };
5408
5409 static void
5410 cmd_set_bypass_timeout_parsed(void *parsed_result,
5411                 __attribute__((unused)) struct cmdline *cl,
5412                 __attribute__((unused)) void *data)
5413 {
5414         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5415
5416 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5417         if (!strcmp(res->value, "1.5"))
5418                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5419         else if (!strcmp(res->value, "2"))
5420                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5421         else if (!strcmp(res->value, "3"))
5422                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5423         else if (!strcmp(res->value, "4"))
5424                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5425         else if (!strcmp(res->value, "8"))
5426                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5427         else if (!strcmp(res->value, "16"))
5428                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5429         else if (!strcmp(res->value, "32"))
5430                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5431         else
5432                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5433 #endif
5434 }
5435
5436 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5437         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5438                         set, "set");
5439 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5440         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5441                         bypass, "bypass");
5442 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5443         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5444                         timeout, "timeout");
5445 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5446         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5447                         value, "0#1.5#2#3#4#8#16#32");
5448
5449 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5450         .f = cmd_set_bypass_timeout_parsed,
5451         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5452                 "Set the NIC bypass watchdog timeout in seconds",
5453         .data = NULL,
5454         .tokens = {
5455                 (void *)&cmd_setbypass_timeout_set,
5456                 (void *)&cmd_setbypass_timeout_bypass,
5457                 (void *)&cmd_setbypass_timeout_timeout,
5458                 (void *)&cmd_setbypass_timeout_value,
5459                 NULL,
5460         },
5461 };
5462
5463 /* *** SHOW NIC BYPASS MODE *** */
5464 struct cmd_show_bypass_config_result {
5465         cmdline_fixed_string_t show;
5466         cmdline_fixed_string_t bypass;
5467         cmdline_fixed_string_t config;
5468         portid_t port_id;
5469 };
5470
5471 static void
5472 cmd_show_bypass_config_parsed(void *parsed_result,
5473                 __attribute__((unused)) struct cmdline *cl,
5474                 __attribute__((unused)) void *data)
5475 {
5476         struct cmd_show_bypass_config_result *res = parsed_result;
5477         portid_t port_id = res->port_id;
5478         int rc = -EINVAL;
5479 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5480         uint32_t event_mode;
5481         uint32_t bypass_mode;
5482         uint32_t timeout = bypass_timeout;
5483         int i;
5484
5485         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5486                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5487         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5488                 {"UNKNOWN", "normal", "bypass", "isolate"};
5489         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5490                 "NONE",
5491                 "OS/board on",
5492                 "power supply on",
5493                 "OS/board off",
5494                 "power supply off",
5495                 "timeout"};
5496         int num_events = (sizeof events) / (sizeof events[0]);
5497
5498         /* Display the bypass mode.*/
5499         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5500                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5501                 return;
5502         }
5503         else {
5504                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5505                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5506
5507                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5508         }
5509
5510         /* Display the bypass timeout.*/
5511         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5512                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5513
5514         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5515
5516         /* Display the bypass events and associated modes. */
5517         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5518
5519                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5520                         printf("\tFailed to get bypass mode for event = %s\n",
5521                                 events[i]);
5522                 } else {
5523                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5524                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5525
5526                         printf("\tbypass event: %-16s = %s\n", events[i],
5527                                 modes[event_mode]);
5528                 }
5529         }
5530 #endif
5531         if (rc != 0)
5532                 printf("\tFailed to get bypass configuration for port = %d\n",
5533                        port_id);
5534 }
5535
5536 cmdline_parse_token_string_t cmd_showbypass_config_show =
5537         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5538                         show, "show");
5539 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5540         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5541                         bypass, "bypass");
5542 cmdline_parse_token_string_t cmd_showbypass_config_config =
5543         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5544                         config, "config");
5545 cmdline_parse_token_num_t cmd_showbypass_config_port =
5546         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5547                                 port_id, UINT16);
5548
5549 cmdline_parse_inst_t cmd_show_bypass_config = {
5550         .f = cmd_show_bypass_config_parsed,
5551         .help_str = "show bypass config <port_id>: "
5552                     "Show the NIC bypass config for port_id",
5553         .data = NULL,
5554         .tokens = {
5555                 (void *)&cmd_showbypass_config_show,
5556                 (void *)&cmd_showbypass_config_bypass,
5557                 (void *)&cmd_showbypass_config_config,
5558                 (void *)&cmd_showbypass_config_port,
5559                 NULL,
5560         },
5561 };
5562
5563 #ifdef RTE_LIBRTE_PMD_BOND
5564 /* *** SET BONDING MODE *** */
5565 struct cmd_set_bonding_mode_result {
5566         cmdline_fixed_string_t set;
5567         cmdline_fixed_string_t bonding;
5568         cmdline_fixed_string_t mode;
5569         uint8_t value;
5570         portid_t port_id;
5571 };
5572
5573 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5574                 __attribute__((unused))  struct cmdline *cl,
5575                 __attribute__((unused)) void *data)
5576 {
5577         struct cmd_set_bonding_mode_result *res = parsed_result;
5578         portid_t port_id = res->port_id;
5579
5580         /* Set the bonding mode for the relevant port. */
5581         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5582                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5583 }
5584
5585 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5586 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5587                 set, "set");
5588 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5589 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5590                 bonding, "bonding");
5591 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5592 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5593                 mode, "mode");
5594 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5595 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5596                 value, UINT8);
5597 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5598 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5599                 port_id, UINT16);
5600
5601 cmdline_parse_inst_t cmd_set_bonding_mode = {
5602                 .f = cmd_set_bonding_mode_parsed,
5603                 .help_str = "set bonding mode <mode_value> <port_id>: "
5604                         "Set the bonding mode for port_id",
5605                 .data = NULL,
5606                 .tokens = {
5607                                 (void *) &cmd_setbonding_mode_set,
5608                                 (void *) &cmd_setbonding_mode_bonding,
5609                                 (void *) &cmd_setbonding_mode_mode,
5610                                 (void *) &cmd_setbonding_mode_value,
5611                                 (void *) &cmd_setbonding_mode_port,
5612                                 NULL
5613                 }
5614 };
5615
5616 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5617 struct cmd_set_bonding_lacp_dedicated_queues_result {
5618         cmdline_fixed_string_t set;
5619         cmdline_fixed_string_t bonding;
5620         cmdline_fixed_string_t lacp;
5621         cmdline_fixed_string_t dedicated_queues;
5622         portid_t port_id;
5623         cmdline_fixed_string_t mode;
5624 };
5625
5626 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5627                 __attribute__((unused))  struct cmdline *cl,
5628                 __attribute__((unused)) void *data)
5629 {
5630         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5631         portid_t port_id = res->port_id;
5632         struct rte_port *port;
5633
5634         port = &ports[port_id];
5635
5636         /** Check if the port is not started **/
5637         if (port->port_status != RTE_PORT_STOPPED) {
5638                 printf("Please stop port %d first\n", port_id);
5639                 return;
5640         }
5641
5642         if (!strcmp(res->mode, "enable")) {
5643                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5644                         printf("Dedicate queues for LACP control packets"
5645                                         " enabled\n");
5646                 else
5647                         printf("Enabling dedicate queues for LACP control "
5648                                         "packets on port %d failed\n", port_id);
5649         } else if (!strcmp(res->mode, "disable")) {
5650                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5651                         printf("Dedicated queues for LACP control packets "
5652                                         "disabled\n");
5653                 else
5654                         printf("Disabling dedicated queues for LACP control "
5655                                         "traffic on port %d failed\n", port_id);
5656         }
5657 }
5658
5659 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5660 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5661                 set, "set");
5662 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5663 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5664                 bonding, "bonding");
5665 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5666 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5667                 lacp, "lacp");
5668 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5669 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5670                 dedicated_queues, "dedicated_queues");
5671 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5672 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5673                 port_id, UINT16);
5674 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5675 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5676                 mode, "enable#disable");
5677
5678 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5679                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5680                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5681                         "enable|disable: "
5682                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5683                 .data = NULL,
5684                 .tokens = {
5685                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5686                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5687                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5688                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5689                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5690                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5691                         NULL
5692                 }
5693 };
5694
5695 /* *** SET BALANCE XMIT POLICY *** */
5696 struct cmd_set_bonding_balance_xmit_policy_result {
5697         cmdline_fixed_string_t set;
5698         cmdline_fixed_string_t bonding;
5699         cmdline_fixed_string_t balance_xmit_policy;
5700         portid_t port_id;
5701         cmdline_fixed_string_t policy;
5702 };
5703
5704 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5705                 __attribute__((unused))  struct cmdline *cl,
5706                 __attribute__((unused)) void *data)
5707 {
5708         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5709         portid_t port_id = res->port_id;
5710         uint8_t policy;
5711
5712         if (!strcmp(res->policy, "l2")) {
5713                 policy = BALANCE_XMIT_POLICY_LAYER2;
5714         } else if (!strcmp(res->policy, "l23")) {
5715                 policy = BALANCE_XMIT_POLICY_LAYER23;
5716         } else if (!strcmp(res->policy, "l34")) {
5717                 policy = BALANCE_XMIT_POLICY_LAYER34;
5718         } else {
5719                 printf("\t Invalid xmit policy selection");
5720                 return;
5721         }
5722
5723         /* Set the bonding mode for the relevant port. */
5724         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5725                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5726                                 port_id);
5727         }
5728 }
5729
5730 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5731 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5732                 set, "set");
5733 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5734 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5735                 bonding, "bonding");
5736 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5737 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5738                 balance_xmit_policy, "balance_xmit_policy");
5739 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5740 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5741                 port_id, UINT16);
5742 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5743 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5744                 policy, "l2#l23#l34");
5745
5746 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5747                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5748                 .help_str = "set bonding balance_xmit_policy <port_id> "
5749                         "l2|l23|l34: "
5750                         "Set the bonding balance_xmit_policy for port_id",
5751                 .data = NULL,
5752                 .tokens = {
5753                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5754                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5755                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5756                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5757                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5758                                 NULL
5759                 }
5760 };
5761
5762 /* *** SHOW NIC BONDING CONFIGURATION *** */
5763 struct cmd_show_bonding_config_result {
5764         cmdline_fixed_string_t show;
5765         cmdline_fixed_string_t bonding;
5766         cmdline_fixed_string_t config;
5767         portid_t port_id;
5768 };
5769
5770 static void cmd_show_bonding_config_parsed(void *parsed_result,
5771                 __attribute__((unused))  struct cmdline *cl,
5772                 __attribute__((unused)) void *data)
5773 {
5774         struct cmd_show_bonding_config_result *res = parsed_result;
5775         int bonding_mode, agg_mode;
5776         portid_t slaves[RTE_MAX_ETHPORTS];
5777         int num_slaves, num_active_slaves;
5778         int primary_id;
5779         int i;
5780         portid_t port_id = res->port_id;
5781
5782         /* Display the bonding mode.*/
5783         bonding_mode = rte_eth_bond_mode_get(port_id);
5784         if (bonding_mode < 0) {
5785                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5786                 return;
5787         } else
5788                 printf("\tBonding mode: %d\n", bonding_mode);
5789
5790         if (bonding_mode == BONDING_MODE_BALANCE) {
5791                 int balance_xmit_policy;
5792
5793                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5794                 if (balance_xmit_policy < 0) {
5795                         printf("\tFailed to get balance xmit policy for port = %d\n",
5796                                         port_id);
5797                         return;
5798                 } else {
5799                         printf("\tBalance Xmit Policy: ");
5800
5801                         switch (balance_xmit_policy) {
5802                         case BALANCE_XMIT_POLICY_LAYER2:
5803                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5804                                 break;
5805                         case BALANCE_XMIT_POLICY_LAYER23:
5806                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5807                                 break;
5808                         case BALANCE_XMIT_POLICY_LAYER34:
5809                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5810                                 break;
5811                         }
5812                         printf("\n");
5813                 }
5814         }
5815
5816         if (bonding_mode == BONDING_MODE_8023AD) {
5817                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5818                 printf("\tIEEE802.3AD Aggregator Mode: ");
5819                 switch (agg_mode) {
5820                 case AGG_BANDWIDTH:
5821                         printf("bandwidth");
5822                         break;
5823                 case AGG_STABLE:
5824                         printf("stable");
5825                         break;
5826                 case AGG_COUNT:
5827                         printf("count");
5828                         break;
5829                 }
5830                 printf("\n");
5831         }
5832
5833         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5834
5835         if (num_slaves < 0) {
5836                 printf("\tFailed to get slave list for port = %d\n", port_id);
5837                 return;
5838         }
5839         if (num_slaves > 0) {
5840                 printf("\tSlaves (%d): [", num_slaves);
5841                 for (i = 0; i < num_slaves - 1; i++)
5842                         printf("%d ", slaves[i]);
5843
5844                 printf("%d]\n", slaves[num_slaves - 1]);
5845         } else {
5846                 printf("\tSlaves: []\n");
5847
5848         }
5849
5850         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5851                         RTE_MAX_ETHPORTS);
5852
5853         if (num_active_slaves < 0) {
5854                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5855                 return;
5856         }
5857         if (num_active_slaves > 0) {
5858                 printf("\tActive Slaves (%d): [", num_active_slaves);
5859                 for (i = 0; i < num_active_slaves - 1; i++)
5860                         printf("%d ", slaves[i]);
5861
5862                 printf("%d]\n", slaves[num_active_slaves - 1]);
5863
5864         } else {
5865                 printf("\tActive Slaves: []\n");
5866
5867         }
5868
5869         primary_id = rte_eth_bond_primary_get(port_id);
5870         if (primary_id < 0) {
5871                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5872                 return;
5873         } else
5874                 printf("\tPrimary: [%d]\n", primary_id);
5875
5876 }
5877
5878 cmdline_parse_token_string_t cmd_showbonding_config_show =
5879 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5880                 show, "show");
5881 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5882 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5883                 bonding, "bonding");
5884 cmdline_parse_token_string_t cmd_showbonding_config_config =
5885 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5886                 config, "config");
5887 cmdline_parse_token_num_t cmd_showbonding_config_port =
5888 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5889                 port_id, UINT16);
5890
5891 cmdline_parse_inst_t cmd_show_bonding_config = {
5892                 .f = cmd_show_bonding_config_parsed,
5893                 .help_str = "show bonding config <port_id>: "
5894                         "Show the bonding config for port_id",
5895                 .data = NULL,
5896                 .tokens = {
5897                                 (void *)&cmd_showbonding_config_show,
5898                                 (void *)&cmd_showbonding_config_bonding,
5899                                 (void *)&cmd_showbonding_config_config,
5900                                 (void *)&cmd_showbonding_config_port,
5901                                 NULL
5902                 }
5903 };
5904
5905 /* *** SET BONDING PRIMARY *** */
5906 struct cmd_set_bonding_primary_result {
5907         cmdline_fixed_string_t set;
5908         cmdline_fixed_string_t bonding;
5909         cmdline_fixed_string_t primary;
5910         portid_t slave_id;
5911         portid_t port_id;
5912 };
5913
5914 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5915                 __attribute__((unused))  struct cmdline *cl,
5916                 __attribute__((unused)) void *data)
5917 {
5918         struct cmd_set_bonding_primary_result *res = parsed_result;
5919         portid_t master_port_id = res->port_id;
5920         portid_t slave_port_id = res->slave_id;
5921
5922         /* Set the primary slave for a bonded device. */
5923         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5924                 printf("\t Failed to set primary slave for port = %d.\n",
5925                                 master_port_id);
5926                 return;
5927         }
5928         init_port_config();
5929 }
5930
5931 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5932 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5933                 set, "set");
5934 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5935 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5936                 bonding, "bonding");
5937 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5938 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5939                 primary, "primary");
5940 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5941 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5942                 slave_id, UINT16);
5943 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5944 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5945                 port_id, UINT16);
5946
5947 cmdline_parse_inst_t cmd_set_bonding_primary = {
5948                 .f = cmd_set_bonding_primary_parsed,
5949                 .help_str = "set bonding primary <slave_id> <port_id>: "
5950                         "Set the primary slave for port_id",
5951                 .data = NULL,
5952                 .tokens = {
5953                                 (void *)&cmd_setbonding_primary_set,
5954                                 (void *)&cmd_setbonding_primary_bonding,
5955                                 (void *)&cmd_setbonding_primary_primary,
5956                                 (void *)&cmd_setbonding_primary_slave,
5957                                 (void *)&cmd_setbonding_primary_port,
5958                                 NULL
5959                 }
5960 };
5961
5962 /* *** ADD SLAVE *** */
5963 struct cmd_add_bonding_slave_result {
5964         cmdline_fixed_string_t add;
5965         cmdline_fixed_string_t bonding;
5966         cmdline_fixed_string_t slave;
5967         portid_t slave_id;
5968         portid_t port_id;
5969 };
5970
5971 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5972                 __attribute__((unused))  struct cmdline *cl,
5973                 __attribute__((unused)) void *data)
5974 {
5975         struct cmd_add_bonding_slave_result *res = parsed_result;
5976         portid_t master_port_id = res->port_id;
5977         portid_t slave_port_id = res->slave_id;
5978
5979         /* add the slave for a bonded device. */
5980         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5981                 printf("\t Failed to add slave %d to master port = %d.\n",
5982                                 slave_port_id, master_port_id);
5983                 return;
5984         }
5985         init_port_config();
5986         set_port_slave_flag(slave_port_id);
5987 }
5988
5989 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5990 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5991                 add, "add");
5992 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5993 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5994                 bonding, "bonding");
5995 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5996 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5997                 slave, "slave");
5998 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5999 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6000                 slave_id, UINT16);
6001 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6002 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6003                 port_id, UINT16);
6004
6005 cmdline_parse_inst_t cmd_add_bonding_slave = {
6006                 .f = cmd_add_bonding_slave_parsed,
6007                 .help_str = "add bonding slave <slave_id> <port_id>: "
6008                         "Add a slave device to a bonded device",
6009                 .data = NULL,
6010                 .tokens = {
6011                                 (void *)&cmd_addbonding_slave_add,
6012                                 (void *)&cmd_addbonding_slave_bonding,
6013                                 (void *)&cmd_addbonding_slave_slave,
6014                                 (void *)&cmd_addbonding_slave_slaveid,
6015                                 (void *)&cmd_addbonding_slave_port,
6016                                 NULL
6017                 }
6018 };
6019
6020 /* *** REMOVE SLAVE *** */
6021 struct cmd_remove_bonding_slave_result {
6022         cmdline_fixed_string_t remove;
6023         cmdline_fixed_string_t bonding;
6024         cmdline_fixed_string_t slave;
6025         portid_t slave_id;
6026         portid_t port_id;
6027 };
6028
6029 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6030                 __attribute__((unused))  struct cmdline *cl,
6031                 __attribute__((unused)) void *data)
6032 {
6033         struct cmd_remove_bonding_slave_result *res = parsed_result;
6034         portid_t master_port_id = res->port_id;
6035         portid_t slave_port_id = res->slave_id;
6036
6037         /* remove the slave from a bonded device. */
6038         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6039                 printf("\t Failed to remove slave %d from master port = %d.\n",
6040                                 slave_port_id, master_port_id);
6041                 return;
6042         }
6043         init_port_config();
6044         clear_port_slave_flag(slave_port_id);
6045 }
6046
6047 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6048                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6049                                 remove, "remove");
6050 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6051                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6052                                 bonding, "bonding");
6053 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6054                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6055                                 slave, "slave");
6056 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6057                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6058                                 slave_id, UINT16);
6059 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6060                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6061                                 port_id, UINT16);
6062
6063 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6064                 .f = cmd_remove_bonding_slave_parsed,
6065                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6066                         "Remove a slave device from a bonded device",
6067                 .data = NULL,
6068                 .tokens = {
6069                                 (void *)&cmd_removebonding_slave_remove,
6070                                 (void *)&cmd_removebonding_slave_bonding,
6071                                 (void *)&cmd_removebonding_slave_slave,
6072                                 (void *)&cmd_removebonding_slave_slaveid,
6073                                 (void *)&cmd_removebonding_slave_port,
6074                                 NULL
6075                 }
6076 };
6077
6078 /* *** CREATE BONDED DEVICE *** */
6079 struct cmd_create_bonded_device_result {
6080         cmdline_fixed_string_t create;
6081         cmdline_fixed_string_t bonded;
6082         cmdline_fixed_string_t device;
6083         uint8_t mode;
6084         uint8_t socket;
6085 };
6086
6087 static int bond_dev_num = 0;
6088
6089 static void cmd_create_bonded_device_parsed(void *parsed_result,
6090                 __attribute__((unused))  struct cmdline *cl,
6091                 __attribute__((unused)) void *data)
6092 {
6093         struct cmd_create_bonded_device_result *res = parsed_result;
6094         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6095         int port_id;
6096         int ret;
6097
6098         if (test_done == 0) {
6099                 printf("Please stop forwarding first\n");
6100                 return;
6101         }
6102
6103         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6104                         bond_dev_num++);
6105
6106         /* Create a new bonded device. */
6107         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6108         if (port_id < 0) {
6109                 printf("\t Failed to create bonded device.\n");
6110                 return;
6111         } else {
6112                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6113                                 port_id);
6114
6115                 /* Update number of ports */
6116                 nb_ports = rte_eth_dev_count_avail();
6117                 reconfig(port_id, res->socket);
6118                 ret = rte_eth_promiscuous_enable(port_id);
6119                 if (ret != 0)
6120                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6121                                 port_id, rte_strerror(-ret));
6122
6123                 ports[port_id].need_setup = 0;
6124                 ports[port_id].port_status = RTE_PORT_STOPPED;
6125         }
6126
6127 }
6128
6129 cmdline_parse_token_string_t cmd_createbonded_device_create =
6130                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6131                                 create, "create");
6132 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6133                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6134                                 bonded, "bonded");
6135 cmdline_parse_token_string_t cmd_createbonded_device_device =
6136                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6137                                 device, "device");
6138 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6139                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6140                                 mode, UINT8);
6141 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6142                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6143                                 socket, UINT8);
6144
6145 cmdline_parse_inst_t cmd_create_bonded_device = {
6146                 .f = cmd_create_bonded_device_parsed,
6147                 .help_str = "create bonded device <mode> <socket>: "
6148                         "Create a new bonded device with specific bonding mode and socket",
6149                 .data = NULL,
6150                 .tokens = {
6151                                 (void *)&cmd_createbonded_device_create,
6152                                 (void *)&cmd_createbonded_device_bonded,
6153                                 (void *)&cmd_createbonded_device_device,
6154                                 (void *)&cmd_createbonded_device_mode,
6155                                 (void *)&cmd_createbonded_device_socket,
6156                                 NULL
6157                 }
6158 };
6159
6160 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6161 struct cmd_set_bond_mac_addr_result {
6162         cmdline_fixed_string_t set;
6163         cmdline_fixed_string_t bonding;
6164         cmdline_fixed_string_t mac_addr;
6165         uint16_t port_num;
6166         struct rte_ether_addr address;
6167 };
6168
6169 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6170                 __attribute__((unused))  struct cmdline *cl,
6171                 __attribute__((unused)) void *data)
6172 {
6173         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6174         int ret;
6175
6176         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6177                 return;
6178
6179         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6180
6181         /* check the return value and print it if is < 0 */
6182         if (ret < 0)
6183                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6184 }
6185
6186 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6187                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6188 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6189                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6190                                 "bonding");
6191 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6192                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6193                                 "mac_addr");
6194 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6195                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6196                                 port_num, UINT16);
6197 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6198                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6199
6200 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6201                 .f = cmd_set_bond_mac_addr_parsed,
6202                 .data = (void *) 0,
6203                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6204                 .tokens = {
6205                                 (void *)&cmd_set_bond_mac_addr_set,
6206                                 (void *)&cmd_set_bond_mac_addr_bonding,
6207                                 (void *)&cmd_set_bond_mac_addr_mac,
6208                                 (void *)&cmd_set_bond_mac_addr_portnum,
6209                                 (void *)&cmd_set_bond_mac_addr_addr,
6210                                 NULL
6211                 }
6212 };
6213
6214
6215 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6216 struct cmd_set_bond_mon_period_result {
6217         cmdline_fixed_string_t set;
6218         cmdline_fixed_string_t bonding;
6219         cmdline_fixed_string_t mon_period;
6220         uint16_t port_num;
6221         uint32_t period_ms;
6222 };
6223
6224 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6225                 __attribute__((unused))  struct cmdline *cl,
6226                 __attribute__((unused)) void *data)
6227 {
6228         struct cmd_set_bond_mon_period_result *res = parsed_result;
6229         int ret;
6230
6231         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6232
6233         /* check the return value and print it if is < 0 */
6234         if (ret < 0)
6235                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6236 }
6237
6238 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6239                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6240                                 set, "set");
6241 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6242                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6243                                 bonding, "bonding");
6244 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6245                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6246                                 mon_period,     "mon_period");
6247 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6248                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6249                                 port_num, UINT16);
6250 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6251                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6252                                 period_ms, UINT32);
6253
6254 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6255                 .f = cmd_set_bond_mon_period_parsed,
6256                 .data = (void *) 0,
6257                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6258                 .tokens = {
6259                                 (void *)&cmd_set_bond_mon_period_set,
6260                                 (void *)&cmd_set_bond_mon_period_bonding,
6261                                 (void *)&cmd_set_bond_mon_period_mon_period,
6262                                 (void *)&cmd_set_bond_mon_period_portnum,
6263                                 (void *)&cmd_set_bond_mon_period_period_ms,
6264                                 NULL
6265                 }
6266 };
6267
6268
6269
6270 struct cmd_set_bonding_agg_mode_policy_result {
6271         cmdline_fixed_string_t set;
6272         cmdline_fixed_string_t bonding;
6273         cmdline_fixed_string_t agg_mode;
6274         uint16_t port_num;
6275         cmdline_fixed_string_t policy;
6276 };
6277
6278
6279 static void
6280 cmd_set_bonding_agg_mode(void *parsed_result,
6281                 __attribute__((unused)) struct cmdline *cl,
6282                 __attribute__((unused)) void *data)
6283 {
6284         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6285         uint8_t policy = AGG_BANDWIDTH;
6286
6287         if (!strcmp(res->policy, "bandwidth"))
6288                 policy = AGG_BANDWIDTH;
6289         else if (!strcmp(res->policy, "stable"))
6290                 policy = AGG_STABLE;
6291         else if (!strcmp(res->policy, "count"))
6292                 policy = AGG_COUNT;
6293
6294         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6295 }
6296
6297
6298 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6299         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6300                                 set, "set");
6301 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6302         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6303                                 bonding, "bonding");
6304
6305 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6306         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6307                                 agg_mode, "agg_mode");
6308
6309 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6310         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6311                                 port_num, UINT16);
6312
6313 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6314         TOKEN_STRING_INITIALIZER(
6315                         struct cmd_set_bonding_balance_xmit_policy_result,
6316                 policy, "stable#bandwidth#count");
6317
6318 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6319         .f = cmd_set_bonding_agg_mode,
6320         .data = (void *) 0,
6321         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6322         .tokens = {
6323                         (void *)&cmd_set_bonding_agg_mode_set,
6324                         (void *)&cmd_set_bonding_agg_mode_bonding,
6325                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6326                         (void *)&cmd_set_bonding_agg_mode_portnum,
6327                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6328                         NULL
6329                 }
6330 };
6331
6332
6333 #endif /* RTE_LIBRTE_PMD_BOND */
6334
6335 /* *** SET FORWARDING MODE *** */
6336 struct cmd_set_fwd_mode_result {
6337         cmdline_fixed_string_t set;
6338         cmdline_fixed_string_t fwd;
6339         cmdline_fixed_string_t mode;
6340 };
6341
6342 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6343                                     __attribute__((unused)) struct cmdline *cl,
6344                                     __attribute__((unused)) void *data)
6345 {
6346         struct cmd_set_fwd_mode_result *res = parsed_result;
6347
6348         retry_enabled = 0;
6349         set_pkt_forwarding_mode(res->mode);
6350 }
6351
6352 cmdline_parse_token_string_t cmd_setfwd_set =
6353         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6354 cmdline_parse_token_string_t cmd_setfwd_fwd =
6355         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6356 cmdline_parse_token_string_t cmd_setfwd_mode =
6357         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6358                 "" /* defined at init */);
6359
6360 cmdline_parse_inst_t cmd_set_fwd_mode = {
6361         .f = cmd_set_fwd_mode_parsed,
6362         .data = NULL,
6363         .help_str = NULL, /* defined at init */
6364         .tokens = {
6365                 (void *)&cmd_setfwd_set,
6366                 (void *)&cmd_setfwd_fwd,
6367                 (void *)&cmd_setfwd_mode,
6368                 NULL,
6369         },
6370 };
6371
6372 static void cmd_set_fwd_mode_init(void)
6373 {
6374         char *modes, *c;
6375         static char token[128];
6376         static char help[256];
6377         cmdline_parse_token_string_t *token_struct;
6378
6379         modes = list_pkt_forwarding_modes();
6380         snprintf(help, sizeof(help), "set fwd %s: "
6381                 "Set packet forwarding mode", modes);
6382         cmd_set_fwd_mode.help_str = help;
6383
6384         /* string token separator is # */
6385         for (c = token; *modes != '\0'; modes++)
6386                 if (*modes == '|')
6387                         *c++ = '#';
6388                 else
6389                         *c++ = *modes;
6390         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6391         token_struct->string_data.str = token;
6392 }
6393
6394 /* *** SET RETRY FORWARDING MODE *** */
6395 struct cmd_set_fwd_retry_mode_result {
6396         cmdline_fixed_string_t set;
6397         cmdline_fixed_string_t fwd;
6398         cmdline_fixed_string_t mode;
6399         cmdline_fixed_string_t retry;
6400 };
6401
6402 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6403                             __attribute__((unused)) struct cmdline *cl,
6404                             __attribute__((unused)) void *data)
6405 {
6406         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6407
6408         retry_enabled = 1;
6409         set_pkt_forwarding_mode(res->mode);
6410 }
6411
6412 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6413         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6414                         set, "set");
6415 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6416         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6417                         fwd, "fwd");
6418 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6419         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6420                         mode,
6421                 "" /* defined at init */);
6422 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6423         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6424                         retry, "retry");
6425
6426 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6427         .f = cmd_set_fwd_retry_mode_parsed,
6428         .data = NULL,
6429         .help_str = NULL, /* defined at init */
6430         .tokens = {
6431                 (void *)&cmd_setfwd_retry_set,
6432                 (void *)&cmd_setfwd_retry_fwd,
6433                 (void *)&cmd_setfwd_retry_mode,
6434                 (void *)&cmd_setfwd_retry_retry,
6435                 NULL,
6436         },
6437 };
6438
6439 static void cmd_set_fwd_retry_mode_init(void)
6440 {
6441         char *modes, *c;
6442         static char token[128];
6443         static char help[256];
6444         cmdline_parse_token_string_t *token_struct;
6445
6446         modes = list_pkt_forwarding_retry_modes();
6447         snprintf(help, sizeof(help), "set fwd %s retry: "
6448                 "Set packet forwarding mode with retry", modes);
6449         cmd_set_fwd_retry_mode.help_str = help;
6450
6451         /* string token separator is # */
6452         for (c = token; *modes != '\0'; modes++)
6453                 if (*modes == '|')
6454                         *c++ = '#';
6455                 else
6456                         *c++ = *modes;
6457         token_struct = (cmdline_parse_token_string_t *)
6458                 cmd_set_fwd_retry_mode.tokens[2];
6459         token_struct->string_data.str = token;
6460 }
6461
6462 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6463 struct cmd_set_burst_tx_retry_result {
6464         cmdline_fixed_string_t set;
6465         cmdline_fixed_string_t burst;
6466         cmdline_fixed_string_t tx;
6467         cmdline_fixed_string_t delay;
6468         uint32_t time;
6469         cmdline_fixed_string_t retry;
6470         uint32_t retry_num;
6471 };
6472
6473 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6474                                         __attribute__((unused)) struct cmdline *cl,
6475                                         __attribute__((unused)) void *data)
6476 {
6477         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6478
6479         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6480                 && !strcmp(res->tx, "tx")) {
6481                 if (!strcmp(res->delay, "delay"))
6482                         burst_tx_delay_time = res->time;
6483                 if (!strcmp(res->retry, "retry"))
6484                         burst_tx_retry_num = res->retry_num;
6485         }
6486
6487 }
6488
6489 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6490         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6491 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6492         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6493                                  "burst");
6494 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6495         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6496 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6497         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6498 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6499         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6500 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6501         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6502 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6503         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6504
6505 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6506         .f = cmd_set_burst_tx_retry_parsed,
6507         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6508         .tokens = {
6509                 (void *)&cmd_set_burst_tx_retry_set,
6510                 (void *)&cmd_set_burst_tx_retry_burst,
6511                 (void *)&cmd_set_burst_tx_retry_tx,
6512                 (void *)&cmd_set_burst_tx_retry_delay,
6513                 (void *)&cmd_set_burst_tx_retry_time,
6514                 (void *)&cmd_set_burst_tx_retry_retry,
6515                 (void *)&cmd_set_burst_tx_retry_retry_num,
6516                 NULL,
6517         },
6518 };
6519
6520 /* *** SET PROMISC MODE *** */
6521 struct cmd_set_promisc_mode_result {
6522         cmdline_fixed_string_t set;
6523         cmdline_fixed_string_t promisc;
6524         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6525         uint16_t port_num;               /* valid if "allports" argument == 0 */
6526         cmdline_fixed_string_t mode;
6527 };
6528
6529 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6530                                         __attribute__((unused)) struct cmdline *cl,
6531                                         void *allports)
6532 {
6533         struct cmd_set_promisc_mode_result *res = parsed_result;
6534         int enable;
6535         portid_t i;
6536
6537         if (!strcmp(res->mode, "on"))
6538                 enable = 1;
6539         else
6540                 enable = 0;
6541
6542         /* all ports */
6543         if (allports) {
6544                 RTE_ETH_FOREACH_DEV(i)
6545                         eth_set_promisc_mode(i, enable);
6546         } else {
6547                 eth_set_promisc_mode(res->port_num, enable);
6548         }
6549 }
6550
6551 cmdline_parse_token_string_t cmd_setpromisc_set =
6552         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6553 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6554         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6555                                  "promisc");
6556 cmdline_parse_token_string_t cmd_setpromisc_portall =
6557         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6558                                  "all");
6559 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6560         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6561                               UINT16);
6562 cmdline_parse_token_string_t cmd_setpromisc_mode =
6563         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6564                                  "on#off");
6565
6566 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6567         .f = cmd_set_promisc_mode_parsed,
6568         .data = (void *)1,
6569         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6570         .tokens = {
6571                 (void *)&cmd_setpromisc_set,
6572                 (void *)&cmd_setpromisc_promisc,
6573                 (void *)&cmd_setpromisc_portall,
6574                 (void *)&cmd_setpromisc_mode,
6575                 NULL,
6576         },
6577 };
6578
6579 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6580         .f = cmd_set_promisc_mode_parsed,
6581         .data = (void *)0,
6582         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6583         .tokens = {
6584                 (void *)&cmd_setpromisc_set,
6585                 (void *)&cmd_setpromisc_promisc,
6586                 (void *)&cmd_setpromisc_portnum,
6587                 (void *)&cmd_setpromisc_mode,
6588                 NULL,
6589         },
6590 };
6591
6592 /* *** SET ALLMULTI MODE *** */
6593 struct cmd_set_allmulti_mode_result {
6594         cmdline_fixed_string_t set;
6595         cmdline_fixed_string_t allmulti;
6596         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6597         uint16_t port_num;               /* valid if "allports" argument == 0 */
6598         cmdline_fixed_string_t mode;
6599 };
6600
6601 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6602                                         __attribute__((unused)) struct cmdline *cl,
6603                                         void *allports)
6604 {
6605         struct cmd_set_allmulti_mode_result *res = parsed_result;
6606         int enable;
6607         portid_t i;
6608
6609         if (!strcmp(res->mode, "on"))
6610                 enable = 1;
6611         else
6612                 enable = 0;
6613
6614         /* all ports */
6615         if (allports) {
6616                 RTE_ETH_FOREACH_DEV(i) {
6617                         eth_set_allmulticast_mode(i, enable);
6618                 }
6619         }
6620         else {
6621                 eth_set_allmulticast_mode(res->port_num, enable);
6622         }
6623 }
6624
6625 cmdline_parse_token_string_t cmd_setallmulti_set =
6626         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6627 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6628         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6629                                  "allmulti");
6630 cmdline_parse_token_string_t cmd_setallmulti_portall =
6631         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6632                                  "all");
6633 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6634         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6635                               UINT16);
6636 cmdline_parse_token_string_t cmd_setallmulti_mode =
6637         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6638                                  "on#off");
6639
6640 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6641         .f = cmd_set_allmulti_mode_parsed,
6642         .data = (void *)1,
6643         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6644         .tokens = {
6645                 (void *)&cmd_setallmulti_set,
6646                 (void *)&cmd_setallmulti_allmulti,
6647                 (void *)&cmd_setallmulti_portall,
6648                 (void *)&cmd_setallmulti_mode,
6649                 NULL,
6650         },
6651 };
6652
6653 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6654         .f = cmd_set_allmulti_mode_parsed,
6655         .data = (void *)0,
6656         .help_str = "set allmulti <port_id> on|off: "
6657                 "Set allmulti mode on port_id",
6658         .tokens = {
6659                 (void *)&cmd_setallmulti_set,
6660                 (void *)&cmd_setallmulti_allmulti,
6661                 (void *)&cmd_setallmulti_portnum,
6662                 (void *)&cmd_setallmulti_mode,
6663                 NULL,
6664         },
6665 };
6666
6667 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6668 struct cmd_link_flow_ctrl_set_result {
6669         cmdline_fixed_string_t set;
6670         cmdline_fixed_string_t flow_ctrl;
6671         cmdline_fixed_string_t rx;
6672         cmdline_fixed_string_t rx_lfc_mode;
6673         cmdline_fixed_string_t tx;
6674         cmdline_fixed_string_t tx_lfc_mode;
6675         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6676         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6677         cmdline_fixed_string_t autoneg_str;
6678         cmdline_fixed_string_t autoneg;
6679         cmdline_fixed_string_t hw_str;
6680         uint32_t high_water;
6681         cmdline_fixed_string_t lw_str;
6682         uint32_t low_water;
6683         cmdline_fixed_string_t pt_str;
6684         uint16_t pause_time;
6685         cmdline_fixed_string_t xon_str;
6686         uint16_t send_xon;
6687         portid_t port_id;
6688 };
6689
6690 cmdline_parse_token_string_t cmd_lfc_set_set =
6691         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6692                                 set, "set");
6693 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6694         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6695                                 flow_ctrl, "flow_ctrl");
6696 cmdline_parse_token_string_t cmd_lfc_set_rx =
6697         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6698                                 rx, "rx");
6699 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6700         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6701                                 rx_lfc_mode, "on#off");
6702 cmdline_parse_token_string_t cmd_lfc_set_tx =
6703         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6704                                 tx, "tx");
6705 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6706         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6707                                 tx_lfc_mode, "on#off");
6708 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6709         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6710                                 hw_str, "high_water");
6711 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6712         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6713                                 high_water, UINT32);
6714 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6715         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6716                                 lw_str, "low_water");
6717 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6718         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6719                                 low_water, UINT32);
6720 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6721         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6722                                 pt_str, "pause_time");
6723 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6724         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6725                                 pause_time, UINT16);
6726 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6727         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6728                                 xon_str, "send_xon");
6729 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6730         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6731                                 send_xon, UINT16);
6732 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6733         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6734                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6735 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6736         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6737                                 mac_ctrl_frame_fwd_mode, "on#off");
6738 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6739         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6740                                 autoneg_str, "autoneg");
6741 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6742         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6743                                 autoneg, "on#off");
6744 cmdline_parse_token_num_t cmd_lfc_set_portid =
6745         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6746                                 port_id, UINT16);
6747
6748 /* forward declaration */
6749 static void
6750 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6751                               void *data);
6752
6753 cmdline_parse_inst_t cmd_link_flow_control_set = {
6754         .f = cmd_link_flow_ctrl_set_parsed,
6755         .data = NULL,
6756         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6757                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6758                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6759         .tokens = {
6760                 (void *)&cmd_lfc_set_set,
6761                 (void *)&cmd_lfc_set_flow_ctrl,
6762                 (void *)&cmd_lfc_set_rx,
6763                 (void *)&cmd_lfc_set_rx_mode,
6764                 (void *)&cmd_lfc_set_tx,
6765                 (void *)&cmd_lfc_set_tx_mode,
6766                 (void *)&cmd_lfc_set_high_water,
6767                 (void *)&cmd_lfc_set_low_water,
6768                 (void *)&cmd_lfc_set_pause_time,
6769                 (void *)&cmd_lfc_set_send_xon,
6770                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6771                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6772                 (void *)&cmd_lfc_set_autoneg_str,
6773                 (void *)&cmd_lfc_set_autoneg,
6774                 (void *)&cmd_lfc_set_portid,
6775                 NULL,
6776         },
6777 };
6778
6779 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6780         .f = cmd_link_flow_ctrl_set_parsed,
6781         .data = (void *)&cmd_link_flow_control_set_rx,
6782         .help_str = "set flow_ctrl rx on|off <port_id>: "
6783                 "Change rx flow control parameter",
6784         .tokens = {
6785                 (void *)&cmd_lfc_set_set,
6786                 (void *)&cmd_lfc_set_flow_ctrl,
6787                 (void *)&cmd_lfc_set_rx,
6788                 (void *)&cmd_lfc_set_rx_mode,
6789                 (void *)&cmd_lfc_set_portid,
6790                 NULL,
6791         },
6792 };
6793
6794 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6795         .f = cmd_link_flow_ctrl_set_parsed,
6796         .data = (void *)&cmd_link_flow_control_set_tx,
6797         .help_str = "set flow_ctrl tx on|off <port_id>: "
6798                 "Change tx flow control parameter",
6799         .tokens = {
6800                 (void *)&cmd_lfc_set_set,
6801                 (void *)&cmd_lfc_set_flow_ctrl,
6802                 (void *)&cmd_lfc_set_tx,
6803                 (void *)&cmd_lfc_set_tx_mode,
6804                 (void *)&cmd_lfc_set_portid,
6805                 NULL,
6806         },
6807 };
6808
6809 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6810         .f = cmd_link_flow_ctrl_set_parsed,
6811         .data = (void *)&cmd_link_flow_control_set_hw,
6812         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6813                 "Change high water flow control parameter",
6814         .tokens = {
6815                 (void *)&cmd_lfc_set_set,
6816                 (void *)&cmd_lfc_set_flow_ctrl,
6817                 (void *)&cmd_lfc_set_high_water_str,
6818                 (void *)&cmd_lfc_set_high_water,
6819                 (void *)&cmd_lfc_set_portid,
6820                 NULL,
6821         },
6822 };
6823
6824 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6825         .f = cmd_link_flow_ctrl_set_parsed,
6826         .data = (void *)&cmd_link_flow_control_set_lw,
6827         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6828                 "Change low water flow control parameter",
6829         .tokens = {
6830                 (void *)&cmd_lfc_set_set,
6831                 (void *)&cmd_lfc_set_flow_ctrl,
6832                 (void *)&cmd_lfc_set_low_water_str,
6833                 (void *)&cmd_lfc_set_low_water,
6834                 (void *)&cmd_lfc_set_portid,
6835                 NULL,
6836         },
6837 };
6838
6839 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6840         .f = cmd_link_flow_ctrl_set_parsed,
6841         .data = (void *)&cmd_link_flow_control_set_pt,
6842         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6843                 "Change pause time flow control parameter",
6844         .tokens = {
6845                 (void *)&cmd_lfc_set_set,
6846                 (void *)&cmd_lfc_set_flow_ctrl,
6847                 (void *)&cmd_lfc_set_pause_time_str,
6848                 (void *)&cmd_lfc_set_pause_time,
6849                 (void *)&cmd_lfc_set_portid,
6850                 NULL,
6851         },
6852 };
6853
6854 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6855         .f = cmd_link_flow_ctrl_set_parsed,
6856         .data = (void *)&cmd_link_flow_control_set_xon,
6857         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6858                 "Change send_xon flow control parameter",
6859         .tokens = {
6860                 (void *)&cmd_lfc_set_set,
6861                 (void *)&cmd_lfc_set_flow_ctrl,
6862                 (void *)&cmd_lfc_set_send_xon_str,
6863                 (void *)&cmd_lfc_set_send_xon,
6864                 (void *)&cmd_lfc_set_portid,
6865                 NULL,
6866         },
6867 };
6868
6869 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6870         .f = cmd_link_flow_ctrl_set_parsed,
6871         .data = (void *)&cmd_link_flow_control_set_macfwd,
6872         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6873                 "Change mac ctrl fwd flow control parameter",
6874         .tokens = {
6875                 (void *)&cmd_lfc_set_set,
6876                 (void *)&cmd_lfc_set_flow_ctrl,
6877                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6878                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6879                 (void *)&cmd_lfc_set_portid,
6880                 NULL,
6881         },
6882 };
6883
6884 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6885         .f = cmd_link_flow_ctrl_set_parsed,
6886         .data = (void *)&cmd_link_flow_control_set_autoneg,
6887         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6888                 "Change autoneg flow control parameter",
6889         .tokens = {
6890                 (void *)&cmd_lfc_set_set,
6891                 (void *)&cmd_lfc_set_flow_ctrl,
6892                 (void *)&cmd_lfc_set_autoneg_str,
6893                 (void *)&cmd_lfc_set_autoneg,
6894                 (void *)&cmd_lfc_set_portid,
6895                 NULL,
6896         },
6897 };
6898
6899 static void
6900 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6901                               __attribute__((unused)) struct cmdline *cl,
6902                               void *data)
6903 {
6904         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6905         cmdline_parse_inst_t *cmd = data;
6906         struct rte_eth_fc_conf fc_conf;
6907         int rx_fc_en = 0;
6908         int tx_fc_en = 0;
6909         int ret;
6910
6911         /*
6912          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6913          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6914          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6915          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6916          */
6917         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6918                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6919         };
6920
6921         /* Partial command line, retrieve current configuration */
6922         if (cmd) {
6923                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6924                 if (ret != 0) {
6925                         printf("cannot get current flow ctrl parameters, return"
6926                                "code = %d\n", ret);
6927                         return;
6928                 }
6929
6930                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6931                     (fc_conf.mode == RTE_FC_FULL))
6932                         rx_fc_en = 1;
6933                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6934                     (fc_conf.mode == RTE_FC_FULL))
6935                         tx_fc_en = 1;
6936         }
6937
6938         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6939                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6940
6941         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6942                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6943
6944         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6945
6946         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6947                 fc_conf.high_water = res->high_water;
6948
6949         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6950                 fc_conf.low_water = res->low_water;
6951
6952         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6953                 fc_conf.pause_time = res->pause_time;
6954
6955         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6956                 fc_conf.send_xon = res->send_xon;
6957
6958         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6959                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6960                         fc_conf.mac_ctrl_frame_fwd = 1;
6961                 else
6962                         fc_conf.mac_ctrl_frame_fwd = 0;
6963         }
6964
6965         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6966                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6967
6968         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6969         if (ret != 0)
6970                 printf("bad flow contrl parameter, return code = %d \n", ret);
6971 }
6972
6973 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6974 struct cmd_priority_flow_ctrl_set_result {
6975         cmdline_fixed_string_t set;
6976         cmdline_fixed_string_t pfc_ctrl;
6977         cmdline_fixed_string_t rx;
6978         cmdline_fixed_string_t rx_pfc_mode;
6979         cmdline_fixed_string_t tx;
6980         cmdline_fixed_string_t tx_pfc_mode;
6981         uint32_t high_water;
6982         uint32_t low_water;
6983         uint16_t pause_time;
6984         uint8_t  priority;
6985         portid_t port_id;
6986 };
6987
6988 static void
6989 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6990                        __attribute__((unused)) struct cmdline *cl,
6991                        __attribute__((unused)) void *data)
6992 {
6993         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6994         struct rte_eth_pfc_conf pfc_conf;
6995         int rx_fc_enable, tx_fc_enable;
6996         int ret;
6997
6998         /*
6999          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7000          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7001          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7002          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7003          */
7004         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7005                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
7006         };
7007
7008         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7009         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7010         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7011         pfc_conf.fc.high_water = res->high_water;
7012         pfc_conf.fc.low_water  = res->low_water;
7013         pfc_conf.fc.pause_time = res->pause_time;
7014         pfc_conf.priority      = res->priority;
7015
7016         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7017         if (ret != 0)
7018                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7019 }
7020
7021 cmdline_parse_token_string_t cmd_pfc_set_set =
7022         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7023                                 set, "set");
7024 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7025         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7026                                 pfc_ctrl, "pfc_ctrl");
7027 cmdline_parse_token_string_t cmd_pfc_set_rx =
7028         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7029                                 rx, "rx");
7030 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7031         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7032                                 rx_pfc_mode, "on#off");
7033 cmdline_parse_token_string_t cmd_pfc_set_tx =
7034         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7035                                 tx, "tx");
7036 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7037         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7038                                 tx_pfc_mode, "on#off");
7039 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7040         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7041                                 high_water, UINT32);
7042 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7043         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7044                                 low_water, UINT32);
7045 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7046         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7047                                 pause_time, UINT16);
7048 cmdline_parse_token_num_t cmd_pfc_set_priority =
7049         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7050                                 priority, UINT8);
7051 cmdline_parse_token_num_t cmd_pfc_set_portid =
7052         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7053                                 port_id, UINT16);
7054
7055 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7056         .f = cmd_priority_flow_ctrl_set_parsed,
7057         .data = NULL,
7058         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7059                 "<pause_time> <priority> <port_id>: "
7060                 "Configure the Ethernet priority flow control",
7061         .tokens = {
7062                 (void *)&cmd_pfc_set_set,
7063                 (void *)&cmd_pfc_set_flow_ctrl,
7064                 (void *)&cmd_pfc_set_rx,
7065                 (void *)&cmd_pfc_set_rx_mode,
7066                 (void *)&cmd_pfc_set_tx,
7067                 (void *)&cmd_pfc_set_tx_mode,
7068                 (void *)&cmd_pfc_set_high_water,
7069                 (void *)&cmd_pfc_set_low_water,
7070                 (void *)&cmd_pfc_set_pause_time,
7071                 (void *)&cmd_pfc_set_priority,
7072                 (void *)&cmd_pfc_set_portid,
7073                 NULL,
7074         },
7075 };
7076
7077 /* *** RESET CONFIGURATION *** */
7078 struct cmd_reset_result {
7079         cmdline_fixed_string_t reset;
7080         cmdline_fixed_string_t def;
7081 };
7082
7083 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7084                              struct cmdline *cl,
7085                              __attribute__((unused)) void *data)
7086 {
7087         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7088         set_def_fwd_config();
7089 }
7090
7091 cmdline_parse_token_string_t cmd_reset_set =
7092         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7093 cmdline_parse_token_string_t cmd_reset_def =
7094         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7095                                  "default");
7096
7097 cmdline_parse_inst_t cmd_reset = {
7098         .f = cmd_reset_parsed,
7099         .data = NULL,
7100         .help_str = "set default: Reset default forwarding configuration",
7101         .tokens = {
7102                 (void *)&cmd_reset_set,
7103                 (void *)&cmd_reset_def,
7104                 NULL,
7105         },
7106 };
7107
7108 /* *** START FORWARDING *** */
7109 struct cmd_start_result {
7110         cmdline_fixed_string_t start;
7111 };
7112
7113 cmdline_parse_token_string_t cmd_start_start =
7114         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7115
7116 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7117                              __attribute__((unused)) struct cmdline *cl,
7118                              __attribute__((unused)) void *data)
7119 {
7120         start_packet_forwarding(0);
7121 }
7122
7123 cmdline_parse_inst_t cmd_start = {
7124         .f = cmd_start_parsed,
7125         .data = NULL,
7126         .help_str = "start: Start packet forwarding",
7127         .tokens = {
7128                 (void *)&cmd_start_start,
7129                 NULL,
7130         },
7131 };
7132
7133 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7134 struct cmd_start_tx_first_result {
7135         cmdline_fixed_string_t start;
7136         cmdline_fixed_string_t tx_first;
7137 };
7138
7139 static void
7140 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7141                           __attribute__((unused)) struct cmdline *cl,
7142                           __attribute__((unused)) void *data)
7143 {
7144         start_packet_forwarding(1);
7145 }
7146
7147 cmdline_parse_token_string_t cmd_start_tx_first_start =
7148         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7149                                  "start");
7150 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7151         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7152                                  tx_first, "tx_first");
7153
7154 cmdline_parse_inst_t cmd_start_tx_first = {
7155         .f = cmd_start_tx_first_parsed,
7156         .data = NULL,
7157         .help_str = "start tx_first: Start packet forwarding, "
7158                 "after sending 1 burst of packets",
7159         .tokens = {
7160                 (void *)&cmd_start_tx_first_start,
7161                 (void *)&cmd_start_tx_first_tx_first,
7162                 NULL,
7163         },
7164 };
7165
7166 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7167 struct cmd_start_tx_first_n_result {
7168         cmdline_fixed_string_t start;
7169         cmdline_fixed_string_t tx_first;
7170         uint32_t tx_num;
7171 };
7172
7173 static void
7174 cmd_start_tx_first_n_parsed(void *parsed_result,
7175                           __attribute__((unused)) struct cmdline *cl,
7176                           __attribute__((unused)) void *data)
7177 {
7178         struct cmd_start_tx_first_n_result *res = parsed_result;
7179
7180         start_packet_forwarding(res->tx_num);
7181 }
7182
7183 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7184         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7185                         start, "start");
7186 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7187         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7188                         tx_first, "tx_first");
7189 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7190         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7191                         tx_num, UINT32);
7192
7193 cmdline_parse_inst_t cmd_start_tx_first_n = {
7194         .f = cmd_start_tx_first_n_parsed,
7195         .data = NULL,
7196         .help_str = "start tx_first <num>: "
7197                 "packet forwarding, after sending <num> bursts of packets",
7198         .tokens = {
7199                 (void *)&cmd_start_tx_first_n_start,
7200                 (void *)&cmd_start_tx_first_n_tx_first,
7201                 (void *)&cmd_start_tx_first_n_tx_num,
7202                 NULL,
7203         },
7204 };
7205
7206 /* *** SET LINK UP *** */
7207 struct cmd_set_link_up_result {
7208         cmdline_fixed_string_t set;
7209         cmdline_fixed_string_t link_up;
7210         cmdline_fixed_string_t port;
7211         portid_t port_id;
7212 };
7213
7214 cmdline_parse_token_string_t cmd_set_link_up_set =
7215         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7216 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7217         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7218                                 "link-up");
7219 cmdline_parse_token_string_t cmd_set_link_up_port =
7220         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7221 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7222         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7223
7224 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7225                              __attribute__((unused)) struct cmdline *cl,
7226                              __attribute__((unused)) void *data)
7227 {
7228         struct cmd_set_link_up_result *res = parsed_result;
7229         dev_set_link_up(res->port_id);
7230 }
7231
7232 cmdline_parse_inst_t cmd_set_link_up = {
7233         .f = cmd_set_link_up_parsed,
7234         .data = NULL,
7235         .help_str = "set link-up port <port id>",
7236         .tokens = {
7237                 (void *)&cmd_set_link_up_set,
7238                 (void *)&cmd_set_link_up_link_up,
7239                 (void *)&cmd_set_link_up_port,
7240                 (void *)&cmd_set_link_up_port_id,
7241                 NULL,
7242         },
7243 };
7244
7245 /* *** SET LINK DOWN *** */
7246 struct cmd_set_link_down_result {
7247         cmdline_fixed_string_t set;
7248         cmdline_fixed_string_t link_down;
7249         cmdline_fixed_string_t port;
7250         portid_t port_id;
7251 };
7252
7253 cmdline_parse_token_string_t cmd_set_link_down_set =
7254         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7255 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7256         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7257                                 "link-down");
7258 cmdline_parse_token_string_t cmd_set_link_down_port =
7259         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7260 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7261         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7262
7263 static void cmd_set_link_down_parsed(
7264                                 __attribute__((unused)) void *parsed_result,
7265                                 __attribute__((unused)) struct cmdline *cl,
7266                                 __attribute__((unused)) void *data)
7267 {
7268         struct cmd_set_link_down_result *res = parsed_result;
7269         dev_set_link_down(res->port_id);
7270 }
7271
7272 cmdline_parse_inst_t cmd_set_link_down = {
7273         .f = cmd_set_link_down_parsed,
7274         .data = NULL,
7275         .help_str = "set link-down port <port id>",
7276         .tokens = {
7277                 (void *)&cmd_set_link_down_set,
7278                 (void *)&cmd_set_link_down_link_down,
7279                 (void *)&cmd_set_link_down_port,
7280                 (void *)&cmd_set_link_down_port_id,
7281                 NULL,
7282         },
7283 };
7284
7285 /* *** SHOW CFG *** */
7286 struct cmd_showcfg_result {
7287         cmdline_fixed_string_t show;
7288         cmdline_fixed_string_t cfg;
7289         cmdline_fixed_string_t what;
7290 };
7291
7292 static void cmd_showcfg_parsed(void *parsed_result,
7293                                __attribute__((unused)) struct cmdline *cl,
7294                                __attribute__((unused)) void *data)
7295 {
7296         struct cmd_showcfg_result *res = parsed_result;
7297         if (!strcmp(res->what, "rxtx"))
7298                 rxtx_config_display();
7299         else if (!strcmp(res->what, "cores"))
7300                 fwd_lcores_config_display();
7301         else if (!strcmp(res->what, "fwd"))
7302                 pkt_fwd_config_display(&cur_fwd_config);
7303         else if (!strcmp(res->what, "txpkts"))
7304                 show_tx_pkt_segments();
7305 }
7306
7307 cmdline_parse_token_string_t cmd_showcfg_show =
7308         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7309 cmdline_parse_token_string_t cmd_showcfg_port =
7310         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7311 cmdline_parse_token_string_t cmd_showcfg_what =
7312         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7313                                  "rxtx#cores#fwd#txpkts");
7314
7315 cmdline_parse_inst_t cmd_showcfg = {
7316         .f = cmd_showcfg_parsed,
7317         .data = NULL,
7318         .help_str = "show config rxtx|cores|fwd|txpkts",
7319         .tokens = {
7320                 (void *)&cmd_showcfg_show,
7321                 (void *)&cmd_showcfg_port,
7322                 (void *)&cmd_showcfg_what,
7323                 NULL,
7324         },
7325 };
7326
7327 /* *** SHOW ALL PORT INFO *** */
7328 struct cmd_showportall_result {
7329         cmdline_fixed_string_t show;
7330         cmdline_fixed_string_t port;
7331         cmdline_fixed_string_t what;
7332         cmdline_fixed_string_t all;
7333 };
7334
7335 static void cmd_showportall_parsed(void *parsed_result,
7336                                 __attribute__((unused)) struct cmdline *cl,
7337                                 __attribute__((unused)) void *data)
7338 {
7339         portid_t i;
7340
7341         struct cmd_showportall_result *res = parsed_result;
7342         if (!strcmp(res->show, "clear")) {
7343                 if (!strcmp(res->what, "stats"))
7344                         RTE_ETH_FOREACH_DEV(i)
7345                                 nic_stats_clear(i);
7346                 else if (!strcmp(res->what, "xstats"))
7347                         RTE_ETH_FOREACH_DEV(i)
7348                                 nic_xstats_clear(i);
7349         } else if (!strcmp(res->what, "info"))
7350                 RTE_ETH_FOREACH_DEV(i)
7351                         port_infos_display(i);
7352         else if (!strcmp(res->what, "summary")) {
7353                 port_summary_header_display();
7354                 RTE_ETH_FOREACH_DEV(i)
7355                         port_summary_display(i);
7356         }
7357         else if (!strcmp(res->what, "stats"))
7358                 RTE_ETH_FOREACH_DEV(i)
7359                         nic_stats_display(i);
7360         else if (!strcmp(res->what, "xstats"))
7361                 RTE_ETH_FOREACH_DEV(i)
7362                         nic_xstats_display(i);
7363         else if (!strcmp(res->what, "fdir"))
7364                 RTE_ETH_FOREACH_DEV(i)
7365                         fdir_get_infos(i);
7366         else if (!strcmp(res->what, "stat_qmap"))
7367                 RTE_ETH_FOREACH_DEV(i)
7368                         nic_stats_mapping_display(i);
7369         else if (!strcmp(res->what, "dcb_tc"))
7370                 RTE_ETH_FOREACH_DEV(i)
7371                         port_dcb_info_display(i);
7372         else if (!strcmp(res->what, "cap"))
7373                 RTE_ETH_FOREACH_DEV(i)
7374                         port_offload_cap_display(i);
7375 }
7376
7377 cmdline_parse_token_string_t cmd_showportall_show =
7378         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7379                                  "show#clear");
7380 cmdline_parse_token_string_t cmd_showportall_port =
7381         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7382 cmdline_parse_token_string_t cmd_showportall_what =
7383         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7384                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7385 cmdline_parse_token_string_t cmd_showportall_all =
7386         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7387 cmdline_parse_inst_t cmd_showportall = {
7388         .f = cmd_showportall_parsed,
7389         .data = NULL,
7390         .help_str = "show|clear port "
7391                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7392         .tokens = {
7393                 (void *)&cmd_showportall_show,
7394                 (void *)&cmd_showportall_port,
7395                 (void *)&cmd_showportall_what,
7396                 (void *)&cmd_showportall_all,
7397                 NULL,
7398         },
7399 };
7400
7401 /* *** SHOW PORT INFO *** */
7402 struct cmd_showport_result {
7403         cmdline_fixed_string_t show;
7404         cmdline_fixed_string_t port;
7405         cmdline_fixed_string_t what;
7406         uint16_t portnum;
7407 };
7408
7409 static void cmd_showport_parsed(void *parsed_result,
7410                                 __attribute__((unused)) struct cmdline *cl,
7411                                 __attribute__((unused)) void *data)
7412 {
7413         struct cmd_showport_result *res = parsed_result;
7414         if (!strcmp(res->show, "clear")) {
7415                 if (!strcmp(res->what, "stats"))
7416                         nic_stats_clear(res->portnum);
7417                 else if (!strcmp(res->what, "xstats"))
7418                         nic_xstats_clear(res->portnum);
7419         } else if (!strcmp(res->what, "info"))
7420                 port_infos_display(res->portnum);
7421         else if (!strcmp(res->what, "summary")) {
7422                 port_summary_header_display();
7423                 port_summary_display(res->portnum);
7424         }
7425         else if (!strcmp(res->what, "stats"))
7426                 nic_stats_display(res->portnum);
7427         else if (!strcmp(res->what, "xstats"))
7428                 nic_xstats_display(res->portnum);
7429         else if (!strcmp(res->what, "fdir"))
7430                  fdir_get_infos(res->portnum);
7431         else if (!strcmp(res->what, "stat_qmap"))
7432                 nic_stats_mapping_display(res->portnum);
7433         else if (!strcmp(res->what, "dcb_tc"))
7434                 port_dcb_info_display(res->portnum);
7435         else if (!strcmp(res->what, "cap"))
7436                 port_offload_cap_display(res->portnum);
7437 }
7438
7439 cmdline_parse_token_string_t cmd_showport_show =
7440         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7441                                  "show#clear");
7442 cmdline_parse_token_string_t cmd_showport_port =
7443         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7444 cmdline_parse_token_string_t cmd_showport_what =
7445         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7446                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7447 cmdline_parse_token_num_t cmd_showport_portnum =
7448         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7449
7450 cmdline_parse_inst_t cmd_showport = {
7451         .f = cmd_showport_parsed,
7452         .data = NULL,
7453         .help_str = "show|clear port "
7454                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7455                 "<port_id>",
7456         .tokens = {
7457                 (void *)&cmd_showport_show,
7458                 (void *)&cmd_showport_port,
7459                 (void *)&cmd_showport_what,
7460                 (void *)&cmd_showport_portnum,
7461                 NULL,
7462         },
7463 };
7464
7465 /* *** SHOW DEVICE INFO *** */
7466 struct cmd_showdevice_result {
7467         cmdline_fixed_string_t show;
7468         cmdline_fixed_string_t device;
7469         cmdline_fixed_string_t what;
7470         cmdline_fixed_string_t identifier;
7471 };
7472
7473 static void cmd_showdevice_parsed(void *parsed_result,
7474                                 __attribute__((unused)) struct cmdline *cl,
7475                                 __attribute__((unused)) void *data)
7476 {
7477         struct cmd_showdevice_result *res = parsed_result;
7478         if (!strcmp(res->what, "info")) {
7479                 if (!strcmp(res->identifier, "all"))
7480                         device_infos_display(NULL);
7481                 else
7482                         device_infos_display(res->identifier);
7483         }
7484 }
7485
7486 cmdline_parse_token_string_t cmd_showdevice_show =
7487         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7488                                  "show");
7489 cmdline_parse_token_string_t cmd_showdevice_device =
7490         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7491 cmdline_parse_token_string_t cmd_showdevice_what =
7492         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7493                                  "info");
7494 cmdline_parse_token_string_t cmd_showdevice_identifier =
7495         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7496                         identifier, NULL);
7497
7498 cmdline_parse_inst_t cmd_showdevice = {
7499         .f = cmd_showdevice_parsed,
7500         .data = NULL,
7501         .help_str = "show device info <identifier>|all",
7502         .tokens = {
7503                 (void *)&cmd_showdevice_show,
7504                 (void *)&cmd_showdevice_device,
7505                 (void *)&cmd_showdevice_what,
7506                 (void *)&cmd_showdevice_identifier,
7507                 NULL,
7508         },
7509 };
7510 /* *** SHOW QUEUE INFO *** */
7511 struct cmd_showqueue_result {
7512         cmdline_fixed_string_t show;
7513         cmdline_fixed_string_t type;
7514         cmdline_fixed_string_t what;
7515         uint16_t portnum;
7516         uint16_t queuenum;
7517 };
7518
7519 static void
7520 cmd_showqueue_parsed(void *parsed_result,
7521         __attribute__((unused)) struct cmdline *cl,
7522         __attribute__((unused)) void *data)
7523 {
7524         struct cmd_showqueue_result *res = parsed_result;
7525
7526         if (!strcmp(res->type, "rxq"))
7527                 rx_queue_infos_display(res->portnum, res->queuenum);
7528         else if (!strcmp(res->type, "txq"))
7529                 tx_queue_infos_display(res->portnum, res->queuenum);
7530 }
7531
7532 cmdline_parse_token_string_t cmd_showqueue_show =
7533         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7534 cmdline_parse_token_string_t cmd_showqueue_type =
7535         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7536 cmdline_parse_token_string_t cmd_showqueue_what =
7537         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7538 cmdline_parse_token_num_t cmd_showqueue_portnum =
7539         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7540 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7541         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7542
7543 cmdline_parse_inst_t cmd_showqueue = {
7544         .f = cmd_showqueue_parsed,
7545         .data = NULL,
7546         .help_str = "show rxq|txq info <port_id> <queue_id>",
7547         .tokens = {
7548                 (void *)&cmd_showqueue_show,
7549                 (void *)&cmd_showqueue_type,
7550                 (void *)&cmd_showqueue_what,
7551                 (void *)&cmd_showqueue_portnum,
7552                 (void *)&cmd_showqueue_queuenum,
7553                 NULL,
7554         },
7555 };
7556
7557 /* show/clear fwd engine statistics */
7558 struct fwd_result {
7559         cmdline_fixed_string_t action;
7560         cmdline_fixed_string_t fwd;
7561         cmdline_fixed_string_t stats;
7562         cmdline_fixed_string_t all;
7563 };
7564
7565 cmdline_parse_token_string_t cmd_fwd_action =
7566         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7567 cmdline_parse_token_string_t cmd_fwd_fwd =
7568         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7569 cmdline_parse_token_string_t cmd_fwd_stats =
7570         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7571 cmdline_parse_token_string_t cmd_fwd_all =
7572         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7573
7574 static void
7575 cmd_showfwdall_parsed(void *parsed_result,
7576                       __rte_unused struct cmdline *cl,
7577                       __rte_unused void *data)
7578 {
7579         struct fwd_result *res = parsed_result;
7580
7581         if (!strcmp(res->action, "show"))
7582                 fwd_stats_display();
7583         else
7584                 fwd_stats_reset();
7585 }
7586
7587 static cmdline_parse_inst_t cmd_showfwdall = {
7588         .f = cmd_showfwdall_parsed,
7589         .data = NULL,
7590         .help_str = "show|clear fwd stats all",
7591         .tokens = {
7592                 (void *)&cmd_fwd_action,
7593                 (void *)&cmd_fwd_fwd,
7594                 (void *)&cmd_fwd_stats,
7595                 (void *)&cmd_fwd_all,
7596                 NULL,
7597         },
7598 };
7599
7600 /* *** READ PORT REGISTER *** */
7601 struct cmd_read_reg_result {
7602         cmdline_fixed_string_t read;
7603         cmdline_fixed_string_t reg;
7604         portid_t port_id;
7605         uint32_t reg_off;
7606 };
7607
7608 static void
7609 cmd_read_reg_parsed(void *parsed_result,
7610                     __attribute__((unused)) struct cmdline *cl,
7611                     __attribute__((unused)) void *data)
7612 {
7613         struct cmd_read_reg_result *res = parsed_result;
7614         port_reg_display(res->port_id, res->reg_off);
7615 }
7616
7617 cmdline_parse_token_string_t cmd_read_reg_read =
7618         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7619 cmdline_parse_token_string_t cmd_read_reg_reg =
7620         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7621 cmdline_parse_token_num_t cmd_read_reg_port_id =
7622         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7623 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7624         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7625
7626 cmdline_parse_inst_t cmd_read_reg = {
7627         .f = cmd_read_reg_parsed,
7628         .data = NULL,
7629         .help_str = "read reg <port_id> <reg_off>",
7630         .tokens = {
7631                 (void *)&cmd_read_reg_read,
7632                 (void *)&cmd_read_reg_reg,
7633                 (void *)&cmd_read_reg_port_id,
7634                 (void *)&cmd_read_reg_reg_off,
7635                 NULL,
7636         },
7637 };
7638
7639 /* *** READ PORT REGISTER BIT FIELD *** */
7640 struct cmd_read_reg_bit_field_result {
7641         cmdline_fixed_string_t read;
7642         cmdline_fixed_string_t regfield;
7643         portid_t port_id;
7644         uint32_t reg_off;
7645         uint8_t bit1_pos;
7646         uint8_t bit2_pos;
7647 };
7648
7649 static void
7650 cmd_read_reg_bit_field_parsed(void *parsed_result,
7651                               __attribute__((unused)) struct cmdline *cl,
7652                               __attribute__((unused)) void *data)
7653 {
7654         struct cmd_read_reg_bit_field_result *res = parsed_result;
7655         port_reg_bit_field_display(res->port_id, res->reg_off,
7656                                    res->bit1_pos, res->bit2_pos);
7657 }
7658
7659 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7660         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7661                                  "read");
7662 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7663         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7664                                  regfield, "regfield");
7665 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7666         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7667                               UINT16);
7668 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7669         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7670                               UINT32);
7671 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7672         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7673                               UINT8);
7674 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7675         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7676                               UINT8);
7677
7678 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7679         .f = cmd_read_reg_bit_field_parsed,
7680         .data = NULL,
7681         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7682         "Read register bit field between bit_x and bit_y included",
7683         .tokens = {
7684                 (void *)&cmd_read_reg_bit_field_read,
7685                 (void *)&cmd_read_reg_bit_field_regfield,
7686                 (void *)&cmd_read_reg_bit_field_port_id,
7687                 (void *)&cmd_read_reg_bit_field_reg_off,
7688                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7689                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7690                 NULL,
7691         },
7692 };
7693
7694 /* *** READ PORT REGISTER BIT *** */
7695 struct cmd_read_reg_bit_result {
7696         cmdline_fixed_string_t read;
7697         cmdline_fixed_string_t regbit;
7698         portid_t port_id;
7699         uint32_t reg_off;
7700         uint8_t bit_pos;
7701 };
7702
7703 static void
7704 cmd_read_reg_bit_parsed(void *parsed_result,
7705                         __attribute__((unused)) struct cmdline *cl,
7706                         __attribute__((unused)) void *data)
7707 {
7708         struct cmd_read_reg_bit_result *res = parsed_result;
7709         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7710 }
7711
7712 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7713         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7714 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7715         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7716                                  regbit, "regbit");
7717 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7718         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7719 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7720         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7721 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7722         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7723
7724 cmdline_parse_inst_t cmd_read_reg_bit = {
7725         .f = cmd_read_reg_bit_parsed,
7726         .data = NULL,
7727         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7728         .tokens = {
7729                 (void *)&cmd_read_reg_bit_read,
7730                 (void *)&cmd_read_reg_bit_regbit,
7731                 (void *)&cmd_read_reg_bit_port_id,
7732                 (void *)&cmd_read_reg_bit_reg_off,
7733                 (void *)&cmd_read_reg_bit_bit_pos,
7734                 NULL,
7735         },
7736 };
7737
7738 /* *** WRITE PORT REGISTER *** */
7739 struct cmd_write_reg_result {
7740         cmdline_fixed_string_t write;
7741         cmdline_fixed_string_t reg;
7742         portid_t port_id;
7743         uint32_t reg_off;
7744         uint32_t value;
7745 };
7746
7747 static void
7748 cmd_write_reg_parsed(void *parsed_result,
7749                      __attribute__((unused)) struct cmdline *cl,
7750                      __attribute__((unused)) void *data)
7751 {
7752         struct cmd_write_reg_result *res = parsed_result;
7753         port_reg_set(res->port_id, res->reg_off, res->value);
7754 }
7755
7756 cmdline_parse_token_string_t cmd_write_reg_write =
7757         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7758 cmdline_parse_token_string_t cmd_write_reg_reg =
7759         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7760 cmdline_parse_token_num_t cmd_write_reg_port_id =
7761         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7762 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7763         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7764 cmdline_parse_token_num_t cmd_write_reg_value =
7765         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7766
7767 cmdline_parse_inst_t cmd_write_reg = {
7768         .f = cmd_write_reg_parsed,
7769         .data = NULL,
7770         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7771         .tokens = {
7772                 (void *)&cmd_write_reg_write,
7773                 (void *)&cmd_write_reg_reg,
7774                 (void *)&cmd_write_reg_port_id,
7775                 (void *)&cmd_write_reg_reg_off,
7776                 (void *)&cmd_write_reg_value,
7777                 NULL,
7778         },
7779 };
7780
7781 /* *** WRITE PORT REGISTER BIT FIELD *** */
7782 struct cmd_write_reg_bit_field_result {
7783         cmdline_fixed_string_t write;
7784         cmdline_fixed_string_t regfield;
7785         portid_t port_id;
7786         uint32_t reg_off;
7787         uint8_t bit1_pos;
7788         uint8_t bit2_pos;
7789         uint32_t value;
7790 };
7791
7792 static void
7793 cmd_write_reg_bit_field_parsed(void *parsed_result,
7794                                __attribute__((unused)) struct cmdline *cl,
7795                                __attribute__((unused)) void *data)
7796 {
7797         struct cmd_write_reg_bit_field_result *res = parsed_result;
7798         port_reg_bit_field_set(res->port_id, res->reg_off,
7799                           res->bit1_pos, res->bit2_pos, res->value);
7800 }
7801
7802 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7803         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7804                                  "write");
7805 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7806         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7807                                  regfield, "regfield");
7808 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7809         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7810                               UINT16);
7811 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7812         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7813                               UINT32);
7814 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7815         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7816                               UINT8);
7817 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7818         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7819                               UINT8);
7820 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7821         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7822                               UINT32);
7823
7824 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7825         .f = cmd_write_reg_bit_field_parsed,
7826         .data = NULL,
7827         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7828                 "<reg_value>: "
7829                 "Set register bit field between bit_x and bit_y included",
7830         .tokens = {
7831                 (void *)&cmd_write_reg_bit_field_write,
7832                 (void *)&cmd_write_reg_bit_field_regfield,
7833                 (void *)&cmd_write_reg_bit_field_port_id,
7834                 (void *)&cmd_write_reg_bit_field_reg_off,
7835                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7836                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7837                 (void *)&cmd_write_reg_bit_field_value,
7838                 NULL,
7839         },
7840 };
7841
7842 /* *** WRITE PORT REGISTER BIT *** */
7843 struct cmd_write_reg_bit_result {
7844         cmdline_fixed_string_t write;
7845         cmdline_fixed_string_t regbit;
7846         portid_t port_id;
7847         uint32_t reg_off;
7848         uint8_t bit_pos;
7849         uint8_t value;
7850 };
7851
7852 static void
7853 cmd_write_reg_bit_parsed(void *parsed_result,
7854                          __attribute__((unused)) struct cmdline *cl,
7855                          __attribute__((unused)) void *data)
7856 {
7857         struct cmd_write_reg_bit_result *res = parsed_result;
7858         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7859 }
7860
7861 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7862         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7863                                  "write");
7864 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7865         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7866                                  regbit, "regbit");
7867 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7868         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7869 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7870         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7871 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7872         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7873 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7874         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7875
7876 cmdline_parse_inst_t cmd_write_reg_bit = {
7877         .f = cmd_write_reg_bit_parsed,
7878         .data = NULL,
7879         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7880                 "0 <= bit_x <= 31",
7881         .tokens = {
7882                 (void *)&cmd_write_reg_bit_write,
7883                 (void *)&cmd_write_reg_bit_regbit,
7884                 (void *)&cmd_write_reg_bit_port_id,
7885                 (void *)&cmd_write_reg_bit_reg_off,
7886                 (void *)&cmd_write_reg_bit_bit_pos,
7887                 (void *)&cmd_write_reg_bit_value,
7888                 NULL,
7889         },
7890 };
7891
7892 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7893 struct cmd_read_rxd_txd_result {
7894         cmdline_fixed_string_t read;
7895         cmdline_fixed_string_t rxd_txd;
7896         portid_t port_id;
7897         uint16_t queue_id;
7898         uint16_t desc_id;
7899 };
7900
7901 static void
7902 cmd_read_rxd_txd_parsed(void *parsed_result,
7903                         __attribute__((unused)) struct cmdline *cl,
7904                         __attribute__((unused)) void *data)
7905 {
7906         struct cmd_read_rxd_txd_result *res = parsed_result;
7907
7908         if (!strcmp(res->rxd_txd, "rxd"))
7909                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7910         else if (!strcmp(res->rxd_txd, "txd"))
7911                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7912 }
7913
7914 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7915         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7916 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7917         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7918                                  "rxd#txd");
7919 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7920         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7921 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7922         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7923 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7924         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7925
7926 cmdline_parse_inst_t cmd_read_rxd_txd = {
7927         .f = cmd_read_rxd_txd_parsed,
7928         .data = NULL,
7929         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7930         .tokens = {
7931                 (void *)&cmd_read_rxd_txd_read,
7932                 (void *)&cmd_read_rxd_txd_rxd_txd,
7933                 (void *)&cmd_read_rxd_txd_port_id,
7934                 (void *)&cmd_read_rxd_txd_queue_id,
7935                 (void *)&cmd_read_rxd_txd_desc_id,
7936                 NULL,
7937         },
7938 };
7939
7940 /* *** QUIT *** */
7941 struct cmd_quit_result {
7942         cmdline_fixed_string_t quit;
7943 };
7944
7945 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7946                             struct cmdline *cl,
7947                             __attribute__((unused)) void *data)
7948 {
7949         cmdline_quit(cl);
7950 }
7951
7952 cmdline_parse_token_string_t cmd_quit_quit =
7953         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7954
7955 cmdline_parse_inst_t cmd_quit = {
7956         .f = cmd_quit_parsed,
7957         .data = NULL,
7958         .help_str = "quit: Exit application",
7959         .tokens = {
7960                 (void *)&cmd_quit_quit,
7961                 NULL,
7962         },
7963 };
7964
7965 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7966 struct cmd_mac_addr_result {
7967         cmdline_fixed_string_t mac_addr_cmd;
7968         cmdline_fixed_string_t what;
7969         uint16_t port_num;
7970         struct rte_ether_addr address;
7971 };
7972
7973 static void cmd_mac_addr_parsed(void *parsed_result,
7974                 __attribute__((unused)) struct cmdline *cl,
7975                 __attribute__((unused)) void *data)
7976 {
7977         struct cmd_mac_addr_result *res = parsed_result;
7978         int ret;
7979
7980         if (strcmp(res->what, "add") == 0)
7981                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7982         else if (strcmp(res->what, "set") == 0)
7983                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7984                                                        &res->address);
7985         else
7986                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7987
7988         /* check the return value and print it if is < 0 */
7989         if(ret < 0)
7990                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7991
7992 }
7993
7994 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7995         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7996                                 "mac_addr");
7997 cmdline_parse_token_string_t cmd_mac_addr_what =
7998         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7999                                 "add#remove#set");
8000 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8001                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8002                                         UINT16);
8003 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8004                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8005
8006 cmdline_parse_inst_t cmd_mac_addr = {
8007         .f = cmd_mac_addr_parsed,
8008         .data = (void *)0,
8009         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8010                         "Add/Remove/Set MAC address on port_id",
8011         .tokens = {
8012                 (void *)&cmd_mac_addr_cmd,
8013                 (void *)&cmd_mac_addr_what,
8014                 (void *)&cmd_mac_addr_portnum,
8015                 (void *)&cmd_mac_addr_addr,
8016                 NULL,
8017         },
8018 };
8019
8020 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8021 struct cmd_eth_peer_result {
8022         cmdline_fixed_string_t set;
8023         cmdline_fixed_string_t eth_peer;
8024         portid_t port_id;
8025         cmdline_fixed_string_t peer_addr;
8026 };
8027
8028 static void cmd_set_eth_peer_parsed(void *parsed_result,
8029                         __attribute__((unused)) struct cmdline *cl,
8030                         __attribute__((unused)) void *data)
8031 {
8032                 struct cmd_eth_peer_result *res = parsed_result;
8033
8034                 if (test_done == 0) {
8035                         printf("Please stop forwarding first\n");
8036                         return;
8037                 }
8038                 if (!strcmp(res->eth_peer, "eth-peer")) {
8039                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8040                         fwd_config_setup();
8041                 }
8042 }
8043 cmdline_parse_token_string_t cmd_eth_peer_set =
8044         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8045 cmdline_parse_token_string_t cmd_eth_peer =
8046         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8047 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8048         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8049 cmdline_parse_token_string_t cmd_eth_peer_addr =
8050         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8051
8052 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8053         .f = cmd_set_eth_peer_parsed,
8054         .data = NULL,
8055         .help_str = "set eth-peer <port_id> <peer_mac>",
8056         .tokens = {
8057                 (void *)&cmd_eth_peer_set,
8058                 (void *)&cmd_eth_peer,
8059                 (void *)&cmd_eth_peer_port_id,
8060                 (void *)&cmd_eth_peer_addr,
8061                 NULL,
8062         },
8063 };
8064
8065 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8066 struct cmd_set_qmap_result {
8067         cmdline_fixed_string_t set;
8068         cmdline_fixed_string_t qmap;
8069         cmdline_fixed_string_t what;
8070         portid_t port_id;
8071         uint16_t queue_id;
8072         uint8_t map_value;
8073 };
8074
8075 static void
8076 cmd_set_qmap_parsed(void *parsed_result,
8077                        __attribute__((unused)) struct cmdline *cl,
8078                        __attribute__((unused)) void *data)
8079 {
8080         struct cmd_set_qmap_result *res = parsed_result;
8081         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8082
8083         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8084 }
8085
8086 cmdline_parse_token_string_t cmd_setqmap_set =
8087         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8088                                  set, "set");
8089 cmdline_parse_token_string_t cmd_setqmap_qmap =
8090         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8091                                  qmap, "stat_qmap");
8092 cmdline_parse_token_string_t cmd_setqmap_what =
8093         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8094                                  what, "tx#rx");
8095 cmdline_parse_token_num_t cmd_setqmap_portid =
8096         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8097                               port_id, UINT16);
8098 cmdline_parse_token_num_t cmd_setqmap_queueid =
8099         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8100                               queue_id, UINT16);
8101 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8102         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8103                               map_value, UINT8);
8104
8105 cmdline_parse_inst_t cmd_set_qmap = {
8106         .f = cmd_set_qmap_parsed,
8107         .data = NULL,
8108         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8109                 "Set statistics mapping value on tx|rx queue_id of port_id",
8110         .tokens = {
8111                 (void *)&cmd_setqmap_set,
8112                 (void *)&cmd_setqmap_qmap,
8113                 (void *)&cmd_setqmap_what,
8114                 (void *)&cmd_setqmap_portid,
8115                 (void *)&cmd_setqmap_queueid,
8116                 (void *)&cmd_setqmap_mapvalue,
8117                 NULL,
8118         },
8119 };
8120
8121 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8122 struct cmd_set_xstats_hide_zero_result {
8123         cmdline_fixed_string_t keyword;
8124         cmdline_fixed_string_t name;
8125         cmdline_fixed_string_t on_off;
8126 };
8127
8128 static void
8129 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8130                         __attribute__((unused)) struct cmdline *cl,
8131                         __attribute__((unused)) void *data)
8132 {
8133         struct cmd_set_xstats_hide_zero_result *res;
8134         uint16_t on_off = 0;
8135
8136         res = parsed_result;
8137         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8138         set_xstats_hide_zero(on_off);
8139 }
8140
8141 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8142         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8143                                  keyword, "set");
8144 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8145         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8146                                  name, "xstats-hide-zero");
8147 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8148         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8149                                  on_off, "on#off");
8150
8151 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8152         .f = cmd_set_xstats_hide_zero_parsed,
8153         .data = NULL,
8154         .help_str = "set xstats-hide-zero on|off",
8155         .tokens = {
8156                 (void *)&cmd_set_xstats_hide_zero_keyword,
8157                 (void *)&cmd_set_xstats_hide_zero_name,
8158                 (void *)&cmd_set_xstats_hide_zero_on_off,
8159                 NULL,
8160         },
8161 };
8162
8163 /* *** CONFIGURE UNICAST HASH TABLE *** */
8164 struct cmd_set_uc_hash_table {
8165         cmdline_fixed_string_t set;
8166         cmdline_fixed_string_t port;
8167         portid_t port_id;
8168         cmdline_fixed_string_t what;
8169         struct rte_ether_addr address;
8170         cmdline_fixed_string_t mode;
8171 };
8172
8173 static void
8174 cmd_set_uc_hash_parsed(void *parsed_result,
8175                        __attribute__((unused)) struct cmdline *cl,
8176                        __attribute__((unused)) void *data)
8177 {
8178         int ret=0;
8179         struct cmd_set_uc_hash_table *res = parsed_result;
8180
8181         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8182
8183         if (strcmp(res->what, "uta") == 0)
8184                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8185                                                 &res->address,(uint8_t)is_on);
8186         if (ret < 0)
8187                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8188
8189 }
8190
8191 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8192         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8193                                  set, "set");
8194 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8195         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8196                                  port, "port");
8197 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8198         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8199                               port_id, UINT16);
8200 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8201         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8202                                  what, "uta");
8203 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8204         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8205                                 address);
8206 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8207         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8208                                  mode, "on#off");
8209
8210 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8211         .f = cmd_set_uc_hash_parsed,
8212         .data = NULL,
8213         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8214         .tokens = {
8215                 (void *)&cmd_set_uc_hash_set,
8216                 (void *)&cmd_set_uc_hash_port,
8217                 (void *)&cmd_set_uc_hash_portid,
8218                 (void *)&cmd_set_uc_hash_what,
8219                 (void *)&cmd_set_uc_hash_mac,
8220                 (void *)&cmd_set_uc_hash_mode,
8221                 NULL,
8222         },
8223 };
8224
8225 struct cmd_set_uc_all_hash_table {
8226         cmdline_fixed_string_t set;
8227         cmdline_fixed_string_t port;
8228         portid_t port_id;
8229         cmdline_fixed_string_t what;
8230         cmdline_fixed_string_t value;
8231         cmdline_fixed_string_t mode;
8232 };
8233
8234 static void
8235 cmd_set_uc_all_hash_parsed(void *parsed_result,
8236                        __attribute__((unused)) struct cmdline *cl,
8237                        __attribute__((unused)) void *data)
8238 {
8239         int ret=0;
8240         struct cmd_set_uc_all_hash_table *res = parsed_result;
8241
8242         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8243
8244         if ((strcmp(res->what, "uta") == 0) &&
8245                 (strcmp(res->value, "all") == 0))
8246                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8247         if (ret < 0)
8248                 printf("bad unicast hash table parameter,"
8249                         "return code = %d \n", ret);
8250 }
8251
8252 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8253         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8254                                  set, "set");
8255 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8256         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8257                                  port, "port");
8258 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8259         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8260                               port_id, UINT16);
8261 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8262         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8263                                  what, "uta");
8264 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8265         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8266                                 value,"all");
8267 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8268         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8269                                  mode, "on#off");
8270
8271 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8272         .f = cmd_set_uc_all_hash_parsed,
8273         .data = NULL,
8274         .help_str = "set port <port_id> uta all on|off",
8275         .tokens = {
8276                 (void *)&cmd_set_uc_all_hash_set,
8277                 (void *)&cmd_set_uc_all_hash_port,
8278                 (void *)&cmd_set_uc_all_hash_portid,
8279                 (void *)&cmd_set_uc_all_hash_what,
8280                 (void *)&cmd_set_uc_all_hash_value,
8281                 (void *)&cmd_set_uc_all_hash_mode,
8282                 NULL,
8283         },
8284 };
8285
8286 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8287 struct cmd_set_vf_macvlan_filter {
8288         cmdline_fixed_string_t set;
8289         cmdline_fixed_string_t port;
8290         portid_t port_id;
8291         cmdline_fixed_string_t vf;
8292         uint8_t vf_id;
8293         struct rte_ether_addr address;
8294         cmdline_fixed_string_t filter_type;
8295         cmdline_fixed_string_t mode;
8296 };
8297
8298 static void
8299 cmd_set_vf_macvlan_parsed(void *parsed_result,
8300                        __attribute__((unused)) struct cmdline *cl,
8301                        __attribute__((unused)) void *data)
8302 {
8303         int is_on, ret = 0;
8304         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8305         struct rte_eth_mac_filter filter;
8306
8307         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8308
8309         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8310
8311         /* set VF MAC filter */
8312         filter.is_vf = 1;
8313
8314         /* set VF ID */
8315         filter.dst_id = res->vf_id;
8316
8317         if (!strcmp(res->filter_type, "exact-mac"))
8318                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8319         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8320                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8321         else if (!strcmp(res->filter_type, "hashmac"))
8322                 filter.filter_type = RTE_MAC_HASH_MATCH;
8323         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8324                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8325
8326         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8327
8328         if (is_on)
8329                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8330                                         RTE_ETH_FILTER_MACVLAN,
8331                                         RTE_ETH_FILTER_ADD,
8332                                          &filter);
8333         else
8334                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8335                                         RTE_ETH_FILTER_MACVLAN,
8336                                         RTE_ETH_FILTER_DELETE,
8337                                         &filter);
8338
8339         if (ret < 0)
8340                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8341
8342 }
8343
8344 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8345         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8346                                  set, "set");
8347 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8348         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8349                                  port, "port");
8350 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8351         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8352                               port_id, UINT16);
8353 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8354         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8355                                  vf, "vf");
8356 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8357         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8358                                 vf_id, UINT8);
8359 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8360         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8361                                 address);
8362 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8363         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8364                                 filter_type, "exact-mac#exact-mac-vlan"
8365                                 "#hashmac#hashmac-vlan");
8366 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8367         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8368                                  mode, "on#off");
8369
8370 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8371         .f = cmd_set_vf_macvlan_parsed,
8372         .data = NULL,
8373         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8374                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8375                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8376                 "hash match rule: hash match of MAC and exact match of VLAN",
8377         .tokens = {
8378                 (void *)&cmd_set_vf_macvlan_set,
8379                 (void *)&cmd_set_vf_macvlan_port,
8380                 (void *)&cmd_set_vf_macvlan_portid,
8381                 (void *)&cmd_set_vf_macvlan_vf,
8382                 (void *)&cmd_set_vf_macvlan_vf_id,
8383                 (void *)&cmd_set_vf_macvlan_mac,
8384                 (void *)&cmd_set_vf_macvlan_filter_type,
8385                 (void *)&cmd_set_vf_macvlan_mode,
8386                 NULL,
8387         },
8388 };
8389
8390 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8391 struct cmd_set_vf_traffic {
8392         cmdline_fixed_string_t set;
8393         cmdline_fixed_string_t port;
8394         portid_t port_id;
8395         cmdline_fixed_string_t vf;
8396         uint8_t vf_id;
8397         cmdline_fixed_string_t what;
8398         cmdline_fixed_string_t mode;
8399 };
8400
8401 static void
8402 cmd_set_vf_traffic_parsed(void *parsed_result,
8403                        __attribute__((unused)) struct cmdline *cl,
8404                        __attribute__((unused)) void *data)
8405 {
8406         struct cmd_set_vf_traffic *res = parsed_result;
8407         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8408         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8409
8410         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8411 }
8412
8413 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8414         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8415                                  set, "set");
8416 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8417         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8418                                  port, "port");
8419 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8420         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8421                               port_id, UINT16);
8422 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8423         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8424                                  vf, "vf");
8425 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8426         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8427                               vf_id, UINT8);
8428 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8429         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8430                                  what, "tx#rx");
8431 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8432         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8433                                  mode, "on#off");
8434
8435 cmdline_parse_inst_t cmd_set_vf_traffic = {
8436         .f = cmd_set_vf_traffic_parsed,
8437         .data = NULL,
8438         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8439         .tokens = {
8440                 (void *)&cmd_setvf_traffic_set,
8441                 (void *)&cmd_setvf_traffic_port,
8442                 (void *)&cmd_setvf_traffic_portid,
8443                 (void *)&cmd_setvf_traffic_vf,
8444                 (void *)&cmd_setvf_traffic_vfid,
8445                 (void *)&cmd_setvf_traffic_what,
8446                 (void *)&cmd_setvf_traffic_mode,
8447                 NULL,
8448         },
8449 };
8450
8451 /* *** CONFIGURE VF RECEIVE MODE *** */
8452 struct cmd_set_vf_rxmode {
8453         cmdline_fixed_string_t set;
8454         cmdline_fixed_string_t port;
8455         portid_t port_id;
8456         cmdline_fixed_string_t vf;
8457         uint8_t vf_id;
8458         cmdline_fixed_string_t what;
8459         cmdline_fixed_string_t mode;
8460         cmdline_fixed_string_t on;
8461 };
8462
8463 static void
8464 cmd_set_vf_rxmode_parsed(void *parsed_result,
8465                        __attribute__((unused)) struct cmdline *cl,
8466                        __attribute__((unused)) void *data)
8467 {
8468         int ret = -ENOTSUP;
8469         uint16_t vf_rxmode = 0;
8470         struct cmd_set_vf_rxmode *res = parsed_result;
8471
8472         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8473         if (!strcmp(res->what,"rxmode")) {
8474                 if (!strcmp(res->mode, "AUPE"))
8475                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8476                 else if (!strcmp(res->mode, "ROPE"))
8477                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8478                 else if (!strcmp(res->mode, "BAM"))
8479                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8480                 else if (!strncmp(res->mode, "MPE",3))
8481                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8482         }
8483
8484         RTE_SET_USED(is_on);
8485
8486 #ifdef RTE_LIBRTE_IXGBE_PMD
8487         if (ret == -ENOTSUP)
8488                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8489                                                   vf_rxmode, (uint8_t)is_on);
8490 #endif
8491 #ifdef RTE_LIBRTE_BNXT_PMD
8492         if (ret == -ENOTSUP)
8493                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8494                                                  vf_rxmode, (uint8_t)is_on);
8495 #endif
8496         if (ret < 0)
8497                 printf("bad VF receive mode parameter, return code = %d \n",
8498                 ret);
8499 }
8500
8501 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8502         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8503                                  set, "set");
8504 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8505         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8506                                  port, "port");
8507 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8508         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8509                               port_id, UINT16);
8510 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8511         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8512                                  vf, "vf");
8513 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8514         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8515                               vf_id, UINT8);
8516 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8517         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8518                                  what, "rxmode");
8519 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8520         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8521                                  mode, "AUPE#ROPE#BAM#MPE");
8522 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8523         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8524                                  on, "on#off");
8525
8526 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8527         .f = cmd_set_vf_rxmode_parsed,
8528         .data = NULL,
8529         .help_str = "set port <port_id> vf <vf_id> rxmode "
8530                 "AUPE|ROPE|BAM|MPE on|off",
8531         .tokens = {
8532                 (void *)&cmd_set_vf_rxmode_set,
8533                 (void *)&cmd_set_vf_rxmode_port,
8534                 (void *)&cmd_set_vf_rxmode_portid,
8535                 (void *)&cmd_set_vf_rxmode_vf,
8536                 (void *)&cmd_set_vf_rxmode_vfid,
8537                 (void *)&cmd_set_vf_rxmode_what,
8538                 (void *)&cmd_set_vf_rxmode_mode,
8539                 (void *)&cmd_set_vf_rxmode_on,
8540                 NULL,
8541         },
8542 };
8543
8544 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8545 struct cmd_vf_mac_addr_result {
8546         cmdline_fixed_string_t mac_addr_cmd;
8547         cmdline_fixed_string_t what;
8548         cmdline_fixed_string_t port;
8549         uint16_t port_num;
8550         cmdline_fixed_string_t vf;
8551         uint8_t vf_num;
8552         struct rte_ether_addr address;
8553 };
8554
8555 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8556                 __attribute__((unused)) struct cmdline *cl,
8557                 __attribute__((unused)) void *data)
8558 {
8559         struct cmd_vf_mac_addr_result *res = parsed_result;
8560         int ret = -ENOTSUP;
8561
8562         if (strcmp(res->what, "add") != 0)
8563                 return;
8564
8565 #ifdef RTE_LIBRTE_I40E_PMD
8566         if (ret == -ENOTSUP)
8567                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8568                                                    &res->address);
8569 #endif
8570 #ifdef RTE_LIBRTE_BNXT_PMD
8571         if (ret == -ENOTSUP)
8572                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8573                                                 res->vf_num);
8574 #endif
8575
8576         if(ret < 0)
8577                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8578
8579 }
8580
8581 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8582         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8583                                 mac_addr_cmd,"mac_addr");
8584 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8585         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8586                                 what,"add");
8587 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8588         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8589                                 port,"port");
8590 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8591         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8592                                 port_num, UINT16);
8593 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8594         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8595                                 vf,"vf");
8596 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8597         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8598                                 vf_num, UINT8);
8599 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8600         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8601                                 address);
8602
8603 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8604         .f = cmd_vf_mac_addr_parsed,
8605         .data = (void *)0,
8606         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8607                 "Add MAC address filtering for a VF on port_id",
8608         .tokens = {
8609                 (void *)&cmd_vf_mac_addr_cmd,
8610                 (void *)&cmd_vf_mac_addr_what,
8611                 (void *)&cmd_vf_mac_addr_port,
8612                 (void *)&cmd_vf_mac_addr_portnum,
8613                 (void *)&cmd_vf_mac_addr_vf,
8614                 (void *)&cmd_vf_mac_addr_vfnum,
8615                 (void *)&cmd_vf_mac_addr_addr,
8616                 NULL,
8617         },
8618 };
8619
8620 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8621 struct cmd_vf_rx_vlan_filter {
8622         cmdline_fixed_string_t rx_vlan;
8623         cmdline_fixed_string_t what;
8624         uint16_t vlan_id;
8625         cmdline_fixed_string_t port;
8626         portid_t port_id;
8627         cmdline_fixed_string_t vf;
8628         uint64_t vf_mask;
8629 };
8630
8631 static void
8632 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8633                           __attribute__((unused)) struct cmdline *cl,
8634                           __attribute__((unused)) void *data)
8635 {
8636         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8637         int ret = -ENOTSUP;
8638
8639         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8640
8641 #ifdef RTE_LIBRTE_IXGBE_PMD
8642         if (ret == -ENOTSUP)
8643                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8644                                 res->vlan_id, res->vf_mask, is_add);
8645 #endif
8646 #ifdef RTE_LIBRTE_I40E_PMD
8647         if (ret == -ENOTSUP)
8648                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8649                                 res->vlan_id, res->vf_mask, is_add);
8650 #endif
8651 #ifdef RTE_LIBRTE_BNXT_PMD
8652         if (ret == -ENOTSUP)
8653                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8654                                 res->vlan_id, res->vf_mask, is_add);
8655 #endif
8656
8657         switch (ret) {
8658         case 0:
8659                 break;
8660         case -EINVAL:
8661                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8662                                 res->vlan_id, res->vf_mask);
8663                 break;
8664         case -ENODEV:
8665                 printf("invalid port_id %d\n", res->port_id);
8666                 break;
8667         case -ENOTSUP:
8668                 printf("function not implemented or supported\n");
8669                 break;
8670         default:
8671                 printf("programming error: (%s)\n", strerror(-ret));
8672         }
8673 }
8674
8675 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8676         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8677                                  rx_vlan, "rx_vlan");
8678 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8679         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8680                                  what, "add#rm");
8681 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8682         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8683                               vlan_id, UINT16);
8684 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8685         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8686                                  port, "port");
8687 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8688         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8689                               port_id, UINT16);
8690 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8691         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8692                                  vf, "vf");
8693 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8694         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8695                               vf_mask, UINT64);
8696
8697 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8698         .f = cmd_vf_rx_vlan_filter_parsed,
8699         .data = NULL,
8700         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8701                 "(vf_mask = hexadecimal VF mask)",
8702         .tokens = {
8703                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8704                 (void *)&cmd_vf_rx_vlan_filter_what,
8705                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8706                 (void *)&cmd_vf_rx_vlan_filter_port,
8707                 (void *)&cmd_vf_rx_vlan_filter_portid,
8708                 (void *)&cmd_vf_rx_vlan_filter_vf,
8709                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8710                 NULL,
8711         },
8712 };
8713
8714 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8715 struct cmd_queue_rate_limit_result {
8716         cmdline_fixed_string_t set;
8717         cmdline_fixed_string_t port;
8718         uint16_t port_num;
8719         cmdline_fixed_string_t queue;
8720         uint8_t queue_num;
8721         cmdline_fixed_string_t rate;
8722         uint16_t rate_num;
8723 };
8724
8725 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8726                 __attribute__((unused)) struct cmdline *cl,
8727                 __attribute__((unused)) void *data)
8728 {
8729         struct cmd_queue_rate_limit_result *res = parsed_result;
8730         int ret = 0;
8731
8732         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8733                 && (strcmp(res->queue, "queue") == 0)
8734                 && (strcmp(res->rate, "rate") == 0))
8735                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8736                                         res->rate_num);
8737         if (ret < 0)
8738                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8739
8740 }
8741
8742 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8743         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8744                                 set, "set");
8745 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8746         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8747                                 port, "port");
8748 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8749         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8750                                 port_num, UINT16);
8751 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8752         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8753                                 queue, "queue");
8754 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8755         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8756                                 queue_num, UINT8);
8757 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8758         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8759                                 rate, "rate");
8760 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8761         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8762                                 rate_num, UINT16);
8763
8764 cmdline_parse_inst_t cmd_queue_rate_limit = {
8765         .f = cmd_queue_rate_limit_parsed,
8766         .data = (void *)0,
8767         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8768                 "Set rate limit for a queue on port_id",
8769         .tokens = {
8770                 (void *)&cmd_queue_rate_limit_set,
8771                 (void *)&cmd_queue_rate_limit_port,
8772                 (void *)&cmd_queue_rate_limit_portnum,
8773                 (void *)&cmd_queue_rate_limit_queue,
8774                 (void *)&cmd_queue_rate_limit_queuenum,
8775                 (void *)&cmd_queue_rate_limit_rate,
8776                 (void *)&cmd_queue_rate_limit_ratenum,
8777                 NULL,
8778         },
8779 };
8780
8781 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8782 struct cmd_vf_rate_limit_result {
8783         cmdline_fixed_string_t set;
8784         cmdline_fixed_string_t port;
8785         uint16_t port_num;
8786         cmdline_fixed_string_t vf;
8787         uint8_t vf_num;
8788         cmdline_fixed_string_t rate;
8789         uint16_t rate_num;
8790         cmdline_fixed_string_t q_msk;
8791         uint64_t q_msk_val;
8792 };
8793
8794 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8795                 __attribute__((unused)) struct cmdline *cl,
8796                 __attribute__((unused)) void *data)
8797 {
8798         struct cmd_vf_rate_limit_result *res = parsed_result;
8799         int ret = 0;
8800
8801         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8802                 && (strcmp(res->vf, "vf") == 0)
8803                 && (strcmp(res->rate, "rate") == 0)
8804                 && (strcmp(res->q_msk, "queue_mask") == 0))
8805                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8806                                         res->rate_num, res->q_msk_val);
8807         if (ret < 0)
8808                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8809
8810 }
8811
8812 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8813         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8814                                 set, "set");
8815 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8816         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8817                                 port, "port");
8818 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8819         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8820                                 port_num, UINT16);
8821 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8822         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8823                                 vf, "vf");
8824 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8825         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8826                                 vf_num, UINT8);
8827 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8828         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8829                                 rate, "rate");
8830 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8831         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8832                                 rate_num, UINT16);
8833 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8834         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8835                                 q_msk, "queue_mask");
8836 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8837         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8838                                 q_msk_val, UINT64);
8839
8840 cmdline_parse_inst_t cmd_vf_rate_limit = {
8841         .f = cmd_vf_rate_limit_parsed,
8842         .data = (void *)0,
8843         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8844                 "queue_mask <queue_mask_value>: "
8845                 "Set rate limit for queues of VF on port_id",
8846         .tokens = {
8847                 (void *)&cmd_vf_rate_limit_set,
8848                 (void *)&cmd_vf_rate_limit_port,
8849                 (void *)&cmd_vf_rate_limit_portnum,
8850                 (void *)&cmd_vf_rate_limit_vf,
8851                 (void *)&cmd_vf_rate_limit_vfnum,
8852                 (void *)&cmd_vf_rate_limit_rate,
8853                 (void *)&cmd_vf_rate_limit_ratenum,
8854                 (void *)&cmd_vf_rate_limit_q_msk,
8855                 (void *)&cmd_vf_rate_limit_q_msk_val,
8856                 NULL,
8857         },
8858 };
8859
8860 /* *** ADD TUNNEL FILTER OF A PORT *** */
8861 struct cmd_tunnel_filter_result {
8862         cmdline_fixed_string_t cmd;
8863         cmdline_fixed_string_t what;
8864         portid_t port_id;
8865         struct rte_ether_addr outer_mac;
8866         struct rte_ether_addr inner_mac;
8867         cmdline_ipaddr_t ip_value;
8868         uint16_t inner_vlan;
8869         cmdline_fixed_string_t tunnel_type;
8870         cmdline_fixed_string_t filter_type;
8871         uint32_t tenant_id;
8872         uint16_t queue_num;
8873 };
8874
8875 static void
8876 cmd_tunnel_filter_parsed(void *parsed_result,
8877                           __attribute__((unused)) struct cmdline *cl,
8878                           __attribute__((unused)) void *data)
8879 {
8880         struct cmd_tunnel_filter_result *res = parsed_result;
8881         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8882         int ret = 0;
8883
8884         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8885
8886         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8887         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8888         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8889
8890         if (res->ip_value.family == AF_INET) {
8891                 tunnel_filter_conf.ip_addr.ipv4_addr =
8892                         res->ip_value.addr.ipv4.s_addr;
8893                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8894         } else {
8895                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8896                         &(res->ip_value.addr.ipv6),
8897                         sizeof(struct in6_addr));
8898                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8899         }
8900
8901         if (!strcmp(res->filter_type, "imac-ivlan"))
8902                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8903         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8904                 tunnel_filter_conf.filter_type =
8905                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8906         else if (!strcmp(res->filter_type, "imac-tenid"))
8907                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8908         else if (!strcmp(res->filter_type, "imac"))
8909                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8910         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8911                 tunnel_filter_conf.filter_type =
8912                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8913         else if (!strcmp(res->filter_type, "oip"))
8914                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8915         else if (!strcmp(res->filter_type, "iip"))
8916                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8917         else {
8918                 printf("The filter type is not supported");
8919                 return;
8920         }
8921
8922         if (!strcmp(res->tunnel_type, "vxlan"))
8923                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8924         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8925                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8926         else if (!strcmp(res->tunnel_type, "nvgre"))
8927                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8928         else if (!strcmp(res->tunnel_type, "ipingre"))
8929                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8930         else {
8931                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8932                 return;
8933         }
8934
8935         tunnel_filter_conf.tenant_id = res->tenant_id;
8936         tunnel_filter_conf.queue_id = res->queue_num;
8937         if (!strcmp(res->what, "add"))
8938                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8939                                         RTE_ETH_FILTER_TUNNEL,
8940                                         RTE_ETH_FILTER_ADD,
8941                                         &tunnel_filter_conf);
8942         else
8943                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8944                                         RTE_ETH_FILTER_TUNNEL,
8945                                         RTE_ETH_FILTER_DELETE,
8946                                         &tunnel_filter_conf);
8947         if (ret < 0)
8948                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8949                                 strerror(-ret));
8950
8951 }
8952 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8953         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8954         cmd, "tunnel_filter");
8955 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8956         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8957         what, "add#rm");
8958 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8959         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8960         port_id, UINT16);
8961 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8962         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8963         outer_mac);
8964 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8965         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8966         inner_mac);
8967 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8968         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8969         inner_vlan, UINT16);
8970 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8971         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8972         ip_value);
8973 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8974         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8975         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8976
8977 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8978         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8979         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8980                 "imac#omac-imac-tenid");
8981 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8982         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8983         tenant_id, UINT32);
8984 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8985         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8986         queue_num, UINT16);
8987
8988 cmdline_parse_inst_t cmd_tunnel_filter = {
8989         .f = cmd_tunnel_filter_parsed,
8990         .data = (void *)0,
8991         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8992                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8993                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8994                 "<queue_id>: Add/Rm tunnel filter of a port",
8995         .tokens = {
8996                 (void *)&cmd_tunnel_filter_cmd,
8997                 (void *)&cmd_tunnel_filter_what,
8998                 (void *)&cmd_tunnel_filter_port_id,
8999                 (void *)&cmd_tunnel_filter_outer_mac,
9000                 (void *)&cmd_tunnel_filter_inner_mac,
9001                 (void *)&cmd_tunnel_filter_ip_value,
9002                 (void *)&cmd_tunnel_filter_innner_vlan,
9003                 (void *)&cmd_tunnel_filter_tunnel_type,
9004                 (void *)&cmd_tunnel_filter_filter_type,
9005                 (void *)&cmd_tunnel_filter_tenant_id,
9006                 (void *)&cmd_tunnel_filter_queue_num,
9007                 NULL,
9008         },
9009 };
9010
9011 /* *** CONFIGURE TUNNEL UDP PORT *** */
9012 struct cmd_tunnel_udp_config {
9013         cmdline_fixed_string_t cmd;
9014         cmdline_fixed_string_t what;
9015         uint16_t udp_port;
9016         portid_t port_id;
9017 };
9018
9019 static void
9020 cmd_tunnel_udp_config_parsed(void *parsed_result,
9021                           __attribute__((unused)) struct cmdline *cl,
9022                           __attribute__((unused)) void *data)
9023 {
9024         struct cmd_tunnel_udp_config *res = parsed_result;
9025         struct rte_eth_udp_tunnel tunnel_udp;
9026         int ret;
9027
9028         tunnel_udp.udp_port = res->udp_port;
9029
9030         if (!strcmp(res->cmd, "rx_vxlan_port"))
9031                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9032
9033         if (!strcmp(res->what, "add"))
9034                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9035                                                       &tunnel_udp);
9036         else
9037                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9038                                                          &tunnel_udp);
9039
9040         if (ret < 0)
9041                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9042 }
9043
9044 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9045         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9046                                 cmd, "rx_vxlan_port");
9047 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9048         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9049                                 what, "add#rm");
9050 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9051         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9052                                 udp_port, UINT16);
9053 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9054         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9055                                 port_id, UINT16);
9056
9057 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9058         .f = cmd_tunnel_udp_config_parsed,
9059         .data = (void *)0,
9060         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9061                 "Add/Remove a tunneling UDP port filter",
9062         .tokens = {
9063                 (void *)&cmd_tunnel_udp_config_cmd,
9064                 (void *)&cmd_tunnel_udp_config_what,
9065                 (void *)&cmd_tunnel_udp_config_udp_port,
9066                 (void *)&cmd_tunnel_udp_config_port_id,
9067                 NULL,
9068         },
9069 };
9070
9071 struct cmd_config_tunnel_udp_port {
9072         cmdline_fixed_string_t port;
9073         cmdline_fixed_string_t config;
9074         portid_t port_id;
9075         cmdline_fixed_string_t udp_tunnel_port;
9076         cmdline_fixed_string_t action;
9077         cmdline_fixed_string_t tunnel_type;
9078         uint16_t udp_port;
9079 };
9080
9081 static void
9082 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9083                                __attribute__((unused)) struct cmdline *cl,
9084                                __attribute__((unused)) void *data)
9085 {
9086         struct cmd_config_tunnel_udp_port *res = parsed_result;
9087         struct rte_eth_udp_tunnel tunnel_udp;
9088         int ret = 0;
9089
9090         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9091                 return;
9092
9093         tunnel_udp.udp_port = res->udp_port;
9094
9095         if (!strcmp(res->tunnel_type, "vxlan")) {
9096                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9097         } else if (!strcmp(res->tunnel_type, "geneve")) {
9098                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9099         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9100                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9101         } else {
9102                 printf("Invalid tunnel type\n");
9103                 return;
9104         }
9105
9106         if (!strcmp(res->action, "add"))
9107                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9108                                                       &tunnel_udp);
9109         else
9110                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9111                                                          &tunnel_udp);
9112
9113         if (ret < 0)
9114                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9115 }
9116
9117 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9118         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9119                                  "port");
9120 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9121         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9122                                  "config");
9123 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9124         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9125                               UINT16);
9126 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9127         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9128                                  udp_tunnel_port,
9129                                  "udp_tunnel_port");
9130 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9131         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9132                                  "add#rm");
9133 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9134         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9135                                  "vxlan#geneve#vxlan-gpe");
9136 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9137         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9138                               UINT16);
9139
9140 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9141         .f = cmd_cfg_tunnel_udp_port_parsed,
9142         .data = NULL,
9143         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9144         .tokens = {
9145                 (void *)&cmd_config_tunnel_udp_port_port,
9146                 (void *)&cmd_config_tunnel_udp_port_config,
9147                 (void *)&cmd_config_tunnel_udp_port_port_id,
9148                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9149                 (void *)&cmd_config_tunnel_udp_port_action,
9150                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9151                 (void *)&cmd_config_tunnel_udp_port_value,
9152                 NULL,
9153         },
9154 };
9155
9156 /* *** GLOBAL CONFIG *** */
9157 struct cmd_global_config_result {
9158         cmdline_fixed_string_t cmd;
9159         portid_t port_id;
9160         cmdline_fixed_string_t cfg_type;
9161         uint8_t len;
9162 };
9163
9164 static void
9165 cmd_global_config_parsed(void *parsed_result,
9166                          __attribute__((unused)) struct cmdline *cl,
9167                          __attribute__((unused)) void *data)
9168 {
9169         struct cmd_global_config_result *res = parsed_result;
9170         struct rte_eth_global_cfg conf;
9171         int ret;
9172
9173         memset(&conf, 0, sizeof(conf));
9174         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9175         conf.cfg.gre_key_len = res->len;
9176         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9177                                       RTE_ETH_FILTER_SET, &conf);
9178         if (ret != 0)
9179                 printf("Global config error\n");
9180 }
9181
9182 cmdline_parse_token_string_t cmd_global_config_cmd =
9183         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9184                 "global_config");
9185 cmdline_parse_token_num_t cmd_global_config_port_id =
9186         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9187                                UINT16);
9188 cmdline_parse_token_string_t cmd_global_config_type =
9189         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9190                 cfg_type, "gre-key-len");
9191 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9192         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9193                 len, UINT8);
9194
9195 cmdline_parse_inst_t cmd_global_config = {
9196         .f = cmd_global_config_parsed,
9197         .data = (void *)NULL,
9198         .help_str = "global_config <port_id> gre-key-len <key_len>",
9199         .tokens = {
9200                 (void *)&cmd_global_config_cmd,
9201                 (void *)&cmd_global_config_port_id,
9202                 (void *)&cmd_global_config_type,
9203                 (void *)&cmd_global_config_gre_key_len,
9204                 NULL,
9205         },
9206 };
9207
9208 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9209 struct cmd_set_mirror_mask_result {
9210         cmdline_fixed_string_t set;
9211         cmdline_fixed_string_t port;
9212         portid_t port_id;
9213         cmdline_fixed_string_t mirror;
9214         uint8_t rule_id;
9215         cmdline_fixed_string_t what;
9216         cmdline_fixed_string_t value;
9217         cmdline_fixed_string_t dstpool;
9218         uint8_t dstpool_id;
9219         cmdline_fixed_string_t on;
9220 };
9221
9222 cmdline_parse_token_string_t cmd_mirror_mask_set =
9223         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9224                                 set, "set");
9225 cmdline_parse_token_string_t cmd_mirror_mask_port =
9226         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9227                                 port, "port");
9228 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9229         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9230                                 port_id, UINT16);
9231 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9232         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9233                                 mirror, "mirror-rule");
9234 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9235         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9236                                 rule_id, UINT8);
9237 cmdline_parse_token_string_t cmd_mirror_mask_what =
9238         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9239                                 what, "pool-mirror-up#pool-mirror-down"
9240                                       "#vlan-mirror");
9241 cmdline_parse_token_string_t cmd_mirror_mask_value =
9242         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9243                                 value, NULL);
9244 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9245         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9246                                 dstpool, "dst-pool");
9247 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9248         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9249                                 dstpool_id, UINT8);
9250 cmdline_parse_token_string_t cmd_mirror_mask_on =
9251         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9252                                 on, "on#off");
9253
9254 static void
9255 cmd_set_mirror_mask_parsed(void *parsed_result,
9256                        __attribute__((unused)) struct cmdline *cl,
9257                        __attribute__((unused)) void *data)
9258 {
9259         int ret,nb_item,i;
9260         struct cmd_set_mirror_mask_result *res = parsed_result;
9261         struct rte_eth_mirror_conf mr_conf;
9262
9263         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9264
9265         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9266
9267         mr_conf.dst_pool = res->dstpool_id;
9268
9269         if (!strcmp(res->what, "pool-mirror-up")) {
9270                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9271                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9272         } else if (!strcmp(res->what, "pool-mirror-down")) {
9273                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9274                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9275         } else if (!strcmp(res->what, "vlan-mirror")) {
9276                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9277                 nb_item = parse_item_list(res->value, "vlan",
9278                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9279                 if (nb_item <= 0)
9280                         return;
9281
9282                 for (i = 0; i < nb_item; i++) {
9283                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9284                                 printf("Invalid vlan_id: must be < 4096\n");
9285                                 return;
9286                         }
9287
9288                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9289                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9290                 }
9291         }
9292
9293         if (!strcmp(res->on, "on"))
9294                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9295                                                 res->rule_id, 1);
9296         else
9297                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9298                                                 res->rule_id, 0);
9299         if (ret < 0)
9300                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9301 }
9302
9303 cmdline_parse_inst_t cmd_set_mirror_mask = {
9304                 .f = cmd_set_mirror_mask_parsed,
9305                 .data = NULL,
9306                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9307                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9308                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9309                 .tokens = {
9310                         (void *)&cmd_mirror_mask_set,
9311                         (void *)&cmd_mirror_mask_port,
9312                         (void *)&cmd_mirror_mask_portid,
9313                         (void *)&cmd_mirror_mask_mirror,
9314                         (void *)&cmd_mirror_mask_ruleid,
9315                         (void *)&cmd_mirror_mask_what,
9316                         (void *)&cmd_mirror_mask_value,
9317                         (void *)&cmd_mirror_mask_dstpool,
9318                         (void *)&cmd_mirror_mask_poolid,
9319                         (void *)&cmd_mirror_mask_on,
9320                         NULL,
9321                 },
9322 };
9323
9324 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9325 struct cmd_set_mirror_link_result {
9326         cmdline_fixed_string_t set;
9327         cmdline_fixed_string_t port;
9328         portid_t port_id;
9329         cmdline_fixed_string_t mirror;
9330         uint8_t rule_id;
9331         cmdline_fixed_string_t what;
9332         cmdline_fixed_string_t dstpool;
9333         uint8_t dstpool_id;
9334         cmdline_fixed_string_t on;
9335 };
9336
9337 cmdline_parse_token_string_t cmd_mirror_link_set =
9338         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9339                                  set, "set");
9340 cmdline_parse_token_string_t cmd_mirror_link_port =
9341         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9342                                 port, "port");
9343 cmdline_parse_token_num_t cmd_mirror_link_portid =
9344         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9345                                 port_id, UINT16);
9346 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9347         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9348                                 mirror, "mirror-rule");
9349 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9350         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9351                             rule_id, UINT8);
9352 cmdline_parse_token_string_t cmd_mirror_link_what =
9353         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9354                                 what, "uplink-mirror#downlink-mirror");
9355 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9356         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9357                                 dstpool, "dst-pool");
9358 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9359         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9360                                 dstpool_id, UINT8);
9361 cmdline_parse_token_string_t cmd_mirror_link_on =
9362         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9363                                 on, "on#off");
9364
9365 static void
9366 cmd_set_mirror_link_parsed(void *parsed_result,
9367                        __attribute__((unused)) struct cmdline *cl,
9368                        __attribute__((unused)) void *data)
9369 {
9370         int ret;
9371         struct cmd_set_mirror_link_result *res = parsed_result;
9372         struct rte_eth_mirror_conf mr_conf;
9373
9374         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9375         if (!strcmp(res->what, "uplink-mirror"))
9376                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9377         else
9378                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9379
9380         mr_conf.dst_pool = res->dstpool_id;
9381
9382         if (!strcmp(res->on, "on"))
9383                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9384                                                 res->rule_id, 1);
9385         else
9386                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9387                                                 res->rule_id, 0);
9388
9389         /* check the return value and print it if is < 0 */
9390         if (ret < 0)
9391                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9392
9393 }
9394
9395 cmdline_parse_inst_t cmd_set_mirror_link = {
9396                 .f = cmd_set_mirror_link_parsed,
9397                 .data = NULL,
9398                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9399                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9400                 .tokens = {
9401                         (void *)&cmd_mirror_link_set,
9402                         (void *)&cmd_mirror_link_port,
9403                         (void *)&cmd_mirror_link_portid,
9404                         (void *)&cmd_mirror_link_mirror,
9405                         (void *)&cmd_mirror_link_ruleid,
9406                         (void *)&cmd_mirror_link_what,
9407                         (void *)&cmd_mirror_link_dstpool,
9408                         (void *)&cmd_mirror_link_poolid,
9409                         (void *)&cmd_mirror_link_on,
9410                         NULL,
9411                 },
9412 };
9413
9414 /* *** RESET VM MIRROR RULE *** */
9415 struct cmd_rm_mirror_rule_result {
9416         cmdline_fixed_string_t reset;
9417         cmdline_fixed_string_t port;
9418         portid_t port_id;
9419         cmdline_fixed_string_t mirror;
9420         uint8_t rule_id;
9421 };
9422
9423 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9424         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9425                                  reset, "reset");
9426 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9427         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9428                                 port, "port");
9429 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9430         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9431                                 port_id, UINT16);
9432 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9433         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9434                                 mirror, "mirror-rule");
9435 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9436         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9437                                 rule_id, UINT8);
9438
9439 static void
9440 cmd_reset_mirror_rule_parsed(void *parsed_result,
9441                        __attribute__((unused)) struct cmdline *cl,
9442                        __attribute__((unused)) void *data)
9443 {
9444         int ret;
9445         struct cmd_set_mirror_link_result *res = parsed_result;
9446         /* check rule_id */
9447         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9448         if(ret < 0)
9449                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9450 }
9451
9452 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9453                 .f = cmd_reset_mirror_rule_parsed,
9454                 .data = NULL,
9455                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9456                 .tokens = {
9457                         (void *)&cmd_rm_mirror_rule_reset,
9458                         (void *)&cmd_rm_mirror_rule_port,
9459                         (void *)&cmd_rm_mirror_rule_portid,
9460                         (void *)&cmd_rm_mirror_rule_mirror,
9461                         (void *)&cmd_rm_mirror_rule_ruleid,
9462                         NULL,
9463                 },
9464 };
9465
9466 /* ******************************************************************************** */
9467
9468 struct cmd_dump_result {
9469         cmdline_fixed_string_t dump;
9470 };
9471
9472 static void
9473 dump_struct_sizes(void)
9474 {
9475 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9476         DUMP_SIZE(struct rte_mbuf);
9477         DUMP_SIZE(struct rte_mempool);
9478         DUMP_SIZE(struct rte_ring);
9479 #undef DUMP_SIZE
9480 }
9481
9482 static void cmd_dump_parsed(void *parsed_result,
9483                             __attribute__((unused)) struct cmdline *cl,
9484                             __attribute__((unused)) void *data)
9485 {
9486         struct cmd_dump_result *res = parsed_result;
9487
9488         if (!strcmp(res->dump, "dump_physmem"))
9489                 rte_dump_physmem_layout(stdout);
9490         else if (!strcmp(res->dump, "dump_memzone"))
9491                 rte_memzone_dump(stdout);
9492         else if (!strcmp(res->dump, "dump_struct_sizes"))
9493                 dump_struct_sizes();
9494         else if (!strcmp(res->dump, "dump_ring"))
9495                 rte_ring_list_dump(stdout);
9496         else if (!strcmp(res->dump, "dump_mempool"))
9497                 rte_mempool_list_dump(stdout);
9498         else if (!strcmp(res->dump, "dump_devargs"))
9499                 rte_devargs_dump(stdout);
9500         else if (!strcmp(res->dump, "dump_log_types"))
9501                 rte_log_dump(stdout);
9502 }
9503
9504 cmdline_parse_token_string_t cmd_dump_dump =
9505         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9506                 "dump_physmem#"
9507                 "dump_memzone#"
9508                 "dump_struct_sizes#"
9509                 "dump_ring#"
9510                 "dump_mempool#"
9511                 "dump_devargs#"
9512                 "dump_log_types");
9513
9514 cmdline_parse_inst_t cmd_dump = {
9515         .f = cmd_dump_parsed,  /* function to call */
9516         .data = NULL,      /* 2nd arg of func */
9517         .help_str = "Dump status",
9518         .tokens = {        /* token list, NULL terminated */
9519                 (void *)&cmd_dump_dump,
9520                 NULL,
9521         },
9522 };
9523
9524 /* ******************************************************************************** */
9525
9526 struct cmd_dump_one_result {
9527         cmdline_fixed_string_t dump;
9528         cmdline_fixed_string_t name;
9529 };
9530
9531 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9532                                 __attribute__((unused)) void *data)
9533 {
9534         struct cmd_dump_one_result *res = parsed_result;
9535
9536         if (!strcmp(res->dump, "dump_ring")) {
9537                 struct rte_ring *r;
9538                 r = rte_ring_lookup(res->name);
9539                 if (r == NULL) {
9540                         cmdline_printf(cl, "Cannot find ring\n");
9541                         return;
9542                 }
9543                 rte_ring_dump(stdout, r);
9544         } else if (!strcmp(res->dump, "dump_mempool")) {
9545                 struct rte_mempool *mp;
9546                 mp = rte_mempool_lookup(res->name);
9547                 if (mp == NULL) {
9548                         cmdline_printf(cl, "Cannot find mempool\n");
9549                         return;
9550                 }
9551                 rte_mempool_dump(stdout, mp);
9552         }
9553 }
9554
9555 cmdline_parse_token_string_t cmd_dump_one_dump =
9556         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9557                                  "dump_ring#dump_mempool");
9558
9559 cmdline_parse_token_string_t cmd_dump_one_name =
9560         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9561
9562 cmdline_parse_inst_t cmd_dump_one = {
9563         .f = cmd_dump_one_parsed,  /* function to call */
9564         .data = NULL,      /* 2nd arg of func */
9565         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9566         .tokens = {        /* token list, NULL terminated */
9567                 (void *)&cmd_dump_one_dump,
9568                 (void *)&cmd_dump_one_name,
9569                 NULL,
9570         },
9571 };
9572
9573 /* *** Add/Del syn filter *** */
9574 struct cmd_syn_filter_result {
9575         cmdline_fixed_string_t filter;
9576         portid_t port_id;
9577         cmdline_fixed_string_t ops;
9578         cmdline_fixed_string_t priority;
9579         cmdline_fixed_string_t high;
9580         cmdline_fixed_string_t queue;
9581         uint16_t queue_id;
9582 };
9583
9584 static void
9585 cmd_syn_filter_parsed(void *parsed_result,
9586                         __attribute__((unused)) struct cmdline *cl,
9587                         __attribute__((unused)) void *data)
9588 {
9589         struct cmd_syn_filter_result *res = parsed_result;
9590         struct rte_eth_syn_filter syn_filter;
9591         int ret = 0;
9592
9593         ret = rte_eth_dev_filter_supported(res->port_id,
9594                                         RTE_ETH_FILTER_SYN);
9595         if (ret < 0) {
9596                 printf("syn filter is not supported on port %u.\n",
9597                                 res->port_id);
9598                 return;
9599         }
9600
9601         memset(&syn_filter, 0, sizeof(syn_filter));
9602
9603         if (!strcmp(res->ops, "add")) {
9604                 if (!strcmp(res->high, "high"))
9605                         syn_filter.hig_pri = 1;
9606                 else
9607                         syn_filter.hig_pri = 0;
9608
9609                 syn_filter.queue = res->queue_id;
9610                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9611                                                 RTE_ETH_FILTER_SYN,
9612                                                 RTE_ETH_FILTER_ADD,
9613                                                 &syn_filter);
9614         } else
9615                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9616                                                 RTE_ETH_FILTER_SYN,
9617                                                 RTE_ETH_FILTER_DELETE,
9618                                                 &syn_filter);
9619
9620         if (ret < 0)
9621                 printf("syn filter programming error: (%s)\n",
9622                                 strerror(-ret));
9623 }
9624
9625 cmdline_parse_token_string_t cmd_syn_filter_filter =
9626         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9627         filter, "syn_filter");
9628 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9629         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9630         port_id, UINT16);
9631 cmdline_parse_token_string_t cmd_syn_filter_ops =
9632         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9633         ops, "add#del");
9634 cmdline_parse_token_string_t cmd_syn_filter_priority =
9635         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9636                                 priority, "priority");
9637 cmdline_parse_token_string_t cmd_syn_filter_high =
9638         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9639                                 high, "high#low");
9640 cmdline_parse_token_string_t cmd_syn_filter_queue =
9641         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9642                                 queue, "queue");
9643 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9644         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9645                                 queue_id, UINT16);
9646
9647 cmdline_parse_inst_t cmd_syn_filter = {
9648         .f = cmd_syn_filter_parsed,
9649         .data = NULL,
9650         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9651                 "<queue_id>: Add/Delete syn filter",
9652         .tokens = {
9653                 (void *)&cmd_syn_filter_filter,
9654                 (void *)&cmd_syn_filter_port_id,
9655                 (void *)&cmd_syn_filter_ops,
9656                 (void *)&cmd_syn_filter_priority,
9657                 (void *)&cmd_syn_filter_high,
9658                 (void *)&cmd_syn_filter_queue,
9659                 (void *)&cmd_syn_filter_queue_id,
9660                 NULL,
9661         },
9662 };
9663
9664 /* *** queue region set *** */
9665 struct cmd_queue_region_result {
9666         cmdline_fixed_string_t set;
9667         cmdline_fixed_string_t port;
9668         portid_t port_id;
9669         cmdline_fixed_string_t cmd;
9670         cmdline_fixed_string_t region;
9671         uint8_t  region_id;
9672         cmdline_fixed_string_t queue_start_index;
9673         uint8_t  queue_id;
9674         cmdline_fixed_string_t queue_num;
9675         uint8_t  queue_num_value;
9676 };
9677
9678 static void
9679 cmd_queue_region_parsed(void *parsed_result,
9680                         __attribute__((unused)) struct cmdline *cl,
9681                         __attribute__((unused)) void *data)
9682 {
9683         struct cmd_queue_region_result *res = parsed_result;
9684         int ret = -ENOTSUP;
9685 #ifdef RTE_LIBRTE_I40E_PMD
9686         struct rte_pmd_i40e_queue_region_conf region_conf;
9687         enum rte_pmd_i40e_queue_region_op op_type;
9688 #endif
9689
9690         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9691                 return;
9692
9693 #ifdef RTE_LIBRTE_I40E_PMD
9694         memset(&region_conf, 0, sizeof(region_conf));
9695         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9696         region_conf.region_id = res->region_id;
9697         region_conf.queue_num = res->queue_num_value;
9698         region_conf.queue_start_index = res->queue_id;
9699
9700         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9701                                 op_type, &region_conf);
9702 #endif
9703
9704         switch (ret) {
9705         case 0:
9706                 break;
9707         case -ENOTSUP:
9708                 printf("function not implemented or supported\n");
9709                 break;
9710         default:
9711                 printf("queue region config error: (%s)\n", strerror(-ret));
9712         }
9713 }
9714
9715 cmdline_parse_token_string_t cmd_queue_region_set =
9716 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9717                 set, "set");
9718 cmdline_parse_token_string_t cmd_queue_region_port =
9719         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9720 cmdline_parse_token_num_t cmd_queue_region_port_id =
9721         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9722                                 port_id, UINT16);
9723 cmdline_parse_token_string_t cmd_queue_region_cmd =
9724         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9725                                  cmd, "queue-region");
9726 cmdline_parse_token_string_t cmd_queue_region_id =
9727         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9728                                 region, "region_id");
9729 cmdline_parse_token_num_t cmd_queue_region_index =
9730         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9731                                 region_id, UINT8);
9732 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9733         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9734                                 queue_start_index, "queue_start_index");
9735 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9736         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9737                                 queue_id, UINT8);
9738 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9739         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9740                                 queue_num, "queue_num");
9741 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9742         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9743                                 queue_num_value, UINT8);
9744
9745 cmdline_parse_inst_t cmd_queue_region = {
9746         .f = cmd_queue_region_parsed,
9747         .data = NULL,
9748         .help_str = "set port <port_id> queue-region region_id <value> "
9749                 "queue_start_index <value> queue_num <value>: Set a queue region",
9750         .tokens = {
9751                 (void *)&cmd_queue_region_set,
9752                 (void *)&cmd_queue_region_port,
9753                 (void *)&cmd_queue_region_port_id,
9754                 (void *)&cmd_queue_region_cmd,
9755                 (void *)&cmd_queue_region_id,
9756                 (void *)&cmd_queue_region_index,
9757                 (void *)&cmd_queue_region_queue_start_index,
9758                 (void *)&cmd_queue_region_queue_id,
9759                 (void *)&cmd_queue_region_queue_num,
9760                 (void *)&cmd_queue_region_queue_num_value,
9761                 NULL,
9762         },
9763 };
9764
9765 /* *** queue region and flowtype set *** */
9766 struct cmd_region_flowtype_result {
9767         cmdline_fixed_string_t set;
9768         cmdline_fixed_string_t port;
9769         portid_t port_id;
9770         cmdline_fixed_string_t cmd;
9771         cmdline_fixed_string_t region;
9772         uint8_t  region_id;
9773         cmdline_fixed_string_t flowtype;
9774         uint8_t  flowtype_id;
9775 };
9776
9777 static void
9778 cmd_region_flowtype_parsed(void *parsed_result,
9779                         __attribute__((unused)) struct cmdline *cl,
9780                         __attribute__((unused)) void *data)
9781 {
9782         struct cmd_region_flowtype_result *res = parsed_result;
9783         int ret = -ENOTSUP;
9784 #ifdef RTE_LIBRTE_I40E_PMD
9785         struct rte_pmd_i40e_queue_region_conf region_conf;
9786         enum rte_pmd_i40e_queue_region_op op_type;
9787 #endif
9788
9789         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9790                 return;
9791
9792 #ifdef RTE_LIBRTE_I40E_PMD
9793         memset(&region_conf, 0, sizeof(region_conf));
9794
9795         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9796         region_conf.region_id = res->region_id;
9797         region_conf.hw_flowtype = res->flowtype_id;
9798
9799         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9800                         op_type, &region_conf);
9801 #endif
9802
9803         switch (ret) {
9804         case 0:
9805                 break;
9806         case -ENOTSUP:
9807                 printf("function not implemented or supported\n");
9808                 break;
9809         default:
9810                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9811         }
9812 }
9813
9814 cmdline_parse_token_string_t cmd_region_flowtype_set =
9815 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9816                                 set, "set");
9817 cmdline_parse_token_string_t cmd_region_flowtype_port =
9818         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9819                                 port, "port");
9820 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9821         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9822                                 port_id, UINT16);
9823 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9824         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9825                                 cmd, "queue-region");
9826 cmdline_parse_token_string_t cmd_region_flowtype_index =
9827         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9828                                 region, "region_id");
9829 cmdline_parse_token_num_t cmd_region_flowtype_id =
9830         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9831                                 region_id, UINT8);
9832 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9833         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9834                                 flowtype, "flowtype");
9835 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9836         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9837                                 flowtype_id, UINT8);
9838 cmdline_parse_inst_t cmd_region_flowtype = {
9839         .f = cmd_region_flowtype_parsed,
9840         .data = NULL,
9841         .help_str = "set port <port_id> queue-region region_id <value> "
9842                 "flowtype <value>: Set a flowtype region index",
9843         .tokens = {
9844                 (void *)&cmd_region_flowtype_set,
9845                 (void *)&cmd_region_flowtype_port,
9846                 (void *)&cmd_region_flowtype_port_index,
9847                 (void *)&cmd_region_flowtype_cmd,
9848                 (void *)&cmd_region_flowtype_index,
9849                 (void *)&cmd_region_flowtype_id,
9850                 (void *)&cmd_region_flowtype_flow_index,
9851                 (void *)&cmd_region_flowtype_flow_id,
9852                 NULL,
9853         },
9854 };
9855
9856 /* *** User Priority (UP) to queue region (region_id) set *** */
9857 struct cmd_user_priority_region_result {
9858         cmdline_fixed_string_t set;
9859         cmdline_fixed_string_t port;
9860         portid_t port_id;
9861         cmdline_fixed_string_t cmd;
9862         cmdline_fixed_string_t user_priority;
9863         uint8_t  user_priority_id;
9864         cmdline_fixed_string_t region;
9865         uint8_t  region_id;
9866 };
9867
9868 static void
9869 cmd_user_priority_region_parsed(void *parsed_result,
9870                         __attribute__((unused)) struct cmdline *cl,
9871                         __attribute__((unused)) void *data)
9872 {
9873         struct cmd_user_priority_region_result *res = parsed_result;
9874         int ret = -ENOTSUP;
9875 #ifdef RTE_LIBRTE_I40E_PMD
9876         struct rte_pmd_i40e_queue_region_conf region_conf;
9877         enum rte_pmd_i40e_queue_region_op op_type;
9878 #endif
9879
9880         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9881                 return;
9882
9883 #ifdef RTE_LIBRTE_I40E_PMD
9884         memset(&region_conf, 0, sizeof(region_conf));
9885         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9886         region_conf.user_priority = res->user_priority_id;
9887         region_conf.region_id = res->region_id;
9888
9889         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9890                                 op_type, &region_conf);
9891 #endif
9892
9893         switch (ret) {
9894         case 0:
9895                 break;
9896         case -ENOTSUP:
9897                 printf("function not implemented or supported\n");
9898                 break;
9899         default:
9900                 printf("user_priority region config error: (%s)\n",
9901                                 strerror(-ret));
9902         }
9903 }
9904
9905 cmdline_parse_token_string_t cmd_user_priority_region_set =
9906         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9907                                 set, "set");
9908 cmdline_parse_token_string_t cmd_user_priority_region_port =
9909         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9910                                 port, "port");
9911 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9912         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9913                                 port_id, UINT16);
9914 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9915         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9916                                 cmd, "queue-region");
9917 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9918         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9919                                 user_priority, "UP");
9920 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9921         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9922                                 user_priority_id, UINT8);
9923 cmdline_parse_token_string_t cmd_user_priority_region_region =
9924         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9925                                 region, "region_id");
9926 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9927         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9928                                 region_id, UINT8);
9929
9930 cmdline_parse_inst_t cmd_user_priority_region = {
9931         .f = cmd_user_priority_region_parsed,
9932         .data = NULL,
9933         .help_str = "set port <port_id> queue-region UP <value> "
9934                 "region_id <value>: Set the mapping of User Priority (UP) "
9935                 "to queue region (region_id) ",
9936         .tokens = {
9937                 (void *)&cmd_user_priority_region_set,
9938                 (void *)&cmd_user_priority_region_port,
9939                 (void *)&cmd_user_priority_region_port_index,
9940                 (void *)&cmd_user_priority_region_cmd,
9941                 (void *)&cmd_user_priority_region_UP,
9942                 (void *)&cmd_user_priority_region_UP_id,
9943                 (void *)&cmd_user_priority_region_region,
9944                 (void *)&cmd_user_priority_region_region_id,
9945                 NULL,
9946         },
9947 };
9948
9949 /* *** flush all queue region related configuration *** */
9950 struct cmd_flush_queue_region_result {
9951         cmdline_fixed_string_t set;
9952         cmdline_fixed_string_t port;
9953         portid_t port_id;
9954         cmdline_fixed_string_t cmd;
9955         cmdline_fixed_string_t flush;
9956         cmdline_fixed_string_t what;
9957 };
9958
9959 static void
9960 cmd_flush_queue_region_parsed(void *parsed_result,
9961                         __attribute__((unused)) struct cmdline *cl,
9962                         __attribute__((unused)) void *data)
9963 {
9964         struct cmd_flush_queue_region_result *res = parsed_result;
9965         int ret = -ENOTSUP;
9966 #ifdef RTE_LIBRTE_I40E_PMD
9967         struct rte_pmd_i40e_queue_region_conf region_conf;
9968         enum rte_pmd_i40e_queue_region_op op_type;
9969 #endif
9970
9971         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9972                 return;
9973
9974 #ifdef RTE_LIBRTE_I40E_PMD
9975         memset(&region_conf, 0, sizeof(region_conf));
9976
9977         if (strcmp(res->what, "on") == 0)
9978                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9979         else
9980                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9981
9982         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9983                                 op_type, &region_conf);
9984 #endif
9985
9986         switch (ret) {
9987         case 0:
9988                 break;
9989         case -ENOTSUP:
9990                 printf("function not implemented or supported\n");
9991                 break;
9992         default:
9993                 printf("queue region config flush error: (%s)\n",
9994                                 strerror(-ret));
9995         }
9996 }
9997
9998 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9999         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10000                                 set, "set");
10001 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10002         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10003                                 port, "port");
10004 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10005         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10006                                 port_id, UINT16);
10007 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10008         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10009                                 cmd, "queue-region");
10010 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10011         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10012                                 flush, "flush");
10013 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10014         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10015                                 what, "on#off");
10016
10017 cmdline_parse_inst_t cmd_flush_queue_region = {
10018         .f = cmd_flush_queue_region_parsed,
10019         .data = NULL,
10020         .help_str = "set port <port_id> queue-region flush on|off"
10021                 ": flush all queue region related configuration",
10022         .tokens = {
10023                 (void *)&cmd_flush_queue_region_set,
10024                 (void *)&cmd_flush_queue_region_port,
10025                 (void *)&cmd_flush_queue_region_port_index,
10026                 (void *)&cmd_flush_queue_region_cmd,
10027                 (void *)&cmd_flush_queue_region_flush,
10028                 (void *)&cmd_flush_queue_region_what,
10029                 NULL,
10030         },
10031 };
10032
10033 /* *** get all queue region related configuration info *** */
10034 struct cmd_show_queue_region_info {
10035         cmdline_fixed_string_t show;
10036         cmdline_fixed_string_t port;
10037         portid_t port_id;
10038         cmdline_fixed_string_t cmd;
10039 };
10040
10041 static void
10042 cmd_show_queue_region_info_parsed(void *parsed_result,
10043                         __attribute__((unused)) struct cmdline *cl,
10044                         __attribute__((unused)) void *data)
10045 {
10046         struct cmd_show_queue_region_info *res = parsed_result;
10047         int ret = -ENOTSUP;
10048 #ifdef RTE_LIBRTE_I40E_PMD
10049         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10050         enum rte_pmd_i40e_queue_region_op op_type;
10051 #endif
10052
10053         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10054                 return;
10055
10056 #ifdef RTE_LIBRTE_I40E_PMD
10057         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10058
10059         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10060
10061         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10062                                         op_type, &rte_pmd_regions);
10063
10064         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10065 #endif
10066
10067         switch (ret) {
10068         case 0:
10069                 break;
10070         case -ENOTSUP:
10071                 printf("function not implemented or supported\n");
10072                 break;
10073         default:
10074                 printf("queue region config info show error: (%s)\n",
10075                                 strerror(-ret));
10076         }
10077 }
10078
10079 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10080 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10081                                 show, "show");
10082 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10083         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10084                                 port, "port");
10085 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10086         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10087                                 port_id, UINT16);
10088 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10089         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10090                                 cmd, "queue-region");
10091
10092 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10093         .f = cmd_show_queue_region_info_parsed,
10094         .data = NULL,
10095         .help_str = "show port <port_id> queue-region"
10096                 ": show all queue region related configuration info",
10097         .tokens = {
10098                 (void *)&cmd_show_queue_region_info_get,
10099                 (void *)&cmd_show_queue_region_info_port,
10100                 (void *)&cmd_show_queue_region_info_port_index,
10101                 (void *)&cmd_show_queue_region_info_cmd,
10102                 NULL,
10103         },
10104 };
10105
10106 /* *** ADD/REMOVE A 2tuple FILTER *** */
10107 struct cmd_2tuple_filter_result {
10108         cmdline_fixed_string_t filter;
10109         portid_t port_id;
10110         cmdline_fixed_string_t ops;
10111         cmdline_fixed_string_t dst_port;
10112         uint16_t dst_port_value;
10113         cmdline_fixed_string_t protocol;
10114         uint8_t protocol_value;
10115         cmdline_fixed_string_t mask;
10116         uint8_t  mask_value;
10117         cmdline_fixed_string_t tcp_flags;
10118         uint8_t tcp_flags_value;
10119         cmdline_fixed_string_t priority;
10120         uint8_t  priority_value;
10121         cmdline_fixed_string_t queue;
10122         uint16_t  queue_id;
10123 };
10124
10125 static void
10126 cmd_2tuple_filter_parsed(void *parsed_result,
10127                         __attribute__((unused)) struct cmdline *cl,
10128                         __attribute__((unused)) void *data)
10129 {
10130         struct rte_eth_ntuple_filter filter;
10131         struct cmd_2tuple_filter_result *res = parsed_result;
10132         int ret = 0;
10133
10134         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10135         if (ret < 0) {
10136                 printf("ntuple filter is not supported on port %u.\n",
10137                         res->port_id);
10138                 return;
10139         }
10140
10141         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10142
10143         filter.flags = RTE_2TUPLE_FLAGS;
10144         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10145         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10146         filter.proto = res->protocol_value;
10147         filter.priority = res->priority_value;
10148         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10149                 printf("nonzero tcp_flags is only meaningful"
10150                         " when protocol is TCP.\n");
10151                 return;
10152         }
10153         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10154                 printf("invalid TCP flags.\n");
10155                 return;
10156         }
10157
10158         if (res->tcp_flags_value != 0) {
10159                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10160                 filter.tcp_flags = res->tcp_flags_value;
10161         }
10162
10163         /* need convert to big endian. */
10164         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10165         filter.queue = res->queue_id;
10166
10167         if (!strcmp(res->ops, "add"))
10168                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10169                                 RTE_ETH_FILTER_NTUPLE,
10170                                 RTE_ETH_FILTER_ADD,
10171                                 &filter);
10172         else
10173                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10174                                 RTE_ETH_FILTER_NTUPLE,
10175                                 RTE_ETH_FILTER_DELETE,
10176                                 &filter);
10177         if (ret < 0)
10178                 printf("2tuple filter programming error: (%s)\n",
10179                         strerror(-ret));
10180
10181 }
10182
10183 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10184         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10185                                  filter, "2tuple_filter");
10186 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10187         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10188                                 port_id, UINT16);
10189 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10190         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10191                                  ops, "add#del");
10192 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10193         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10194                                 dst_port, "dst_port");
10195 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10196         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10197                                 dst_port_value, UINT16);
10198 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10199         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10200                                 protocol, "protocol");
10201 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10202         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10203                                 protocol_value, UINT8);
10204 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10205         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10206                                 mask, "mask");
10207 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10208         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10209                                 mask_value, INT8);
10210 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10211         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10212                                 tcp_flags, "tcp_flags");
10213 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10214         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10215                                 tcp_flags_value, UINT8);
10216 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10217         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10218                                 priority, "priority");
10219 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10220         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10221                                 priority_value, UINT8);
10222 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10223         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10224                                 queue, "queue");
10225 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10226         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10227                                 queue_id, UINT16);
10228
10229 cmdline_parse_inst_t cmd_2tuple_filter = {
10230         .f = cmd_2tuple_filter_parsed,
10231         .data = NULL,
10232         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10233                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10234                 "<queue_id>: Add a 2tuple filter",
10235         .tokens = {
10236                 (void *)&cmd_2tuple_filter_filter,
10237                 (void *)&cmd_2tuple_filter_port_id,
10238                 (void *)&cmd_2tuple_filter_ops,
10239                 (void *)&cmd_2tuple_filter_dst_port,
10240                 (void *)&cmd_2tuple_filter_dst_port_value,
10241                 (void *)&cmd_2tuple_filter_protocol,
10242                 (void *)&cmd_2tuple_filter_protocol_value,
10243                 (void *)&cmd_2tuple_filter_mask,
10244                 (void *)&cmd_2tuple_filter_mask_value,
10245                 (void *)&cmd_2tuple_filter_tcp_flags,
10246                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10247                 (void *)&cmd_2tuple_filter_priority,
10248                 (void *)&cmd_2tuple_filter_priority_value,
10249                 (void *)&cmd_2tuple_filter_queue,
10250                 (void *)&cmd_2tuple_filter_queue_id,
10251                 NULL,
10252         },
10253 };
10254
10255 /* *** ADD/REMOVE A 5tuple FILTER *** */
10256 struct cmd_5tuple_filter_result {
10257         cmdline_fixed_string_t filter;
10258         portid_t port_id;
10259         cmdline_fixed_string_t ops;
10260         cmdline_fixed_string_t dst_ip;
10261         cmdline_ipaddr_t dst_ip_value;
10262         cmdline_fixed_string_t src_ip;
10263         cmdline_ipaddr_t src_ip_value;
10264         cmdline_fixed_string_t dst_port;
10265         uint16_t dst_port_value;
10266         cmdline_fixed_string_t src_port;
10267         uint16_t src_port_value;
10268         cmdline_fixed_string_t protocol;
10269         uint8_t protocol_value;
10270         cmdline_fixed_string_t mask;
10271         uint8_t  mask_value;
10272         cmdline_fixed_string_t tcp_flags;
10273         uint8_t tcp_flags_value;
10274         cmdline_fixed_string_t priority;
10275         uint8_t  priority_value;
10276         cmdline_fixed_string_t queue;
10277         uint16_t  queue_id;
10278 };
10279
10280 static void
10281 cmd_5tuple_filter_parsed(void *parsed_result,
10282                         __attribute__((unused)) struct cmdline *cl,
10283                         __attribute__((unused)) void *data)
10284 {
10285         struct rte_eth_ntuple_filter filter;
10286         struct cmd_5tuple_filter_result *res = parsed_result;
10287         int ret = 0;
10288
10289         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10290         if (ret < 0) {
10291                 printf("ntuple filter is not supported on port %u.\n",
10292                         res->port_id);
10293                 return;
10294         }
10295
10296         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10297
10298         filter.flags = RTE_5TUPLE_FLAGS;
10299         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10300         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10301         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10302         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10303         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10304         filter.proto = res->protocol_value;
10305         filter.priority = res->priority_value;
10306         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10307                 printf("nonzero tcp_flags is only meaningful"
10308                         " when protocol is TCP.\n");
10309                 return;
10310         }
10311         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10312                 printf("invalid TCP flags.\n");
10313                 return;
10314         }
10315
10316         if (res->tcp_flags_value != 0) {
10317                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10318                 filter.tcp_flags = res->tcp_flags_value;
10319         }
10320
10321         if (res->dst_ip_value.family == AF_INET)
10322                 /* no need to convert, already big endian. */
10323                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10324         else {
10325                 if (filter.dst_ip_mask == 0) {
10326                         printf("can not support ipv6 involved compare.\n");
10327                         return;
10328                 }
10329                 filter.dst_ip = 0;
10330         }
10331
10332         if (res->src_ip_value.family == AF_INET)
10333                 /* no need to convert, already big endian. */
10334                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10335         else {
10336                 if (filter.src_ip_mask == 0) {
10337                         printf("can not support ipv6 involved compare.\n");
10338                         return;
10339                 }
10340                 filter.src_ip = 0;
10341         }
10342         /* need convert to big endian. */
10343         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10344         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10345         filter.queue = res->queue_id;
10346
10347         if (!strcmp(res->ops, "add"))
10348                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10349                                 RTE_ETH_FILTER_NTUPLE,
10350                                 RTE_ETH_FILTER_ADD,
10351                                 &filter);
10352         else
10353                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10354                                 RTE_ETH_FILTER_NTUPLE,
10355                                 RTE_ETH_FILTER_DELETE,
10356                                 &filter);
10357         if (ret < 0)
10358                 printf("5tuple filter programming error: (%s)\n",
10359                         strerror(-ret));
10360 }
10361
10362 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10363         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10364                                  filter, "5tuple_filter");
10365 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10366         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10367                                 port_id, UINT16);
10368 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10369         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10370                                  ops, "add#del");
10371 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10372         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10373                                 dst_ip, "dst_ip");
10374 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10375         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10376                                 dst_ip_value);
10377 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10378         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10379                                 src_ip, "src_ip");
10380 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10381         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10382                                 src_ip_value);
10383 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10384         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10385                                 dst_port, "dst_port");
10386 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10387         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10388                                 dst_port_value, UINT16);
10389 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10390         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10391                                 src_port, "src_port");
10392 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10393         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10394                                 src_port_value, UINT16);
10395 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10396         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10397                                 protocol, "protocol");
10398 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10399         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10400                                 protocol_value, UINT8);
10401 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10402         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10403                                 mask, "mask");
10404 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10405         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10406                                 mask_value, INT8);
10407 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10408         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10409                                 tcp_flags, "tcp_flags");
10410 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10411         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10412                                 tcp_flags_value, UINT8);
10413 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10414         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10415                                 priority, "priority");
10416 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10417         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10418                                 priority_value, UINT8);
10419 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10420         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10421                                 queue, "queue");
10422 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10423         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10424                                 queue_id, UINT16);
10425
10426 cmdline_parse_inst_t cmd_5tuple_filter = {
10427         .f = cmd_5tuple_filter_parsed,
10428         .data = NULL,
10429         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10430                 "src_ip <value> dst_port <value> src_port <value> "
10431                 "protocol <value>  mask <value> tcp_flags <value> "
10432                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10433         .tokens = {
10434                 (void *)&cmd_5tuple_filter_filter,
10435                 (void *)&cmd_5tuple_filter_port_id,
10436                 (void *)&cmd_5tuple_filter_ops,
10437                 (void *)&cmd_5tuple_filter_dst_ip,
10438                 (void *)&cmd_5tuple_filter_dst_ip_value,
10439                 (void *)&cmd_5tuple_filter_src_ip,
10440                 (void *)&cmd_5tuple_filter_src_ip_value,
10441                 (void *)&cmd_5tuple_filter_dst_port,
10442                 (void *)&cmd_5tuple_filter_dst_port_value,
10443                 (void *)&cmd_5tuple_filter_src_port,
10444                 (void *)&cmd_5tuple_filter_src_port_value,
10445                 (void *)&cmd_5tuple_filter_protocol,
10446                 (void *)&cmd_5tuple_filter_protocol_value,
10447                 (void *)&cmd_5tuple_filter_mask,
10448                 (void *)&cmd_5tuple_filter_mask_value,
10449                 (void *)&cmd_5tuple_filter_tcp_flags,
10450                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10451                 (void *)&cmd_5tuple_filter_priority,
10452                 (void *)&cmd_5tuple_filter_priority_value,
10453                 (void *)&cmd_5tuple_filter_queue,
10454                 (void *)&cmd_5tuple_filter_queue_id,
10455                 NULL,
10456         },
10457 };
10458
10459 /* *** ADD/REMOVE A flex FILTER *** */
10460 struct cmd_flex_filter_result {
10461         cmdline_fixed_string_t filter;
10462         cmdline_fixed_string_t ops;
10463         portid_t port_id;
10464         cmdline_fixed_string_t len;
10465         uint8_t len_value;
10466         cmdline_fixed_string_t bytes;
10467         cmdline_fixed_string_t bytes_value;
10468         cmdline_fixed_string_t mask;
10469         cmdline_fixed_string_t mask_value;
10470         cmdline_fixed_string_t priority;
10471         uint8_t priority_value;
10472         cmdline_fixed_string_t queue;
10473         uint16_t queue_id;
10474 };
10475
10476 static int xdigit2val(unsigned char c)
10477 {
10478         int val;
10479         if (isdigit(c))
10480                 val = c - '0';
10481         else if (isupper(c))
10482                 val = c - 'A' + 10;
10483         else
10484                 val = c - 'a' + 10;
10485         return val;
10486 }
10487
10488 static void
10489 cmd_flex_filter_parsed(void *parsed_result,
10490                           __attribute__((unused)) struct cmdline *cl,
10491                           __attribute__((unused)) void *data)
10492 {
10493         int ret = 0;
10494         struct rte_eth_flex_filter filter;
10495         struct cmd_flex_filter_result *res = parsed_result;
10496         char *bytes_ptr, *mask_ptr;
10497         uint16_t len, i, j = 0;
10498         char c;
10499         int val;
10500         uint8_t byte = 0;
10501
10502         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10503                 printf("the len exceed the max length 128\n");
10504                 return;
10505         }
10506         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10507         filter.len = res->len_value;
10508         filter.priority = res->priority_value;
10509         filter.queue = res->queue_id;
10510         bytes_ptr = res->bytes_value;
10511         mask_ptr = res->mask_value;
10512
10513          /* translate bytes string to array. */
10514         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10515                 (bytes_ptr[1] == 'X')))
10516                 bytes_ptr += 2;
10517         len = strnlen(bytes_ptr, res->len_value * 2);
10518         if (len == 0 || (len % 8 != 0)) {
10519                 printf("please check len and bytes input\n");
10520                 return;
10521         }
10522         for (i = 0; i < len; i++) {
10523                 c = bytes_ptr[i];
10524                 if (isxdigit(c) == 0) {
10525                         /* invalid characters. */
10526                         printf("invalid input\n");
10527                         return;
10528                 }
10529                 val = xdigit2val(c);
10530                 if (i % 2) {
10531                         byte |= val;
10532                         filter.bytes[j] = byte;
10533                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10534                         j++;
10535                         byte = 0;
10536                 } else
10537                         byte |= val << 4;
10538         }
10539         printf("\n");
10540          /* translate mask string to uint8_t array. */
10541         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10542                 (mask_ptr[1] == 'X')))
10543                 mask_ptr += 2;
10544         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10545         if (len == 0) {
10546                 printf("invalid input\n");
10547                 return;
10548         }
10549         j = 0;
10550         byte = 0;
10551         for (i = 0; i < len; i++) {
10552                 c = mask_ptr[i];
10553                 if (isxdigit(c) == 0) {
10554                         /* invalid characters. */
10555                         printf("invalid input\n");
10556                         return;
10557                 }
10558                 val = xdigit2val(c);
10559                 if (i % 2) {
10560                         byte |= val;
10561                         filter.mask[j] = byte;
10562                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10563                         j++;
10564                         byte = 0;
10565                 } else
10566                         byte |= val << 4;
10567         }
10568         printf("\n");
10569
10570         if (!strcmp(res->ops, "add"))
10571                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10572                                 RTE_ETH_FILTER_FLEXIBLE,
10573                                 RTE_ETH_FILTER_ADD,
10574                                 &filter);
10575         else
10576                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10577                                 RTE_ETH_FILTER_FLEXIBLE,
10578                                 RTE_ETH_FILTER_DELETE,
10579                                 &filter);
10580
10581         if (ret < 0)
10582                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10583 }
10584
10585 cmdline_parse_token_string_t cmd_flex_filter_filter =
10586         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10587                                 filter, "flex_filter");
10588 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10589         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10590                                 port_id, UINT16);
10591 cmdline_parse_token_string_t cmd_flex_filter_ops =
10592         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10593                                 ops, "add#del");
10594 cmdline_parse_token_string_t cmd_flex_filter_len =
10595         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10596                                 len, "len");
10597 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10598         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10599                                 len_value, UINT8);
10600 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10601         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10602                                 bytes, "bytes");
10603 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10604         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10605                                 bytes_value, NULL);
10606 cmdline_parse_token_string_t cmd_flex_filter_mask =
10607         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10608                                 mask, "mask");
10609 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10610         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10611                                 mask_value, NULL);
10612 cmdline_parse_token_string_t cmd_flex_filter_priority =
10613         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10614                                 priority, "priority");
10615 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10616         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10617                                 priority_value, UINT8);
10618 cmdline_parse_token_string_t cmd_flex_filter_queue =
10619         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10620                                 queue, "queue");
10621 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10622         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10623                                 queue_id, UINT16);
10624 cmdline_parse_inst_t cmd_flex_filter = {
10625         .f = cmd_flex_filter_parsed,
10626         .data = NULL,
10627         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10628                 "<value> mask <value> priority <value> queue <queue_id>: "
10629                 "Add/Del a flex filter",
10630         .tokens = {
10631                 (void *)&cmd_flex_filter_filter,
10632                 (void *)&cmd_flex_filter_port_id,
10633                 (void *)&cmd_flex_filter_ops,
10634                 (void *)&cmd_flex_filter_len,
10635                 (void *)&cmd_flex_filter_len_value,
10636                 (void *)&cmd_flex_filter_bytes,
10637                 (void *)&cmd_flex_filter_bytes_value,
10638                 (void *)&cmd_flex_filter_mask,
10639                 (void *)&cmd_flex_filter_mask_value,
10640                 (void *)&cmd_flex_filter_priority,
10641                 (void *)&cmd_flex_filter_priority_value,
10642                 (void *)&cmd_flex_filter_queue,
10643                 (void *)&cmd_flex_filter_queue_id,
10644                 NULL,
10645         },
10646 };
10647
10648 /* *** Filters Control *** */
10649
10650 /* *** deal with ethertype filter *** */
10651 struct cmd_ethertype_filter_result {
10652         cmdline_fixed_string_t filter;
10653         portid_t port_id;
10654         cmdline_fixed_string_t ops;
10655         cmdline_fixed_string_t mac;
10656         struct rte_ether_addr mac_addr;
10657         cmdline_fixed_string_t ethertype;
10658         uint16_t ethertype_value;
10659         cmdline_fixed_string_t drop;
10660         cmdline_fixed_string_t queue;
10661         uint16_t  queue_id;
10662 };
10663
10664 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10665         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10666                                  filter, "ethertype_filter");
10667 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10668         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10669                               port_id, UINT16);
10670 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10671         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10672                                  ops, "add#del");
10673 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10674         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10675                                  mac, "mac_addr#mac_ignr");
10676 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10677         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10678                                      mac_addr);
10679 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10680         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10681                                  ethertype, "ethertype");
10682 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10683         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10684                               ethertype_value, UINT16);
10685 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10686         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10687                                  drop, "drop#fwd");
10688 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10689         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10690                                  queue, "queue");
10691 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10692         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10693                               queue_id, UINT16);
10694
10695 static void
10696 cmd_ethertype_filter_parsed(void *parsed_result,
10697                           __attribute__((unused)) struct cmdline *cl,
10698                           __attribute__((unused)) void *data)
10699 {
10700         struct cmd_ethertype_filter_result *res = parsed_result;
10701         struct rte_eth_ethertype_filter filter;
10702         int ret = 0;
10703
10704         ret = rte_eth_dev_filter_supported(res->port_id,
10705                         RTE_ETH_FILTER_ETHERTYPE);
10706         if (ret < 0) {
10707                 printf("ethertype filter is not supported on port %u.\n",
10708                         res->port_id);
10709                 return;
10710         }
10711
10712         memset(&filter, 0, sizeof(filter));
10713         if (!strcmp(res->mac, "mac_addr")) {
10714                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10715                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10716                         sizeof(struct rte_ether_addr));
10717         }
10718         if (!strcmp(res->drop, "drop"))
10719                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10720         filter.ether_type = res->ethertype_value;
10721         filter.queue = res->queue_id;
10722
10723         if (!strcmp(res->ops, "add"))
10724                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10725                                 RTE_ETH_FILTER_ETHERTYPE,
10726                                 RTE_ETH_FILTER_ADD,
10727                                 &filter);
10728         else
10729                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10730                                 RTE_ETH_FILTER_ETHERTYPE,
10731                                 RTE_ETH_FILTER_DELETE,
10732                                 &filter);
10733         if (ret < 0)
10734                 printf("ethertype filter programming error: (%s)\n",
10735                         strerror(-ret));
10736 }
10737
10738 cmdline_parse_inst_t cmd_ethertype_filter = {
10739         .f = cmd_ethertype_filter_parsed,
10740         .data = NULL,
10741         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10742                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10743                 "Add or delete an ethertype filter entry",
10744         .tokens = {
10745                 (void *)&cmd_ethertype_filter_filter,
10746                 (void *)&cmd_ethertype_filter_port_id,
10747                 (void *)&cmd_ethertype_filter_ops,
10748                 (void *)&cmd_ethertype_filter_mac,
10749                 (void *)&cmd_ethertype_filter_mac_addr,
10750                 (void *)&cmd_ethertype_filter_ethertype,
10751                 (void *)&cmd_ethertype_filter_ethertype_value,
10752                 (void *)&cmd_ethertype_filter_drop,
10753                 (void *)&cmd_ethertype_filter_queue,
10754                 (void *)&cmd_ethertype_filter_queue_id,
10755                 NULL,
10756         },
10757 };
10758
10759 /* *** deal with flow director filter *** */
10760 struct cmd_flow_director_result {
10761         cmdline_fixed_string_t flow_director_filter;
10762         portid_t port_id;
10763         cmdline_fixed_string_t mode;
10764         cmdline_fixed_string_t mode_value;
10765         cmdline_fixed_string_t ops;
10766         cmdline_fixed_string_t flow;
10767         cmdline_fixed_string_t flow_type;
10768         cmdline_fixed_string_t ether;
10769         uint16_t ether_type;
10770         cmdline_fixed_string_t src;
10771         cmdline_ipaddr_t ip_src;
10772         uint16_t port_src;
10773         cmdline_fixed_string_t dst;
10774         cmdline_ipaddr_t ip_dst;
10775         uint16_t port_dst;
10776         cmdline_fixed_string_t verify_tag;
10777         uint32_t verify_tag_value;
10778         cmdline_fixed_string_t tos;
10779         uint8_t tos_value;
10780         cmdline_fixed_string_t proto;
10781         uint8_t proto_value;
10782         cmdline_fixed_string_t ttl;
10783         uint8_t ttl_value;
10784         cmdline_fixed_string_t vlan;
10785         uint16_t vlan_value;
10786         cmdline_fixed_string_t flexbytes;
10787         cmdline_fixed_string_t flexbytes_value;
10788         cmdline_fixed_string_t pf_vf;
10789         cmdline_fixed_string_t drop;
10790         cmdline_fixed_string_t queue;
10791         uint16_t  queue_id;
10792         cmdline_fixed_string_t fd_id;
10793         uint32_t  fd_id_value;
10794         cmdline_fixed_string_t mac;
10795         struct rte_ether_addr mac_addr;
10796         cmdline_fixed_string_t tunnel;
10797         cmdline_fixed_string_t tunnel_type;
10798         cmdline_fixed_string_t tunnel_id;
10799         uint32_t tunnel_id_value;
10800         cmdline_fixed_string_t packet;
10801         char filepath[];
10802 };
10803
10804 static inline int
10805 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10806 {
10807         char s[256];
10808         const char *p, *p0 = q_arg;
10809         char *end;
10810         unsigned long int_fld;
10811         char *str_fld[max_num];
10812         int i;
10813         unsigned size;
10814         int ret = -1;
10815
10816         p = strchr(p0, '(');
10817         if (p == NULL)
10818                 return -1;
10819         ++p;
10820         p0 = strchr(p, ')');
10821         if (p0 == NULL)
10822                 return -1;
10823
10824         size = p0 - p;
10825         if (size >= sizeof(s))
10826                 return -1;
10827
10828         snprintf(s, sizeof(s), "%.*s", size, p);
10829         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10830         if (ret < 0 || ret > max_num)
10831                 return -1;
10832         for (i = 0; i < ret; i++) {
10833                 errno = 0;
10834                 int_fld = strtoul(str_fld[i], &end, 0);
10835                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10836                         return -1;
10837                 flexbytes[i] = (uint8_t)int_fld;
10838         }
10839         return ret;
10840 }
10841
10842 static uint16_t
10843 str2flowtype(char *string)
10844 {
10845         uint8_t i = 0;
10846         static const struct {
10847                 char str[32];
10848                 uint16_t type;
10849         } flowtype_str[] = {
10850                 {"raw", RTE_ETH_FLOW_RAW},
10851                 {"ipv4", RTE_ETH_FLOW_IPV4},
10852                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10853                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10854                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10855                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10856                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10857                 {"ipv6", RTE_ETH_FLOW_IPV6},
10858                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10859                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10860                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10861                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10862                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10863                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10864         };
10865
10866         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10867                 if (!strcmp(flowtype_str[i].str, string))
10868                         return flowtype_str[i].type;
10869         }
10870
10871         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10872                 return (uint16_t)atoi(string);
10873
10874         return RTE_ETH_FLOW_UNKNOWN;
10875 }
10876
10877 static enum rte_eth_fdir_tunnel_type
10878 str2fdir_tunneltype(char *string)
10879 {
10880         uint8_t i = 0;
10881
10882         static const struct {
10883                 char str[32];
10884                 enum rte_eth_fdir_tunnel_type type;
10885         } tunneltype_str[] = {
10886                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10887                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10888         };
10889
10890         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10891                 if (!strcmp(tunneltype_str[i].str, string))
10892                         return tunneltype_str[i].type;
10893         }
10894         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10895 }
10896
10897 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10898 do { \
10899         if ((ip_addr).family == AF_INET) \
10900                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10901         else { \
10902                 printf("invalid parameter.\n"); \
10903                 return; \
10904         } \
10905 } while (0)
10906
10907 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10908 do { \
10909         if ((ip_addr).family == AF_INET6) \
10910                 rte_memcpy(&(ip), \
10911                                  &((ip_addr).addr.ipv6), \
10912                                  sizeof(struct in6_addr)); \
10913         else { \
10914                 printf("invalid parameter.\n"); \
10915                 return; \
10916         } \
10917 } while (0)
10918
10919 static void
10920 cmd_flow_director_filter_parsed(void *parsed_result,
10921                           __attribute__((unused)) struct cmdline *cl,
10922                           __attribute__((unused)) void *data)
10923 {
10924         struct cmd_flow_director_result *res = parsed_result;
10925         struct rte_eth_fdir_filter entry;
10926         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10927         char *end;
10928         unsigned long vf_id;
10929         int ret = 0;
10930
10931         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10932         if (ret < 0) {
10933                 printf("flow director is not supported on port %u.\n",
10934                         res->port_id);
10935                 return;
10936         }
10937         memset(flexbytes, 0, sizeof(flexbytes));
10938         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10939
10940         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10941                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10942                         printf("Please set mode to MAC-VLAN.\n");
10943                         return;
10944                 }
10945         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10946                 if (strcmp(res->mode_value, "Tunnel")) {
10947                         printf("Please set mode to Tunnel.\n");
10948                         return;
10949                 }
10950         } else {
10951                 if (!strcmp(res->mode_value, "raw")) {
10952 #ifdef RTE_LIBRTE_I40E_PMD
10953                         struct rte_pmd_i40e_flow_type_mapping
10954                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10955                         struct rte_pmd_i40e_pkt_template_conf conf;
10956                         uint16_t flow_type = str2flowtype(res->flow_type);
10957                         uint16_t i, port = res->port_id;
10958                         uint8_t add;
10959
10960                         memset(&conf, 0, sizeof(conf));
10961
10962                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10963                                 printf("Invalid flow type specified.\n");
10964                                 return;
10965                         }
10966                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10967                                                                  mapping);
10968                         if (ret)
10969                                 return;
10970                         if (mapping[flow_type].pctype == 0ULL) {
10971                                 printf("Invalid flow type specified.\n");
10972                                 return;
10973                         }
10974                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10975                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10976                                         conf.input.pctype = i;
10977                                         break;
10978                                 }
10979                         }
10980
10981                         conf.input.packet = open_file(res->filepath,
10982                                                 &conf.input.length);
10983                         if (!conf.input.packet)
10984                                 return;
10985                         if (!strcmp(res->drop, "drop"))
10986                                 conf.action.behavior =
10987                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10988                         else
10989                                 conf.action.behavior =
10990                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10991                         conf.action.report_status =
10992                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10993                         conf.action.rx_queue = res->queue_id;
10994                         conf.soft_id = res->fd_id_value;
10995                         add  = strcmp(res->ops, "del") ? 1 : 0;
10996                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10997                                                                         &conf,
10998                                                                         add);
10999                         if (ret < 0)
11000                                 printf("flow director config error: (%s)\n",
11001                                        strerror(-ret));
11002                         close_file(conf.input.packet);
11003 #endif
11004                         return;
11005                 } else if (strcmp(res->mode_value, "IP")) {
11006                         printf("Please set mode to IP or raw.\n");
11007                         return;
11008                 }
11009                 entry.input.flow_type = str2flowtype(res->flow_type);
11010         }
11011
11012         ret = parse_flexbytes(res->flexbytes_value,
11013                                         flexbytes,
11014                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11015         if (ret < 0) {
11016                 printf("error: Cannot parse flexbytes input.\n");
11017                 return;
11018         }
11019
11020         switch (entry.input.flow_type) {
11021         case RTE_ETH_FLOW_FRAG_IPV4:
11022         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11023                 entry.input.flow.ip4_flow.proto = res->proto_value;
11024                 /* fall-through */
11025         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11026         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11027                 IPV4_ADDR_TO_UINT(res->ip_dst,
11028                         entry.input.flow.ip4_flow.dst_ip);
11029                 IPV4_ADDR_TO_UINT(res->ip_src,
11030                         entry.input.flow.ip4_flow.src_ip);
11031                 entry.input.flow.ip4_flow.tos = res->tos_value;
11032                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11033                 /* need convert to big endian. */
11034                 entry.input.flow.udp4_flow.dst_port =
11035                                 rte_cpu_to_be_16(res->port_dst);
11036                 entry.input.flow.udp4_flow.src_port =
11037                                 rte_cpu_to_be_16(res->port_src);
11038                 break;
11039         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11040                 IPV4_ADDR_TO_UINT(res->ip_dst,
11041                         entry.input.flow.sctp4_flow.ip.dst_ip);
11042                 IPV4_ADDR_TO_UINT(res->ip_src,
11043                         entry.input.flow.sctp4_flow.ip.src_ip);
11044                 entry.input.flow.ip4_flow.tos = res->tos_value;
11045                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11046                 /* need convert to big endian. */
11047                 entry.input.flow.sctp4_flow.dst_port =
11048                                 rte_cpu_to_be_16(res->port_dst);
11049                 entry.input.flow.sctp4_flow.src_port =
11050                                 rte_cpu_to_be_16(res->port_src);
11051                 entry.input.flow.sctp4_flow.verify_tag =
11052                                 rte_cpu_to_be_32(res->verify_tag_value);
11053                 break;
11054         case RTE_ETH_FLOW_FRAG_IPV6:
11055         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11056                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11057                 /* fall-through */
11058         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11059         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11060                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11061                         entry.input.flow.ipv6_flow.dst_ip);
11062                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11063                         entry.input.flow.ipv6_flow.src_ip);
11064                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11065                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11066                 /* need convert to big endian. */
11067                 entry.input.flow.udp6_flow.dst_port =
11068                                 rte_cpu_to_be_16(res->port_dst);
11069                 entry.input.flow.udp6_flow.src_port =
11070                                 rte_cpu_to_be_16(res->port_src);
11071                 break;
11072         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11073                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11074                         entry.input.flow.sctp6_flow.ip.dst_ip);
11075                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11076                         entry.input.flow.sctp6_flow.ip.src_ip);
11077                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11078                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11079                 /* need convert to big endian. */
11080                 entry.input.flow.sctp6_flow.dst_port =
11081                                 rte_cpu_to_be_16(res->port_dst);
11082                 entry.input.flow.sctp6_flow.src_port =
11083                                 rte_cpu_to_be_16(res->port_src);
11084                 entry.input.flow.sctp6_flow.verify_tag =
11085                                 rte_cpu_to_be_32(res->verify_tag_value);
11086                 break;
11087         case RTE_ETH_FLOW_L2_PAYLOAD:
11088                 entry.input.flow.l2_flow.ether_type =
11089                         rte_cpu_to_be_16(res->ether_type);
11090                 break;
11091         default:
11092                 break;
11093         }
11094
11095         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11096                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11097                                  &res->mac_addr,
11098                                  sizeof(struct rte_ether_addr));
11099
11100         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11101                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11102                                  &res->mac_addr,
11103                                  sizeof(struct rte_ether_addr));
11104                 entry.input.flow.tunnel_flow.tunnel_type =
11105                         str2fdir_tunneltype(res->tunnel_type);
11106                 entry.input.flow.tunnel_flow.tunnel_id =
11107                         rte_cpu_to_be_32(res->tunnel_id_value);
11108         }
11109
11110         rte_memcpy(entry.input.flow_ext.flexbytes,
11111                    flexbytes,
11112                    RTE_ETH_FDIR_MAX_FLEXLEN);
11113
11114         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11115
11116         entry.action.flex_off = 0;  /*use 0 by default */
11117         if (!strcmp(res->drop, "drop"))
11118                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11119         else
11120                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11121
11122         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11123             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11124                 if (!strcmp(res->pf_vf, "pf"))
11125                         entry.input.flow_ext.is_vf = 0;
11126                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11127                         struct rte_eth_dev_info dev_info;
11128
11129                         ret = eth_dev_info_get_print_err(res->port_id,
11130                                                 &dev_info);
11131                         if (ret != 0)
11132                                 return;
11133
11134                         errno = 0;
11135                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11136                         if (errno != 0 || *end != '\0' ||
11137                             vf_id >= dev_info.max_vfs) {
11138                                 printf("invalid parameter %s.\n", res->pf_vf);
11139                                 return;
11140                         }
11141                         entry.input.flow_ext.is_vf = 1;
11142                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11143                 } else {
11144                         printf("invalid parameter %s.\n", res->pf_vf);
11145                         return;
11146                 }
11147         }
11148
11149         /* set to report FD ID by default */
11150         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11151         entry.action.rx_queue = res->queue_id;
11152         entry.soft_id = res->fd_id_value;
11153         if (!strcmp(res->ops, "add"))
11154                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11155                                              RTE_ETH_FILTER_ADD, &entry);
11156         else if (!strcmp(res->ops, "del"))
11157                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11158                                              RTE_ETH_FILTER_DELETE, &entry);
11159         else
11160                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11161                                              RTE_ETH_FILTER_UPDATE, &entry);
11162         if (ret < 0)
11163                 printf("flow director programming error: (%s)\n",
11164                         strerror(-ret));
11165 }
11166
11167 cmdline_parse_token_string_t cmd_flow_director_filter =
11168         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11169                                  flow_director_filter, "flow_director_filter");
11170 cmdline_parse_token_num_t cmd_flow_director_port_id =
11171         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11172                               port_id, UINT16);
11173 cmdline_parse_token_string_t cmd_flow_director_ops =
11174         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11175                                  ops, "add#del#update");
11176 cmdline_parse_token_string_t cmd_flow_director_flow =
11177         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11178                                  flow, "flow");
11179 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11180         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11181                 flow_type, NULL);
11182 cmdline_parse_token_string_t cmd_flow_director_ether =
11183         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11184                                  ether, "ether");
11185 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11186         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11187                               ether_type, UINT16);
11188 cmdline_parse_token_string_t cmd_flow_director_src =
11189         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11190                                  src, "src");
11191 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11192         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11193                                  ip_src);
11194 cmdline_parse_token_num_t cmd_flow_director_port_src =
11195         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11196                               port_src, UINT16);
11197 cmdline_parse_token_string_t cmd_flow_director_dst =
11198         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11199                                  dst, "dst");
11200 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11201         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11202                                  ip_dst);
11203 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11204         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11205                               port_dst, UINT16);
11206 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11207         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11208                                   verify_tag, "verify_tag");
11209 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11210         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11211                               verify_tag_value, UINT32);
11212 cmdline_parse_token_string_t cmd_flow_director_tos =
11213         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11214                                  tos, "tos");
11215 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11216         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11217                               tos_value, UINT8);
11218 cmdline_parse_token_string_t cmd_flow_director_proto =
11219         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11220                                  proto, "proto");
11221 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11222         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11223                               proto_value, UINT8);
11224 cmdline_parse_token_string_t cmd_flow_director_ttl =
11225         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11226                                  ttl, "ttl");
11227 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11228         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11229                               ttl_value, UINT8);
11230 cmdline_parse_token_string_t cmd_flow_director_vlan =
11231         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11232                                  vlan, "vlan");
11233 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11234         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11235                               vlan_value, UINT16);
11236 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11237         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11238                                  flexbytes, "flexbytes");
11239 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11240         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11241                               flexbytes_value, NULL);
11242 cmdline_parse_token_string_t cmd_flow_director_drop =
11243         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11244                                  drop, "drop#fwd");
11245 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11246         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11247                               pf_vf, NULL);
11248 cmdline_parse_token_string_t cmd_flow_director_queue =
11249         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11250                                  queue, "queue");
11251 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11252         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11253                               queue_id, UINT16);
11254 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11255         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11256                                  fd_id, "fd_id");
11257 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11258         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11259                               fd_id_value, UINT32);
11260
11261 cmdline_parse_token_string_t cmd_flow_director_mode =
11262         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11263                                  mode, "mode");
11264 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11265         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11266                                  mode_value, "IP");
11267 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11268         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11269                                  mode_value, "MAC-VLAN");
11270 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11272                                  mode_value, "Tunnel");
11273 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11274         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11275                                  mode_value, "raw");
11276 cmdline_parse_token_string_t cmd_flow_director_mac =
11277         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11278                                  mac, "mac");
11279 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11280         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11281                                     mac_addr);
11282 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11283         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11284                                  tunnel, "tunnel");
11285 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11286         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11287                                  tunnel_type, "NVGRE#VxLAN");
11288 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11289         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11290                                  tunnel_id, "tunnel-id");
11291 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11292         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11293                               tunnel_id_value, UINT32);
11294 cmdline_parse_token_string_t cmd_flow_director_packet =
11295         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11296                                  packet, "packet");
11297 cmdline_parse_token_string_t cmd_flow_director_filepath =
11298         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11299                                  filepath, NULL);
11300
11301 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11302         .f = cmd_flow_director_filter_parsed,
11303         .data = NULL,
11304         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11305                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11306                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11307                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11308                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11309                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11310                 "fd_id <fd_id_value>: "
11311                 "Add or delete an ip flow director entry on NIC",
11312         .tokens = {
11313                 (void *)&cmd_flow_director_filter,
11314                 (void *)&cmd_flow_director_port_id,
11315                 (void *)&cmd_flow_director_mode,
11316                 (void *)&cmd_flow_director_mode_ip,
11317                 (void *)&cmd_flow_director_ops,
11318                 (void *)&cmd_flow_director_flow,
11319                 (void *)&cmd_flow_director_flow_type,
11320                 (void *)&cmd_flow_director_src,
11321                 (void *)&cmd_flow_director_ip_src,
11322                 (void *)&cmd_flow_director_dst,
11323                 (void *)&cmd_flow_director_ip_dst,
11324                 (void *)&cmd_flow_director_tos,
11325                 (void *)&cmd_flow_director_tos_value,
11326                 (void *)&cmd_flow_director_proto,
11327                 (void *)&cmd_flow_director_proto_value,
11328                 (void *)&cmd_flow_director_ttl,
11329                 (void *)&cmd_flow_director_ttl_value,
11330                 (void *)&cmd_flow_director_vlan,
11331                 (void *)&cmd_flow_director_vlan_value,
11332                 (void *)&cmd_flow_director_flexbytes,
11333                 (void *)&cmd_flow_director_flexbytes_value,
11334                 (void *)&cmd_flow_director_drop,
11335                 (void *)&cmd_flow_director_pf_vf,
11336                 (void *)&cmd_flow_director_queue,
11337                 (void *)&cmd_flow_director_queue_id,
11338                 (void *)&cmd_flow_director_fd_id,
11339                 (void *)&cmd_flow_director_fd_id_value,
11340                 NULL,
11341         },
11342 };
11343
11344 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11345         .f = cmd_flow_director_filter_parsed,
11346         .data = NULL,
11347         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11348                 "director entry on NIC",
11349         .tokens = {
11350                 (void *)&cmd_flow_director_filter,
11351                 (void *)&cmd_flow_director_port_id,
11352                 (void *)&cmd_flow_director_mode,
11353                 (void *)&cmd_flow_director_mode_ip,
11354                 (void *)&cmd_flow_director_ops,
11355                 (void *)&cmd_flow_director_flow,
11356                 (void *)&cmd_flow_director_flow_type,
11357                 (void *)&cmd_flow_director_src,
11358                 (void *)&cmd_flow_director_ip_src,
11359                 (void *)&cmd_flow_director_port_src,
11360                 (void *)&cmd_flow_director_dst,
11361                 (void *)&cmd_flow_director_ip_dst,
11362                 (void *)&cmd_flow_director_port_dst,
11363                 (void *)&cmd_flow_director_tos,
11364                 (void *)&cmd_flow_director_tos_value,
11365                 (void *)&cmd_flow_director_ttl,
11366                 (void *)&cmd_flow_director_ttl_value,
11367                 (void *)&cmd_flow_director_vlan,
11368                 (void *)&cmd_flow_director_vlan_value,
11369                 (void *)&cmd_flow_director_flexbytes,
11370                 (void *)&cmd_flow_director_flexbytes_value,
11371                 (void *)&cmd_flow_director_drop,
11372                 (void *)&cmd_flow_director_pf_vf,
11373                 (void *)&cmd_flow_director_queue,
11374                 (void *)&cmd_flow_director_queue_id,
11375                 (void *)&cmd_flow_director_fd_id,
11376                 (void *)&cmd_flow_director_fd_id_value,
11377                 NULL,
11378         },
11379 };
11380
11381 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11382         .f = cmd_flow_director_filter_parsed,
11383         .data = NULL,
11384         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11385                 "director entry on NIC",
11386         .tokens = {
11387                 (void *)&cmd_flow_director_filter,
11388                 (void *)&cmd_flow_director_port_id,
11389                 (void *)&cmd_flow_director_mode,
11390                 (void *)&cmd_flow_director_mode_ip,
11391                 (void *)&cmd_flow_director_ops,
11392                 (void *)&cmd_flow_director_flow,
11393                 (void *)&cmd_flow_director_flow_type,
11394                 (void *)&cmd_flow_director_src,
11395                 (void *)&cmd_flow_director_ip_src,
11396                 (void *)&cmd_flow_director_port_src,
11397                 (void *)&cmd_flow_director_dst,
11398                 (void *)&cmd_flow_director_ip_dst,
11399                 (void *)&cmd_flow_director_port_dst,
11400                 (void *)&cmd_flow_director_verify_tag,
11401                 (void *)&cmd_flow_director_verify_tag_value,
11402                 (void *)&cmd_flow_director_tos,
11403                 (void *)&cmd_flow_director_tos_value,
11404                 (void *)&cmd_flow_director_ttl,
11405                 (void *)&cmd_flow_director_ttl_value,
11406                 (void *)&cmd_flow_director_vlan,
11407                 (void *)&cmd_flow_director_vlan_value,
11408                 (void *)&cmd_flow_director_flexbytes,
11409                 (void *)&cmd_flow_director_flexbytes_value,
11410                 (void *)&cmd_flow_director_drop,
11411                 (void *)&cmd_flow_director_pf_vf,
11412                 (void *)&cmd_flow_director_queue,
11413                 (void *)&cmd_flow_director_queue_id,
11414                 (void *)&cmd_flow_director_fd_id,
11415                 (void *)&cmd_flow_director_fd_id_value,
11416                 NULL,
11417         },
11418 };
11419
11420 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11421         .f = cmd_flow_director_filter_parsed,
11422         .data = NULL,
11423         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11424                 "director entry on NIC",
11425         .tokens = {
11426                 (void *)&cmd_flow_director_filter,
11427                 (void *)&cmd_flow_director_port_id,
11428                 (void *)&cmd_flow_director_mode,
11429                 (void *)&cmd_flow_director_mode_ip,
11430                 (void *)&cmd_flow_director_ops,
11431                 (void *)&cmd_flow_director_flow,
11432                 (void *)&cmd_flow_director_flow_type,
11433                 (void *)&cmd_flow_director_ether,
11434                 (void *)&cmd_flow_director_ether_type,
11435                 (void *)&cmd_flow_director_flexbytes,
11436                 (void *)&cmd_flow_director_flexbytes_value,
11437                 (void *)&cmd_flow_director_drop,
11438                 (void *)&cmd_flow_director_pf_vf,
11439                 (void *)&cmd_flow_director_queue,
11440                 (void *)&cmd_flow_director_queue_id,
11441                 (void *)&cmd_flow_director_fd_id,
11442                 (void *)&cmd_flow_director_fd_id_value,
11443                 NULL,
11444         },
11445 };
11446
11447 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11448         .f = cmd_flow_director_filter_parsed,
11449         .data = NULL,
11450         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11451                 "director entry on NIC",
11452         .tokens = {
11453                 (void *)&cmd_flow_director_filter,
11454                 (void *)&cmd_flow_director_port_id,
11455                 (void *)&cmd_flow_director_mode,
11456                 (void *)&cmd_flow_director_mode_mac_vlan,
11457                 (void *)&cmd_flow_director_ops,
11458                 (void *)&cmd_flow_director_mac,
11459                 (void *)&cmd_flow_director_mac_addr,
11460                 (void *)&cmd_flow_director_vlan,
11461                 (void *)&cmd_flow_director_vlan_value,
11462                 (void *)&cmd_flow_director_flexbytes,
11463                 (void *)&cmd_flow_director_flexbytes_value,
11464                 (void *)&cmd_flow_director_drop,
11465                 (void *)&cmd_flow_director_queue,
11466                 (void *)&cmd_flow_director_queue_id,
11467                 (void *)&cmd_flow_director_fd_id,
11468                 (void *)&cmd_flow_director_fd_id_value,
11469                 NULL,
11470         },
11471 };
11472
11473 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11474         .f = cmd_flow_director_filter_parsed,
11475         .data = NULL,
11476         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11477                 "director entry on NIC",
11478         .tokens = {
11479                 (void *)&cmd_flow_director_filter,
11480                 (void *)&cmd_flow_director_port_id,
11481                 (void *)&cmd_flow_director_mode,
11482                 (void *)&cmd_flow_director_mode_tunnel,
11483                 (void *)&cmd_flow_director_ops,
11484                 (void *)&cmd_flow_director_mac,
11485                 (void *)&cmd_flow_director_mac_addr,
11486                 (void *)&cmd_flow_director_vlan,
11487                 (void *)&cmd_flow_director_vlan_value,
11488                 (void *)&cmd_flow_director_tunnel,
11489                 (void *)&cmd_flow_director_tunnel_type,
11490                 (void *)&cmd_flow_director_tunnel_id,
11491                 (void *)&cmd_flow_director_tunnel_id_value,
11492                 (void *)&cmd_flow_director_flexbytes,
11493                 (void *)&cmd_flow_director_flexbytes_value,
11494                 (void *)&cmd_flow_director_drop,
11495                 (void *)&cmd_flow_director_queue,
11496                 (void *)&cmd_flow_director_queue_id,
11497                 (void *)&cmd_flow_director_fd_id,
11498                 (void *)&cmd_flow_director_fd_id_value,
11499                 NULL,
11500         },
11501 };
11502
11503 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11504         .f = cmd_flow_director_filter_parsed,
11505         .data = NULL,
11506         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11507                 "director entry on NIC",
11508         .tokens = {
11509                 (void *)&cmd_flow_director_filter,
11510                 (void *)&cmd_flow_director_port_id,
11511                 (void *)&cmd_flow_director_mode,
11512                 (void *)&cmd_flow_director_mode_raw,
11513                 (void *)&cmd_flow_director_ops,
11514                 (void *)&cmd_flow_director_flow,
11515                 (void *)&cmd_flow_director_flow_type,
11516                 (void *)&cmd_flow_director_drop,
11517                 (void *)&cmd_flow_director_queue,
11518                 (void *)&cmd_flow_director_queue_id,
11519                 (void *)&cmd_flow_director_fd_id,
11520                 (void *)&cmd_flow_director_fd_id_value,
11521                 (void *)&cmd_flow_director_packet,
11522                 (void *)&cmd_flow_director_filepath,
11523                 NULL,
11524         },
11525 };
11526
11527 struct cmd_flush_flow_director_result {
11528         cmdline_fixed_string_t flush_flow_director;
11529         portid_t port_id;
11530 };
11531
11532 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11533         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11534                                  flush_flow_director, "flush_flow_director");
11535 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11536         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11537                               port_id, UINT16);
11538
11539 static void
11540 cmd_flush_flow_director_parsed(void *parsed_result,
11541                           __attribute__((unused)) struct cmdline *cl,
11542                           __attribute__((unused)) void *data)
11543 {
11544         struct cmd_flow_director_result *res = parsed_result;
11545         int ret = 0;
11546
11547         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11548         if (ret < 0) {
11549                 printf("flow director is not supported on port %u.\n",
11550                         res->port_id);
11551                 return;
11552         }
11553
11554         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11555                         RTE_ETH_FILTER_FLUSH, NULL);
11556         if (ret < 0)
11557                 printf("flow director table flushing error: (%s)\n",
11558                         strerror(-ret));
11559 }
11560
11561 cmdline_parse_inst_t cmd_flush_flow_director = {
11562         .f = cmd_flush_flow_director_parsed,
11563         .data = NULL,
11564         .help_str = "flush_flow_director <port_id>: "
11565                 "Flush all flow director entries of a device on NIC",
11566         .tokens = {
11567                 (void *)&cmd_flush_flow_director_flush,
11568                 (void *)&cmd_flush_flow_director_port_id,
11569                 NULL,
11570         },
11571 };
11572
11573 /* *** deal with flow director mask *** */
11574 struct cmd_flow_director_mask_result {
11575         cmdline_fixed_string_t flow_director_mask;
11576         portid_t port_id;
11577         cmdline_fixed_string_t mode;
11578         cmdline_fixed_string_t mode_value;
11579         cmdline_fixed_string_t vlan;
11580         uint16_t vlan_mask;
11581         cmdline_fixed_string_t src_mask;
11582         cmdline_ipaddr_t ipv4_src;
11583         cmdline_ipaddr_t ipv6_src;
11584         uint16_t port_src;
11585         cmdline_fixed_string_t dst_mask;
11586         cmdline_ipaddr_t ipv4_dst;
11587         cmdline_ipaddr_t ipv6_dst;
11588         uint16_t port_dst;
11589         cmdline_fixed_string_t mac;
11590         uint8_t mac_addr_byte_mask;
11591         cmdline_fixed_string_t tunnel_id;
11592         uint32_t tunnel_id_mask;
11593         cmdline_fixed_string_t tunnel_type;
11594         uint8_t tunnel_type_mask;
11595 };
11596
11597 static void
11598 cmd_flow_director_mask_parsed(void *parsed_result,
11599                           __attribute__((unused)) struct cmdline *cl,
11600                           __attribute__((unused)) void *data)
11601 {
11602         struct cmd_flow_director_mask_result *res = parsed_result;
11603         struct rte_eth_fdir_masks *mask;
11604         struct rte_port *port;
11605
11606         port = &ports[res->port_id];
11607         /** Check if the port is not started **/
11608         if (port->port_status != RTE_PORT_STOPPED) {
11609                 printf("Please stop port %d first\n", res->port_id);
11610                 return;
11611         }
11612
11613         mask = &port->dev_conf.fdir_conf.mask;
11614
11615         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11616                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11617                         printf("Please set mode to MAC-VLAN.\n");
11618                         return;
11619                 }
11620
11621                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11622         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11623                 if (strcmp(res->mode_value, "Tunnel")) {
11624                         printf("Please set mode to Tunnel.\n");
11625                         return;
11626                 }
11627
11628                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11629                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11630                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11631                 mask->tunnel_type_mask = res->tunnel_type_mask;
11632         } else {
11633                 if (strcmp(res->mode_value, "IP")) {
11634                         printf("Please set mode to IP.\n");
11635                         return;
11636                 }
11637
11638                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11639                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11640                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11641                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11642                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11643                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11644                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11645         }
11646
11647         cmd_reconfig_device_queue(res->port_id, 1, 1);
11648 }
11649
11650 cmdline_parse_token_string_t cmd_flow_director_mask =
11651         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11652                                  flow_director_mask, "flow_director_mask");
11653 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11654         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11655                               port_id, UINT16);
11656 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11657         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11658                                  vlan, "vlan");
11659 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11660         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11661                               vlan_mask, UINT16);
11662 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11663         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11664                                  src_mask, "src_mask");
11665 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11666         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11667                                  ipv4_src);
11668 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11669         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11670                                  ipv6_src);
11671 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11672         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11673                               port_src, UINT16);
11674 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11675         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11676                                  dst_mask, "dst_mask");
11677 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11678         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11679                                  ipv4_dst);
11680 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11681         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11682                                  ipv6_dst);
11683 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11684         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11685                               port_dst, UINT16);
11686
11687 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11688         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11689                                  mode, "mode");
11690 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11691         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11692                                  mode_value, "IP");
11693 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11694         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11695                                  mode_value, "MAC-VLAN");
11696 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11697         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11698                                  mode_value, "Tunnel");
11699 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11700         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11701                                  mac, "mac");
11702 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11703         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11704                               mac_addr_byte_mask, UINT8);
11705 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11706         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11707                                  tunnel_type, "tunnel-type");
11708 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11709         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11710                               tunnel_type_mask, UINT8);
11711 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11712         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11713                                  tunnel_id, "tunnel-id");
11714 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11715         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11716                               tunnel_id_mask, UINT32);
11717
11718 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11719         .f = cmd_flow_director_mask_parsed,
11720         .data = NULL,
11721         .help_str = "flow_director_mask ... : "
11722                 "Set IP mode flow director's mask on NIC",
11723         .tokens = {
11724                 (void *)&cmd_flow_director_mask,
11725                 (void *)&cmd_flow_director_mask_port_id,
11726                 (void *)&cmd_flow_director_mask_mode,
11727                 (void *)&cmd_flow_director_mask_mode_ip,
11728                 (void *)&cmd_flow_director_mask_vlan,
11729                 (void *)&cmd_flow_director_mask_vlan_value,
11730                 (void *)&cmd_flow_director_mask_src,
11731                 (void *)&cmd_flow_director_mask_ipv4_src,
11732                 (void *)&cmd_flow_director_mask_ipv6_src,
11733                 (void *)&cmd_flow_director_mask_port_src,
11734                 (void *)&cmd_flow_director_mask_dst,
11735                 (void *)&cmd_flow_director_mask_ipv4_dst,
11736                 (void *)&cmd_flow_director_mask_ipv6_dst,
11737                 (void *)&cmd_flow_director_mask_port_dst,
11738                 NULL,
11739         },
11740 };
11741
11742 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11743         .f = cmd_flow_director_mask_parsed,
11744         .data = NULL,
11745         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11746                 "flow director's mask on NIC",
11747         .tokens = {
11748                 (void *)&cmd_flow_director_mask,
11749                 (void *)&cmd_flow_director_mask_port_id,
11750                 (void *)&cmd_flow_director_mask_mode,
11751                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11752                 (void *)&cmd_flow_director_mask_vlan,
11753                 (void *)&cmd_flow_director_mask_vlan_value,
11754                 NULL,
11755         },
11756 };
11757
11758 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11759         .f = cmd_flow_director_mask_parsed,
11760         .data = NULL,
11761         .help_str = "flow_director_mask ... : Set tunnel mode "
11762                 "flow director's mask on NIC",
11763         .tokens = {
11764                 (void *)&cmd_flow_director_mask,
11765                 (void *)&cmd_flow_director_mask_port_id,
11766                 (void *)&cmd_flow_director_mask_mode,
11767                 (void *)&cmd_flow_director_mask_mode_tunnel,
11768                 (void *)&cmd_flow_director_mask_vlan,
11769                 (void *)&cmd_flow_director_mask_vlan_value,
11770                 (void *)&cmd_flow_director_mask_mac,
11771                 (void *)&cmd_flow_director_mask_mac_value,
11772                 (void *)&cmd_flow_director_mask_tunnel_type,
11773                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11774                 (void *)&cmd_flow_director_mask_tunnel_id,
11775                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11776                 NULL,
11777         },
11778 };
11779
11780 /* *** deal with flow director mask on flexible payload *** */
11781 struct cmd_flow_director_flex_mask_result {
11782         cmdline_fixed_string_t flow_director_flexmask;
11783         portid_t port_id;
11784         cmdline_fixed_string_t flow;
11785         cmdline_fixed_string_t flow_type;
11786         cmdline_fixed_string_t mask;
11787 };
11788
11789 static void
11790 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11791                           __attribute__((unused)) struct cmdline *cl,
11792                           __attribute__((unused)) void *data)
11793 {
11794         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11795         struct rte_eth_fdir_info fdir_info;
11796         struct rte_eth_fdir_flex_mask flex_mask;
11797         struct rte_port *port;
11798         uint64_t flow_type_mask;
11799         uint16_t i;
11800         int ret;
11801
11802         port = &ports[res->port_id];
11803         /** Check if the port is not started **/
11804         if (port->port_status != RTE_PORT_STOPPED) {
11805                 printf("Please stop port %d first\n", res->port_id);
11806                 return;
11807         }
11808
11809         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11810         ret = parse_flexbytes(res->mask,
11811                         flex_mask.mask,
11812                         RTE_ETH_FDIR_MAX_FLEXLEN);
11813         if (ret < 0) {
11814                 printf("error: Cannot parse mask input.\n");
11815                 return;
11816         }
11817
11818         memset(&fdir_info, 0, sizeof(fdir_info));
11819         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11820                                 RTE_ETH_FILTER_INFO, &fdir_info);
11821         if (ret < 0) {
11822                 printf("Cannot get FDir filter info\n");
11823                 return;
11824         }
11825
11826         if (!strcmp(res->flow_type, "none")) {
11827                 /* means don't specify the flow type */
11828                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11829                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11830                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11831                                0, sizeof(struct rte_eth_fdir_flex_mask));
11832                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11833                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11834                                  &flex_mask,
11835                                  sizeof(struct rte_eth_fdir_flex_mask));
11836                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11837                 return;
11838         }
11839         flow_type_mask = fdir_info.flow_types_mask[0];
11840         if (!strcmp(res->flow_type, "all")) {
11841                 if (!flow_type_mask) {
11842                         printf("No flow type supported\n");
11843                         return;
11844                 }
11845                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11846                         if (flow_type_mask & (1ULL << i)) {
11847                                 flex_mask.flow_type = i;
11848                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11849                         }
11850                 }
11851                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11852                 return;
11853         }
11854         flex_mask.flow_type = str2flowtype(res->flow_type);
11855         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11856                 printf("Flow type %s not supported on port %d\n",
11857                                 res->flow_type, res->port_id);
11858                 return;
11859         }
11860         fdir_set_flex_mask(res->port_id, &flex_mask);
11861         cmd_reconfig_device_queue(res->port_id, 1, 1);
11862 }
11863
11864 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11865         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11866                                  flow_director_flexmask,
11867                                  "flow_director_flex_mask");
11868 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11869         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11870                               port_id, UINT16);
11871 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11872         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11873                                  flow, "flow");
11874 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11875         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11876                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11877                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11878 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11879         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11880                                  mask, NULL);
11881
11882 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11883         .f = cmd_flow_director_flex_mask_parsed,
11884         .data = NULL,
11885         .help_str = "flow_director_flex_mask ... : "
11886                 "Set flow director's flex mask on NIC",
11887         .tokens = {
11888                 (void *)&cmd_flow_director_flexmask,
11889                 (void *)&cmd_flow_director_flexmask_port_id,
11890                 (void *)&cmd_flow_director_flexmask_flow,
11891                 (void *)&cmd_flow_director_flexmask_flow_type,
11892                 (void *)&cmd_flow_director_flexmask_mask,
11893                 NULL,
11894         },
11895 };
11896
11897 /* *** deal with flow director flexible payload configuration *** */
11898 struct cmd_flow_director_flexpayload_result {
11899         cmdline_fixed_string_t flow_director_flexpayload;
11900         portid_t port_id;
11901         cmdline_fixed_string_t payload_layer;
11902         cmdline_fixed_string_t payload_cfg;
11903 };
11904
11905 static inline int
11906 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11907 {
11908         char s[256];
11909         const char *p, *p0 = q_arg;
11910         char *end;
11911         unsigned long int_fld;
11912         char *str_fld[max_num];
11913         int i;
11914         unsigned size;
11915         int ret = -1;
11916
11917         p = strchr(p0, '(');
11918         if (p == NULL)
11919                 return -1;
11920         ++p;
11921         p0 = strchr(p, ')');
11922         if (p0 == NULL)
11923                 return -1;
11924
11925         size = p0 - p;
11926         if (size >= sizeof(s))
11927                 return -1;
11928
11929         snprintf(s, sizeof(s), "%.*s", size, p);
11930         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11931         if (ret < 0 || ret > max_num)
11932                 return -1;
11933         for (i = 0; i < ret; i++) {
11934                 errno = 0;
11935                 int_fld = strtoul(str_fld[i], &end, 0);
11936                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11937                         return -1;
11938                 offsets[i] = (uint16_t)int_fld;
11939         }
11940         return ret;
11941 }
11942
11943 static void
11944 cmd_flow_director_flxpld_parsed(void *parsed_result,
11945                           __attribute__((unused)) struct cmdline *cl,
11946                           __attribute__((unused)) void *data)
11947 {
11948         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11949         struct rte_eth_flex_payload_cfg flex_cfg;
11950         struct rte_port *port;
11951         int ret = 0;
11952
11953         port = &ports[res->port_id];
11954         /** Check if the port is not started **/
11955         if (port->port_status != RTE_PORT_STOPPED) {
11956                 printf("Please stop port %d first\n", res->port_id);
11957                 return;
11958         }
11959
11960         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11961
11962         if (!strcmp(res->payload_layer, "raw"))
11963                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11964         else if (!strcmp(res->payload_layer, "l2"))
11965                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11966         else if (!strcmp(res->payload_layer, "l3"))
11967                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11968         else if (!strcmp(res->payload_layer, "l4"))
11969                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11970
11971         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11972                             RTE_ETH_FDIR_MAX_FLEXLEN);
11973         if (ret < 0) {
11974                 printf("error: Cannot parse flex payload input.\n");
11975                 return;
11976         }
11977
11978         fdir_set_flex_payload(res->port_id, &flex_cfg);
11979         cmd_reconfig_device_queue(res->port_id, 1, 1);
11980 }
11981
11982 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11983         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11984                                  flow_director_flexpayload,
11985                                  "flow_director_flex_payload");
11986 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11987         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11988                               port_id, UINT16);
11989 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11990         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11991                                  payload_layer, "raw#l2#l3#l4");
11992 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11993         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11994                                  payload_cfg, NULL);
11995
11996 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11997         .f = cmd_flow_director_flxpld_parsed,
11998         .data = NULL,
11999         .help_str = "flow_director_flexpayload ... : "
12000                 "Set flow director's flex payload on NIC",
12001         .tokens = {
12002                 (void *)&cmd_flow_director_flexpayload,
12003                 (void *)&cmd_flow_director_flexpayload_port_id,
12004                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12005                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12006                 NULL,
12007         },
12008 };
12009
12010 /* Generic flow interface command. */
12011 extern cmdline_parse_inst_t cmd_flow;
12012
12013 /* *** Classification Filters Control *** */
12014 /* *** Get symmetric hash enable per port *** */
12015 struct cmd_get_sym_hash_ena_per_port_result {
12016         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12017         portid_t port_id;
12018 };
12019
12020 static void
12021 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12022                                  __rte_unused struct cmdline *cl,
12023                                  __rte_unused void *data)
12024 {
12025         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12026         struct rte_eth_hash_filter_info info;
12027         int ret;
12028
12029         if (rte_eth_dev_filter_supported(res->port_id,
12030                                 RTE_ETH_FILTER_HASH) < 0) {
12031                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12032                                                         res->port_id);
12033                 return;
12034         }
12035
12036         memset(&info, 0, sizeof(info));
12037         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12038         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12039                                                 RTE_ETH_FILTER_GET, &info);
12040
12041         if (ret < 0) {
12042                 printf("Cannot get symmetric hash enable per port "
12043                                         "on port %u\n", res->port_id);
12044                 return;
12045         }
12046
12047         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12048                                 "enabled" : "disabled", res->port_id);
12049 }
12050
12051 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12052         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12053                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12054 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12055         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12056                 port_id, UINT16);
12057
12058 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12059         .f = cmd_get_sym_hash_per_port_parsed,
12060         .data = NULL,
12061         .help_str = "get_sym_hash_ena_per_port <port_id>",
12062         .tokens = {
12063                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12064                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12065                 NULL,
12066         },
12067 };
12068
12069 /* *** Set symmetric hash enable per port *** */
12070 struct cmd_set_sym_hash_ena_per_port_result {
12071         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12072         cmdline_fixed_string_t enable;
12073         portid_t port_id;
12074 };
12075
12076 static void
12077 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12078                                  __rte_unused struct cmdline *cl,
12079                                  __rte_unused void *data)
12080 {
12081         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12082         struct rte_eth_hash_filter_info info;
12083         int ret;
12084
12085         if (rte_eth_dev_filter_supported(res->port_id,
12086                                 RTE_ETH_FILTER_HASH) < 0) {
12087                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12088                                                         res->port_id);
12089                 return;
12090         }
12091
12092         memset(&info, 0, sizeof(info));
12093         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12094         if (!strcmp(res->enable, "enable"))
12095                 info.info.enable = 1;
12096         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12097                                         RTE_ETH_FILTER_SET, &info);
12098         if (ret < 0) {
12099                 printf("Cannot set symmetric hash enable per port on "
12100                                         "port %u\n", res->port_id);
12101                 return;
12102         }
12103         printf("Symmetric hash has been set to %s on port %u\n",
12104                                         res->enable, res->port_id);
12105 }
12106
12107 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12108         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12109                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12110 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12111         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12112                 port_id, UINT16);
12113 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12114         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12115                 enable, "enable#disable");
12116
12117 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12118         .f = cmd_set_sym_hash_per_port_parsed,
12119         .data = NULL,
12120         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12121         .tokens = {
12122                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12123                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12124                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12125                 NULL,
12126         },
12127 };
12128
12129 /* Get global config of hash function */
12130 struct cmd_get_hash_global_config_result {
12131         cmdline_fixed_string_t get_hash_global_config;
12132         portid_t port_id;
12133 };
12134
12135 static char *
12136 flowtype_to_str(uint16_t ftype)
12137 {
12138         uint16_t i;
12139         static struct {
12140                 char str[16];
12141                 uint16_t ftype;
12142         } ftype_table[] = {
12143                 {"ipv4", RTE_ETH_FLOW_IPV4},
12144                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12145                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12146                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12147                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12148                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12149                 {"ipv6", RTE_ETH_FLOW_IPV6},
12150                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12151                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12152                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12153                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12154                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12155                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12156                 {"port", RTE_ETH_FLOW_PORT},
12157                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12158                 {"geneve", RTE_ETH_FLOW_GENEVE},
12159                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12160                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12161         };
12162
12163         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12164                 if (ftype_table[i].ftype == ftype)
12165                         return ftype_table[i].str;
12166         }
12167
12168         return NULL;
12169 }
12170
12171 static void
12172 cmd_get_hash_global_config_parsed(void *parsed_result,
12173                                   __rte_unused struct cmdline *cl,
12174                                   __rte_unused void *data)
12175 {
12176         struct cmd_get_hash_global_config_result *res = parsed_result;
12177         struct rte_eth_hash_filter_info info;
12178         uint32_t idx, offset;
12179         uint16_t i;
12180         char *str;
12181         int ret;
12182
12183         if (rte_eth_dev_filter_supported(res->port_id,
12184                         RTE_ETH_FILTER_HASH) < 0) {
12185                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12186                                                         res->port_id);
12187                 return;
12188         }
12189
12190         memset(&info, 0, sizeof(info));
12191         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12192         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12193                                         RTE_ETH_FILTER_GET, &info);
12194         if (ret < 0) {
12195                 printf("Cannot get hash global configurations by port %d\n",
12196                                                         res->port_id);
12197                 return;
12198         }
12199
12200         switch (info.info.global_conf.hash_func) {
12201         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12202                 printf("Hash function is Toeplitz\n");
12203                 break;
12204         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12205                 printf("Hash function is Simple XOR\n");
12206                 break;
12207         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12208                 printf("Hash function is Symmetric Toeplitz\n");
12209                 break;
12210         default:
12211                 printf("Unknown hash function\n");
12212                 break;
12213         }
12214
12215         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12216                 idx = i / UINT64_BIT;
12217                 offset = i % UINT64_BIT;
12218                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12219                                                 (1ULL << offset)))
12220                         continue;
12221                 str = flowtype_to_str(i);
12222                 if (!str)
12223                         continue;
12224                 printf("Symmetric hash is %s globally for flow type %s "
12225                                                         "by port %d\n",
12226                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12227                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12228                                                         res->port_id);
12229         }
12230 }
12231
12232 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12233         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12234                 get_hash_global_config, "get_hash_global_config");
12235 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12236         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12237                 port_id, UINT16);
12238
12239 cmdline_parse_inst_t cmd_get_hash_global_config = {
12240         .f = cmd_get_hash_global_config_parsed,
12241         .data = NULL,
12242         .help_str = "get_hash_global_config <port_id>",
12243         .tokens = {
12244                 (void *)&cmd_get_hash_global_config_all,
12245                 (void *)&cmd_get_hash_global_config_port_id,
12246                 NULL,
12247         },
12248 };
12249
12250 /* Set global config of hash function */
12251 struct cmd_set_hash_global_config_result {
12252         cmdline_fixed_string_t set_hash_global_config;
12253         portid_t port_id;
12254         cmdline_fixed_string_t hash_func;
12255         cmdline_fixed_string_t flow_type;
12256         cmdline_fixed_string_t enable;
12257 };
12258
12259 static void
12260 cmd_set_hash_global_config_parsed(void *parsed_result,
12261                                   __rte_unused struct cmdline *cl,
12262                                   __rte_unused void *data)
12263 {
12264         struct cmd_set_hash_global_config_result *res = parsed_result;
12265         struct rte_eth_hash_filter_info info;
12266         uint32_t ftype, idx, offset;
12267         int ret;
12268
12269         if (rte_eth_dev_filter_supported(res->port_id,
12270                                 RTE_ETH_FILTER_HASH) < 0) {
12271                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12272                                                         res->port_id);
12273                 return;
12274         }
12275         memset(&info, 0, sizeof(info));
12276         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12277         if (!strcmp(res->hash_func, "toeplitz"))
12278                 info.info.global_conf.hash_func =
12279                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12280         else if (!strcmp(res->hash_func, "simple_xor"))
12281                 info.info.global_conf.hash_func =
12282                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12283         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12284                 info.info.global_conf.hash_func =
12285                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12286         else if (!strcmp(res->hash_func, "default"))
12287                 info.info.global_conf.hash_func =
12288                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12289
12290         ftype = str2flowtype(res->flow_type);
12291         idx = ftype / UINT64_BIT;
12292         offset = ftype % UINT64_BIT;
12293         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12294         if (!strcmp(res->enable, "enable"))
12295                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12296                                                 (1ULL << offset);
12297         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12298                                         RTE_ETH_FILTER_SET, &info);
12299         if (ret < 0)
12300                 printf("Cannot set global hash configurations by port %d\n",
12301                                                         res->port_id);
12302         else
12303                 printf("Global hash configurations have been set "
12304                         "successfully by port %d\n", res->port_id);
12305 }
12306
12307 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12308         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12309                 set_hash_global_config, "set_hash_global_config");
12310 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12311         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12312                 port_id, UINT16);
12313 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12314         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12315                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12316 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12317         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12318                 flow_type,
12319                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12320                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12321 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12322         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12323                 enable, "enable#disable");
12324
12325 cmdline_parse_inst_t cmd_set_hash_global_config = {
12326         .f = cmd_set_hash_global_config_parsed,
12327         .data = NULL,
12328         .help_str = "set_hash_global_config <port_id> "
12329                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12330                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12331                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12332                 "l2_payload enable|disable",
12333         .tokens = {
12334                 (void *)&cmd_set_hash_global_config_all,
12335                 (void *)&cmd_set_hash_global_config_port_id,
12336                 (void *)&cmd_set_hash_global_config_hash_func,
12337                 (void *)&cmd_set_hash_global_config_flow_type,
12338                 (void *)&cmd_set_hash_global_config_enable,
12339                 NULL,
12340         },
12341 };
12342
12343 /* Set hash input set */
12344 struct cmd_set_hash_input_set_result {
12345         cmdline_fixed_string_t set_hash_input_set;
12346         portid_t port_id;
12347         cmdline_fixed_string_t flow_type;
12348         cmdline_fixed_string_t inset_field;
12349         cmdline_fixed_string_t select;
12350 };
12351
12352 static enum rte_eth_input_set_field
12353 str2inset(char *string)
12354 {
12355         uint16_t i;
12356
12357         static const struct {
12358                 char str[32];
12359                 enum rte_eth_input_set_field inset;
12360         } inset_table[] = {
12361                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12362                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12363                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12364                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12365                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12366                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12367                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12368                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12369                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12370                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12371                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12372                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12373                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12374                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12375                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12376                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12377                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12378                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12379                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12380                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12381                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12382                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12383                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12384                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12385                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12386                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12387                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12388                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12389                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12390                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12391                 {"none", RTE_ETH_INPUT_SET_NONE},
12392         };
12393
12394         for (i = 0; i < RTE_DIM(inset_table); i++) {
12395                 if (!strcmp(string, inset_table[i].str))
12396                         return inset_table[i].inset;
12397         }
12398
12399         return RTE_ETH_INPUT_SET_UNKNOWN;
12400 }
12401
12402 static void
12403 cmd_set_hash_input_set_parsed(void *parsed_result,
12404                               __rte_unused struct cmdline *cl,
12405                               __rte_unused void *data)
12406 {
12407         struct cmd_set_hash_input_set_result *res = parsed_result;
12408         struct rte_eth_hash_filter_info info;
12409
12410         memset(&info, 0, sizeof(info));
12411         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12412         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12413         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12414         info.info.input_set_conf.inset_size = 1;
12415         if (!strcmp(res->select, "select"))
12416                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12417         else if (!strcmp(res->select, "add"))
12418                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12419         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12420                                 RTE_ETH_FILTER_SET, &info);
12421 }
12422
12423 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12424         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12425                 set_hash_input_set, "set_hash_input_set");
12426 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12427         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12428                 port_id, UINT16);
12429 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12430         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12431                 flow_type, NULL);
12432 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12433         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12434                 inset_field,
12435                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12436                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12437                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12438                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12439                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12440                 "fld-8th#none");
12441 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12442         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12443                 select, "select#add");
12444
12445 cmdline_parse_inst_t cmd_set_hash_input_set = {
12446         .f = cmd_set_hash_input_set_parsed,
12447         .data = NULL,
12448         .help_str = "set_hash_input_set <port_id> "
12449         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12450         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12451         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12452         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12453         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12454         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12455         "fld-7th|fld-8th|none select|add",
12456         .tokens = {
12457                 (void *)&cmd_set_hash_input_set_cmd,
12458                 (void *)&cmd_set_hash_input_set_port_id,
12459                 (void *)&cmd_set_hash_input_set_flow_type,
12460                 (void *)&cmd_set_hash_input_set_field,
12461                 (void *)&cmd_set_hash_input_set_select,
12462                 NULL,
12463         },
12464 };
12465
12466 /* Set flow director input set */
12467 struct cmd_set_fdir_input_set_result {
12468         cmdline_fixed_string_t set_fdir_input_set;
12469         portid_t port_id;
12470         cmdline_fixed_string_t flow_type;
12471         cmdline_fixed_string_t inset_field;
12472         cmdline_fixed_string_t select;
12473 };
12474
12475 static void
12476 cmd_set_fdir_input_set_parsed(void *parsed_result,
12477         __rte_unused struct cmdline *cl,
12478         __rte_unused void *data)
12479 {
12480         struct cmd_set_fdir_input_set_result *res = parsed_result;
12481         struct rte_eth_fdir_filter_info info;
12482
12483         memset(&info, 0, sizeof(info));
12484         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12485         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12486         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12487         info.info.input_set_conf.inset_size = 1;
12488         if (!strcmp(res->select, "select"))
12489                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12490         else if (!strcmp(res->select, "add"))
12491                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12492         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12493                 RTE_ETH_FILTER_SET, &info);
12494 }
12495
12496 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12497         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12498         set_fdir_input_set, "set_fdir_input_set");
12499 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12500         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12501         port_id, UINT16);
12502 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12503         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12504         flow_type,
12505         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12506         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12507 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12508         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12509         inset_field,
12510         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12511         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12512         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12513         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12514         "sctp-veri-tag#none");
12515 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12516         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12517         select, "select#add");
12518
12519 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12520         .f = cmd_set_fdir_input_set_parsed,
12521         .data = NULL,
12522         .help_str = "set_fdir_input_set <port_id> "
12523         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12524         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12525         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12526         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12527         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12528         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12529         "sctp-veri-tag|none select|add",
12530         .tokens = {
12531                 (void *)&cmd_set_fdir_input_set_cmd,
12532                 (void *)&cmd_set_fdir_input_set_port_id,
12533                 (void *)&cmd_set_fdir_input_set_flow_type,
12534                 (void *)&cmd_set_fdir_input_set_field,
12535                 (void *)&cmd_set_fdir_input_set_select,
12536                 NULL,
12537         },
12538 };
12539
12540 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12541 struct cmd_mcast_addr_result {
12542         cmdline_fixed_string_t mcast_addr_cmd;
12543         cmdline_fixed_string_t what;
12544         uint16_t port_num;
12545         struct rte_ether_addr mc_addr;
12546 };
12547
12548 static void cmd_mcast_addr_parsed(void *parsed_result,
12549                 __attribute__((unused)) struct cmdline *cl,
12550                 __attribute__((unused)) void *data)
12551 {
12552         struct cmd_mcast_addr_result *res = parsed_result;
12553
12554         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12555                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12556                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12557                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12558                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12559                 return;
12560         }
12561         if (strcmp(res->what, "add") == 0)
12562                 mcast_addr_add(res->port_num, &res->mc_addr);
12563         else
12564                 mcast_addr_remove(res->port_num, &res->mc_addr);
12565 }
12566
12567 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12568         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12569                                  mcast_addr_cmd, "mcast_addr");
12570 cmdline_parse_token_string_t cmd_mcast_addr_what =
12571         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12572                                  "add#remove");
12573 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12574         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12575 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12576         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12577
12578 cmdline_parse_inst_t cmd_mcast_addr = {
12579         .f = cmd_mcast_addr_parsed,
12580         .data = (void *)0,
12581         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12582                 "Add/Remove multicast MAC address on port_id",
12583         .tokens = {
12584                 (void *)&cmd_mcast_addr_cmd,
12585                 (void *)&cmd_mcast_addr_what,
12586                 (void *)&cmd_mcast_addr_portnum,
12587                 (void *)&cmd_mcast_addr_addr,
12588                 NULL,
12589         },
12590 };
12591
12592 /* l2 tunnel config
12593  * only support E-tag now.
12594  */
12595
12596 /* Ether type config */
12597 struct cmd_config_l2_tunnel_eth_type_result {
12598         cmdline_fixed_string_t port;
12599         cmdline_fixed_string_t config;
12600         cmdline_fixed_string_t all;
12601         portid_t id;
12602         cmdline_fixed_string_t l2_tunnel;
12603         cmdline_fixed_string_t l2_tunnel_type;
12604         cmdline_fixed_string_t eth_type;
12605         uint16_t eth_type_val;
12606 };
12607
12608 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12609         TOKEN_STRING_INITIALIZER
12610                 (struct cmd_config_l2_tunnel_eth_type_result,
12611                  port, "port");
12612 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12613         TOKEN_STRING_INITIALIZER
12614                 (struct cmd_config_l2_tunnel_eth_type_result,
12615                  config, "config");
12616 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12617         TOKEN_STRING_INITIALIZER
12618                 (struct cmd_config_l2_tunnel_eth_type_result,
12619                  all, "all");
12620 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12621         TOKEN_NUM_INITIALIZER
12622                 (struct cmd_config_l2_tunnel_eth_type_result,
12623                  id, UINT16);
12624 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12625         TOKEN_STRING_INITIALIZER
12626                 (struct cmd_config_l2_tunnel_eth_type_result,
12627                  l2_tunnel, "l2-tunnel");
12628 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12629         TOKEN_STRING_INITIALIZER
12630                 (struct cmd_config_l2_tunnel_eth_type_result,
12631                  l2_tunnel_type, "E-tag");
12632 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12633         TOKEN_STRING_INITIALIZER
12634                 (struct cmd_config_l2_tunnel_eth_type_result,
12635                  eth_type, "ether-type");
12636 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12637         TOKEN_NUM_INITIALIZER
12638                 (struct cmd_config_l2_tunnel_eth_type_result,
12639                  eth_type_val, UINT16);
12640
12641 static enum rte_eth_tunnel_type
12642 str2fdir_l2_tunnel_type(char *string)
12643 {
12644         uint32_t i = 0;
12645
12646         static const struct {
12647                 char str[32];
12648                 enum rte_eth_tunnel_type type;
12649         } l2_tunnel_type_str[] = {
12650                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12651         };
12652
12653         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12654                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12655                         return l2_tunnel_type_str[i].type;
12656         }
12657         return RTE_TUNNEL_TYPE_NONE;
12658 }
12659
12660 /* ether type config for all ports */
12661 static void
12662 cmd_config_l2_tunnel_eth_type_all_parsed
12663         (void *parsed_result,
12664          __attribute__((unused)) struct cmdline *cl,
12665          __attribute__((unused)) void *data)
12666 {
12667         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12668         struct rte_eth_l2_tunnel_conf entry;
12669         portid_t pid;
12670
12671         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12672         entry.ether_type = res->eth_type_val;
12673
12674         RTE_ETH_FOREACH_DEV(pid) {
12675                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12676         }
12677 }
12678
12679 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12680         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12681         .data = NULL,
12682         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12683         .tokens = {
12684                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12685                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12686                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12687                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12688                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12689                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12690                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12691                 NULL,
12692         },
12693 };
12694
12695 /* ether type config for a specific port */
12696 static void
12697 cmd_config_l2_tunnel_eth_type_specific_parsed(
12698         void *parsed_result,
12699         __attribute__((unused)) struct cmdline *cl,
12700         __attribute__((unused)) void *data)
12701 {
12702         struct cmd_config_l2_tunnel_eth_type_result *res =
12703                  parsed_result;
12704         struct rte_eth_l2_tunnel_conf entry;
12705
12706         if (port_id_is_invalid(res->id, ENABLED_WARN))
12707                 return;
12708
12709         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12710         entry.ether_type = res->eth_type_val;
12711
12712         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12713 }
12714
12715 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12716         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12717         .data = NULL,
12718         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12719         .tokens = {
12720                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12721                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12722                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12723                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12724                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12725                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12726                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12727                 NULL,
12728         },
12729 };
12730
12731 /* Enable/disable l2 tunnel */
12732 struct cmd_config_l2_tunnel_en_dis_result {
12733         cmdline_fixed_string_t port;
12734         cmdline_fixed_string_t config;
12735         cmdline_fixed_string_t all;
12736         portid_t id;
12737         cmdline_fixed_string_t l2_tunnel;
12738         cmdline_fixed_string_t l2_tunnel_type;
12739         cmdline_fixed_string_t en_dis;
12740 };
12741
12742 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12743         TOKEN_STRING_INITIALIZER
12744                 (struct cmd_config_l2_tunnel_en_dis_result,
12745                  port, "port");
12746 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12747         TOKEN_STRING_INITIALIZER
12748                 (struct cmd_config_l2_tunnel_en_dis_result,
12749                  config, "config");
12750 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12751         TOKEN_STRING_INITIALIZER
12752                 (struct cmd_config_l2_tunnel_en_dis_result,
12753                  all, "all");
12754 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12755         TOKEN_NUM_INITIALIZER
12756                 (struct cmd_config_l2_tunnel_en_dis_result,
12757                  id, UINT16);
12758 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12759         TOKEN_STRING_INITIALIZER
12760                 (struct cmd_config_l2_tunnel_en_dis_result,
12761                  l2_tunnel, "l2-tunnel");
12762 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12763         TOKEN_STRING_INITIALIZER
12764                 (struct cmd_config_l2_tunnel_en_dis_result,
12765                  l2_tunnel_type, "E-tag");
12766 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12767         TOKEN_STRING_INITIALIZER
12768                 (struct cmd_config_l2_tunnel_en_dis_result,
12769                  en_dis, "enable#disable");
12770
12771 /* enable/disable l2 tunnel for all ports */
12772 static void
12773 cmd_config_l2_tunnel_en_dis_all_parsed(
12774         void *parsed_result,
12775         __attribute__((unused)) struct cmdline *cl,
12776         __attribute__((unused)) void *data)
12777 {
12778         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12779         struct rte_eth_l2_tunnel_conf entry;
12780         portid_t pid;
12781         uint8_t en;
12782
12783         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12784
12785         if (!strcmp("enable", res->en_dis))
12786                 en = 1;
12787         else
12788                 en = 0;
12789
12790         RTE_ETH_FOREACH_DEV(pid) {
12791                 rte_eth_dev_l2_tunnel_offload_set(pid,
12792                                                   &entry,
12793                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12794                                                   en);
12795         }
12796 }
12797
12798 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12799         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12800         .data = NULL,
12801         .help_str = "port config all l2-tunnel E-tag enable|disable",
12802         .tokens = {
12803                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12804                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12805                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12806                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12807                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12808                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12809                 NULL,
12810         },
12811 };
12812
12813 /* enable/disable l2 tunnel for a port */
12814 static void
12815 cmd_config_l2_tunnel_en_dis_specific_parsed(
12816         void *parsed_result,
12817         __attribute__((unused)) struct cmdline *cl,
12818         __attribute__((unused)) void *data)
12819 {
12820         struct cmd_config_l2_tunnel_en_dis_result *res =
12821                 parsed_result;
12822         struct rte_eth_l2_tunnel_conf entry;
12823
12824         if (port_id_is_invalid(res->id, ENABLED_WARN))
12825                 return;
12826
12827         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12828
12829         if (!strcmp("enable", res->en_dis))
12830                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12831                                                   &entry,
12832                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12833                                                   1);
12834         else
12835                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12836                                                   &entry,
12837                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12838                                                   0);
12839 }
12840
12841 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12842         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12843         .data = NULL,
12844         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12845         .tokens = {
12846                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12847                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12848                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12849                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12850                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12851                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12852                 NULL,
12853         },
12854 };
12855
12856 /* E-tag configuration */
12857
12858 /* Common result structure for all E-tag configuration */
12859 struct cmd_config_e_tag_result {
12860         cmdline_fixed_string_t e_tag;
12861         cmdline_fixed_string_t set;
12862         cmdline_fixed_string_t insertion;
12863         cmdline_fixed_string_t stripping;
12864         cmdline_fixed_string_t forwarding;
12865         cmdline_fixed_string_t filter;
12866         cmdline_fixed_string_t add;
12867         cmdline_fixed_string_t del;
12868         cmdline_fixed_string_t on;
12869         cmdline_fixed_string_t off;
12870         cmdline_fixed_string_t on_off;
12871         cmdline_fixed_string_t port_tag_id;
12872         uint32_t port_tag_id_val;
12873         cmdline_fixed_string_t e_tag_id;
12874         uint16_t e_tag_id_val;
12875         cmdline_fixed_string_t dst_pool;
12876         uint8_t dst_pool_val;
12877         cmdline_fixed_string_t port;
12878         portid_t port_id;
12879         cmdline_fixed_string_t vf;
12880         uint8_t vf_id;
12881 };
12882
12883 /* Common CLI fields for all E-tag configuration */
12884 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12885         TOKEN_STRING_INITIALIZER
12886                 (struct cmd_config_e_tag_result,
12887                  e_tag, "E-tag");
12888 cmdline_parse_token_string_t cmd_config_e_tag_set =
12889         TOKEN_STRING_INITIALIZER
12890                 (struct cmd_config_e_tag_result,
12891                  set, "set");
12892 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12893         TOKEN_STRING_INITIALIZER
12894                 (struct cmd_config_e_tag_result,
12895                  insertion, "insertion");
12896 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12897         TOKEN_STRING_INITIALIZER
12898                 (struct cmd_config_e_tag_result,
12899                  stripping, "stripping");
12900 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12901         TOKEN_STRING_INITIALIZER
12902                 (struct cmd_config_e_tag_result,
12903                  forwarding, "forwarding");
12904 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12905         TOKEN_STRING_INITIALIZER
12906                 (struct cmd_config_e_tag_result,
12907                  filter, "filter");
12908 cmdline_parse_token_string_t cmd_config_e_tag_add =
12909         TOKEN_STRING_INITIALIZER
12910                 (struct cmd_config_e_tag_result,
12911                  add, "add");
12912 cmdline_parse_token_string_t cmd_config_e_tag_del =
12913         TOKEN_STRING_INITIALIZER
12914                 (struct cmd_config_e_tag_result,
12915                  del, "del");
12916 cmdline_parse_token_string_t cmd_config_e_tag_on =
12917         TOKEN_STRING_INITIALIZER
12918                 (struct cmd_config_e_tag_result,
12919                  on, "on");
12920 cmdline_parse_token_string_t cmd_config_e_tag_off =
12921         TOKEN_STRING_INITIALIZER
12922                 (struct cmd_config_e_tag_result,
12923                  off, "off");
12924 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12925         TOKEN_STRING_INITIALIZER
12926                 (struct cmd_config_e_tag_result,
12927                  on_off, "on#off");
12928 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12929         TOKEN_STRING_INITIALIZER
12930                 (struct cmd_config_e_tag_result,
12931                  port_tag_id, "port-tag-id");
12932 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12933         TOKEN_NUM_INITIALIZER
12934                 (struct cmd_config_e_tag_result,
12935                  port_tag_id_val, UINT32);
12936 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12937         TOKEN_STRING_INITIALIZER
12938                 (struct cmd_config_e_tag_result,
12939                  e_tag_id, "e-tag-id");
12940 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12941         TOKEN_NUM_INITIALIZER
12942                 (struct cmd_config_e_tag_result,
12943                  e_tag_id_val, UINT16);
12944 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12945         TOKEN_STRING_INITIALIZER
12946                 (struct cmd_config_e_tag_result,
12947                  dst_pool, "dst-pool");
12948 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12949         TOKEN_NUM_INITIALIZER
12950                 (struct cmd_config_e_tag_result,
12951                  dst_pool_val, UINT8);
12952 cmdline_parse_token_string_t cmd_config_e_tag_port =
12953         TOKEN_STRING_INITIALIZER
12954                 (struct cmd_config_e_tag_result,
12955                  port, "port");
12956 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12957         TOKEN_NUM_INITIALIZER
12958                 (struct cmd_config_e_tag_result,
12959                  port_id, UINT16);
12960 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12961         TOKEN_STRING_INITIALIZER
12962                 (struct cmd_config_e_tag_result,
12963                  vf, "vf");
12964 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12965         TOKEN_NUM_INITIALIZER
12966                 (struct cmd_config_e_tag_result,
12967                  vf_id, UINT8);
12968
12969 /* E-tag insertion configuration */
12970 static void
12971 cmd_config_e_tag_insertion_en_parsed(
12972         void *parsed_result,
12973         __attribute__((unused)) struct cmdline *cl,
12974         __attribute__((unused)) void *data)
12975 {
12976         struct cmd_config_e_tag_result *res =
12977                 parsed_result;
12978         struct rte_eth_l2_tunnel_conf entry;
12979
12980         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12981                 return;
12982
12983         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12984         entry.tunnel_id = res->port_tag_id_val;
12985         entry.vf_id = res->vf_id;
12986         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12987                                           &entry,
12988                                           ETH_L2_TUNNEL_INSERTION_MASK,
12989                                           1);
12990 }
12991
12992 static void
12993 cmd_config_e_tag_insertion_dis_parsed(
12994         void *parsed_result,
12995         __attribute__((unused)) struct cmdline *cl,
12996         __attribute__((unused)) void *data)
12997 {
12998         struct cmd_config_e_tag_result *res =
12999                 parsed_result;
13000         struct rte_eth_l2_tunnel_conf entry;
13001
13002         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13003                 return;
13004
13005         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13006         entry.vf_id = res->vf_id;
13007
13008         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13009                                           &entry,
13010                                           ETH_L2_TUNNEL_INSERTION_MASK,
13011                                           0);
13012 }
13013
13014 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13015         .f = cmd_config_e_tag_insertion_en_parsed,
13016         .data = NULL,
13017         .help_str = "E-tag ... : E-tag insertion enable",
13018         .tokens = {
13019                 (void *)&cmd_config_e_tag_e_tag,
13020                 (void *)&cmd_config_e_tag_set,
13021                 (void *)&cmd_config_e_tag_insertion,
13022                 (void *)&cmd_config_e_tag_on,
13023                 (void *)&cmd_config_e_tag_port_tag_id,
13024                 (void *)&cmd_config_e_tag_port_tag_id_val,
13025                 (void *)&cmd_config_e_tag_port,
13026                 (void *)&cmd_config_e_tag_port_id,
13027                 (void *)&cmd_config_e_tag_vf,
13028                 (void *)&cmd_config_e_tag_vf_id,
13029                 NULL,
13030         },
13031 };
13032
13033 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13034         .f = cmd_config_e_tag_insertion_dis_parsed,
13035         .data = NULL,
13036         .help_str = "E-tag ... : E-tag insertion disable",
13037         .tokens = {
13038                 (void *)&cmd_config_e_tag_e_tag,
13039                 (void *)&cmd_config_e_tag_set,
13040                 (void *)&cmd_config_e_tag_insertion,
13041                 (void *)&cmd_config_e_tag_off,
13042                 (void *)&cmd_config_e_tag_port,
13043                 (void *)&cmd_config_e_tag_port_id,
13044                 (void *)&cmd_config_e_tag_vf,
13045                 (void *)&cmd_config_e_tag_vf_id,
13046                 NULL,
13047         },
13048 };
13049
13050 /* E-tag stripping configuration */
13051 static void
13052 cmd_config_e_tag_stripping_parsed(
13053         void *parsed_result,
13054         __attribute__((unused)) struct cmdline *cl,
13055         __attribute__((unused)) void *data)
13056 {
13057         struct cmd_config_e_tag_result *res =
13058                 parsed_result;
13059         struct rte_eth_l2_tunnel_conf entry;
13060
13061         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13062                 return;
13063
13064         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13065
13066         if (!strcmp(res->on_off, "on"))
13067                 rte_eth_dev_l2_tunnel_offload_set
13068                         (res->port_id,
13069                          &entry,
13070                          ETH_L2_TUNNEL_STRIPPING_MASK,
13071                          1);
13072         else
13073                 rte_eth_dev_l2_tunnel_offload_set
13074                         (res->port_id,
13075                          &entry,
13076                          ETH_L2_TUNNEL_STRIPPING_MASK,
13077                          0);
13078 }
13079
13080 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13081         .f = cmd_config_e_tag_stripping_parsed,
13082         .data = NULL,
13083         .help_str = "E-tag ... : E-tag stripping enable/disable",
13084         .tokens = {
13085                 (void *)&cmd_config_e_tag_e_tag,
13086                 (void *)&cmd_config_e_tag_set,
13087                 (void *)&cmd_config_e_tag_stripping,
13088                 (void *)&cmd_config_e_tag_on_off,
13089                 (void *)&cmd_config_e_tag_port,
13090                 (void *)&cmd_config_e_tag_port_id,
13091                 NULL,
13092         },
13093 };
13094
13095 /* E-tag forwarding configuration */
13096 static void
13097 cmd_config_e_tag_forwarding_parsed(
13098         void *parsed_result,
13099         __attribute__((unused)) struct cmdline *cl,
13100         __attribute__((unused)) void *data)
13101 {
13102         struct cmd_config_e_tag_result *res = parsed_result;
13103         struct rte_eth_l2_tunnel_conf entry;
13104
13105         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13106                 return;
13107
13108         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13109
13110         if (!strcmp(res->on_off, "on"))
13111                 rte_eth_dev_l2_tunnel_offload_set
13112                         (res->port_id,
13113                          &entry,
13114                          ETH_L2_TUNNEL_FORWARDING_MASK,
13115                          1);
13116         else
13117                 rte_eth_dev_l2_tunnel_offload_set
13118                         (res->port_id,
13119                          &entry,
13120                          ETH_L2_TUNNEL_FORWARDING_MASK,
13121                          0);
13122 }
13123
13124 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13125         .f = cmd_config_e_tag_forwarding_parsed,
13126         .data = NULL,
13127         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13128         .tokens = {
13129                 (void *)&cmd_config_e_tag_e_tag,
13130                 (void *)&cmd_config_e_tag_set,
13131                 (void *)&cmd_config_e_tag_forwarding,
13132                 (void *)&cmd_config_e_tag_on_off,
13133                 (void *)&cmd_config_e_tag_port,
13134                 (void *)&cmd_config_e_tag_port_id,
13135                 NULL,
13136         },
13137 };
13138
13139 /* E-tag filter configuration */
13140 static void
13141 cmd_config_e_tag_filter_add_parsed(
13142         void *parsed_result,
13143         __attribute__((unused)) struct cmdline *cl,
13144         __attribute__((unused)) void *data)
13145 {
13146         struct cmd_config_e_tag_result *res = parsed_result;
13147         struct rte_eth_l2_tunnel_conf entry;
13148         int ret = 0;
13149
13150         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13151                 return;
13152
13153         if (res->e_tag_id_val > 0x3fff) {
13154                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13155                 return;
13156         }
13157
13158         ret = rte_eth_dev_filter_supported(res->port_id,
13159                                            RTE_ETH_FILTER_L2_TUNNEL);
13160         if (ret < 0) {
13161                 printf("E-tag filter is not supported on port %u.\n",
13162                        res->port_id);
13163                 return;
13164         }
13165
13166         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13167         entry.tunnel_id = res->e_tag_id_val;
13168         entry.pool = res->dst_pool_val;
13169
13170         ret = rte_eth_dev_filter_ctrl(res->port_id,
13171                                       RTE_ETH_FILTER_L2_TUNNEL,
13172                                       RTE_ETH_FILTER_ADD,
13173                                       &entry);
13174         if (ret < 0)
13175                 printf("E-tag filter programming error: (%s)\n",
13176                        strerror(-ret));
13177 }
13178
13179 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13180         .f = cmd_config_e_tag_filter_add_parsed,
13181         .data = NULL,
13182         .help_str = "E-tag ... : E-tag filter add",
13183         .tokens = {
13184                 (void *)&cmd_config_e_tag_e_tag,
13185                 (void *)&cmd_config_e_tag_set,
13186                 (void *)&cmd_config_e_tag_filter,
13187                 (void *)&cmd_config_e_tag_add,
13188                 (void *)&cmd_config_e_tag_e_tag_id,
13189                 (void *)&cmd_config_e_tag_e_tag_id_val,
13190                 (void *)&cmd_config_e_tag_dst_pool,
13191                 (void *)&cmd_config_e_tag_dst_pool_val,
13192                 (void *)&cmd_config_e_tag_port,
13193                 (void *)&cmd_config_e_tag_port_id,
13194                 NULL,
13195         },
13196 };
13197
13198 static void
13199 cmd_config_e_tag_filter_del_parsed(
13200         void *parsed_result,
13201         __attribute__((unused)) struct cmdline *cl,
13202         __attribute__((unused)) void *data)
13203 {
13204         struct cmd_config_e_tag_result *res = parsed_result;
13205         struct rte_eth_l2_tunnel_conf entry;
13206         int ret = 0;
13207
13208         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13209                 return;
13210
13211         if (res->e_tag_id_val > 0x3fff) {
13212                 printf("e-tag-id must be less than 0x3fff.\n");
13213                 return;
13214         }
13215
13216         ret = rte_eth_dev_filter_supported(res->port_id,
13217                                            RTE_ETH_FILTER_L2_TUNNEL);
13218         if (ret < 0) {
13219                 printf("E-tag filter is not supported on port %u.\n",
13220                        res->port_id);
13221                 return;
13222         }
13223
13224         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13225         entry.tunnel_id = res->e_tag_id_val;
13226
13227         ret = rte_eth_dev_filter_ctrl(res->port_id,
13228                                       RTE_ETH_FILTER_L2_TUNNEL,
13229                                       RTE_ETH_FILTER_DELETE,
13230                                       &entry);
13231         if (ret < 0)
13232                 printf("E-tag filter programming error: (%s)\n",
13233                        strerror(-ret));
13234 }
13235
13236 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13237         .f = cmd_config_e_tag_filter_del_parsed,
13238         .data = NULL,
13239         .help_str = "E-tag ... : E-tag filter delete",
13240         .tokens = {
13241                 (void *)&cmd_config_e_tag_e_tag,
13242                 (void *)&cmd_config_e_tag_set,
13243                 (void *)&cmd_config_e_tag_filter,
13244                 (void *)&cmd_config_e_tag_del,
13245                 (void *)&cmd_config_e_tag_e_tag_id,
13246                 (void *)&cmd_config_e_tag_e_tag_id_val,
13247                 (void *)&cmd_config_e_tag_port,
13248                 (void *)&cmd_config_e_tag_port_id,
13249                 NULL,
13250         },
13251 };
13252
13253 /* vf vlan anti spoof configuration */
13254
13255 /* Common result structure for vf vlan anti spoof */
13256 struct cmd_vf_vlan_anti_spoof_result {
13257         cmdline_fixed_string_t set;
13258         cmdline_fixed_string_t vf;
13259         cmdline_fixed_string_t vlan;
13260         cmdline_fixed_string_t antispoof;
13261         portid_t port_id;
13262         uint32_t vf_id;
13263         cmdline_fixed_string_t on_off;
13264 };
13265
13266 /* Common CLI fields for vf vlan anti spoof enable disable */
13267 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13268         TOKEN_STRING_INITIALIZER
13269                 (struct cmd_vf_vlan_anti_spoof_result,
13270                  set, "set");
13271 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13272         TOKEN_STRING_INITIALIZER
13273                 (struct cmd_vf_vlan_anti_spoof_result,
13274                  vf, "vf");
13275 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13276         TOKEN_STRING_INITIALIZER
13277                 (struct cmd_vf_vlan_anti_spoof_result,
13278                  vlan, "vlan");
13279 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13280         TOKEN_STRING_INITIALIZER
13281                 (struct cmd_vf_vlan_anti_spoof_result,
13282                  antispoof, "antispoof");
13283 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13284         TOKEN_NUM_INITIALIZER
13285                 (struct cmd_vf_vlan_anti_spoof_result,
13286                  port_id, UINT16);
13287 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13288         TOKEN_NUM_INITIALIZER
13289                 (struct cmd_vf_vlan_anti_spoof_result,
13290                  vf_id, UINT32);
13291 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13292         TOKEN_STRING_INITIALIZER
13293                 (struct cmd_vf_vlan_anti_spoof_result,
13294                  on_off, "on#off");
13295
13296 static void
13297 cmd_set_vf_vlan_anti_spoof_parsed(
13298         void *parsed_result,
13299         __attribute__((unused)) struct cmdline *cl,
13300         __attribute__((unused)) void *data)
13301 {
13302         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13303         int ret = -ENOTSUP;
13304
13305         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13306
13307         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13308                 return;
13309
13310 #ifdef RTE_LIBRTE_IXGBE_PMD
13311         if (ret == -ENOTSUP)
13312                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13313                                 res->vf_id, is_on);
13314 #endif
13315 #ifdef RTE_LIBRTE_I40E_PMD
13316         if (ret == -ENOTSUP)
13317                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13318                                 res->vf_id, is_on);
13319 #endif
13320 #ifdef RTE_LIBRTE_BNXT_PMD
13321         if (ret == -ENOTSUP)
13322                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13323                                 res->vf_id, is_on);
13324 #endif
13325
13326         switch (ret) {
13327         case 0:
13328                 break;
13329         case -EINVAL:
13330                 printf("invalid vf_id %d\n", res->vf_id);
13331                 break;
13332         case -ENODEV:
13333                 printf("invalid port_id %d\n", res->port_id);
13334                 break;
13335         case -ENOTSUP:
13336                 printf("function not implemented\n");
13337                 break;
13338         default:
13339                 printf("programming error: (%s)\n", strerror(-ret));
13340         }
13341 }
13342
13343 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13344         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13345         .data = NULL,
13346         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13347         .tokens = {
13348                 (void *)&cmd_vf_vlan_anti_spoof_set,
13349                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13350                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13351                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13352                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13353                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13354                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13355                 NULL,
13356         },
13357 };
13358
13359 /* vf mac anti spoof configuration */
13360
13361 /* Common result structure for vf mac anti spoof */
13362 struct cmd_vf_mac_anti_spoof_result {
13363         cmdline_fixed_string_t set;
13364         cmdline_fixed_string_t vf;
13365         cmdline_fixed_string_t mac;
13366         cmdline_fixed_string_t antispoof;
13367         portid_t port_id;
13368         uint32_t vf_id;
13369         cmdline_fixed_string_t on_off;
13370 };
13371
13372 /* Common CLI fields for vf mac anti spoof enable disable */
13373 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13374         TOKEN_STRING_INITIALIZER
13375                 (struct cmd_vf_mac_anti_spoof_result,
13376                  set, "set");
13377 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13378         TOKEN_STRING_INITIALIZER
13379                 (struct cmd_vf_mac_anti_spoof_result,
13380                  vf, "vf");
13381 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13382         TOKEN_STRING_INITIALIZER
13383                 (struct cmd_vf_mac_anti_spoof_result,
13384                  mac, "mac");
13385 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13386         TOKEN_STRING_INITIALIZER
13387                 (struct cmd_vf_mac_anti_spoof_result,
13388                  antispoof, "antispoof");
13389 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13390         TOKEN_NUM_INITIALIZER
13391                 (struct cmd_vf_mac_anti_spoof_result,
13392                  port_id, UINT16);
13393 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13394         TOKEN_NUM_INITIALIZER
13395                 (struct cmd_vf_mac_anti_spoof_result,
13396                  vf_id, UINT32);
13397 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13398         TOKEN_STRING_INITIALIZER
13399                 (struct cmd_vf_mac_anti_spoof_result,
13400                  on_off, "on#off");
13401
13402 static void
13403 cmd_set_vf_mac_anti_spoof_parsed(
13404         void *parsed_result,
13405         __attribute__((unused)) struct cmdline *cl,
13406         __attribute__((unused)) void *data)
13407 {
13408         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13409         int ret = -ENOTSUP;
13410
13411         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13412
13413         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13414                 return;
13415
13416 #ifdef RTE_LIBRTE_IXGBE_PMD
13417         if (ret == -ENOTSUP)
13418                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13419                         res->vf_id, is_on);
13420 #endif
13421 #ifdef RTE_LIBRTE_I40E_PMD
13422         if (ret == -ENOTSUP)
13423                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13424                         res->vf_id, is_on);
13425 #endif
13426 #ifdef RTE_LIBRTE_BNXT_PMD
13427         if (ret == -ENOTSUP)
13428                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13429                         res->vf_id, is_on);
13430 #endif
13431
13432         switch (ret) {
13433         case 0:
13434                 break;
13435         case -EINVAL:
13436                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13437                 break;
13438         case -ENODEV:
13439                 printf("invalid port_id %d\n", res->port_id);
13440                 break;
13441         case -ENOTSUP:
13442                 printf("function not implemented\n");
13443                 break;
13444         default:
13445                 printf("programming error: (%s)\n", strerror(-ret));
13446         }
13447 }
13448
13449 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13450         .f = cmd_set_vf_mac_anti_spoof_parsed,
13451         .data = NULL,
13452         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13453         .tokens = {
13454                 (void *)&cmd_vf_mac_anti_spoof_set,
13455                 (void *)&cmd_vf_mac_anti_spoof_vf,
13456                 (void *)&cmd_vf_mac_anti_spoof_mac,
13457                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13458                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13459                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13460                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13461                 NULL,
13462         },
13463 };
13464
13465 /* vf vlan strip queue configuration */
13466
13467 /* Common result structure for vf mac anti spoof */
13468 struct cmd_vf_vlan_stripq_result {
13469         cmdline_fixed_string_t set;
13470         cmdline_fixed_string_t vf;
13471         cmdline_fixed_string_t vlan;
13472         cmdline_fixed_string_t stripq;
13473         portid_t port_id;
13474         uint16_t vf_id;
13475         cmdline_fixed_string_t on_off;
13476 };
13477
13478 /* Common CLI fields for vf vlan strip enable disable */
13479 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13480         TOKEN_STRING_INITIALIZER
13481                 (struct cmd_vf_vlan_stripq_result,
13482                  set, "set");
13483 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13484         TOKEN_STRING_INITIALIZER
13485                 (struct cmd_vf_vlan_stripq_result,
13486                  vf, "vf");
13487 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13488         TOKEN_STRING_INITIALIZER
13489                 (struct cmd_vf_vlan_stripq_result,
13490                  vlan, "vlan");
13491 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13492         TOKEN_STRING_INITIALIZER
13493                 (struct cmd_vf_vlan_stripq_result,
13494                  stripq, "stripq");
13495 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13496         TOKEN_NUM_INITIALIZER
13497                 (struct cmd_vf_vlan_stripq_result,
13498                  port_id, UINT16);
13499 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13500         TOKEN_NUM_INITIALIZER
13501                 (struct cmd_vf_vlan_stripq_result,
13502                  vf_id, UINT16);
13503 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13504         TOKEN_STRING_INITIALIZER
13505                 (struct cmd_vf_vlan_stripq_result,
13506                  on_off, "on#off");
13507
13508 static void
13509 cmd_set_vf_vlan_stripq_parsed(
13510         void *parsed_result,
13511         __attribute__((unused)) struct cmdline *cl,
13512         __attribute__((unused)) void *data)
13513 {
13514         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13515         int ret = -ENOTSUP;
13516
13517         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13518
13519         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13520                 return;
13521
13522 #ifdef RTE_LIBRTE_IXGBE_PMD
13523         if (ret == -ENOTSUP)
13524                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13525                         res->vf_id, is_on);
13526 #endif
13527 #ifdef RTE_LIBRTE_I40E_PMD
13528         if (ret == -ENOTSUP)
13529                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13530                         res->vf_id, is_on);
13531 #endif
13532 #ifdef RTE_LIBRTE_BNXT_PMD
13533         if (ret == -ENOTSUP)
13534                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13535                         res->vf_id, is_on);
13536 #endif
13537
13538         switch (ret) {
13539         case 0:
13540                 break;
13541         case -EINVAL:
13542                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13543                 break;
13544         case -ENODEV:
13545                 printf("invalid port_id %d\n", res->port_id);
13546                 break;
13547         case -ENOTSUP:
13548                 printf("function not implemented\n");
13549                 break;
13550         default:
13551                 printf("programming error: (%s)\n", strerror(-ret));
13552         }
13553 }
13554
13555 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13556         .f = cmd_set_vf_vlan_stripq_parsed,
13557         .data = NULL,
13558         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13559         .tokens = {
13560                 (void *)&cmd_vf_vlan_stripq_set,
13561                 (void *)&cmd_vf_vlan_stripq_vf,
13562                 (void *)&cmd_vf_vlan_stripq_vlan,
13563                 (void *)&cmd_vf_vlan_stripq_stripq,
13564                 (void *)&cmd_vf_vlan_stripq_port_id,
13565                 (void *)&cmd_vf_vlan_stripq_vf_id,
13566                 (void *)&cmd_vf_vlan_stripq_on_off,
13567                 NULL,
13568         },
13569 };
13570
13571 /* vf vlan insert configuration */
13572
13573 /* Common result structure for vf vlan insert */
13574 struct cmd_vf_vlan_insert_result {
13575         cmdline_fixed_string_t set;
13576         cmdline_fixed_string_t vf;
13577         cmdline_fixed_string_t vlan;
13578         cmdline_fixed_string_t insert;
13579         portid_t port_id;
13580         uint16_t vf_id;
13581         uint16_t vlan_id;
13582 };
13583
13584 /* Common CLI fields for vf vlan insert enable disable */
13585 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13586         TOKEN_STRING_INITIALIZER
13587                 (struct cmd_vf_vlan_insert_result,
13588                  set, "set");
13589 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13590         TOKEN_STRING_INITIALIZER
13591                 (struct cmd_vf_vlan_insert_result,
13592                  vf, "vf");
13593 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13594         TOKEN_STRING_INITIALIZER
13595                 (struct cmd_vf_vlan_insert_result,
13596                  vlan, "vlan");
13597 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13598         TOKEN_STRING_INITIALIZER
13599                 (struct cmd_vf_vlan_insert_result,
13600                  insert, "insert");
13601 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13602         TOKEN_NUM_INITIALIZER
13603                 (struct cmd_vf_vlan_insert_result,
13604                  port_id, UINT16);
13605 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13606         TOKEN_NUM_INITIALIZER
13607                 (struct cmd_vf_vlan_insert_result,
13608                  vf_id, UINT16);
13609 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13610         TOKEN_NUM_INITIALIZER
13611                 (struct cmd_vf_vlan_insert_result,
13612                  vlan_id, UINT16);
13613
13614 static void
13615 cmd_set_vf_vlan_insert_parsed(
13616         void *parsed_result,
13617         __attribute__((unused)) struct cmdline *cl,
13618         __attribute__((unused)) void *data)
13619 {
13620         struct cmd_vf_vlan_insert_result *res = parsed_result;
13621         int ret = -ENOTSUP;
13622
13623         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13624                 return;
13625
13626 #ifdef RTE_LIBRTE_IXGBE_PMD
13627         if (ret == -ENOTSUP)
13628                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13629                         res->vlan_id);
13630 #endif
13631 #ifdef RTE_LIBRTE_I40E_PMD
13632         if (ret == -ENOTSUP)
13633                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13634                         res->vlan_id);
13635 #endif
13636 #ifdef RTE_LIBRTE_BNXT_PMD
13637         if (ret == -ENOTSUP)
13638                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13639                         res->vlan_id);
13640 #endif
13641
13642         switch (ret) {
13643         case 0:
13644                 break;
13645         case -EINVAL:
13646                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13647                 break;
13648         case -ENODEV:
13649                 printf("invalid port_id %d\n", res->port_id);
13650                 break;
13651         case -ENOTSUP:
13652                 printf("function not implemented\n");
13653                 break;
13654         default:
13655                 printf("programming error: (%s)\n", strerror(-ret));
13656         }
13657 }
13658
13659 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13660         .f = cmd_set_vf_vlan_insert_parsed,
13661         .data = NULL,
13662         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13663         .tokens = {
13664                 (void *)&cmd_vf_vlan_insert_set,
13665                 (void *)&cmd_vf_vlan_insert_vf,
13666                 (void *)&cmd_vf_vlan_insert_vlan,
13667                 (void *)&cmd_vf_vlan_insert_insert,
13668                 (void *)&cmd_vf_vlan_insert_port_id,
13669                 (void *)&cmd_vf_vlan_insert_vf_id,
13670                 (void *)&cmd_vf_vlan_insert_vlan_id,
13671                 NULL,
13672         },
13673 };
13674
13675 /* tx loopback configuration */
13676
13677 /* Common result structure for tx loopback */
13678 struct cmd_tx_loopback_result {
13679         cmdline_fixed_string_t set;
13680         cmdline_fixed_string_t tx;
13681         cmdline_fixed_string_t loopback;
13682         portid_t port_id;
13683         cmdline_fixed_string_t on_off;
13684 };
13685
13686 /* Common CLI fields for tx loopback enable disable */
13687 cmdline_parse_token_string_t cmd_tx_loopback_set =
13688         TOKEN_STRING_INITIALIZER
13689                 (struct cmd_tx_loopback_result,
13690                  set, "set");
13691 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13692         TOKEN_STRING_INITIALIZER
13693                 (struct cmd_tx_loopback_result,
13694                  tx, "tx");
13695 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13696         TOKEN_STRING_INITIALIZER
13697                 (struct cmd_tx_loopback_result,
13698                  loopback, "loopback");
13699 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13700         TOKEN_NUM_INITIALIZER
13701                 (struct cmd_tx_loopback_result,
13702                  port_id, UINT16);
13703 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13704         TOKEN_STRING_INITIALIZER
13705                 (struct cmd_tx_loopback_result,
13706                  on_off, "on#off");
13707
13708 static void
13709 cmd_set_tx_loopback_parsed(
13710         void *parsed_result,
13711         __attribute__((unused)) struct cmdline *cl,
13712         __attribute__((unused)) void *data)
13713 {
13714         struct cmd_tx_loopback_result *res = parsed_result;
13715         int ret = -ENOTSUP;
13716
13717         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13718
13719         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13720                 return;
13721
13722 #ifdef RTE_LIBRTE_IXGBE_PMD
13723         if (ret == -ENOTSUP)
13724                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13725 #endif
13726 #ifdef RTE_LIBRTE_I40E_PMD
13727         if (ret == -ENOTSUP)
13728                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13729 #endif
13730 #ifdef RTE_LIBRTE_BNXT_PMD
13731         if (ret == -ENOTSUP)
13732                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13733 #endif
13734 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13735         if (ret == -ENOTSUP)
13736                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13737 #endif
13738
13739         switch (ret) {
13740         case 0:
13741                 break;
13742         case -EINVAL:
13743                 printf("invalid is_on %d\n", is_on);
13744                 break;
13745         case -ENODEV:
13746                 printf("invalid port_id %d\n", res->port_id);
13747                 break;
13748         case -ENOTSUP:
13749                 printf("function not implemented\n");
13750                 break;
13751         default:
13752                 printf("programming error: (%s)\n", strerror(-ret));
13753         }
13754 }
13755
13756 cmdline_parse_inst_t cmd_set_tx_loopback = {
13757         .f = cmd_set_tx_loopback_parsed,
13758         .data = NULL,
13759         .help_str = "set tx loopback <port_id> on|off",
13760         .tokens = {
13761                 (void *)&cmd_tx_loopback_set,
13762                 (void *)&cmd_tx_loopback_tx,
13763                 (void *)&cmd_tx_loopback_loopback,
13764                 (void *)&cmd_tx_loopback_port_id,
13765                 (void *)&cmd_tx_loopback_on_off,
13766                 NULL,
13767         },
13768 };
13769
13770 /* all queues drop enable configuration */
13771
13772 /* Common result structure for all queues drop enable */
13773 struct cmd_all_queues_drop_en_result {
13774         cmdline_fixed_string_t set;
13775         cmdline_fixed_string_t all;
13776         cmdline_fixed_string_t queues;
13777         cmdline_fixed_string_t drop;
13778         portid_t port_id;
13779         cmdline_fixed_string_t on_off;
13780 };
13781
13782 /* Common CLI fields for tx loopback enable disable */
13783 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13784         TOKEN_STRING_INITIALIZER
13785                 (struct cmd_all_queues_drop_en_result,
13786                  set, "set");
13787 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13788         TOKEN_STRING_INITIALIZER
13789                 (struct cmd_all_queues_drop_en_result,
13790                  all, "all");
13791 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13792         TOKEN_STRING_INITIALIZER
13793                 (struct cmd_all_queues_drop_en_result,
13794                  queues, "queues");
13795 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13796         TOKEN_STRING_INITIALIZER
13797                 (struct cmd_all_queues_drop_en_result,
13798                  drop, "drop");
13799 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13800         TOKEN_NUM_INITIALIZER
13801                 (struct cmd_all_queues_drop_en_result,
13802                  port_id, UINT16);
13803 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13804         TOKEN_STRING_INITIALIZER
13805                 (struct cmd_all_queues_drop_en_result,
13806                  on_off, "on#off");
13807
13808 static void
13809 cmd_set_all_queues_drop_en_parsed(
13810         void *parsed_result,
13811         __attribute__((unused)) struct cmdline *cl,
13812         __attribute__((unused)) void *data)
13813 {
13814         struct cmd_all_queues_drop_en_result *res = parsed_result;
13815         int ret = -ENOTSUP;
13816         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13817
13818         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13819                 return;
13820
13821 #ifdef RTE_LIBRTE_IXGBE_PMD
13822         if (ret == -ENOTSUP)
13823                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13824 #endif
13825 #ifdef RTE_LIBRTE_BNXT_PMD
13826         if (ret == -ENOTSUP)
13827                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13828 #endif
13829         switch (ret) {
13830         case 0:
13831                 break;
13832         case -EINVAL:
13833                 printf("invalid is_on %d\n", is_on);
13834                 break;
13835         case -ENODEV:
13836                 printf("invalid port_id %d\n", res->port_id);
13837                 break;
13838         case -ENOTSUP:
13839                 printf("function not implemented\n");
13840                 break;
13841         default:
13842                 printf("programming error: (%s)\n", strerror(-ret));
13843         }
13844 }
13845
13846 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13847         .f = cmd_set_all_queues_drop_en_parsed,
13848         .data = NULL,
13849         .help_str = "set all queues drop <port_id> on|off",
13850         .tokens = {
13851                 (void *)&cmd_all_queues_drop_en_set,
13852                 (void *)&cmd_all_queues_drop_en_all,
13853                 (void *)&cmd_all_queues_drop_en_queues,
13854                 (void *)&cmd_all_queues_drop_en_drop,
13855                 (void *)&cmd_all_queues_drop_en_port_id,
13856                 (void *)&cmd_all_queues_drop_en_on_off,
13857                 NULL,
13858         },
13859 };
13860
13861 /* vf split drop enable configuration */
13862
13863 /* Common result structure for vf split drop enable */
13864 struct cmd_vf_split_drop_en_result {
13865         cmdline_fixed_string_t set;
13866         cmdline_fixed_string_t vf;
13867         cmdline_fixed_string_t split;
13868         cmdline_fixed_string_t drop;
13869         portid_t port_id;
13870         uint16_t vf_id;
13871         cmdline_fixed_string_t on_off;
13872 };
13873
13874 /* Common CLI fields for vf split drop enable disable */
13875 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13876         TOKEN_STRING_INITIALIZER
13877                 (struct cmd_vf_split_drop_en_result,
13878                  set, "set");
13879 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13880         TOKEN_STRING_INITIALIZER
13881                 (struct cmd_vf_split_drop_en_result,
13882                  vf, "vf");
13883 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13884         TOKEN_STRING_INITIALIZER
13885                 (struct cmd_vf_split_drop_en_result,
13886                  split, "split");
13887 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13888         TOKEN_STRING_INITIALIZER
13889                 (struct cmd_vf_split_drop_en_result,
13890                  drop, "drop");
13891 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13892         TOKEN_NUM_INITIALIZER
13893                 (struct cmd_vf_split_drop_en_result,
13894                  port_id, UINT16);
13895 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13896         TOKEN_NUM_INITIALIZER
13897                 (struct cmd_vf_split_drop_en_result,
13898                  vf_id, UINT16);
13899 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13900         TOKEN_STRING_INITIALIZER
13901                 (struct cmd_vf_split_drop_en_result,
13902                  on_off, "on#off");
13903
13904 static void
13905 cmd_set_vf_split_drop_en_parsed(
13906         void *parsed_result,
13907         __attribute__((unused)) struct cmdline *cl,
13908         __attribute__((unused)) void *data)
13909 {
13910         struct cmd_vf_split_drop_en_result *res = parsed_result;
13911         int ret = -ENOTSUP;
13912         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13913
13914         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13915                 return;
13916
13917 #ifdef RTE_LIBRTE_IXGBE_PMD
13918         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13919                         is_on);
13920 #endif
13921         switch (ret) {
13922         case 0:
13923                 break;
13924         case -EINVAL:
13925                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13926                 break;
13927         case -ENODEV:
13928                 printf("invalid port_id %d\n", res->port_id);
13929                 break;
13930         case -ENOTSUP:
13931                 printf("not supported on port %d\n", res->port_id);
13932                 break;
13933         default:
13934                 printf("programming error: (%s)\n", strerror(-ret));
13935         }
13936 }
13937
13938 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13939         .f = cmd_set_vf_split_drop_en_parsed,
13940         .data = NULL,
13941         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13942         .tokens = {
13943                 (void *)&cmd_vf_split_drop_en_set,
13944                 (void *)&cmd_vf_split_drop_en_vf,
13945                 (void *)&cmd_vf_split_drop_en_split,
13946                 (void *)&cmd_vf_split_drop_en_drop,
13947                 (void *)&cmd_vf_split_drop_en_port_id,
13948                 (void *)&cmd_vf_split_drop_en_vf_id,
13949                 (void *)&cmd_vf_split_drop_en_on_off,
13950                 NULL,
13951         },
13952 };
13953
13954 /* vf mac address configuration */
13955
13956 /* Common result structure for vf mac address */
13957 struct cmd_set_vf_mac_addr_result {
13958         cmdline_fixed_string_t set;
13959         cmdline_fixed_string_t vf;
13960         cmdline_fixed_string_t mac;
13961         cmdline_fixed_string_t addr;
13962         portid_t port_id;
13963         uint16_t vf_id;
13964         struct rte_ether_addr mac_addr;
13965
13966 };
13967
13968 /* Common CLI fields for vf split drop enable disable */
13969 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13970         TOKEN_STRING_INITIALIZER
13971                 (struct cmd_set_vf_mac_addr_result,
13972                  set, "set");
13973 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13974         TOKEN_STRING_INITIALIZER
13975                 (struct cmd_set_vf_mac_addr_result,
13976                  vf, "vf");
13977 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13978         TOKEN_STRING_INITIALIZER
13979                 (struct cmd_set_vf_mac_addr_result,
13980                  mac, "mac");
13981 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13982         TOKEN_STRING_INITIALIZER
13983                 (struct cmd_set_vf_mac_addr_result,
13984                  addr, "addr");
13985 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13986         TOKEN_NUM_INITIALIZER
13987                 (struct cmd_set_vf_mac_addr_result,
13988                  port_id, UINT16);
13989 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13990         TOKEN_NUM_INITIALIZER
13991                 (struct cmd_set_vf_mac_addr_result,
13992                  vf_id, UINT16);
13993 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13994         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13995                  mac_addr);
13996
13997 static void
13998 cmd_set_vf_mac_addr_parsed(
13999         void *parsed_result,
14000         __attribute__((unused)) struct cmdline *cl,
14001         __attribute__((unused)) void *data)
14002 {
14003         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14004         int ret = -ENOTSUP;
14005
14006         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14007                 return;
14008
14009 #ifdef RTE_LIBRTE_IXGBE_PMD
14010         if (ret == -ENOTSUP)
14011                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14012                                 &res->mac_addr);
14013 #endif
14014 #ifdef RTE_LIBRTE_I40E_PMD
14015         if (ret == -ENOTSUP)
14016                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14017                                 &res->mac_addr);
14018 #endif
14019 #ifdef RTE_LIBRTE_BNXT_PMD
14020         if (ret == -ENOTSUP)
14021                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14022                                 &res->mac_addr);
14023 #endif
14024
14025         switch (ret) {
14026         case 0:
14027                 break;
14028         case -EINVAL:
14029                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14030                 break;
14031         case -ENODEV:
14032                 printf("invalid port_id %d\n", res->port_id);
14033                 break;
14034         case -ENOTSUP:
14035                 printf("function not implemented\n");
14036                 break;
14037         default:
14038                 printf("programming error: (%s)\n", strerror(-ret));
14039         }
14040 }
14041
14042 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14043         .f = cmd_set_vf_mac_addr_parsed,
14044         .data = NULL,
14045         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14046         .tokens = {
14047                 (void *)&cmd_set_vf_mac_addr_set,
14048                 (void *)&cmd_set_vf_mac_addr_vf,
14049                 (void *)&cmd_set_vf_mac_addr_mac,
14050                 (void *)&cmd_set_vf_mac_addr_addr,
14051                 (void *)&cmd_set_vf_mac_addr_port_id,
14052                 (void *)&cmd_set_vf_mac_addr_vf_id,
14053                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14054                 NULL,
14055         },
14056 };
14057
14058 /* MACsec configuration */
14059
14060 /* Common result structure for MACsec offload enable */
14061 struct cmd_macsec_offload_on_result {
14062         cmdline_fixed_string_t set;
14063         cmdline_fixed_string_t macsec;
14064         cmdline_fixed_string_t offload;
14065         portid_t port_id;
14066         cmdline_fixed_string_t on;
14067         cmdline_fixed_string_t encrypt;
14068         cmdline_fixed_string_t en_on_off;
14069         cmdline_fixed_string_t replay_protect;
14070         cmdline_fixed_string_t rp_on_off;
14071 };
14072
14073 /* Common CLI fields for MACsec offload disable */
14074 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14075         TOKEN_STRING_INITIALIZER
14076                 (struct cmd_macsec_offload_on_result,
14077                  set, "set");
14078 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14079         TOKEN_STRING_INITIALIZER
14080                 (struct cmd_macsec_offload_on_result,
14081                  macsec, "macsec");
14082 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14083         TOKEN_STRING_INITIALIZER
14084                 (struct cmd_macsec_offload_on_result,
14085                  offload, "offload");
14086 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14087         TOKEN_NUM_INITIALIZER
14088                 (struct cmd_macsec_offload_on_result,
14089                  port_id, UINT16);
14090 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14091         TOKEN_STRING_INITIALIZER
14092                 (struct cmd_macsec_offload_on_result,
14093                  on, "on");
14094 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14095         TOKEN_STRING_INITIALIZER
14096                 (struct cmd_macsec_offload_on_result,
14097                  encrypt, "encrypt");
14098 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14099         TOKEN_STRING_INITIALIZER
14100                 (struct cmd_macsec_offload_on_result,
14101                  en_on_off, "on#off");
14102 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14103         TOKEN_STRING_INITIALIZER
14104                 (struct cmd_macsec_offload_on_result,
14105                  replay_protect, "replay-protect");
14106 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14107         TOKEN_STRING_INITIALIZER
14108                 (struct cmd_macsec_offload_on_result,
14109                  rp_on_off, "on#off");
14110
14111 static void
14112 cmd_set_macsec_offload_on_parsed(
14113         void *parsed_result,
14114         __attribute__((unused)) struct cmdline *cl,
14115         __attribute__((unused)) void *data)
14116 {
14117         struct cmd_macsec_offload_on_result *res = parsed_result;
14118         int ret = -ENOTSUP;
14119         portid_t port_id = res->port_id;
14120         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14121         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14122         struct rte_eth_dev_info dev_info;
14123
14124         if (port_id_is_invalid(port_id, ENABLED_WARN))
14125                 return;
14126         if (!port_is_stopped(port_id)) {
14127                 printf("Please stop port %d first\n", port_id);
14128                 return;
14129         }
14130
14131         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14132         if (ret != 0)
14133                 return;
14134
14135         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14136 #ifdef RTE_LIBRTE_IXGBE_PMD
14137                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14138 #endif
14139         }
14140         RTE_SET_USED(en);
14141         RTE_SET_USED(rp);
14142
14143         switch (ret) {
14144         case 0:
14145                 ports[port_id].dev_conf.txmode.offloads |=
14146                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14147                 cmd_reconfig_device_queue(port_id, 1, 1);
14148                 break;
14149         case -ENODEV:
14150                 printf("invalid port_id %d\n", port_id);
14151                 break;
14152         case -ENOTSUP:
14153                 printf("not supported on port %d\n", port_id);
14154                 break;
14155         default:
14156                 printf("programming error: (%s)\n", strerror(-ret));
14157         }
14158 }
14159
14160 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14161         .f = cmd_set_macsec_offload_on_parsed,
14162         .data = NULL,
14163         .help_str = "set macsec offload <port_id> on "
14164                 "encrypt on|off replay-protect on|off",
14165         .tokens = {
14166                 (void *)&cmd_macsec_offload_on_set,
14167                 (void *)&cmd_macsec_offload_on_macsec,
14168                 (void *)&cmd_macsec_offload_on_offload,
14169                 (void *)&cmd_macsec_offload_on_port_id,
14170                 (void *)&cmd_macsec_offload_on_on,
14171                 (void *)&cmd_macsec_offload_on_encrypt,
14172                 (void *)&cmd_macsec_offload_on_en_on_off,
14173                 (void *)&cmd_macsec_offload_on_replay_protect,
14174                 (void *)&cmd_macsec_offload_on_rp_on_off,
14175                 NULL,
14176         },
14177 };
14178
14179 /* Common result structure for MACsec offload disable */
14180 struct cmd_macsec_offload_off_result {
14181         cmdline_fixed_string_t set;
14182         cmdline_fixed_string_t macsec;
14183         cmdline_fixed_string_t offload;
14184         portid_t port_id;
14185         cmdline_fixed_string_t off;
14186 };
14187
14188 /* Common CLI fields for MACsec offload disable */
14189 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14190         TOKEN_STRING_INITIALIZER
14191                 (struct cmd_macsec_offload_off_result,
14192                  set, "set");
14193 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14194         TOKEN_STRING_INITIALIZER
14195                 (struct cmd_macsec_offload_off_result,
14196                  macsec, "macsec");
14197 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14198         TOKEN_STRING_INITIALIZER
14199                 (struct cmd_macsec_offload_off_result,
14200                  offload, "offload");
14201 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14202         TOKEN_NUM_INITIALIZER
14203                 (struct cmd_macsec_offload_off_result,
14204                  port_id, UINT16);
14205 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14206         TOKEN_STRING_INITIALIZER
14207                 (struct cmd_macsec_offload_off_result,
14208                  off, "off");
14209
14210 static void
14211 cmd_set_macsec_offload_off_parsed(
14212         void *parsed_result,
14213         __attribute__((unused)) struct cmdline *cl,
14214         __attribute__((unused)) void *data)
14215 {
14216         struct cmd_macsec_offload_off_result *res = parsed_result;
14217         int ret = -ENOTSUP;
14218         struct rte_eth_dev_info dev_info;
14219         portid_t port_id = res->port_id;
14220
14221         if (port_id_is_invalid(port_id, ENABLED_WARN))
14222                 return;
14223         if (!port_is_stopped(port_id)) {
14224                 printf("Please stop port %d first\n", port_id);
14225                 return;
14226         }
14227
14228         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14229         if (ret != 0)
14230                 return;
14231
14232         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14233 #ifdef RTE_LIBRTE_IXGBE_PMD
14234                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14235 #endif
14236         }
14237         switch (ret) {
14238         case 0:
14239                 ports[port_id].dev_conf.txmode.offloads &=
14240                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14241                 cmd_reconfig_device_queue(port_id, 1, 1);
14242                 break;
14243         case -ENODEV:
14244                 printf("invalid port_id %d\n", port_id);
14245                 break;
14246         case -ENOTSUP:
14247                 printf("not supported on port %d\n", port_id);
14248                 break;
14249         default:
14250                 printf("programming error: (%s)\n", strerror(-ret));
14251         }
14252 }
14253
14254 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14255         .f = cmd_set_macsec_offload_off_parsed,
14256         .data = NULL,
14257         .help_str = "set macsec offload <port_id> off",
14258         .tokens = {
14259                 (void *)&cmd_macsec_offload_off_set,
14260                 (void *)&cmd_macsec_offload_off_macsec,
14261                 (void *)&cmd_macsec_offload_off_offload,
14262                 (void *)&cmd_macsec_offload_off_port_id,
14263                 (void *)&cmd_macsec_offload_off_off,
14264                 NULL,
14265         },
14266 };
14267
14268 /* Common result structure for MACsec secure connection configure */
14269 struct cmd_macsec_sc_result {
14270         cmdline_fixed_string_t set;
14271         cmdline_fixed_string_t macsec;
14272         cmdline_fixed_string_t sc;
14273         cmdline_fixed_string_t tx_rx;
14274         portid_t port_id;
14275         struct rte_ether_addr mac;
14276         uint16_t pi;
14277 };
14278
14279 /* Common CLI fields for MACsec secure connection configure */
14280 cmdline_parse_token_string_t cmd_macsec_sc_set =
14281         TOKEN_STRING_INITIALIZER
14282                 (struct cmd_macsec_sc_result,
14283                  set, "set");
14284 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14285         TOKEN_STRING_INITIALIZER
14286                 (struct cmd_macsec_sc_result,
14287                  macsec, "macsec");
14288 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14289         TOKEN_STRING_INITIALIZER
14290                 (struct cmd_macsec_sc_result,
14291                  sc, "sc");
14292 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14293         TOKEN_STRING_INITIALIZER
14294                 (struct cmd_macsec_sc_result,
14295                  tx_rx, "tx#rx");
14296 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14297         TOKEN_NUM_INITIALIZER
14298                 (struct cmd_macsec_sc_result,
14299                  port_id, UINT16);
14300 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14301         TOKEN_ETHERADDR_INITIALIZER
14302                 (struct cmd_macsec_sc_result,
14303                  mac);
14304 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14305         TOKEN_NUM_INITIALIZER
14306                 (struct cmd_macsec_sc_result,
14307                  pi, UINT16);
14308
14309 static void
14310 cmd_set_macsec_sc_parsed(
14311         void *parsed_result,
14312         __attribute__((unused)) struct cmdline *cl,
14313         __attribute__((unused)) void *data)
14314 {
14315         struct cmd_macsec_sc_result *res = parsed_result;
14316         int ret = -ENOTSUP;
14317         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14318
14319 #ifdef RTE_LIBRTE_IXGBE_PMD
14320         ret = is_tx ?
14321                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14322                                 res->mac.addr_bytes) :
14323                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14324                                 res->mac.addr_bytes, res->pi);
14325 #endif
14326         RTE_SET_USED(is_tx);
14327
14328         switch (ret) {
14329         case 0:
14330                 break;
14331         case -ENODEV:
14332                 printf("invalid port_id %d\n", res->port_id);
14333                 break;
14334         case -ENOTSUP:
14335                 printf("not supported on port %d\n", res->port_id);
14336                 break;
14337         default:
14338                 printf("programming error: (%s)\n", strerror(-ret));
14339         }
14340 }
14341
14342 cmdline_parse_inst_t cmd_set_macsec_sc = {
14343         .f = cmd_set_macsec_sc_parsed,
14344         .data = NULL,
14345         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14346         .tokens = {
14347                 (void *)&cmd_macsec_sc_set,
14348                 (void *)&cmd_macsec_sc_macsec,
14349                 (void *)&cmd_macsec_sc_sc,
14350                 (void *)&cmd_macsec_sc_tx_rx,
14351                 (void *)&cmd_macsec_sc_port_id,
14352                 (void *)&cmd_macsec_sc_mac,
14353                 (void *)&cmd_macsec_sc_pi,
14354                 NULL,
14355         },
14356 };
14357
14358 /* Common result structure for MACsec secure connection configure */
14359 struct cmd_macsec_sa_result {
14360         cmdline_fixed_string_t set;
14361         cmdline_fixed_string_t macsec;
14362         cmdline_fixed_string_t sa;
14363         cmdline_fixed_string_t tx_rx;
14364         portid_t port_id;
14365         uint8_t idx;
14366         uint8_t an;
14367         uint32_t pn;
14368         cmdline_fixed_string_t key;
14369 };
14370
14371 /* Common CLI fields for MACsec secure connection configure */
14372 cmdline_parse_token_string_t cmd_macsec_sa_set =
14373         TOKEN_STRING_INITIALIZER
14374                 (struct cmd_macsec_sa_result,
14375                  set, "set");
14376 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14377         TOKEN_STRING_INITIALIZER
14378                 (struct cmd_macsec_sa_result,
14379                  macsec, "macsec");
14380 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14381         TOKEN_STRING_INITIALIZER
14382                 (struct cmd_macsec_sa_result,
14383                  sa, "sa");
14384 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14385         TOKEN_STRING_INITIALIZER
14386                 (struct cmd_macsec_sa_result,
14387                  tx_rx, "tx#rx");
14388 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14389         TOKEN_NUM_INITIALIZER
14390                 (struct cmd_macsec_sa_result,
14391                  port_id, UINT16);
14392 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14393         TOKEN_NUM_INITIALIZER
14394                 (struct cmd_macsec_sa_result,
14395                  idx, UINT8);
14396 cmdline_parse_token_num_t cmd_macsec_sa_an =
14397         TOKEN_NUM_INITIALIZER
14398                 (struct cmd_macsec_sa_result,
14399                  an, UINT8);
14400 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14401         TOKEN_NUM_INITIALIZER
14402                 (struct cmd_macsec_sa_result,
14403                  pn, UINT32);
14404 cmdline_parse_token_string_t cmd_macsec_sa_key =
14405         TOKEN_STRING_INITIALIZER
14406                 (struct cmd_macsec_sa_result,
14407                  key, NULL);
14408
14409 static void
14410 cmd_set_macsec_sa_parsed(
14411         void *parsed_result,
14412         __attribute__((unused)) struct cmdline *cl,
14413         __attribute__((unused)) void *data)
14414 {
14415         struct cmd_macsec_sa_result *res = parsed_result;
14416         int ret = -ENOTSUP;
14417         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14418         uint8_t key[16] = { 0 };
14419         uint8_t xdgt0;
14420         uint8_t xdgt1;
14421         int key_len;
14422         int i;
14423
14424         key_len = strlen(res->key) / 2;
14425         if (key_len > 16)
14426                 key_len = 16;
14427
14428         for (i = 0; i < key_len; i++) {
14429                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14430                 if (xdgt0 == 0xFF)
14431                         return;
14432                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14433                 if (xdgt1 == 0xFF)
14434                         return;
14435                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14436         }
14437
14438 #ifdef RTE_LIBRTE_IXGBE_PMD
14439         ret = is_tx ?
14440                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14441                         res->idx, res->an, res->pn, key) :
14442                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14443                         res->idx, res->an, res->pn, key);
14444 #endif
14445         RTE_SET_USED(is_tx);
14446         RTE_SET_USED(key);
14447
14448         switch (ret) {
14449         case 0:
14450                 break;
14451         case -EINVAL:
14452                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14453                 break;
14454         case -ENODEV:
14455                 printf("invalid port_id %d\n", res->port_id);
14456                 break;
14457         case -ENOTSUP:
14458                 printf("not supported on port %d\n", res->port_id);
14459                 break;
14460         default:
14461                 printf("programming error: (%s)\n", strerror(-ret));
14462         }
14463 }
14464
14465 cmdline_parse_inst_t cmd_set_macsec_sa = {
14466         .f = cmd_set_macsec_sa_parsed,
14467         .data = NULL,
14468         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14469         .tokens = {
14470                 (void *)&cmd_macsec_sa_set,
14471                 (void *)&cmd_macsec_sa_macsec,
14472                 (void *)&cmd_macsec_sa_sa,
14473                 (void *)&cmd_macsec_sa_tx_rx,
14474                 (void *)&cmd_macsec_sa_port_id,
14475                 (void *)&cmd_macsec_sa_idx,
14476                 (void *)&cmd_macsec_sa_an,
14477                 (void *)&cmd_macsec_sa_pn,
14478                 (void *)&cmd_macsec_sa_key,
14479                 NULL,
14480         },
14481 };
14482
14483 /* VF unicast promiscuous mode configuration */
14484
14485 /* Common result structure for VF unicast promiscuous mode */
14486 struct cmd_vf_promisc_result {
14487         cmdline_fixed_string_t set;
14488         cmdline_fixed_string_t vf;
14489         cmdline_fixed_string_t promisc;
14490         portid_t port_id;
14491         uint32_t vf_id;
14492         cmdline_fixed_string_t on_off;
14493 };
14494
14495 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14496 cmdline_parse_token_string_t cmd_vf_promisc_set =
14497         TOKEN_STRING_INITIALIZER
14498                 (struct cmd_vf_promisc_result,
14499                  set, "set");
14500 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14501         TOKEN_STRING_INITIALIZER
14502                 (struct cmd_vf_promisc_result,
14503                  vf, "vf");
14504 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14505         TOKEN_STRING_INITIALIZER
14506                 (struct cmd_vf_promisc_result,
14507                  promisc, "promisc");
14508 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14509         TOKEN_NUM_INITIALIZER
14510                 (struct cmd_vf_promisc_result,
14511                  port_id, UINT16);
14512 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14513         TOKEN_NUM_INITIALIZER
14514                 (struct cmd_vf_promisc_result,
14515                  vf_id, UINT32);
14516 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14517         TOKEN_STRING_INITIALIZER
14518                 (struct cmd_vf_promisc_result,
14519                  on_off, "on#off");
14520
14521 static void
14522 cmd_set_vf_promisc_parsed(
14523         void *parsed_result,
14524         __attribute__((unused)) struct cmdline *cl,
14525         __attribute__((unused)) void *data)
14526 {
14527         struct cmd_vf_promisc_result *res = parsed_result;
14528         int ret = -ENOTSUP;
14529
14530         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14531
14532         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14533                 return;
14534
14535 #ifdef RTE_LIBRTE_I40E_PMD
14536         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14537                                                   res->vf_id, is_on);
14538 #endif
14539
14540         switch (ret) {
14541         case 0:
14542                 break;
14543         case -EINVAL:
14544                 printf("invalid vf_id %d\n", res->vf_id);
14545                 break;
14546         case -ENODEV:
14547                 printf("invalid port_id %d\n", res->port_id);
14548                 break;
14549         case -ENOTSUP:
14550                 printf("function not implemented\n");
14551                 break;
14552         default:
14553                 printf("programming error: (%s)\n", strerror(-ret));
14554         }
14555 }
14556
14557 cmdline_parse_inst_t cmd_set_vf_promisc = {
14558         .f = cmd_set_vf_promisc_parsed,
14559         .data = NULL,
14560         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14561                 "Set unicast promiscuous mode for a VF from the PF",
14562         .tokens = {
14563                 (void *)&cmd_vf_promisc_set,
14564                 (void *)&cmd_vf_promisc_vf,
14565                 (void *)&cmd_vf_promisc_promisc,
14566                 (void *)&cmd_vf_promisc_port_id,
14567                 (void *)&cmd_vf_promisc_vf_id,
14568                 (void *)&cmd_vf_promisc_on_off,
14569                 NULL,
14570         },
14571 };
14572
14573 /* VF multicast promiscuous mode configuration */
14574
14575 /* Common result structure for VF multicast promiscuous mode */
14576 struct cmd_vf_allmulti_result {
14577         cmdline_fixed_string_t set;
14578         cmdline_fixed_string_t vf;
14579         cmdline_fixed_string_t allmulti;
14580         portid_t port_id;
14581         uint32_t vf_id;
14582         cmdline_fixed_string_t on_off;
14583 };
14584
14585 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14586 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14587         TOKEN_STRING_INITIALIZER
14588                 (struct cmd_vf_allmulti_result,
14589                  set, "set");
14590 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14591         TOKEN_STRING_INITIALIZER
14592                 (struct cmd_vf_allmulti_result,
14593                  vf, "vf");
14594 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14595         TOKEN_STRING_INITIALIZER
14596                 (struct cmd_vf_allmulti_result,
14597                  allmulti, "allmulti");
14598 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14599         TOKEN_NUM_INITIALIZER
14600                 (struct cmd_vf_allmulti_result,
14601                  port_id, UINT16);
14602 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14603         TOKEN_NUM_INITIALIZER
14604                 (struct cmd_vf_allmulti_result,
14605                  vf_id, UINT32);
14606 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14607         TOKEN_STRING_INITIALIZER
14608                 (struct cmd_vf_allmulti_result,
14609                  on_off, "on#off");
14610
14611 static void
14612 cmd_set_vf_allmulti_parsed(
14613         void *parsed_result,
14614         __attribute__((unused)) struct cmdline *cl,
14615         __attribute__((unused)) void *data)
14616 {
14617         struct cmd_vf_allmulti_result *res = parsed_result;
14618         int ret = -ENOTSUP;
14619
14620         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14621
14622         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14623                 return;
14624
14625 #ifdef RTE_LIBRTE_I40E_PMD
14626         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14627                                                     res->vf_id, is_on);
14628 #endif
14629
14630         switch (ret) {
14631         case 0:
14632                 break;
14633         case -EINVAL:
14634                 printf("invalid vf_id %d\n", res->vf_id);
14635                 break;
14636         case -ENODEV:
14637                 printf("invalid port_id %d\n", res->port_id);
14638                 break;
14639         case -ENOTSUP:
14640                 printf("function not implemented\n");
14641                 break;
14642         default:
14643                 printf("programming error: (%s)\n", strerror(-ret));
14644         }
14645 }
14646
14647 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14648         .f = cmd_set_vf_allmulti_parsed,
14649         .data = NULL,
14650         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14651                 "Set multicast promiscuous mode for a VF from the PF",
14652         .tokens = {
14653                 (void *)&cmd_vf_allmulti_set,
14654                 (void *)&cmd_vf_allmulti_vf,
14655                 (void *)&cmd_vf_allmulti_allmulti,
14656                 (void *)&cmd_vf_allmulti_port_id,
14657                 (void *)&cmd_vf_allmulti_vf_id,
14658                 (void *)&cmd_vf_allmulti_on_off,
14659                 NULL,
14660         },
14661 };
14662
14663 /* vf broadcast mode configuration */
14664
14665 /* Common result structure for vf broadcast */
14666 struct cmd_set_vf_broadcast_result {
14667         cmdline_fixed_string_t set;
14668         cmdline_fixed_string_t vf;
14669         cmdline_fixed_string_t broadcast;
14670         portid_t port_id;
14671         uint16_t vf_id;
14672         cmdline_fixed_string_t on_off;
14673 };
14674
14675 /* Common CLI fields for vf broadcast enable disable */
14676 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14677         TOKEN_STRING_INITIALIZER
14678                 (struct cmd_set_vf_broadcast_result,
14679                  set, "set");
14680 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14681         TOKEN_STRING_INITIALIZER
14682                 (struct cmd_set_vf_broadcast_result,
14683                  vf, "vf");
14684 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14685         TOKEN_STRING_INITIALIZER
14686                 (struct cmd_set_vf_broadcast_result,
14687                  broadcast, "broadcast");
14688 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14689         TOKEN_NUM_INITIALIZER
14690                 (struct cmd_set_vf_broadcast_result,
14691                  port_id, UINT16);
14692 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14693         TOKEN_NUM_INITIALIZER
14694                 (struct cmd_set_vf_broadcast_result,
14695                  vf_id, UINT16);
14696 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14697         TOKEN_STRING_INITIALIZER
14698                 (struct cmd_set_vf_broadcast_result,
14699                  on_off, "on#off");
14700
14701 static void
14702 cmd_set_vf_broadcast_parsed(
14703         void *parsed_result,
14704         __attribute__((unused)) struct cmdline *cl,
14705         __attribute__((unused)) void *data)
14706 {
14707         struct cmd_set_vf_broadcast_result *res = parsed_result;
14708         int ret = -ENOTSUP;
14709
14710         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14711
14712         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14713                 return;
14714
14715 #ifdef RTE_LIBRTE_I40E_PMD
14716         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14717                                             res->vf_id, is_on);
14718 #endif
14719
14720         switch (ret) {
14721         case 0:
14722                 break;
14723         case -EINVAL:
14724                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14725                 break;
14726         case -ENODEV:
14727                 printf("invalid port_id %d\n", res->port_id);
14728                 break;
14729         case -ENOTSUP:
14730                 printf("function not implemented\n");
14731                 break;
14732         default:
14733                 printf("programming error: (%s)\n", strerror(-ret));
14734         }
14735 }
14736
14737 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14738         .f = cmd_set_vf_broadcast_parsed,
14739         .data = NULL,
14740         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14741         .tokens = {
14742                 (void *)&cmd_set_vf_broadcast_set,
14743                 (void *)&cmd_set_vf_broadcast_vf,
14744                 (void *)&cmd_set_vf_broadcast_broadcast,
14745                 (void *)&cmd_set_vf_broadcast_port_id,
14746                 (void *)&cmd_set_vf_broadcast_vf_id,
14747                 (void *)&cmd_set_vf_broadcast_on_off,
14748                 NULL,
14749         },
14750 };
14751
14752 /* vf vlan tag configuration */
14753
14754 /* Common result structure for vf vlan tag */
14755 struct cmd_set_vf_vlan_tag_result {
14756         cmdline_fixed_string_t set;
14757         cmdline_fixed_string_t vf;
14758         cmdline_fixed_string_t vlan;
14759         cmdline_fixed_string_t tag;
14760         portid_t port_id;
14761         uint16_t vf_id;
14762         cmdline_fixed_string_t on_off;
14763 };
14764
14765 /* Common CLI fields for vf vlan tag enable disable */
14766 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14767         TOKEN_STRING_INITIALIZER
14768                 (struct cmd_set_vf_vlan_tag_result,
14769                  set, "set");
14770 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14771         TOKEN_STRING_INITIALIZER
14772                 (struct cmd_set_vf_vlan_tag_result,
14773                  vf, "vf");
14774 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14775         TOKEN_STRING_INITIALIZER
14776                 (struct cmd_set_vf_vlan_tag_result,
14777                  vlan, "vlan");
14778 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14779         TOKEN_STRING_INITIALIZER
14780                 (struct cmd_set_vf_vlan_tag_result,
14781                  tag, "tag");
14782 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14783         TOKEN_NUM_INITIALIZER
14784                 (struct cmd_set_vf_vlan_tag_result,
14785                  port_id, UINT16);
14786 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14787         TOKEN_NUM_INITIALIZER
14788                 (struct cmd_set_vf_vlan_tag_result,
14789                  vf_id, UINT16);
14790 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14791         TOKEN_STRING_INITIALIZER
14792                 (struct cmd_set_vf_vlan_tag_result,
14793                  on_off, "on#off");
14794
14795 static void
14796 cmd_set_vf_vlan_tag_parsed(
14797         void *parsed_result,
14798         __attribute__((unused)) struct cmdline *cl,
14799         __attribute__((unused)) void *data)
14800 {
14801         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14802         int ret = -ENOTSUP;
14803
14804         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14805
14806         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14807                 return;
14808
14809 #ifdef RTE_LIBRTE_I40E_PMD
14810         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14811                                            res->vf_id, is_on);
14812 #endif
14813
14814         switch (ret) {
14815         case 0:
14816                 break;
14817         case -EINVAL:
14818                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14819                 break;
14820         case -ENODEV:
14821                 printf("invalid port_id %d\n", res->port_id);
14822                 break;
14823         case -ENOTSUP:
14824                 printf("function not implemented\n");
14825                 break;
14826         default:
14827                 printf("programming error: (%s)\n", strerror(-ret));
14828         }
14829 }
14830
14831 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14832         .f = cmd_set_vf_vlan_tag_parsed,
14833         .data = NULL,
14834         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14835         .tokens = {
14836                 (void *)&cmd_set_vf_vlan_tag_set,
14837                 (void *)&cmd_set_vf_vlan_tag_vf,
14838                 (void *)&cmd_set_vf_vlan_tag_vlan,
14839                 (void *)&cmd_set_vf_vlan_tag_tag,
14840                 (void *)&cmd_set_vf_vlan_tag_port_id,
14841                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14842                 (void *)&cmd_set_vf_vlan_tag_on_off,
14843                 NULL,
14844         },
14845 };
14846
14847 /* Common definition of VF and TC TX bandwidth configuration */
14848 struct cmd_vf_tc_bw_result {
14849         cmdline_fixed_string_t set;
14850         cmdline_fixed_string_t vf;
14851         cmdline_fixed_string_t tc;
14852         cmdline_fixed_string_t tx;
14853         cmdline_fixed_string_t min_bw;
14854         cmdline_fixed_string_t max_bw;
14855         cmdline_fixed_string_t strict_link_prio;
14856         portid_t port_id;
14857         uint16_t vf_id;
14858         uint8_t tc_no;
14859         uint32_t bw;
14860         cmdline_fixed_string_t bw_list;
14861         uint8_t tc_map;
14862 };
14863
14864 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14865         TOKEN_STRING_INITIALIZER
14866                 (struct cmd_vf_tc_bw_result,
14867                  set, "set");
14868 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14869         TOKEN_STRING_INITIALIZER
14870                 (struct cmd_vf_tc_bw_result,
14871                  vf, "vf");
14872 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14873         TOKEN_STRING_INITIALIZER
14874                 (struct cmd_vf_tc_bw_result,
14875                  tc, "tc");
14876 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14877         TOKEN_STRING_INITIALIZER
14878                 (struct cmd_vf_tc_bw_result,
14879                  tx, "tx");
14880 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14881         TOKEN_STRING_INITIALIZER
14882                 (struct cmd_vf_tc_bw_result,
14883                  strict_link_prio, "strict-link-priority");
14884 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14885         TOKEN_STRING_INITIALIZER
14886                 (struct cmd_vf_tc_bw_result,
14887                  min_bw, "min-bandwidth");
14888 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14889         TOKEN_STRING_INITIALIZER
14890                 (struct cmd_vf_tc_bw_result,
14891                  max_bw, "max-bandwidth");
14892 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14893         TOKEN_NUM_INITIALIZER
14894                 (struct cmd_vf_tc_bw_result,
14895                  port_id, UINT16);
14896 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14897         TOKEN_NUM_INITIALIZER
14898                 (struct cmd_vf_tc_bw_result,
14899                  vf_id, UINT16);
14900 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14901         TOKEN_NUM_INITIALIZER
14902                 (struct cmd_vf_tc_bw_result,
14903                  tc_no, UINT8);
14904 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14905         TOKEN_NUM_INITIALIZER
14906                 (struct cmd_vf_tc_bw_result,
14907                  bw, UINT32);
14908 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14909         TOKEN_STRING_INITIALIZER
14910                 (struct cmd_vf_tc_bw_result,
14911                  bw_list, NULL);
14912 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14913         TOKEN_NUM_INITIALIZER
14914                 (struct cmd_vf_tc_bw_result,
14915                  tc_map, UINT8);
14916
14917 /* VF max bandwidth setting */
14918 static void
14919 cmd_vf_max_bw_parsed(
14920         void *parsed_result,
14921         __attribute__((unused)) struct cmdline *cl,
14922         __attribute__((unused)) void *data)
14923 {
14924         struct cmd_vf_tc_bw_result *res = parsed_result;
14925         int ret = -ENOTSUP;
14926
14927         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14928                 return;
14929
14930 #ifdef RTE_LIBRTE_I40E_PMD
14931         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14932                                          res->vf_id, res->bw);
14933 #endif
14934
14935         switch (ret) {
14936         case 0:
14937                 break;
14938         case -EINVAL:
14939                 printf("invalid vf_id %d or bandwidth %d\n",
14940                        res->vf_id, res->bw);
14941                 break;
14942         case -ENODEV:
14943                 printf("invalid port_id %d\n", res->port_id);
14944                 break;
14945         case -ENOTSUP:
14946                 printf("function not implemented\n");
14947                 break;
14948         default:
14949                 printf("programming error: (%s)\n", strerror(-ret));
14950         }
14951 }
14952
14953 cmdline_parse_inst_t cmd_vf_max_bw = {
14954         .f = cmd_vf_max_bw_parsed,
14955         .data = NULL,
14956         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14957         .tokens = {
14958                 (void *)&cmd_vf_tc_bw_set,
14959                 (void *)&cmd_vf_tc_bw_vf,
14960                 (void *)&cmd_vf_tc_bw_tx,
14961                 (void *)&cmd_vf_tc_bw_max_bw,
14962                 (void *)&cmd_vf_tc_bw_port_id,
14963                 (void *)&cmd_vf_tc_bw_vf_id,
14964                 (void *)&cmd_vf_tc_bw_bw,
14965                 NULL,
14966         },
14967 };
14968
14969 static int
14970 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14971                            uint8_t *tc_num,
14972                            char *str)
14973 {
14974         uint32_t size;
14975         const char *p, *p0 = str;
14976         char s[256];
14977         char *end;
14978         char *str_fld[16];
14979         uint16_t i;
14980         int ret;
14981
14982         p = strchr(p0, '(');
14983         if (p == NULL) {
14984                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14985                 return -1;
14986         }
14987         p++;
14988         p0 = strchr(p, ')');
14989         if (p0 == NULL) {
14990                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14991                 return -1;
14992         }
14993         size = p0 - p;
14994         if (size >= sizeof(s)) {
14995                 printf("The string size exceeds the internal buffer size\n");
14996                 return -1;
14997         }
14998         snprintf(s, sizeof(s), "%.*s", size, p);
14999         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15000         if (ret <= 0) {
15001                 printf("Failed to get the bandwidth list. ");
15002                 return -1;
15003         }
15004         *tc_num = ret;
15005         for (i = 0; i < ret; i++)
15006                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15007
15008         return 0;
15009 }
15010
15011 /* TC min bandwidth setting */
15012 static void
15013 cmd_vf_tc_min_bw_parsed(
15014         void *parsed_result,
15015         __attribute__((unused)) struct cmdline *cl,
15016         __attribute__((unused)) void *data)
15017 {
15018         struct cmd_vf_tc_bw_result *res = parsed_result;
15019         uint8_t tc_num;
15020         uint8_t bw[16];
15021         int ret = -ENOTSUP;
15022
15023         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15024                 return;
15025
15026         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15027         if (ret)
15028                 return;
15029
15030 #ifdef RTE_LIBRTE_I40E_PMD
15031         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15032                                               tc_num, bw);
15033 #endif
15034
15035         switch (ret) {
15036         case 0:
15037                 break;
15038         case -EINVAL:
15039                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15040                 break;
15041         case -ENODEV:
15042                 printf("invalid port_id %d\n", res->port_id);
15043                 break;
15044         case -ENOTSUP:
15045                 printf("function not implemented\n");
15046                 break;
15047         default:
15048                 printf("programming error: (%s)\n", strerror(-ret));
15049         }
15050 }
15051
15052 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15053         .f = cmd_vf_tc_min_bw_parsed,
15054         .data = NULL,
15055         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15056                     " <bw1, bw2, ...>",
15057         .tokens = {
15058                 (void *)&cmd_vf_tc_bw_set,
15059                 (void *)&cmd_vf_tc_bw_vf,
15060                 (void *)&cmd_vf_tc_bw_tc,
15061                 (void *)&cmd_vf_tc_bw_tx,
15062                 (void *)&cmd_vf_tc_bw_min_bw,
15063                 (void *)&cmd_vf_tc_bw_port_id,
15064                 (void *)&cmd_vf_tc_bw_vf_id,
15065                 (void *)&cmd_vf_tc_bw_bw_list,
15066                 NULL,
15067         },
15068 };
15069
15070 static void
15071 cmd_tc_min_bw_parsed(
15072         void *parsed_result,
15073         __attribute__((unused)) struct cmdline *cl,
15074         __attribute__((unused)) void *data)
15075 {
15076         struct cmd_vf_tc_bw_result *res = parsed_result;
15077         struct rte_port *port;
15078         uint8_t tc_num;
15079         uint8_t bw[16];
15080         int ret = -ENOTSUP;
15081
15082         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15083                 return;
15084
15085         port = &ports[res->port_id];
15086         /** Check if the port is not started **/
15087         if (port->port_status != RTE_PORT_STOPPED) {
15088                 printf("Please stop port %d first\n", res->port_id);
15089                 return;
15090         }
15091
15092         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15093         if (ret)
15094                 return;
15095
15096 #ifdef RTE_LIBRTE_IXGBE_PMD
15097         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15098 #endif
15099
15100         switch (ret) {
15101         case 0:
15102                 break;
15103         case -EINVAL:
15104                 printf("invalid bandwidth\n");
15105                 break;
15106         case -ENODEV:
15107                 printf("invalid port_id %d\n", res->port_id);
15108                 break;
15109         case -ENOTSUP:
15110                 printf("function not implemented\n");
15111                 break;
15112         default:
15113                 printf("programming error: (%s)\n", strerror(-ret));
15114         }
15115 }
15116
15117 cmdline_parse_inst_t cmd_tc_min_bw = {
15118         .f = cmd_tc_min_bw_parsed,
15119         .data = NULL,
15120         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15121         .tokens = {
15122                 (void *)&cmd_vf_tc_bw_set,
15123                 (void *)&cmd_vf_tc_bw_tc,
15124                 (void *)&cmd_vf_tc_bw_tx,
15125                 (void *)&cmd_vf_tc_bw_min_bw,
15126                 (void *)&cmd_vf_tc_bw_port_id,
15127                 (void *)&cmd_vf_tc_bw_bw_list,
15128                 NULL,
15129         },
15130 };
15131
15132 /* TC max bandwidth setting */
15133 static void
15134 cmd_vf_tc_max_bw_parsed(
15135         void *parsed_result,
15136         __attribute__((unused)) struct cmdline *cl,
15137         __attribute__((unused)) void *data)
15138 {
15139         struct cmd_vf_tc_bw_result *res = parsed_result;
15140         int ret = -ENOTSUP;
15141
15142         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15143                 return;
15144
15145 #ifdef RTE_LIBRTE_I40E_PMD
15146         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15147                                             res->tc_no, res->bw);
15148 #endif
15149
15150         switch (ret) {
15151         case 0:
15152                 break;
15153         case -EINVAL:
15154                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15155                        res->vf_id, res->tc_no, res->bw);
15156                 break;
15157         case -ENODEV:
15158                 printf("invalid port_id %d\n", res->port_id);
15159                 break;
15160         case -ENOTSUP:
15161                 printf("function not implemented\n");
15162                 break;
15163         default:
15164                 printf("programming error: (%s)\n", strerror(-ret));
15165         }
15166 }
15167
15168 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15169         .f = cmd_vf_tc_max_bw_parsed,
15170         .data = NULL,
15171         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15172                     " <bandwidth>",
15173         .tokens = {
15174                 (void *)&cmd_vf_tc_bw_set,
15175                 (void *)&cmd_vf_tc_bw_vf,
15176                 (void *)&cmd_vf_tc_bw_tc,
15177                 (void *)&cmd_vf_tc_bw_tx,
15178                 (void *)&cmd_vf_tc_bw_max_bw,
15179                 (void *)&cmd_vf_tc_bw_port_id,
15180                 (void *)&cmd_vf_tc_bw_vf_id,
15181                 (void *)&cmd_vf_tc_bw_tc_no,
15182                 (void *)&cmd_vf_tc_bw_bw,
15183                 NULL,
15184         },
15185 };
15186
15187
15188 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15189
15190 /* *** Set Port default Traffic Management Hierarchy *** */
15191 struct cmd_set_port_tm_hierarchy_default_result {
15192         cmdline_fixed_string_t set;
15193         cmdline_fixed_string_t port;
15194         cmdline_fixed_string_t tm;
15195         cmdline_fixed_string_t hierarchy;
15196         cmdline_fixed_string_t def;
15197         portid_t port_id;
15198 };
15199
15200 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15201         TOKEN_STRING_INITIALIZER(
15202                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15203 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15204         TOKEN_STRING_INITIALIZER(
15205                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15206 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15207         TOKEN_STRING_INITIALIZER(
15208                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15209 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15210         TOKEN_STRING_INITIALIZER(
15211                 struct cmd_set_port_tm_hierarchy_default_result,
15212                         hierarchy, "hierarchy");
15213 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15214         TOKEN_STRING_INITIALIZER(
15215                 struct cmd_set_port_tm_hierarchy_default_result,
15216                         def, "default");
15217 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15218         TOKEN_NUM_INITIALIZER(
15219                 struct cmd_set_port_tm_hierarchy_default_result,
15220                         port_id, UINT16);
15221
15222 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15223         __attribute__((unused)) struct cmdline *cl,
15224         __attribute__((unused)) void *data)
15225 {
15226         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15227         struct rte_port *p;
15228         portid_t port_id = res->port_id;
15229
15230         if (port_id_is_invalid(port_id, ENABLED_WARN))
15231                 return;
15232
15233         p = &ports[port_id];
15234
15235         /* Forward mode: tm */
15236         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15237                 printf("  softnicfwd mode not enabled(error)\n");
15238                 return;
15239         }
15240
15241         /* Set the default tm hierarchy */
15242         p->softport.default_tm_hierarchy_enable = 1;
15243 }
15244
15245 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15246         .f = cmd_set_port_tm_hierarchy_default_parsed,
15247         .data = NULL,
15248         .help_str = "set port tm hierarchy default <port_id>",
15249         .tokens = {
15250                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15251                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15252                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15253                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15254                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15255                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15256                 NULL,
15257         },
15258 };
15259 #endif
15260
15261 /** Set VXLAN encapsulation details */
15262 struct cmd_set_vxlan_result {
15263         cmdline_fixed_string_t set;
15264         cmdline_fixed_string_t vxlan;
15265         cmdline_fixed_string_t pos_token;
15266         cmdline_fixed_string_t ip_version;
15267         uint32_t vlan_present:1;
15268         uint32_t vni;
15269         uint16_t udp_src;
15270         uint16_t udp_dst;
15271         cmdline_ipaddr_t ip_src;
15272         cmdline_ipaddr_t ip_dst;
15273         uint16_t tci;
15274         uint8_t tos;
15275         uint8_t ttl;
15276         struct rte_ether_addr eth_src;
15277         struct rte_ether_addr eth_dst;
15278 };
15279
15280 cmdline_parse_token_string_t cmd_set_vxlan_set =
15281         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15282 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15283         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15284 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15285         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15286                                  "vxlan-tos-ttl");
15287 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15288         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15289                                  "vxlan-with-vlan");
15290 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15291         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15292                                  "ip-version");
15293 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15294         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15295                                  "ipv4#ipv6");
15296 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15297         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15298                                  "vni");
15299 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15300         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15301 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15302         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15303                                  "udp-src");
15304 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15305         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15306 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15307         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15308                                  "udp-dst");
15309 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15310         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15311 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15312         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15313                                  "ip-tos");
15314 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15315         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15316 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15317         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15318                                  "ip-ttl");
15319 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15320         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15321 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15322         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15323                                  "ip-src");
15324 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15325         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15326 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15327         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15328                                  "ip-dst");
15329 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15330         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15331 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15332         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15333                                  "vlan-tci");
15334 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15335         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15336 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15337         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15338                                  "eth-src");
15339 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15340         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15341 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15342         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15343                                  "eth-dst");
15344 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15345         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15346
15347 static void cmd_set_vxlan_parsed(void *parsed_result,
15348         __attribute__((unused)) struct cmdline *cl,
15349         __attribute__((unused)) void *data)
15350 {
15351         struct cmd_set_vxlan_result *res = parsed_result;
15352         union {
15353                 uint32_t vxlan_id;
15354                 uint8_t vni[4];
15355         } id = {
15356                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15357         };
15358
15359         vxlan_encap_conf.select_tos_ttl = 0;
15360         if (strcmp(res->vxlan, "vxlan") == 0)
15361                 vxlan_encap_conf.select_vlan = 0;
15362         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15363                 vxlan_encap_conf.select_vlan = 1;
15364         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15365                 vxlan_encap_conf.select_vlan = 0;
15366                 vxlan_encap_conf.select_tos_ttl = 1;
15367         }
15368         if (strcmp(res->ip_version, "ipv4") == 0)
15369                 vxlan_encap_conf.select_ipv4 = 1;
15370         else if (strcmp(res->ip_version, "ipv6") == 0)
15371                 vxlan_encap_conf.select_ipv4 = 0;
15372         else
15373                 return;
15374         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15375         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15376         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15377         vxlan_encap_conf.ip_tos = res->tos;
15378         vxlan_encap_conf.ip_ttl = res->ttl;
15379         if (vxlan_encap_conf.select_ipv4) {
15380                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15381                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15382         } else {
15383                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15384                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15385         }
15386         if (vxlan_encap_conf.select_vlan)
15387                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15388         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15389                    RTE_ETHER_ADDR_LEN);
15390         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15391                    RTE_ETHER_ADDR_LEN);
15392 }
15393
15394 cmdline_parse_inst_t cmd_set_vxlan = {
15395         .f = cmd_set_vxlan_parsed,
15396         .data = NULL,
15397         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15398                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15399                 " eth-src <eth-src> eth-dst <eth-dst>",
15400         .tokens = {
15401                 (void *)&cmd_set_vxlan_set,
15402                 (void *)&cmd_set_vxlan_vxlan,
15403                 (void *)&cmd_set_vxlan_ip_version,
15404                 (void *)&cmd_set_vxlan_ip_version_value,
15405                 (void *)&cmd_set_vxlan_vni,
15406                 (void *)&cmd_set_vxlan_vni_value,
15407                 (void *)&cmd_set_vxlan_udp_src,
15408                 (void *)&cmd_set_vxlan_udp_src_value,
15409                 (void *)&cmd_set_vxlan_udp_dst,
15410                 (void *)&cmd_set_vxlan_udp_dst_value,
15411                 (void *)&cmd_set_vxlan_ip_src,
15412                 (void *)&cmd_set_vxlan_ip_src_value,
15413                 (void *)&cmd_set_vxlan_ip_dst,
15414                 (void *)&cmd_set_vxlan_ip_dst_value,
15415                 (void *)&cmd_set_vxlan_eth_src,
15416                 (void *)&cmd_set_vxlan_eth_src_value,
15417                 (void *)&cmd_set_vxlan_eth_dst,
15418                 (void *)&cmd_set_vxlan_eth_dst_value,
15419                 NULL,
15420         },
15421 };
15422
15423 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15424         .f = cmd_set_vxlan_parsed,
15425         .data = NULL,
15426         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15427                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15428                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15429                 " eth-dst <eth-dst>",
15430         .tokens = {
15431                 (void *)&cmd_set_vxlan_set,
15432                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15433                 (void *)&cmd_set_vxlan_ip_version,
15434                 (void *)&cmd_set_vxlan_ip_version_value,
15435                 (void *)&cmd_set_vxlan_vni,
15436                 (void *)&cmd_set_vxlan_vni_value,
15437                 (void *)&cmd_set_vxlan_udp_src,
15438                 (void *)&cmd_set_vxlan_udp_src_value,
15439                 (void *)&cmd_set_vxlan_udp_dst,
15440                 (void *)&cmd_set_vxlan_udp_dst_value,
15441                 (void *)&cmd_set_vxlan_ip_tos,
15442                 (void *)&cmd_set_vxlan_ip_tos_value,
15443                 (void *)&cmd_set_vxlan_ip_ttl,
15444                 (void *)&cmd_set_vxlan_ip_ttl_value,
15445                 (void *)&cmd_set_vxlan_ip_src,
15446                 (void *)&cmd_set_vxlan_ip_src_value,
15447                 (void *)&cmd_set_vxlan_ip_dst,
15448                 (void *)&cmd_set_vxlan_ip_dst_value,
15449                 (void *)&cmd_set_vxlan_eth_src,
15450                 (void *)&cmd_set_vxlan_eth_src_value,
15451                 (void *)&cmd_set_vxlan_eth_dst,
15452                 (void *)&cmd_set_vxlan_eth_dst_value,
15453                 NULL,
15454         },
15455 };
15456
15457 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15458         .f = cmd_set_vxlan_parsed,
15459         .data = NULL,
15460         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15461                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15462                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15463                 " <eth-dst>",
15464         .tokens = {
15465                 (void *)&cmd_set_vxlan_set,
15466                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15467                 (void *)&cmd_set_vxlan_ip_version,
15468                 (void *)&cmd_set_vxlan_ip_version_value,
15469                 (void *)&cmd_set_vxlan_vni,
15470                 (void *)&cmd_set_vxlan_vni_value,
15471                 (void *)&cmd_set_vxlan_udp_src,
15472                 (void *)&cmd_set_vxlan_udp_src_value,
15473                 (void *)&cmd_set_vxlan_udp_dst,
15474                 (void *)&cmd_set_vxlan_udp_dst_value,
15475                 (void *)&cmd_set_vxlan_ip_src,
15476                 (void *)&cmd_set_vxlan_ip_src_value,
15477                 (void *)&cmd_set_vxlan_ip_dst,
15478                 (void *)&cmd_set_vxlan_ip_dst_value,
15479                 (void *)&cmd_set_vxlan_vlan,
15480                 (void *)&cmd_set_vxlan_vlan_value,
15481                 (void *)&cmd_set_vxlan_eth_src,
15482                 (void *)&cmd_set_vxlan_eth_src_value,
15483                 (void *)&cmd_set_vxlan_eth_dst,
15484                 (void *)&cmd_set_vxlan_eth_dst_value,
15485                 NULL,
15486         },
15487 };
15488
15489 /** Set NVGRE encapsulation details */
15490 struct cmd_set_nvgre_result {
15491         cmdline_fixed_string_t set;
15492         cmdline_fixed_string_t nvgre;
15493         cmdline_fixed_string_t pos_token;
15494         cmdline_fixed_string_t ip_version;
15495         uint32_t tni;
15496         cmdline_ipaddr_t ip_src;
15497         cmdline_ipaddr_t ip_dst;
15498         uint16_t tci;
15499         struct rte_ether_addr eth_src;
15500         struct rte_ether_addr eth_dst;
15501 };
15502
15503 cmdline_parse_token_string_t cmd_set_nvgre_set =
15504         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15505 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15506         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15507 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15508         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15509                                  "nvgre-with-vlan");
15510 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15511         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15512                                  "ip-version");
15513 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15514         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15515                                  "ipv4#ipv6");
15516 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15517         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15518                                  "tni");
15519 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15520         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15521 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15522         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15523                                  "ip-src");
15524 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15525         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15526 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15527         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15528                                  "ip-dst");
15529 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15530         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15531 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15532         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15533                                  "vlan-tci");
15534 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15535         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15536 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15537         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15538                                  "eth-src");
15539 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15540         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15541 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15542         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15543                                  "eth-dst");
15544 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15545         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15546
15547 static void cmd_set_nvgre_parsed(void *parsed_result,
15548         __attribute__((unused)) struct cmdline *cl,
15549         __attribute__((unused)) void *data)
15550 {
15551         struct cmd_set_nvgre_result *res = parsed_result;
15552         union {
15553                 uint32_t nvgre_tni;
15554                 uint8_t tni[4];
15555         } id = {
15556                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15557         };
15558
15559         if (strcmp(res->nvgre, "nvgre") == 0)
15560                 nvgre_encap_conf.select_vlan = 0;
15561         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15562                 nvgre_encap_conf.select_vlan = 1;
15563         if (strcmp(res->ip_version, "ipv4") == 0)
15564                 nvgre_encap_conf.select_ipv4 = 1;
15565         else if (strcmp(res->ip_version, "ipv6") == 0)
15566                 nvgre_encap_conf.select_ipv4 = 0;
15567         else
15568                 return;
15569         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15570         if (nvgre_encap_conf.select_ipv4) {
15571                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15572                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15573         } else {
15574                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15575                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15576         }
15577         if (nvgre_encap_conf.select_vlan)
15578                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15579         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15580                    RTE_ETHER_ADDR_LEN);
15581         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15582                    RTE_ETHER_ADDR_LEN);
15583 }
15584
15585 cmdline_parse_inst_t cmd_set_nvgre = {
15586         .f = cmd_set_nvgre_parsed,
15587         .data = NULL,
15588         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15589                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15590                 " eth-dst <eth-dst>",
15591         .tokens = {
15592                 (void *)&cmd_set_nvgre_set,
15593                 (void *)&cmd_set_nvgre_nvgre,
15594                 (void *)&cmd_set_nvgre_ip_version,
15595                 (void *)&cmd_set_nvgre_ip_version_value,
15596                 (void *)&cmd_set_nvgre_tni,
15597                 (void *)&cmd_set_nvgre_tni_value,
15598                 (void *)&cmd_set_nvgre_ip_src,
15599                 (void *)&cmd_set_nvgre_ip_src_value,
15600                 (void *)&cmd_set_nvgre_ip_dst,
15601                 (void *)&cmd_set_nvgre_ip_dst_value,
15602                 (void *)&cmd_set_nvgre_eth_src,
15603                 (void *)&cmd_set_nvgre_eth_src_value,
15604                 (void *)&cmd_set_nvgre_eth_dst,
15605                 (void *)&cmd_set_nvgre_eth_dst_value,
15606                 NULL,
15607         },
15608 };
15609
15610 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15611         .f = cmd_set_nvgre_parsed,
15612         .data = NULL,
15613         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15614                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15615                 " eth-src <eth-src> eth-dst <eth-dst>",
15616         .tokens = {
15617                 (void *)&cmd_set_nvgre_set,
15618                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15619                 (void *)&cmd_set_nvgre_ip_version,
15620                 (void *)&cmd_set_nvgre_ip_version_value,
15621                 (void *)&cmd_set_nvgre_tni,
15622                 (void *)&cmd_set_nvgre_tni_value,
15623                 (void *)&cmd_set_nvgre_ip_src,
15624                 (void *)&cmd_set_nvgre_ip_src_value,
15625                 (void *)&cmd_set_nvgre_ip_dst,
15626                 (void *)&cmd_set_nvgre_ip_dst_value,
15627                 (void *)&cmd_set_nvgre_vlan,
15628                 (void *)&cmd_set_nvgre_vlan_value,
15629                 (void *)&cmd_set_nvgre_eth_src,
15630                 (void *)&cmd_set_nvgre_eth_src_value,
15631                 (void *)&cmd_set_nvgre_eth_dst,
15632                 (void *)&cmd_set_nvgre_eth_dst_value,
15633                 NULL,
15634         },
15635 };
15636
15637 /** Set L2 encapsulation details */
15638 struct cmd_set_l2_encap_result {
15639         cmdline_fixed_string_t set;
15640         cmdline_fixed_string_t l2_encap;
15641         cmdline_fixed_string_t pos_token;
15642         cmdline_fixed_string_t ip_version;
15643         uint32_t vlan_present:1;
15644         uint16_t tci;
15645         struct rte_ether_addr eth_src;
15646         struct rte_ether_addr eth_dst;
15647 };
15648
15649 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15650         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15651 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15652         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15653 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15654         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15655                                  "l2_encap-with-vlan");
15656 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15657         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15658                                  "ip-version");
15659 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15660         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15661                                  "ipv4#ipv6");
15662 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15663         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15664                                  "vlan-tci");
15665 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15666         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15667 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15668         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15669                                  "eth-src");
15670 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15671         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15672 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15673         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15674                                  "eth-dst");
15675 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15676         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15677
15678 static void cmd_set_l2_encap_parsed(void *parsed_result,
15679         __attribute__((unused)) struct cmdline *cl,
15680         __attribute__((unused)) void *data)
15681 {
15682         struct cmd_set_l2_encap_result *res = parsed_result;
15683
15684         if (strcmp(res->l2_encap, "l2_encap") == 0)
15685                 l2_encap_conf.select_vlan = 0;
15686         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15687                 l2_encap_conf.select_vlan = 1;
15688         if (strcmp(res->ip_version, "ipv4") == 0)
15689                 l2_encap_conf.select_ipv4 = 1;
15690         else if (strcmp(res->ip_version, "ipv6") == 0)
15691                 l2_encap_conf.select_ipv4 = 0;
15692         else
15693                 return;
15694         if (l2_encap_conf.select_vlan)
15695                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15696         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15697                    RTE_ETHER_ADDR_LEN);
15698         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15699                    RTE_ETHER_ADDR_LEN);
15700 }
15701
15702 cmdline_parse_inst_t cmd_set_l2_encap = {
15703         .f = cmd_set_l2_encap_parsed,
15704         .data = NULL,
15705         .help_str = "set l2_encap ip-version ipv4|ipv6"
15706                 " eth-src <eth-src> eth-dst <eth-dst>",
15707         .tokens = {
15708                 (void *)&cmd_set_l2_encap_set,
15709                 (void *)&cmd_set_l2_encap_l2_encap,
15710                 (void *)&cmd_set_l2_encap_ip_version,
15711                 (void *)&cmd_set_l2_encap_ip_version_value,
15712                 (void *)&cmd_set_l2_encap_eth_src,
15713                 (void *)&cmd_set_l2_encap_eth_src_value,
15714                 (void *)&cmd_set_l2_encap_eth_dst,
15715                 (void *)&cmd_set_l2_encap_eth_dst_value,
15716                 NULL,
15717         },
15718 };
15719
15720 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15721         .f = cmd_set_l2_encap_parsed,
15722         .data = NULL,
15723         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15724                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15725         .tokens = {
15726                 (void *)&cmd_set_l2_encap_set,
15727                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15728                 (void *)&cmd_set_l2_encap_ip_version,
15729                 (void *)&cmd_set_l2_encap_ip_version_value,
15730                 (void *)&cmd_set_l2_encap_vlan,
15731                 (void *)&cmd_set_l2_encap_vlan_value,
15732                 (void *)&cmd_set_l2_encap_eth_src,
15733                 (void *)&cmd_set_l2_encap_eth_src_value,
15734                 (void *)&cmd_set_l2_encap_eth_dst,
15735                 (void *)&cmd_set_l2_encap_eth_dst_value,
15736                 NULL,
15737         },
15738 };
15739
15740 /** Set L2 decapsulation details */
15741 struct cmd_set_l2_decap_result {
15742         cmdline_fixed_string_t set;
15743         cmdline_fixed_string_t l2_decap;
15744         cmdline_fixed_string_t pos_token;
15745         uint32_t vlan_present:1;
15746 };
15747
15748 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15749         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15750 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15751         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15752                                  "l2_decap");
15753 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15754         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15755                                  "l2_decap-with-vlan");
15756
15757 static void cmd_set_l2_decap_parsed(void *parsed_result,
15758         __attribute__((unused)) struct cmdline *cl,
15759         __attribute__((unused)) void *data)
15760 {
15761         struct cmd_set_l2_decap_result *res = parsed_result;
15762
15763         if (strcmp(res->l2_decap, "l2_decap") == 0)
15764                 l2_decap_conf.select_vlan = 0;
15765         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15766                 l2_decap_conf.select_vlan = 1;
15767 }
15768
15769 cmdline_parse_inst_t cmd_set_l2_decap = {
15770         .f = cmd_set_l2_decap_parsed,
15771         .data = NULL,
15772         .help_str = "set l2_decap",
15773         .tokens = {
15774                 (void *)&cmd_set_l2_decap_set,
15775                 (void *)&cmd_set_l2_decap_l2_decap,
15776                 NULL,
15777         },
15778 };
15779
15780 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15781         .f = cmd_set_l2_decap_parsed,
15782         .data = NULL,
15783         .help_str = "set l2_decap-with-vlan",
15784         .tokens = {
15785                 (void *)&cmd_set_l2_decap_set,
15786                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15787                 NULL,
15788         },
15789 };
15790
15791 /** Set MPLSoGRE encapsulation details */
15792 struct cmd_set_mplsogre_encap_result {
15793         cmdline_fixed_string_t set;
15794         cmdline_fixed_string_t mplsogre;
15795         cmdline_fixed_string_t pos_token;
15796         cmdline_fixed_string_t ip_version;
15797         uint32_t vlan_present:1;
15798         uint32_t label;
15799         cmdline_ipaddr_t ip_src;
15800         cmdline_ipaddr_t ip_dst;
15801         uint16_t tci;
15802         struct rte_ether_addr eth_src;
15803         struct rte_ether_addr eth_dst;
15804 };
15805
15806 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15807         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15808                                  "set");
15809 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15810         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15811                                  "mplsogre_encap");
15812 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15813         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15814                                  mplsogre, "mplsogre_encap-with-vlan");
15815 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15816         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15817                                  pos_token, "ip-version");
15818 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15819         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15820                                  ip_version, "ipv4#ipv6");
15821 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15822         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15823                                  pos_token, "label");
15824 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15825         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15826                               UINT32);
15827 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15828         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15829                                  pos_token, "ip-src");
15830 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15831         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15832 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15833         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15834                                  pos_token, "ip-dst");
15835 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15836         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15837 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15838         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15839                                  pos_token, "vlan-tci");
15840 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15841         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15842                               UINT16);
15843 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15844         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15845                                  pos_token, "eth-src");
15846 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15847         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15848                                     eth_src);
15849 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15850         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15851                                  pos_token, "eth-dst");
15852 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15853         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15854                                     eth_dst);
15855
15856 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15857         __attribute__((unused)) struct cmdline *cl,
15858         __attribute__((unused)) void *data)
15859 {
15860         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15861         union {
15862                 uint32_t mplsogre_label;
15863                 uint8_t label[4];
15864         } id = {
15865                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15866         };
15867
15868         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15869                 mplsogre_encap_conf.select_vlan = 0;
15870         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15871                 mplsogre_encap_conf.select_vlan = 1;
15872         if (strcmp(res->ip_version, "ipv4") == 0)
15873                 mplsogre_encap_conf.select_ipv4 = 1;
15874         else if (strcmp(res->ip_version, "ipv6") == 0)
15875                 mplsogre_encap_conf.select_ipv4 = 0;
15876         else
15877                 return;
15878         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15879         if (mplsogre_encap_conf.select_ipv4) {
15880                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15881                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15882         } else {
15883                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15884                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15885         }
15886         if (mplsogre_encap_conf.select_vlan)
15887                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15888         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15889                    RTE_ETHER_ADDR_LEN);
15890         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15891                    RTE_ETHER_ADDR_LEN);
15892 }
15893
15894 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15895         .f = cmd_set_mplsogre_encap_parsed,
15896         .data = NULL,
15897         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15898                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15899                 " eth-dst <eth-dst>",
15900         .tokens = {
15901                 (void *)&cmd_set_mplsogre_encap_set,
15902                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15903                 (void *)&cmd_set_mplsogre_encap_ip_version,
15904                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15905                 (void *)&cmd_set_mplsogre_encap_label,
15906                 (void *)&cmd_set_mplsogre_encap_label_value,
15907                 (void *)&cmd_set_mplsogre_encap_ip_src,
15908                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15909                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15910                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15911                 (void *)&cmd_set_mplsogre_encap_eth_src,
15912                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15913                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15914                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15915                 NULL,
15916         },
15917 };
15918
15919 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15920         .f = cmd_set_mplsogre_encap_parsed,
15921         .data = NULL,
15922         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15923                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15924                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15925         .tokens = {
15926                 (void *)&cmd_set_mplsogre_encap_set,
15927                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15928                 (void *)&cmd_set_mplsogre_encap_ip_version,
15929                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15930                 (void *)&cmd_set_mplsogre_encap_label,
15931                 (void *)&cmd_set_mplsogre_encap_label_value,
15932                 (void *)&cmd_set_mplsogre_encap_ip_src,
15933                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15934                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15935                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15936                 (void *)&cmd_set_mplsogre_encap_vlan,
15937                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15938                 (void *)&cmd_set_mplsogre_encap_eth_src,
15939                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15940                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15941                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15942                 NULL,
15943         },
15944 };
15945
15946 /** Set MPLSoGRE decapsulation details */
15947 struct cmd_set_mplsogre_decap_result {
15948         cmdline_fixed_string_t set;
15949         cmdline_fixed_string_t mplsogre;
15950         cmdline_fixed_string_t pos_token;
15951         cmdline_fixed_string_t ip_version;
15952         uint32_t vlan_present:1;
15953 };
15954
15955 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15956         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15957                                  "set");
15958 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15959         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15960                                  "mplsogre_decap");
15961 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15962         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15963                                  mplsogre, "mplsogre_decap-with-vlan");
15964 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15965         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15966                                  pos_token, "ip-version");
15967 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15968         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15969                                  ip_version, "ipv4#ipv6");
15970
15971 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15972         __attribute__((unused)) struct cmdline *cl,
15973         __attribute__((unused)) void *data)
15974 {
15975         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15976
15977         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15978                 mplsogre_decap_conf.select_vlan = 0;
15979         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15980                 mplsogre_decap_conf.select_vlan = 1;
15981         if (strcmp(res->ip_version, "ipv4") == 0)
15982                 mplsogre_decap_conf.select_ipv4 = 1;
15983         else if (strcmp(res->ip_version, "ipv6") == 0)
15984                 mplsogre_decap_conf.select_ipv4 = 0;
15985 }
15986
15987 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15988         .f = cmd_set_mplsogre_decap_parsed,
15989         .data = NULL,
15990         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15991         .tokens = {
15992                 (void *)&cmd_set_mplsogre_decap_set,
15993                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15994                 (void *)&cmd_set_mplsogre_decap_ip_version,
15995                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15996                 NULL,
15997         },
15998 };
15999
16000 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16001         .f = cmd_set_mplsogre_decap_parsed,
16002         .data = NULL,
16003         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16004         .tokens = {
16005                 (void *)&cmd_set_mplsogre_decap_set,
16006                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16007                 (void *)&cmd_set_mplsogre_decap_ip_version,
16008                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16009                 NULL,
16010         },
16011 };
16012
16013 /** Set MPLSoUDP encapsulation details */
16014 struct cmd_set_mplsoudp_encap_result {
16015         cmdline_fixed_string_t set;
16016         cmdline_fixed_string_t mplsoudp;
16017         cmdline_fixed_string_t pos_token;
16018         cmdline_fixed_string_t ip_version;
16019         uint32_t vlan_present:1;
16020         uint32_t label;
16021         uint16_t udp_src;
16022         uint16_t udp_dst;
16023         cmdline_ipaddr_t ip_src;
16024         cmdline_ipaddr_t ip_dst;
16025         uint16_t tci;
16026         struct rte_ether_addr eth_src;
16027         struct rte_ether_addr eth_dst;
16028 };
16029
16030 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16031         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16032                                  "set");
16033 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16034         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16035                                  "mplsoudp_encap");
16036 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16037         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16038                                  mplsoudp, "mplsoudp_encap-with-vlan");
16039 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16040         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16041                                  pos_token, "ip-version");
16042 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16043         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16044                                  ip_version, "ipv4#ipv6");
16045 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16046         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16047                                  pos_token, "label");
16048 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16049         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16050                               UINT32);
16051 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16052         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16053                                  pos_token, "udp-src");
16054 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16055         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16056                               UINT16);
16057 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16058         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16059                                  pos_token, "udp-dst");
16060 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16061         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16062                               UINT16);
16063 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16064         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16065                                  pos_token, "ip-src");
16066 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16067         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16068 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16069         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16070                                  pos_token, "ip-dst");
16071 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16072         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16073 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16074         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16075                                  pos_token, "vlan-tci");
16076 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16077         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16078                               UINT16);
16079 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16080         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16081                                  pos_token, "eth-src");
16082 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16083         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16084                                     eth_src);
16085 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16086         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16087                                  pos_token, "eth-dst");
16088 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16089         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16090                                     eth_dst);
16091
16092 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16093         __attribute__((unused)) struct cmdline *cl,
16094         __attribute__((unused)) void *data)
16095 {
16096         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16097         union {
16098                 uint32_t mplsoudp_label;
16099                 uint8_t label[4];
16100         } id = {
16101                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16102         };
16103
16104         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16105                 mplsoudp_encap_conf.select_vlan = 0;
16106         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16107                 mplsoudp_encap_conf.select_vlan = 1;
16108         if (strcmp(res->ip_version, "ipv4") == 0)
16109                 mplsoudp_encap_conf.select_ipv4 = 1;
16110         else if (strcmp(res->ip_version, "ipv6") == 0)
16111                 mplsoudp_encap_conf.select_ipv4 = 0;
16112         else
16113                 return;
16114         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16115         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16116         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16117         if (mplsoudp_encap_conf.select_ipv4) {
16118                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16119                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16120         } else {
16121                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16122                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16123         }
16124         if (mplsoudp_encap_conf.select_vlan)
16125                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16126         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16127                    RTE_ETHER_ADDR_LEN);
16128         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16129                    RTE_ETHER_ADDR_LEN);
16130 }
16131
16132 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16133         .f = cmd_set_mplsoudp_encap_parsed,
16134         .data = NULL,
16135         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16136                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16137                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16138         .tokens = {
16139                 (void *)&cmd_set_mplsoudp_encap_set,
16140                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16141                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16142                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16143                 (void *)&cmd_set_mplsoudp_encap_label,
16144                 (void *)&cmd_set_mplsoudp_encap_label_value,
16145                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16146                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16147                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16148                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16149                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16150                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16151                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16152                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16153                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16154                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16155                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16156                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16157                 NULL,
16158         },
16159 };
16160
16161 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16162         .f = cmd_set_mplsoudp_encap_parsed,
16163         .data = NULL,
16164         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16165                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16166                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16167                 " eth-src <eth-src> eth-dst <eth-dst>",
16168         .tokens = {
16169                 (void *)&cmd_set_mplsoudp_encap_set,
16170                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16171                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16172                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16173                 (void *)&cmd_set_mplsoudp_encap_label,
16174                 (void *)&cmd_set_mplsoudp_encap_label_value,
16175                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16176                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16177                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16178                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16179                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16180                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16181                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16182                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16183                 (void *)&cmd_set_mplsoudp_encap_vlan,
16184                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16185                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16186                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16187                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16188                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16189                 NULL,
16190         },
16191 };
16192
16193 /** Set MPLSoUDP decapsulation details */
16194 struct cmd_set_mplsoudp_decap_result {
16195         cmdline_fixed_string_t set;
16196         cmdline_fixed_string_t mplsoudp;
16197         cmdline_fixed_string_t pos_token;
16198         cmdline_fixed_string_t ip_version;
16199         uint32_t vlan_present:1;
16200 };
16201
16202 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16203         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16204                                  "set");
16205 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16206         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16207                                  "mplsoudp_decap");
16208 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16209         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16210                                  mplsoudp, "mplsoudp_decap-with-vlan");
16211 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16212         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16213                                  pos_token, "ip-version");
16214 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16215         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16216                                  ip_version, "ipv4#ipv6");
16217
16218 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16219         __attribute__((unused)) struct cmdline *cl,
16220         __attribute__((unused)) void *data)
16221 {
16222         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16223
16224         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16225                 mplsoudp_decap_conf.select_vlan = 0;
16226         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16227                 mplsoudp_decap_conf.select_vlan = 1;
16228         if (strcmp(res->ip_version, "ipv4") == 0)
16229                 mplsoudp_decap_conf.select_ipv4 = 1;
16230         else if (strcmp(res->ip_version, "ipv6") == 0)
16231                 mplsoudp_decap_conf.select_ipv4 = 0;
16232 }
16233
16234 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16235         .f = cmd_set_mplsoudp_decap_parsed,
16236         .data = NULL,
16237         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16238         .tokens = {
16239                 (void *)&cmd_set_mplsoudp_decap_set,
16240                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16241                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16242                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16243                 NULL,
16244         },
16245 };
16246
16247 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16248         .f = cmd_set_mplsoudp_decap_parsed,
16249         .data = NULL,
16250         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16251         .tokens = {
16252                 (void *)&cmd_set_mplsoudp_decap_set,
16253                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16254                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16255                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16256                 NULL,
16257         },
16258 };
16259
16260 /* Strict link priority scheduling mode setting */
16261 static void
16262 cmd_strict_link_prio_parsed(
16263         void *parsed_result,
16264         __attribute__((unused)) struct cmdline *cl,
16265         __attribute__((unused)) void *data)
16266 {
16267         struct cmd_vf_tc_bw_result *res = parsed_result;
16268         int ret = -ENOTSUP;
16269
16270         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16271                 return;
16272
16273 #ifdef RTE_LIBRTE_I40E_PMD
16274         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16275 #endif
16276
16277         switch (ret) {
16278         case 0:
16279                 break;
16280         case -EINVAL:
16281                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16282                 break;
16283         case -ENODEV:
16284                 printf("invalid port_id %d\n", res->port_id);
16285                 break;
16286         case -ENOTSUP:
16287                 printf("function not implemented\n");
16288                 break;
16289         default:
16290                 printf("programming error: (%s)\n", strerror(-ret));
16291         }
16292 }
16293
16294 cmdline_parse_inst_t cmd_strict_link_prio = {
16295         .f = cmd_strict_link_prio_parsed,
16296         .data = NULL,
16297         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16298         .tokens = {
16299                 (void *)&cmd_vf_tc_bw_set,
16300                 (void *)&cmd_vf_tc_bw_tx,
16301                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16302                 (void *)&cmd_vf_tc_bw_port_id,
16303                 (void *)&cmd_vf_tc_bw_tc_map,
16304                 NULL,
16305         },
16306 };
16307
16308 /* Load dynamic device personalization*/
16309 struct cmd_ddp_add_result {
16310         cmdline_fixed_string_t ddp;
16311         cmdline_fixed_string_t add;
16312         portid_t port_id;
16313         char filepath[];
16314 };
16315
16316 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16317         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16318 cmdline_parse_token_string_t cmd_ddp_add_add =
16319         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16320 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16321         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16322 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16323         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16324
16325 static void
16326 cmd_ddp_add_parsed(
16327         void *parsed_result,
16328         __attribute__((unused)) struct cmdline *cl,
16329         __attribute__((unused)) void *data)
16330 {
16331         struct cmd_ddp_add_result *res = parsed_result;
16332         uint8_t *buff;
16333         uint32_t size;
16334         char *filepath;
16335         char *file_fld[2];
16336         int file_num;
16337         int ret = -ENOTSUP;
16338
16339         if (!all_ports_stopped()) {
16340                 printf("Please stop all ports first\n");
16341                 return;
16342         }
16343
16344         filepath = strdup(res->filepath);
16345         if (filepath == NULL) {
16346                 printf("Failed to allocate memory\n");
16347                 return;
16348         }
16349         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16350
16351         buff = open_file(file_fld[0], &size);
16352         if (!buff) {
16353                 free((void *)filepath);
16354                 return;
16355         }
16356
16357 #ifdef RTE_LIBRTE_I40E_PMD
16358         if (ret == -ENOTSUP)
16359                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16360                                                buff, size,
16361                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16362 #endif
16363
16364         if (ret == -EEXIST)
16365                 printf("Profile has already existed.\n");
16366         else if (ret < 0)
16367                 printf("Failed to load profile.\n");
16368         else if (file_num == 2)
16369                 save_file(file_fld[1], buff, size);
16370
16371         close_file(buff);
16372         free((void *)filepath);
16373 }
16374
16375 cmdline_parse_inst_t cmd_ddp_add = {
16376         .f = cmd_ddp_add_parsed,
16377         .data = NULL,
16378         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16379         .tokens = {
16380                 (void *)&cmd_ddp_add_ddp,
16381                 (void *)&cmd_ddp_add_add,
16382                 (void *)&cmd_ddp_add_port_id,
16383                 (void *)&cmd_ddp_add_filepath,
16384                 NULL,
16385         },
16386 };
16387
16388 /* Delete dynamic device personalization*/
16389 struct cmd_ddp_del_result {
16390         cmdline_fixed_string_t ddp;
16391         cmdline_fixed_string_t del;
16392         portid_t port_id;
16393         char filepath[];
16394 };
16395
16396 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16397         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16398 cmdline_parse_token_string_t cmd_ddp_del_del =
16399         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16400 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16401         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16402 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16403         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16404
16405 static void
16406 cmd_ddp_del_parsed(
16407         void *parsed_result,
16408         __attribute__((unused)) struct cmdline *cl,
16409         __attribute__((unused)) void *data)
16410 {
16411         struct cmd_ddp_del_result *res = parsed_result;
16412         uint8_t *buff;
16413         uint32_t size;
16414         int ret = -ENOTSUP;
16415
16416         if (!all_ports_stopped()) {
16417                 printf("Please stop all ports first\n");
16418                 return;
16419         }
16420
16421         buff = open_file(res->filepath, &size);
16422         if (!buff)
16423                 return;
16424
16425 #ifdef RTE_LIBRTE_I40E_PMD
16426         if (ret == -ENOTSUP)
16427                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16428                                                buff, size,
16429                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16430 #endif
16431
16432         if (ret == -EACCES)
16433                 printf("Profile does not exist.\n");
16434         else if (ret < 0)
16435                 printf("Failed to delete profile.\n");
16436
16437         close_file(buff);
16438 }
16439
16440 cmdline_parse_inst_t cmd_ddp_del = {
16441         .f = cmd_ddp_del_parsed,
16442         .data = NULL,
16443         .help_str = "ddp del <port_id> <backup_profile_path>",
16444         .tokens = {
16445                 (void *)&cmd_ddp_del_ddp,
16446                 (void *)&cmd_ddp_del_del,
16447                 (void *)&cmd_ddp_del_port_id,
16448                 (void *)&cmd_ddp_del_filepath,
16449                 NULL,
16450         },
16451 };
16452
16453 /* Get dynamic device personalization profile info */
16454 struct cmd_ddp_info_result {
16455         cmdline_fixed_string_t ddp;
16456         cmdline_fixed_string_t get;
16457         cmdline_fixed_string_t info;
16458         char filepath[];
16459 };
16460
16461 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16462         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16463 cmdline_parse_token_string_t cmd_ddp_info_get =
16464         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16465 cmdline_parse_token_string_t cmd_ddp_info_info =
16466         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16467 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16468         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16469
16470 static void
16471 cmd_ddp_info_parsed(
16472         void *parsed_result,
16473         __attribute__((unused)) struct cmdline *cl,
16474         __attribute__((unused)) void *data)
16475 {
16476         struct cmd_ddp_info_result *res = parsed_result;
16477         uint8_t *pkg;
16478         uint32_t pkg_size;
16479         int ret = -ENOTSUP;
16480 #ifdef RTE_LIBRTE_I40E_PMD
16481         uint32_t i, j, n;
16482         uint8_t *buff;
16483         uint32_t buff_size = 0;
16484         struct rte_pmd_i40e_profile_info info;
16485         uint32_t dev_num = 0;
16486         struct rte_pmd_i40e_ddp_device_id *devs;
16487         uint32_t proto_num = 0;
16488         struct rte_pmd_i40e_proto_info *proto = NULL;
16489         uint32_t pctype_num = 0;
16490         struct rte_pmd_i40e_ptype_info *pctype;
16491         uint32_t ptype_num = 0;
16492         struct rte_pmd_i40e_ptype_info *ptype;
16493         uint8_t proto_id;
16494
16495 #endif
16496
16497         pkg = open_file(res->filepath, &pkg_size);
16498         if (!pkg)
16499                 return;
16500
16501 #ifdef RTE_LIBRTE_I40E_PMD
16502         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16503                                 (uint8_t *)&info, sizeof(info),
16504                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16505         if (!ret) {
16506                 printf("Global Track id:       0x%x\n", info.track_id);
16507                 printf("Global Version:        %d.%d.%d.%d\n",
16508                         info.version.major,
16509                         info.version.minor,
16510                         info.version.update,
16511                         info.version.draft);
16512                 printf("Global Package name:   %s\n\n", info.name);
16513         }
16514
16515         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16516                                 (uint8_t *)&info, sizeof(info),
16517                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16518         if (!ret) {
16519                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16520                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16521                         info.version.major,
16522                         info.version.minor,
16523                         info.version.update,
16524                         info.version.draft);
16525                 printf("i40e Profile name:     %s\n\n", info.name);
16526         }
16527
16528         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16529                                 (uint8_t *)&buff_size, sizeof(buff_size),
16530                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16531         if (!ret && buff_size) {
16532                 buff = (uint8_t *)malloc(buff_size);
16533                 if (buff) {
16534                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16535                                                 buff, buff_size,
16536                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16537                         if (!ret)
16538                                 printf("Package Notes:\n%s\n\n", buff);
16539                         free(buff);
16540                 }
16541         }
16542
16543         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16544                                 (uint8_t *)&dev_num, sizeof(dev_num),
16545                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16546         if (!ret && dev_num) {
16547                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16548                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16549                 if (devs) {
16550                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16551                                                 (uint8_t *)devs, buff_size,
16552                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16553                         if (!ret) {
16554                                 printf("List of supported devices:\n");
16555                                 for (i = 0; i < dev_num; i++) {
16556                                         printf("  %04X:%04X %04X:%04X\n",
16557                                                 devs[i].vendor_dev_id >> 16,
16558                                                 devs[i].vendor_dev_id & 0xFFFF,
16559                                                 devs[i].sub_vendor_dev_id >> 16,
16560                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16561                                 }
16562                                 printf("\n");
16563                         }
16564                         free(devs);
16565                 }
16566         }
16567
16568         /* get information about protocols and packet types */
16569         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16570                 (uint8_t *)&proto_num, sizeof(proto_num),
16571                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16572         if (ret || !proto_num)
16573                 goto no_print_return;
16574
16575         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16576         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16577         if (!proto)
16578                 goto no_print_return;
16579
16580         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16581                                         buff_size,
16582                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16583         if (!ret) {
16584                 printf("List of used protocols:\n");
16585                 for (i = 0; i < proto_num; i++)
16586                         printf("  %2u: %s\n", proto[i].proto_id,
16587                                proto[i].name);
16588                 printf("\n");
16589         }
16590         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16591                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16592                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16593         if (ret || !pctype_num)
16594                 goto no_print_pctypes;
16595
16596         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16597         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16598         if (!pctype)
16599                 goto no_print_pctypes;
16600
16601         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16602                                         buff_size,
16603                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16604         if (ret) {
16605                 free(pctype);
16606                 goto no_print_pctypes;
16607         }
16608
16609         printf("List of defined packet classification types:\n");
16610         for (i = 0; i < pctype_num; i++) {
16611                 printf("  %2u:", pctype[i].ptype_id);
16612                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16613                         proto_id = pctype[i].protocols[j];
16614                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16615                                 for (n = 0; n < proto_num; n++) {
16616                                         if (proto[n].proto_id == proto_id) {
16617                                                 printf(" %s", proto[n].name);
16618                                                 break;
16619                                         }
16620                                 }
16621                         }
16622                 }
16623                 printf("\n");
16624         }
16625         printf("\n");
16626         free(pctype);
16627
16628 no_print_pctypes:
16629
16630         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16631                                         sizeof(ptype_num),
16632                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16633         if (ret || !ptype_num)
16634                 goto no_print_return;
16635
16636         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16637         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16638         if (!ptype)
16639                 goto no_print_return;
16640
16641         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16642                                         buff_size,
16643                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16644         if (ret) {
16645                 free(ptype);
16646                 goto no_print_return;
16647         }
16648         printf("List of defined packet types:\n");
16649         for (i = 0; i < ptype_num; i++) {
16650                 printf("  %2u:", ptype[i].ptype_id);
16651                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16652                         proto_id = ptype[i].protocols[j];
16653                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16654                                 for (n = 0; n < proto_num; n++) {
16655                                         if (proto[n].proto_id == proto_id) {
16656                                                 printf(" %s", proto[n].name);
16657                                                 break;
16658                                         }
16659                                 }
16660                         }
16661                 }
16662                 printf("\n");
16663         }
16664         free(ptype);
16665         printf("\n");
16666
16667         ret = 0;
16668 no_print_return:
16669         if (proto)
16670                 free(proto);
16671 #endif
16672         if (ret == -ENOTSUP)
16673                 printf("Function not supported in PMD driver\n");
16674         close_file(pkg);
16675 }
16676
16677 cmdline_parse_inst_t cmd_ddp_get_info = {
16678         .f = cmd_ddp_info_parsed,
16679         .data = NULL,
16680         .help_str = "ddp get info <profile_path>",
16681         .tokens = {
16682                 (void *)&cmd_ddp_info_ddp,
16683                 (void *)&cmd_ddp_info_get,
16684                 (void *)&cmd_ddp_info_info,
16685                 (void *)&cmd_ddp_info_filepath,
16686                 NULL,
16687         },
16688 };
16689
16690 /* Get dynamic device personalization profile info list*/
16691 #define PROFILE_INFO_SIZE 48
16692 #define MAX_PROFILE_NUM 16
16693
16694 struct cmd_ddp_get_list_result {
16695         cmdline_fixed_string_t ddp;
16696         cmdline_fixed_string_t get;
16697         cmdline_fixed_string_t list;
16698         portid_t port_id;
16699 };
16700
16701 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16702         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16703 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16704         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16705 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16706         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16707 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16708         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16709
16710 static void
16711 cmd_ddp_get_list_parsed(
16712         __attribute__((unused)) void *parsed_result,
16713         __attribute__((unused)) struct cmdline *cl,
16714         __attribute__((unused)) void *data)
16715 {
16716 #ifdef RTE_LIBRTE_I40E_PMD
16717         struct cmd_ddp_get_list_result *res = parsed_result;
16718         struct rte_pmd_i40e_profile_list *p_list;
16719         struct rte_pmd_i40e_profile_info *p_info;
16720         uint32_t p_num;
16721         uint32_t size;
16722         uint32_t i;
16723 #endif
16724         int ret = -ENOTSUP;
16725
16726 #ifdef RTE_LIBRTE_I40E_PMD
16727         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16728         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16729         if (!p_list)
16730                 printf("%s: Failed to malloc buffer\n", __func__);
16731
16732         if (ret == -ENOTSUP)
16733                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16734                                                 (uint8_t *)p_list, size);
16735
16736         if (!ret) {
16737                 p_num = p_list->p_count;
16738                 printf("Profile number is: %d\n\n", p_num);
16739
16740                 for (i = 0; i < p_num; i++) {
16741                         p_info = &p_list->p_info[i];
16742                         printf("Profile %d:\n", i);
16743                         printf("Track id:     0x%x\n", p_info->track_id);
16744                         printf("Version:      %d.%d.%d.%d\n",
16745                                p_info->version.major,
16746                                p_info->version.minor,
16747                                p_info->version.update,
16748                                p_info->version.draft);
16749                         printf("Profile name: %s\n\n", p_info->name);
16750                 }
16751         }
16752
16753         free(p_list);
16754 #endif
16755
16756         if (ret < 0)
16757                 printf("Failed to get ddp list\n");
16758 }
16759
16760 cmdline_parse_inst_t cmd_ddp_get_list = {
16761         .f = cmd_ddp_get_list_parsed,
16762         .data = NULL,
16763         .help_str = "ddp get list <port_id>",
16764         .tokens = {
16765                 (void *)&cmd_ddp_get_list_ddp,
16766                 (void *)&cmd_ddp_get_list_get,
16767                 (void *)&cmd_ddp_get_list_list,
16768                 (void *)&cmd_ddp_get_list_port_id,
16769                 NULL,
16770         },
16771 };
16772
16773 /* Configure input set */
16774 struct cmd_cfg_input_set_result {
16775         cmdline_fixed_string_t port;
16776         cmdline_fixed_string_t cfg;
16777         portid_t port_id;
16778         cmdline_fixed_string_t pctype;
16779         uint8_t pctype_id;
16780         cmdline_fixed_string_t inset_type;
16781         cmdline_fixed_string_t opt;
16782         cmdline_fixed_string_t field;
16783         uint8_t field_idx;
16784 };
16785
16786 static void
16787 cmd_cfg_input_set_parsed(
16788         __attribute__((unused)) void *parsed_result,
16789         __attribute__((unused)) struct cmdline *cl,
16790         __attribute__((unused)) void *data)
16791 {
16792 #ifdef RTE_LIBRTE_I40E_PMD
16793         struct cmd_cfg_input_set_result *res = parsed_result;
16794         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16795         struct rte_pmd_i40e_inset inset;
16796 #endif
16797         int ret = -ENOTSUP;
16798
16799         if (!all_ports_stopped()) {
16800                 printf("Please stop all ports first\n");
16801                 return;
16802         }
16803
16804 #ifdef RTE_LIBRTE_I40E_PMD
16805         if (!strcmp(res->inset_type, "hash_inset"))
16806                 inset_type = INSET_HASH;
16807         else if (!strcmp(res->inset_type, "fdir_inset"))
16808                 inset_type = INSET_FDIR;
16809         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16810                 inset_type = INSET_FDIR_FLX;
16811         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16812                                      &inset, inset_type);
16813         if (ret) {
16814                 printf("Failed to get input set.\n");
16815                 return;
16816         }
16817
16818         if (!strcmp(res->opt, "get")) {
16819                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16820                                                    res->field_idx);
16821                 if (ret)
16822                         printf("Field index %d is enabled.\n", res->field_idx);
16823                 else
16824                         printf("Field index %d is disabled.\n", res->field_idx);
16825                 return;
16826         } else if (!strcmp(res->opt, "set"))
16827                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16828                                                    res->field_idx);
16829         else if (!strcmp(res->opt, "clear"))
16830                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16831                                                      res->field_idx);
16832         if (ret) {
16833                 printf("Failed to configure input set field.\n");
16834                 return;
16835         }
16836
16837         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16838                                      &inset, inset_type);
16839         if (ret) {
16840                 printf("Failed to set input set.\n");
16841                 return;
16842         }
16843 #endif
16844
16845         if (ret == -ENOTSUP)
16846                 printf("Function not supported\n");
16847 }
16848
16849 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16850         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16851                                  port, "port");
16852 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16853         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16854                                  cfg, "config");
16855 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16856         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16857                               port_id, UINT16);
16858 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16859         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16860                                  pctype, "pctype");
16861 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16862         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16863                               pctype_id, UINT8);
16864 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16865         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16866                                  inset_type,
16867                                  "hash_inset#fdir_inset#fdir_flx_inset");
16868 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16869         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16870                                  opt, "get#set#clear");
16871 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16872         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16873                                  field, "field");
16874 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16875         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16876                               field_idx, UINT8);
16877
16878 cmdline_parse_inst_t cmd_cfg_input_set = {
16879         .f = cmd_cfg_input_set_parsed,
16880         .data = NULL,
16881         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16882                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16883         .tokens = {
16884                 (void *)&cmd_cfg_input_set_port,
16885                 (void *)&cmd_cfg_input_set_cfg,
16886                 (void *)&cmd_cfg_input_set_port_id,
16887                 (void *)&cmd_cfg_input_set_pctype,
16888                 (void *)&cmd_cfg_input_set_pctype_id,
16889                 (void *)&cmd_cfg_input_set_inset_type,
16890                 (void *)&cmd_cfg_input_set_opt,
16891                 (void *)&cmd_cfg_input_set_field,
16892                 (void *)&cmd_cfg_input_set_field_idx,
16893                 NULL,
16894         },
16895 };
16896
16897 /* Clear input set */
16898 struct cmd_clear_input_set_result {
16899         cmdline_fixed_string_t port;
16900         cmdline_fixed_string_t cfg;
16901         portid_t port_id;
16902         cmdline_fixed_string_t pctype;
16903         uint8_t pctype_id;
16904         cmdline_fixed_string_t inset_type;
16905         cmdline_fixed_string_t clear;
16906         cmdline_fixed_string_t all;
16907 };
16908
16909 static void
16910 cmd_clear_input_set_parsed(
16911         __attribute__((unused)) void *parsed_result,
16912         __attribute__((unused)) struct cmdline *cl,
16913         __attribute__((unused)) void *data)
16914 {
16915 #ifdef RTE_LIBRTE_I40E_PMD
16916         struct cmd_clear_input_set_result *res = parsed_result;
16917         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16918         struct rte_pmd_i40e_inset inset;
16919 #endif
16920         int ret = -ENOTSUP;
16921
16922         if (!all_ports_stopped()) {
16923                 printf("Please stop all ports first\n");
16924                 return;
16925         }
16926
16927 #ifdef RTE_LIBRTE_I40E_PMD
16928         if (!strcmp(res->inset_type, "hash_inset"))
16929                 inset_type = INSET_HASH;
16930         else if (!strcmp(res->inset_type, "fdir_inset"))
16931                 inset_type = INSET_FDIR;
16932         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16933                 inset_type = INSET_FDIR_FLX;
16934
16935         memset(&inset, 0, sizeof(inset));
16936
16937         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16938                                      &inset, inset_type);
16939         if (ret) {
16940                 printf("Failed to clear input set.\n");
16941                 return;
16942         }
16943
16944 #endif
16945
16946         if (ret == -ENOTSUP)
16947                 printf("Function not supported\n");
16948 }
16949
16950 cmdline_parse_token_string_t cmd_clear_input_set_port =
16951         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16952                                  port, "port");
16953 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16954         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16955                                  cfg, "config");
16956 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16957         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16958                               port_id, UINT16);
16959 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16960         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16961                                  pctype, "pctype");
16962 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16963         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16964                               pctype_id, UINT8);
16965 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16966         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16967                                  inset_type,
16968                                  "hash_inset#fdir_inset#fdir_flx_inset");
16969 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16970         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16971                                  clear, "clear");
16972 cmdline_parse_token_string_t cmd_clear_input_set_all =
16973         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16974                                  all, "all");
16975
16976 cmdline_parse_inst_t cmd_clear_input_set = {
16977         .f = cmd_clear_input_set_parsed,
16978         .data = NULL,
16979         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16980                     "fdir_inset|fdir_flx_inset clear all",
16981         .tokens = {
16982                 (void *)&cmd_clear_input_set_port,
16983                 (void *)&cmd_clear_input_set_cfg,
16984                 (void *)&cmd_clear_input_set_port_id,
16985                 (void *)&cmd_clear_input_set_pctype,
16986                 (void *)&cmd_clear_input_set_pctype_id,
16987                 (void *)&cmd_clear_input_set_inset_type,
16988                 (void *)&cmd_clear_input_set_clear,
16989                 (void *)&cmd_clear_input_set_all,
16990                 NULL,
16991         },
16992 };
16993
16994 /* show vf stats */
16995
16996 /* Common result structure for show vf stats */
16997 struct cmd_show_vf_stats_result {
16998         cmdline_fixed_string_t show;
16999         cmdline_fixed_string_t vf;
17000         cmdline_fixed_string_t stats;
17001         portid_t port_id;
17002         uint16_t vf_id;
17003 };
17004
17005 /* Common CLI fields show vf stats*/
17006 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17007         TOKEN_STRING_INITIALIZER
17008                 (struct cmd_show_vf_stats_result,
17009                  show, "show");
17010 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17011         TOKEN_STRING_INITIALIZER
17012                 (struct cmd_show_vf_stats_result,
17013                  vf, "vf");
17014 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17015         TOKEN_STRING_INITIALIZER
17016                 (struct cmd_show_vf_stats_result,
17017                  stats, "stats");
17018 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17019         TOKEN_NUM_INITIALIZER
17020                 (struct cmd_show_vf_stats_result,
17021                  port_id, UINT16);
17022 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17023         TOKEN_NUM_INITIALIZER
17024                 (struct cmd_show_vf_stats_result,
17025                  vf_id, UINT16);
17026
17027 static void
17028 cmd_show_vf_stats_parsed(
17029         void *parsed_result,
17030         __attribute__((unused)) struct cmdline *cl,
17031         __attribute__((unused)) void *data)
17032 {
17033         struct cmd_show_vf_stats_result *res = parsed_result;
17034         struct rte_eth_stats stats;
17035         int ret = -ENOTSUP;
17036         static const char *nic_stats_border = "########################";
17037
17038         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17039                 return;
17040
17041         memset(&stats, 0, sizeof(stats));
17042
17043 #ifdef RTE_LIBRTE_I40E_PMD
17044         if (ret == -ENOTSUP)
17045                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17046                                                 res->vf_id,
17047                                                 &stats);
17048 #endif
17049 #ifdef RTE_LIBRTE_BNXT_PMD
17050         if (ret == -ENOTSUP)
17051                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17052                                                 res->vf_id,
17053                                                 &stats);
17054 #endif
17055
17056         switch (ret) {
17057         case 0:
17058                 break;
17059         case -EINVAL:
17060                 printf("invalid vf_id %d\n", res->vf_id);
17061                 break;
17062         case -ENODEV:
17063                 printf("invalid port_id %d\n", res->port_id);
17064                 break;
17065         case -ENOTSUP:
17066                 printf("function not implemented\n");
17067                 break;
17068         default:
17069                 printf("programming error: (%s)\n", strerror(-ret));
17070         }
17071
17072         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17073                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17074
17075         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17076                "%-"PRIu64"\n",
17077                stats.ipackets, stats.imissed, stats.ibytes);
17078         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17079         printf("  RX-nombuf:  %-10"PRIu64"\n",
17080                stats.rx_nombuf);
17081         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17082                "%-"PRIu64"\n",
17083                stats.opackets, stats.oerrors, stats.obytes);
17084
17085         printf("  %s############################%s\n",
17086                                nic_stats_border, nic_stats_border);
17087 }
17088
17089 cmdline_parse_inst_t cmd_show_vf_stats = {
17090         .f = cmd_show_vf_stats_parsed,
17091         .data = NULL,
17092         .help_str = "show vf stats <port_id> <vf_id>",
17093         .tokens = {
17094                 (void *)&cmd_show_vf_stats_show,
17095                 (void *)&cmd_show_vf_stats_vf,
17096                 (void *)&cmd_show_vf_stats_stats,
17097                 (void *)&cmd_show_vf_stats_port_id,
17098                 (void *)&cmd_show_vf_stats_vf_id,
17099                 NULL,
17100         },
17101 };
17102
17103 /* clear vf stats */
17104
17105 /* Common result structure for clear vf stats */
17106 struct cmd_clear_vf_stats_result {
17107         cmdline_fixed_string_t clear;
17108         cmdline_fixed_string_t vf;
17109         cmdline_fixed_string_t stats;
17110         portid_t port_id;
17111         uint16_t vf_id;
17112 };
17113
17114 /* Common CLI fields clear vf stats*/
17115 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17116         TOKEN_STRING_INITIALIZER
17117                 (struct cmd_clear_vf_stats_result,
17118                  clear, "clear");
17119 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17120         TOKEN_STRING_INITIALIZER
17121                 (struct cmd_clear_vf_stats_result,
17122                  vf, "vf");
17123 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17124         TOKEN_STRING_INITIALIZER
17125                 (struct cmd_clear_vf_stats_result,
17126                  stats, "stats");
17127 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17128         TOKEN_NUM_INITIALIZER
17129                 (struct cmd_clear_vf_stats_result,
17130                  port_id, UINT16);
17131 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17132         TOKEN_NUM_INITIALIZER
17133                 (struct cmd_clear_vf_stats_result,
17134                  vf_id, UINT16);
17135
17136 static void
17137 cmd_clear_vf_stats_parsed(
17138         void *parsed_result,
17139         __attribute__((unused)) struct cmdline *cl,
17140         __attribute__((unused)) void *data)
17141 {
17142         struct cmd_clear_vf_stats_result *res = parsed_result;
17143         int ret = -ENOTSUP;
17144
17145         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17146                 return;
17147
17148 #ifdef RTE_LIBRTE_I40E_PMD
17149         if (ret == -ENOTSUP)
17150                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17151                                                   res->vf_id);
17152 #endif
17153 #ifdef RTE_LIBRTE_BNXT_PMD
17154         if (ret == -ENOTSUP)
17155                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17156                                                   res->vf_id);
17157 #endif
17158
17159         switch (ret) {
17160         case 0:
17161                 break;
17162         case -EINVAL:
17163                 printf("invalid vf_id %d\n", res->vf_id);
17164                 break;
17165         case -ENODEV:
17166                 printf("invalid port_id %d\n", res->port_id);
17167                 break;
17168         case -ENOTSUP:
17169                 printf("function not implemented\n");
17170                 break;
17171         default:
17172                 printf("programming error: (%s)\n", strerror(-ret));
17173         }
17174 }
17175
17176 cmdline_parse_inst_t cmd_clear_vf_stats = {
17177         .f = cmd_clear_vf_stats_parsed,
17178         .data = NULL,
17179         .help_str = "clear vf stats <port_id> <vf_id>",
17180         .tokens = {
17181                 (void *)&cmd_clear_vf_stats_clear,
17182                 (void *)&cmd_clear_vf_stats_vf,
17183                 (void *)&cmd_clear_vf_stats_stats,
17184                 (void *)&cmd_clear_vf_stats_port_id,
17185                 (void *)&cmd_clear_vf_stats_vf_id,
17186                 NULL,
17187         },
17188 };
17189
17190 /* port config pctype mapping reset */
17191
17192 /* Common result structure for port config pctype mapping reset */
17193 struct cmd_pctype_mapping_reset_result {
17194         cmdline_fixed_string_t port;
17195         cmdline_fixed_string_t config;
17196         portid_t port_id;
17197         cmdline_fixed_string_t pctype;
17198         cmdline_fixed_string_t mapping;
17199         cmdline_fixed_string_t reset;
17200 };
17201
17202 /* Common CLI fields for port config pctype mapping reset*/
17203 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17204         TOKEN_STRING_INITIALIZER
17205                 (struct cmd_pctype_mapping_reset_result,
17206                  port, "port");
17207 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17208         TOKEN_STRING_INITIALIZER
17209                 (struct cmd_pctype_mapping_reset_result,
17210                  config, "config");
17211 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17212         TOKEN_NUM_INITIALIZER
17213                 (struct cmd_pctype_mapping_reset_result,
17214                  port_id, UINT16);
17215 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17216         TOKEN_STRING_INITIALIZER
17217                 (struct cmd_pctype_mapping_reset_result,
17218                  pctype, "pctype");
17219 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17220         TOKEN_STRING_INITIALIZER
17221                 (struct cmd_pctype_mapping_reset_result,
17222                  mapping, "mapping");
17223 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17224         TOKEN_STRING_INITIALIZER
17225                 (struct cmd_pctype_mapping_reset_result,
17226                  reset, "reset");
17227
17228 static void
17229 cmd_pctype_mapping_reset_parsed(
17230         void *parsed_result,
17231         __attribute__((unused)) struct cmdline *cl,
17232         __attribute__((unused)) void *data)
17233 {
17234         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17235         int ret = -ENOTSUP;
17236
17237         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17238                 return;
17239
17240 #ifdef RTE_LIBRTE_I40E_PMD
17241         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17242 #endif
17243
17244         switch (ret) {
17245         case 0:
17246                 break;
17247         case -ENODEV:
17248                 printf("invalid port_id %d\n", res->port_id);
17249                 break;
17250         case -ENOTSUP:
17251                 printf("function not implemented\n");
17252                 break;
17253         default:
17254                 printf("programming error: (%s)\n", strerror(-ret));
17255         }
17256 }
17257
17258 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17259         .f = cmd_pctype_mapping_reset_parsed,
17260         .data = NULL,
17261         .help_str = "port config <port_id> pctype mapping reset",
17262         .tokens = {
17263                 (void *)&cmd_pctype_mapping_reset_port,
17264                 (void *)&cmd_pctype_mapping_reset_config,
17265                 (void *)&cmd_pctype_mapping_reset_port_id,
17266                 (void *)&cmd_pctype_mapping_reset_pctype,
17267                 (void *)&cmd_pctype_mapping_reset_mapping,
17268                 (void *)&cmd_pctype_mapping_reset_reset,
17269                 NULL,
17270         },
17271 };
17272
17273 /* show port pctype mapping */
17274
17275 /* Common result structure for show port pctype mapping */
17276 struct cmd_pctype_mapping_get_result {
17277         cmdline_fixed_string_t show;
17278         cmdline_fixed_string_t port;
17279         portid_t port_id;
17280         cmdline_fixed_string_t pctype;
17281         cmdline_fixed_string_t mapping;
17282 };
17283
17284 /* Common CLI fields for pctype mapping get */
17285 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17286         TOKEN_STRING_INITIALIZER
17287                 (struct cmd_pctype_mapping_get_result,
17288                  show, "show");
17289 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17290         TOKEN_STRING_INITIALIZER
17291                 (struct cmd_pctype_mapping_get_result,
17292                  port, "port");
17293 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17294         TOKEN_NUM_INITIALIZER
17295                 (struct cmd_pctype_mapping_get_result,
17296                  port_id, UINT16);
17297 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17298         TOKEN_STRING_INITIALIZER
17299                 (struct cmd_pctype_mapping_get_result,
17300                  pctype, "pctype");
17301 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17302         TOKEN_STRING_INITIALIZER
17303                 (struct cmd_pctype_mapping_get_result,
17304                  mapping, "mapping");
17305
17306 static void
17307 cmd_pctype_mapping_get_parsed(
17308         void *parsed_result,
17309         __attribute__((unused)) struct cmdline *cl,
17310         __attribute__((unused)) void *data)
17311 {
17312         struct cmd_pctype_mapping_get_result *res = parsed_result;
17313         int ret = -ENOTSUP;
17314 #ifdef RTE_LIBRTE_I40E_PMD
17315         struct rte_pmd_i40e_flow_type_mapping
17316                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17317         int i, j, first_pctype;
17318 #endif
17319
17320         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17321                 return;
17322
17323 #ifdef RTE_LIBRTE_I40E_PMD
17324         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17325 #endif
17326
17327         switch (ret) {
17328         case 0:
17329                 break;
17330         case -ENODEV:
17331                 printf("invalid port_id %d\n", res->port_id);
17332                 return;
17333         case -ENOTSUP:
17334                 printf("function not implemented\n");
17335                 return;
17336         default:
17337                 printf("programming error: (%s)\n", strerror(-ret));
17338                 return;
17339         }
17340
17341 #ifdef RTE_LIBRTE_I40E_PMD
17342         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17343                 if (mapping[i].pctype != 0ULL) {
17344                         first_pctype = 1;
17345
17346                         printf("pctype: ");
17347                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17348                                 if (mapping[i].pctype & (1ULL << j)) {
17349                                         printf(first_pctype ?
17350                                                "%02d" : ",%02d", j);
17351                                         first_pctype = 0;
17352                                 }
17353                         }
17354                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17355                 }
17356         }
17357 #endif
17358 }
17359
17360 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17361         .f = cmd_pctype_mapping_get_parsed,
17362         .data = NULL,
17363         .help_str = "show port <port_id> pctype mapping",
17364         .tokens = {
17365                 (void *)&cmd_pctype_mapping_get_show,
17366                 (void *)&cmd_pctype_mapping_get_port,
17367                 (void *)&cmd_pctype_mapping_get_port_id,
17368                 (void *)&cmd_pctype_mapping_get_pctype,
17369                 (void *)&cmd_pctype_mapping_get_mapping,
17370                 NULL,
17371         },
17372 };
17373
17374 /* port config pctype mapping update */
17375
17376 /* Common result structure for port config pctype mapping update */
17377 struct cmd_pctype_mapping_update_result {
17378         cmdline_fixed_string_t port;
17379         cmdline_fixed_string_t config;
17380         portid_t port_id;
17381         cmdline_fixed_string_t pctype;
17382         cmdline_fixed_string_t mapping;
17383         cmdline_fixed_string_t update;
17384         cmdline_fixed_string_t pctype_list;
17385         uint16_t flow_type;
17386 };
17387
17388 /* Common CLI fields for pctype mapping update*/
17389 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17390         TOKEN_STRING_INITIALIZER
17391                 (struct cmd_pctype_mapping_update_result,
17392                  port, "port");
17393 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17394         TOKEN_STRING_INITIALIZER
17395                 (struct cmd_pctype_mapping_update_result,
17396                  config, "config");
17397 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17398         TOKEN_NUM_INITIALIZER
17399                 (struct cmd_pctype_mapping_update_result,
17400                  port_id, UINT16);
17401 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17402         TOKEN_STRING_INITIALIZER
17403                 (struct cmd_pctype_mapping_update_result,
17404                  pctype, "pctype");
17405 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17406         TOKEN_STRING_INITIALIZER
17407                 (struct cmd_pctype_mapping_update_result,
17408                  mapping, "mapping");
17409 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17410         TOKEN_STRING_INITIALIZER
17411                 (struct cmd_pctype_mapping_update_result,
17412                  update, "update");
17413 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17414         TOKEN_STRING_INITIALIZER
17415                 (struct cmd_pctype_mapping_update_result,
17416                  pctype_list, NULL);
17417 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17418         TOKEN_NUM_INITIALIZER
17419                 (struct cmd_pctype_mapping_update_result,
17420                  flow_type, UINT16);
17421
17422 static void
17423 cmd_pctype_mapping_update_parsed(
17424         void *parsed_result,
17425         __attribute__((unused)) struct cmdline *cl,
17426         __attribute__((unused)) void *data)
17427 {
17428         struct cmd_pctype_mapping_update_result *res = parsed_result;
17429         int ret = -ENOTSUP;
17430 #ifdef RTE_LIBRTE_I40E_PMD
17431         struct rte_pmd_i40e_flow_type_mapping mapping;
17432         unsigned int i;
17433         unsigned int nb_item;
17434         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17435 #endif
17436
17437         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17438                 return;
17439
17440 #ifdef RTE_LIBRTE_I40E_PMD
17441         nb_item = parse_item_list(res->pctype_list, "pctypes",
17442                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17443         mapping.flow_type = res->flow_type;
17444         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17445                 mapping.pctype |= (1ULL << pctype_list[i]);
17446         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17447                                                 &mapping,
17448                                                 1,
17449                                                 0);
17450 #endif
17451
17452         switch (ret) {
17453         case 0:
17454                 break;
17455         case -EINVAL:
17456                 printf("invalid pctype or flow type\n");
17457                 break;
17458         case -ENODEV:
17459                 printf("invalid port_id %d\n", res->port_id);
17460                 break;
17461         case -ENOTSUP:
17462                 printf("function not implemented\n");
17463                 break;
17464         default:
17465                 printf("programming error: (%s)\n", strerror(-ret));
17466         }
17467 }
17468
17469 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17470         .f = cmd_pctype_mapping_update_parsed,
17471         .data = NULL,
17472         .help_str = "port config <port_id> pctype mapping update"
17473         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17474         .tokens = {
17475                 (void *)&cmd_pctype_mapping_update_port,
17476                 (void *)&cmd_pctype_mapping_update_config,
17477                 (void *)&cmd_pctype_mapping_update_port_id,
17478                 (void *)&cmd_pctype_mapping_update_pctype,
17479                 (void *)&cmd_pctype_mapping_update_mapping,
17480                 (void *)&cmd_pctype_mapping_update_update,
17481                 (void *)&cmd_pctype_mapping_update_pc_type,
17482                 (void *)&cmd_pctype_mapping_update_flow_type,
17483                 NULL,
17484         },
17485 };
17486
17487 /* ptype mapping get */
17488
17489 /* Common result structure for ptype mapping get */
17490 struct cmd_ptype_mapping_get_result {
17491         cmdline_fixed_string_t ptype;
17492         cmdline_fixed_string_t mapping;
17493         cmdline_fixed_string_t get;
17494         portid_t port_id;
17495         uint8_t valid_only;
17496 };
17497
17498 /* Common CLI fields for ptype mapping get */
17499 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17500         TOKEN_STRING_INITIALIZER
17501                 (struct cmd_ptype_mapping_get_result,
17502                  ptype, "ptype");
17503 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17504         TOKEN_STRING_INITIALIZER
17505                 (struct cmd_ptype_mapping_get_result,
17506                  mapping, "mapping");
17507 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17508         TOKEN_STRING_INITIALIZER
17509                 (struct cmd_ptype_mapping_get_result,
17510                  get, "get");
17511 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17512         TOKEN_NUM_INITIALIZER
17513                 (struct cmd_ptype_mapping_get_result,
17514                  port_id, UINT16);
17515 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17516         TOKEN_NUM_INITIALIZER
17517                 (struct cmd_ptype_mapping_get_result,
17518                  valid_only, UINT8);
17519
17520 static void
17521 cmd_ptype_mapping_get_parsed(
17522         void *parsed_result,
17523         __attribute__((unused)) struct cmdline *cl,
17524         __attribute__((unused)) void *data)
17525 {
17526         struct cmd_ptype_mapping_get_result *res = parsed_result;
17527         int ret = -ENOTSUP;
17528 #ifdef RTE_LIBRTE_I40E_PMD
17529         int max_ptype_num = 256;
17530         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17531         uint16_t count;
17532         int i;
17533 #endif
17534
17535         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17536                 return;
17537
17538 #ifdef RTE_LIBRTE_I40E_PMD
17539         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17540                                         mapping,
17541                                         max_ptype_num,
17542                                         &count,
17543                                         res->valid_only);
17544 #endif
17545
17546         switch (ret) {
17547         case 0:
17548                 break;
17549         case -ENODEV:
17550                 printf("invalid port_id %d\n", res->port_id);
17551                 break;
17552         case -ENOTSUP:
17553                 printf("function not implemented\n");
17554                 break;
17555         default:
17556                 printf("programming error: (%s)\n", strerror(-ret));
17557         }
17558
17559 #ifdef RTE_LIBRTE_I40E_PMD
17560         if (!ret) {
17561                 for (i = 0; i < count; i++)
17562                         printf("%3d\t0x%08x\n",
17563                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17564         }
17565 #endif
17566 }
17567
17568 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17569         .f = cmd_ptype_mapping_get_parsed,
17570         .data = NULL,
17571         .help_str = "ptype mapping get <port_id> <valid_only>",
17572         .tokens = {
17573                 (void *)&cmd_ptype_mapping_get_ptype,
17574                 (void *)&cmd_ptype_mapping_get_mapping,
17575                 (void *)&cmd_ptype_mapping_get_get,
17576                 (void *)&cmd_ptype_mapping_get_port_id,
17577                 (void *)&cmd_ptype_mapping_get_valid_only,
17578                 NULL,
17579         },
17580 };
17581
17582 /* ptype mapping replace */
17583
17584 /* Common result structure for ptype mapping replace */
17585 struct cmd_ptype_mapping_replace_result {
17586         cmdline_fixed_string_t ptype;
17587         cmdline_fixed_string_t mapping;
17588         cmdline_fixed_string_t replace;
17589         portid_t port_id;
17590         uint32_t target;
17591         uint8_t mask;
17592         uint32_t pkt_type;
17593 };
17594
17595 /* Common CLI fields for ptype mapping replace */
17596 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17597         TOKEN_STRING_INITIALIZER
17598                 (struct cmd_ptype_mapping_replace_result,
17599                  ptype, "ptype");
17600 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17601         TOKEN_STRING_INITIALIZER
17602                 (struct cmd_ptype_mapping_replace_result,
17603                  mapping, "mapping");
17604 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17605         TOKEN_STRING_INITIALIZER
17606                 (struct cmd_ptype_mapping_replace_result,
17607                  replace, "replace");
17608 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17609         TOKEN_NUM_INITIALIZER
17610                 (struct cmd_ptype_mapping_replace_result,
17611                  port_id, UINT16);
17612 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17613         TOKEN_NUM_INITIALIZER
17614                 (struct cmd_ptype_mapping_replace_result,
17615                  target, UINT32);
17616 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17617         TOKEN_NUM_INITIALIZER
17618                 (struct cmd_ptype_mapping_replace_result,
17619                  mask, UINT8);
17620 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17621         TOKEN_NUM_INITIALIZER
17622                 (struct cmd_ptype_mapping_replace_result,
17623                  pkt_type, UINT32);
17624
17625 static void
17626 cmd_ptype_mapping_replace_parsed(
17627         void *parsed_result,
17628         __attribute__((unused)) struct cmdline *cl,
17629         __attribute__((unused)) void *data)
17630 {
17631         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17632         int ret = -ENOTSUP;
17633
17634         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17635                 return;
17636
17637 #ifdef RTE_LIBRTE_I40E_PMD
17638         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17639                                         res->target,
17640                                         res->mask,
17641                                         res->pkt_type);
17642 #endif
17643
17644         switch (ret) {
17645         case 0:
17646                 break;
17647         case -EINVAL:
17648                 printf("invalid ptype 0x%8x or 0x%8x\n",
17649                                 res->target, res->pkt_type);
17650                 break;
17651         case -ENODEV:
17652                 printf("invalid port_id %d\n", res->port_id);
17653                 break;
17654         case -ENOTSUP:
17655                 printf("function not implemented\n");
17656                 break;
17657         default:
17658                 printf("programming error: (%s)\n", strerror(-ret));
17659         }
17660 }
17661
17662 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17663         .f = cmd_ptype_mapping_replace_parsed,
17664         .data = NULL,
17665         .help_str =
17666                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17667         .tokens = {
17668                 (void *)&cmd_ptype_mapping_replace_ptype,
17669                 (void *)&cmd_ptype_mapping_replace_mapping,
17670                 (void *)&cmd_ptype_mapping_replace_replace,
17671                 (void *)&cmd_ptype_mapping_replace_port_id,
17672                 (void *)&cmd_ptype_mapping_replace_target,
17673                 (void *)&cmd_ptype_mapping_replace_mask,
17674                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17675                 NULL,
17676         },
17677 };
17678
17679 /* ptype mapping reset */
17680
17681 /* Common result structure for ptype mapping reset */
17682 struct cmd_ptype_mapping_reset_result {
17683         cmdline_fixed_string_t ptype;
17684         cmdline_fixed_string_t mapping;
17685         cmdline_fixed_string_t reset;
17686         portid_t port_id;
17687 };
17688
17689 /* Common CLI fields for ptype mapping reset*/
17690 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17691         TOKEN_STRING_INITIALIZER
17692                 (struct cmd_ptype_mapping_reset_result,
17693                  ptype, "ptype");
17694 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17695         TOKEN_STRING_INITIALIZER
17696                 (struct cmd_ptype_mapping_reset_result,
17697                  mapping, "mapping");
17698 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17699         TOKEN_STRING_INITIALIZER
17700                 (struct cmd_ptype_mapping_reset_result,
17701                  reset, "reset");
17702 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17703         TOKEN_NUM_INITIALIZER
17704                 (struct cmd_ptype_mapping_reset_result,
17705                  port_id, UINT16);
17706
17707 static void
17708 cmd_ptype_mapping_reset_parsed(
17709         void *parsed_result,
17710         __attribute__((unused)) struct cmdline *cl,
17711         __attribute__((unused)) void *data)
17712 {
17713         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17714         int ret = -ENOTSUP;
17715
17716         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17717                 return;
17718
17719 #ifdef RTE_LIBRTE_I40E_PMD
17720         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17721 #endif
17722
17723         switch (ret) {
17724         case 0:
17725                 break;
17726         case -ENODEV:
17727                 printf("invalid port_id %d\n", res->port_id);
17728                 break;
17729         case -ENOTSUP:
17730                 printf("function not implemented\n");
17731                 break;
17732         default:
17733                 printf("programming error: (%s)\n", strerror(-ret));
17734         }
17735 }
17736
17737 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17738         .f = cmd_ptype_mapping_reset_parsed,
17739         .data = NULL,
17740         .help_str = "ptype mapping reset <port_id>",
17741         .tokens = {
17742                 (void *)&cmd_ptype_mapping_reset_ptype,
17743                 (void *)&cmd_ptype_mapping_reset_mapping,
17744                 (void *)&cmd_ptype_mapping_reset_reset,
17745                 (void *)&cmd_ptype_mapping_reset_port_id,
17746                 NULL,
17747         },
17748 };
17749
17750 /* ptype mapping update */
17751
17752 /* Common result structure for ptype mapping update */
17753 struct cmd_ptype_mapping_update_result {
17754         cmdline_fixed_string_t ptype;
17755         cmdline_fixed_string_t mapping;
17756         cmdline_fixed_string_t reset;
17757         portid_t port_id;
17758         uint8_t hw_ptype;
17759         uint32_t sw_ptype;
17760 };
17761
17762 /* Common CLI fields for ptype mapping update*/
17763 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17764         TOKEN_STRING_INITIALIZER
17765                 (struct cmd_ptype_mapping_update_result,
17766                  ptype, "ptype");
17767 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17768         TOKEN_STRING_INITIALIZER
17769                 (struct cmd_ptype_mapping_update_result,
17770                  mapping, "mapping");
17771 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17772         TOKEN_STRING_INITIALIZER
17773                 (struct cmd_ptype_mapping_update_result,
17774                  reset, "update");
17775 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17776         TOKEN_NUM_INITIALIZER
17777                 (struct cmd_ptype_mapping_update_result,
17778                  port_id, UINT16);
17779 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17780         TOKEN_NUM_INITIALIZER
17781                 (struct cmd_ptype_mapping_update_result,
17782                  hw_ptype, UINT8);
17783 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17784         TOKEN_NUM_INITIALIZER
17785                 (struct cmd_ptype_mapping_update_result,
17786                  sw_ptype, UINT32);
17787
17788 static void
17789 cmd_ptype_mapping_update_parsed(
17790         void *parsed_result,
17791         __attribute__((unused)) struct cmdline *cl,
17792         __attribute__((unused)) void *data)
17793 {
17794         struct cmd_ptype_mapping_update_result *res = parsed_result;
17795         int ret = -ENOTSUP;
17796 #ifdef RTE_LIBRTE_I40E_PMD
17797         struct rte_pmd_i40e_ptype_mapping mapping;
17798 #endif
17799         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17800                 return;
17801
17802 #ifdef RTE_LIBRTE_I40E_PMD
17803         mapping.hw_ptype = res->hw_ptype;
17804         mapping.sw_ptype = res->sw_ptype;
17805         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17806                                                 &mapping,
17807                                                 1,
17808                                                 0);
17809 #endif
17810
17811         switch (ret) {
17812         case 0:
17813                 break;
17814         case -EINVAL:
17815                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17816                 break;
17817         case -ENODEV:
17818                 printf("invalid port_id %d\n", res->port_id);
17819                 break;
17820         case -ENOTSUP:
17821                 printf("function not implemented\n");
17822                 break;
17823         default:
17824                 printf("programming error: (%s)\n", strerror(-ret));
17825         }
17826 }
17827
17828 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17829         .f = cmd_ptype_mapping_update_parsed,
17830         .data = NULL,
17831         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17832         .tokens = {
17833                 (void *)&cmd_ptype_mapping_update_ptype,
17834                 (void *)&cmd_ptype_mapping_update_mapping,
17835                 (void *)&cmd_ptype_mapping_update_update,
17836                 (void *)&cmd_ptype_mapping_update_port_id,
17837                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17838                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17839                 NULL,
17840         },
17841 };
17842
17843 /* Common result structure for file commands */
17844 struct cmd_cmdfile_result {
17845         cmdline_fixed_string_t load;
17846         cmdline_fixed_string_t filename;
17847 };
17848
17849 /* Common CLI fields for file commands */
17850 cmdline_parse_token_string_t cmd_load_cmdfile =
17851         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17852 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17853         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17854
17855 static void
17856 cmd_load_from_file_parsed(
17857         void *parsed_result,
17858         __attribute__((unused)) struct cmdline *cl,
17859         __attribute__((unused)) void *data)
17860 {
17861         struct cmd_cmdfile_result *res = parsed_result;
17862
17863         cmdline_read_from_file(res->filename);
17864 }
17865
17866 cmdline_parse_inst_t cmd_load_from_file = {
17867         .f = cmd_load_from_file_parsed,
17868         .data = NULL,
17869         .help_str = "load <filename>",
17870         .tokens = {
17871                 (void *)&cmd_load_cmdfile,
17872                 (void *)&cmd_load_cmdfile_filename,
17873                 NULL,
17874         },
17875 };
17876
17877 /* Get Rx offloads capabilities */
17878 struct cmd_rx_offload_get_capa_result {
17879         cmdline_fixed_string_t show;
17880         cmdline_fixed_string_t port;
17881         portid_t port_id;
17882         cmdline_fixed_string_t rx_offload;
17883         cmdline_fixed_string_t capabilities;
17884 };
17885
17886 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17887         TOKEN_STRING_INITIALIZER
17888                 (struct cmd_rx_offload_get_capa_result,
17889                  show, "show");
17890 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17891         TOKEN_STRING_INITIALIZER
17892                 (struct cmd_rx_offload_get_capa_result,
17893                  port, "port");
17894 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17895         TOKEN_NUM_INITIALIZER
17896                 (struct cmd_rx_offload_get_capa_result,
17897                  port_id, UINT16);
17898 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17899         TOKEN_STRING_INITIALIZER
17900                 (struct cmd_rx_offload_get_capa_result,
17901                  rx_offload, "rx_offload");
17902 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17903         TOKEN_STRING_INITIALIZER
17904                 (struct cmd_rx_offload_get_capa_result,
17905                  capabilities, "capabilities");
17906
17907 static void
17908 print_rx_offloads(uint64_t offloads)
17909 {
17910         uint64_t single_offload;
17911         int begin;
17912         int end;
17913         int bit;
17914
17915         if (offloads == 0)
17916                 return;
17917
17918         begin = __builtin_ctzll(offloads);
17919         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17920
17921         single_offload = 1ULL << begin;
17922         for (bit = begin; bit < end; bit++) {
17923                 if (offloads & single_offload)
17924                         printf(" %s",
17925                                rte_eth_dev_rx_offload_name(single_offload));
17926                 single_offload <<= 1;
17927         }
17928 }
17929
17930 static void
17931 cmd_rx_offload_get_capa_parsed(
17932         void *parsed_result,
17933         __attribute__((unused)) struct cmdline *cl,
17934         __attribute__((unused)) void *data)
17935 {
17936         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17937         struct rte_eth_dev_info dev_info;
17938         portid_t port_id = res->port_id;
17939         uint64_t queue_offloads;
17940         uint64_t port_offloads;
17941         int ret;
17942
17943         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17944         if (ret != 0)
17945                 return;
17946
17947         queue_offloads = dev_info.rx_queue_offload_capa;
17948         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17949
17950         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17951         printf("  Per Queue :");
17952         print_rx_offloads(queue_offloads);
17953
17954         printf("\n");
17955         printf("  Per Port  :");
17956         print_rx_offloads(port_offloads);
17957         printf("\n\n");
17958 }
17959
17960 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17961         .f = cmd_rx_offload_get_capa_parsed,
17962         .data = NULL,
17963         .help_str = "show port <port_id> rx_offload capabilities",
17964         .tokens = {
17965                 (void *)&cmd_rx_offload_get_capa_show,
17966                 (void *)&cmd_rx_offload_get_capa_port,
17967                 (void *)&cmd_rx_offload_get_capa_port_id,
17968                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17969                 (void *)&cmd_rx_offload_get_capa_capabilities,
17970                 NULL,
17971         }
17972 };
17973
17974 /* Get Rx offloads configuration */
17975 struct cmd_rx_offload_get_configuration_result {
17976         cmdline_fixed_string_t show;
17977         cmdline_fixed_string_t port;
17978         portid_t port_id;
17979         cmdline_fixed_string_t rx_offload;
17980         cmdline_fixed_string_t configuration;
17981 };
17982
17983 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17984         TOKEN_STRING_INITIALIZER
17985                 (struct cmd_rx_offload_get_configuration_result,
17986                  show, "show");
17987 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17988         TOKEN_STRING_INITIALIZER
17989                 (struct cmd_rx_offload_get_configuration_result,
17990                  port, "port");
17991 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17992         TOKEN_NUM_INITIALIZER
17993                 (struct cmd_rx_offload_get_configuration_result,
17994                  port_id, UINT16);
17995 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17996         TOKEN_STRING_INITIALIZER
17997                 (struct cmd_rx_offload_get_configuration_result,
17998                  rx_offload, "rx_offload");
17999 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18000         TOKEN_STRING_INITIALIZER
18001                 (struct cmd_rx_offload_get_configuration_result,
18002                  configuration, "configuration");
18003
18004 static void
18005 cmd_rx_offload_get_configuration_parsed(
18006         void *parsed_result,
18007         __attribute__((unused)) struct cmdline *cl,
18008         __attribute__((unused)) void *data)
18009 {
18010         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18011         struct rte_eth_dev_info dev_info;
18012         portid_t port_id = res->port_id;
18013         struct rte_port *port = &ports[port_id];
18014         uint64_t port_offloads;
18015         uint64_t queue_offloads;
18016         uint16_t nb_rx_queues;
18017         int q;
18018         int ret;
18019
18020         printf("Rx Offloading Configuration of port %d :\n", port_id);
18021
18022         port_offloads = port->dev_conf.rxmode.offloads;
18023         printf("  Port :");
18024         print_rx_offloads(port_offloads);
18025         printf("\n");
18026
18027         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18028         if (ret != 0)
18029                 return;
18030
18031         nb_rx_queues = dev_info.nb_rx_queues;
18032         for (q = 0; q < nb_rx_queues; q++) {
18033                 queue_offloads = port->rx_conf[q].offloads;
18034                 printf("  Queue[%2d] :", q);
18035                 print_rx_offloads(queue_offloads);
18036                 printf("\n");
18037         }
18038         printf("\n");
18039 }
18040
18041 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18042         .f = cmd_rx_offload_get_configuration_parsed,
18043         .data = NULL,
18044         .help_str = "show port <port_id> rx_offload configuration",
18045         .tokens = {
18046                 (void *)&cmd_rx_offload_get_configuration_show,
18047                 (void *)&cmd_rx_offload_get_configuration_port,
18048                 (void *)&cmd_rx_offload_get_configuration_port_id,
18049                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18050                 (void *)&cmd_rx_offload_get_configuration_configuration,
18051                 NULL,
18052         }
18053 };
18054
18055 /* Enable/Disable a per port offloading */
18056 struct cmd_config_per_port_rx_offload_result {
18057         cmdline_fixed_string_t port;
18058         cmdline_fixed_string_t config;
18059         portid_t port_id;
18060         cmdline_fixed_string_t rx_offload;
18061         cmdline_fixed_string_t offload;
18062         cmdline_fixed_string_t on_off;
18063 };
18064
18065 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18066         TOKEN_STRING_INITIALIZER
18067                 (struct cmd_config_per_port_rx_offload_result,
18068                  port, "port");
18069 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18070         TOKEN_STRING_INITIALIZER
18071                 (struct cmd_config_per_port_rx_offload_result,
18072                  config, "config");
18073 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18074         TOKEN_NUM_INITIALIZER
18075                 (struct cmd_config_per_port_rx_offload_result,
18076                  port_id, UINT16);
18077 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18078         TOKEN_STRING_INITIALIZER
18079                 (struct cmd_config_per_port_rx_offload_result,
18080                  rx_offload, "rx_offload");
18081 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18082         TOKEN_STRING_INITIALIZER
18083                 (struct cmd_config_per_port_rx_offload_result,
18084                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18085                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18086                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18087                            "scatter#timestamp#security#keep_crc");
18088 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18089         TOKEN_STRING_INITIALIZER
18090                 (struct cmd_config_per_port_rx_offload_result,
18091                  on_off, "on#off");
18092
18093 static uint64_t
18094 search_rx_offload(const char *name)
18095 {
18096         uint64_t single_offload;
18097         const char *single_name;
18098         int found = 0;
18099         unsigned int bit;
18100
18101         single_offload = 1;
18102         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18103                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18104                 if (!strcasecmp(single_name, name)) {
18105                         found = 1;
18106                         break;
18107                 }
18108                 single_offload <<= 1;
18109         }
18110
18111         if (found)
18112                 return single_offload;
18113
18114         return 0;
18115 }
18116
18117 static void
18118 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18119                                 __attribute__((unused)) struct cmdline *cl,
18120                                 __attribute__((unused)) void *data)
18121 {
18122         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18123         portid_t port_id = res->port_id;
18124         struct rte_eth_dev_info dev_info;
18125         struct rte_port *port = &ports[port_id];
18126         uint64_t single_offload;
18127         uint16_t nb_rx_queues;
18128         int q;
18129         int ret;
18130
18131         if (port->port_status != RTE_PORT_STOPPED) {
18132                 printf("Error: Can't config offload when Port %d "
18133                        "is not stopped\n", port_id);
18134                 return;
18135         }
18136
18137         single_offload = search_rx_offload(res->offload);
18138         if (single_offload == 0) {
18139                 printf("Unknown offload name: %s\n", res->offload);
18140                 return;
18141         }
18142
18143         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18144         if (ret != 0)
18145                 return;
18146
18147         nb_rx_queues = dev_info.nb_rx_queues;
18148         if (!strcmp(res->on_off, "on")) {
18149                 port->dev_conf.rxmode.offloads |= single_offload;
18150                 for (q = 0; q < nb_rx_queues; q++)
18151                         port->rx_conf[q].offloads |= single_offload;
18152         } else {
18153                 port->dev_conf.rxmode.offloads &= ~single_offload;
18154                 for (q = 0; q < nb_rx_queues; q++)
18155                         port->rx_conf[q].offloads &= ~single_offload;
18156         }
18157
18158         cmd_reconfig_device_queue(port_id, 1, 1);
18159 }
18160
18161 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18162         .f = cmd_config_per_port_rx_offload_parsed,
18163         .data = NULL,
18164         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18165                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18166                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18167                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18168                     "on|off",
18169         .tokens = {
18170                 (void *)&cmd_config_per_port_rx_offload_result_port,
18171                 (void *)&cmd_config_per_port_rx_offload_result_config,
18172                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18173                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18174                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18175                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18176                 NULL,
18177         }
18178 };
18179
18180 /* Enable/Disable a per queue offloading */
18181 struct cmd_config_per_queue_rx_offload_result {
18182         cmdline_fixed_string_t port;
18183         portid_t port_id;
18184         cmdline_fixed_string_t rxq;
18185         uint16_t queue_id;
18186         cmdline_fixed_string_t rx_offload;
18187         cmdline_fixed_string_t offload;
18188         cmdline_fixed_string_t on_off;
18189 };
18190
18191 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18192         TOKEN_STRING_INITIALIZER
18193                 (struct cmd_config_per_queue_rx_offload_result,
18194                  port, "port");
18195 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18196         TOKEN_NUM_INITIALIZER
18197                 (struct cmd_config_per_queue_rx_offload_result,
18198                  port_id, UINT16);
18199 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18200         TOKEN_STRING_INITIALIZER
18201                 (struct cmd_config_per_queue_rx_offload_result,
18202                  rxq, "rxq");
18203 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18204         TOKEN_NUM_INITIALIZER
18205                 (struct cmd_config_per_queue_rx_offload_result,
18206                  queue_id, UINT16);
18207 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18208         TOKEN_STRING_INITIALIZER
18209                 (struct cmd_config_per_queue_rx_offload_result,
18210                  rx_offload, "rx_offload");
18211 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18212         TOKEN_STRING_INITIALIZER
18213                 (struct cmd_config_per_queue_rx_offload_result,
18214                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18215                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18216                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18217                            "scatter#timestamp#security#keep_crc");
18218 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18219         TOKEN_STRING_INITIALIZER
18220                 (struct cmd_config_per_queue_rx_offload_result,
18221                  on_off, "on#off");
18222
18223 static void
18224 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18225                                 __attribute__((unused)) struct cmdline *cl,
18226                                 __attribute__((unused)) void *data)
18227 {
18228         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18229         struct rte_eth_dev_info dev_info;
18230         portid_t port_id = res->port_id;
18231         uint16_t queue_id = res->queue_id;
18232         struct rte_port *port = &ports[port_id];
18233         uint64_t single_offload;
18234         int ret;
18235
18236         if (port->port_status != RTE_PORT_STOPPED) {
18237                 printf("Error: Can't config offload when Port %d "
18238                        "is not stopped\n", port_id);
18239                 return;
18240         }
18241
18242         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18243         if (ret != 0)
18244                 return;
18245
18246         if (queue_id >= dev_info.nb_rx_queues) {
18247                 printf("Error: input queue_id should be 0 ... "
18248                        "%d\n", dev_info.nb_rx_queues - 1);
18249                 return;
18250         }
18251
18252         single_offload = search_rx_offload(res->offload);
18253         if (single_offload == 0) {
18254                 printf("Unknown offload name: %s\n", res->offload);
18255                 return;
18256         }
18257
18258         if (!strcmp(res->on_off, "on"))
18259                 port->rx_conf[queue_id].offloads |= single_offload;
18260         else
18261                 port->rx_conf[queue_id].offloads &= ~single_offload;
18262
18263         cmd_reconfig_device_queue(port_id, 1, 1);
18264 }
18265
18266 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18267         .f = cmd_config_per_queue_rx_offload_parsed,
18268         .data = NULL,
18269         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18270                     "vlan_strip|ipv4_cksum|"
18271                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18272                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18273                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18274                     "on|off",
18275         .tokens = {
18276                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18277                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18278                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18279                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18280                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18281                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18282                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18283                 NULL,
18284         }
18285 };
18286
18287 /* Get Tx offloads capabilities */
18288 struct cmd_tx_offload_get_capa_result {
18289         cmdline_fixed_string_t show;
18290         cmdline_fixed_string_t port;
18291         portid_t port_id;
18292         cmdline_fixed_string_t tx_offload;
18293         cmdline_fixed_string_t capabilities;
18294 };
18295
18296 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18297         TOKEN_STRING_INITIALIZER
18298                 (struct cmd_tx_offload_get_capa_result,
18299                  show, "show");
18300 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18301         TOKEN_STRING_INITIALIZER
18302                 (struct cmd_tx_offload_get_capa_result,
18303                  port, "port");
18304 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18305         TOKEN_NUM_INITIALIZER
18306                 (struct cmd_tx_offload_get_capa_result,
18307                  port_id, UINT16);
18308 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18309         TOKEN_STRING_INITIALIZER
18310                 (struct cmd_tx_offload_get_capa_result,
18311                  tx_offload, "tx_offload");
18312 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18313         TOKEN_STRING_INITIALIZER
18314                 (struct cmd_tx_offload_get_capa_result,
18315                  capabilities, "capabilities");
18316
18317 static void
18318 print_tx_offloads(uint64_t offloads)
18319 {
18320         uint64_t single_offload;
18321         int begin;
18322         int end;
18323         int bit;
18324
18325         if (offloads == 0)
18326                 return;
18327
18328         begin = __builtin_ctzll(offloads);
18329         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18330
18331         single_offload = 1ULL << begin;
18332         for (bit = begin; bit < end; bit++) {
18333                 if (offloads & single_offload)
18334                         printf(" %s",
18335                                rte_eth_dev_tx_offload_name(single_offload));
18336                 single_offload <<= 1;
18337         }
18338 }
18339
18340 static void
18341 cmd_tx_offload_get_capa_parsed(
18342         void *parsed_result,
18343         __attribute__((unused)) struct cmdline *cl,
18344         __attribute__((unused)) void *data)
18345 {
18346         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18347         struct rte_eth_dev_info dev_info;
18348         portid_t port_id = res->port_id;
18349         uint64_t queue_offloads;
18350         uint64_t port_offloads;
18351         int ret;
18352
18353         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18354         if (ret != 0)
18355                 return;
18356
18357         queue_offloads = dev_info.tx_queue_offload_capa;
18358         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18359
18360         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18361         printf("  Per Queue :");
18362         print_tx_offloads(queue_offloads);
18363
18364         printf("\n");
18365         printf("  Per Port  :");
18366         print_tx_offloads(port_offloads);
18367         printf("\n\n");
18368 }
18369
18370 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18371         .f = cmd_tx_offload_get_capa_parsed,
18372         .data = NULL,
18373         .help_str = "show port <port_id> tx_offload capabilities",
18374         .tokens = {
18375                 (void *)&cmd_tx_offload_get_capa_show,
18376                 (void *)&cmd_tx_offload_get_capa_port,
18377                 (void *)&cmd_tx_offload_get_capa_port_id,
18378                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18379                 (void *)&cmd_tx_offload_get_capa_capabilities,
18380                 NULL,
18381         }
18382 };
18383
18384 /* Get Tx offloads configuration */
18385 struct cmd_tx_offload_get_configuration_result {
18386         cmdline_fixed_string_t show;
18387         cmdline_fixed_string_t port;
18388         portid_t port_id;
18389         cmdline_fixed_string_t tx_offload;
18390         cmdline_fixed_string_t configuration;
18391 };
18392
18393 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18394         TOKEN_STRING_INITIALIZER
18395                 (struct cmd_tx_offload_get_configuration_result,
18396                  show, "show");
18397 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18398         TOKEN_STRING_INITIALIZER
18399                 (struct cmd_tx_offload_get_configuration_result,
18400                  port, "port");
18401 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18402         TOKEN_NUM_INITIALIZER
18403                 (struct cmd_tx_offload_get_configuration_result,
18404                  port_id, UINT16);
18405 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18406         TOKEN_STRING_INITIALIZER
18407                 (struct cmd_tx_offload_get_configuration_result,
18408                  tx_offload, "tx_offload");
18409 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18410         TOKEN_STRING_INITIALIZER
18411                 (struct cmd_tx_offload_get_configuration_result,
18412                  configuration, "configuration");
18413
18414 static void
18415 cmd_tx_offload_get_configuration_parsed(
18416         void *parsed_result,
18417         __attribute__((unused)) struct cmdline *cl,
18418         __attribute__((unused)) void *data)
18419 {
18420         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18421         struct rte_eth_dev_info dev_info;
18422         portid_t port_id = res->port_id;
18423         struct rte_port *port = &ports[port_id];
18424         uint64_t port_offloads;
18425         uint64_t queue_offloads;
18426         uint16_t nb_tx_queues;
18427         int q;
18428         int ret;
18429
18430         printf("Tx Offloading Configuration of port %d :\n", port_id);
18431
18432         port_offloads = port->dev_conf.txmode.offloads;
18433         printf("  Port :");
18434         print_tx_offloads(port_offloads);
18435         printf("\n");
18436
18437         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18438         if (ret != 0)
18439                 return;
18440
18441         nb_tx_queues = dev_info.nb_tx_queues;
18442         for (q = 0; q < nb_tx_queues; q++) {
18443                 queue_offloads = port->tx_conf[q].offloads;
18444                 printf("  Queue[%2d] :", q);
18445                 print_tx_offloads(queue_offloads);
18446                 printf("\n");
18447         }
18448         printf("\n");
18449 }
18450
18451 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18452         .f = cmd_tx_offload_get_configuration_parsed,
18453         .data = NULL,
18454         .help_str = "show port <port_id> tx_offload configuration",
18455         .tokens = {
18456                 (void *)&cmd_tx_offload_get_configuration_show,
18457                 (void *)&cmd_tx_offload_get_configuration_port,
18458                 (void *)&cmd_tx_offload_get_configuration_port_id,
18459                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18460                 (void *)&cmd_tx_offload_get_configuration_configuration,
18461                 NULL,
18462         }
18463 };
18464
18465 /* Enable/Disable a per port offloading */
18466 struct cmd_config_per_port_tx_offload_result {
18467         cmdline_fixed_string_t port;
18468         cmdline_fixed_string_t config;
18469         portid_t port_id;
18470         cmdline_fixed_string_t tx_offload;
18471         cmdline_fixed_string_t offload;
18472         cmdline_fixed_string_t on_off;
18473 };
18474
18475 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18476         TOKEN_STRING_INITIALIZER
18477                 (struct cmd_config_per_port_tx_offload_result,
18478                  port, "port");
18479 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18480         TOKEN_STRING_INITIALIZER
18481                 (struct cmd_config_per_port_tx_offload_result,
18482                  config, "config");
18483 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18484         TOKEN_NUM_INITIALIZER
18485                 (struct cmd_config_per_port_tx_offload_result,
18486                  port_id, UINT16);
18487 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18488         TOKEN_STRING_INITIALIZER
18489                 (struct cmd_config_per_port_tx_offload_result,
18490                  tx_offload, "tx_offload");
18491 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18492         TOKEN_STRING_INITIALIZER
18493                 (struct cmd_config_per_port_tx_offload_result,
18494                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18495                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18496                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18497                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18498                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18499                           "match_metadata");
18500 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18501         TOKEN_STRING_INITIALIZER
18502                 (struct cmd_config_per_port_tx_offload_result,
18503                  on_off, "on#off");
18504
18505 static uint64_t
18506 search_tx_offload(const char *name)
18507 {
18508         uint64_t single_offload;
18509         const char *single_name;
18510         int found = 0;
18511         unsigned int bit;
18512
18513         single_offload = 1;
18514         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18515                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18516                 if (single_name == NULL)
18517                         break;
18518                 if (!strcasecmp(single_name, name)) {
18519                         found = 1;
18520                         break;
18521                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18522                         break;
18523                 single_offload <<= 1;
18524         }
18525
18526         if (found)
18527                 return single_offload;
18528
18529         return 0;
18530 }
18531
18532 static void
18533 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18534                                 __attribute__((unused)) struct cmdline *cl,
18535                                 __attribute__((unused)) void *data)
18536 {
18537         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18538         portid_t port_id = res->port_id;
18539         struct rte_eth_dev_info dev_info;
18540         struct rte_port *port = &ports[port_id];
18541         uint64_t single_offload;
18542         uint16_t nb_tx_queues;
18543         int q;
18544         int ret;
18545
18546         if (port->port_status != RTE_PORT_STOPPED) {
18547                 printf("Error: Can't config offload when Port %d "
18548                        "is not stopped\n", port_id);
18549                 return;
18550         }
18551
18552         single_offload = search_tx_offload(res->offload);
18553         if (single_offload == 0) {
18554                 printf("Unknown offload name: %s\n", res->offload);
18555                 return;
18556         }
18557
18558         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18559         if (ret != 0)
18560                 return;
18561
18562         nb_tx_queues = dev_info.nb_tx_queues;
18563         if (!strcmp(res->on_off, "on")) {
18564                 port->dev_conf.txmode.offloads |= single_offload;
18565                 for (q = 0; q < nb_tx_queues; q++)
18566                         port->tx_conf[q].offloads |= single_offload;
18567         } else {
18568                 port->dev_conf.txmode.offloads &= ~single_offload;
18569                 for (q = 0; q < nb_tx_queues; q++)
18570                         port->tx_conf[q].offloads &= ~single_offload;
18571         }
18572
18573         cmd_reconfig_device_queue(port_id, 1, 1);
18574 }
18575
18576 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18577         .f = cmd_config_per_port_tx_offload_parsed,
18578         .data = NULL,
18579         .help_str = "port config <port_id> tx_offload "
18580                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18581                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18582                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18583                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18584                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18585                     "match_metadata on|off",
18586         .tokens = {
18587                 (void *)&cmd_config_per_port_tx_offload_result_port,
18588                 (void *)&cmd_config_per_port_tx_offload_result_config,
18589                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18590                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18591                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18592                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18593                 NULL,
18594         }
18595 };
18596
18597 /* Enable/Disable a per queue offloading */
18598 struct cmd_config_per_queue_tx_offload_result {
18599         cmdline_fixed_string_t port;
18600         portid_t port_id;
18601         cmdline_fixed_string_t txq;
18602         uint16_t queue_id;
18603         cmdline_fixed_string_t tx_offload;
18604         cmdline_fixed_string_t offload;
18605         cmdline_fixed_string_t on_off;
18606 };
18607
18608 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18609         TOKEN_STRING_INITIALIZER
18610                 (struct cmd_config_per_queue_tx_offload_result,
18611                  port, "port");
18612 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18613         TOKEN_NUM_INITIALIZER
18614                 (struct cmd_config_per_queue_tx_offload_result,
18615                  port_id, UINT16);
18616 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18617         TOKEN_STRING_INITIALIZER
18618                 (struct cmd_config_per_queue_tx_offload_result,
18619                  txq, "txq");
18620 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18621         TOKEN_NUM_INITIALIZER
18622                 (struct cmd_config_per_queue_tx_offload_result,
18623                  queue_id, UINT16);
18624 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18625         TOKEN_STRING_INITIALIZER
18626                 (struct cmd_config_per_queue_tx_offload_result,
18627                  tx_offload, "tx_offload");
18628 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18629         TOKEN_STRING_INITIALIZER
18630                 (struct cmd_config_per_queue_tx_offload_result,
18631                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18632                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18633                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18634                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18635                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18636 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18637         TOKEN_STRING_INITIALIZER
18638                 (struct cmd_config_per_queue_tx_offload_result,
18639                  on_off, "on#off");
18640
18641 static void
18642 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18643                                 __attribute__((unused)) struct cmdline *cl,
18644                                 __attribute__((unused)) void *data)
18645 {
18646         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18647         struct rte_eth_dev_info dev_info;
18648         portid_t port_id = res->port_id;
18649         uint16_t queue_id = res->queue_id;
18650         struct rte_port *port = &ports[port_id];
18651         uint64_t single_offload;
18652         int ret;
18653
18654         if (port->port_status != RTE_PORT_STOPPED) {
18655                 printf("Error: Can't config offload when Port %d "
18656                        "is not stopped\n", port_id);
18657                 return;
18658         }
18659
18660         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18661         if (ret != 0)
18662                 return;
18663
18664         if (queue_id >= dev_info.nb_tx_queues) {
18665                 printf("Error: input queue_id should be 0 ... "
18666                        "%d\n", dev_info.nb_tx_queues - 1);
18667                 return;
18668         }
18669
18670         single_offload = search_tx_offload(res->offload);
18671         if (single_offload == 0) {
18672                 printf("Unknown offload name: %s\n", res->offload);
18673                 return;
18674         }
18675
18676         if (!strcmp(res->on_off, "on"))
18677                 port->tx_conf[queue_id].offloads |= single_offload;
18678         else
18679                 port->tx_conf[queue_id].offloads &= ~single_offload;
18680
18681         cmd_reconfig_device_queue(port_id, 1, 1);
18682 }
18683
18684 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18685         .f = cmd_config_per_queue_tx_offload_parsed,
18686         .data = NULL,
18687         .help_str = "port <port_id> txq <queue_id> tx_offload "
18688                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18689                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18690                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18691                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18692                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18693                     "on|off",
18694         .tokens = {
18695                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18696                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18697                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18698                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18699                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18700                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18701                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18702                 NULL,
18703         }
18704 };
18705
18706 /* *** configure tx_metadata for specific port *** */
18707 struct cmd_config_tx_metadata_specific_result {
18708         cmdline_fixed_string_t port;
18709         cmdline_fixed_string_t keyword;
18710         uint16_t port_id;
18711         cmdline_fixed_string_t item;
18712         uint32_t value;
18713 };
18714
18715 static void
18716 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18717                                 __attribute__((unused)) struct cmdline *cl,
18718                                 __attribute__((unused)) void *data)
18719 {
18720         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18721
18722         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18723                 return;
18724         ports[res->port_id].tx_metadata = res->value;
18725         /* Add/remove callback to insert valid metadata in every Tx packet. */
18726         if (ports[res->port_id].tx_metadata)
18727                 add_tx_md_callback(res->port_id);
18728         else
18729                 remove_tx_md_callback(res->port_id);
18730         rte_flow_dynf_metadata_register();
18731 }
18732
18733 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18734         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18735                         port, "port");
18736 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18737         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18738                         keyword, "config");
18739 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18740         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18741                         port_id, UINT16);
18742 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18743         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18744                         item, "tx_metadata");
18745 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18746         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18747                         value, UINT32);
18748
18749 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18750         .f = cmd_config_tx_metadata_specific_parsed,
18751         .data = NULL,
18752         .help_str = "port config <port_id> tx_metadata <value>",
18753         .tokens = {
18754                 (void *)&cmd_config_tx_metadata_specific_port,
18755                 (void *)&cmd_config_tx_metadata_specific_keyword,
18756                 (void *)&cmd_config_tx_metadata_specific_id,
18757                 (void *)&cmd_config_tx_metadata_specific_item,
18758                 (void *)&cmd_config_tx_metadata_specific_value,
18759                 NULL,
18760         },
18761 };
18762
18763 /* *** display tx_metadata per port configuration *** */
18764 struct cmd_show_tx_metadata_result {
18765         cmdline_fixed_string_t cmd_show;
18766         cmdline_fixed_string_t cmd_port;
18767         cmdline_fixed_string_t cmd_keyword;
18768         portid_t cmd_pid;
18769 };
18770
18771 static void
18772 cmd_show_tx_metadata_parsed(void *parsed_result,
18773                 __attribute__((unused)) struct cmdline *cl,
18774                 __attribute__((unused)) void *data)
18775 {
18776         struct cmd_show_tx_metadata_result *res = parsed_result;
18777
18778         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18779                 printf("invalid port id %u\n", res->cmd_pid);
18780                 return;
18781         }
18782         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18783                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18784                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18785         }
18786 }
18787
18788 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18789         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18790                         cmd_show, "show");
18791 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18792         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18793                         cmd_port, "port");
18794 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18795         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18796                         cmd_pid, UINT16);
18797 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18798         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18799                         cmd_keyword, "tx_metadata");
18800
18801 cmdline_parse_inst_t cmd_show_tx_metadata = {
18802         .f = cmd_show_tx_metadata_parsed,
18803         .data = NULL,
18804         .help_str = "show port <port_id> tx_metadata",
18805         .tokens = {
18806                 (void *)&cmd_show_tx_metadata_show,
18807                 (void *)&cmd_show_tx_metadata_port,
18808                 (void *)&cmd_show_tx_metadata_pid,
18809                 (void *)&cmd_show_tx_metadata_keyword,
18810                 NULL,
18811         },
18812 };
18813
18814 /* show port supported ptypes */
18815
18816 /* Common result structure for show port ptypes */
18817 struct cmd_show_port_supported_ptypes_result {
18818         cmdline_fixed_string_t show;
18819         cmdline_fixed_string_t port;
18820         portid_t port_id;
18821         cmdline_fixed_string_t ptypes;
18822 };
18823
18824 /* Common CLI fields for show port ptypes */
18825 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
18826         TOKEN_STRING_INITIALIZER
18827                 (struct cmd_show_port_supported_ptypes_result,
18828                  show, "show");
18829 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
18830         TOKEN_STRING_INITIALIZER
18831                 (struct cmd_show_port_supported_ptypes_result,
18832                  port, "port");
18833 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
18834         TOKEN_NUM_INITIALIZER
18835                 (struct cmd_show_port_supported_ptypes_result,
18836                  port_id, UINT16);
18837 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
18838         TOKEN_STRING_INITIALIZER
18839                 (struct cmd_show_port_supported_ptypes_result,
18840                  ptypes, "ptypes");
18841
18842 static void
18843 cmd_show_port_supported_ptypes_parsed(
18844         void *parsed_result,
18845         __attribute__((unused)) struct cmdline *cl,
18846         __attribute__((unused)) void *data)
18847 {
18848 #define RSVD_PTYPE_MASK       0xf0000000
18849 #define MAX_PTYPES_PER_LAYER  16
18850 #define LTYPE_NAMESIZE        32
18851 #define PTYPE_NAMESIZE        256
18852         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
18853         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
18854         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
18855         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
18856         uint16_t port_id = res->port_id;
18857         int ret, i;
18858
18859         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
18860         if (ret < 0)
18861                 return;
18862
18863         while (ptype_mask != RSVD_PTYPE_MASK) {
18864
18865                 switch (ptype_mask) {
18866                 case RTE_PTYPE_L2_MASK:
18867                         strlcpy(ltype, "L2", sizeof(ltype));
18868                         break;
18869                 case RTE_PTYPE_L3_MASK:
18870                         strlcpy(ltype, "L3", sizeof(ltype));
18871                         break;
18872                 case RTE_PTYPE_L4_MASK:
18873                         strlcpy(ltype, "L4", sizeof(ltype));
18874                         break;
18875                 case RTE_PTYPE_TUNNEL_MASK:
18876                         strlcpy(ltype, "Tunnel", sizeof(ltype));
18877                         break;
18878                 case RTE_PTYPE_INNER_L2_MASK:
18879                         strlcpy(ltype, "Inner L2", sizeof(ltype));
18880                         break;
18881                 case RTE_PTYPE_INNER_L3_MASK:
18882                         strlcpy(ltype, "Inner L3", sizeof(ltype));
18883                         break;
18884                 case RTE_PTYPE_INNER_L4_MASK:
18885                         strlcpy(ltype, "Inner L4", sizeof(ltype));
18886                         break;
18887                 default:
18888                         return;
18889                 }
18890
18891                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
18892                                                        ptype_mask, ptypes,
18893                                                        MAX_PTYPES_PER_LAYER);
18894
18895                 if (ret > 0)
18896                         printf("Supported %s ptypes:\n", ltype);
18897                 else
18898                         printf("%s ptypes unsupported\n", ltype);
18899
18900                 for (i = 0; i < ret; ++i) {
18901                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
18902                         printf("%s\n", buf);
18903                 }
18904
18905                 ptype_mask <<= 4;
18906         }
18907 }
18908
18909 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
18910         .f = cmd_show_port_supported_ptypes_parsed,
18911         .data = NULL,
18912         .help_str = "show port <port_id> ptypes",
18913         .tokens = {
18914                 (void *)&cmd_show_port_supported_ptypes_show,
18915                 (void *)&cmd_show_port_supported_ptypes_port,
18916                 (void *)&cmd_show_port_supported_ptypes_port_id,
18917                 (void *)&cmd_show_port_supported_ptypes_ptypes,
18918                 NULL,
18919         },
18920 };
18921
18922 /* *** display rx/tx descriptor status *** */
18923 struct cmd_show_rx_tx_desc_status_result {
18924         cmdline_fixed_string_t cmd_show;
18925         cmdline_fixed_string_t cmd_port;
18926         cmdline_fixed_string_t cmd_keyword;
18927         cmdline_fixed_string_t cmd_desc;
18928         cmdline_fixed_string_t cmd_status;
18929         portid_t cmd_pid;
18930         portid_t cmd_qid;
18931         portid_t cmd_did;
18932 };
18933
18934 static void
18935 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
18936                 __attribute__((unused)) struct cmdline *cl,
18937                 __attribute__((unused)) void *data)
18938 {
18939         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
18940         int rc;
18941
18942         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18943                 printf("invalid port id %u\n", res->cmd_pid);
18944                 return;
18945         }
18946
18947         if (!strcmp(res->cmd_keyword, "rxq")) {
18948                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
18949                                              res->cmd_did);
18950                 if (rc < 0) {
18951                         printf("Invalid queueid = %d\n", res->cmd_qid);
18952                         return;
18953                 }
18954                 if (rc == RTE_ETH_RX_DESC_AVAIL)
18955                         printf("Desc status = AVAILABLE\n");
18956                 else if (rc == RTE_ETH_RX_DESC_DONE)
18957                         printf("Desc status = DONE\n");
18958                 else
18959                         printf("Desc status = UNAVAILABLE\n");
18960         } else if (!strcmp(res->cmd_keyword, "txq")) {
18961                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
18962                                              res->cmd_did);
18963                 if (rc < 0) {
18964                         printf("Invalid queueid = %d\n", res->cmd_qid);
18965                         return;
18966                 }
18967                 if (rc == RTE_ETH_TX_DESC_FULL)
18968                         printf("Desc status = FULL\n");
18969                 else if (rc == RTE_ETH_TX_DESC_DONE)
18970                         printf("Desc status = DONE\n");
18971                 else
18972                         printf("Desc status = UNAVAILABLE\n");
18973         }
18974 }
18975
18976 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
18977         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18978                         cmd_show, "show");
18979 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
18980         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18981                         cmd_port, "port");
18982 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
18983         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18984                         cmd_pid, UINT16);
18985 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
18986         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18987                         cmd_keyword, "rxq#txq");
18988 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
18989         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18990                         cmd_qid, UINT16);
18991 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
18992         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18993                         cmd_desc, "desc");
18994 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
18995         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18996                         cmd_did, UINT16);
18997 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
18998         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18999                         cmd_status, "status");
19000 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19001         .f = cmd_show_rx_tx_desc_status_parsed,
19002         .data = NULL,
19003         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19004                 "status",
19005         .tokens = {
19006                 (void *)&cmd_show_rx_tx_desc_status_show,
19007                 (void *)&cmd_show_rx_tx_desc_status_port,
19008                 (void *)&cmd_show_rx_tx_desc_status_pid,
19009                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19010                 (void *)&cmd_show_rx_tx_desc_status_qid,
19011                 (void *)&cmd_show_rx_tx_desc_status_desc,
19012                 (void *)&cmd_show_rx_tx_desc_status_did,
19013                 (void *)&cmd_show_rx_tx_desc_status_status,
19014                 NULL,
19015         },
19016 };
19017
19018 /* ******************************************************************************** */
19019
19020 /* list of instructions */
19021 cmdline_parse_ctx_t main_ctx[] = {
19022         (cmdline_parse_inst_t *)&cmd_help_brief,
19023         (cmdline_parse_inst_t *)&cmd_help_long,
19024         (cmdline_parse_inst_t *)&cmd_quit,
19025         (cmdline_parse_inst_t *)&cmd_load_from_file,
19026         (cmdline_parse_inst_t *)&cmd_showport,
19027         (cmdline_parse_inst_t *)&cmd_showqueue,
19028         (cmdline_parse_inst_t *)&cmd_showportall,
19029         (cmdline_parse_inst_t *)&cmd_showdevice,
19030         (cmdline_parse_inst_t *)&cmd_showcfg,
19031         (cmdline_parse_inst_t *)&cmd_showfwdall,
19032         (cmdline_parse_inst_t *)&cmd_start,
19033         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19034         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19035         (cmdline_parse_inst_t *)&cmd_set_link_up,
19036         (cmdline_parse_inst_t *)&cmd_set_link_down,
19037         (cmdline_parse_inst_t *)&cmd_reset,
19038         (cmdline_parse_inst_t *)&cmd_set_numbers,
19039         (cmdline_parse_inst_t *)&cmd_set_log,
19040         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19041         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19042         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19043         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19044         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19045         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19046         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19047         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19048         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19049         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19050         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19051         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19052         (cmdline_parse_inst_t *)&cmd_set_link_check,
19053         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19054         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19055         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19056         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19057 #ifdef RTE_LIBRTE_PMD_BOND
19058         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19059         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19060         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19061         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19062         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19063         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19064         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19065         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19066         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19067         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19068         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19069 #endif
19070         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19071         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19072         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19073         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19074         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19075         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19076         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19077         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19078         (cmdline_parse_inst_t *)&cmd_csum_set,
19079         (cmdline_parse_inst_t *)&cmd_csum_show,
19080         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19081         (cmdline_parse_inst_t *)&cmd_tso_set,
19082         (cmdline_parse_inst_t *)&cmd_tso_show,
19083         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19084         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19085         (cmdline_parse_inst_t *)&cmd_gro_enable,
19086         (cmdline_parse_inst_t *)&cmd_gro_flush,
19087         (cmdline_parse_inst_t *)&cmd_gro_show,
19088         (cmdline_parse_inst_t *)&cmd_gso_enable,
19089         (cmdline_parse_inst_t *)&cmd_gso_size,
19090         (cmdline_parse_inst_t *)&cmd_gso_show,
19091         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19092         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19093         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19094         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19095         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19096         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19097         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19098         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19099         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19100         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19101         (cmdline_parse_inst_t *)&cmd_config_dcb,
19102         (cmdline_parse_inst_t *)&cmd_read_reg,
19103         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19104         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19105         (cmdline_parse_inst_t *)&cmd_write_reg,
19106         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19107         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19108         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19109         (cmdline_parse_inst_t *)&cmd_stop,
19110         (cmdline_parse_inst_t *)&cmd_mac_addr,
19111         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19112         (cmdline_parse_inst_t *)&cmd_set_qmap,
19113         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19114         (cmdline_parse_inst_t *)&cmd_operate_port,
19115         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19116         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19117         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19118         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19119         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19120         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19121         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19122         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19123         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19124         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19125         (cmdline_parse_inst_t *)&cmd_config_mtu,
19126         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19127         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19128         (cmdline_parse_inst_t *)&cmd_config_rss,
19129         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19130         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19131         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19132         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19133         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19134         (cmdline_parse_inst_t *)&cmd_showport_reta,
19135         (cmdline_parse_inst_t *)&cmd_config_burst,
19136         (cmdline_parse_inst_t *)&cmd_config_thresh,
19137         (cmdline_parse_inst_t *)&cmd_config_threshold,
19138         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19139         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19140         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19141         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19142         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19143         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19144         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19145         (cmdline_parse_inst_t *)&cmd_global_config,
19146         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19147         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19148         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19149         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19150         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19151         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19152         (cmdline_parse_inst_t *)&cmd_dump,
19153         (cmdline_parse_inst_t *)&cmd_dump_one,
19154         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19155         (cmdline_parse_inst_t *)&cmd_syn_filter,
19156         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19157         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19158         (cmdline_parse_inst_t *)&cmd_flex_filter,
19159         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19160         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19161         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19162         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19163         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19164         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19165         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19166         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19167         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19168         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19169         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19170         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19171         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19172         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19173         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19174         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19175         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19176         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19177         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19178         (cmdline_parse_inst_t *)&cmd_flow,
19179         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19180         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19181         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19182         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19183         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19184         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19185         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19186         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19187         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19188         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19189         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19190         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19191         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19192         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19193         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19194         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19195         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19196         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19197         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19198         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19199         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19200         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19201         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19202         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19203         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19204         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19205         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19206         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19207         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19208         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19209         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19210         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19211         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19212         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19213         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19214         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19215         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19216         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19217         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19218         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19219         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19220         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19221         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19222         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19223         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19224         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19225         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19226         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19227         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19228 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19229         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19230 #endif
19231         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19232         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19233         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19234         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19235         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19236         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19237         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19238         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19239         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19240         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19241         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19242         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19243         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19244         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19245         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19246         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19247         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19248         (cmdline_parse_inst_t *)&cmd_ddp_add,
19249         (cmdline_parse_inst_t *)&cmd_ddp_del,
19250         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19251         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19252         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19253         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19254         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19255         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19256         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19257         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19258         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19259         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19260         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19261
19262         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19263         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19264         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19265         (cmdline_parse_inst_t *)&cmd_queue_region,
19266         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19267         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19268         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19269         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19270         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19271         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19272         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19273         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19274         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19275         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19276         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19277         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19278         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19279         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19280         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19281         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19282         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19283         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19284         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19285         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19286         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19287         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19288         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19289         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19290         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19291         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19292         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19293         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19294         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19295         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19296         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19297         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19298         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19299         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19300         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19301 #ifdef RTE_LIBRTE_BPF
19302         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19303         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19304 #endif
19305         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19306         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19307         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19308         (cmdline_parse_inst_t *)&cmd_set_raw,
19309         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19310         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19311         NULL,
19312 };
19313
19314 /* read cmdline commands from file */
19315 void
19316 cmdline_read_from_file(const char *filename)
19317 {
19318         struct cmdline *cl;
19319
19320         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19321         if (cl == NULL) {
19322                 printf("Failed to create file based cmdline context: %s\n",
19323                        filename);
19324                 return;
19325         }
19326
19327         cmdline_interact(cl);
19328         cmdline_quit(cl);
19329
19330         cmdline_free(cl);
19331
19332         printf("Read CLI commands from %s\n", filename);
19333 }
19334
19335 /* prompt function, called from main on MASTER lcore */
19336 void
19337 prompt(void)
19338 {
19339         /* initialize non-constant commands */
19340         cmd_set_fwd_mode_init();
19341         cmd_set_fwd_retry_mode_init();
19342
19343         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19344         if (testpmd_cl == NULL)
19345                 return;
19346         cmdline_interact(testpmd_cl);
19347         cmdline_stdin_exit(testpmd_cl);
19348 }
19349
19350 void
19351 prompt_exit(void)
19352 {
19353         if (testpmd_cl != NULL)
19354                 cmdline_quit(testpmd_cl);
19355 }
19356
19357 static void
19358 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19359 {
19360         if (id == (portid_t)RTE_PORT_ALL) {
19361                 portid_t pid;
19362
19363                 RTE_ETH_FOREACH_DEV(pid) {
19364                         /* check if need_reconfig has been set to 1 */
19365                         if (ports[pid].need_reconfig == 0)
19366                                 ports[pid].need_reconfig = dev;
19367                         /* check if need_reconfig_queues has been set to 1 */
19368                         if (ports[pid].need_reconfig_queues == 0)
19369                                 ports[pid].need_reconfig_queues = queue;
19370                 }
19371         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19372                 /* check if need_reconfig has been set to 1 */
19373                 if (ports[id].need_reconfig == 0)
19374                         ports[id].need_reconfig = dev;
19375                 /* check if need_reconfig_queues has been set to 1 */
19376                 if (ports[id].need_reconfig_queues == 0)
19377                         ports[id].need_reconfig_queues = queue;
19378         }
19379 }