app/testpmd: support QinQ offload in VLAN set command
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #ifdef __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         }
245
246         if (show_all || !strcmp(res->section, "config")) {
247                 cmdline_printf(
248                         cl,
249                         "\n"
250                         "Configuration:\n"
251                         "--------------\n"
252                         "Configuration changes only become active when"
253                         " forwarding is started/restarted.\n\n"
254
255                         "set default\n"
256                         "    Reset forwarding to the default configuration.\n\n"
257
258                         "set verbose (level)\n"
259                         "    Set the debug verbosity level X.\n\n"
260
261                         "set log global|(type) (level)\n"
262                         "    Set the log level.\n\n"
263
264                         "set nbport (num)\n"
265                         "    Set number of ports.\n\n"
266
267                         "set nbcore (num)\n"
268                         "    Set number of cores.\n\n"
269
270                         "set coremask (mask)\n"
271                         "    Set the forwarding cores hexadecimal mask.\n\n"
272
273                         "set portmask (mask)\n"
274                         "    Set the forwarding ports hexadecimal mask.\n\n"
275
276                         "set burst (num)\n"
277                         "    Set number of packets per burst.\n\n"
278
279                         "set burst tx delay (microseconds) retry (num)\n"
280                         "    Set the transmit delay time and number of retries,"
281                         " effective when retry is enabled.\n\n"
282
283                         "set txpkts (x[,y]*)\n"
284                         "    Set the length of each segment of TXONLY"
285                         " and optionally CSUM packets.\n\n"
286
287                         "set txsplit (off|on|rand)\n"
288                         "    Set the split policy for the TX packets."
289                         " Right now only applicable for CSUM and TXONLY"
290                         " modes\n\n"
291
292                         "set corelist (x[,y]*)\n"
293                         "    Set the list of forwarding cores.\n\n"
294
295                         "set portlist (x[,y]*)\n"
296                         "    Set the list of forwarding ports.\n\n"
297
298                         "set port setup on (iterator|event)\n"
299                         "    Select how attached port is retrieved for setup.\n\n"
300
301                         "set tx loopback (port_id) (on|off)\n"
302                         "    Enable or disable tx loopback.\n\n"
303
304                         "set all queues drop (port_id) (on|off)\n"
305                         "    Set drop enable bit for all queues.\n\n"
306
307                         "set vf split drop (port_id) (vf_id) (on|off)\n"
308                         "    Set split drop enable bit for a VF from the PF.\n\n"
309
310                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
311                         "    Set MAC antispoof for a VF from the PF.\n\n"
312
313                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
314                         "    Enable MACsec offload.\n\n"
315
316                         "set macsec offload (port_id) off\n"
317                         "    Disable MACsec offload.\n\n"
318
319                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
320                         "    Configure MACsec secure connection (SC).\n\n"
321
322                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
323                         "    Configure MACsec secure association (SA).\n\n"
324
325                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
326                         "    Set VF broadcast for a VF from the PF.\n\n"
327
328                         "vlan set stripq (on|off) (port_id,queue_id)\n"
329                         "    Set the VLAN strip for a queue on a port.\n\n"
330
331                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
332                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
333
334                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
335                         "    Set VLAN insert for a VF from the PF.\n\n"
336
337                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
338                         "    Set VLAN antispoof for a VF from the PF.\n\n"
339
340                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
341                         "    Set VLAN tag for a VF from the PF.\n\n"
342
343                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
344                         "    Set a VF's max bandwidth(Mbps).\n\n"
345
346                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
347                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
348
349                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
350                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
351
352                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
353                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
354
355                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
356                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
357
358                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
359                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
360
361                         "vlan set (inner|outer) tpid (value) (port_id)\n"
362                         "    Set the VLAN TPID for Packet Filtering on"
363                         " a port\n\n"
364
365                         "rx_vlan add (vlan_id|all) (port_id)\n"
366                         "    Add a vlan_id, or all identifiers, to the set"
367                         " of VLAN identifiers filtered by port_id.\n\n"
368
369                         "rx_vlan rm (vlan_id|all) (port_id)\n"
370                         "    Remove a vlan_id, or all identifiers, from the set"
371                         " of VLAN identifiers filtered by port_id.\n\n"
372
373                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
374                         "    Add a vlan_id, to the set of VLAN identifiers"
375                         "filtered for VF(s) from port_id.\n\n"
376
377                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
378                         "    Remove a vlan_id, to the set of VLAN identifiers"
379                         "filtered for VF(s) from port_id.\n\n"
380
381                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
382                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
383                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
384                         "   add a tunnel filter of a port.\n\n"
385
386                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
387                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
388                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
389                         "   remove a tunnel filter of a port.\n\n"
390
391                         "rx_vxlan_port add (udp_port) (port_id)\n"
392                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
393
394                         "rx_vxlan_port rm (udp_port) (port_id)\n"
395                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
396
397                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
398                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
399                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
400
401                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
402                         "    Set port based TX VLAN insertion.\n\n"
403
404                         "tx_vlan reset (port_id)\n"
405                         "    Disable hardware insertion of a VLAN header in"
406                         " packets sent on a port.\n\n"
407
408                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
409                         "    Select hardware or software calculation of the"
410                         " checksum when transmitting a packet using the"
411                         " csum forward engine.\n"
412                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
413                         "    outer-ip concerns the outer IP layer in"
414                         "    outer-udp concerns the outer UDP layer in"
415                         " case the packet is recognized as a tunnel packet by"
416                         " the forward engine (vxlan, gre and ipip are supported)\n"
417                         "    Please check the NIC datasheet for HW limits.\n\n"
418
419                         "csum parse-tunnel (on|off) (tx_port_id)\n"
420                         "    If disabled, treat tunnel packets as non-tunneled"
421                         " packets (treat inner headers as payload). The port\n"
422                         "    argument is the port used for TX in csum forward"
423                         " engine.\n\n"
424
425                         "csum show (port_id)\n"
426                         "    Display tx checksum offload configuration\n\n"
427
428                         "tso set (segsize) (portid)\n"
429                         "    Enable TCP Segmentation Offload in csum forward"
430                         " engine.\n"
431                         "    Please check the NIC datasheet for HW limits.\n\n"
432
433                         "tso show (portid)"
434                         "    Display the status of TCP Segmentation Offload.\n\n"
435
436                         "set port (port_id) gro on|off\n"
437                         "    Enable or disable Generic Receive Offload in"
438                         " csum forwarding engine.\n\n"
439
440                         "show port (port_id) gro\n"
441                         "    Display GRO configuration.\n\n"
442
443                         "set gro flush (cycles)\n"
444                         "    Set the cycle to flush GROed packets from"
445                         " reassembly tables.\n\n"
446
447                         "set port (port_id) gso (on|off)"
448                         "    Enable or disable Generic Segmentation Offload in"
449                         " csum forwarding engine.\n\n"
450
451                         "set gso segsz (length)\n"
452                         "    Set max packet length for output GSO segments,"
453                         " including packet header and payload.\n\n"
454
455                         "show port (port_id) gso\n"
456                         "    Show GSO configuration.\n\n"
457
458                         "set fwd (%s)\n"
459                         "    Set packet forwarding mode.\n\n"
460
461                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
462                         "    Add a MAC address on port_id.\n\n"
463
464                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
465                         "    Remove a MAC address from port_id.\n\n"
466
467                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Set the default MAC address for port_id.\n\n"
469
470                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
471                         "    Add a MAC address for a VF on the port.\n\n"
472
473                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
474                         "    Set the MAC address for a VF from the PF.\n\n"
475
476                         "set eth-peer (port_id) (peer_addr)\n"
477                         "    set the peer address for certain port.\n\n"
478
479                         "set port (port_id) uta (mac_address|all) (on|off)\n"
480                         "    Add/Remove a or all unicast hash filter(s)"
481                         "from port X.\n\n"
482
483                         "set promisc (port_id|all) (on|off)\n"
484                         "    Set the promiscuous mode on port_id, or all.\n\n"
485
486                         "set allmulti (port_id|all) (on|off)\n"
487                         "    Set the allmulti mode on port_id, or all.\n\n"
488
489                         "set vf promisc (port_id) (vf_id) (on|off)\n"
490                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
491
492                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
493                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
494
495                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
496                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
497                         " (on|off) autoneg (on|off) (port_id)\n"
498                         "set flow_ctrl rx (on|off) (portid)\n"
499                         "set flow_ctrl tx (on|off) (portid)\n"
500                         "set flow_ctrl high_water (high_water) (portid)\n"
501                         "set flow_ctrl low_water (low_water) (portid)\n"
502                         "set flow_ctrl pause_time (pause_time) (portid)\n"
503                         "set flow_ctrl send_xon (send_xon) (portid)\n"
504                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
505                         "set flow_ctrl autoneg (on|off) (port_id)\n"
506                         "    Set the link flow control parameter on a port.\n\n"
507
508                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
509                         " (low_water) (pause_time) (priority) (port_id)\n"
510                         "    Set the priority flow control parameter on a"
511                         " port.\n\n"
512
513                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
514                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
515                         " queue on port.\n"
516                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
517                         " on port 0 to mapping 5.\n\n"
518
519                         "set xstats-hide-zero on|off\n"
520                         "    Set the option to hide the zero values"
521                         " for xstats display.\n"
522
523                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
524                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
525
526                         "set port (port_id) vf (vf_id) (mac_addr)"
527                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
528                         "   Add/Remove unicast or multicast MAC addr filter"
529                         " for a VF.\n\n"
530
531                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
532                         "|MPE) (on|off)\n"
533                         "    AUPE:accepts untagged VLAN;"
534                         "ROPE:accept unicast hash\n\n"
535                         "    BAM:accepts broadcast packets;"
536                         "MPE:accepts all multicast packets\n\n"
537                         "    Enable/Disable a VF receive mode of a port\n\n"
538
539                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
540                         "    Set rate limit for a queue of a port\n\n"
541
542                         "set port (port_id) vf (vf_id) rate (rate_num) "
543                         "queue_mask (queue_mask_value)\n"
544                         "    Set rate limit for queues in VF of a port\n\n"
545
546                         "set port (port_id) mirror-rule (rule_id)"
547                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
548                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
549                         "   Set pool or vlan type mirror rule on a port.\n"
550                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
551                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
552                         " to pool 0.\n\n"
553
554                         "set port (port_id) mirror-rule (rule_id)"
555                         " (uplink-mirror|downlink-mirror) dst-pool"
556                         " (pool_id) (on|off)\n"
557                         "   Set uplink or downlink type mirror rule on a port.\n"
558                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
559                         " 0 on' enable mirror income traffic to pool 0.\n\n"
560
561                         "reset port (port_id) mirror-rule (rule_id)\n"
562                         "   Reset a mirror rule.\n\n"
563
564                         "set flush_rx (on|off)\n"
565                         "   Flush (default) or don't flush RX streams before"
566                         " forwarding. Mainly used with PCAP drivers.\n\n"
567
568                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
569                         "   Set the bypass mode for the lowest port on bypass enabled"
570                         " NIC.\n\n"
571
572                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
573                         "mode (normal|bypass|isolate) (port_id)\n"
574                         "   Set the event required to initiate specified bypass mode for"
575                         " the lowest port on a bypass enabled NIC where:\n"
576                         "       timeout   = enable bypass after watchdog timeout.\n"
577                         "       os_on     = enable bypass when OS/board is powered on.\n"
578                         "       os_off    = enable bypass when OS/board is powered off.\n"
579                         "       power_on  = enable bypass when power supply is turned on.\n"
580                         "       power_off = enable bypass when power supply is turned off."
581                         "\n\n"
582
583                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
584                         "   Set the bypass watchdog timeout to 'n' seconds"
585                         " where 0 = instant.\n\n"
586
587                         "show bypass config (port_id)\n"
588                         "   Show the bypass configuration for a bypass enabled NIC"
589                         " using the lowest port on the NIC.\n\n"
590
591 #ifdef RTE_LIBRTE_PMD_BOND
592                         "create bonded device (mode) (socket)\n"
593                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
594
595                         "add bonding slave (slave_id) (port_id)\n"
596                         "       Add a slave device to a bonded device.\n\n"
597
598                         "remove bonding slave (slave_id) (port_id)\n"
599                         "       Remove a slave device from a bonded device.\n\n"
600
601                         "set bonding mode (value) (port_id)\n"
602                         "       Set the bonding mode on a bonded device.\n\n"
603
604                         "set bonding primary (slave_id) (port_id)\n"
605                         "       Set the primary slave for a bonded device.\n\n"
606
607                         "show bonding config (port_id)\n"
608                         "       Show the bonding config for port_id.\n\n"
609
610                         "set bonding mac_addr (port_id) (address)\n"
611                         "       Set the MAC address of a bonded device.\n\n"
612
613                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
614                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
615
616                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
617                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
618
619                         "set bonding mon_period (port_id) (value)\n"
620                         "       Set the bonding link status monitoring polling period in ms.\n\n"
621
622                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
623                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
624
625 #endif
626                         "set link-up port (port_id)\n"
627                         "       Set link up for a port.\n\n"
628
629                         "set link-down port (port_id)\n"
630                         "       Set link down for a port.\n\n"
631
632                         "E-tag set insertion on port-tag-id (value)"
633                         " port (port_id) vf (vf_id)\n"
634                         "    Enable E-tag insertion for a VF on a port\n\n"
635
636                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
637                         "    Disable E-tag insertion for a VF on a port\n\n"
638
639                         "E-tag set stripping (on|off) port (port_id)\n"
640                         "    Enable/disable E-tag stripping on a port\n\n"
641
642                         "E-tag set forwarding (on|off) port (port_id)\n"
643                         "    Enable/disable E-tag based forwarding"
644                         " on a port\n\n"
645
646                         "E-tag set filter add e-tag-id (value) dst-pool"
647                         " (pool_id) port (port_id)\n"
648                         "    Add an E-tag forwarding filter on a port\n\n"
649
650                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
651                         "    Delete an E-tag forwarding filter on a port\n\n"
652
653                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
654                         "    Load a profile package on a port\n\n"
655
656                         "ddp del (port_id) (backup_profile_path)\n"
657                         "    Delete a profile package from a port\n\n"
658
659                         "ptype mapping get (port_id) (valid_only)\n"
660                         "    Get ptype mapping on a port\n\n"
661
662                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
663                         "    Replace target with the pkt_type in ptype mapping\n\n"
664
665                         "ptype mapping reset (port_id)\n"
666                         "    Reset ptype mapping on a port\n\n"
667
668                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
669                         "    Update a ptype mapping item on a port\n\n"
670
671                         "set port (port_id) queue-region region_id (value) "
672                         "queue_start_index (value) queue_num (value)\n"
673                         "    Set a queue region on a port\n\n"
674
675                         "set port (port_id) queue-region region_id (value) "
676                         "flowtype (value)\n"
677                         "    Set a flowtype region index on a port\n\n"
678
679                         "set port (port_id) queue-region UP (value) region_id (value)\n"
680                         "    Set the mapping of User Priority to "
681                         "queue region on a port\n\n"
682
683                         "set port (port_id) queue-region flush (on|off)\n"
684                         "    flush all queue region related configuration\n\n"
685
686                         "show port meter cap (port_id)\n"
687                         "    Show port meter capability information\n\n"
688
689                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
690                         "    meter profile add - srtcm rfc 2697\n\n"
691
692                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
693                         "    meter profile add - trtcm rfc 2698\n\n"
694
695                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
696                         "    meter profile add - trtcm rfc 4115\n\n"
697
698                         "del port meter profile (port_id) (profile_id)\n"
699                         "    meter profile delete\n\n"
700
701                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
702                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
703                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
704                         "(dscp_tbl_entry63)]\n"
705                         "    meter create\n\n"
706
707                         "enable port meter (port_id) (mtr_id)\n"
708                         "    meter enable\n\n"
709
710                         "disable port meter (port_id) (mtr_id)\n"
711                         "    meter disable\n\n"
712
713                         "del port meter (port_id) (mtr_id)\n"
714                         "    meter delete\n\n"
715
716                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
717                         "    meter update meter profile\n\n"
718
719                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
720                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
721                         "    update meter dscp table entries\n\n"
722
723                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
724                         "(action0) [(action1) (action2)]\n"
725                         "    meter update policer action\n\n"
726
727                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
728                         "    meter update stats\n\n"
729
730                         "show port (port_id) queue-region\n"
731                         "    show all queue region related configuration info\n\n"
732
733                         , list_pkt_forwarding_modes()
734                 );
735         }
736
737         if (show_all || !strcmp(res->section, "ports")) {
738
739                 cmdline_printf(
740                         cl,
741                         "\n"
742                         "Port Operations:\n"
743                         "----------------\n\n"
744
745                         "port start (port_id|all)\n"
746                         "    Start all ports or port_id.\n\n"
747
748                         "port stop (port_id|all)\n"
749                         "    Stop all ports or port_id.\n\n"
750
751                         "port close (port_id|all)\n"
752                         "    Close all ports or port_id.\n\n"
753
754                         "port reset (port_id|all)\n"
755                         "    Reset all ports or port_id.\n\n"
756
757                         "port attach (ident)\n"
758                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
759
760                         "port detach (port_id)\n"
761                         "    Detach physical or virtual dev by port_id\n\n"
762
763                         "port config (port_id|all)"
764                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
765                         " duplex (half|full|auto)\n"
766                         "    Set speed and duplex for all ports or port_id\n\n"
767
768                         "port config (port_id|all) loopback (mode)\n"
769                         "    Set loopback mode for all ports or port_id\n\n"
770
771                         "port config all (rxq|txq|rxd|txd) (value)\n"
772                         "    Set number for rxq/txq/rxd/txd.\n\n"
773
774                         "port config all max-pkt-len (value)\n"
775                         "    Set the max packet length.\n\n"
776
777                         "port config all drop-en (on|off)\n"
778                         "    Enable or disable packet drop on all RX queues of all ports when no "
779                         "receive buffers available.\n\n"
780
781                         "port config all rss (all|default|ip|tcp|udp|sctp|"
782                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
783                         "    Set the RSS mode.\n\n"
784
785                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
786                         "    Set the RSS redirection table.\n\n"
787
788                         "port config (port_id) dcb vt (on|off) (traffic_class)"
789                         " pfc (on|off)\n"
790                         "    Set the DCB mode.\n\n"
791
792                         "port config all burst (value)\n"
793                         "    Set the number of packets per burst.\n\n"
794
795                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
796                         " (value)\n"
797                         "    Set the ring prefetch/host/writeback threshold"
798                         " for tx/rx queue.\n\n"
799
800                         "port config all (txfreet|txrst|rxfreet) (value)\n"
801                         "    Set free threshold for rx/tx, or set"
802                         " tx rs bit threshold.\n\n"
803                         "port config mtu X value\n"
804                         "    Set the MTU of port X to a given value\n\n"
805
806                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
807                         "    Set a rx/tx queue's ring size configuration, the new"
808                         " value will take effect after command that (re-)start the port"
809                         " or command that setup the specific queue\n\n"
810
811                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
812                         "    Start/stop a rx/tx queue of port X. Only take effect"
813                         " when port X is started\n\n"
814
815                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
816                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
817                         " take effect when port X is stopped.\n\n"
818
819                         "port (port_id) (rxq|txq) (queue_id) setup\n"
820                         "    Setup a rx/tx queue of port X.\n\n"
821
822                         "port config (port_id|all) l2-tunnel E-tag ether-type"
823                         " (value)\n"
824                         "    Set the value of E-tag ether-type.\n\n"
825
826                         "port config (port_id|all) l2-tunnel E-tag"
827                         " (enable|disable)\n"
828                         "    Enable/disable the E-tag support.\n\n"
829
830                         "port config (port_id) pctype mapping reset\n"
831                         "    Reset flow type to pctype mapping on a port\n\n"
832
833                         "port config (port_id) pctype mapping update"
834                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
835                         "    Update a flow type to pctype mapping item on a port\n\n"
836
837                         "port config (port_id) pctype (pctype_id) hash_inset|"
838                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
839                         " (field_idx)\n"
840                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
841
842                         "port config (port_id) pctype (pctype_id) hash_inset|"
843                         "fdir_inset|fdir_flx_inset clear all"
844                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
845
846                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
847                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
848
849                         "port config <port_id> rx_offload vlan_strip|"
850                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
851                         "outer_ipv4_cksum|macsec_strip|header_split|"
852                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
853                         "scatter|timestamp|security|keep_crc on|off\n"
854                         "     Enable or disable a per port Rx offloading"
855                         " on all Rx queues of a port\n\n"
856
857                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
858                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
859                         "outer_ipv4_cksum|macsec_strip|header_split|"
860                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
861                         "scatter|timestamp|security|keep_crc on|off\n"
862                         "    Enable or disable a per queue Rx offloading"
863                         " only on a specific Rx queue\n\n"
864
865                         "port config (port_id) tx_offload vlan_insert|"
866                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
867                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
868                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
869                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
870                         "security|match_metadata on|off\n"
871                         "    Enable or disable a per port Tx offloading"
872                         " on all Tx queues of a port\n\n"
873
874                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
875                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
876                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
877                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
878                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
879                         " on|off\n"
880                         "    Enable or disable a per queue Tx offloading"
881                         " only on a specific Tx queue\n\n"
882
883                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
884                         "    Load an eBPF program as a callback"
885                         " for particular RX/TX queue\n\n"
886
887                         "bpf-unload rx|tx (port) (queue)\n"
888                         "    Unload previously loaded eBPF program"
889                         " for particular RX/TX queue\n\n"
890
891                         "port config (port_id) tx_metadata (value)\n"
892                         "    Set Tx metadata value per port. Testpmd will add this value"
893                         " to any Tx packet sent from this port\n\n"
894                 );
895         }
896
897         if (show_all || !strcmp(res->section, "registers")) {
898
899                 cmdline_printf(
900                         cl,
901                         "\n"
902                         "Registers:\n"
903                         "----------\n\n"
904
905                         "read reg (port_id) (address)\n"
906                         "    Display value of a port register.\n\n"
907
908                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
909                         "    Display a port register bit field.\n\n"
910
911                         "read regbit (port_id) (address) (bit_x)\n"
912                         "    Display a single port register bit.\n\n"
913
914                         "write reg (port_id) (address) (value)\n"
915                         "    Set value of a port register.\n\n"
916
917                         "write regfield (port_id) (address) (bit_x) (bit_y)"
918                         " (value)\n"
919                         "    Set bit field of a port register.\n\n"
920
921                         "write regbit (port_id) (address) (bit_x) (value)\n"
922                         "    Set single bit value of a port register.\n\n"
923                 );
924         }
925         if (show_all || !strcmp(res->section, "filters")) {
926
927                 cmdline_printf(
928                         cl,
929                         "\n"
930                         "filters:\n"
931                         "--------\n\n"
932
933                         "ethertype_filter (port_id) (add|del)"
934                         " (mac_addr|mac_ignr) (mac_address) ethertype"
935                         " (ether_type) (drop|fwd) queue (queue_id)\n"
936                         "    Add/Del an ethertype filter.\n\n"
937
938                         "2tuple_filter (port_id) (add|del)"
939                         " dst_port (dst_port_value) protocol (protocol_value)"
940                         " mask (mask_value) tcp_flags (tcp_flags_value)"
941                         " priority (prio_value) queue (queue_id)\n"
942                         "    Add/Del a 2tuple filter.\n\n"
943
944                         "5tuple_filter (port_id) (add|del)"
945                         " dst_ip (dst_address) src_ip (src_address)"
946                         " dst_port (dst_port_value) src_port (src_port_value)"
947                         " protocol (protocol_value)"
948                         " mask (mask_value) tcp_flags (tcp_flags_value)"
949                         " priority (prio_value) queue (queue_id)\n"
950                         "    Add/Del a 5tuple filter.\n\n"
951
952                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
953                         "    Add/Del syn filter.\n\n"
954
955                         "flex_filter (port_id) (add|del) len (len_value)"
956                         " bytes (bytes_value) mask (mask_value)"
957                         " priority (prio_value) queue (queue_id)\n"
958                         "    Add/Del a flex filter.\n\n"
959
960                         "flow_director_filter (port_id) mode IP (add|del|update)"
961                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
962                         " src (src_ip_address) dst (dst_ip_address)"
963                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
964                         " vlan (vlan_value) flexbytes (flexbytes_value)"
965                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
966                         " fd_id (fd_id_value)\n"
967                         "    Add/Del an IP type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
971                         " src (src_ip_address) (src_port)"
972                         " dst (dst_ip_address) (dst_port)"
973                         " tos (tos_value) ttl (ttl_value)"
974                         " vlan (vlan_value) flexbytes (flexbytes_value)"
975                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
976                         " fd_id (fd_id_value)\n"
977                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
978
979                         "flow_director_filter (port_id) mode IP (add|del|update)"
980                         " flow (ipv4-sctp|ipv6-sctp)"
981                         " src (src_ip_address) (src_port)"
982                         " dst (dst_ip_address) (dst_port)"
983                         " tag (verification_tag) "
984                         " tos (tos_value) ttl (ttl_value)"
985                         " vlan (vlan_value)"
986                         " flexbytes (flexbytes_value) (drop|fwd)"
987                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
988                         "    Add/Del a SCTP type flow director filter.\n\n"
989
990                         "flow_director_filter (port_id) mode IP (add|del|update)"
991                         " flow l2_payload ether (ethertype)"
992                         " flexbytes (flexbytes_value) (drop|fwd)"
993                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
994                         "    Add/Del a l2 payload type flow director filter.\n\n"
995
996                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
997                         " mac (mac_address) vlan (vlan_value)"
998                         " flexbytes (flexbytes_value) (drop|fwd)"
999                         " queue (queue_id) fd_id (fd_id_value)\n"
1000                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1001
1002                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1003                         " mac (mac_address) vlan (vlan_value)"
1004                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1005                         " flexbytes (flexbytes_value) (drop|fwd)"
1006                         " queue (queue_id) fd_id (fd_id_value)\n"
1007                         "    Add/Del a Tunnel flow director filter.\n\n"
1008
1009                         "flow_director_filter (port_id) mode raw (add|del|update)"
1010                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1011                         " fd_id (fd_id_value) packet (packet file name)\n"
1012                         "    Add/Del a raw type flow director filter.\n\n"
1013
1014                         "flush_flow_director (port_id)\n"
1015                         "    Flush all flow director entries of a device.\n\n"
1016
1017                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1018                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1019                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1020                         "    Set flow director IP mask.\n\n"
1021
1022                         "flow_director_mask (port_id) mode MAC-VLAN"
1023                         " vlan (vlan_value)\n"
1024                         "    Set flow director MAC-VLAN mask.\n\n"
1025
1026                         "flow_director_mask (port_id) mode Tunnel"
1027                         " vlan (vlan_value) mac (mac_value)"
1028                         " tunnel-type (tunnel_type_value)"
1029                         " tunnel-id (tunnel_id_value)\n"
1030                         "    Set flow director Tunnel mask.\n\n"
1031
1032                         "flow_director_flex_mask (port_id)"
1033                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1034                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1035                         " (mask)\n"
1036                         "    Configure mask of flex payload.\n\n"
1037
1038                         "flow_director_flex_payload (port_id)"
1039                         " (raw|l2|l3|l4) (config)\n"
1040                         "    Configure flex payload selection.\n\n"
1041
1042                         "get_sym_hash_ena_per_port (port_id)\n"
1043                         "    get symmetric hash enable configuration per port.\n\n"
1044
1045                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1046                         "    set symmetric hash enable configuration per port"
1047                         " to enable or disable.\n\n"
1048
1049                         "get_hash_global_config (port_id)\n"
1050                         "    Get the global configurations of hash filters.\n\n"
1051
1052                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1053                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1054                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1055                         " (enable|disable)\n"
1056                         "    Set the global configurations of hash filters.\n\n"
1057
1058                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1059                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1060                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1061                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1062                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1063                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1064                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1065                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1066                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1067                         "fld-8th|none) (select|add)\n"
1068                         "    Set the input set for hash.\n\n"
1069
1070                         "set_fdir_input_set (port_id) "
1071                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1072                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1073                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1074                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1075                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1076                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1077                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1078                         " (select|add)\n"
1079                         "    Set the input set for FDir.\n\n"
1080
1081                         "flow validate {port_id}"
1082                         " [group {group_id}] [priority {level}]"
1083                         " [ingress] [egress]"
1084                         " pattern {item} [/ {item} [...]] / end"
1085                         " actions {action} [/ {action} [...]] / end\n"
1086                         "    Check whether a flow rule can be created.\n\n"
1087
1088                         "flow create {port_id}"
1089                         " [group {group_id}] [priority {level}]"
1090                         " [ingress] [egress]"
1091                         " pattern {item} [/ {item} [...]] / end"
1092                         " actions {action} [/ {action} [...]] / end\n"
1093                         "    Create a flow rule.\n\n"
1094
1095                         "flow destroy {port_id} rule {rule_id} [...]\n"
1096                         "    Destroy specific flow rules.\n\n"
1097
1098                         "flow flush {port_id}\n"
1099                         "    Destroy all flow rules.\n\n"
1100
1101                         "flow query {port_id} {rule_id} {action}\n"
1102                         "    Query an existing flow rule.\n\n"
1103
1104                         "flow list {port_id} [group {group_id}] [...]\n"
1105                         "    List existing flow rules sorted by priority,"
1106                         " filtered by group identifiers.\n\n"
1107
1108                         "flow isolate {port_id} {boolean}\n"
1109                         "    Restrict ingress traffic to the defined"
1110                         " flow rules\n\n"
1111
1112                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1113                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1114                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1115                         "       Configure the VXLAN encapsulation for flows.\n\n"
1116
1117                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1118                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1119                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1120                         " eth-dst (eth-dst)\n"
1121                         "       Configure the VXLAN encapsulation for flows.\n\n"
1122
1123                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1124                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1125                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1126                         " eth-dst (eth-dst)\n"
1127                         "       Configure the VXLAN encapsulation for flows.\n\n"
1128
1129                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1130                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1131                         " (eth-dst)\n"
1132                         "       Configure the NVGRE encapsulation for flows.\n\n"
1133
1134                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1135                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1136                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1137                         "       Configure the NVGRE encapsulation for flows.\n\n"
1138
1139                         "set raw_encap {flow items}\n"
1140                         "       Configure the encapsulation with raw data.\n\n"
1141
1142                         "set raw_decap {flow items}\n"
1143                         "       Configure the decapsulation with raw data.\n\n"
1144
1145                 );
1146         }
1147
1148         if (show_all || !strcmp(res->section, "traffic_management")) {
1149                 cmdline_printf(
1150                         cl,
1151                         "\n"
1152                         "Traffic Management:\n"
1153                         "--------------\n"
1154                         "show port tm cap (port_id)\n"
1155                         "       Display the port TM capability.\n\n"
1156
1157                         "show port tm level cap (port_id) (level_id)\n"
1158                         "       Display the port TM hierarchical level capability.\n\n"
1159
1160                         "show port tm node cap (port_id) (node_id)\n"
1161                         "       Display the port TM node capability.\n\n"
1162
1163                         "show port tm node type (port_id) (node_id)\n"
1164                         "       Display the port TM node type.\n\n"
1165
1166                         "show port tm node stats (port_id) (node_id) (clear)\n"
1167                         "       Display the port TM node stats.\n\n"
1168
1169 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1170                         "set port tm hierarchy default (port_id)\n"
1171                         "       Set default traffic Management hierarchy on a port\n\n"
1172 #endif
1173
1174                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1175                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1176                         " (packet_length_adjust)\n"
1177                         "       Add port tm node private shaper profile.\n\n"
1178
1179                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1180                         "       Delete port tm node private shaper profile.\n\n"
1181
1182                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1183                         " (shaper_profile_id)\n"
1184                         "       Add/update port tm node shared shaper.\n\n"
1185
1186                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1187                         "       Delete port tm node shared shaper.\n\n"
1188
1189                         "set port tm node shaper profile (port_id) (node_id)"
1190                         " (shaper_profile_id)\n"
1191                         "       Set port tm node shaper profile.\n\n"
1192
1193                         "add port tm node wred profile (port_id) (wred_profile_id)"
1194                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1195                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1196                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1197                         "       Add port tm node wred profile.\n\n"
1198
1199                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1200                         "       Delete port tm node wred profile.\n\n"
1201
1202                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1203                         " (priority) (weight) (level_id) (shaper_profile_id)"
1204                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1205                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1206                         "       Add port tm nonleaf node.\n\n"
1207
1208                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1209                         " (priority) (weight) (level_id) (shaper_profile_id)"
1210                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1211                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1212                         "       Add port tm leaf node.\n\n"
1213
1214                         "del port tm node (port_id) (node_id)\n"
1215                         "       Delete port tm node.\n\n"
1216
1217                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1218                         " (priority) (weight)\n"
1219                         "       Set port tm node parent.\n\n"
1220
1221                         "suspend port tm node (port_id) (node_id)"
1222                         "       Suspend tm node.\n\n"
1223
1224                         "resume port tm node (port_id) (node_id)"
1225                         "       Resume tm node.\n\n"
1226
1227                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1228                         "       Commit tm hierarchy.\n\n"
1229
1230                         "set port tm mark ip_ecn (port) (green) (yellow)"
1231                         " (red)\n"
1232                         "    Enables/Disables the traffic management marking"
1233                         " for IP ECN (Explicit Congestion Notification)"
1234                         " packets on a given port\n\n"
1235
1236                         "set port tm mark ip_dscp (port) (green) (yellow)"
1237                         " (red)\n"
1238                         "    Enables/Disables the traffic management marking"
1239                         " on the port for IP dscp packets\n\n"
1240
1241                         "set port tm mark vlan_dei (port) (green) (yellow)"
1242                         " (red)\n"
1243                         "    Enables/Disables the traffic management marking"
1244                         " on the port for VLAN packets with DEI enabled\n\n"
1245                 );
1246         }
1247
1248         if (show_all || !strcmp(res->section, "devices")) {
1249                 cmdline_printf(
1250                         cl,
1251                         "\n"
1252                         "Device Operations:\n"
1253                         "--------------\n"
1254                         "device detach (identifier)\n"
1255                         "       Detach device by identifier.\n\n"
1256                 );
1257         }
1258
1259 }
1260
1261 cmdline_parse_token_string_t cmd_help_long_help =
1262         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1263
1264 cmdline_parse_token_string_t cmd_help_long_section =
1265         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1266                         "all#control#display#config#"
1267                         "ports#registers#filters#traffic_management#devices");
1268
1269 cmdline_parse_inst_t cmd_help_long = {
1270         .f = cmd_help_long_parsed,
1271         .data = NULL,
1272         .help_str = "help all|control|display|config|ports|register|"
1273                 "filters|traffic_management|devices: "
1274                 "Show help",
1275         .tokens = {
1276                 (void *)&cmd_help_long_help,
1277                 (void *)&cmd_help_long_section,
1278                 NULL,
1279         },
1280 };
1281
1282
1283 /* *** start/stop/close all ports *** */
1284 struct cmd_operate_port_result {
1285         cmdline_fixed_string_t keyword;
1286         cmdline_fixed_string_t name;
1287         cmdline_fixed_string_t value;
1288 };
1289
1290 static void cmd_operate_port_parsed(void *parsed_result,
1291                                 __attribute__((unused)) struct cmdline *cl,
1292                                 __attribute__((unused)) void *data)
1293 {
1294         struct cmd_operate_port_result *res = parsed_result;
1295
1296         if (!strcmp(res->name, "start"))
1297                 start_port(RTE_PORT_ALL);
1298         else if (!strcmp(res->name, "stop"))
1299                 stop_port(RTE_PORT_ALL);
1300         else if (!strcmp(res->name, "close"))
1301                 close_port(RTE_PORT_ALL);
1302         else if (!strcmp(res->name, "reset"))
1303                 reset_port(RTE_PORT_ALL);
1304         else
1305                 printf("Unknown parameter\n");
1306 }
1307
1308 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1309         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1310                                                                 "port");
1311 cmdline_parse_token_string_t cmd_operate_port_all_port =
1312         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1313                                                 "start#stop#close#reset");
1314 cmdline_parse_token_string_t cmd_operate_port_all_all =
1315         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1316
1317 cmdline_parse_inst_t cmd_operate_port = {
1318         .f = cmd_operate_port_parsed,
1319         .data = NULL,
1320         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1321         .tokens = {
1322                 (void *)&cmd_operate_port_all_cmd,
1323                 (void *)&cmd_operate_port_all_port,
1324                 (void *)&cmd_operate_port_all_all,
1325                 NULL,
1326         },
1327 };
1328
1329 /* *** start/stop/close specific port *** */
1330 struct cmd_operate_specific_port_result {
1331         cmdline_fixed_string_t keyword;
1332         cmdline_fixed_string_t name;
1333         uint8_t value;
1334 };
1335
1336 static void cmd_operate_specific_port_parsed(void *parsed_result,
1337                         __attribute__((unused)) struct cmdline *cl,
1338                                 __attribute__((unused)) void *data)
1339 {
1340         struct cmd_operate_specific_port_result *res = parsed_result;
1341
1342         if (!strcmp(res->name, "start"))
1343                 start_port(res->value);
1344         else if (!strcmp(res->name, "stop"))
1345                 stop_port(res->value);
1346         else if (!strcmp(res->name, "close"))
1347                 close_port(res->value);
1348         else if (!strcmp(res->name, "reset"))
1349                 reset_port(res->value);
1350         else
1351                 printf("Unknown parameter\n");
1352 }
1353
1354 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1355         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1356                                                         keyword, "port");
1357 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1358         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1359                                                 name, "start#stop#close#reset");
1360 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1361         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1362                                                         value, UINT8);
1363
1364 cmdline_parse_inst_t cmd_operate_specific_port = {
1365         .f = cmd_operate_specific_port_parsed,
1366         .data = NULL,
1367         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1368         .tokens = {
1369                 (void *)&cmd_operate_specific_port_cmd,
1370                 (void *)&cmd_operate_specific_port_port,
1371                 (void *)&cmd_operate_specific_port_id,
1372                 NULL,
1373         },
1374 };
1375
1376 /* *** enable port setup (after attach) via iterator or event *** */
1377 struct cmd_set_port_setup_on_result {
1378         cmdline_fixed_string_t set;
1379         cmdline_fixed_string_t port;
1380         cmdline_fixed_string_t setup;
1381         cmdline_fixed_string_t on;
1382         cmdline_fixed_string_t mode;
1383 };
1384
1385 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1386                                 __attribute__((unused)) struct cmdline *cl,
1387                                 __attribute__((unused)) void *data)
1388 {
1389         struct cmd_set_port_setup_on_result *res = parsed_result;
1390
1391         if (strcmp(res->mode, "event") == 0)
1392                 setup_on_probe_event = true;
1393         else if (strcmp(res->mode, "iterator") == 0)
1394                 setup_on_probe_event = false;
1395         else
1396                 printf("Unknown mode\n");
1397 }
1398
1399 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1400         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1401                         set, "set");
1402 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1403         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1404                         port, "port");
1405 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1406         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1407                         setup, "setup");
1408 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1409         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1410                         on, "on");
1411 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1412         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1413                         mode, "iterator#event");
1414
1415 cmdline_parse_inst_t cmd_set_port_setup_on = {
1416         .f = cmd_set_port_setup_on_parsed,
1417         .data = NULL,
1418         .help_str = "set port setup on iterator|event",
1419         .tokens = {
1420                 (void *)&cmd_set_port_setup_on_set,
1421                 (void *)&cmd_set_port_setup_on_port,
1422                 (void *)&cmd_set_port_setup_on_setup,
1423                 (void *)&cmd_set_port_setup_on_on,
1424                 (void *)&cmd_set_port_setup_on_mode,
1425                 NULL,
1426         },
1427 };
1428
1429 /* *** attach a specified port *** */
1430 struct cmd_operate_attach_port_result {
1431         cmdline_fixed_string_t port;
1432         cmdline_fixed_string_t keyword;
1433         cmdline_fixed_string_t identifier;
1434 };
1435
1436 static void cmd_operate_attach_port_parsed(void *parsed_result,
1437                                 __attribute__((unused)) struct cmdline *cl,
1438                                 __attribute__((unused)) void *data)
1439 {
1440         struct cmd_operate_attach_port_result *res = parsed_result;
1441
1442         if (!strcmp(res->keyword, "attach"))
1443                 attach_port(res->identifier);
1444         else
1445                 printf("Unknown parameter\n");
1446 }
1447
1448 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1449         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1450                         port, "port");
1451 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1452         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1453                         keyword, "attach");
1454 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1455         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1456                         identifier, NULL);
1457
1458 cmdline_parse_inst_t cmd_operate_attach_port = {
1459         .f = cmd_operate_attach_port_parsed,
1460         .data = NULL,
1461         .help_str = "port attach <identifier>: "
1462                 "(identifier: pci address or virtual dev name)",
1463         .tokens = {
1464                 (void *)&cmd_operate_attach_port_port,
1465                 (void *)&cmd_operate_attach_port_keyword,
1466                 (void *)&cmd_operate_attach_port_identifier,
1467                 NULL,
1468         },
1469 };
1470
1471 /* *** detach a specified port *** */
1472 struct cmd_operate_detach_port_result {
1473         cmdline_fixed_string_t port;
1474         cmdline_fixed_string_t keyword;
1475         portid_t port_id;
1476 };
1477
1478 static void cmd_operate_detach_port_parsed(void *parsed_result,
1479                                 __attribute__((unused)) struct cmdline *cl,
1480                                 __attribute__((unused)) void *data)
1481 {
1482         struct cmd_operate_detach_port_result *res = parsed_result;
1483
1484         if (!strcmp(res->keyword, "detach"))
1485                 detach_port_device(res->port_id);
1486         else
1487                 printf("Unknown parameter\n");
1488 }
1489
1490 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1491         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1492                         port, "port");
1493 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1494         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1495                         keyword, "detach");
1496 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1497         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1498                         port_id, UINT16);
1499
1500 cmdline_parse_inst_t cmd_operate_detach_port = {
1501         .f = cmd_operate_detach_port_parsed,
1502         .data = NULL,
1503         .help_str = "port detach <port_id>",
1504         .tokens = {
1505                 (void *)&cmd_operate_detach_port_port,
1506                 (void *)&cmd_operate_detach_port_keyword,
1507                 (void *)&cmd_operate_detach_port_port_id,
1508                 NULL,
1509         },
1510 };
1511
1512 /* *** detach device by identifier *** */
1513 struct cmd_operate_detach_device_result {
1514         cmdline_fixed_string_t device;
1515         cmdline_fixed_string_t keyword;
1516         cmdline_fixed_string_t identifier;
1517 };
1518
1519 static void cmd_operate_detach_device_parsed(void *parsed_result,
1520                                 __attribute__((unused)) struct cmdline *cl,
1521                                 __attribute__((unused)) void *data)
1522 {
1523         struct cmd_operate_detach_device_result *res = parsed_result;
1524
1525         if (!strcmp(res->keyword, "detach"))
1526                 detach_device(res->identifier);
1527         else
1528                 printf("Unknown parameter\n");
1529 }
1530
1531 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1532         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1533                         device, "device");
1534 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1535         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1536                         keyword, "detach");
1537 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1538         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1539                         identifier, NULL);
1540
1541 cmdline_parse_inst_t cmd_operate_detach_device = {
1542         .f = cmd_operate_detach_device_parsed,
1543         .data = NULL,
1544         .help_str = "device detach <identifier>:"
1545                 "(identifier: pci address or virtual dev name)",
1546         .tokens = {
1547                 (void *)&cmd_operate_detach_device_device,
1548                 (void *)&cmd_operate_detach_device_keyword,
1549                 (void *)&cmd_operate_detach_device_identifier,
1550                 NULL,
1551         },
1552 };
1553 /* *** configure speed for all ports *** */
1554 struct cmd_config_speed_all {
1555         cmdline_fixed_string_t port;
1556         cmdline_fixed_string_t keyword;
1557         cmdline_fixed_string_t all;
1558         cmdline_fixed_string_t item1;
1559         cmdline_fixed_string_t item2;
1560         cmdline_fixed_string_t value1;
1561         cmdline_fixed_string_t value2;
1562 };
1563
1564 static int
1565 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1566 {
1567
1568         int duplex;
1569
1570         if (!strcmp(duplexstr, "half")) {
1571                 duplex = ETH_LINK_HALF_DUPLEX;
1572         } else if (!strcmp(duplexstr, "full")) {
1573                 duplex = ETH_LINK_FULL_DUPLEX;
1574         } else if (!strcmp(duplexstr, "auto")) {
1575                 duplex = ETH_LINK_FULL_DUPLEX;
1576         } else {
1577                 printf("Unknown duplex parameter\n");
1578                 return -1;
1579         }
1580
1581         if (!strcmp(speedstr, "10")) {
1582                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1583                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1584         } else if (!strcmp(speedstr, "100")) {
1585                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1586                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1587         } else {
1588                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1589                         printf("Invalid speed/duplex parameters\n");
1590                         return -1;
1591                 }
1592                 if (!strcmp(speedstr, "1000")) {
1593                         *speed = ETH_LINK_SPEED_1G;
1594                 } else if (!strcmp(speedstr, "10000")) {
1595                         *speed = ETH_LINK_SPEED_10G;
1596                 } else if (!strcmp(speedstr, "25000")) {
1597                         *speed = ETH_LINK_SPEED_25G;
1598                 } else if (!strcmp(speedstr, "40000")) {
1599                         *speed = ETH_LINK_SPEED_40G;
1600                 } else if (!strcmp(speedstr, "50000")) {
1601                         *speed = ETH_LINK_SPEED_50G;
1602                 } else if (!strcmp(speedstr, "100000")) {
1603                         *speed = ETH_LINK_SPEED_100G;
1604                 } else if (!strcmp(speedstr, "auto")) {
1605                         *speed = ETH_LINK_SPEED_AUTONEG;
1606                 } else {
1607                         printf("Unknown speed parameter\n");
1608                         return -1;
1609                 }
1610         }
1611
1612         return 0;
1613 }
1614
1615 static void
1616 cmd_config_speed_all_parsed(void *parsed_result,
1617                         __attribute__((unused)) struct cmdline *cl,
1618                         __attribute__((unused)) void *data)
1619 {
1620         struct cmd_config_speed_all *res = parsed_result;
1621         uint32_t link_speed;
1622         portid_t pid;
1623
1624         if (!all_ports_stopped()) {
1625                 printf("Please stop all ports first\n");
1626                 return;
1627         }
1628
1629         if (parse_and_check_speed_duplex(res->value1, res->value2,
1630                         &link_speed) < 0)
1631                 return;
1632
1633         RTE_ETH_FOREACH_DEV(pid) {
1634                 ports[pid].dev_conf.link_speeds = link_speed;
1635         }
1636
1637         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1638 }
1639
1640 cmdline_parse_token_string_t cmd_config_speed_all_port =
1641         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1642 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1643         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1644                                                         "config");
1645 cmdline_parse_token_string_t cmd_config_speed_all_all =
1646         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1647 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1648         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1649 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1650         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1651                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1652 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1653         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1654 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1655         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1656                                                 "half#full#auto");
1657
1658 cmdline_parse_inst_t cmd_config_speed_all = {
1659         .f = cmd_config_speed_all_parsed,
1660         .data = NULL,
1661         .help_str = "port config all speed "
1662                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1663                                                         "half|full|auto",
1664         .tokens = {
1665                 (void *)&cmd_config_speed_all_port,
1666                 (void *)&cmd_config_speed_all_keyword,
1667                 (void *)&cmd_config_speed_all_all,
1668                 (void *)&cmd_config_speed_all_item1,
1669                 (void *)&cmd_config_speed_all_value1,
1670                 (void *)&cmd_config_speed_all_item2,
1671                 (void *)&cmd_config_speed_all_value2,
1672                 NULL,
1673         },
1674 };
1675
1676 /* *** configure speed for specific port *** */
1677 struct cmd_config_speed_specific {
1678         cmdline_fixed_string_t port;
1679         cmdline_fixed_string_t keyword;
1680         portid_t id;
1681         cmdline_fixed_string_t item1;
1682         cmdline_fixed_string_t item2;
1683         cmdline_fixed_string_t value1;
1684         cmdline_fixed_string_t value2;
1685 };
1686
1687 static void
1688 cmd_config_speed_specific_parsed(void *parsed_result,
1689                                 __attribute__((unused)) struct cmdline *cl,
1690                                 __attribute__((unused)) void *data)
1691 {
1692         struct cmd_config_speed_specific *res = parsed_result;
1693         uint32_t link_speed;
1694
1695         if (!all_ports_stopped()) {
1696                 printf("Please stop all ports first\n");
1697                 return;
1698         }
1699
1700         if (port_id_is_invalid(res->id, ENABLED_WARN))
1701                 return;
1702
1703         if (parse_and_check_speed_duplex(res->value1, res->value2,
1704                         &link_speed) < 0)
1705                 return;
1706
1707         ports[res->id].dev_conf.link_speeds = link_speed;
1708
1709         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1710 }
1711
1712
1713 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1714         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1715                                                                 "port");
1716 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1717         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1718                                                                 "config");
1719 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1720         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1721 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1722         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1723                                                                 "speed");
1724 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1725         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1726                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1727 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1728         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1729                                                                 "duplex");
1730 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1731         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1732                                                         "half#full#auto");
1733
1734 cmdline_parse_inst_t cmd_config_speed_specific = {
1735         .f = cmd_config_speed_specific_parsed,
1736         .data = NULL,
1737         .help_str = "port config <port_id> speed "
1738                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1739                                                         "half|full|auto",
1740         .tokens = {
1741                 (void *)&cmd_config_speed_specific_port,
1742                 (void *)&cmd_config_speed_specific_keyword,
1743                 (void *)&cmd_config_speed_specific_id,
1744                 (void *)&cmd_config_speed_specific_item1,
1745                 (void *)&cmd_config_speed_specific_value1,
1746                 (void *)&cmd_config_speed_specific_item2,
1747                 (void *)&cmd_config_speed_specific_value2,
1748                 NULL,
1749         },
1750 };
1751
1752 /* *** configure loopback for all ports *** */
1753 struct cmd_config_loopback_all {
1754         cmdline_fixed_string_t port;
1755         cmdline_fixed_string_t keyword;
1756         cmdline_fixed_string_t all;
1757         cmdline_fixed_string_t item;
1758         uint32_t mode;
1759 };
1760
1761 static void
1762 cmd_config_loopback_all_parsed(void *parsed_result,
1763                         __attribute__((unused)) struct cmdline *cl,
1764                         __attribute__((unused)) void *data)
1765 {
1766         struct cmd_config_loopback_all *res = parsed_result;
1767         portid_t pid;
1768
1769         if (!all_ports_stopped()) {
1770                 printf("Please stop all ports first\n");
1771                 return;
1772         }
1773
1774         RTE_ETH_FOREACH_DEV(pid) {
1775                 ports[pid].dev_conf.lpbk_mode = res->mode;
1776         }
1777
1778         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1779 }
1780
1781 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1782         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1783 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1784         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1785                                                         "config");
1786 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1787         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1788 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1789         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1790                                                         "loopback");
1791 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1792         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1793
1794 cmdline_parse_inst_t cmd_config_loopback_all = {
1795         .f = cmd_config_loopback_all_parsed,
1796         .data = NULL,
1797         .help_str = "port config all loopback <mode>",
1798         .tokens = {
1799                 (void *)&cmd_config_loopback_all_port,
1800                 (void *)&cmd_config_loopback_all_keyword,
1801                 (void *)&cmd_config_loopback_all_all,
1802                 (void *)&cmd_config_loopback_all_item,
1803                 (void *)&cmd_config_loopback_all_mode,
1804                 NULL,
1805         },
1806 };
1807
1808 /* *** configure loopback for specific port *** */
1809 struct cmd_config_loopback_specific {
1810         cmdline_fixed_string_t port;
1811         cmdline_fixed_string_t keyword;
1812         uint16_t port_id;
1813         cmdline_fixed_string_t item;
1814         uint32_t mode;
1815 };
1816
1817 static void
1818 cmd_config_loopback_specific_parsed(void *parsed_result,
1819                                 __attribute__((unused)) struct cmdline *cl,
1820                                 __attribute__((unused)) void *data)
1821 {
1822         struct cmd_config_loopback_specific *res = parsed_result;
1823
1824         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1825                 return;
1826
1827         if (!port_is_stopped(res->port_id)) {
1828                 printf("Please stop port %u first\n", res->port_id);
1829                 return;
1830         }
1831
1832         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1833
1834         cmd_reconfig_device_queue(res->port_id, 1, 1);
1835 }
1836
1837
1838 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1839         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1840                                                                 "port");
1841 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1842         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1843                                                                 "config");
1844 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1845         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1846                                                                 UINT16);
1847 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1848         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1849                                                                 "loopback");
1850 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1851         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1852                               UINT32);
1853
1854 cmdline_parse_inst_t cmd_config_loopback_specific = {
1855         .f = cmd_config_loopback_specific_parsed,
1856         .data = NULL,
1857         .help_str = "port config <port_id> loopback <mode>",
1858         .tokens = {
1859                 (void *)&cmd_config_loopback_specific_port,
1860                 (void *)&cmd_config_loopback_specific_keyword,
1861                 (void *)&cmd_config_loopback_specific_id,
1862                 (void *)&cmd_config_loopback_specific_item,
1863                 (void *)&cmd_config_loopback_specific_mode,
1864                 NULL,
1865         },
1866 };
1867
1868 /* *** configure txq/rxq, txd/rxd *** */
1869 struct cmd_config_rx_tx {
1870         cmdline_fixed_string_t port;
1871         cmdline_fixed_string_t keyword;
1872         cmdline_fixed_string_t all;
1873         cmdline_fixed_string_t name;
1874         uint16_t value;
1875 };
1876
1877 static void
1878 cmd_config_rx_tx_parsed(void *parsed_result,
1879                         __attribute__((unused)) struct cmdline *cl,
1880                         __attribute__((unused)) void *data)
1881 {
1882         struct cmd_config_rx_tx *res = parsed_result;
1883
1884         if (!all_ports_stopped()) {
1885                 printf("Please stop all ports first\n");
1886                 return;
1887         }
1888         if (!strcmp(res->name, "rxq")) {
1889                 if (!res->value && !nb_txq) {
1890                         printf("Warning: Either rx or tx queues should be non zero\n");
1891                         return;
1892                 }
1893                 if (check_nb_rxq(res->value) != 0)
1894                         return;
1895                 nb_rxq = res->value;
1896         }
1897         else if (!strcmp(res->name, "txq")) {
1898                 if (!res->value && !nb_rxq) {
1899                         printf("Warning: Either rx or tx queues should be non zero\n");
1900                         return;
1901                 }
1902                 if (check_nb_txq(res->value) != 0)
1903                         return;
1904                 nb_txq = res->value;
1905         }
1906         else if (!strcmp(res->name, "rxd")) {
1907                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1908                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1909                                         res->value, RTE_TEST_RX_DESC_MAX);
1910                         return;
1911                 }
1912                 nb_rxd = res->value;
1913         } else if (!strcmp(res->name, "txd")) {
1914                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1915                         printf("txd %d invalid - must be > 0 && <= %d\n",
1916                                         res->value, RTE_TEST_TX_DESC_MAX);
1917                         return;
1918                 }
1919                 nb_txd = res->value;
1920         } else {
1921                 printf("Unknown parameter\n");
1922                 return;
1923         }
1924
1925         fwd_config_setup();
1926
1927         init_port_config();
1928
1929         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1930 }
1931
1932 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1933         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1934 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1935         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1936 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1937         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1938 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1939         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1940                                                 "rxq#txq#rxd#txd");
1941 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1942         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1943
1944 cmdline_parse_inst_t cmd_config_rx_tx = {
1945         .f = cmd_config_rx_tx_parsed,
1946         .data = NULL,
1947         .help_str = "port config all rxq|txq|rxd|txd <value>",
1948         .tokens = {
1949                 (void *)&cmd_config_rx_tx_port,
1950                 (void *)&cmd_config_rx_tx_keyword,
1951                 (void *)&cmd_config_rx_tx_all,
1952                 (void *)&cmd_config_rx_tx_name,
1953                 (void *)&cmd_config_rx_tx_value,
1954                 NULL,
1955         },
1956 };
1957
1958 /* *** config max packet length *** */
1959 struct cmd_config_max_pkt_len_result {
1960         cmdline_fixed_string_t port;
1961         cmdline_fixed_string_t keyword;
1962         cmdline_fixed_string_t all;
1963         cmdline_fixed_string_t name;
1964         uint32_t value;
1965 };
1966
1967 static void
1968 cmd_config_max_pkt_len_parsed(void *parsed_result,
1969                                 __attribute__((unused)) struct cmdline *cl,
1970                                 __attribute__((unused)) void *data)
1971 {
1972         struct cmd_config_max_pkt_len_result *res = parsed_result;
1973         portid_t pid;
1974
1975         if (!all_ports_stopped()) {
1976                 printf("Please stop all ports first\n");
1977                 return;
1978         }
1979
1980         RTE_ETH_FOREACH_DEV(pid) {
1981                 struct rte_port *port = &ports[pid];
1982                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1983
1984                 if (!strcmp(res->name, "max-pkt-len")) {
1985                         if (res->value < RTE_ETHER_MIN_LEN) {
1986                                 printf("max-pkt-len can not be less than %d\n",
1987                                                 RTE_ETHER_MIN_LEN);
1988                                 return;
1989                         }
1990                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1991                                 return;
1992
1993                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1994                         if (res->value > RTE_ETHER_MAX_LEN)
1995                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1996                         else
1997                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1998                         port->dev_conf.rxmode.offloads = rx_offloads;
1999                 } else {
2000                         printf("Unknown parameter\n");
2001                         return;
2002                 }
2003         }
2004
2005         init_port_config();
2006
2007         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2008 }
2009
2010 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2011         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2012                                                                 "port");
2013 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2014         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2015                                                                 "config");
2016 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2017         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2018                                                                 "all");
2019 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2020         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2021                                                                 "max-pkt-len");
2022 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2023         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2024                                                                 UINT32);
2025
2026 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2027         .f = cmd_config_max_pkt_len_parsed,
2028         .data = NULL,
2029         .help_str = "port config all max-pkt-len <value>",
2030         .tokens = {
2031                 (void *)&cmd_config_max_pkt_len_port,
2032                 (void *)&cmd_config_max_pkt_len_keyword,
2033                 (void *)&cmd_config_max_pkt_len_all,
2034                 (void *)&cmd_config_max_pkt_len_name,
2035                 (void *)&cmd_config_max_pkt_len_value,
2036                 NULL,
2037         },
2038 };
2039
2040 /* *** configure port MTU *** */
2041 struct cmd_config_mtu_result {
2042         cmdline_fixed_string_t port;
2043         cmdline_fixed_string_t keyword;
2044         cmdline_fixed_string_t mtu;
2045         portid_t port_id;
2046         uint16_t value;
2047 };
2048
2049 static void
2050 cmd_config_mtu_parsed(void *parsed_result,
2051                       __attribute__((unused)) struct cmdline *cl,
2052                       __attribute__((unused)) void *data)
2053 {
2054         struct cmd_config_mtu_result *res = parsed_result;
2055
2056         if (res->value < RTE_ETHER_MIN_LEN) {
2057                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2058                 return;
2059         }
2060         port_mtu_set(res->port_id, res->value);
2061 }
2062
2063 cmdline_parse_token_string_t cmd_config_mtu_port =
2064         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2065                                  "port");
2066 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2067         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2068                                  "config");
2069 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2070         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2071                                  "mtu");
2072 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2073         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2074 cmdline_parse_token_num_t cmd_config_mtu_value =
2075         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2076
2077 cmdline_parse_inst_t cmd_config_mtu = {
2078         .f = cmd_config_mtu_parsed,
2079         .data = NULL,
2080         .help_str = "port config mtu <port_id> <value>",
2081         .tokens = {
2082                 (void *)&cmd_config_mtu_port,
2083                 (void *)&cmd_config_mtu_keyword,
2084                 (void *)&cmd_config_mtu_mtu,
2085                 (void *)&cmd_config_mtu_port_id,
2086                 (void *)&cmd_config_mtu_value,
2087                 NULL,
2088         },
2089 };
2090
2091 /* *** configure rx mode *** */
2092 struct cmd_config_rx_mode_flag {
2093         cmdline_fixed_string_t port;
2094         cmdline_fixed_string_t keyword;
2095         cmdline_fixed_string_t all;
2096         cmdline_fixed_string_t name;
2097         cmdline_fixed_string_t value;
2098 };
2099
2100 static void
2101 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2102                                 __attribute__((unused)) struct cmdline *cl,
2103                                 __attribute__((unused)) void *data)
2104 {
2105         struct cmd_config_rx_mode_flag *res = parsed_result;
2106
2107         if (!all_ports_stopped()) {
2108                 printf("Please stop all ports first\n");
2109                 return;
2110         }
2111
2112         if (!strcmp(res->name, "drop-en")) {
2113                 if (!strcmp(res->value, "on"))
2114                         rx_drop_en = 1;
2115                 else if (!strcmp(res->value, "off"))
2116                         rx_drop_en = 0;
2117                 else {
2118                         printf("Unknown parameter\n");
2119                         return;
2120                 }
2121         } else {
2122                 printf("Unknown parameter\n");
2123                 return;
2124         }
2125
2126         init_port_config();
2127
2128         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2129 }
2130
2131 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2132         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2133 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2134         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2135                                                                 "config");
2136 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2137         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2138 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2139         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2140                                         "drop-en");
2141 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2142         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2143                                                         "on#off");
2144
2145 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2146         .f = cmd_config_rx_mode_flag_parsed,
2147         .data = NULL,
2148         .help_str = "port config all drop-en on|off",
2149         .tokens = {
2150                 (void *)&cmd_config_rx_mode_flag_port,
2151                 (void *)&cmd_config_rx_mode_flag_keyword,
2152                 (void *)&cmd_config_rx_mode_flag_all,
2153                 (void *)&cmd_config_rx_mode_flag_name,
2154                 (void *)&cmd_config_rx_mode_flag_value,
2155                 NULL,
2156         },
2157 };
2158
2159 /* *** configure rss *** */
2160 struct cmd_config_rss {
2161         cmdline_fixed_string_t port;
2162         cmdline_fixed_string_t keyword;
2163         cmdline_fixed_string_t all;
2164         cmdline_fixed_string_t name;
2165         cmdline_fixed_string_t value;
2166 };
2167
2168 static void
2169 cmd_config_rss_parsed(void *parsed_result,
2170                         __attribute__((unused)) struct cmdline *cl,
2171                         __attribute__((unused)) void *data)
2172 {
2173         struct cmd_config_rss *res = parsed_result;
2174         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2175         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2176         int use_default = 0;
2177         int all_updated = 1;
2178         int diag;
2179         uint16_t i;
2180         int ret;
2181
2182         if (!strcmp(res->value, "all"))
2183                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2184                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2185                                         ETH_RSS_L2_PAYLOAD;
2186         else if (!strcmp(res->value, "ip"))
2187                 rss_conf.rss_hf = ETH_RSS_IP;
2188         else if (!strcmp(res->value, "udp"))
2189                 rss_conf.rss_hf = ETH_RSS_UDP;
2190         else if (!strcmp(res->value, "tcp"))
2191                 rss_conf.rss_hf = ETH_RSS_TCP;
2192         else if (!strcmp(res->value, "sctp"))
2193                 rss_conf.rss_hf = ETH_RSS_SCTP;
2194         else if (!strcmp(res->value, "ether"))
2195                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2196         else if (!strcmp(res->value, "port"))
2197                 rss_conf.rss_hf = ETH_RSS_PORT;
2198         else if (!strcmp(res->value, "vxlan"))
2199                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2200         else if (!strcmp(res->value, "geneve"))
2201                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2202         else if (!strcmp(res->value, "nvgre"))
2203                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2204         else if (!strcmp(res->value, "none"))
2205                 rss_conf.rss_hf = 0;
2206         else if (!strcmp(res->value, "default"))
2207                 use_default = 1;
2208         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2209                                                 atoi(res->value) < 64)
2210                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2211         else {
2212                 printf("Unknown parameter\n");
2213                 return;
2214         }
2215         rss_conf.rss_key = NULL;
2216         /* Update global configuration for RSS types. */
2217         RTE_ETH_FOREACH_DEV(i) {
2218                 struct rte_eth_rss_conf local_rss_conf;
2219
2220                 ret = eth_dev_info_get_print_err(i, &dev_info);
2221                 if (ret != 0)
2222                         return;
2223
2224                 if (use_default)
2225                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2226
2227                 local_rss_conf = rss_conf;
2228                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2229                         dev_info.flow_type_rss_offloads;
2230                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2231                         printf("Port %u modified RSS hash function based on hardware support,"
2232                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2233                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2234                 }
2235                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2236                 if (diag < 0) {
2237                         all_updated = 0;
2238                         printf("Configuration of RSS hash at ethernet port %d "
2239                                 "failed with error (%d): %s.\n",
2240                                 i, -diag, strerror(-diag));
2241                 }
2242         }
2243         if (all_updated && !use_default)
2244                 rss_hf = rss_conf.rss_hf;
2245 }
2246
2247 cmdline_parse_token_string_t cmd_config_rss_port =
2248         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2249 cmdline_parse_token_string_t cmd_config_rss_keyword =
2250         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2251 cmdline_parse_token_string_t cmd_config_rss_all =
2252         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2253 cmdline_parse_token_string_t cmd_config_rss_name =
2254         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2255 cmdline_parse_token_string_t cmd_config_rss_value =
2256         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2257
2258 cmdline_parse_inst_t cmd_config_rss = {
2259         .f = cmd_config_rss_parsed,
2260         .data = NULL,
2261         .help_str = "port config all rss "
2262                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2263         .tokens = {
2264                 (void *)&cmd_config_rss_port,
2265                 (void *)&cmd_config_rss_keyword,
2266                 (void *)&cmd_config_rss_all,
2267                 (void *)&cmd_config_rss_name,
2268                 (void *)&cmd_config_rss_value,
2269                 NULL,
2270         },
2271 };
2272
2273 /* *** configure rss hash key *** */
2274 struct cmd_config_rss_hash_key {
2275         cmdline_fixed_string_t port;
2276         cmdline_fixed_string_t config;
2277         portid_t port_id;
2278         cmdline_fixed_string_t rss_hash_key;
2279         cmdline_fixed_string_t rss_type;
2280         cmdline_fixed_string_t key;
2281 };
2282
2283 static uint8_t
2284 hexa_digit_to_value(char hexa_digit)
2285 {
2286         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2287                 return (uint8_t) (hexa_digit - '0');
2288         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2289                 return (uint8_t) ((hexa_digit - 'a') + 10);
2290         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2291                 return (uint8_t) ((hexa_digit - 'A') + 10);
2292         /* Invalid hexa digit */
2293         return 0xFF;
2294 }
2295
2296 static uint8_t
2297 parse_and_check_key_hexa_digit(char *key, int idx)
2298 {
2299         uint8_t hexa_v;
2300
2301         hexa_v = hexa_digit_to_value(key[idx]);
2302         if (hexa_v == 0xFF)
2303                 printf("invalid key: character %c at position %d is not a "
2304                        "valid hexa digit\n", key[idx], idx);
2305         return hexa_v;
2306 }
2307
2308 static void
2309 cmd_config_rss_hash_key_parsed(void *parsed_result,
2310                                __attribute__((unused)) struct cmdline *cl,
2311                                __attribute__((unused)) void *data)
2312 {
2313         struct cmd_config_rss_hash_key *res = parsed_result;
2314         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2315         uint8_t xdgt0;
2316         uint8_t xdgt1;
2317         int i;
2318         struct rte_eth_dev_info dev_info;
2319         uint8_t hash_key_size;
2320         uint32_t key_len;
2321         int ret;
2322
2323         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2324         if (ret != 0)
2325                 return;
2326
2327         if (dev_info.hash_key_size > 0 &&
2328                         dev_info.hash_key_size <= sizeof(hash_key))
2329                 hash_key_size = dev_info.hash_key_size;
2330         else {
2331                 printf("dev_info did not provide a valid hash key size\n");
2332                 return;
2333         }
2334         /* Check the length of the RSS hash key */
2335         key_len = strlen(res->key);
2336         if (key_len != (hash_key_size * 2)) {
2337                 printf("key length: %d invalid - key must be a string of %d"
2338                            " hexa-decimal numbers\n",
2339                            (int) key_len, hash_key_size * 2);
2340                 return;
2341         }
2342         /* Translate RSS hash key into binary representation */
2343         for (i = 0; i < hash_key_size; i++) {
2344                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2345                 if (xdgt0 == 0xFF)
2346                         return;
2347                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2348                 if (xdgt1 == 0xFF)
2349                         return;
2350                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2351         }
2352         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2353                         hash_key_size);
2354 }
2355
2356 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2357         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2358 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2359         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2360                                  "config");
2361 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2362         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2363 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2364         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2365                                  rss_hash_key, "rss-hash-key");
2366 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2367         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2368                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2369                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2370                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2371                                  "ipv6-tcp-ex#ipv6-udp-ex");
2372 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2373         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2374
2375 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2376         .f = cmd_config_rss_hash_key_parsed,
2377         .data = NULL,
2378         .help_str = "port config <port_id> rss-hash-key "
2379                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2380                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2381                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2382                 "<string of hex digits (variable length, NIC dependent)>",
2383         .tokens = {
2384                 (void *)&cmd_config_rss_hash_key_port,
2385                 (void *)&cmd_config_rss_hash_key_config,
2386                 (void *)&cmd_config_rss_hash_key_port_id,
2387                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2388                 (void *)&cmd_config_rss_hash_key_rss_type,
2389                 (void *)&cmd_config_rss_hash_key_value,
2390                 NULL,
2391         },
2392 };
2393
2394 /* *** configure port rxq/txq ring size *** */
2395 struct cmd_config_rxtx_ring_size {
2396         cmdline_fixed_string_t port;
2397         cmdline_fixed_string_t config;
2398         portid_t portid;
2399         cmdline_fixed_string_t rxtxq;
2400         uint16_t qid;
2401         cmdline_fixed_string_t rsize;
2402         uint16_t size;
2403 };
2404
2405 static void
2406 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2407                                  __attribute__((unused)) struct cmdline *cl,
2408                                  __attribute__((unused)) void *data)
2409 {
2410         struct cmd_config_rxtx_ring_size *res = parsed_result;
2411         struct rte_port *port;
2412         uint8_t isrx;
2413
2414         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2415                 return;
2416
2417         if (res->portid == (portid_t)RTE_PORT_ALL) {
2418                 printf("Invalid port id\n");
2419                 return;
2420         }
2421
2422         port = &ports[res->portid];
2423
2424         if (!strcmp(res->rxtxq, "rxq"))
2425                 isrx = 1;
2426         else if (!strcmp(res->rxtxq, "txq"))
2427                 isrx = 0;
2428         else {
2429                 printf("Unknown parameter\n");
2430                 return;
2431         }
2432
2433         if (isrx && rx_queue_id_is_invalid(res->qid))
2434                 return;
2435         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2436                 return;
2437
2438         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2439                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2440                        rx_free_thresh);
2441                 return;
2442         }
2443
2444         if (isrx)
2445                 port->nb_rx_desc[res->qid] = res->size;
2446         else
2447                 port->nb_tx_desc[res->qid] = res->size;
2448
2449         cmd_reconfig_device_queue(res->portid, 0, 1);
2450 }
2451
2452 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2453         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2454                                  port, "port");
2455 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2456         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2457                                  config, "config");
2458 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2459         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2460                                  portid, UINT16);
2461 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2462         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2463                                  rxtxq, "rxq#txq");
2464 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2465         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2466                               qid, UINT16);
2467 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2468         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2469                                  rsize, "ring_size");
2470 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2471         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2472                               size, UINT16);
2473
2474 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2475         .f = cmd_config_rxtx_ring_size_parsed,
2476         .data = NULL,
2477         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2478         .tokens = {
2479                 (void *)&cmd_config_rxtx_ring_size_port,
2480                 (void *)&cmd_config_rxtx_ring_size_config,
2481                 (void *)&cmd_config_rxtx_ring_size_portid,
2482                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2483                 (void *)&cmd_config_rxtx_ring_size_qid,
2484                 (void *)&cmd_config_rxtx_ring_size_rsize,
2485                 (void *)&cmd_config_rxtx_ring_size_size,
2486                 NULL,
2487         },
2488 };
2489
2490 /* *** configure port rxq/txq start/stop *** */
2491 struct cmd_config_rxtx_queue {
2492         cmdline_fixed_string_t port;
2493         portid_t portid;
2494         cmdline_fixed_string_t rxtxq;
2495         uint16_t qid;
2496         cmdline_fixed_string_t opname;
2497 };
2498
2499 static void
2500 cmd_config_rxtx_queue_parsed(void *parsed_result,
2501                         __attribute__((unused)) struct cmdline *cl,
2502                         __attribute__((unused)) void *data)
2503 {
2504         struct cmd_config_rxtx_queue *res = parsed_result;
2505         uint8_t isrx;
2506         uint8_t isstart;
2507         int ret = 0;
2508
2509         if (test_done == 0) {
2510                 printf("Please stop forwarding first\n");
2511                 return;
2512         }
2513
2514         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2515                 return;
2516
2517         if (port_is_started(res->portid) != 1) {
2518                 printf("Please start port %u first\n", res->portid);
2519                 return;
2520         }
2521
2522         if (!strcmp(res->rxtxq, "rxq"))
2523                 isrx = 1;
2524         else if (!strcmp(res->rxtxq, "txq"))
2525                 isrx = 0;
2526         else {
2527                 printf("Unknown parameter\n");
2528                 return;
2529         }
2530
2531         if (isrx && rx_queue_id_is_invalid(res->qid))
2532                 return;
2533         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2534                 return;
2535
2536         if (!strcmp(res->opname, "start"))
2537                 isstart = 1;
2538         else if (!strcmp(res->opname, "stop"))
2539                 isstart = 0;
2540         else {
2541                 printf("Unknown parameter\n");
2542                 return;
2543         }
2544
2545         if (isstart && isrx)
2546                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2547         else if (!isstart && isrx)
2548                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2549         else if (isstart && !isrx)
2550                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2551         else
2552                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2553
2554         if (ret == -ENOTSUP)
2555                 printf("Function not supported in PMD driver\n");
2556 }
2557
2558 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2559         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2560 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2561         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2562 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2563         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2564 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2565         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2566 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2567         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2568                                                 "start#stop");
2569
2570 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2571         .f = cmd_config_rxtx_queue_parsed,
2572         .data = NULL,
2573         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2574         .tokens = {
2575                 (void *)&cmd_config_rxtx_queue_port,
2576                 (void *)&cmd_config_rxtx_queue_portid,
2577                 (void *)&cmd_config_rxtx_queue_rxtxq,
2578                 (void *)&cmd_config_rxtx_queue_qid,
2579                 (void *)&cmd_config_rxtx_queue_opname,
2580                 NULL,
2581         },
2582 };
2583
2584 /* *** configure port rxq/txq deferred start on/off *** */
2585 struct cmd_config_deferred_start_rxtx_queue {
2586         cmdline_fixed_string_t port;
2587         portid_t port_id;
2588         cmdline_fixed_string_t rxtxq;
2589         uint16_t qid;
2590         cmdline_fixed_string_t opname;
2591         cmdline_fixed_string_t state;
2592 };
2593
2594 static void
2595 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2596                         __attribute__((unused)) struct cmdline *cl,
2597                         __attribute__((unused)) void *data)
2598 {
2599         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2600         struct rte_port *port;
2601         uint8_t isrx;
2602         uint8_t ison;
2603         uint8_t needreconfig = 0;
2604
2605         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2606                 return;
2607
2608         if (port_is_started(res->port_id) != 0) {
2609                 printf("Please stop port %u first\n", res->port_id);
2610                 return;
2611         }
2612
2613         port = &ports[res->port_id];
2614
2615         isrx = !strcmp(res->rxtxq, "rxq");
2616
2617         if (isrx && rx_queue_id_is_invalid(res->qid))
2618                 return;
2619         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2620                 return;
2621
2622         ison = !strcmp(res->state, "on");
2623
2624         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2625                 port->rx_conf[res->qid].rx_deferred_start = ison;
2626                 needreconfig = 1;
2627         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2628                 port->tx_conf[res->qid].tx_deferred_start = ison;
2629                 needreconfig = 1;
2630         }
2631
2632         if (needreconfig)
2633                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2634 }
2635
2636 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2637         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2638                                                 port, "port");
2639 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2640         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2641                                                 port_id, UINT16);
2642 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2643         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2644                                                 rxtxq, "rxq#txq");
2645 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2646         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2647                                                 qid, UINT16);
2648 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2649         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2650                                                 opname, "deferred_start");
2651 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2652         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2653                                                 state, "on#off");
2654
2655 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2656         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2657         .data = NULL,
2658         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2659         .tokens = {
2660                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2661                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2662                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2663                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2664                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2665                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2666                 NULL,
2667         },
2668 };
2669
2670 /* *** configure port rxq/txq setup *** */
2671 struct cmd_setup_rxtx_queue {
2672         cmdline_fixed_string_t port;
2673         portid_t portid;
2674         cmdline_fixed_string_t rxtxq;
2675         uint16_t qid;
2676         cmdline_fixed_string_t setup;
2677 };
2678
2679 /* Common CLI fields for queue setup */
2680 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2681         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2682 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2683         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2684 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2685         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2686 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2687         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2688 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2689         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2690
2691 static void
2692 cmd_setup_rxtx_queue_parsed(
2693         void *parsed_result,
2694         __attribute__((unused)) struct cmdline *cl,
2695         __attribute__((unused)) void *data)
2696 {
2697         struct cmd_setup_rxtx_queue *res = parsed_result;
2698         struct rte_port *port;
2699         struct rte_mempool *mp;
2700         unsigned int socket_id;
2701         uint8_t isrx = 0;
2702         int ret;
2703
2704         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2705                 return;
2706
2707         if (res->portid == (portid_t)RTE_PORT_ALL) {
2708                 printf("Invalid port id\n");
2709                 return;
2710         }
2711
2712         if (!strcmp(res->rxtxq, "rxq"))
2713                 isrx = 1;
2714         else if (!strcmp(res->rxtxq, "txq"))
2715                 isrx = 0;
2716         else {
2717                 printf("Unknown parameter\n");
2718                 return;
2719         }
2720
2721         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2722                 printf("Invalid rx queue\n");
2723                 return;
2724         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2725                 printf("Invalid tx queue\n");
2726                 return;
2727         }
2728
2729         port = &ports[res->portid];
2730         if (isrx) {
2731                 socket_id = rxring_numa[res->portid];
2732                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2733                         socket_id = port->socket_id;
2734
2735                 mp = mbuf_pool_find(socket_id);
2736                 if (mp == NULL) {
2737                         printf("Failed to setup RX queue: "
2738                                 "No mempool allocation"
2739                                 " on the socket %d\n",
2740                                 rxring_numa[res->portid]);
2741                         return;
2742                 }
2743                 ret = rte_eth_rx_queue_setup(res->portid,
2744                                              res->qid,
2745                                              port->nb_rx_desc[res->qid],
2746                                              socket_id,
2747                                              &port->rx_conf[res->qid],
2748                                              mp);
2749                 if (ret)
2750                         printf("Failed to setup RX queue\n");
2751         } else {
2752                 socket_id = txring_numa[res->portid];
2753                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2754                         socket_id = port->socket_id;
2755
2756                 ret = rte_eth_tx_queue_setup(res->portid,
2757                                              res->qid,
2758                                              port->nb_tx_desc[res->qid],
2759                                              socket_id,
2760                                              &port->tx_conf[res->qid]);
2761                 if (ret)
2762                         printf("Failed to setup TX queue\n");
2763         }
2764 }
2765
2766 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2767         .f = cmd_setup_rxtx_queue_parsed,
2768         .data = NULL,
2769         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2770         .tokens = {
2771                 (void *)&cmd_setup_rxtx_queue_port,
2772                 (void *)&cmd_setup_rxtx_queue_portid,
2773                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2774                 (void *)&cmd_setup_rxtx_queue_qid,
2775                 (void *)&cmd_setup_rxtx_queue_setup,
2776                 NULL,
2777         },
2778 };
2779
2780
2781 /* *** Configure RSS RETA *** */
2782 struct cmd_config_rss_reta {
2783         cmdline_fixed_string_t port;
2784         cmdline_fixed_string_t keyword;
2785         portid_t port_id;
2786         cmdline_fixed_string_t name;
2787         cmdline_fixed_string_t list_name;
2788         cmdline_fixed_string_t list_of_items;
2789 };
2790
2791 static int
2792 parse_reta_config(const char *str,
2793                   struct rte_eth_rss_reta_entry64 *reta_conf,
2794                   uint16_t nb_entries)
2795 {
2796         int i;
2797         unsigned size;
2798         uint16_t hash_index, idx, shift;
2799         uint16_t nb_queue;
2800         char s[256];
2801         const char *p, *p0 = str;
2802         char *end;
2803         enum fieldnames {
2804                 FLD_HASH_INDEX = 0,
2805                 FLD_QUEUE,
2806                 _NUM_FLD
2807         };
2808         unsigned long int_fld[_NUM_FLD];
2809         char *str_fld[_NUM_FLD];
2810
2811         while ((p = strchr(p0,'(')) != NULL) {
2812                 ++p;
2813                 if((p0 = strchr(p,')')) == NULL)
2814                         return -1;
2815
2816                 size = p0 - p;
2817                 if(size >= sizeof(s))
2818                         return -1;
2819
2820                 snprintf(s, sizeof(s), "%.*s", size, p);
2821                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2822                         return -1;
2823                 for (i = 0; i < _NUM_FLD; i++) {
2824                         errno = 0;
2825                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2826                         if (errno != 0 || end == str_fld[i] ||
2827                                         int_fld[i] > 65535)
2828                                 return -1;
2829                 }
2830
2831                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2832                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2833
2834                 if (hash_index >= nb_entries) {
2835                         printf("Invalid RETA hash index=%d\n", hash_index);
2836                         return -1;
2837                 }
2838
2839                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2840                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2841                 reta_conf[idx].mask |= (1ULL << shift);
2842                 reta_conf[idx].reta[shift] = nb_queue;
2843         }
2844
2845         return 0;
2846 }
2847
2848 static void
2849 cmd_set_rss_reta_parsed(void *parsed_result,
2850                         __attribute__((unused)) struct cmdline *cl,
2851                         __attribute__((unused)) void *data)
2852 {
2853         int ret;
2854         struct rte_eth_dev_info dev_info;
2855         struct rte_eth_rss_reta_entry64 reta_conf[8];
2856         struct cmd_config_rss_reta *res = parsed_result;
2857
2858         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2859         if (ret != 0)
2860                 return;
2861
2862         if (dev_info.reta_size == 0) {
2863                 printf("Redirection table size is 0 which is "
2864                                         "invalid for RSS\n");
2865                 return;
2866         } else
2867                 printf("The reta size of port %d is %u\n",
2868                         res->port_id, dev_info.reta_size);
2869         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2870                 printf("Currently do not support more than %u entries of "
2871                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2872                 return;
2873         }
2874
2875         memset(reta_conf, 0, sizeof(reta_conf));
2876         if (!strcmp(res->list_name, "reta")) {
2877                 if (parse_reta_config(res->list_of_items, reta_conf,
2878                                                 dev_info.reta_size)) {
2879                         printf("Invalid RSS Redirection Table "
2880                                         "config entered\n");
2881                         return;
2882                 }
2883                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2884                                 reta_conf, dev_info.reta_size);
2885                 if (ret != 0)
2886                         printf("Bad redirection table parameter, "
2887                                         "return code = %d \n", ret);
2888         }
2889 }
2890
2891 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2892         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2893 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2894         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2895 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2896         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2897 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2898         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2899 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2900         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2901 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2902         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2903                                  NULL);
2904 cmdline_parse_inst_t cmd_config_rss_reta = {
2905         .f = cmd_set_rss_reta_parsed,
2906         .data = NULL,
2907         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2908         .tokens = {
2909                 (void *)&cmd_config_rss_reta_port,
2910                 (void *)&cmd_config_rss_reta_keyword,
2911                 (void *)&cmd_config_rss_reta_port_id,
2912                 (void *)&cmd_config_rss_reta_name,
2913                 (void *)&cmd_config_rss_reta_list_name,
2914                 (void *)&cmd_config_rss_reta_list_of_items,
2915                 NULL,
2916         },
2917 };
2918
2919 /* *** SHOW PORT RETA INFO *** */
2920 struct cmd_showport_reta {
2921         cmdline_fixed_string_t show;
2922         cmdline_fixed_string_t port;
2923         portid_t port_id;
2924         cmdline_fixed_string_t rss;
2925         cmdline_fixed_string_t reta;
2926         uint16_t size;
2927         cmdline_fixed_string_t list_of_items;
2928 };
2929
2930 static int
2931 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2932                            uint16_t nb_entries,
2933                            char *str)
2934 {
2935         uint32_t size;
2936         const char *p, *p0 = str;
2937         char s[256];
2938         char *end;
2939         char *str_fld[8];
2940         uint16_t i;
2941         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2942                         RTE_RETA_GROUP_SIZE;
2943         int ret;
2944
2945         p = strchr(p0, '(');
2946         if (p == NULL)
2947                 return -1;
2948         p++;
2949         p0 = strchr(p, ')');
2950         if (p0 == NULL)
2951                 return -1;
2952         size = p0 - p;
2953         if (size >= sizeof(s)) {
2954                 printf("The string size exceeds the internal buffer size\n");
2955                 return -1;
2956         }
2957         snprintf(s, sizeof(s), "%.*s", size, p);
2958         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2959         if (ret <= 0 || ret != num) {
2960                 printf("The bits of masks do not match the number of "
2961                                         "reta entries: %u\n", num);
2962                 return -1;
2963         }
2964         for (i = 0; i < ret; i++)
2965                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2966
2967         return 0;
2968 }
2969
2970 static void
2971 cmd_showport_reta_parsed(void *parsed_result,
2972                          __attribute__((unused)) struct cmdline *cl,
2973                          __attribute__((unused)) void *data)
2974 {
2975         struct cmd_showport_reta *res = parsed_result;
2976         struct rte_eth_rss_reta_entry64 reta_conf[8];
2977         struct rte_eth_dev_info dev_info;
2978         uint16_t max_reta_size;
2979         int ret;
2980
2981         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2982         if (ret != 0)
2983                 return;
2984
2985         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2986         if (res->size == 0 || res->size > max_reta_size) {
2987                 printf("Invalid redirection table size: %u (1-%u)\n",
2988                         res->size, max_reta_size);
2989                 return;
2990         }
2991
2992         memset(reta_conf, 0, sizeof(reta_conf));
2993         if (showport_parse_reta_config(reta_conf, res->size,
2994                                 res->list_of_items) < 0) {
2995                 printf("Invalid string: %s for reta masks\n",
2996                                         res->list_of_items);
2997                 return;
2998         }
2999         port_rss_reta_info(res->port_id, reta_conf, res->size);
3000 }
3001
3002 cmdline_parse_token_string_t cmd_showport_reta_show =
3003         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3004 cmdline_parse_token_string_t cmd_showport_reta_port =
3005         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3006 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3007         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3008 cmdline_parse_token_string_t cmd_showport_reta_rss =
3009         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3010 cmdline_parse_token_string_t cmd_showport_reta_reta =
3011         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3012 cmdline_parse_token_num_t cmd_showport_reta_size =
3013         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3014 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3015         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3016                                         list_of_items, NULL);
3017
3018 cmdline_parse_inst_t cmd_showport_reta = {
3019         .f = cmd_showport_reta_parsed,
3020         .data = NULL,
3021         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3022         .tokens = {
3023                 (void *)&cmd_showport_reta_show,
3024                 (void *)&cmd_showport_reta_port,
3025                 (void *)&cmd_showport_reta_port_id,
3026                 (void *)&cmd_showport_reta_rss,
3027                 (void *)&cmd_showport_reta_reta,
3028                 (void *)&cmd_showport_reta_size,
3029                 (void *)&cmd_showport_reta_list_of_items,
3030                 NULL,
3031         },
3032 };
3033
3034 /* *** Show RSS hash configuration *** */
3035 struct cmd_showport_rss_hash {
3036         cmdline_fixed_string_t show;
3037         cmdline_fixed_string_t port;
3038         portid_t port_id;
3039         cmdline_fixed_string_t rss_hash;
3040         cmdline_fixed_string_t rss_type;
3041         cmdline_fixed_string_t key; /* optional argument */
3042 };
3043
3044 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3045                                 __attribute__((unused)) struct cmdline *cl,
3046                                 void *show_rss_key)
3047 {
3048         struct cmd_showport_rss_hash *res = parsed_result;
3049
3050         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3051 }
3052
3053 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3054         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3055 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3056         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3057 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3058         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3059 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3060         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3061                                  "rss-hash");
3062 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3063         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3064
3065 cmdline_parse_inst_t cmd_showport_rss_hash = {
3066         .f = cmd_showport_rss_hash_parsed,
3067         .data = NULL,
3068         .help_str = "show port <port_id> rss-hash",
3069         .tokens = {
3070                 (void *)&cmd_showport_rss_hash_show,
3071                 (void *)&cmd_showport_rss_hash_port,
3072                 (void *)&cmd_showport_rss_hash_port_id,
3073                 (void *)&cmd_showport_rss_hash_rss_hash,
3074                 NULL,
3075         },
3076 };
3077
3078 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3079         .f = cmd_showport_rss_hash_parsed,
3080         .data = (void *)1,
3081         .help_str = "show port <port_id> rss-hash key",
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                 (void *)&cmd_showport_rss_hash_rss_key,
3088                 NULL,
3089         },
3090 };
3091
3092 /* *** Configure DCB *** */
3093 struct cmd_config_dcb {
3094         cmdline_fixed_string_t port;
3095         cmdline_fixed_string_t config;
3096         portid_t port_id;
3097         cmdline_fixed_string_t dcb;
3098         cmdline_fixed_string_t vt;
3099         cmdline_fixed_string_t vt_en;
3100         uint8_t num_tcs;
3101         cmdline_fixed_string_t pfc;
3102         cmdline_fixed_string_t pfc_en;
3103 };
3104
3105 static void
3106 cmd_config_dcb_parsed(void *parsed_result,
3107                         __attribute__((unused)) struct cmdline *cl,
3108                         __attribute__((unused)) void *data)
3109 {
3110         struct cmd_config_dcb *res = parsed_result;
3111         portid_t port_id = res->port_id;
3112         struct rte_port *port;
3113         uint8_t pfc_en;
3114         int ret;
3115
3116         port = &ports[port_id];
3117         /** Check if the port is not started **/
3118         if (port->port_status != RTE_PORT_STOPPED) {
3119                 printf("Please stop port %d first\n", port_id);
3120                 return;
3121         }
3122
3123         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3124                 printf("The invalid number of traffic class,"
3125                         " only 4 or 8 allowed.\n");
3126                 return;
3127         }
3128
3129         if (nb_fwd_lcores < res->num_tcs) {
3130                 printf("nb_cores shouldn't be less than number of TCs.\n");
3131                 return;
3132         }
3133         if (!strncmp(res->pfc_en, "on", 2))
3134                 pfc_en = 1;
3135         else
3136                 pfc_en = 0;
3137
3138         /* DCB in VT mode */
3139         if (!strncmp(res->vt_en, "on", 2))
3140                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3141                                 (enum rte_eth_nb_tcs)res->num_tcs,
3142                                 pfc_en);
3143         else
3144                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3145                                 (enum rte_eth_nb_tcs)res->num_tcs,
3146                                 pfc_en);
3147
3148
3149         if (ret != 0) {
3150                 printf("Cannot initialize network ports.\n");
3151                 return;
3152         }
3153
3154         cmd_reconfig_device_queue(port_id, 1, 1);
3155 }
3156
3157 cmdline_parse_token_string_t cmd_config_dcb_port =
3158         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3159 cmdline_parse_token_string_t cmd_config_dcb_config =
3160         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3161 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3162         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3163 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3164         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3165 cmdline_parse_token_string_t cmd_config_dcb_vt =
3166         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3167 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3168         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3169 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3170         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3171 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3172         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3173 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3174         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3175
3176 cmdline_parse_inst_t cmd_config_dcb = {
3177         .f = cmd_config_dcb_parsed,
3178         .data = NULL,
3179         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3180         .tokens = {
3181                 (void *)&cmd_config_dcb_port,
3182                 (void *)&cmd_config_dcb_config,
3183                 (void *)&cmd_config_dcb_port_id,
3184                 (void *)&cmd_config_dcb_dcb,
3185                 (void *)&cmd_config_dcb_vt,
3186                 (void *)&cmd_config_dcb_vt_en,
3187                 (void *)&cmd_config_dcb_num_tcs,
3188                 (void *)&cmd_config_dcb_pfc,
3189                 (void *)&cmd_config_dcb_pfc_en,
3190                 NULL,
3191         },
3192 };
3193
3194 /* *** configure number of packets per burst *** */
3195 struct cmd_config_burst {
3196         cmdline_fixed_string_t port;
3197         cmdline_fixed_string_t keyword;
3198         cmdline_fixed_string_t all;
3199         cmdline_fixed_string_t name;
3200         uint16_t value;
3201 };
3202
3203 static void
3204 cmd_config_burst_parsed(void *parsed_result,
3205                         __attribute__((unused)) struct cmdline *cl,
3206                         __attribute__((unused)) void *data)
3207 {
3208         struct cmd_config_burst *res = parsed_result;
3209         struct rte_eth_dev_info dev_info;
3210         uint16_t rec_nb_pkts;
3211         int ret;
3212
3213         if (!all_ports_stopped()) {
3214                 printf("Please stop all ports first\n");
3215                 return;
3216         }
3217
3218         if (!strcmp(res->name, "burst")) {
3219                 if (res->value == 0) {
3220                         /* If user gives a value of zero, query the PMD for
3221                          * its recommended Rx burst size. Testpmd uses a single
3222                          * size for all ports, so assume all ports are the same
3223                          * NIC model and use the values from Port 0.
3224                          */
3225                         ret = eth_dev_info_get_print_err(0, &dev_info);
3226                         if (ret != 0)
3227                                 return;
3228
3229                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3230
3231                         if (rec_nb_pkts == 0) {
3232                                 printf("PMD does not recommend a burst size.\n"
3233                                         "User provided value must be between"
3234                                         " 1 and %d\n", MAX_PKT_BURST);
3235                                 return;
3236                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3237                                 printf("PMD recommended burst size of %d"
3238                                         " exceeds maximum value of %d\n",
3239                                         rec_nb_pkts, MAX_PKT_BURST);
3240                                 return;
3241                         }
3242                         printf("Using PMD-provided burst value of %d\n",
3243                                 rec_nb_pkts);
3244                         nb_pkt_per_burst = rec_nb_pkts;
3245                 } else if (res->value > MAX_PKT_BURST) {
3246                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3247                         return;
3248                 } else
3249                         nb_pkt_per_burst = res->value;
3250         } else {
3251                 printf("Unknown parameter\n");
3252                 return;
3253         }
3254
3255         init_port_config();
3256
3257         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3258 }
3259
3260 cmdline_parse_token_string_t cmd_config_burst_port =
3261         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3262 cmdline_parse_token_string_t cmd_config_burst_keyword =
3263         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3264 cmdline_parse_token_string_t cmd_config_burst_all =
3265         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3266 cmdline_parse_token_string_t cmd_config_burst_name =
3267         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3268 cmdline_parse_token_num_t cmd_config_burst_value =
3269         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3270
3271 cmdline_parse_inst_t cmd_config_burst = {
3272         .f = cmd_config_burst_parsed,
3273         .data = NULL,
3274         .help_str = "port config all burst <value>",
3275         .tokens = {
3276                 (void *)&cmd_config_burst_port,
3277                 (void *)&cmd_config_burst_keyword,
3278                 (void *)&cmd_config_burst_all,
3279                 (void *)&cmd_config_burst_name,
3280                 (void *)&cmd_config_burst_value,
3281                 NULL,
3282         },
3283 };
3284
3285 /* *** configure rx/tx queues *** */
3286 struct cmd_config_thresh {
3287         cmdline_fixed_string_t port;
3288         cmdline_fixed_string_t keyword;
3289         cmdline_fixed_string_t all;
3290         cmdline_fixed_string_t name;
3291         uint8_t value;
3292 };
3293
3294 static void
3295 cmd_config_thresh_parsed(void *parsed_result,
3296                         __attribute__((unused)) struct cmdline *cl,
3297                         __attribute__((unused)) void *data)
3298 {
3299         struct cmd_config_thresh *res = parsed_result;
3300
3301         if (!all_ports_stopped()) {
3302                 printf("Please stop all ports first\n");
3303                 return;
3304         }
3305
3306         if (!strcmp(res->name, "txpt"))
3307                 tx_pthresh = res->value;
3308         else if(!strcmp(res->name, "txht"))
3309                 tx_hthresh = res->value;
3310         else if(!strcmp(res->name, "txwt"))
3311                 tx_wthresh = res->value;
3312         else if(!strcmp(res->name, "rxpt"))
3313                 rx_pthresh = res->value;
3314         else if(!strcmp(res->name, "rxht"))
3315                 rx_hthresh = res->value;
3316         else if(!strcmp(res->name, "rxwt"))
3317                 rx_wthresh = res->value;
3318         else {
3319                 printf("Unknown parameter\n");
3320                 return;
3321         }
3322
3323         init_port_config();
3324
3325         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3326 }
3327
3328 cmdline_parse_token_string_t cmd_config_thresh_port =
3329         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3330 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3331         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3332 cmdline_parse_token_string_t cmd_config_thresh_all =
3333         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3334 cmdline_parse_token_string_t cmd_config_thresh_name =
3335         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3336                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3337 cmdline_parse_token_num_t cmd_config_thresh_value =
3338         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3339
3340 cmdline_parse_inst_t cmd_config_thresh = {
3341         .f = cmd_config_thresh_parsed,
3342         .data = NULL,
3343         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3344         .tokens = {
3345                 (void *)&cmd_config_thresh_port,
3346                 (void *)&cmd_config_thresh_keyword,
3347                 (void *)&cmd_config_thresh_all,
3348                 (void *)&cmd_config_thresh_name,
3349                 (void *)&cmd_config_thresh_value,
3350                 NULL,
3351         },
3352 };
3353
3354 /* *** configure free/rs threshold *** */
3355 struct cmd_config_threshold {
3356         cmdline_fixed_string_t port;
3357         cmdline_fixed_string_t keyword;
3358         cmdline_fixed_string_t all;
3359         cmdline_fixed_string_t name;
3360         uint16_t value;
3361 };
3362
3363 static void
3364 cmd_config_threshold_parsed(void *parsed_result,
3365                         __attribute__((unused)) struct cmdline *cl,
3366                         __attribute__((unused)) void *data)
3367 {
3368         struct cmd_config_threshold *res = parsed_result;
3369
3370         if (!all_ports_stopped()) {
3371                 printf("Please stop all ports first\n");
3372                 return;
3373         }
3374
3375         if (!strcmp(res->name, "txfreet"))
3376                 tx_free_thresh = res->value;
3377         else if (!strcmp(res->name, "txrst"))
3378                 tx_rs_thresh = res->value;
3379         else if (!strcmp(res->name, "rxfreet"))
3380                 rx_free_thresh = res->value;
3381         else {
3382                 printf("Unknown parameter\n");
3383                 return;
3384         }
3385
3386         init_port_config();
3387
3388         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3389 }
3390
3391 cmdline_parse_token_string_t cmd_config_threshold_port =
3392         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3393 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3394         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3395                                                                 "config");
3396 cmdline_parse_token_string_t cmd_config_threshold_all =
3397         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3398 cmdline_parse_token_string_t cmd_config_threshold_name =
3399         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3400                                                 "txfreet#txrst#rxfreet");
3401 cmdline_parse_token_num_t cmd_config_threshold_value =
3402         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3403
3404 cmdline_parse_inst_t cmd_config_threshold = {
3405         .f = cmd_config_threshold_parsed,
3406         .data = NULL,
3407         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3408         .tokens = {
3409                 (void *)&cmd_config_threshold_port,
3410                 (void *)&cmd_config_threshold_keyword,
3411                 (void *)&cmd_config_threshold_all,
3412                 (void *)&cmd_config_threshold_name,
3413                 (void *)&cmd_config_threshold_value,
3414                 NULL,
3415         },
3416 };
3417
3418 /* *** stop *** */
3419 struct cmd_stop_result {
3420         cmdline_fixed_string_t stop;
3421 };
3422
3423 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3424                             __attribute__((unused)) struct cmdline *cl,
3425                             __attribute__((unused)) void *data)
3426 {
3427         stop_packet_forwarding();
3428 }
3429
3430 cmdline_parse_token_string_t cmd_stop_stop =
3431         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3432
3433 cmdline_parse_inst_t cmd_stop = {
3434         .f = cmd_stop_parsed,
3435         .data = NULL,
3436         .help_str = "stop: Stop packet forwarding",
3437         .tokens = {
3438                 (void *)&cmd_stop_stop,
3439                 NULL,
3440         },
3441 };
3442
3443 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3444
3445 unsigned int
3446 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3447                 unsigned int *parsed_items, int check_unique_values)
3448 {
3449         unsigned int nb_item;
3450         unsigned int value;
3451         unsigned int i;
3452         unsigned int j;
3453         int value_ok;
3454         char c;
3455
3456         /*
3457          * First parse all items in the list and store their value.
3458          */
3459         value = 0;
3460         nb_item = 0;
3461         value_ok = 0;
3462         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3463                 c = str[i];
3464                 if ((c >= '0') && (c <= '9')) {
3465                         value = (unsigned int) (value * 10 + (c - '0'));
3466                         value_ok = 1;
3467                         continue;
3468                 }
3469                 if (c != ',') {
3470                         printf("character %c is not a decimal digit\n", c);
3471                         return 0;
3472                 }
3473                 if (! value_ok) {
3474                         printf("No valid value before comma\n");
3475                         return 0;
3476                 }
3477                 if (nb_item < max_items) {
3478                         parsed_items[nb_item] = value;
3479                         value_ok = 0;
3480                         value = 0;
3481                 }
3482                 nb_item++;
3483         }
3484         if (nb_item >= max_items) {
3485                 printf("Number of %s = %u > %u (maximum items)\n",
3486                        item_name, nb_item + 1, max_items);
3487                 return 0;
3488         }
3489         parsed_items[nb_item++] = value;
3490         if (! check_unique_values)
3491                 return nb_item;
3492
3493         /*
3494          * Then, check that all values in the list are differents.
3495          * No optimization here...
3496          */
3497         for (i = 0; i < nb_item; i++) {
3498                 for (j = i + 1; j < nb_item; j++) {
3499                         if (parsed_items[j] == parsed_items[i]) {
3500                                 printf("duplicated %s %u at index %u and %u\n",
3501                                        item_name, parsed_items[i], i, j);
3502                                 return 0;
3503                         }
3504                 }
3505         }
3506         return nb_item;
3507 }
3508
3509 struct cmd_set_list_result {
3510         cmdline_fixed_string_t cmd_keyword;
3511         cmdline_fixed_string_t list_name;
3512         cmdline_fixed_string_t list_of_items;
3513 };
3514
3515 static void cmd_set_list_parsed(void *parsed_result,
3516                                 __attribute__((unused)) struct cmdline *cl,
3517                                 __attribute__((unused)) void *data)
3518 {
3519         struct cmd_set_list_result *res;
3520         union {
3521                 unsigned int lcorelist[RTE_MAX_LCORE];
3522                 unsigned int portlist[RTE_MAX_ETHPORTS];
3523         } parsed_items;
3524         unsigned int nb_item;
3525
3526         if (test_done == 0) {
3527                 printf("Please stop forwarding first\n");
3528                 return;
3529         }
3530
3531         res = parsed_result;
3532         if (!strcmp(res->list_name, "corelist")) {
3533                 nb_item = parse_item_list(res->list_of_items, "core",
3534                                           RTE_MAX_LCORE,
3535                                           parsed_items.lcorelist, 1);
3536                 if (nb_item > 0) {
3537                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3538                         fwd_config_setup();
3539                 }
3540                 return;
3541         }
3542         if (!strcmp(res->list_name, "portlist")) {
3543                 nb_item = parse_item_list(res->list_of_items, "port",
3544                                           RTE_MAX_ETHPORTS,
3545                                           parsed_items.portlist, 1);
3546                 if (nb_item > 0) {
3547                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3548                         fwd_config_setup();
3549                 }
3550         }
3551 }
3552
3553 cmdline_parse_token_string_t cmd_set_list_keyword =
3554         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3555                                  "set");
3556 cmdline_parse_token_string_t cmd_set_list_name =
3557         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3558                                  "corelist#portlist");
3559 cmdline_parse_token_string_t cmd_set_list_of_items =
3560         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3561                                  NULL);
3562
3563 cmdline_parse_inst_t cmd_set_fwd_list = {
3564         .f = cmd_set_list_parsed,
3565         .data = NULL,
3566         .help_str = "set corelist|portlist <list0[,list1]*>",
3567         .tokens = {
3568                 (void *)&cmd_set_list_keyword,
3569                 (void *)&cmd_set_list_name,
3570                 (void *)&cmd_set_list_of_items,
3571                 NULL,
3572         },
3573 };
3574
3575 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3576
3577 struct cmd_setmask_result {
3578         cmdline_fixed_string_t set;
3579         cmdline_fixed_string_t mask;
3580         uint64_t hexavalue;
3581 };
3582
3583 static void cmd_set_mask_parsed(void *parsed_result,
3584                                 __attribute__((unused)) struct cmdline *cl,
3585                                 __attribute__((unused)) void *data)
3586 {
3587         struct cmd_setmask_result *res = parsed_result;
3588
3589         if (test_done == 0) {
3590                 printf("Please stop forwarding first\n");
3591                 return;
3592         }
3593         if (!strcmp(res->mask, "coremask")) {
3594                 set_fwd_lcores_mask(res->hexavalue);
3595                 fwd_config_setup();
3596         } else if (!strcmp(res->mask, "portmask")) {
3597                 set_fwd_ports_mask(res->hexavalue);
3598                 fwd_config_setup();
3599         }
3600 }
3601
3602 cmdline_parse_token_string_t cmd_setmask_set =
3603         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3604 cmdline_parse_token_string_t cmd_setmask_mask =
3605         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3606                                  "coremask#portmask");
3607 cmdline_parse_token_num_t cmd_setmask_value =
3608         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3609
3610 cmdline_parse_inst_t cmd_set_fwd_mask = {
3611         .f = cmd_set_mask_parsed,
3612         .data = NULL,
3613         .help_str = "set coremask|portmask <hexadecimal value>",
3614         .tokens = {
3615                 (void *)&cmd_setmask_set,
3616                 (void *)&cmd_setmask_mask,
3617                 (void *)&cmd_setmask_value,
3618                 NULL,
3619         },
3620 };
3621
3622 /*
3623  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3624  */
3625 struct cmd_set_result {
3626         cmdline_fixed_string_t set;
3627         cmdline_fixed_string_t what;
3628         uint16_t value;
3629 };
3630
3631 static void cmd_set_parsed(void *parsed_result,
3632                            __attribute__((unused)) struct cmdline *cl,
3633                            __attribute__((unused)) void *data)
3634 {
3635         struct cmd_set_result *res = parsed_result;
3636         if (!strcmp(res->what, "nbport")) {
3637                 set_fwd_ports_number(res->value);
3638                 fwd_config_setup();
3639         } else if (!strcmp(res->what, "nbcore")) {
3640                 set_fwd_lcores_number(res->value);
3641                 fwd_config_setup();
3642         } else if (!strcmp(res->what, "burst"))
3643                 set_nb_pkt_per_burst(res->value);
3644         else if (!strcmp(res->what, "verbose"))
3645                 set_verbose_level(res->value);
3646 }
3647
3648 cmdline_parse_token_string_t cmd_set_set =
3649         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3650 cmdline_parse_token_string_t cmd_set_what =
3651         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3652                                  "nbport#nbcore#burst#verbose");
3653 cmdline_parse_token_num_t cmd_set_value =
3654         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3655
3656 cmdline_parse_inst_t cmd_set_numbers = {
3657         .f = cmd_set_parsed,
3658         .data = NULL,
3659         .help_str = "set nbport|nbcore|burst|verbose <value>",
3660         .tokens = {
3661                 (void *)&cmd_set_set,
3662                 (void *)&cmd_set_what,
3663                 (void *)&cmd_set_value,
3664                 NULL,
3665         },
3666 };
3667
3668 /* *** SET LOG LEVEL CONFIGURATION *** */
3669
3670 struct cmd_set_log_result {
3671         cmdline_fixed_string_t set;
3672         cmdline_fixed_string_t log;
3673         cmdline_fixed_string_t type;
3674         uint32_t level;
3675 };
3676
3677 static void
3678 cmd_set_log_parsed(void *parsed_result,
3679                    __attribute__((unused)) struct cmdline *cl,
3680                    __attribute__((unused)) void *data)
3681 {
3682         struct cmd_set_log_result *res;
3683         int ret;
3684
3685         res = parsed_result;
3686         if (!strcmp(res->type, "global"))
3687                 rte_log_set_global_level(res->level);
3688         else {
3689                 ret = rte_log_set_level_regexp(res->type, res->level);
3690                 if (ret < 0)
3691                         printf("Unable to set log level\n");
3692         }
3693 }
3694
3695 cmdline_parse_token_string_t cmd_set_log_set =
3696         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3697 cmdline_parse_token_string_t cmd_set_log_log =
3698         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3699 cmdline_parse_token_string_t cmd_set_log_type =
3700         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3701 cmdline_parse_token_num_t cmd_set_log_level =
3702         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3703
3704 cmdline_parse_inst_t cmd_set_log = {
3705         .f = cmd_set_log_parsed,
3706         .data = NULL,
3707         .help_str = "set log global|<type> <level>",
3708         .tokens = {
3709                 (void *)&cmd_set_log_set,
3710                 (void *)&cmd_set_log_log,
3711                 (void *)&cmd_set_log_type,
3712                 (void *)&cmd_set_log_level,
3713                 NULL,
3714         },
3715 };
3716
3717 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3718
3719 struct cmd_set_txpkts_result {
3720         cmdline_fixed_string_t cmd_keyword;
3721         cmdline_fixed_string_t txpkts;
3722         cmdline_fixed_string_t seg_lengths;
3723 };
3724
3725 static void
3726 cmd_set_txpkts_parsed(void *parsed_result,
3727                       __attribute__((unused)) struct cmdline *cl,
3728                       __attribute__((unused)) void *data)
3729 {
3730         struct cmd_set_txpkts_result *res;
3731         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3732         unsigned int nb_segs;
3733
3734         res = parsed_result;
3735         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3736                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3737         if (nb_segs > 0)
3738                 set_tx_pkt_segments(seg_lengths, nb_segs);
3739 }
3740
3741 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3742         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3743                                  cmd_keyword, "set");
3744 cmdline_parse_token_string_t cmd_set_txpkts_name =
3745         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3746                                  txpkts, "txpkts");
3747 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3748         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3749                                  seg_lengths, NULL);
3750
3751 cmdline_parse_inst_t cmd_set_txpkts = {
3752         .f = cmd_set_txpkts_parsed,
3753         .data = NULL,
3754         .help_str = "set txpkts <len0[,len1]*>",
3755         .tokens = {
3756                 (void *)&cmd_set_txpkts_keyword,
3757                 (void *)&cmd_set_txpkts_name,
3758                 (void *)&cmd_set_txpkts_lengths,
3759                 NULL,
3760         },
3761 };
3762
3763 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3764
3765 struct cmd_set_txsplit_result {
3766         cmdline_fixed_string_t cmd_keyword;
3767         cmdline_fixed_string_t txsplit;
3768         cmdline_fixed_string_t mode;
3769 };
3770
3771 static void
3772 cmd_set_txsplit_parsed(void *parsed_result,
3773                       __attribute__((unused)) struct cmdline *cl,
3774                       __attribute__((unused)) void *data)
3775 {
3776         struct cmd_set_txsplit_result *res;
3777
3778         res = parsed_result;
3779         set_tx_pkt_split(res->mode);
3780 }
3781
3782 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3783         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3784                                  cmd_keyword, "set");
3785 cmdline_parse_token_string_t cmd_set_txsplit_name =
3786         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3787                                  txsplit, "txsplit");
3788 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3789         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3790                                  mode, NULL);
3791
3792 cmdline_parse_inst_t cmd_set_txsplit = {
3793         .f = cmd_set_txsplit_parsed,
3794         .data = NULL,
3795         .help_str = "set txsplit on|off|rand",
3796         .tokens = {
3797                 (void *)&cmd_set_txsplit_keyword,
3798                 (void *)&cmd_set_txsplit_name,
3799                 (void *)&cmd_set_txsplit_mode,
3800                 NULL,
3801         },
3802 };
3803
3804 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3805 struct cmd_rx_vlan_filter_all_result {
3806         cmdline_fixed_string_t rx_vlan;
3807         cmdline_fixed_string_t what;
3808         cmdline_fixed_string_t all;
3809         portid_t port_id;
3810 };
3811
3812 static void
3813 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3814                               __attribute__((unused)) struct cmdline *cl,
3815                               __attribute__((unused)) void *data)
3816 {
3817         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3818
3819         if (!strcmp(res->what, "add"))
3820                 rx_vlan_all_filter_set(res->port_id, 1);
3821         else
3822                 rx_vlan_all_filter_set(res->port_id, 0);
3823 }
3824
3825 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3826         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3827                                  rx_vlan, "rx_vlan");
3828 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3829         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3830                                  what, "add#rm");
3831 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3832         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3833                                  all, "all");
3834 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3835         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3836                               port_id, UINT16);
3837
3838 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3839         .f = cmd_rx_vlan_filter_all_parsed,
3840         .data = NULL,
3841         .help_str = "rx_vlan add|rm all <port_id>: "
3842                 "Add/Remove all identifiers to/from the set of VLAN "
3843                 "identifiers filtered by a port",
3844         .tokens = {
3845                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3846                 (void *)&cmd_rx_vlan_filter_all_what,
3847                 (void *)&cmd_rx_vlan_filter_all_all,
3848                 (void *)&cmd_rx_vlan_filter_all_portid,
3849                 NULL,
3850         },
3851 };
3852
3853 /* *** VLAN OFFLOAD SET ON A PORT *** */
3854 struct cmd_vlan_offload_result {
3855         cmdline_fixed_string_t vlan;
3856         cmdline_fixed_string_t set;
3857         cmdline_fixed_string_t vlan_type;
3858         cmdline_fixed_string_t what;
3859         cmdline_fixed_string_t on;
3860         cmdline_fixed_string_t port_id;
3861 };
3862
3863 static void
3864 cmd_vlan_offload_parsed(void *parsed_result,
3865                           __attribute__((unused)) struct cmdline *cl,
3866                           __attribute__((unused)) void *data)
3867 {
3868         int on;
3869         struct cmd_vlan_offload_result *res = parsed_result;
3870         char *str;
3871         int i, len = 0;
3872         portid_t port_id = 0;
3873         unsigned int tmp;
3874
3875         str = res->port_id;
3876         len = strnlen(str, STR_TOKEN_SIZE);
3877         i = 0;
3878         /* Get port_id first */
3879         while(i < len){
3880                 if(str[i] == ',')
3881                         break;
3882
3883                 i++;
3884         }
3885         str[i]='\0';
3886         tmp = strtoul(str, NULL, 0);
3887         /* If port_id greater that what portid_t can represent, return */
3888         if(tmp >= RTE_MAX_ETHPORTS)
3889                 return;
3890         port_id = (portid_t)tmp;
3891
3892         if (!strcmp(res->on, "on"))
3893                 on = 1;
3894         else
3895                 on = 0;
3896
3897         if (!strcmp(res->what, "strip"))
3898                 rx_vlan_strip_set(port_id,  on);
3899         else if(!strcmp(res->what, "stripq")){
3900                 uint16_t queue_id = 0;
3901
3902                 /* No queue_id, return */
3903                 if(i + 1 >= len) {
3904                         printf("must specify (port,queue_id)\n");
3905                         return;
3906                 }
3907                 tmp = strtoul(str + i + 1, NULL, 0);
3908                 /* If queue_id greater that what 16-bits can represent, return */
3909                 if(tmp > 0xffff)
3910                         return;
3911
3912                 queue_id = (uint16_t)tmp;
3913                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3914         }
3915         else if (!strcmp(res->what, "filter"))
3916                 rx_vlan_filter_set(port_id, on);
3917         else if (!strcmp(res->what, "qinq_strip"))
3918                 rx_vlan_qinq_strip_set(port_id, on);
3919         else
3920                 vlan_extend_set(port_id, on);
3921
3922         return;
3923 }
3924
3925 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3926         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3927                                  vlan, "vlan");
3928 cmdline_parse_token_string_t cmd_vlan_offload_set =
3929         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3930                                  set, "set");
3931 cmdline_parse_token_string_t cmd_vlan_offload_what =
3932         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3933                                 what, "strip#filter#qinq_strip#extend#stripq");
3934 cmdline_parse_token_string_t cmd_vlan_offload_on =
3935         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3936                               on, "on#off");
3937 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3938         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3939                               port_id, NULL);
3940
3941 cmdline_parse_inst_t cmd_vlan_offload = {
3942         .f = cmd_vlan_offload_parsed,
3943         .data = NULL,
3944         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
3945                 "<port_id[,queue_id]>: "
3946                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
3947         .tokens = {
3948                 (void *)&cmd_vlan_offload_vlan,
3949                 (void *)&cmd_vlan_offload_set,
3950                 (void *)&cmd_vlan_offload_what,
3951                 (void *)&cmd_vlan_offload_on,
3952                 (void *)&cmd_vlan_offload_portid,
3953                 NULL,
3954         },
3955 };
3956
3957 /* *** VLAN TPID SET ON A PORT *** */
3958 struct cmd_vlan_tpid_result {
3959         cmdline_fixed_string_t vlan;
3960         cmdline_fixed_string_t set;
3961         cmdline_fixed_string_t vlan_type;
3962         cmdline_fixed_string_t what;
3963         uint16_t tp_id;
3964         portid_t port_id;
3965 };
3966
3967 static void
3968 cmd_vlan_tpid_parsed(void *parsed_result,
3969                           __attribute__((unused)) struct cmdline *cl,
3970                           __attribute__((unused)) void *data)
3971 {
3972         struct cmd_vlan_tpid_result *res = parsed_result;
3973         enum rte_vlan_type vlan_type;
3974
3975         if (!strcmp(res->vlan_type, "inner"))
3976                 vlan_type = ETH_VLAN_TYPE_INNER;
3977         else if (!strcmp(res->vlan_type, "outer"))
3978                 vlan_type = ETH_VLAN_TYPE_OUTER;
3979         else {
3980                 printf("Unknown vlan type\n");
3981                 return;
3982         }
3983         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3984 }
3985
3986 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3987         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3988                                  vlan, "vlan");
3989 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3990         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3991                                  set, "set");
3992 cmdline_parse_token_string_t cmd_vlan_type =
3993         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3994                                  vlan_type, "inner#outer");
3995 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3996         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3997                                  what, "tpid");
3998 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3999         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4000                               tp_id, UINT16);
4001 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4002         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4003                               port_id, UINT16);
4004
4005 cmdline_parse_inst_t cmd_vlan_tpid = {
4006         .f = cmd_vlan_tpid_parsed,
4007         .data = NULL,
4008         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4009                 "Set the VLAN Ether type",
4010         .tokens = {
4011                 (void *)&cmd_vlan_tpid_vlan,
4012                 (void *)&cmd_vlan_tpid_set,
4013                 (void *)&cmd_vlan_type,
4014                 (void *)&cmd_vlan_tpid_what,
4015                 (void *)&cmd_vlan_tpid_tpid,
4016                 (void *)&cmd_vlan_tpid_portid,
4017                 NULL,
4018         },
4019 };
4020
4021 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4022 struct cmd_rx_vlan_filter_result {
4023         cmdline_fixed_string_t rx_vlan;
4024         cmdline_fixed_string_t what;
4025         uint16_t vlan_id;
4026         portid_t port_id;
4027 };
4028
4029 static void
4030 cmd_rx_vlan_filter_parsed(void *parsed_result,
4031                           __attribute__((unused)) struct cmdline *cl,
4032                           __attribute__((unused)) void *data)
4033 {
4034         struct cmd_rx_vlan_filter_result *res = parsed_result;
4035
4036         if (!strcmp(res->what, "add"))
4037                 rx_vft_set(res->port_id, res->vlan_id, 1);
4038         else
4039                 rx_vft_set(res->port_id, res->vlan_id, 0);
4040 }
4041
4042 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4043         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4044                                  rx_vlan, "rx_vlan");
4045 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4046         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4047                                  what, "add#rm");
4048 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4049         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4050                               vlan_id, UINT16);
4051 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4052         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4053                               port_id, UINT16);
4054
4055 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4056         .f = cmd_rx_vlan_filter_parsed,
4057         .data = NULL,
4058         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4059                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4060                 "identifiers filtered by a port",
4061         .tokens = {
4062                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4063                 (void *)&cmd_rx_vlan_filter_what,
4064                 (void *)&cmd_rx_vlan_filter_vlanid,
4065                 (void *)&cmd_rx_vlan_filter_portid,
4066                 NULL,
4067         },
4068 };
4069
4070 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4071 struct cmd_tx_vlan_set_result {
4072         cmdline_fixed_string_t tx_vlan;
4073         cmdline_fixed_string_t set;
4074         portid_t port_id;
4075         uint16_t vlan_id;
4076 };
4077
4078 static void
4079 cmd_tx_vlan_set_parsed(void *parsed_result,
4080                        __attribute__((unused)) struct cmdline *cl,
4081                        __attribute__((unused)) void *data)
4082 {
4083         struct cmd_tx_vlan_set_result *res = parsed_result;
4084
4085         if (!port_is_stopped(res->port_id)) {
4086                 printf("Please stop port %d first\n", res->port_id);
4087                 return;
4088         }
4089
4090         tx_vlan_set(res->port_id, res->vlan_id);
4091
4092         cmd_reconfig_device_queue(res->port_id, 1, 1);
4093 }
4094
4095 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4096         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4097                                  tx_vlan, "tx_vlan");
4098 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4099         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4100                                  set, "set");
4101 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4102         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4103                               port_id, UINT16);
4104 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4105         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4106                               vlan_id, UINT16);
4107
4108 cmdline_parse_inst_t cmd_tx_vlan_set = {
4109         .f = cmd_tx_vlan_set_parsed,
4110         .data = NULL,
4111         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4112                 "Enable hardware insertion of a single VLAN header "
4113                 "with a given TAG Identifier in packets sent on a port",
4114         .tokens = {
4115                 (void *)&cmd_tx_vlan_set_tx_vlan,
4116                 (void *)&cmd_tx_vlan_set_set,
4117                 (void *)&cmd_tx_vlan_set_portid,
4118                 (void *)&cmd_tx_vlan_set_vlanid,
4119                 NULL,
4120         },
4121 };
4122
4123 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4124 struct cmd_tx_vlan_set_qinq_result {
4125         cmdline_fixed_string_t tx_vlan;
4126         cmdline_fixed_string_t set;
4127         portid_t port_id;
4128         uint16_t vlan_id;
4129         uint16_t vlan_id_outer;
4130 };
4131
4132 static void
4133 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4134                             __attribute__((unused)) struct cmdline *cl,
4135                             __attribute__((unused)) void *data)
4136 {
4137         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4138
4139         if (!port_is_stopped(res->port_id)) {
4140                 printf("Please stop port %d first\n", res->port_id);
4141                 return;
4142         }
4143
4144         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4145
4146         cmd_reconfig_device_queue(res->port_id, 1, 1);
4147 }
4148
4149 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4150         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4151                 tx_vlan, "tx_vlan");
4152 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4153         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4154                 set, "set");
4155 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4156         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4157                 port_id, UINT16);
4158 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4159         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4160                 vlan_id, UINT16);
4161 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4162         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4163                 vlan_id_outer, UINT16);
4164
4165 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4166         .f = cmd_tx_vlan_set_qinq_parsed,
4167         .data = NULL,
4168         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4169                 "Enable hardware insertion of double VLAN header "
4170                 "with given TAG Identifiers in packets sent on a port",
4171         .tokens = {
4172                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4173                 (void *)&cmd_tx_vlan_set_qinq_set,
4174                 (void *)&cmd_tx_vlan_set_qinq_portid,
4175                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4176                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4177                 NULL,
4178         },
4179 };
4180
4181 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4182 struct cmd_tx_vlan_set_pvid_result {
4183         cmdline_fixed_string_t tx_vlan;
4184         cmdline_fixed_string_t set;
4185         cmdline_fixed_string_t pvid;
4186         portid_t port_id;
4187         uint16_t vlan_id;
4188         cmdline_fixed_string_t mode;
4189 };
4190
4191 static void
4192 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4193                             __attribute__((unused)) struct cmdline *cl,
4194                             __attribute__((unused)) void *data)
4195 {
4196         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4197
4198         if (strcmp(res->mode, "on") == 0)
4199                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4200         else
4201                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4202 }
4203
4204 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4205         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4206                                  tx_vlan, "tx_vlan");
4207 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4208         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4209                                  set, "set");
4210 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4211         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4212                                  pvid, "pvid");
4213 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4214         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4215                              port_id, UINT16);
4216 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4217         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4218                               vlan_id, UINT16);
4219 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4220         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4221                                  mode, "on#off");
4222
4223 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4224         .f = cmd_tx_vlan_set_pvid_parsed,
4225         .data = NULL,
4226         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4227         .tokens = {
4228                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4229                 (void *)&cmd_tx_vlan_set_pvid_set,
4230                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4231                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4232                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4233                 (void *)&cmd_tx_vlan_set_pvid_mode,
4234                 NULL,
4235         },
4236 };
4237
4238 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4239 struct cmd_tx_vlan_reset_result {
4240         cmdline_fixed_string_t tx_vlan;
4241         cmdline_fixed_string_t reset;
4242         portid_t port_id;
4243 };
4244
4245 static void
4246 cmd_tx_vlan_reset_parsed(void *parsed_result,
4247                          __attribute__((unused)) struct cmdline *cl,
4248                          __attribute__((unused)) void *data)
4249 {
4250         struct cmd_tx_vlan_reset_result *res = parsed_result;
4251
4252         if (!port_is_stopped(res->port_id)) {
4253                 printf("Please stop port %d first\n", res->port_id);
4254                 return;
4255         }
4256
4257         tx_vlan_reset(res->port_id);
4258
4259         cmd_reconfig_device_queue(res->port_id, 1, 1);
4260 }
4261
4262 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4263         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4264                                  tx_vlan, "tx_vlan");
4265 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4266         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4267                                  reset, "reset");
4268 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4269         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4270                               port_id, UINT16);
4271
4272 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4273         .f = cmd_tx_vlan_reset_parsed,
4274         .data = NULL,
4275         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4276                 "VLAN header in packets sent on a port",
4277         .tokens = {
4278                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4279                 (void *)&cmd_tx_vlan_reset_reset,
4280                 (void *)&cmd_tx_vlan_reset_portid,
4281                 NULL,
4282         },
4283 };
4284
4285
4286 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4287 struct cmd_csum_result {
4288         cmdline_fixed_string_t csum;
4289         cmdline_fixed_string_t mode;
4290         cmdline_fixed_string_t proto;
4291         cmdline_fixed_string_t hwsw;
4292         portid_t port_id;
4293 };
4294
4295 static void
4296 csum_show(int port_id)
4297 {
4298         struct rte_eth_dev_info dev_info;
4299         uint64_t tx_offloads;
4300         int ret;
4301
4302         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4303         printf("Parse tunnel is %s\n",
4304                 (ports[port_id].parse_tunnel) ? "on" : "off");
4305         printf("IP checksum offload is %s\n",
4306                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4307         printf("UDP checksum offload is %s\n",
4308                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4309         printf("TCP checksum offload is %s\n",
4310                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4311         printf("SCTP checksum offload is %s\n",
4312                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4313         printf("Outer-Ip checksum offload is %s\n",
4314                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4315         printf("Outer-Udp checksum offload is %s\n",
4316                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4317
4318         /* display warnings if configuration is not supported by the NIC */
4319         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4320         if (ret != 0)
4321                 return;
4322
4323         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4324                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4325                 printf("Warning: hardware IP checksum enabled but not "
4326                         "supported by port %d\n", port_id);
4327         }
4328         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4329                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4330                 printf("Warning: hardware UDP checksum enabled but not "
4331                         "supported by port %d\n", port_id);
4332         }
4333         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4334                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4335                 printf("Warning: hardware TCP checksum enabled but not "
4336                         "supported by port %d\n", port_id);
4337         }
4338         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4339                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4340                 printf("Warning: hardware SCTP checksum enabled but not "
4341                         "supported by port %d\n", port_id);
4342         }
4343         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4344                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4345                 printf("Warning: hardware outer IP checksum enabled but not "
4346                         "supported by port %d\n", port_id);
4347         }
4348         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4349                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4350                         == 0) {
4351                 printf("Warning: hardware outer UDP checksum enabled but not "
4352                         "supported by port %d\n", port_id);
4353         }
4354 }
4355
4356 static void
4357 cmd_config_queue_tx_offloads(struct rte_port *port)
4358 {
4359         int k;
4360
4361         /* Apply queue tx offloads configuration */
4362         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4363                 port->tx_conf[k].offloads =
4364                         port->dev_conf.txmode.offloads;
4365 }
4366
4367 static void
4368 cmd_csum_parsed(void *parsed_result,
4369                        __attribute__((unused)) struct cmdline *cl,
4370                        __attribute__((unused)) void *data)
4371 {
4372         struct cmd_csum_result *res = parsed_result;
4373         int hw = 0;
4374         uint64_t csum_offloads = 0;
4375         struct rte_eth_dev_info dev_info;
4376         int ret;
4377
4378         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4379                 printf("invalid port %d\n", res->port_id);
4380                 return;
4381         }
4382         if (!port_is_stopped(res->port_id)) {
4383                 printf("Please stop port %d first\n", res->port_id);
4384                 return;
4385         }
4386
4387         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4388         if (ret != 0)
4389                 return;
4390
4391         if (!strcmp(res->mode, "set")) {
4392
4393                 if (!strcmp(res->hwsw, "hw"))
4394                         hw = 1;
4395
4396                 if (!strcmp(res->proto, "ip")) {
4397                         if (hw == 0 || (dev_info.tx_offload_capa &
4398                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4399                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4400                         } else {
4401                                 printf("IP checksum offload is not supported "
4402                                        "by port %u\n", res->port_id);
4403                         }
4404                 } else if (!strcmp(res->proto, "udp")) {
4405                         if (hw == 0 || (dev_info.tx_offload_capa &
4406                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4407                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4408                         } else {
4409                                 printf("UDP checksum offload is not supported "
4410                                        "by port %u\n", res->port_id);
4411                         }
4412                 } else if (!strcmp(res->proto, "tcp")) {
4413                         if (hw == 0 || (dev_info.tx_offload_capa &
4414                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4415                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4416                         } else {
4417                                 printf("TCP checksum offload is not supported "
4418                                        "by port %u\n", res->port_id);
4419                         }
4420                 } else if (!strcmp(res->proto, "sctp")) {
4421                         if (hw == 0 || (dev_info.tx_offload_capa &
4422                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4423                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4424                         } else {
4425                                 printf("SCTP checksum offload is not supported "
4426                                        "by port %u\n", res->port_id);
4427                         }
4428                 } else if (!strcmp(res->proto, "outer-ip")) {
4429                         if (hw == 0 || (dev_info.tx_offload_capa &
4430                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4431                                 csum_offloads |=
4432                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4433                         } else {
4434                                 printf("Outer IP checksum offload is not "
4435                                        "supported by port %u\n", res->port_id);
4436                         }
4437                 } else if (!strcmp(res->proto, "outer-udp")) {
4438                         if (hw == 0 || (dev_info.tx_offload_capa &
4439                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4440                                 csum_offloads |=
4441                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4442                         } else {
4443                                 printf("Outer UDP checksum offload is not "
4444                                        "supported by port %u\n", res->port_id);
4445                         }
4446                 }
4447
4448                 if (hw) {
4449                         ports[res->port_id].dev_conf.txmode.offloads |=
4450                                                         csum_offloads;
4451                 } else {
4452                         ports[res->port_id].dev_conf.txmode.offloads &=
4453                                                         (~csum_offloads);
4454                 }
4455                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4456         }
4457         csum_show(res->port_id);
4458
4459         cmd_reconfig_device_queue(res->port_id, 1, 1);
4460 }
4461
4462 cmdline_parse_token_string_t cmd_csum_csum =
4463         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4464                                 csum, "csum");
4465 cmdline_parse_token_string_t cmd_csum_mode =
4466         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4467                                 mode, "set");
4468 cmdline_parse_token_string_t cmd_csum_proto =
4469         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4470                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4471 cmdline_parse_token_string_t cmd_csum_hwsw =
4472         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4473                                 hwsw, "hw#sw");
4474 cmdline_parse_token_num_t cmd_csum_portid =
4475         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4476                                 port_id, UINT16);
4477
4478 cmdline_parse_inst_t cmd_csum_set = {
4479         .f = cmd_csum_parsed,
4480         .data = NULL,
4481         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4482                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4483                 "using csum forward engine",
4484         .tokens = {
4485                 (void *)&cmd_csum_csum,
4486                 (void *)&cmd_csum_mode,
4487                 (void *)&cmd_csum_proto,
4488                 (void *)&cmd_csum_hwsw,
4489                 (void *)&cmd_csum_portid,
4490                 NULL,
4491         },
4492 };
4493
4494 cmdline_parse_token_string_t cmd_csum_mode_show =
4495         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4496                                 mode, "show");
4497
4498 cmdline_parse_inst_t cmd_csum_show = {
4499         .f = cmd_csum_parsed,
4500         .data = NULL,
4501         .help_str = "csum show <port_id>: Show checksum offload configuration",
4502         .tokens = {
4503                 (void *)&cmd_csum_csum,
4504                 (void *)&cmd_csum_mode_show,
4505                 (void *)&cmd_csum_portid,
4506                 NULL,
4507         },
4508 };
4509
4510 /* Enable/disable tunnel parsing */
4511 struct cmd_csum_tunnel_result {
4512         cmdline_fixed_string_t csum;
4513         cmdline_fixed_string_t parse;
4514         cmdline_fixed_string_t onoff;
4515         portid_t port_id;
4516 };
4517
4518 static void
4519 cmd_csum_tunnel_parsed(void *parsed_result,
4520                        __attribute__((unused)) struct cmdline *cl,
4521                        __attribute__((unused)) void *data)
4522 {
4523         struct cmd_csum_tunnel_result *res = parsed_result;
4524
4525         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4526                 return;
4527
4528         if (!strcmp(res->onoff, "on"))
4529                 ports[res->port_id].parse_tunnel = 1;
4530         else
4531                 ports[res->port_id].parse_tunnel = 0;
4532
4533         csum_show(res->port_id);
4534 }
4535
4536 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4537         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4538                                 csum, "csum");
4539 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4540         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4541                                 parse, "parse-tunnel");
4542 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4543         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4544                                 onoff, "on#off");
4545 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4546         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4547                                 port_id, UINT16);
4548
4549 cmdline_parse_inst_t cmd_csum_tunnel = {
4550         .f = cmd_csum_tunnel_parsed,
4551         .data = NULL,
4552         .help_str = "csum parse-tunnel on|off <port_id>: "
4553                 "Enable/Disable parsing of tunnels for csum engine",
4554         .tokens = {
4555                 (void *)&cmd_csum_tunnel_csum,
4556                 (void *)&cmd_csum_tunnel_parse,
4557                 (void *)&cmd_csum_tunnel_onoff,
4558                 (void *)&cmd_csum_tunnel_portid,
4559                 NULL,
4560         },
4561 };
4562
4563 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4564 struct cmd_tso_set_result {
4565         cmdline_fixed_string_t tso;
4566         cmdline_fixed_string_t mode;
4567         uint16_t tso_segsz;
4568         portid_t port_id;
4569 };
4570
4571 static void
4572 cmd_tso_set_parsed(void *parsed_result,
4573                        __attribute__((unused)) struct cmdline *cl,
4574                        __attribute__((unused)) void *data)
4575 {
4576         struct cmd_tso_set_result *res = parsed_result;
4577         struct rte_eth_dev_info dev_info;
4578         int ret;
4579
4580         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4581                 return;
4582         if (!port_is_stopped(res->port_id)) {
4583                 printf("Please stop port %d first\n", res->port_id);
4584                 return;
4585         }
4586
4587         if (!strcmp(res->mode, "set"))
4588                 ports[res->port_id].tso_segsz = res->tso_segsz;
4589
4590         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4591         if (ret != 0)
4592                 return;
4593
4594         if ((ports[res->port_id].tso_segsz != 0) &&
4595                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4596                 printf("Error: TSO is not supported by port %d\n",
4597                        res->port_id);
4598                 return;
4599         }
4600
4601         if (ports[res->port_id].tso_segsz == 0) {
4602                 ports[res->port_id].dev_conf.txmode.offloads &=
4603                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4604                 printf("TSO for non-tunneled packets is disabled\n");
4605         } else {
4606                 ports[res->port_id].dev_conf.txmode.offloads |=
4607                                                 DEV_TX_OFFLOAD_TCP_TSO;
4608                 printf("TSO segment size for non-tunneled packets is %d\n",
4609                         ports[res->port_id].tso_segsz);
4610         }
4611         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4612
4613         /* display warnings if configuration is not supported by the NIC */
4614         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4615         if (ret != 0)
4616                 return;
4617
4618         if ((ports[res->port_id].tso_segsz != 0) &&
4619                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4620                 printf("Warning: TSO enabled but not "
4621                         "supported by port %d\n", res->port_id);
4622         }
4623
4624         cmd_reconfig_device_queue(res->port_id, 1, 1);
4625 }
4626
4627 cmdline_parse_token_string_t cmd_tso_set_tso =
4628         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4629                                 tso, "tso");
4630 cmdline_parse_token_string_t cmd_tso_set_mode =
4631         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4632                                 mode, "set");
4633 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4634         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4635                                 tso_segsz, UINT16);
4636 cmdline_parse_token_num_t cmd_tso_set_portid =
4637         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4638                                 port_id, UINT16);
4639
4640 cmdline_parse_inst_t cmd_tso_set = {
4641         .f = cmd_tso_set_parsed,
4642         .data = NULL,
4643         .help_str = "tso set <tso_segsz> <port_id>: "
4644                 "Set TSO segment size of non-tunneled packets for csum engine "
4645                 "(0 to disable)",
4646         .tokens = {
4647                 (void *)&cmd_tso_set_tso,
4648                 (void *)&cmd_tso_set_mode,
4649                 (void *)&cmd_tso_set_tso_segsz,
4650                 (void *)&cmd_tso_set_portid,
4651                 NULL,
4652         },
4653 };
4654
4655 cmdline_parse_token_string_t cmd_tso_show_mode =
4656         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4657                                 mode, "show");
4658
4659
4660 cmdline_parse_inst_t cmd_tso_show = {
4661         .f = cmd_tso_set_parsed,
4662         .data = NULL,
4663         .help_str = "tso show <port_id>: "
4664                 "Show TSO segment size of non-tunneled packets for csum engine",
4665         .tokens = {
4666                 (void *)&cmd_tso_set_tso,
4667                 (void *)&cmd_tso_show_mode,
4668                 (void *)&cmd_tso_set_portid,
4669                 NULL,
4670         },
4671 };
4672
4673 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4674 struct cmd_tunnel_tso_set_result {
4675         cmdline_fixed_string_t tso;
4676         cmdline_fixed_string_t mode;
4677         uint16_t tso_segsz;
4678         portid_t port_id;
4679 };
4680
4681 static struct rte_eth_dev_info
4682 check_tunnel_tso_nic_support(portid_t port_id)
4683 {
4684         struct rte_eth_dev_info dev_info;
4685
4686         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4687                 return dev_info;
4688
4689         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4690                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4691                        "not enabled for port %d\n", port_id);
4692         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4693                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4694                        "not enabled for port %d\n", port_id);
4695         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4696                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4697                        "not enabled for port %d\n", port_id);
4698         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4699                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4700                        "not enabled for port %d\n", port_id);
4701         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4702                 printf("Warning: IP TUNNEL TSO not supported therefore "
4703                        "not enabled for port %d\n", port_id);
4704         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4705                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4706                        "not enabled for port %d\n", port_id);
4707         return dev_info;
4708 }
4709
4710 static void
4711 cmd_tunnel_tso_set_parsed(void *parsed_result,
4712                           __attribute__((unused)) struct cmdline *cl,
4713                           __attribute__((unused)) void *data)
4714 {
4715         struct cmd_tunnel_tso_set_result *res = parsed_result;
4716         struct rte_eth_dev_info dev_info;
4717
4718         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4719                 return;
4720         if (!port_is_stopped(res->port_id)) {
4721                 printf("Please stop port %d first\n", res->port_id);
4722                 return;
4723         }
4724
4725         if (!strcmp(res->mode, "set"))
4726                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4727
4728         dev_info = check_tunnel_tso_nic_support(res->port_id);
4729         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4730                 ports[res->port_id].dev_conf.txmode.offloads &=
4731                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4732                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4733                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4734                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4735                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4736                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4737                 printf("TSO for tunneled packets is disabled\n");
4738         } else {
4739                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4740                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4741                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4742                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4743                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4744                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4745
4746                 ports[res->port_id].dev_conf.txmode.offloads |=
4747                         (tso_offloads & dev_info.tx_offload_capa);
4748                 printf("TSO segment size for tunneled packets is %d\n",
4749                         ports[res->port_id].tunnel_tso_segsz);
4750
4751                 /* Below conditions are needed to make it work:
4752                  * (1) tunnel TSO is supported by the NIC;
4753                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4754                  * are recognized;
4755                  * (3) for tunneled pkts with outer L3 of IPv4,
4756                  * "csum set outer-ip" must be set to hw, because after tso,
4757                  * total_len of outer IP header is changed, and the checksum
4758                  * of outer IP header calculated by sw should be wrong; that
4759                  * is not necessary for IPv6 tunneled pkts because there's no
4760                  * checksum in IP header anymore.
4761                  */
4762
4763                 if (!ports[res->port_id].parse_tunnel)
4764                         printf("Warning: csum parse_tunnel must be set "
4765                                 "so that tunneled packets are recognized\n");
4766                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4767                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4768                         printf("Warning: csum set outer-ip must be set to hw "
4769                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4770         }
4771
4772         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4773         cmd_reconfig_device_queue(res->port_id, 1, 1);
4774 }
4775
4776 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4777         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4778                                 tso, "tunnel_tso");
4779 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4780         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4781                                 mode, "set");
4782 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4783         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4784                                 tso_segsz, UINT16);
4785 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4786         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4787                                 port_id, UINT16);
4788
4789 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4790         .f = cmd_tunnel_tso_set_parsed,
4791         .data = NULL,
4792         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4793                 "Set TSO segment size of tunneled packets for csum engine "
4794                 "(0 to disable)",
4795         .tokens = {
4796                 (void *)&cmd_tunnel_tso_set_tso,
4797                 (void *)&cmd_tunnel_tso_set_mode,
4798                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4799                 (void *)&cmd_tunnel_tso_set_portid,
4800                 NULL,
4801         },
4802 };
4803
4804 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4805         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4806                                 mode, "show");
4807
4808
4809 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4810         .f = cmd_tunnel_tso_set_parsed,
4811         .data = NULL,
4812         .help_str = "tunnel_tso show <port_id> "
4813                 "Show TSO segment size of tunneled packets for csum engine",
4814         .tokens = {
4815                 (void *)&cmd_tunnel_tso_set_tso,
4816                 (void *)&cmd_tunnel_tso_show_mode,
4817                 (void *)&cmd_tunnel_tso_set_portid,
4818                 NULL,
4819         },
4820 };
4821
4822 /* *** SET GRO FOR A PORT *** */
4823 struct cmd_gro_enable_result {
4824         cmdline_fixed_string_t cmd_set;
4825         cmdline_fixed_string_t cmd_port;
4826         cmdline_fixed_string_t cmd_keyword;
4827         cmdline_fixed_string_t cmd_onoff;
4828         portid_t cmd_pid;
4829 };
4830
4831 static void
4832 cmd_gro_enable_parsed(void *parsed_result,
4833                 __attribute__((unused)) struct cmdline *cl,
4834                 __attribute__((unused)) void *data)
4835 {
4836         struct cmd_gro_enable_result *res;
4837
4838         res = parsed_result;
4839         if (!strcmp(res->cmd_keyword, "gro"))
4840                 setup_gro(res->cmd_onoff, res->cmd_pid);
4841 }
4842
4843 cmdline_parse_token_string_t cmd_gro_enable_set =
4844         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4845                         cmd_set, "set");
4846 cmdline_parse_token_string_t cmd_gro_enable_port =
4847         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4848                         cmd_keyword, "port");
4849 cmdline_parse_token_num_t cmd_gro_enable_pid =
4850         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4851                         cmd_pid, UINT16);
4852 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4853         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4854                         cmd_keyword, "gro");
4855 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4856         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4857                         cmd_onoff, "on#off");
4858
4859 cmdline_parse_inst_t cmd_gro_enable = {
4860         .f = cmd_gro_enable_parsed,
4861         .data = NULL,
4862         .help_str = "set port <port_id> gro on|off",
4863         .tokens = {
4864                 (void *)&cmd_gro_enable_set,
4865                 (void *)&cmd_gro_enable_port,
4866                 (void *)&cmd_gro_enable_pid,
4867                 (void *)&cmd_gro_enable_keyword,
4868                 (void *)&cmd_gro_enable_onoff,
4869                 NULL,
4870         },
4871 };
4872
4873 /* *** DISPLAY GRO CONFIGURATION *** */
4874 struct cmd_gro_show_result {
4875         cmdline_fixed_string_t cmd_show;
4876         cmdline_fixed_string_t cmd_port;
4877         cmdline_fixed_string_t cmd_keyword;
4878         portid_t cmd_pid;
4879 };
4880
4881 static void
4882 cmd_gro_show_parsed(void *parsed_result,
4883                 __attribute__((unused)) struct cmdline *cl,
4884                 __attribute__((unused)) void *data)
4885 {
4886         struct cmd_gro_show_result *res;
4887
4888         res = parsed_result;
4889         if (!strcmp(res->cmd_keyword, "gro"))
4890                 show_gro(res->cmd_pid);
4891 }
4892
4893 cmdline_parse_token_string_t cmd_gro_show_show =
4894         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4895                         cmd_show, "show");
4896 cmdline_parse_token_string_t cmd_gro_show_port =
4897         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4898                         cmd_port, "port");
4899 cmdline_parse_token_num_t cmd_gro_show_pid =
4900         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4901                         cmd_pid, UINT16);
4902 cmdline_parse_token_string_t cmd_gro_show_keyword =
4903         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4904                         cmd_keyword, "gro");
4905
4906 cmdline_parse_inst_t cmd_gro_show = {
4907         .f = cmd_gro_show_parsed,
4908         .data = NULL,
4909         .help_str = "show port <port_id> gro",
4910         .tokens = {
4911                 (void *)&cmd_gro_show_show,
4912                 (void *)&cmd_gro_show_port,
4913                 (void *)&cmd_gro_show_pid,
4914                 (void *)&cmd_gro_show_keyword,
4915                 NULL,
4916         },
4917 };
4918
4919 /* *** SET FLUSH CYCLES FOR GRO *** */
4920 struct cmd_gro_flush_result {
4921         cmdline_fixed_string_t cmd_set;
4922         cmdline_fixed_string_t cmd_keyword;
4923         cmdline_fixed_string_t cmd_flush;
4924         uint8_t cmd_cycles;
4925 };
4926
4927 static void
4928 cmd_gro_flush_parsed(void *parsed_result,
4929                 __attribute__((unused)) struct cmdline *cl,
4930                 __attribute__((unused)) void *data)
4931 {
4932         struct cmd_gro_flush_result *res;
4933
4934         res = parsed_result;
4935         if ((!strcmp(res->cmd_keyword, "gro")) &&
4936                         (!strcmp(res->cmd_flush, "flush")))
4937                 setup_gro_flush_cycles(res->cmd_cycles);
4938 }
4939
4940 cmdline_parse_token_string_t cmd_gro_flush_set =
4941         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4942                         cmd_set, "set");
4943 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4944         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4945                         cmd_keyword, "gro");
4946 cmdline_parse_token_string_t cmd_gro_flush_flush =
4947         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4948                         cmd_flush, "flush");
4949 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4950         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4951                         cmd_cycles, UINT8);
4952
4953 cmdline_parse_inst_t cmd_gro_flush = {
4954         .f = cmd_gro_flush_parsed,
4955         .data = NULL,
4956         .help_str = "set gro flush <cycles>",
4957         .tokens = {
4958                 (void *)&cmd_gro_flush_set,
4959                 (void *)&cmd_gro_flush_keyword,
4960                 (void *)&cmd_gro_flush_flush,
4961                 (void *)&cmd_gro_flush_cycles,
4962                 NULL,
4963         },
4964 };
4965
4966 /* *** ENABLE/DISABLE GSO *** */
4967 struct cmd_gso_enable_result {
4968         cmdline_fixed_string_t cmd_set;
4969         cmdline_fixed_string_t cmd_port;
4970         cmdline_fixed_string_t cmd_keyword;
4971         cmdline_fixed_string_t cmd_mode;
4972         portid_t cmd_pid;
4973 };
4974
4975 static void
4976 cmd_gso_enable_parsed(void *parsed_result,
4977                 __attribute__((unused)) struct cmdline *cl,
4978                 __attribute__((unused)) void *data)
4979 {
4980         struct cmd_gso_enable_result *res;
4981
4982         res = parsed_result;
4983         if (!strcmp(res->cmd_keyword, "gso"))
4984                 setup_gso(res->cmd_mode, res->cmd_pid);
4985 }
4986
4987 cmdline_parse_token_string_t cmd_gso_enable_set =
4988         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4989                         cmd_set, "set");
4990 cmdline_parse_token_string_t cmd_gso_enable_port =
4991         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4992                         cmd_port, "port");
4993 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4994         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4995                         cmd_keyword, "gso");
4996 cmdline_parse_token_string_t cmd_gso_enable_mode =
4997         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4998                         cmd_mode, "on#off");
4999 cmdline_parse_token_num_t cmd_gso_enable_pid =
5000         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5001                         cmd_pid, UINT16);
5002
5003 cmdline_parse_inst_t cmd_gso_enable = {
5004         .f = cmd_gso_enable_parsed,
5005         .data = NULL,
5006         .help_str = "set port <port_id> gso on|off",
5007         .tokens = {
5008                 (void *)&cmd_gso_enable_set,
5009                 (void *)&cmd_gso_enable_port,
5010                 (void *)&cmd_gso_enable_pid,
5011                 (void *)&cmd_gso_enable_keyword,
5012                 (void *)&cmd_gso_enable_mode,
5013                 NULL,
5014         },
5015 };
5016
5017 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5018 struct cmd_gso_size_result {
5019         cmdline_fixed_string_t cmd_set;
5020         cmdline_fixed_string_t cmd_keyword;
5021         cmdline_fixed_string_t cmd_segsz;
5022         uint16_t cmd_size;
5023 };
5024
5025 static void
5026 cmd_gso_size_parsed(void *parsed_result,
5027                        __attribute__((unused)) struct cmdline *cl,
5028                        __attribute__((unused)) void *data)
5029 {
5030         struct cmd_gso_size_result *res = parsed_result;
5031
5032         if (test_done == 0) {
5033                 printf("Before setting GSO segsz, please first"
5034                                 " stop fowarding\n");
5035                 return;
5036         }
5037
5038         if (!strcmp(res->cmd_keyword, "gso") &&
5039                         !strcmp(res->cmd_segsz, "segsz")) {
5040                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5041                         printf("gso_size should be larger than %zu."
5042                                         " Please input a legal value\n",
5043                                         RTE_GSO_SEG_SIZE_MIN);
5044                 else
5045                         gso_max_segment_size = res->cmd_size;
5046         }
5047 }
5048
5049 cmdline_parse_token_string_t cmd_gso_size_set =
5050         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5051                                 cmd_set, "set");
5052 cmdline_parse_token_string_t cmd_gso_size_keyword =
5053         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5054                                 cmd_keyword, "gso");
5055 cmdline_parse_token_string_t cmd_gso_size_segsz =
5056         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5057                                 cmd_segsz, "segsz");
5058 cmdline_parse_token_num_t cmd_gso_size_size =
5059         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5060                                 cmd_size, UINT16);
5061
5062 cmdline_parse_inst_t cmd_gso_size = {
5063         .f = cmd_gso_size_parsed,
5064         .data = NULL,
5065         .help_str = "set gso segsz <length>",
5066         .tokens = {
5067                 (void *)&cmd_gso_size_set,
5068                 (void *)&cmd_gso_size_keyword,
5069                 (void *)&cmd_gso_size_segsz,
5070                 (void *)&cmd_gso_size_size,
5071                 NULL,
5072         },
5073 };
5074
5075 /* *** SHOW GSO CONFIGURATION *** */
5076 struct cmd_gso_show_result {
5077         cmdline_fixed_string_t cmd_show;
5078         cmdline_fixed_string_t cmd_port;
5079         cmdline_fixed_string_t cmd_keyword;
5080         portid_t cmd_pid;
5081 };
5082
5083 static void
5084 cmd_gso_show_parsed(void *parsed_result,
5085                        __attribute__((unused)) struct cmdline *cl,
5086                        __attribute__((unused)) void *data)
5087 {
5088         struct cmd_gso_show_result *res = parsed_result;
5089
5090         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5091                 printf("invalid port id %u\n", res->cmd_pid);
5092                 return;
5093         }
5094         if (!strcmp(res->cmd_keyword, "gso")) {
5095                 if (gso_ports[res->cmd_pid].enable) {
5096                         printf("Max GSO'd packet size: %uB\n"
5097                                         "Supported GSO types: TCP/IPv4, "
5098                                         "UDP/IPv4, VxLAN with inner "
5099                                         "TCP/IPv4 packet, GRE with inner "
5100                                         "TCP/IPv4 packet\n",
5101                                         gso_max_segment_size);
5102                 } else
5103                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5104         }
5105 }
5106
5107 cmdline_parse_token_string_t cmd_gso_show_show =
5108 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5109                 cmd_show, "show");
5110 cmdline_parse_token_string_t cmd_gso_show_port =
5111 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5112                 cmd_port, "port");
5113 cmdline_parse_token_string_t cmd_gso_show_keyword =
5114         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5115                                 cmd_keyword, "gso");
5116 cmdline_parse_token_num_t cmd_gso_show_pid =
5117         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5118                                 cmd_pid, UINT16);
5119
5120 cmdline_parse_inst_t cmd_gso_show = {
5121         .f = cmd_gso_show_parsed,
5122         .data = NULL,
5123         .help_str = "show port <port_id> gso",
5124         .tokens = {
5125                 (void *)&cmd_gso_show_show,
5126                 (void *)&cmd_gso_show_port,
5127                 (void *)&cmd_gso_show_pid,
5128                 (void *)&cmd_gso_show_keyword,
5129                 NULL,
5130         },
5131 };
5132
5133 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5134 struct cmd_set_flush_rx {
5135         cmdline_fixed_string_t set;
5136         cmdline_fixed_string_t flush_rx;
5137         cmdline_fixed_string_t mode;
5138 };
5139
5140 static void
5141 cmd_set_flush_rx_parsed(void *parsed_result,
5142                 __attribute__((unused)) struct cmdline *cl,
5143                 __attribute__((unused)) void *data)
5144 {
5145         struct cmd_set_flush_rx *res = parsed_result;
5146         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5147 }
5148
5149 cmdline_parse_token_string_t cmd_setflushrx_set =
5150         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5151                         set, "set");
5152 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5153         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5154                         flush_rx, "flush_rx");
5155 cmdline_parse_token_string_t cmd_setflushrx_mode =
5156         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5157                         mode, "on#off");
5158
5159
5160 cmdline_parse_inst_t cmd_set_flush_rx = {
5161         .f = cmd_set_flush_rx_parsed,
5162         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5163         .data = NULL,
5164         .tokens = {
5165                 (void *)&cmd_setflushrx_set,
5166                 (void *)&cmd_setflushrx_flush_rx,
5167                 (void *)&cmd_setflushrx_mode,
5168                 NULL,
5169         },
5170 };
5171
5172 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5173 struct cmd_set_link_check {
5174         cmdline_fixed_string_t set;
5175         cmdline_fixed_string_t link_check;
5176         cmdline_fixed_string_t mode;
5177 };
5178
5179 static void
5180 cmd_set_link_check_parsed(void *parsed_result,
5181                 __attribute__((unused)) struct cmdline *cl,
5182                 __attribute__((unused)) void *data)
5183 {
5184         struct cmd_set_link_check *res = parsed_result;
5185         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5186 }
5187
5188 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5189         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5190                         set, "set");
5191 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5192         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5193                         link_check, "link_check");
5194 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5195         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5196                         mode, "on#off");
5197
5198
5199 cmdline_parse_inst_t cmd_set_link_check = {
5200         .f = cmd_set_link_check_parsed,
5201         .help_str = "set link_check on|off: Enable/Disable link status check "
5202                     "when starting/stopping a port",
5203         .data = NULL,
5204         .tokens = {
5205                 (void *)&cmd_setlinkcheck_set,
5206                 (void *)&cmd_setlinkcheck_link_check,
5207                 (void *)&cmd_setlinkcheck_mode,
5208                 NULL,
5209         },
5210 };
5211
5212 /* *** SET NIC BYPASS MODE *** */
5213 struct cmd_set_bypass_mode_result {
5214         cmdline_fixed_string_t set;
5215         cmdline_fixed_string_t bypass;
5216         cmdline_fixed_string_t mode;
5217         cmdline_fixed_string_t value;
5218         portid_t port_id;
5219 };
5220
5221 static void
5222 cmd_set_bypass_mode_parsed(void *parsed_result,
5223                 __attribute__((unused)) struct cmdline *cl,
5224                 __attribute__((unused)) void *data)
5225 {
5226         struct cmd_set_bypass_mode_result *res = parsed_result;
5227         portid_t port_id = res->port_id;
5228         int32_t rc = -EINVAL;
5229
5230 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5231         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5232
5233         if (!strcmp(res->value, "bypass"))
5234                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5235         else if (!strcmp(res->value, "isolate"))
5236                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5237         else
5238                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5239
5240         /* Set the bypass mode for the relevant port. */
5241         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5242 #endif
5243         if (rc != 0)
5244                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5245 }
5246
5247 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5248         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5249                         set, "set");
5250 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5251         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5252                         bypass, "bypass");
5253 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5254         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5255                         mode, "mode");
5256 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5257         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5258                         value, "normal#bypass#isolate");
5259 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5260         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5261                                 port_id, UINT16);
5262
5263 cmdline_parse_inst_t cmd_set_bypass_mode = {
5264         .f = cmd_set_bypass_mode_parsed,
5265         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5266                     "Set the NIC bypass mode for port_id",
5267         .data = NULL,
5268         .tokens = {
5269                 (void *)&cmd_setbypass_mode_set,
5270                 (void *)&cmd_setbypass_mode_bypass,
5271                 (void *)&cmd_setbypass_mode_mode,
5272                 (void *)&cmd_setbypass_mode_value,
5273                 (void *)&cmd_setbypass_mode_port,
5274                 NULL,
5275         },
5276 };
5277
5278 /* *** SET NIC BYPASS EVENT *** */
5279 struct cmd_set_bypass_event_result {
5280         cmdline_fixed_string_t set;
5281         cmdline_fixed_string_t bypass;
5282         cmdline_fixed_string_t event;
5283         cmdline_fixed_string_t event_value;
5284         cmdline_fixed_string_t mode;
5285         cmdline_fixed_string_t mode_value;
5286         portid_t port_id;
5287 };
5288
5289 static void
5290 cmd_set_bypass_event_parsed(void *parsed_result,
5291                 __attribute__((unused)) struct cmdline *cl,
5292                 __attribute__((unused)) void *data)
5293 {
5294         int32_t rc = -EINVAL;
5295         struct cmd_set_bypass_event_result *res = parsed_result;
5296         portid_t port_id = res->port_id;
5297
5298 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5299         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5300         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5301
5302         if (!strcmp(res->event_value, "timeout"))
5303                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5304         else if (!strcmp(res->event_value, "os_on"))
5305                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5306         else if (!strcmp(res->event_value, "os_off"))
5307                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5308         else if (!strcmp(res->event_value, "power_on"))
5309                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5310         else if (!strcmp(res->event_value, "power_off"))
5311                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5312         else
5313                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5314
5315         if (!strcmp(res->mode_value, "bypass"))
5316                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5317         else if (!strcmp(res->mode_value, "isolate"))
5318                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5319         else
5320                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5321
5322         /* Set the watchdog timeout. */
5323         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5324
5325                 rc = -EINVAL;
5326                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5327                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5328                                                            bypass_timeout);
5329                 }
5330                 if (rc != 0) {
5331                         printf("Failed to set timeout value %u "
5332                         "for port %d, errto code: %d.\n",
5333                         bypass_timeout, port_id, rc);
5334                 }
5335         }
5336
5337         /* Set the bypass event to transition to bypass mode. */
5338         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5339                                               bypass_mode);
5340 #endif
5341
5342         if (rc != 0)
5343                 printf("\t Failed to set bypass event for port = %d.\n",
5344                        port_id);
5345 }
5346
5347 cmdline_parse_token_string_t cmd_setbypass_event_set =
5348         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5349                         set, "set");
5350 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5351         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5352                         bypass, "bypass");
5353 cmdline_parse_token_string_t cmd_setbypass_event_event =
5354         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5355                         event, "event");
5356 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5357         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5358                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5359 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5360         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5361                         mode, "mode");
5362 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5363         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5364                         mode_value, "normal#bypass#isolate");
5365 cmdline_parse_token_num_t cmd_setbypass_event_port =
5366         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5367                                 port_id, UINT16);
5368
5369 cmdline_parse_inst_t cmd_set_bypass_event = {
5370         .f = cmd_set_bypass_event_parsed,
5371         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5372                 "power_off mode normal|bypass|isolate <port_id>: "
5373                 "Set the NIC bypass event mode for port_id",
5374         .data = NULL,
5375         .tokens = {
5376                 (void *)&cmd_setbypass_event_set,
5377                 (void *)&cmd_setbypass_event_bypass,
5378                 (void *)&cmd_setbypass_event_event,
5379                 (void *)&cmd_setbypass_event_event_value,
5380                 (void *)&cmd_setbypass_event_mode,
5381                 (void *)&cmd_setbypass_event_mode_value,
5382                 (void *)&cmd_setbypass_event_port,
5383                 NULL,
5384         },
5385 };
5386
5387
5388 /* *** SET NIC BYPASS TIMEOUT *** */
5389 struct cmd_set_bypass_timeout_result {
5390         cmdline_fixed_string_t set;
5391         cmdline_fixed_string_t bypass;
5392         cmdline_fixed_string_t timeout;
5393         cmdline_fixed_string_t value;
5394 };
5395
5396 static void
5397 cmd_set_bypass_timeout_parsed(void *parsed_result,
5398                 __attribute__((unused)) struct cmdline *cl,
5399                 __attribute__((unused)) void *data)
5400 {
5401         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5402
5403 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5404         if (!strcmp(res->value, "1.5"))
5405                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5406         else if (!strcmp(res->value, "2"))
5407                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5408         else if (!strcmp(res->value, "3"))
5409                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5410         else if (!strcmp(res->value, "4"))
5411                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5412         else if (!strcmp(res->value, "8"))
5413                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5414         else if (!strcmp(res->value, "16"))
5415                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5416         else if (!strcmp(res->value, "32"))
5417                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5418         else
5419                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5420 #endif
5421 }
5422
5423 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5424         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5425                         set, "set");
5426 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5427         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5428                         bypass, "bypass");
5429 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5430         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5431                         timeout, "timeout");
5432 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5433         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5434                         value, "0#1.5#2#3#4#8#16#32");
5435
5436 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5437         .f = cmd_set_bypass_timeout_parsed,
5438         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5439                 "Set the NIC bypass watchdog timeout in seconds",
5440         .data = NULL,
5441         .tokens = {
5442                 (void *)&cmd_setbypass_timeout_set,
5443                 (void *)&cmd_setbypass_timeout_bypass,
5444                 (void *)&cmd_setbypass_timeout_timeout,
5445                 (void *)&cmd_setbypass_timeout_value,
5446                 NULL,
5447         },
5448 };
5449
5450 /* *** SHOW NIC BYPASS MODE *** */
5451 struct cmd_show_bypass_config_result {
5452         cmdline_fixed_string_t show;
5453         cmdline_fixed_string_t bypass;
5454         cmdline_fixed_string_t config;
5455         portid_t port_id;
5456 };
5457
5458 static void
5459 cmd_show_bypass_config_parsed(void *parsed_result,
5460                 __attribute__((unused)) struct cmdline *cl,
5461                 __attribute__((unused)) void *data)
5462 {
5463         struct cmd_show_bypass_config_result *res = parsed_result;
5464         portid_t port_id = res->port_id;
5465         int rc = -EINVAL;
5466 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5467         uint32_t event_mode;
5468         uint32_t bypass_mode;
5469         uint32_t timeout = bypass_timeout;
5470         int i;
5471
5472         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5473                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5474         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5475                 {"UNKNOWN", "normal", "bypass", "isolate"};
5476         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5477                 "NONE",
5478                 "OS/board on",
5479                 "power supply on",
5480                 "OS/board off",
5481                 "power supply off",
5482                 "timeout"};
5483         int num_events = (sizeof events) / (sizeof events[0]);
5484
5485         /* Display the bypass mode.*/
5486         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5487                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5488                 return;
5489         }
5490         else {
5491                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5492                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5493
5494                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5495         }
5496
5497         /* Display the bypass timeout.*/
5498         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5499                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5500
5501         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5502
5503         /* Display the bypass events and associated modes. */
5504         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5505
5506                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5507                         printf("\tFailed to get bypass mode for event = %s\n",
5508                                 events[i]);
5509                 } else {
5510                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5511                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5512
5513                         printf("\tbypass event: %-16s = %s\n", events[i],
5514                                 modes[event_mode]);
5515                 }
5516         }
5517 #endif
5518         if (rc != 0)
5519                 printf("\tFailed to get bypass configuration for port = %d\n",
5520                        port_id);
5521 }
5522
5523 cmdline_parse_token_string_t cmd_showbypass_config_show =
5524         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5525                         show, "show");
5526 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5527         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5528                         bypass, "bypass");
5529 cmdline_parse_token_string_t cmd_showbypass_config_config =
5530         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5531                         config, "config");
5532 cmdline_parse_token_num_t cmd_showbypass_config_port =
5533         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5534                                 port_id, UINT16);
5535
5536 cmdline_parse_inst_t cmd_show_bypass_config = {
5537         .f = cmd_show_bypass_config_parsed,
5538         .help_str = "show bypass config <port_id>: "
5539                     "Show the NIC bypass config for port_id",
5540         .data = NULL,
5541         .tokens = {
5542                 (void *)&cmd_showbypass_config_show,
5543                 (void *)&cmd_showbypass_config_bypass,
5544                 (void *)&cmd_showbypass_config_config,
5545                 (void *)&cmd_showbypass_config_port,
5546                 NULL,
5547         },
5548 };
5549
5550 #ifdef RTE_LIBRTE_PMD_BOND
5551 /* *** SET BONDING MODE *** */
5552 struct cmd_set_bonding_mode_result {
5553         cmdline_fixed_string_t set;
5554         cmdline_fixed_string_t bonding;
5555         cmdline_fixed_string_t mode;
5556         uint8_t value;
5557         portid_t port_id;
5558 };
5559
5560 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5561                 __attribute__((unused))  struct cmdline *cl,
5562                 __attribute__((unused)) void *data)
5563 {
5564         struct cmd_set_bonding_mode_result *res = parsed_result;
5565         portid_t port_id = res->port_id;
5566
5567         /* Set the bonding mode for the relevant port. */
5568         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5569                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5570 }
5571
5572 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5573 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5574                 set, "set");
5575 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5576 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5577                 bonding, "bonding");
5578 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5579 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5580                 mode, "mode");
5581 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5582 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5583                 value, UINT8);
5584 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5585 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5586                 port_id, UINT16);
5587
5588 cmdline_parse_inst_t cmd_set_bonding_mode = {
5589                 .f = cmd_set_bonding_mode_parsed,
5590                 .help_str = "set bonding mode <mode_value> <port_id>: "
5591                         "Set the bonding mode for port_id",
5592                 .data = NULL,
5593                 .tokens = {
5594                                 (void *) &cmd_setbonding_mode_set,
5595                                 (void *) &cmd_setbonding_mode_bonding,
5596                                 (void *) &cmd_setbonding_mode_mode,
5597                                 (void *) &cmd_setbonding_mode_value,
5598                                 (void *) &cmd_setbonding_mode_port,
5599                                 NULL
5600                 }
5601 };
5602
5603 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5604 struct cmd_set_bonding_lacp_dedicated_queues_result {
5605         cmdline_fixed_string_t set;
5606         cmdline_fixed_string_t bonding;
5607         cmdline_fixed_string_t lacp;
5608         cmdline_fixed_string_t dedicated_queues;
5609         portid_t port_id;
5610         cmdline_fixed_string_t mode;
5611 };
5612
5613 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5614                 __attribute__((unused))  struct cmdline *cl,
5615                 __attribute__((unused)) void *data)
5616 {
5617         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5618         portid_t port_id = res->port_id;
5619         struct rte_port *port;
5620
5621         port = &ports[port_id];
5622
5623         /** Check if the port is not started **/
5624         if (port->port_status != RTE_PORT_STOPPED) {
5625                 printf("Please stop port %d first\n", port_id);
5626                 return;
5627         }
5628
5629         if (!strcmp(res->mode, "enable")) {
5630                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5631                         printf("Dedicate queues for LACP control packets"
5632                                         " enabled\n");
5633                 else
5634                         printf("Enabling dedicate queues for LACP control "
5635                                         "packets on port %d failed\n", port_id);
5636         } else if (!strcmp(res->mode, "disable")) {
5637                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5638                         printf("Dedicated queues for LACP control packets "
5639                                         "disabled\n");
5640                 else
5641                         printf("Disabling dedicated queues for LACP control "
5642                                         "traffic on port %d failed\n", port_id);
5643         }
5644 }
5645
5646 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5647 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5648                 set, "set");
5649 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5650 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5651                 bonding, "bonding");
5652 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5653 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5654                 lacp, "lacp");
5655 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5656 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5657                 dedicated_queues, "dedicated_queues");
5658 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5659 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5660                 port_id, UINT16);
5661 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5662 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5663                 mode, "enable#disable");
5664
5665 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5666                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5667                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5668                         "enable|disable: "
5669                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5670                 .data = NULL,
5671                 .tokens = {
5672                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5673                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5674                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5675                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5676                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5677                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5678                         NULL
5679                 }
5680 };
5681
5682 /* *** SET BALANCE XMIT POLICY *** */
5683 struct cmd_set_bonding_balance_xmit_policy_result {
5684         cmdline_fixed_string_t set;
5685         cmdline_fixed_string_t bonding;
5686         cmdline_fixed_string_t balance_xmit_policy;
5687         portid_t port_id;
5688         cmdline_fixed_string_t policy;
5689 };
5690
5691 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5692                 __attribute__((unused))  struct cmdline *cl,
5693                 __attribute__((unused)) void *data)
5694 {
5695         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5696         portid_t port_id = res->port_id;
5697         uint8_t policy;
5698
5699         if (!strcmp(res->policy, "l2")) {
5700                 policy = BALANCE_XMIT_POLICY_LAYER2;
5701         } else if (!strcmp(res->policy, "l23")) {
5702                 policy = BALANCE_XMIT_POLICY_LAYER23;
5703         } else if (!strcmp(res->policy, "l34")) {
5704                 policy = BALANCE_XMIT_POLICY_LAYER34;
5705         } else {
5706                 printf("\t Invalid xmit policy selection");
5707                 return;
5708         }
5709
5710         /* Set the bonding mode for the relevant port. */
5711         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5712                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5713                                 port_id);
5714         }
5715 }
5716
5717 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5718 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5719                 set, "set");
5720 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5721 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5722                 bonding, "bonding");
5723 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5724 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5725                 balance_xmit_policy, "balance_xmit_policy");
5726 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5727 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5728                 port_id, UINT16);
5729 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5730 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5731                 policy, "l2#l23#l34");
5732
5733 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5734                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5735                 .help_str = "set bonding balance_xmit_policy <port_id> "
5736                         "l2|l23|l34: "
5737                         "Set the bonding balance_xmit_policy for port_id",
5738                 .data = NULL,
5739                 .tokens = {
5740                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5741                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5742                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5743                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5744                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5745                                 NULL
5746                 }
5747 };
5748
5749 /* *** SHOW NIC BONDING CONFIGURATION *** */
5750 struct cmd_show_bonding_config_result {
5751         cmdline_fixed_string_t show;
5752         cmdline_fixed_string_t bonding;
5753         cmdline_fixed_string_t config;
5754         portid_t port_id;
5755 };
5756
5757 static void cmd_show_bonding_config_parsed(void *parsed_result,
5758                 __attribute__((unused))  struct cmdline *cl,
5759                 __attribute__((unused)) void *data)
5760 {
5761         struct cmd_show_bonding_config_result *res = parsed_result;
5762         int bonding_mode, agg_mode;
5763         portid_t slaves[RTE_MAX_ETHPORTS];
5764         int num_slaves, num_active_slaves;
5765         int primary_id;
5766         int i;
5767         portid_t port_id = res->port_id;
5768
5769         /* Display the bonding mode.*/
5770         bonding_mode = rte_eth_bond_mode_get(port_id);
5771         if (bonding_mode < 0) {
5772                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5773                 return;
5774         } else
5775                 printf("\tBonding mode: %d\n", bonding_mode);
5776
5777         if (bonding_mode == BONDING_MODE_BALANCE) {
5778                 int balance_xmit_policy;
5779
5780                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5781                 if (balance_xmit_policy < 0) {
5782                         printf("\tFailed to get balance xmit policy for port = %d\n",
5783                                         port_id);
5784                         return;
5785                 } else {
5786                         printf("\tBalance Xmit Policy: ");
5787
5788                         switch (balance_xmit_policy) {
5789                         case BALANCE_XMIT_POLICY_LAYER2:
5790                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5791                                 break;
5792                         case BALANCE_XMIT_POLICY_LAYER23:
5793                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5794                                 break;
5795                         case BALANCE_XMIT_POLICY_LAYER34:
5796                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5797                                 break;
5798                         }
5799                         printf("\n");
5800                 }
5801         }
5802
5803         if (bonding_mode == BONDING_MODE_8023AD) {
5804                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5805                 printf("\tIEEE802.3AD Aggregator Mode: ");
5806                 switch (agg_mode) {
5807                 case AGG_BANDWIDTH:
5808                         printf("bandwidth");
5809                         break;
5810                 case AGG_STABLE:
5811                         printf("stable");
5812                         break;
5813                 case AGG_COUNT:
5814                         printf("count");
5815                         break;
5816                 }
5817                 printf("\n");
5818         }
5819
5820         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5821
5822         if (num_slaves < 0) {
5823                 printf("\tFailed to get slave list for port = %d\n", port_id);
5824                 return;
5825         }
5826         if (num_slaves > 0) {
5827                 printf("\tSlaves (%d): [", num_slaves);
5828                 for (i = 0; i < num_slaves - 1; i++)
5829                         printf("%d ", slaves[i]);
5830
5831                 printf("%d]\n", slaves[num_slaves - 1]);
5832         } else {
5833                 printf("\tSlaves: []\n");
5834
5835         }
5836
5837         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5838                         RTE_MAX_ETHPORTS);
5839
5840         if (num_active_slaves < 0) {
5841                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5842                 return;
5843         }
5844         if (num_active_slaves > 0) {
5845                 printf("\tActive Slaves (%d): [", num_active_slaves);
5846                 for (i = 0; i < num_active_slaves - 1; i++)
5847                         printf("%d ", slaves[i]);
5848
5849                 printf("%d]\n", slaves[num_active_slaves - 1]);
5850
5851         } else {
5852                 printf("\tActive Slaves: []\n");
5853
5854         }
5855
5856         primary_id = rte_eth_bond_primary_get(port_id);
5857         if (primary_id < 0) {
5858                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5859                 return;
5860         } else
5861                 printf("\tPrimary: [%d]\n", primary_id);
5862
5863 }
5864
5865 cmdline_parse_token_string_t cmd_showbonding_config_show =
5866 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5867                 show, "show");
5868 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5869 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5870                 bonding, "bonding");
5871 cmdline_parse_token_string_t cmd_showbonding_config_config =
5872 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5873                 config, "config");
5874 cmdline_parse_token_num_t cmd_showbonding_config_port =
5875 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5876                 port_id, UINT16);
5877
5878 cmdline_parse_inst_t cmd_show_bonding_config = {
5879                 .f = cmd_show_bonding_config_parsed,
5880                 .help_str = "show bonding config <port_id>: "
5881                         "Show the bonding config for port_id",
5882                 .data = NULL,
5883                 .tokens = {
5884                                 (void *)&cmd_showbonding_config_show,
5885                                 (void *)&cmd_showbonding_config_bonding,
5886                                 (void *)&cmd_showbonding_config_config,
5887                                 (void *)&cmd_showbonding_config_port,
5888                                 NULL
5889                 }
5890 };
5891
5892 /* *** SET BONDING PRIMARY *** */
5893 struct cmd_set_bonding_primary_result {
5894         cmdline_fixed_string_t set;
5895         cmdline_fixed_string_t bonding;
5896         cmdline_fixed_string_t primary;
5897         portid_t slave_id;
5898         portid_t port_id;
5899 };
5900
5901 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5902                 __attribute__((unused))  struct cmdline *cl,
5903                 __attribute__((unused)) void *data)
5904 {
5905         struct cmd_set_bonding_primary_result *res = parsed_result;
5906         portid_t master_port_id = res->port_id;
5907         portid_t slave_port_id = res->slave_id;
5908
5909         /* Set the primary slave for a bonded device. */
5910         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5911                 printf("\t Failed to set primary slave for port = %d.\n",
5912                                 master_port_id);
5913                 return;
5914         }
5915         init_port_config();
5916 }
5917
5918 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5919 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5920                 set, "set");
5921 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5922 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5923                 bonding, "bonding");
5924 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5925 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5926                 primary, "primary");
5927 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5928 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5929                 slave_id, UINT16);
5930 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5931 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5932                 port_id, UINT16);
5933
5934 cmdline_parse_inst_t cmd_set_bonding_primary = {
5935                 .f = cmd_set_bonding_primary_parsed,
5936                 .help_str = "set bonding primary <slave_id> <port_id>: "
5937                         "Set the primary slave for port_id",
5938                 .data = NULL,
5939                 .tokens = {
5940                                 (void *)&cmd_setbonding_primary_set,
5941                                 (void *)&cmd_setbonding_primary_bonding,
5942                                 (void *)&cmd_setbonding_primary_primary,
5943                                 (void *)&cmd_setbonding_primary_slave,
5944                                 (void *)&cmd_setbonding_primary_port,
5945                                 NULL
5946                 }
5947 };
5948
5949 /* *** ADD SLAVE *** */
5950 struct cmd_add_bonding_slave_result {
5951         cmdline_fixed_string_t add;
5952         cmdline_fixed_string_t bonding;
5953         cmdline_fixed_string_t slave;
5954         portid_t slave_id;
5955         portid_t port_id;
5956 };
5957
5958 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5959                 __attribute__((unused))  struct cmdline *cl,
5960                 __attribute__((unused)) void *data)
5961 {
5962         struct cmd_add_bonding_slave_result *res = parsed_result;
5963         portid_t master_port_id = res->port_id;
5964         portid_t slave_port_id = res->slave_id;
5965
5966         /* add the slave for a bonded device. */
5967         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5968                 printf("\t Failed to add slave %d to master port = %d.\n",
5969                                 slave_port_id, master_port_id);
5970                 return;
5971         }
5972         init_port_config();
5973         set_port_slave_flag(slave_port_id);
5974 }
5975
5976 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5977 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5978                 add, "add");
5979 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5980 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5981                 bonding, "bonding");
5982 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5983 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5984                 slave, "slave");
5985 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5986 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5987                 slave_id, UINT16);
5988 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5989 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5990                 port_id, UINT16);
5991
5992 cmdline_parse_inst_t cmd_add_bonding_slave = {
5993                 .f = cmd_add_bonding_slave_parsed,
5994                 .help_str = "add bonding slave <slave_id> <port_id>: "
5995                         "Add a slave device to a bonded device",
5996                 .data = NULL,
5997                 .tokens = {
5998                                 (void *)&cmd_addbonding_slave_add,
5999                                 (void *)&cmd_addbonding_slave_bonding,
6000                                 (void *)&cmd_addbonding_slave_slave,
6001                                 (void *)&cmd_addbonding_slave_slaveid,
6002                                 (void *)&cmd_addbonding_slave_port,
6003                                 NULL
6004                 }
6005 };
6006
6007 /* *** REMOVE SLAVE *** */
6008 struct cmd_remove_bonding_slave_result {
6009         cmdline_fixed_string_t remove;
6010         cmdline_fixed_string_t bonding;
6011         cmdline_fixed_string_t slave;
6012         portid_t slave_id;
6013         portid_t port_id;
6014 };
6015
6016 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6017                 __attribute__((unused))  struct cmdline *cl,
6018                 __attribute__((unused)) void *data)
6019 {
6020         struct cmd_remove_bonding_slave_result *res = parsed_result;
6021         portid_t master_port_id = res->port_id;
6022         portid_t slave_port_id = res->slave_id;
6023
6024         /* remove the slave from a bonded device. */
6025         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6026                 printf("\t Failed to remove slave %d from master port = %d.\n",
6027                                 slave_port_id, master_port_id);
6028                 return;
6029         }
6030         init_port_config();
6031         clear_port_slave_flag(slave_port_id);
6032 }
6033
6034 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6035                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6036                                 remove, "remove");
6037 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6038                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6039                                 bonding, "bonding");
6040 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6041                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6042                                 slave, "slave");
6043 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6044                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6045                                 slave_id, UINT16);
6046 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6047                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6048                                 port_id, UINT16);
6049
6050 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6051                 .f = cmd_remove_bonding_slave_parsed,
6052                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6053                         "Remove a slave device from a bonded device",
6054                 .data = NULL,
6055                 .tokens = {
6056                                 (void *)&cmd_removebonding_slave_remove,
6057                                 (void *)&cmd_removebonding_slave_bonding,
6058                                 (void *)&cmd_removebonding_slave_slave,
6059                                 (void *)&cmd_removebonding_slave_slaveid,
6060                                 (void *)&cmd_removebonding_slave_port,
6061                                 NULL
6062                 }
6063 };
6064
6065 /* *** CREATE BONDED DEVICE *** */
6066 struct cmd_create_bonded_device_result {
6067         cmdline_fixed_string_t create;
6068         cmdline_fixed_string_t bonded;
6069         cmdline_fixed_string_t device;
6070         uint8_t mode;
6071         uint8_t socket;
6072 };
6073
6074 static int bond_dev_num = 0;
6075
6076 static void cmd_create_bonded_device_parsed(void *parsed_result,
6077                 __attribute__((unused))  struct cmdline *cl,
6078                 __attribute__((unused)) void *data)
6079 {
6080         struct cmd_create_bonded_device_result *res = parsed_result;
6081         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6082         int port_id;
6083         int ret;
6084
6085         if (test_done == 0) {
6086                 printf("Please stop forwarding first\n");
6087                 return;
6088         }
6089
6090         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6091                         bond_dev_num++);
6092
6093         /* Create a new bonded device. */
6094         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6095         if (port_id < 0) {
6096                 printf("\t Failed to create bonded device.\n");
6097                 return;
6098         } else {
6099                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6100                                 port_id);
6101
6102                 /* Update number of ports */
6103                 nb_ports = rte_eth_dev_count_avail();
6104                 reconfig(port_id, res->socket);
6105                 ret = rte_eth_promiscuous_enable(port_id);
6106                 if (ret != 0)
6107                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6108                                 port_id, rte_strerror(-ret));
6109
6110                 ports[port_id].need_setup = 0;
6111                 ports[port_id].port_status = RTE_PORT_STOPPED;
6112         }
6113
6114 }
6115
6116 cmdline_parse_token_string_t cmd_createbonded_device_create =
6117                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6118                                 create, "create");
6119 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6120                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6121                                 bonded, "bonded");
6122 cmdline_parse_token_string_t cmd_createbonded_device_device =
6123                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6124                                 device, "device");
6125 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6126                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6127                                 mode, UINT8);
6128 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6129                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6130                                 socket, UINT8);
6131
6132 cmdline_parse_inst_t cmd_create_bonded_device = {
6133                 .f = cmd_create_bonded_device_parsed,
6134                 .help_str = "create bonded device <mode> <socket>: "
6135                         "Create a new bonded device with specific bonding mode and socket",
6136                 .data = NULL,
6137                 .tokens = {
6138                                 (void *)&cmd_createbonded_device_create,
6139                                 (void *)&cmd_createbonded_device_bonded,
6140                                 (void *)&cmd_createbonded_device_device,
6141                                 (void *)&cmd_createbonded_device_mode,
6142                                 (void *)&cmd_createbonded_device_socket,
6143                                 NULL
6144                 }
6145 };
6146
6147 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6148 struct cmd_set_bond_mac_addr_result {
6149         cmdline_fixed_string_t set;
6150         cmdline_fixed_string_t bonding;
6151         cmdline_fixed_string_t mac_addr;
6152         uint16_t port_num;
6153         struct rte_ether_addr address;
6154 };
6155
6156 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6157                 __attribute__((unused))  struct cmdline *cl,
6158                 __attribute__((unused)) void *data)
6159 {
6160         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6161         int ret;
6162
6163         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6164                 return;
6165
6166         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6167
6168         /* check the return value and print it if is < 0 */
6169         if (ret < 0)
6170                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6171 }
6172
6173 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6174                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6175 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6176                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6177                                 "bonding");
6178 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6179                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6180                                 "mac_addr");
6181 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6182                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6183                                 port_num, UINT16);
6184 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6185                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6186
6187 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6188                 .f = cmd_set_bond_mac_addr_parsed,
6189                 .data = (void *) 0,
6190                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6191                 .tokens = {
6192                                 (void *)&cmd_set_bond_mac_addr_set,
6193                                 (void *)&cmd_set_bond_mac_addr_bonding,
6194                                 (void *)&cmd_set_bond_mac_addr_mac,
6195                                 (void *)&cmd_set_bond_mac_addr_portnum,
6196                                 (void *)&cmd_set_bond_mac_addr_addr,
6197                                 NULL
6198                 }
6199 };
6200
6201
6202 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6203 struct cmd_set_bond_mon_period_result {
6204         cmdline_fixed_string_t set;
6205         cmdline_fixed_string_t bonding;
6206         cmdline_fixed_string_t mon_period;
6207         uint16_t port_num;
6208         uint32_t period_ms;
6209 };
6210
6211 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6212                 __attribute__((unused))  struct cmdline *cl,
6213                 __attribute__((unused)) void *data)
6214 {
6215         struct cmd_set_bond_mon_period_result *res = parsed_result;
6216         int ret;
6217
6218         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6219
6220         /* check the return value and print it if is < 0 */
6221         if (ret < 0)
6222                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6223 }
6224
6225 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6226                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6227                                 set, "set");
6228 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6229                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6230                                 bonding, "bonding");
6231 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6232                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6233                                 mon_period,     "mon_period");
6234 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6235                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6236                                 port_num, UINT16);
6237 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6238                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6239                                 period_ms, UINT32);
6240
6241 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6242                 .f = cmd_set_bond_mon_period_parsed,
6243                 .data = (void *) 0,
6244                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6245                 .tokens = {
6246                                 (void *)&cmd_set_bond_mon_period_set,
6247                                 (void *)&cmd_set_bond_mon_period_bonding,
6248                                 (void *)&cmd_set_bond_mon_period_mon_period,
6249                                 (void *)&cmd_set_bond_mon_period_portnum,
6250                                 (void *)&cmd_set_bond_mon_period_period_ms,
6251                                 NULL
6252                 }
6253 };
6254
6255
6256
6257 struct cmd_set_bonding_agg_mode_policy_result {
6258         cmdline_fixed_string_t set;
6259         cmdline_fixed_string_t bonding;
6260         cmdline_fixed_string_t agg_mode;
6261         uint16_t port_num;
6262         cmdline_fixed_string_t policy;
6263 };
6264
6265
6266 static void
6267 cmd_set_bonding_agg_mode(void *parsed_result,
6268                 __attribute__((unused)) struct cmdline *cl,
6269                 __attribute__((unused)) void *data)
6270 {
6271         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6272         uint8_t policy = AGG_BANDWIDTH;
6273
6274         if (!strcmp(res->policy, "bandwidth"))
6275                 policy = AGG_BANDWIDTH;
6276         else if (!strcmp(res->policy, "stable"))
6277                 policy = AGG_STABLE;
6278         else if (!strcmp(res->policy, "count"))
6279                 policy = AGG_COUNT;
6280
6281         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6282 }
6283
6284
6285 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6286         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6287                                 set, "set");
6288 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6289         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6290                                 bonding, "bonding");
6291
6292 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6293         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6294                                 agg_mode, "agg_mode");
6295
6296 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6297         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6298                                 port_num, UINT16);
6299
6300 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6301         TOKEN_STRING_INITIALIZER(
6302                         struct cmd_set_bonding_balance_xmit_policy_result,
6303                 policy, "stable#bandwidth#count");
6304
6305 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6306         .f = cmd_set_bonding_agg_mode,
6307         .data = (void *) 0,
6308         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6309         .tokens = {
6310                         (void *)&cmd_set_bonding_agg_mode_set,
6311                         (void *)&cmd_set_bonding_agg_mode_bonding,
6312                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6313                         (void *)&cmd_set_bonding_agg_mode_portnum,
6314                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6315                         NULL
6316                 }
6317 };
6318
6319
6320 #endif /* RTE_LIBRTE_PMD_BOND */
6321
6322 /* *** SET FORWARDING MODE *** */
6323 struct cmd_set_fwd_mode_result {
6324         cmdline_fixed_string_t set;
6325         cmdline_fixed_string_t fwd;
6326         cmdline_fixed_string_t mode;
6327 };
6328
6329 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6330                                     __attribute__((unused)) struct cmdline *cl,
6331                                     __attribute__((unused)) void *data)
6332 {
6333         struct cmd_set_fwd_mode_result *res = parsed_result;
6334
6335         retry_enabled = 0;
6336         set_pkt_forwarding_mode(res->mode);
6337 }
6338
6339 cmdline_parse_token_string_t cmd_setfwd_set =
6340         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6341 cmdline_parse_token_string_t cmd_setfwd_fwd =
6342         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6343 cmdline_parse_token_string_t cmd_setfwd_mode =
6344         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6345                 "" /* defined at init */);
6346
6347 cmdline_parse_inst_t cmd_set_fwd_mode = {
6348         .f = cmd_set_fwd_mode_parsed,
6349         .data = NULL,
6350         .help_str = NULL, /* defined at init */
6351         .tokens = {
6352                 (void *)&cmd_setfwd_set,
6353                 (void *)&cmd_setfwd_fwd,
6354                 (void *)&cmd_setfwd_mode,
6355                 NULL,
6356         },
6357 };
6358
6359 static void cmd_set_fwd_mode_init(void)
6360 {
6361         char *modes, *c;
6362         static char token[128];
6363         static char help[256];
6364         cmdline_parse_token_string_t *token_struct;
6365
6366         modes = list_pkt_forwarding_modes();
6367         snprintf(help, sizeof(help), "set fwd %s: "
6368                 "Set packet forwarding mode", modes);
6369         cmd_set_fwd_mode.help_str = help;
6370
6371         /* string token separator is # */
6372         for (c = token; *modes != '\0'; modes++)
6373                 if (*modes == '|')
6374                         *c++ = '#';
6375                 else
6376                         *c++ = *modes;
6377         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6378         token_struct->string_data.str = token;
6379 }
6380
6381 /* *** SET RETRY FORWARDING MODE *** */
6382 struct cmd_set_fwd_retry_mode_result {
6383         cmdline_fixed_string_t set;
6384         cmdline_fixed_string_t fwd;
6385         cmdline_fixed_string_t mode;
6386         cmdline_fixed_string_t retry;
6387 };
6388
6389 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6390                             __attribute__((unused)) struct cmdline *cl,
6391                             __attribute__((unused)) void *data)
6392 {
6393         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6394
6395         retry_enabled = 1;
6396         set_pkt_forwarding_mode(res->mode);
6397 }
6398
6399 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6400         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6401                         set, "set");
6402 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6403         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6404                         fwd, "fwd");
6405 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6406         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6407                         mode,
6408                 "" /* defined at init */);
6409 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6410         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6411                         retry, "retry");
6412
6413 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6414         .f = cmd_set_fwd_retry_mode_parsed,
6415         .data = NULL,
6416         .help_str = NULL, /* defined at init */
6417         .tokens = {
6418                 (void *)&cmd_setfwd_retry_set,
6419                 (void *)&cmd_setfwd_retry_fwd,
6420                 (void *)&cmd_setfwd_retry_mode,
6421                 (void *)&cmd_setfwd_retry_retry,
6422                 NULL,
6423         },
6424 };
6425
6426 static void cmd_set_fwd_retry_mode_init(void)
6427 {
6428         char *modes, *c;
6429         static char token[128];
6430         static char help[256];
6431         cmdline_parse_token_string_t *token_struct;
6432
6433         modes = list_pkt_forwarding_retry_modes();
6434         snprintf(help, sizeof(help), "set fwd %s retry: "
6435                 "Set packet forwarding mode with retry", modes);
6436         cmd_set_fwd_retry_mode.help_str = help;
6437
6438         /* string token separator is # */
6439         for (c = token; *modes != '\0'; modes++)
6440                 if (*modes == '|')
6441                         *c++ = '#';
6442                 else
6443                         *c++ = *modes;
6444         token_struct = (cmdline_parse_token_string_t *)
6445                 cmd_set_fwd_retry_mode.tokens[2];
6446         token_struct->string_data.str = token;
6447 }
6448
6449 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6450 struct cmd_set_burst_tx_retry_result {
6451         cmdline_fixed_string_t set;
6452         cmdline_fixed_string_t burst;
6453         cmdline_fixed_string_t tx;
6454         cmdline_fixed_string_t delay;
6455         uint32_t time;
6456         cmdline_fixed_string_t retry;
6457         uint32_t retry_num;
6458 };
6459
6460 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6461                                         __attribute__((unused)) struct cmdline *cl,
6462                                         __attribute__((unused)) void *data)
6463 {
6464         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6465
6466         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6467                 && !strcmp(res->tx, "tx")) {
6468                 if (!strcmp(res->delay, "delay"))
6469                         burst_tx_delay_time = res->time;
6470                 if (!strcmp(res->retry, "retry"))
6471                         burst_tx_retry_num = res->retry_num;
6472         }
6473
6474 }
6475
6476 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6477         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6478 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6479         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6480                                  "burst");
6481 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6482         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6483 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6484         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6485 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6486         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6487 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6488         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6489 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6490         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6491
6492 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6493         .f = cmd_set_burst_tx_retry_parsed,
6494         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6495         .tokens = {
6496                 (void *)&cmd_set_burst_tx_retry_set,
6497                 (void *)&cmd_set_burst_tx_retry_burst,
6498                 (void *)&cmd_set_burst_tx_retry_tx,
6499                 (void *)&cmd_set_burst_tx_retry_delay,
6500                 (void *)&cmd_set_burst_tx_retry_time,
6501                 (void *)&cmd_set_burst_tx_retry_retry,
6502                 (void *)&cmd_set_burst_tx_retry_retry_num,
6503                 NULL,
6504         },
6505 };
6506
6507 /* *** SET PROMISC MODE *** */
6508 struct cmd_set_promisc_mode_result {
6509         cmdline_fixed_string_t set;
6510         cmdline_fixed_string_t promisc;
6511         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6512         uint16_t port_num;               /* valid if "allports" argument == 0 */
6513         cmdline_fixed_string_t mode;
6514 };
6515
6516 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6517                                         __attribute__((unused)) struct cmdline *cl,
6518                                         void *allports)
6519 {
6520         struct cmd_set_promisc_mode_result *res = parsed_result;
6521         int enable;
6522         portid_t i;
6523
6524         if (!strcmp(res->mode, "on"))
6525                 enable = 1;
6526         else
6527                 enable = 0;
6528
6529         /* all ports */
6530         if (allports) {
6531                 RTE_ETH_FOREACH_DEV(i)
6532                         eth_set_promisc_mode(i, enable);
6533         } else {
6534                 eth_set_promisc_mode(res->port_num, enable);
6535         }
6536 }
6537
6538 cmdline_parse_token_string_t cmd_setpromisc_set =
6539         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6540 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6541         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6542                                  "promisc");
6543 cmdline_parse_token_string_t cmd_setpromisc_portall =
6544         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6545                                  "all");
6546 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6547         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6548                               UINT16);
6549 cmdline_parse_token_string_t cmd_setpromisc_mode =
6550         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6551                                  "on#off");
6552
6553 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6554         .f = cmd_set_promisc_mode_parsed,
6555         .data = (void *)1,
6556         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6557         .tokens = {
6558                 (void *)&cmd_setpromisc_set,
6559                 (void *)&cmd_setpromisc_promisc,
6560                 (void *)&cmd_setpromisc_portall,
6561                 (void *)&cmd_setpromisc_mode,
6562                 NULL,
6563         },
6564 };
6565
6566 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6567         .f = cmd_set_promisc_mode_parsed,
6568         .data = (void *)0,
6569         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6570         .tokens = {
6571                 (void *)&cmd_setpromisc_set,
6572                 (void *)&cmd_setpromisc_promisc,
6573                 (void *)&cmd_setpromisc_portnum,
6574                 (void *)&cmd_setpromisc_mode,
6575                 NULL,
6576         },
6577 };
6578
6579 /* *** SET ALLMULTI MODE *** */
6580 struct cmd_set_allmulti_mode_result {
6581         cmdline_fixed_string_t set;
6582         cmdline_fixed_string_t allmulti;
6583         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6584         uint16_t port_num;               /* valid if "allports" argument == 0 */
6585         cmdline_fixed_string_t mode;
6586 };
6587
6588 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6589                                         __attribute__((unused)) struct cmdline *cl,
6590                                         void *allports)
6591 {
6592         struct cmd_set_allmulti_mode_result *res = parsed_result;
6593         int enable;
6594         portid_t i;
6595
6596         if (!strcmp(res->mode, "on"))
6597                 enable = 1;
6598         else
6599                 enable = 0;
6600
6601         /* all ports */
6602         if (allports) {
6603                 RTE_ETH_FOREACH_DEV(i) {
6604                         eth_set_allmulticast_mode(i, enable);
6605                 }
6606         }
6607         else {
6608                 eth_set_allmulticast_mode(res->port_num, enable);
6609         }
6610 }
6611
6612 cmdline_parse_token_string_t cmd_setallmulti_set =
6613         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6614 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6615         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6616                                  "allmulti");
6617 cmdline_parse_token_string_t cmd_setallmulti_portall =
6618         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6619                                  "all");
6620 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6621         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6622                               UINT16);
6623 cmdline_parse_token_string_t cmd_setallmulti_mode =
6624         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6625                                  "on#off");
6626
6627 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6628         .f = cmd_set_allmulti_mode_parsed,
6629         .data = (void *)1,
6630         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6631         .tokens = {
6632                 (void *)&cmd_setallmulti_set,
6633                 (void *)&cmd_setallmulti_allmulti,
6634                 (void *)&cmd_setallmulti_portall,
6635                 (void *)&cmd_setallmulti_mode,
6636                 NULL,
6637         },
6638 };
6639
6640 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6641         .f = cmd_set_allmulti_mode_parsed,
6642         .data = (void *)0,
6643         .help_str = "set allmulti <port_id> on|off: "
6644                 "Set allmulti mode on port_id",
6645         .tokens = {
6646                 (void *)&cmd_setallmulti_set,
6647                 (void *)&cmd_setallmulti_allmulti,
6648                 (void *)&cmd_setallmulti_portnum,
6649                 (void *)&cmd_setallmulti_mode,
6650                 NULL,
6651         },
6652 };
6653
6654 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6655 struct cmd_link_flow_ctrl_set_result {
6656         cmdline_fixed_string_t set;
6657         cmdline_fixed_string_t flow_ctrl;
6658         cmdline_fixed_string_t rx;
6659         cmdline_fixed_string_t rx_lfc_mode;
6660         cmdline_fixed_string_t tx;
6661         cmdline_fixed_string_t tx_lfc_mode;
6662         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6663         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6664         cmdline_fixed_string_t autoneg_str;
6665         cmdline_fixed_string_t autoneg;
6666         cmdline_fixed_string_t hw_str;
6667         uint32_t high_water;
6668         cmdline_fixed_string_t lw_str;
6669         uint32_t low_water;
6670         cmdline_fixed_string_t pt_str;
6671         uint16_t pause_time;
6672         cmdline_fixed_string_t xon_str;
6673         uint16_t send_xon;
6674         portid_t port_id;
6675 };
6676
6677 cmdline_parse_token_string_t cmd_lfc_set_set =
6678         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6679                                 set, "set");
6680 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6681         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6682                                 flow_ctrl, "flow_ctrl");
6683 cmdline_parse_token_string_t cmd_lfc_set_rx =
6684         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6685                                 rx, "rx");
6686 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6687         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6688                                 rx_lfc_mode, "on#off");
6689 cmdline_parse_token_string_t cmd_lfc_set_tx =
6690         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6691                                 tx, "tx");
6692 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6693         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6694                                 tx_lfc_mode, "on#off");
6695 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6696         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6697                                 hw_str, "high_water");
6698 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6699         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6700                                 high_water, UINT32);
6701 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6702         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6703                                 lw_str, "low_water");
6704 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6705         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6706                                 low_water, UINT32);
6707 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6708         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6709                                 pt_str, "pause_time");
6710 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6711         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6712                                 pause_time, UINT16);
6713 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6714         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6715                                 xon_str, "send_xon");
6716 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6717         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6718                                 send_xon, UINT16);
6719 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6720         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6721                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6722 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6723         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6724                                 mac_ctrl_frame_fwd_mode, "on#off");
6725 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6726         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6727                                 autoneg_str, "autoneg");
6728 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6729         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6730                                 autoneg, "on#off");
6731 cmdline_parse_token_num_t cmd_lfc_set_portid =
6732         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6733                                 port_id, UINT16);
6734
6735 /* forward declaration */
6736 static void
6737 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6738                               void *data);
6739
6740 cmdline_parse_inst_t cmd_link_flow_control_set = {
6741         .f = cmd_link_flow_ctrl_set_parsed,
6742         .data = NULL,
6743         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6744                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6745                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6746         .tokens = {
6747                 (void *)&cmd_lfc_set_set,
6748                 (void *)&cmd_lfc_set_flow_ctrl,
6749                 (void *)&cmd_lfc_set_rx,
6750                 (void *)&cmd_lfc_set_rx_mode,
6751                 (void *)&cmd_lfc_set_tx,
6752                 (void *)&cmd_lfc_set_tx_mode,
6753                 (void *)&cmd_lfc_set_high_water,
6754                 (void *)&cmd_lfc_set_low_water,
6755                 (void *)&cmd_lfc_set_pause_time,
6756                 (void *)&cmd_lfc_set_send_xon,
6757                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6758                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6759                 (void *)&cmd_lfc_set_autoneg_str,
6760                 (void *)&cmd_lfc_set_autoneg,
6761                 (void *)&cmd_lfc_set_portid,
6762                 NULL,
6763         },
6764 };
6765
6766 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6767         .f = cmd_link_flow_ctrl_set_parsed,
6768         .data = (void *)&cmd_link_flow_control_set_rx,
6769         .help_str = "set flow_ctrl rx on|off <port_id>: "
6770                 "Change rx flow control parameter",
6771         .tokens = {
6772                 (void *)&cmd_lfc_set_set,
6773                 (void *)&cmd_lfc_set_flow_ctrl,
6774                 (void *)&cmd_lfc_set_rx,
6775                 (void *)&cmd_lfc_set_rx_mode,
6776                 (void *)&cmd_lfc_set_portid,
6777                 NULL,
6778         },
6779 };
6780
6781 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6782         .f = cmd_link_flow_ctrl_set_parsed,
6783         .data = (void *)&cmd_link_flow_control_set_tx,
6784         .help_str = "set flow_ctrl tx on|off <port_id>: "
6785                 "Change tx flow control parameter",
6786         .tokens = {
6787                 (void *)&cmd_lfc_set_set,
6788                 (void *)&cmd_lfc_set_flow_ctrl,
6789                 (void *)&cmd_lfc_set_tx,
6790                 (void *)&cmd_lfc_set_tx_mode,
6791                 (void *)&cmd_lfc_set_portid,
6792                 NULL,
6793         },
6794 };
6795
6796 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6797         .f = cmd_link_flow_ctrl_set_parsed,
6798         .data = (void *)&cmd_link_flow_control_set_hw,
6799         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6800                 "Change high water flow control parameter",
6801         .tokens = {
6802                 (void *)&cmd_lfc_set_set,
6803                 (void *)&cmd_lfc_set_flow_ctrl,
6804                 (void *)&cmd_lfc_set_high_water_str,
6805                 (void *)&cmd_lfc_set_high_water,
6806                 (void *)&cmd_lfc_set_portid,
6807                 NULL,
6808         },
6809 };
6810
6811 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6812         .f = cmd_link_flow_ctrl_set_parsed,
6813         .data = (void *)&cmd_link_flow_control_set_lw,
6814         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6815                 "Change low water flow control parameter",
6816         .tokens = {
6817                 (void *)&cmd_lfc_set_set,
6818                 (void *)&cmd_lfc_set_flow_ctrl,
6819                 (void *)&cmd_lfc_set_low_water_str,
6820                 (void *)&cmd_lfc_set_low_water,
6821                 (void *)&cmd_lfc_set_portid,
6822                 NULL,
6823         },
6824 };
6825
6826 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6827         .f = cmd_link_flow_ctrl_set_parsed,
6828         .data = (void *)&cmd_link_flow_control_set_pt,
6829         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6830                 "Change pause time flow control parameter",
6831         .tokens = {
6832                 (void *)&cmd_lfc_set_set,
6833                 (void *)&cmd_lfc_set_flow_ctrl,
6834                 (void *)&cmd_lfc_set_pause_time_str,
6835                 (void *)&cmd_lfc_set_pause_time,
6836                 (void *)&cmd_lfc_set_portid,
6837                 NULL,
6838         },
6839 };
6840
6841 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6842         .f = cmd_link_flow_ctrl_set_parsed,
6843         .data = (void *)&cmd_link_flow_control_set_xon,
6844         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6845                 "Change send_xon flow control parameter",
6846         .tokens = {
6847                 (void *)&cmd_lfc_set_set,
6848                 (void *)&cmd_lfc_set_flow_ctrl,
6849                 (void *)&cmd_lfc_set_send_xon_str,
6850                 (void *)&cmd_lfc_set_send_xon,
6851                 (void *)&cmd_lfc_set_portid,
6852                 NULL,
6853         },
6854 };
6855
6856 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6857         .f = cmd_link_flow_ctrl_set_parsed,
6858         .data = (void *)&cmd_link_flow_control_set_macfwd,
6859         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6860                 "Change mac ctrl fwd flow control parameter",
6861         .tokens = {
6862                 (void *)&cmd_lfc_set_set,
6863                 (void *)&cmd_lfc_set_flow_ctrl,
6864                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6865                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6866                 (void *)&cmd_lfc_set_portid,
6867                 NULL,
6868         },
6869 };
6870
6871 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6872         .f = cmd_link_flow_ctrl_set_parsed,
6873         .data = (void *)&cmd_link_flow_control_set_autoneg,
6874         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6875                 "Change autoneg flow control parameter",
6876         .tokens = {
6877                 (void *)&cmd_lfc_set_set,
6878                 (void *)&cmd_lfc_set_flow_ctrl,
6879                 (void *)&cmd_lfc_set_autoneg_str,
6880                 (void *)&cmd_lfc_set_autoneg,
6881                 (void *)&cmd_lfc_set_portid,
6882                 NULL,
6883         },
6884 };
6885
6886 static void
6887 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6888                               __attribute__((unused)) struct cmdline *cl,
6889                               void *data)
6890 {
6891         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6892         cmdline_parse_inst_t *cmd = data;
6893         struct rte_eth_fc_conf fc_conf;
6894         int rx_fc_en = 0;
6895         int tx_fc_en = 0;
6896         int ret;
6897
6898         /*
6899          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6900          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6901          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6902          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6903          */
6904         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6905                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6906         };
6907
6908         /* Partial command line, retrieve current configuration */
6909         if (cmd) {
6910                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6911                 if (ret != 0) {
6912                         printf("cannot get current flow ctrl parameters, return"
6913                                "code = %d\n", ret);
6914                         return;
6915                 }
6916
6917                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6918                     (fc_conf.mode == RTE_FC_FULL))
6919                         rx_fc_en = 1;
6920                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6921                     (fc_conf.mode == RTE_FC_FULL))
6922                         tx_fc_en = 1;
6923         }
6924
6925         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6926                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6927
6928         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6929                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6930
6931         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6932
6933         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6934                 fc_conf.high_water = res->high_water;
6935
6936         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6937                 fc_conf.low_water = res->low_water;
6938
6939         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6940                 fc_conf.pause_time = res->pause_time;
6941
6942         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6943                 fc_conf.send_xon = res->send_xon;
6944
6945         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6946                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6947                         fc_conf.mac_ctrl_frame_fwd = 1;
6948                 else
6949                         fc_conf.mac_ctrl_frame_fwd = 0;
6950         }
6951
6952         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6953                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6954
6955         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6956         if (ret != 0)
6957                 printf("bad flow contrl parameter, return code = %d \n", ret);
6958 }
6959
6960 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6961 struct cmd_priority_flow_ctrl_set_result {
6962         cmdline_fixed_string_t set;
6963         cmdline_fixed_string_t pfc_ctrl;
6964         cmdline_fixed_string_t rx;
6965         cmdline_fixed_string_t rx_pfc_mode;
6966         cmdline_fixed_string_t tx;
6967         cmdline_fixed_string_t tx_pfc_mode;
6968         uint32_t high_water;
6969         uint32_t low_water;
6970         uint16_t pause_time;
6971         uint8_t  priority;
6972         portid_t port_id;
6973 };
6974
6975 static void
6976 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6977                        __attribute__((unused)) struct cmdline *cl,
6978                        __attribute__((unused)) void *data)
6979 {
6980         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6981         struct rte_eth_pfc_conf pfc_conf;
6982         int rx_fc_enable, tx_fc_enable;
6983         int ret;
6984
6985         /*
6986          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6987          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6988          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6989          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6990          */
6991         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6992                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6993         };
6994
6995         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6996         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6997         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6998         pfc_conf.fc.high_water = res->high_water;
6999         pfc_conf.fc.low_water  = res->low_water;
7000         pfc_conf.fc.pause_time = res->pause_time;
7001         pfc_conf.priority      = res->priority;
7002
7003         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7004         if (ret != 0)
7005                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7006 }
7007
7008 cmdline_parse_token_string_t cmd_pfc_set_set =
7009         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7010                                 set, "set");
7011 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7012         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7013                                 pfc_ctrl, "pfc_ctrl");
7014 cmdline_parse_token_string_t cmd_pfc_set_rx =
7015         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7016                                 rx, "rx");
7017 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7018         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7019                                 rx_pfc_mode, "on#off");
7020 cmdline_parse_token_string_t cmd_pfc_set_tx =
7021         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7022                                 tx, "tx");
7023 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7024         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7025                                 tx_pfc_mode, "on#off");
7026 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7027         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7028                                 high_water, UINT32);
7029 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7030         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7031                                 low_water, UINT32);
7032 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7033         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7034                                 pause_time, UINT16);
7035 cmdline_parse_token_num_t cmd_pfc_set_priority =
7036         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7037                                 priority, UINT8);
7038 cmdline_parse_token_num_t cmd_pfc_set_portid =
7039         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7040                                 port_id, UINT16);
7041
7042 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7043         .f = cmd_priority_flow_ctrl_set_parsed,
7044         .data = NULL,
7045         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7046                 "<pause_time> <priority> <port_id>: "
7047                 "Configure the Ethernet priority flow control",
7048         .tokens = {
7049                 (void *)&cmd_pfc_set_set,
7050                 (void *)&cmd_pfc_set_flow_ctrl,
7051                 (void *)&cmd_pfc_set_rx,
7052                 (void *)&cmd_pfc_set_rx_mode,
7053                 (void *)&cmd_pfc_set_tx,
7054                 (void *)&cmd_pfc_set_tx_mode,
7055                 (void *)&cmd_pfc_set_high_water,
7056                 (void *)&cmd_pfc_set_low_water,
7057                 (void *)&cmd_pfc_set_pause_time,
7058                 (void *)&cmd_pfc_set_priority,
7059                 (void *)&cmd_pfc_set_portid,
7060                 NULL,
7061         },
7062 };
7063
7064 /* *** RESET CONFIGURATION *** */
7065 struct cmd_reset_result {
7066         cmdline_fixed_string_t reset;
7067         cmdline_fixed_string_t def;
7068 };
7069
7070 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7071                              struct cmdline *cl,
7072                              __attribute__((unused)) void *data)
7073 {
7074         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7075         set_def_fwd_config();
7076 }
7077
7078 cmdline_parse_token_string_t cmd_reset_set =
7079         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7080 cmdline_parse_token_string_t cmd_reset_def =
7081         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7082                                  "default");
7083
7084 cmdline_parse_inst_t cmd_reset = {
7085         .f = cmd_reset_parsed,
7086         .data = NULL,
7087         .help_str = "set default: Reset default forwarding configuration",
7088         .tokens = {
7089                 (void *)&cmd_reset_set,
7090                 (void *)&cmd_reset_def,
7091                 NULL,
7092         },
7093 };
7094
7095 /* *** START FORWARDING *** */
7096 struct cmd_start_result {
7097         cmdline_fixed_string_t start;
7098 };
7099
7100 cmdline_parse_token_string_t cmd_start_start =
7101         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7102
7103 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7104                              __attribute__((unused)) struct cmdline *cl,
7105                              __attribute__((unused)) void *data)
7106 {
7107         start_packet_forwarding(0);
7108 }
7109
7110 cmdline_parse_inst_t cmd_start = {
7111         .f = cmd_start_parsed,
7112         .data = NULL,
7113         .help_str = "start: Start packet forwarding",
7114         .tokens = {
7115                 (void *)&cmd_start_start,
7116                 NULL,
7117         },
7118 };
7119
7120 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7121 struct cmd_start_tx_first_result {
7122         cmdline_fixed_string_t start;
7123         cmdline_fixed_string_t tx_first;
7124 };
7125
7126 static void
7127 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7128                           __attribute__((unused)) struct cmdline *cl,
7129                           __attribute__((unused)) void *data)
7130 {
7131         start_packet_forwarding(1);
7132 }
7133
7134 cmdline_parse_token_string_t cmd_start_tx_first_start =
7135         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7136                                  "start");
7137 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7138         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7139                                  tx_first, "tx_first");
7140
7141 cmdline_parse_inst_t cmd_start_tx_first = {
7142         .f = cmd_start_tx_first_parsed,
7143         .data = NULL,
7144         .help_str = "start tx_first: Start packet forwarding, "
7145                 "after sending 1 burst of packets",
7146         .tokens = {
7147                 (void *)&cmd_start_tx_first_start,
7148                 (void *)&cmd_start_tx_first_tx_first,
7149                 NULL,
7150         },
7151 };
7152
7153 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7154 struct cmd_start_tx_first_n_result {
7155         cmdline_fixed_string_t start;
7156         cmdline_fixed_string_t tx_first;
7157         uint32_t tx_num;
7158 };
7159
7160 static void
7161 cmd_start_tx_first_n_parsed(void *parsed_result,
7162                           __attribute__((unused)) struct cmdline *cl,
7163                           __attribute__((unused)) void *data)
7164 {
7165         struct cmd_start_tx_first_n_result *res = parsed_result;
7166
7167         start_packet_forwarding(res->tx_num);
7168 }
7169
7170 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7171         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7172                         start, "start");
7173 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7174         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7175                         tx_first, "tx_first");
7176 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7177         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7178                         tx_num, UINT32);
7179
7180 cmdline_parse_inst_t cmd_start_tx_first_n = {
7181         .f = cmd_start_tx_first_n_parsed,
7182         .data = NULL,
7183         .help_str = "start tx_first <num>: "
7184                 "packet forwarding, after sending <num> bursts of packets",
7185         .tokens = {
7186                 (void *)&cmd_start_tx_first_n_start,
7187                 (void *)&cmd_start_tx_first_n_tx_first,
7188                 (void *)&cmd_start_tx_first_n_tx_num,
7189                 NULL,
7190         },
7191 };
7192
7193 /* *** SET LINK UP *** */
7194 struct cmd_set_link_up_result {
7195         cmdline_fixed_string_t set;
7196         cmdline_fixed_string_t link_up;
7197         cmdline_fixed_string_t port;
7198         portid_t port_id;
7199 };
7200
7201 cmdline_parse_token_string_t cmd_set_link_up_set =
7202         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7203 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7204         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7205                                 "link-up");
7206 cmdline_parse_token_string_t cmd_set_link_up_port =
7207         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7208 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7209         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7210
7211 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7212                              __attribute__((unused)) struct cmdline *cl,
7213                              __attribute__((unused)) void *data)
7214 {
7215         struct cmd_set_link_up_result *res = parsed_result;
7216         dev_set_link_up(res->port_id);
7217 }
7218
7219 cmdline_parse_inst_t cmd_set_link_up = {
7220         .f = cmd_set_link_up_parsed,
7221         .data = NULL,
7222         .help_str = "set link-up port <port id>",
7223         .tokens = {
7224                 (void *)&cmd_set_link_up_set,
7225                 (void *)&cmd_set_link_up_link_up,
7226                 (void *)&cmd_set_link_up_port,
7227                 (void *)&cmd_set_link_up_port_id,
7228                 NULL,
7229         },
7230 };
7231
7232 /* *** SET LINK DOWN *** */
7233 struct cmd_set_link_down_result {
7234         cmdline_fixed_string_t set;
7235         cmdline_fixed_string_t link_down;
7236         cmdline_fixed_string_t port;
7237         portid_t port_id;
7238 };
7239
7240 cmdline_parse_token_string_t cmd_set_link_down_set =
7241         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7242 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7243         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7244                                 "link-down");
7245 cmdline_parse_token_string_t cmd_set_link_down_port =
7246         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7247 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7248         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7249
7250 static void cmd_set_link_down_parsed(
7251                                 __attribute__((unused)) void *parsed_result,
7252                                 __attribute__((unused)) struct cmdline *cl,
7253                                 __attribute__((unused)) void *data)
7254 {
7255         struct cmd_set_link_down_result *res = parsed_result;
7256         dev_set_link_down(res->port_id);
7257 }
7258
7259 cmdline_parse_inst_t cmd_set_link_down = {
7260         .f = cmd_set_link_down_parsed,
7261         .data = NULL,
7262         .help_str = "set link-down port <port id>",
7263         .tokens = {
7264                 (void *)&cmd_set_link_down_set,
7265                 (void *)&cmd_set_link_down_link_down,
7266                 (void *)&cmd_set_link_down_port,
7267                 (void *)&cmd_set_link_down_port_id,
7268                 NULL,
7269         },
7270 };
7271
7272 /* *** SHOW CFG *** */
7273 struct cmd_showcfg_result {
7274         cmdline_fixed_string_t show;
7275         cmdline_fixed_string_t cfg;
7276         cmdline_fixed_string_t what;
7277 };
7278
7279 static void cmd_showcfg_parsed(void *parsed_result,
7280                                __attribute__((unused)) struct cmdline *cl,
7281                                __attribute__((unused)) void *data)
7282 {
7283         struct cmd_showcfg_result *res = parsed_result;
7284         if (!strcmp(res->what, "rxtx"))
7285                 rxtx_config_display();
7286         else if (!strcmp(res->what, "cores"))
7287                 fwd_lcores_config_display();
7288         else if (!strcmp(res->what, "fwd"))
7289                 pkt_fwd_config_display(&cur_fwd_config);
7290         else if (!strcmp(res->what, "txpkts"))
7291                 show_tx_pkt_segments();
7292 }
7293
7294 cmdline_parse_token_string_t cmd_showcfg_show =
7295         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7296 cmdline_parse_token_string_t cmd_showcfg_port =
7297         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7298 cmdline_parse_token_string_t cmd_showcfg_what =
7299         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7300                                  "rxtx#cores#fwd#txpkts");
7301
7302 cmdline_parse_inst_t cmd_showcfg = {
7303         .f = cmd_showcfg_parsed,
7304         .data = NULL,
7305         .help_str = "show config rxtx|cores|fwd|txpkts",
7306         .tokens = {
7307                 (void *)&cmd_showcfg_show,
7308                 (void *)&cmd_showcfg_port,
7309                 (void *)&cmd_showcfg_what,
7310                 NULL,
7311         },
7312 };
7313
7314 /* *** SHOW ALL PORT INFO *** */
7315 struct cmd_showportall_result {
7316         cmdline_fixed_string_t show;
7317         cmdline_fixed_string_t port;
7318         cmdline_fixed_string_t what;
7319         cmdline_fixed_string_t all;
7320 };
7321
7322 static void cmd_showportall_parsed(void *parsed_result,
7323                                 __attribute__((unused)) struct cmdline *cl,
7324                                 __attribute__((unused)) void *data)
7325 {
7326         portid_t i;
7327
7328         struct cmd_showportall_result *res = parsed_result;
7329         if (!strcmp(res->show, "clear")) {
7330                 if (!strcmp(res->what, "stats"))
7331                         RTE_ETH_FOREACH_DEV(i)
7332                                 nic_stats_clear(i);
7333                 else if (!strcmp(res->what, "xstats"))
7334                         RTE_ETH_FOREACH_DEV(i)
7335                                 nic_xstats_clear(i);
7336         } else if (!strcmp(res->what, "info"))
7337                 RTE_ETH_FOREACH_DEV(i)
7338                         port_infos_display(i);
7339         else if (!strcmp(res->what, "summary")) {
7340                 port_summary_header_display();
7341                 RTE_ETH_FOREACH_DEV(i)
7342                         port_summary_display(i);
7343         }
7344         else if (!strcmp(res->what, "stats"))
7345                 RTE_ETH_FOREACH_DEV(i)
7346                         nic_stats_display(i);
7347         else if (!strcmp(res->what, "xstats"))
7348                 RTE_ETH_FOREACH_DEV(i)
7349                         nic_xstats_display(i);
7350         else if (!strcmp(res->what, "fdir"))
7351                 RTE_ETH_FOREACH_DEV(i)
7352                         fdir_get_infos(i);
7353         else if (!strcmp(res->what, "stat_qmap"))
7354                 RTE_ETH_FOREACH_DEV(i)
7355                         nic_stats_mapping_display(i);
7356         else if (!strcmp(res->what, "dcb_tc"))
7357                 RTE_ETH_FOREACH_DEV(i)
7358                         port_dcb_info_display(i);
7359         else if (!strcmp(res->what, "cap"))
7360                 RTE_ETH_FOREACH_DEV(i)
7361                         port_offload_cap_display(i);
7362 }
7363
7364 cmdline_parse_token_string_t cmd_showportall_show =
7365         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7366                                  "show#clear");
7367 cmdline_parse_token_string_t cmd_showportall_port =
7368         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7369 cmdline_parse_token_string_t cmd_showportall_what =
7370         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7371                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7372 cmdline_parse_token_string_t cmd_showportall_all =
7373         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7374 cmdline_parse_inst_t cmd_showportall = {
7375         .f = cmd_showportall_parsed,
7376         .data = NULL,
7377         .help_str = "show|clear port "
7378                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7379         .tokens = {
7380                 (void *)&cmd_showportall_show,
7381                 (void *)&cmd_showportall_port,
7382                 (void *)&cmd_showportall_what,
7383                 (void *)&cmd_showportall_all,
7384                 NULL,
7385         },
7386 };
7387
7388 /* *** SHOW PORT INFO *** */
7389 struct cmd_showport_result {
7390         cmdline_fixed_string_t show;
7391         cmdline_fixed_string_t port;
7392         cmdline_fixed_string_t what;
7393         uint16_t portnum;
7394 };
7395
7396 static void cmd_showport_parsed(void *parsed_result,
7397                                 __attribute__((unused)) struct cmdline *cl,
7398                                 __attribute__((unused)) void *data)
7399 {
7400         struct cmd_showport_result *res = parsed_result;
7401         if (!strcmp(res->show, "clear")) {
7402                 if (!strcmp(res->what, "stats"))
7403                         nic_stats_clear(res->portnum);
7404                 else if (!strcmp(res->what, "xstats"))
7405                         nic_xstats_clear(res->portnum);
7406         } else if (!strcmp(res->what, "info"))
7407                 port_infos_display(res->portnum);
7408         else if (!strcmp(res->what, "summary")) {
7409                 port_summary_header_display();
7410                 port_summary_display(res->portnum);
7411         }
7412         else if (!strcmp(res->what, "stats"))
7413                 nic_stats_display(res->portnum);
7414         else if (!strcmp(res->what, "xstats"))
7415                 nic_xstats_display(res->portnum);
7416         else if (!strcmp(res->what, "fdir"))
7417                  fdir_get_infos(res->portnum);
7418         else if (!strcmp(res->what, "stat_qmap"))
7419                 nic_stats_mapping_display(res->portnum);
7420         else if (!strcmp(res->what, "dcb_tc"))
7421                 port_dcb_info_display(res->portnum);
7422         else if (!strcmp(res->what, "cap"))
7423                 port_offload_cap_display(res->portnum);
7424 }
7425
7426 cmdline_parse_token_string_t cmd_showport_show =
7427         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7428                                  "show#clear");
7429 cmdline_parse_token_string_t cmd_showport_port =
7430         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7431 cmdline_parse_token_string_t cmd_showport_what =
7432         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7433                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7434 cmdline_parse_token_num_t cmd_showport_portnum =
7435         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7436
7437 cmdline_parse_inst_t cmd_showport = {
7438         .f = cmd_showport_parsed,
7439         .data = NULL,
7440         .help_str = "show|clear port "
7441                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7442                 "<port_id>",
7443         .tokens = {
7444                 (void *)&cmd_showport_show,
7445                 (void *)&cmd_showport_port,
7446                 (void *)&cmd_showport_what,
7447                 (void *)&cmd_showport_portnum,
7448                 NULL,
7449         },
7450 };
7451
7452 /* *** SHOW DEVICE INFO *** */
7453 struct cmd_showdevice_result {
7454         cmdline_fixed_string_t show;
7455         cmdline_fixed_string_t device;
7456         cmdline_fixed_string_t what;
7457         cmdline_fixed_string_t identifier;
7458 };
7459
7460 static void cmd_showdevice_parsed(void *parsed_result,
7461                                 __attribute__((unused)) struct cmdline *cl,
7462                                 __attribute__((unused)) void *data)
7463 {
7464         struct cmd_showdevice_result *res = parsed_result;
7465         if (!strcmp(res->what, "info")) {
7466                 if (!strcmp(res->identifier, "all"))
7467                         device_infos_display(NULL);
7468                 else
7469                         device_infos_display(res->identifier);
7470         }
7471 }
7472
7473 cmdline_parse_token_string_t cmd_showdevice_show =
7474         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7475                                  "show");
7476 cmdline_parse_token_string_t cmd_showdevice_device =
7477         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7478 cmdline_parse_token_string_t cmd_showdevice_what =
7479         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7480                                  "info");
7481 cmdline_parse_token_string_t cmd_showdevice_identifier =
7482         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7483                         identifier, NULL);
7484
7485 cmdline_parse_inst_t cmd_showdevice = {
7486         .f = cmd_showdevice_parsed,
7487         .data = NULL,
7488         .help_str = "show device info <identifier>|all",
7489         .tokens = {
7490                 (void *)&cmd_showdevice_show,
7491                 (void *)&cmd_showdevice_device,
7492                 (void *)&cmd_showdevice_what,
7493                 (void *)&cmd_showdevice_identifier,
7494                 NULL,
7495         },
7496 };
7497 /* *** SHOW QUEUE INFO *** */
7498 struct cmd_showqueue_result {
7499         cmdline_fixed_string_t show;
7500         cmdline_fixed_string_t type;
7501         cmdline_fixed_string_t what;
7502         uint16_t portnum;
7503         uint16_t queuenum;
7504 };
7505
7506 static void
7507 cmd_showqueue_parsed(void *parsed_result,
7508         __attribute__((unused)) struct cmdline *cl,
7509         __attribute__((unused)) void *data)
7510 {
7511         struct cmd_showqueue_result *res = parsed_result;
7512
7513         if (!strcmp(res->type, "rxq"))
7514                 rx_queue_infos_display(res->portnum, res->queuenum);
7515         else if (!strcmp(res->type, "txq"))
7516                 tx_queue_infos_display(res->portnum, res->queuenum);
7517 }
7518
7519 cmdline_parse_token_string_t cmd_showqueue_show =
7520         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7521 cmdline_parse_token_string_t cmd_showqueue_type =
7522         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7523 cmdline_parse_token_string_t cmd_showqueue_what =
7524         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7525 cmdline_parse_token_num_t cmd_showqueue_portnum =
7526         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7527 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7528         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7529
7530 cmdline_parse_inst_t cmd_showqueue = {
7531         .f = cmd_showqueue_parsed,
7532         .data = NULL,
7533         .help_str = "show rxq|txq info <port_id> <queue_id>",
7534         .tokens = {
7535                 (void *)&cmd_showqueue_show,
7536                 (void *)&cmd_showqueue_type,
7537                 (void *)&cmd_showqueue_what,
7538                 (void *)&cmd_showqueue_portnum,
7539                 (void *)&cmd_showqueue_queuenum,
7540                 NULL,
7541         },
7542 };
7543
7544 /* show/clear fwd engine statistics */
7545 struct fwd_result {
7546         cmdline_fixed_string_t action;
7547         cmdline_fixed_string_t fwd;
7548         cmdline_fixed_string_t stats;
7549         cmdline_fixed_string_t all;
7550 };
7551
7552 cmdline_parse_token_string_t cmd_fwd_action =
7553         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7554 cmdline_parse_token_string_t cmd_fwd_fwd =
7555         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7556 cmdline_parse_token_string_t cmd_fwd_stats =
7557         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7558 cmdline_parse_token_string_t cmd_fwd_all =
7559         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7560
7561 static void
7562 cmd_showfwdall_parsed(void *parsed_result,
7563                       __rte_unused struct cmdline *cl,
7564                       __rte_unused void *data)
7565 {
7566         struct fwd_result *res = parsed_result;
7567
7568         if (!strcmp(res->action, "show"))
7569                 fwd_stats_display();
7570         else
7571                 fwd_stats_reset();
7572 }
7573
7574 static cmdline_parse_inst_t cmd_showfwdall = {
7575         .f = cmd_showfwdall_parsed,
7576         .data = NULL,
7577         .help_str = "show|clear fwd stats all",
7578         .tokens = {
7579                 (void *)&cmd_fwd_action,
7580                 (void *)&cmd_fwd_fwd,
7581                 (void *)&cmd_fwd_stats,
7582                 (void *)&cmd_fwd_all,
7583                 NULL,
7584         },
7585 };
7586
7587 /* *** READ PORT REGISTER *** */
7588 struct cmd_read_reg_result {
7589         cmdline_fixed_string_t read;
7590         cmdline_fixed_string_t reg;
7591         portid_t port_id;
7592         uint32_t reg_off;
7593 };
7594
7595 static void
7596 cmd_read_reg_parsed(void *parsed_result,
7597                     __attribute__((unused)) struct cmdline *cl,
7598                     __attribute__((unused)) void *data)
7599 {
7600         struct cmd_read_reg_result *res = parsed_result;
7601         port_reg_display(res->port_id, res->reg_off);
7602 }
7603
7604 cmdline_parse_token_string_t cmd_read_reg_read =
7605         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7606 cmdline_parse_token_string_t cmd_read_reg_reg =
7607         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7608 cmdline_parse_token_num_t cmd_read_reg_port_id =
7609         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7610 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7611         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7612
7613 cmdline_parse_inst_t cmd_read_reg = {
7614         .f = cmd_read_reg_parsed,
7615         .data = NULL,
7616         .help_str = "read reg <port_id> <reg_off>",
7617         .tokens = {
7618                 (void *)&cmd_read_reg_read,
7619                 (void *)&cmd_read_reg_reg,
7620                 (void *)&cmd_read_reg_port_id,
7621                 (void *)&cmd_read_reg_reg_off,
7622                 NULL,
7623         },
7624 };
7625
7626 /* *** READ PORT REGISTER BIT FIELD *** */
7627 struct cmd_read_reg_bit_field_result {
7628         cmdline_fixed_string_t read;
7629         cmdline_fixed_string_t regfield;
7630         portid_t port_id;
7631         uint32_t reg_off;
7632         uint8_t bit1_pos;
7633         uint8_t bit2_pos;
7634 };
7635
7636 static void
7637 cmd_read_reg_bit_field_parsed(void *parsed_result,
7638                               __attribute__((unused)) struct cmdline *cl,
7639                               __attribute__((unused)) void *data)
7640 {
7641         struct cmd_read_reg_bit_field_result *res = parsed_result;
7642         port_reg_bit_field_display(res->port_id, res->reg_off,
7643                                    res->bit1_pos, res->bit2_pos);
7644 }
7645
7646 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7647         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7648                                  "read");
7649 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7650         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7651                                  regfield, "regfield");
7652 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7653         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7654                               UINT16);
7655 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7656         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7657                               UINT32);
7658 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7659         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7660                               UINT8);
7661 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7662         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7663                               UINT8);
7664
7665 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7666         .f = cmd_read_reg_bit_field_parsed,
7667         .data = NULL,
7668         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7669         "Read register bit field between bit_x and bit_y included",
7670         .tokens = {
7671                 (void *)&cmd_read_reg_bit_field_read,
7672                 (void *)&cmd_read_reg_bit_field_regfield,
7673                 (void *)&cmd_read_reg_bit_field_port_id,
7674                 (void *)&cmd_read_reg_bit_field_reg_off,
7675                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7676                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7677                 NULL,
7678         },
7679 };
7680
7681 /* *** READ PORT REGISTER BIT *** */
7682 struct cmd_read_reg_bit_result {
7683         cmdline_fixed_string_t read;
7684         cmdline_fixed_string_t regbit;
7685         portid_t port_id;
7686         uint32_t reg_off;
7687         uint8_t bit_pos;
7688 };
7689
7690 static void
7691 cmd_read_reg_bit_parsed(void *parsed_result,
7692                         __attribute__((unused)) struct cmdline *cl,
7693                         __attribute__((unused)) void *data)
7694 {
7695         struct cmd_read_reg_bit_result *res = parsed_result;
7696         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7697 }
7698
7699 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7700         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7701 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7702         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7703                                  regbit, "regbit");
7704 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7705         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7706 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7707         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7708 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7709         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7710
7711 cmdline_parse_inst_t cmd_read_reg_bit = {
7712         .f = cmd_read_reg_bit_parsed,
7713         .data = NULL,
7714         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7715         .tokens = {
7716                 (void *)&cmd_read_reg_bit_read,
7717                 (void *)&cmd_read_reg_bit_regbit,
7718                 (void *)&cmd_read_reg_bit_port_id,
7719                 (void *)&cmd_read_reg_bit_reg_off,
7720                 (void *)&cmd_read_reg_bit_bit_pos,
7721                 NULL,
7722         },
7723 };
7724
7725 /* *** WRITE PORT REGISTER *** */
7726 struct cmd_write_reg_result {
7727         cmdline_fixed_string_t write;
7728         cmdline_fixed_string_t reg;
7729         portid_t port_id;
7730         uint32_t reg_off;
7731         uint32_t value;
7732 };
7733
7734 static void
7735 cmd_write_reg_parsed(void *parsed_result,
7736                      __attribute__((unused)) struct cmdline *cl,
7737                      __attribute__((unused)) void *data)
7738 {
7739         struct cmd_write_reg_result *res = parsed_result;
7740         port_reg_set(res->port_id, res->reg_off, res->value);
7741 }
7742
7743 cmdline_parse_token_string_t cmd_write_reg_write =
7744         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7745 cmdline_parse_token_string_t cmd_write_reg_reg =
7746         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7747 cmdline_parse_token_num_t cmd_write_reg_port_id =
7748         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7749 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7750         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7751 cmdline_parse_token_num_t cmd_write_reg_value =
7752         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7753
7754 cmdline_parse_inst_t cmd_write_reg = {
7755         .f = cmd_write_reg_parsed,
7756         .data = NULL,
7757         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7758         .tokens = {
7759                 (void *)&cmd_write_reg_write,
7760                 (void *)&cmd_write_reg_reg,
7761                 (void *)&cmd_write_reg_port_id,
7762                 (void *)&cmd_write_reg_reg_off,
7763                 (void *)&cmd_write_reg_value,
7764                 NULL,
7765         },
7766 };
7767
7768 /* *** WRITE PORT REGISTER BIT FIELD *** */
7769 struct cmd_write_reg_bit_field_result {
7770         cmdline_fixed_string_t write;
7771         cmdline_fixed_string_t regfield;
7772         portid_t port_id;
7773         uint32_t reg_off;
7774         uint8_t bit1_pos;
7775         uint8_t bit2_pos;
7776         uint32_t value;
7777 };
7778
7779 static void
7780 cmd_write_reg_bit_field_parsed(void *parsed_result,
7781                                __attribute__((unused)) struct cmdline *cl,
7782                                __attribute__((unused)) void *data)
7783 {
7784         struct cmd_write_reg_bit_field_result *res = parsed_result;
7785         port_reg_bit_field_set(res->port_id, res->reg_off,
7786                           res->bit1_pos, res->bit2_pos, res->value);
7787 }
7788
7789 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7790         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7791                                  "write");
7792 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7793         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7794                                  regfield, "regfield");
7795 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7796         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7797                               UINT16);
7798 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7799         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7800                               UINT32);
7801 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7802         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7803                               UINT8);
7804 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7805         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7806                               UINT8);
7807 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7808         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7809                               UINT32);
7810
7811 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7812         .f = cmd_write_reg_bit_field_parsed,
7813         .data = NULL,
7814         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7815                 "<reg_value>: "
7816                 "Set register bit field between bit_x and bit_y included",
7817         .tokens = {
7818                 (void *)&cmd_write_reg_bit_field_write,
7819                 (void *)&cmd_write_reg_bit_field_regfield,
7820                 (void *)&cmd_write_reg_bit_field_port_id,
7821                 (void *)&cmd_write_reg_bit_field_reg_off,
7822                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7823                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7824                 (void *)&cmd_write_reg_bit_field_value,
7825                 NULL,
7826         },
7827 };
7828
7829 /* *** WRITE PORT REGISTER BIT *** */
7830 struct cmd_write_reg_bit_result {
7831         cmdline_fixed_string_t write;
7832         cmdline_fixed_string_t regbit;
7833         portid_t port_id;
7834         uint32_t reg_off;
7835         uint8_t bit_pos;
7836         uint8_t value;
7837 };
7838
7839 static void
7840 cmd_write_reg_bit_parsed(void *parsed_result,
7841                          __attribute__((unused)) struct cmdline *cl,
7842                          __attribute__((unused)) void *data)
7843 {
7844         struct cmd_write_reg_bit_result *res = parsed_result;
7845         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7846 }
7847
7848 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7849         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7850                                  "write");
7851 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7852         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7853                                  regbit, "regbit");
7854 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7855         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7856 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7857         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7858 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7859         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7860 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7861         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7862
7863 cmdline_parse_inst_t cmd_write_reg_bit = {
7864         .f = cmd_write_reg_bit_parsed,
7865         .data = NULL,
7866         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7867                 "0 <= bit_x <= 31",
7868         .tokens = {
7869                 (void *)&cmd_write_reg_bit_write,
7870                 (void *)&cmd_write_reg_bit_regbit,
7871                 (void *)&cmd_write_reg_bit_port_id,
7872                 (void *)&cmd_write_reg_bit_reg_off,
7873                 (void *)&cmd_write_reg_bit_bit_pos,
7874                 (void *)&cmd_write_reg_bit_value,
7875                 NULL,
7876         },
7877 };
7878
7879 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7880 struct cmd_read_rxd_txd_result {
7881         cmdline_fixed_string_t read;
7882         cmdline_fixed_string_t rxd_txd;
7883         portid_t port_id;
7884         uint16_t queue_id;
7885         uint16_t desc_id;
7886 };
7887
7888 static void
7889 cmd_read_rxd_txd_parsed(void *parsed_result,
7890                         __attribute__((unused)) struct cmdline *cl,
7891                         __attribute__((unused)) void *data)
7892 {
7893         struct cmd_read_rxd_txd_result *res = parsed_result;
7894
7895         if (!strcmp(res->rxd_txd, "rxd"))
7896                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7897         else if (!strcmp(res->rxd_txd, "txd"))
7898                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7899 }
7900
7901 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7902         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7903 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7904         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7905                                  "rxd#txd");
7906 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7907         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7908 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7909         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7910 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7911         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7912
7913 cmdline_parse_inst_t cmd_read_rxd_txd = {
7914         .f = cmd_read_rxd_txd_parsed,
7915         .data = NULL,
7916         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7917         .tokens = {
7918                 (void *)&cmd_read_rxd_txd_read,
7919                 (void *)&cmd_read_rxd_txd_rxd_txd,
7920                 (void *)&cmd_read_rxd_txd_port_id,
7921                 (void *)&cmd_read_rxd_txd_queue_id,
7922                 (void *)&cmd_read_rxd_txd_desc_id,
7923                 NULL,
7924         },
7925 };
7926
7927 /* *** QUIT *** */
7928 struct cmd_quit_result {
7929         cmdline_fixed_string_t quit;
7930 };
7931
7932 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7933                             struct cmdline *cl,
7934                             __attribute__((unused)) void *data)
7935 {
7936         cmdline_quit(cl);
7937 }
7938
7939 cmdline_parse_token_string_t cmd_quit_quit =
7940         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7941
7942 cmdline_parse_inst_t cmd_quit = {
7943         .f = cmd_quit_parsed,
7944         .data = NULL,
7945         .help_str = "quit: Exit application",
7946         .tokens = {
7947                 (void *)&cmd_quit_quit,
7948                 NULL,
7949         },
7950 };
7951
7952 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7953 struct cmd_mac_addr_result {
7954         cmdline_fixed_string_t mac_addr_cmd;
7955         cmdline_fixed_string_t what;
7956         uint16_t port_num;
7957         struct rte_ether_addr address;
7958 };
7959
7960 static void cmd_mac_addr_parsed(void *parsed_result,
7961                 __attribute__((unused)) struct cmdline *cl,
7962                 __attribute__((unused)) void *data)
7963 {
7964         struct cmd_mac_addr_result *res = parsed_result;
7965         int ret;
7966
7967         if (strcmp(res->what, "add") == 0)
7968                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7969         else if (strcmp(res->what, "set") == 0)
7970                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7971                                                        &res->address);
7972         else
7973                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7974
7975         /* check the return value and print it if is < 0 */
7976         if(ret < 0)
7977                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7978
7979 }
7980
7981 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7982         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7983                                 "mac_addr");
7984 cmdline_parse_token_string_t cmd_mac_addr_what =
7985         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7986                                 "add#remove#set");
7987 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7988                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7989                                         UINT16);
7990 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7991                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7992
7993 cmdline_parse_inst_t cmd_mac_addr = {
7994         .f = cmd_mac_addr_parsed,
7995         .data = (void *)0,
7996         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7997                         "Add/Remove/Set MAC address on port_id",
7998         .tokens = {
7999                 (void *)&cmd_mac_addr_cmd,
8000                 (void *)&cmd_mac_addr_what,
8001                 (void *)&cmd_mac_addr_portnum,
8002                 (void *)&cmd_mac_addr_addr,
8003                 NULL,
8004         },
8005 };
8006
8007 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8008 struct cmd_eth_peer_result {
8009         cmdline_fixed_string_t set;
8010         cmdline_fixed_string_t eth_peer;
8011         portid_t port_id;
8012         cmdline_fixed_string_t peer_addr;
8013 };
8014
8015 static void cmd_set_eth_peer_parsed(void *parsed_result,
8016                         __attribute__((unused)) struct cmdline *cl,
8017                         __attribute__((unused)) void *data)
8018 {
8019                 struct cmd_eth_peer_result *res = parsed_result;
8020
8021                 if (test_done == 0) {
8022                         printf("Please stop forwarding first\n");
8023                         return;
8024                 }
8025                 if (!strcmp(res->eth_peer, "eth-peer")) {
8026                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8027                         fwd_config_setup();
8028                 }
8029 }
8030 cmdline_parse_token_string_t cmd_eth_peer_set =
8031         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8032 cmdline_parse_token_string_t cmd_eth_peer =
8033         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8034 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8035         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8036 cmdline_parse_token_string_t cmd_eth_peer_addr =
8037         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8038
8039 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8040         .f = cmd_set_eth_peer_parsed,
8041         .data = NULL,
8042         .help_str = "set eth-peer <port_id> <peer_mac>",
8043         .tokens = {
8044                 (void *)&cmd_eth_peer_set,
8045                 (void *)&cmd_eth_peer,
8046                 (void *)&cmd_eth_peer_port_id,
8047                 (void *)&cmd_eth_peer_addr,
8048                 NULL,
8049         },
8050 };
8051
8052 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8053 struct cmd_set_qmap_result {
8054         cmdline_fixed_string_t set;
8055         cmdline_fixed_string_t qmap;
8056         cmdline_fixed_string_t what;
8057         portid_t port_id;
8058         uint16_t queue_id;
8059         uint8_t map_value;
8060 };
8061
8062 static void
8063 cmd_set_qmap_parsed(void *parsed_result,
8064                        __attribute__((unused)) struct cmdline *cl,
8065                        __attribute__((unused)) void *data)
8066 {
8067         struct cmd_set_qmap_result *res = parsed_result;
8068         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8069
8070         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8071 }
8072
8073 cmdline_parse_token_string_t cmd_setqmap_set =
8074         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8075                                  set, "set");
8076 cmdline_parse_token_string_t cmd_setqmap_qmap =
8077         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8078                                  qmap, "stat_qmap");
8079 cmdline_parse_token_string_t cmd_setqmap_what =
8080         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8081                                  what, "tx#rx");
8082 cmdline_parse_token_num_t cmd_setqmap_portid =
8083         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8084                               port_id, UINT16);
8085 cmdline_parse_token_num_t cmd_setqmap_queueid =
8086         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8087                               queue_id, UINT16);
8088 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8089         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8090                               map_value, UINT8);
8091
8092 cmdline_parse_inst_t cmd_set_qmap = {
8093         .f = cmd_set_qmap_parsed,
8094         .data = NULL,
8095         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8096                 "Set statistics mapping value on tx|rx queue_id of port_id",
8097         .tokens = {
8098                 (void *)&cmd_setqmap_set,
8099                 (void *)&cmd_setqmap_qmap,
8100                 (void *)&cmd_setqmap_what,
8101                 (void *)&cmd_setqmap_portid,
8102                 (void *)&cmd_setqmap_queueid,
8103                 (void *)&cmd_setqmap_mapvalue,
8104                 NULL,
8105         },
8106 };
8107
8108 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8109 struct cmd_set_xstats_hide_zero_result {
8110         cmdline_fixed_string_t keyword;
8111         cmdline_fixed_string_t name;
8112         cmdline_fixed_string_t on_off;
8113 };
8114
8115 static void
8116 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8117                         __attribute__((unused)) struct cmdline *cl,
8118                         __attribute__((unused)) void *data)
8119 {
8120         struct cmd_set_xstats_hide_zero_result *res;
8121         uint16_t on_off = 0;
8122
8123         res = parsed_result;
8124         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8125         set_xstats_hide_zero(on_off);
8126 }
8127
8128 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8129         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8130                                  keyword, "set");
8131 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8132         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8133                                  name, "xstats-hide-zero");
8134 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8135         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8136                                  on_off, "on#off");
8137
8138 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8139         .f = cmd_set_xstats_hide_zero_parsed,
8140         .data = NULL,
8141         .help_str = "set xstats-hide-zero on|off",
8142         .tokens = {
8143                 (void *)&cmd_set_xstats_hide_zero_keyword,
8144                 (void *)&cmd_set_xstats_hide_zero_name,
8145                 (void *)&cmd_set_xstats_hide_zero_on_off,
8146                 NULL,
8147         },
8148 };
8149
8150 /* *** CONFIGURE UNICAST HASH TABLE *** */
8151 struct cmd_set_uc_hash_table {
8152         cmdline_fixed_string_t set;
8153         cmdline_fixed_string_t port;
8154         portid_t port_id;
8155         cmdline_fixed_string_t what;
8156         struct rte_ether_addr address;
8157         cmdline_fixed_string_t mode;
8158 };
8159
8160 static void
8161 cmd_set_uc_hash_parsed(void *parsed_result,
8162                        __attribute__((unused)) struct cmdline *cl,
8163                        __attribute__((unused)) void *data)
8164 {
8165         int ret=0;
8166         struct cmd_set_uc_hash_table *res = parsed_result;
8167
8168         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8169
8170         if (strcmp(res->what, "uta") == 0)
8171                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8172                                                 &res->address,(uint8_t)is_on);
8173         if (ret < 0)
8174                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8175
8176 }
8177
8178 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8179         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8180                                  set, "set");
8181 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8182         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8183                                  port, "port");
8184 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8185         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8186                               port_id, UINT16);
8187 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8188         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8189                                  what, "uta");
8190 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8191         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8192                                 address);
8193 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8194         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8195                                  mode, "on#off");
8196
8197 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8198         .f = cmd_set_uc_hash_parsed,
8199         .data = NULL,
8200         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8201         .tokens = {
8202                 (void *)&cmd_set_uc_hash_set,
8203                 (void *)&cmd_set_uc_hash_port,
8204                 (void *)&cmd_set_uc_hash_portid,
8205                 (void *)&cmd_set_uc_hash_what,
8206                 (void *)&cmd_set_uc_hash_mac,
8207                 (void *)&cmd_set_uc_hash_mode,
8208                 NULL,
8209         },
8210 };
8211
8212 struct cmd_set_uc_all_hash_table {
8213         cmdline_fixed_string_t set;
8214         cmdline_fixed_string_t port;
8215         portid_t port_id;
8216         cmdline_fixed_string_t what;
8217         cmdline_fixed_string_t value;
8218         cmdline_fixed_string_t mode;
8219 };
8220
8221 static void
8222 cmd_set_uc_all_hash_parsed(void *parsed_result,
8223                        __attribute__((unused)) struct cmdline *cl,
8224                        __attribute__((unused)) void *data)
8225 {
8226         int ret=0;
8227         struct cmd_set_uc_all_hash_table *res = parsed_result;
8228
8229         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8230
8231         if ((strcmp(res->what, "uta") == 0) &&
8232                 (strcmp(res->value, "all") == 0))
8233                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8234         if (ret < 0)
8235                 printf("bad unicast hash table parameter,"
8236                         "return code = %d \n", ret);
8237 }
8238
8239 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8240         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8241                                  set, "set");
8242 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8243         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8244                                  port, "port");
8245 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8246         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8247                               port_id, UINT16);
8248 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8249         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8250                                  what, "uta");
8251 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8252         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8253                                 value,"all");
8254 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8255         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8256                                  mode, "on#off");
8257
8258 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8259         .f = cmd_set_uc_all_hash_parsed,
8260         .data = NULL,
8261         .help_str = "set port <port_id> uta all on|off",
8262         .tokens = {
8263                 (void *)&cmd_set_uc_all_hash_set,
8264                 (void *)&cmd_set_uc_all_hash_port,
8265                 (void *)&cmd_set_uc_all_hash_portid,
8266                 (void *)&cmd_set_uc_all_hash_what,
8267                 (void *)&cmd_set_uc_all_hash_value,
8268                 (void *)&cmd_set_uc_all_hash_mode,
8269                 NULL,
8270         },
8271 };
8272
8273 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8274 struct cmd_set_vf_macvlan_filter {
8275         cmdline_fixed_string_t set;
8276         cmdline_fixed_string_t port;
8277         portid_t port_id;
8278         cmdline_fixed_string_t vf;
8279         uint8_t vf_id;
8280         struct rte_ether_addr address;
8281         cmdline_fixed_string_t filter_type;
8282         cmdline_fixed_string_t mode;
8283 };
8284
8285 static void
8286 cmd_set_vf_macvlan_parsed(void *parsed_result,
8287                        __attribute__((unused)) struct cmdline *cl,
8288                        __attribute__((unused)) void *data)
8289 {
8290         int is_on, ret = 0;
8291         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8292         struct rte_eth_mac_filter filter;
8293
8294         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8295
8296         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8297
8298         /* set VF MAC filter */
8299         filter.is_vf = 1;
8300
8301         /* set VF ID */
8302         filter.dst_id = res->vf_id;
8303
8304         if (!strcmp(res->filter_type, "exact-mac"))
8305                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8306         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8307                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8308         else if (!strcmp(res->filter_type, "hashmac"))
8309                 filter.filter_type = RTE_MAC_HASH_MATCH;
8310         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8311                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8312
8313         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8314
8315         if (is_on)
8316                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8317                                         RTE_ETH_FILTER_MACVLAN,
8318                                         RTE_ETH_FILTER_ADD,
8319                                          &filter);
8320         else
8321                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8322                                         RTE_ETH_FILTER_MACVLAN,
8323                                         RTE_ETH_FILTER_DELETE,
8324                                         &filter);
8325
8326         if (ret < 0)
8327                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8328
8329 }
8330
8331 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8332         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8333                                  set, "set");
8334 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8335         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8336                                  port, "port");
8337 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8338         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8339                               port_id, UINT16);
8340 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8341         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8342                                  vf, "vf");
8343 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8344         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8345                                 vf_id, UINT8);
8346 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8347         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8348                                 address);
8349 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8350         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8351                                 filter_type, "exact-mac#exact-mac-vlan"
8352                                 "#hashmac#hashmac-vlan");
8353 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8354         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8355                                  mode, "on#off");
8356
8357 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8358         .f = cmd_set_vf_macvlan_parsed,
8359         .data = NULL,
8360         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8361                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8362                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8363                 "hash match rule: hash match of MAC and exact match of VLAN",
8364         .tokens = {
8365                 (void *)&cmd_set_vf_macvlan_set,
8366                 (void *)&cmd_set_vf_macvlan_port,
8367                 (void *)&cmd_set_vf_macvlan_portid,
8368                 (void *)&cmd_set_vf_macvlan_vf,
8369                 (void *)&cmd_set_vf_macvlan_vf_id,
8370                 (void *)&cmd_set_vf_macvlan_mac,
8371                 (void *)&cmd_set_vf_macvlan_filter_type,
8372                 (void *)&cmd_set_vf_macvlan_mode,
8373                 NULL,
8374         },
8375 };
8376
8377 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8378 struct cmd_set_vf_traffic {
8379         cmdline_fixed_string_t set;
8380         cmdline_fixed_string_t port;
8381         portid_t port_id;
8382         cmdline_fixed_string_t vf;
8383         uint8_t vf_id;
8384         cmdline_fixed_string_t what;
8385         cmdline_fixed_string_t mode;
8386 };
8387
8388 static void
8389 cmd_set_vf_traffic_parsed(void *parsed_result,
8390                        __attribute__((unused)) struct cmdline *cl,
8391                        __attribute__((unused)) void *data)
8392 {
8393         struct cmd_set_vf_traffic *res = parsed_result;
8394         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8395         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8396
8397         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8398 }
8399
8400 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8401         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8402                                  set, "set");
8403 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8404         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8405                                  port, "port");
8406 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8407         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8408                               port_id, UINT16);
8409 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8410         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8411                                  vf, "vf");
8412 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8413         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8414                               vf_id, UINT8);
8415 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8416         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8417                                  what, "tx#rx");
8418 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8419         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8420                                  mode, "on#off");
8421
8422 cmdline_parse_inst_t cmd_set_vf_traffic = {
8423         .f = cmd_set_vf_traffic_parsed,
8424         .data = NULL,
8425         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8426         .tokens = {
8427                 (void *)&cmd_setvf_traffic_set,
8428                 (void *)&cmd_setvf_traffic_port,
8429                 (void *)&cmd_setvf_traffic_portid,
8430                 (void *)&cmd_setvf_traffic_vf,
8431                 (void *)&cmd_setvf_traffic_vfid,
8432                 (void *)&cmd_setvf_traffic_what,
8433                 (void *)&cmd_setvf_traffic_mode,
8434                 NULL,
8435         },
8436 };
8437
8438 /* *** CONFIGURE VF RECEIVE MODE *** */
8439 struct cmd_set_vf_rxmode {
8440         cmdline_fixed_string_t set;
8441         cmdline_fixed_string_t port;
8442         portid_t port_id;
8443         cmdline_fixed_string_t vf;
8444         uint8_t vf_id;
8445         cmdline_fixed_string_t what;
8446         cmdline_fixed_string_t mode;
8447         cmdline_fixed_string_t on;
8448 };
8449
8450 static void
8451 cmd_set_vf_rxmode_parsed(void *parsed_result,
8452                        __attribute__((unused)) struct cmdline *cl,
8453                        __attribute__((unused)) void *data)
8454 {
8455         int ret = -ENOTSUP;
8456         uint16_t vf_rxmode = 0;
8457         struct cmd_set_vf_rxmode *res = parsed_result;
8458
8459         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8460         if (!strcmp(res->what,"rxmode")) {
8461                 if (!strcmp(res->mode, "AUPE"))
8462                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8463                 else if (!strcmp(res->mode, "ROPE"))
8464                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8465                 else if (!strcmp(res->mode, "BAM"))
8466                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8467                 else if (!strncmp(res->mode, "MPE",3))
8468                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8469         }
8470
8471         RTE_SET_USED(is_on);
8472
8473 #ifdef RTE_LIBRTE_IXGBE_PMD
8474         if (ret == -ENOTSUP)
8475                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8476                                                   vf_rxmode, (uint8_t)is_on);
8477 #endif
8478 #ifdef RTE_LIBRTE_BNXT_PMD
8479         if (ret == -ENOTSUP)
8480                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8481                                                  vf_rxmode, (uint8_t)is_on);
8482 #endif
8483         if (ret < 0)
8484                 printf("bad VF receive mode parameter, return code = %d \n",
8485                 ret);
8486 }
8487
8488 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8489         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8490                                  set, "set");
8491 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8492         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8493                                  port, "port");
8494 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8495         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8496                               port_id, UINT16);
8497 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8498         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8499                                  vf, "vf");
8500 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8501         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8502                               vf_id, UINT8);
8503 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8504         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8505                                  what, "rxmode");
8506 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8507         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8508                                  mode, "AUPE#ROPE#BAM#MPE");
8509 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8510         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8511                                  on, "on#off");
8512
8513 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8514         .f = cmd_set_vf_rxmode_parsed,
8515         .data = NULL,
8516         .help_str = "set port <port_id> vf <vf_id> rxmode "
8517                 "AUPE|ROPE|BAM|MPE on|off",
8518         .tokens = {
8519                 (void *)&cmd_set_vf_rxmode_set,
8520                 (void *)&cmd_set_vf_rxmode_port,
8521                 (void *)&cmd_set_vf_rxmode_portid,
8522                 (void *)&cmd_set_vf_rxmode_vf,
8523                 (void *)&cmd_set_vf_rxmode_vfid,
8524                 (void *)&cmd_set_vf_rxmode_what,
8525                 (void *)&cmd_set_vf_rxmode_mode,
8526                 (void *)&cmd_set_vf_rxmode_on,
8527                 NULL,
8528         },
8529 };
8530
8531 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8532 struct cmd_vf_mac_addr_result {
8533         cmdline_fixed_string_t mac_addr_cmd;
8534         cmdline_fixed_string_t what;
8535         cmdline_fixed_string_t port;
8536         uint16_t port_num;
8537         cmdline_fixed_string_t vf;
8538         uint8_t vf_num;
8539         struct rte_ether_addr address;
8540 };
8541
8542 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8543                 __attribute__((unused)) struct cmdline *cl,
8544                 __attribute__((unused)) void *data)
8545 {
8546         struct cmd_vf_mac_addr_result *res = parsed_result;
8547         int ret = -ENOTSUP;
8548
8549         if (strcmp(res->what, "add") != 0)
8550                 return;
8551
8552 #ifdef RTE_LIBRTE_I40E_PMD
8553         if (ret == -ENOTSUP)
8554                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8555                                                    &res->address);
8556 #endif
8557 #ifdef RTE_LIBRTE_BNXT_PMD
8558         if (ret == -ENOTSUP)
8559                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8560                                                 res->vf_num);
8561 #endif
8562
8563         if(ret < 0)
8564                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8565
8566 }
8567
8568 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8569         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8570                                 mac_addr_cmd,"mac_addr");
8571 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8572         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8573                                 what,"add");
8574 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8575         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8576                                 port,"port");
8577 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8578         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8579                                 port_num, UINT16);
8580 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8581         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8582                                 vf,"vf");
8583 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8584         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8585                                 vf_num, UINT8);
8586 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8587         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8588                                 address);
8589
8590 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8591         .f = cmd_vf_mac_addr_parsed,
8592         .data = (void *)0,
8593         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8594                 "Add MAC address filtering for a VF on port_id",
8595         .tokens = {
8596                 (void *)&cmd_vf_mac_addr_cmd,
8597                 (void *)&cmd_vf_mac_addr_what,
8598                 (void *)&cmd_vf_mac_addr_port,
8599                 (void *)&cmd_vf_mac_addr_portnum,
8600                 (void *)&cmd_vf_mac_addr_vf,
8601                 (void *)&cmd_vf_mac_addr_vfnum,
8602                 (void *)&cmd_vf_mac_addr_addr,
8603                 NULL,
8604         },
8605 };
8606
8607 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8608 struct cmd_vf_rx_vlan_filter {
8609         cmdline_fixed_string_t rx_vlan;
8610         cmdline_fixed_string_t what;
8611         uint16_t vlan_id;
8612         cmdline_fixed_string_t port;
8613         portid_t port_id;
8614         cmdline_fixed_string_t vf;
8615         uint64_t vf_mask;
8616 };
8617
8618 static void
8619 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8620                           __attribute__((unused)) struct cmdline *cl,
8621                           __attribute__((unused)) void *data)
8622 {
8623         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8624         int ret = -ENOTSUP;
8625
8626         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8627
8628 #ifdef RTE_LIBRTE_IXGBE_PMD
8629         if (ret == -ENOTSUP)
8630                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8631                                 res->vlan_id, res->vf_mask, is_add);
8632 #endif
8633 #ifdef RTE_LIBRTE_I40E_PMD
8634         if (ret == -ENOTSUP)
8635                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8636                                 res->vlan_id, res->vf_mask, is_add);
8637 #endif
8638 #ifdef RTE_LIBRTE_BNXT_PMD
8639         if (ret == -ENOTSUP)
8640                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8641                                 res->vlan_id, res->vf_mask, is_add);
8642 #endif
8643
8644         switch (ret) {
8645         case 0:
8646                 break;
8647         case -EINVAL:
8648                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8649                                 res->vlan_id, res->vf_mask);
8650                 break;
8651         case -ENODEV:
8652                 printf("invalid port_id %d\n", res->port_id);
8653                 break;
8654         case -ENOTSUP:
8655                 printf("function not implemented or supported\n");
8656                 break;
8657         default:
8658                 printf("programming error: (%s)\n", strerror(-ret));
8659         }
8660 }
8661
8662 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8663         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8664                                  rx_vlan, "rx_vlan");
8665 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8666         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8667                                  what, "add#rm");
8668 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8669         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8670                               vlan_id, UINT16);
8671 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8672         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8673                                  port, "port");
8674 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8675         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8676                               port_id, UINT16);
8677 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8678         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8679                                  vf, "vf");
8680 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8681         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8682                               vf_mask, UINT64);
8683
8684 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8685         .f = cmd_vf_rx_vlan_filter_parsed,
8686         .data = NULL,
8687         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8688                 "(vf_mask = hexadecimal VF mask)",
8689         .tokens = {
8690                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8691                 (void *)&cmd_vf_rx_vlan_filter_what,
8692                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8693                 (void *)&cmd_vf_rx_vlan_filter_port,
8694                 (void *)&cmd_vf_rx_vlan_filter_portid,
8695                 (void *)&cmd_vf_rx_vlan_filter_vf,
8696                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8697                 NULL,
8698         },
8699 };
8700
8701 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8702 struct cmd_queue_rate_limit_result {
8703         cmdline_fixed_string_t set;
8704         cmdline_fixed_string_t port;
8705         uint16_t port_num;
8706         cmdline_fixed_string_t queue;
8707         uint8_t queue_num;
8708         cmdline_fixed_string_t rate;
8709         uint16_t rate_num;
8710 };
8711
8712 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8713                 __attribute__((unused)) struct cmdline *cl,
8714                 __attribute__((unused)) void *data)
8715 {
8716         struct cmd_queue_rate_limit_result *res = parsed_result;
8717         int ret = 0;
8718
8719         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8720                 && (strcmp(res->queue, "queue") == 0)
8721                 && (strcmp(res->rate, "rate") == 0))
8722                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8723                                         res->rate_num);
8724         if (ret < 0)
8725                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8726
8727 }
8728
8729 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8730         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8731                                 set, "set");
8732 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8733         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8734                                 port, "port");
8735 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8736         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8737                                 port_num, UINT16);
8738 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8739         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8740                                 queue, "queue");
8741 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8742         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8743                                 queue_num, UINT8);
8744 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8745         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8746                                 rate, "rate");
8747 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8748         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8749                                 rate_num, UINT16);
8750
8751 cmdline_parse_inst_t cmd_queue_rate_limit = {
8752         .f = cmd_queue_rate_limit_parsed,
8753         .data = (void *)0,
8754         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8755                 "Set rate limit for a queue on port_id",
8756         .tokens = {
8757                 (void *)&cmd_queue_rate_limit_set,
8758                 (void *)&cmd_queue_rate_limit_port,
8759                 (void *)&cmd_queue_rate_limit_portnum,
8760                 (void *)&cmd_queue_rate_limit_queue,
8761                 (void *)&cmd_queue_rate_limit_queuenum,
8762                 (void *)&cmd_queue_rate_limit_rate,
8763                 (void *)&cmd_queue_rate_limit_ratenum,
8764                 NULL,
8765         },
8766 };
8767
8768 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8769 struct cmd_vf_rate_limit_result {
8770         cmdline_fixed_string_t set;
8771         cmdline_fixed_string_t port;
8772         uint16_t port_num;
8773         cmdline_fixed_string_t vf;
8774         uint8_t vf_num;
8775         cmdline_fixed_string_t rate;
8776         uint16_t rate_num;
8777         cmdline_fixed_string_t q_msk;
8778         uint64_t q_msk_val;
8779 };
8780
8781 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8782                 __attribute__((unused)) struct cmdline *cl,
8783                 __attribute__((unused)) void *data)
8784 {
8785         struct cmd_vf_rate_limit_result *res = parsed_result;
8786         int ret = 0;
8787
8788         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8789                 && (strcmp(res->vf, "vf") == 0)
8790                 && (strcmp(res->rate, "rate") == 0)
8791                 && (strcmp(res->q_msk, "queue_mask") == 0))
8792                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8793                                         res->rate_num, res->q_msk_val);
8794         if (ret < 0)
8795                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8796
8797 }
8798
8799 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8800         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8801                                 set, "set");
8802 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8803         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8804                                 port, "port");
8805 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8806         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8807                                 port_num, UINT16);
8808 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8809         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8810                                 vf, "vf");
8811 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8812         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8813                                 vf_num, UINT8);
8814 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8815         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8816                                 rate, "rate");
8817 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8818         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8819                                 rate_num, UINT16);
8820 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8821         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8822                                 q_msk, "queue_mask");
8823 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8824         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8825                                 q_msk_val, UINT64);
8826
8827 cmdline_parse_inst_t cmd_vf_rate_limit = {
8828         .f = cmd_vf_rate_limit_parsed,
8829         .data = (void *)0,
8830         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8831                 "queue_mask <queue_mask_value>: "
8832                 "Set rate limit for queues of VF on port_id",
8833         .tokens = {
8834                 (void *)&cmd_vf_rate_limit_set,
8835                 (void *)&cmd_vf_rate_limit_port,
8836                 (void *)&cmd_vf_rate_limit_portnum,
8837                 (void *)&cmd_vf_rate_limit_vf,
8838                 (void *)&cmd_vf_rate_limit_vfnum,
8839                 (void *)&cmd_vf_rate_limit_rate,
8840                 (void *)&cmd_vf_rate_limit_ratenum,
8841                 (void *)&cmd_vf_rate_limit_q_msk,
8842                 (void *)&cmd_vf_rate_limit_q_msk_val,
8843                 NULL,
8844         },
8845 };
8846
8847 /* *** ADD TUNNEL FILTER OF A PORT *** */
8848 struct cmd_tunnel_filter_result {
8849         cmdline_fixed_string_t cmd;
8850         cmdline_fixed_string_t what;
8851         portid_t port_id;
8852         struct rte_ether_addr outer_mac;
8853         struct rte_ether_addr inner_mac;
8854         cmdline_ipaddr_t ip_value;
8855         uint16_t inner_vlan;
8856         cmdline_fixed_string_t tunnel_type;
8857         cmdline_fixed_string_t filter_type;
8858         uint32_t tenant_id;
8859         uint16_t queue_num;
8860 };
8861
8862 static void
8863 cmd_tunnel_filter_parsed(void *parsed_result,
8864                           __attribute__((unused)) struct cmdline *cl,
8865                           __attribute__((unused)) void *data)
8866 {
8867         struct cmd_tunnel_filter_result *res = parsed_result;
8868         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8869         int ret = 0;
8870
8871         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8872
8873         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8874         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8875         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8876
8877         if (res->ip_value.family == AF_INET) {
8878                 tunnel_filter_conf.ip_addr.ipv4_addr =
8879                         res->ip_value.addr.ipv4.s_addr;
8880                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8881         } else {
8882                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8883                         &(res->ip_value.addr.ipv6),
8884                         sizeof(struct in6_addr));
8885                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8886         }
8887
8888         if (!strcmp(res->filter_type, "imac-ivlan"))
8889                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8890         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8891                 tunnel_filter_conf.filter_type =
8892                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8893         else if (!strcmp(res->filter_type, "imac-tenid"))
8894                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8895         else if (!strcmp(res->filter_type, "imac"))
8896                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8897         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8898                 tunnel_filter_conf.filter_type =
8899                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8900         else if (!strcmp(res->filter_type, "oip"))
8901                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8902         else if (!strcmp(res->filter_type, "iip"))
8903                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8904         else {
8905                 printf("The filter type is not supported");
8906                 return;
8907         }
8908
8909         if (!strcmp(res->tunnel_type, "vxlan"))
8910                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8911         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8912                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8913         else if (!strcmp(res->tunnel_type, "nvgre"))
8914                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8915         else if (!strcmp(res->tunnel_type, "ipingre"))
8916                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8917         else {
8918                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8919                 return;
8920         }
8921
8922         tunnel_filter_conf.tenant_id = res->tenant_id;
8923         tunnel_filter_conf.queue_id = res->queue_num;
8924         if (!strcmp(res->what, "add"))
8925                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8926                                         RTE_ETH_FILTER_TUNNEL,
8927                                         RTE_ETH_FILTER_ADD,
8928                                         &tunnel_filter_conf);
8929         else
8930                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8931                                         RTE_ETH_FILTER_TUNNEL,
8932                                         RTE_ETH_FILTER_DELETE,
8933                                         &tunnel_filter_conf);
8934         if (ret < 0)
8935                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8936                                 strerror(-ret));
8937
8938 }
8939 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8940         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8941         cmd, "tunnel_filter");
8942 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8943         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8944         what, "add#rm");
8945 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8946         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8947         port_id, UINT16);
8948 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8949         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8950         outer_mac);
8951 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8952         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8953         inner_mac);
8954 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8955         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8956         inner_vlan, UINT16);
8957 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8958         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8959         ip_value);
8960 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8961         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8962         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8963
8964 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8965         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8966         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8967                 "imac#omac-imac-tenid");
8968 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8969         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8970         tenant_id, UINT32);
8971 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8972         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8973         queue_num, UINT16);
8974
8975 cmdline_parse_inst_t cmd_tunnel_filter = {
8976         .f = cmd_tunnel_filter_parsed,
8977         .data = (void *)0,
8978         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8979                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8980                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8981                 "<queue_id>: Add/Rm tunnel filter of a port",
8982         .tokens = {
8983                 (void *)&cmd_tunnel_filter_cmd,
8984                 (void *)&cmd_tunnel_filter_what,
8985                 (void *)&cmd_tunnel_filter_port_id,
8986                 (void *)&cmd_tunnel_filter_outer_mac,
8987                 (void *)&cmd_tunnel_filter_inner_mac,
8988                 (void *)&cmd_tunnel_filter_ip_value,
8989                 (void *)&cmd_tunnel_filter_innner_vlan,
8990                 (void *)&cmd_tunnel_filter_tunnel_type,
8991                 (void *)&cmd_tunnel_filter_filter_type,
8992                 (void *)&cmd_tunnel_filter_tenant_id,
8993                 (void *)&cmd_tunnel_filter_queue_num,
8994                 NULL,
8995         },
8996 };
8997
8998 /* *** CONFIGURE TUNNEL UDP PORT *** */
8999 struct cmd_tunnel_udp_config {
9000         cmdline_fixed_string_t cmd;
9001         cmdline_fixed_string_t what;
9002         uint16_t udp_port;
9003         portid_t port_id;
9004 };
9005
9006 static void
9007 cmd_tunnel_udp_config_parsed(void *parsed_result,
9008                           __attribute__((unused)) struct cmdline *cl,
9009                           __attribute__((unused)) void *data)
9010 {
9011         struct cmd_tunnel_udp_config *res = parsed_result;
9012         struct rte_eth_udp_tunnel tunnel_udp;
9013         int ret;
9014
9015         tunnel_udp.udp_port = res->udp_port;
9016
9017         if (!strcmp(res->cmd, "rx_vxlan_port"))
9018                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9019
9020         if (!strcmp(res->what, "add"))
9021                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9022                                                       &tunnel_udp);
9023         else
9024                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9025                                                          &tunnel_udp);
9026
9027         if (ret < 0)
9028                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9029 }
9030
9031 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9032         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9033                                 cmd, "rx_vxlan_port");
9034 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9035         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9036                                 what, "add#rm");
9037 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9038         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9039                                 udp_port, UINT16);
9040 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9041         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9042                                 port_id, UINT16);
9043
9044 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9045         .f = cmd_tunnel_udp_config_parsed,
9046         .data = (void *)0,
9047         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9048                 "Add/Remove a tunneling UDP port filter",
9049         .tokens = {
9050                 (void *)&cmd_tunnel_udp_config_cmd,
9051                 (void *)&cmd_tunnel_udp_config_what,
9052                 (void *)&cmd_tunnel_udp_config_udp_port,
9053                 (void *)&cmd_tunnel_udp_config_port_id,
9054                 NULL,
9055         },
9056 };
9057
9058 struct cmd_config_tunnel_udp_port {
9059         cmdline_fixed_string_t port;
9060         cmdline_fixed_string_t config;
9061         portid_t port_id;
9062         cmdline_fixed_string_t udp_tunnel_port;
9063         cmdline_fixed_string_t action;
9064         cmdline_fixed_string_t tunnel_type;
9065         uint16_t udp_port;
9066 };
9067
9068 static void
9069 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9070                                __attribute__((unused)) struct cmdline *cl,
9071                                __attribute__((unused)) void *data)
9072 {
9073         struct cmd_config_tunnel_udp_port *res = parsed_result;
9074         struct rte_eth_udp_tunnel tunnel_udp;
9075         int ret = 0;
9076
9077         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9078                 return;
9079
9080         tunnel_udp.udp_port = res->udp_port;
9081
9082         if (!strcmp(res->tunnel_type, "vxlan")) {
9083                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9084         } else if (!strcmp(res->tunnel_type, "geneve")) {
9085                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9086         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9087                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9088         } else {
9089                 printf("Invalid tunnel type\n");
9090                 return;
9091         }
9092
9093         if (!strcmp(res->action, "add"))
9094                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9095                                                       &tunnel_udp);
9096         else
9097                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9098                                                          &tunnel_udp);
9099
9100         if (ret < 0)
9101                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9102 }
9103
9104 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9105         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9106                                  "port");
9107 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9108         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9109                                  "config");
9110 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9111         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9112                               UINT16);
9113 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9114         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9115                                  udp_tunnel_port,
9116                                  "udp_tunnel_port");
9117 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9118         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9119                                  "add#rm");
9120 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9121         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9122                                  "vxlan#geneve#vxlan-gpe");
9123 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9124         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9125                               UINT16);
9126
9127 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9128         .f = cmd_cfg_tunnel_udp_port_parsed,
9129         .data = NULL,
9130         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9131         .tokens = {
9132                 (void *)&cmd_config_tunnel_udp_port_port,
9133                 (void *)&cmd_config_tunnel_udp_port_config,
9134                 (void *)&cmd_config_tunnel_udp_port_port_id,
9135                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9136                 (void *)&cmd_config_tunnel_udp_port_action,
9137                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9138                 (void *)&cmd_config_tunnel_udp_port_value,
9139                 NULL,
9140         },
9141 };
9142
9143 /* *** GLOBAL CONFIG *** */
9144 struct cmd_global_config_result {
9145         cmdline_fixed_string_t cmd;
9146         portid_t port_id;
9147         cmdline_fixed_string_t cfg_type;
9148         uint8_t len;
9149 };
9150
9151 static void
9152 cmd_global_config_parsed(void *parsed_result,
9153                          __attribute__((unused)) struct cmdline *cl,
9154                          __attribute__((unused)) void *data)
9155 {
9156         struct cmd_global_config_result *res = parsed_result;
9157         struct rte_eth_global_cfg conf;
9158         int ret;
9159
9160         memset(&conf, 0, sizeof(conf));
9161         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9162         conf.cfg.gre_key_len = res->len;
9163         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9164                                       RTE_ETH_FILTER_SET, &conf);
9165         if (ret != 0)
9166                 printf("Global config error\n");
9167 }
9168
9169 cmdline_parse_token_string_t cmd_global_config_cmd =
9170         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9171                 "global_config");
9172 cmdline_parse_token_num_t cmd_global_config_port_id =
9173         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9174                                UINT16);
9175 cmdline_parse_token_string_t cmd_global_config_type =
9176         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9177                 cfg_type, "gre-key-len");
9178 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9179         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9180                 len, UINT8);
9181
9182 cmdline_parse_inst_t cmd_global_config = {
9183         .f = cmd_global_config_parsed,
9184         .data = (void *)NULL,
9185         .help_str = "global_config <port_id> gre-key-len <key_len>",
9186         .tokens = {
9187                 (void *)&cmd_global_config_cmd,
9188                 (void *)&cmd_global_config_port_id,
9189                 (void *)&cmd_global_config_type,
9190                 (void *)&cmd_global_config_gre_key_len,
9191                 NULL,
9192         },
9193 };
9194
9195 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9196 struct cmd_set_mirror_mask_result {
9197         cmdline_fixed_string_t set;
9198         cmdline_fixed_string_t port;
9199         portid_t port_id;
9200         cmdline_fixed_string_t mirror;
9201         uint8_t rule_id;
9202         cmdline_fixed_string_t what;
9203         cmdline_fixed_string_t value;
9204         cmdline_fixed_string_t dstpool;
9205         uint8_t dstpool_id;
9206         cmdline_fixed_string_t on;
9207 };
9208
9209 cmdline_parse_token_string_t cmd_mirror_mask_set =
9210         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9211                                 set, "set");
9212 cmdline_parse_token_string_t cmd_mirror_mask_port =
9213         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9214                                 port, "port");
9215 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9216         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9217                                 port_id, UINT16);
9218 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9219         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9220                                 mirror, "mirror-rule");
9221 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9222         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9223                                 rule_id, UINT8);
9224 cmdline_parse_token_string_t cmd_mirror_mask_what =
9225         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9226                                 what, "pool-mirror-up#pool-mirror-down"
9227                                       "#vlan-mirror");
9228 cmdline_parse_token_string_t cmd_mirror_mask_value =
9229         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9230                                 value, NULL);
9231 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9232         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9233                                 dstpool, "dst-pool");
9234 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9235         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9236                                 dstpool_id, UINT8);
9237 cmdline_parse_token_string_t cmd_mirror_mask_on =
9238         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9239                                 on, "on#off");
9240
9241 static void
9242 cmd_set_mirror_mask_parsed(void *parsed_result,
9243                        __attribute__((unused)) struct cmdline *cl,
9244                        __attribute__((unused)) void *data)
9245 {
9246         int ret,nb_item,i;
9247         struct cmd_set_mirror_mask_result *res = parsed_result;
9248         struct rte_eth_mirror_conf mr_conf;
9249
9250         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9251
9252         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9253
9254         mr_conf.dst_pool = res->dstpool_id;
9255
9256         if (!strcmp(res->what, "pool-mirror-up")) {
9257                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9258                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9259         } else if (!strcmp(res->what, "pool-mirror-down")) {
9260                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9261                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9262         } else if (!strcmp(res->what, "vlan-mirror")) {
9263                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9264                 nb_item = parse_item_list(res->value, "vlan",
9265                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9266                 if (nb_item <= 0)
9267                         return;
9268
9269                 for (i = 0; i < nb_item; i++) {
9270                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9271                                 printf("Invalid vlan_id: must be < 4096\n");
9272                                 return;
9273                         }
9274
9275                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9276                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9277                 }
9278         }
9279
9280         if (!strcmp(res->on, "on"))
9281                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9282                                                 res->rule_id, 1);
9283         else
9284                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9285                                                 res->rule_id, 0);
9286         if (ret < 0)
9287                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9288 }
9289
9290 cmdline_parse_inst_t cmd_set_mirror_mask = {
9291                 .f = cmd_set_mirror_mask_parsed,
9292                 .data = NULL,
9293                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9294                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9295                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9296                 .tokens = {
9297                         (void *)&cmd_mirror_mask_set,
9298                         (void *)&cmd_mirror_mask_port,
9299                         (void *)&cmd_mirror_mask_portid,
9300                         (void *)&cmd_mirror_mask_mirror,
9301                         (void *)&cmd_mirror_mask_ruleid,
9302                         (void *)&cmd_mirror_mask_what,
9303                         (void *)&cmd_mirror_mask_value,
9304                         (void *)&cmd_mirror_mask_dstpool,
9305                         (void *)&cmd_mirror_mask_poolid,
9306                         (void *)&cmd_mirror_mask_on,
9307                         NULL,
9308                 },
9309 };
9310
9311 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9312 struct cmd_set_mirror_link_result {
9313         cmdline_fixed_string_t set;
9314         cmdline_fixed_string_t port;
9315         portid_t port_id;
9316         cmdline_fixed_string_t mirror;
9317         uint8_t rule_id;
9318         cmdline_fixed_string_t what;
9319         cmdline_fixed_string_t dstpool;
9320         uint8_t dstpool_id;
9321         cmdline_fixed_string_t on;
9322 };
9323
9324 cmdline_parse_token_string_t cmd_mirror_link_set =
9325         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9326                                  set, "set");
9327 cmdline_parse_token_string_t cmd_mirror_link_port =
9328         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9329                                 port, "port");
9330 cmdline_parse_token_num_t cmd_mirror_link_portid =
9331         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9332                                 port_id, UINT16);
9333 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9334         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9335                                 mirror, "mirror-rule");
9336 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9337         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9338                             rule_id, UINT8);
9339 cmdline_parse_token_string_t cmd_mirror_link_what =
9340         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9341                                 what, "uplink-mirror#downlink-mirror");
9342 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9343         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9344                                 dstpool, "dst-pool");
9345 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9346         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9347                                 dstpool_id, UINT8);
9348 cmdline_parse_token_string_t cmd_mirror_link_on =
9349         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9350                                 on, "on#off");
9351
9352 static void
9353 cmd_set_mirror_link_parsed(void *parsed_result,
9354                        __attribute__((unused)) struct cmdline *cl,
9355                        __attribute__((unused)) void *data)
9356 {
9357         int ret;
9358         struct cmd_set_mirror_link_result *res = parsed_result;
9359         struct rte_eth_mirror_conf mr_conf;
9360
9361         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9362         if (!strcmp(res->what, "uplink-mirror"))
9363                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9364         else
9365                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9366
9367         mr_conf.dst_pool = res->dstpool_id;
9368
9369         if (!strcmp(res->on, "on"))
9370                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9371                                                 res->rule_id, 1);
9372         else
9373                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9374                                                 res->rule_id, 0);
9375
9376         /* check the return value and print it if is < 0 */
9377         if (ret < 0)
9378                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9379
9380 }
9381
9382 cmdline_parse_inst_t cmd_set_mirror_link = {
9383                 .f = cmd_set_mirror_link_parsed,
9384                 .data = NULL,
9385                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9386                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9387                 .tokens = {
9388                         (void *)&cmd_mirror_link_set,
9389                         (void *)&cmd_mirror_link_port,
9390                         (void *)&cmd_mirror_link_portid,
9391                         (void *)&cmd_mirror_link_mirror,
9392                         (void *)&cmd_mirror_link_ruleid,
9393                         (void *)&cmd_mirror_link_what,
9394                         (void *)&cmd_mirror_link_dstpool,
9395                         (void *)&cmd_mirror_link_poolid,
9396                         (void *)&cmd_mirror_link_on,
9397                         NULL,
9398                 },
9399 };
9400
9401 /* *** RESET VM MIRROR RULE *** */
9402 struct cmd_rm_mirror_rule_result {
9403         cmdline_fixed_string_t reset;
9404         cmdline_fixed_string_t port;
9405         portid_t port_id;
9406         cmdline_fixed_string_t mirror;
9407         uint8_t rule_id;
9408 };
9409
9410 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9411         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9412                                  reset, "reset");
9413 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9414         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9415                                 port, "port");
9416 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9417         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9418                                 port_id, UINT16);
9419 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9420         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9421                                 mirror, "mirror-rule");
9422 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9423         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9424                                 rule_id, UINT8);
9425
9426 static void
9427 cmd_reset_mirror_rule_parsed(void *parsed_result,
9428                        __attribute__((unused)) struct cmdline *cl,
9429                        __attribute__((unused)) void *data)
9430 {
9431         int ret;
9432         struct cmd_set_mirror_link_result *res = parsed_result;
9433         /* check rule_id */
9434         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9435         if(ret < 0)
9436                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9437 }
9438
9439 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9440                 .f = cmd_reset_mirror_rule_parsed,
9441                 .data = NULL,
9442                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9443                 .tokens = {
9444                         (void *)&cmd_rm_mirror_rule_reset,
9445                         (void *)&cmd_rm_mirror_rule_port,
9446                         (void *)&cmd_rm_mirror_rule_portid,
9447                         (void *)&cmd_rm_mirror_rule_mirror,
9448                         (void *)&cmd_rm_mirror_rule_ruleid,
9449                         NULL,
9450                 },
9451 };
9452
9453 /* ******************************************************************************** */
9454
9455 struct cmd_dump_result {
9456         cmdline_fixed_string_t dump;
9457 };
9458
9459 static void
9460 dump_struct_sizes(void)
9461 {
9462 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9463         DUMP_SIZE(struct rte_mbuf);
9464         DUMP_SIZE(struct rte_mempool);
9465         DUMP_SIZE(struct rte_ring);
9466 #undef DUMP_SIZE
9467 }
9468
9469 static void cmd_dump_parsed(void *parsed_result,
9470                             __attribute__((unused)) struct cmdline *cl,
9471                             __attribute__((unused)) void *data)
9472 {
9473         struct cmd_dump_result *res = parsed_result;
9474
9475         if (!strcmp(res->dump, "dump_physmem"))
9476                 rte_dump_physmem_layout(stdout);
9477         else if (!strcmp(res->dump, "dump_memzone"))
9478                 rte_memzone_dump(stdout);
9479         else if (!strcmp(res->dump, "dump_struct_sizes"))
9480                 dump_struct_sizes();
9481         else if (!strcmp(res->dump, "dump_ring"))
9482                 rte_ring_list_dump(stdout);
9483         else if (!strcmp(res->dump, "dump_mempool"))
9484                 rte_mempool_list_dump(stdout);
9485         else if (!strcmp(res->dump, "dump_devargs"))
9486                 rte_devargs_dump(stdout);
9487         else if (!strcmp(res->dump, "dump_log_types"))
9488                 rte_log_dump(stdout);
9489 }
9490
9491 cmdline_parse_token_string_t cmd_dump_dump =
9492         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9493                 "dump_physmem#"
9494                 "dump_memzone#"
9495                 "dump_struct_sizes#"
9496                 "dump_ring#"
9497                 "dump_mempool#"
9498                 "dump_devargs#"
9499                 "dump_log_types");
9500
9501 cmdline_parse_inst_t cmd_dump = {
9502         .f = cmd_dump_parsed,  /* function to call */
9503         .data = NULL,      /* 2nd arg of func */
9504         .help_str = "Dump status",
9505         .tokens = {        /* token list, NULL terminated */
9506                 (void *)&cmd_dump_dump,
9507                 NULL,
9508         },
9509 };
9510
9511 /* ******************************************************************************** */
9512
9513 struct cmd_dump_one_result {
9514         cmdline_fixed_string_t dump;
9515         cmdline_fixed_string_t name;
9516 };
9517
9518 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9519                                 __attribute__((unused)) void *data)
9520 {
9521         struct cmd_dump_one_result *res = parsed_result;
9522
9523         if (!strcmp(res->dump, "dump_ring")) {
9524                 struct rte_ring *r;
9525                 r = rte_ring_lookup(res->name);
9526                 if (r == NULL) {
9527                         cmdline_printf(cl, "Cannot find ring\n");
9528                         return;
9529                 }
9530                 rte_ring_dump(stdout, r);
9531         } else if (!strcmp(res->dump, "dump_mempool")) {
9532                 struct rte_mempool *mp;
9533                 mp = rte_mempool_lookup(res->name);
9534                 if (mp == NULL) {
9535                         cmdline_printf(cl, "Cannot find mempool\n");
9536                         return;
9537                 }
9538                 rte_mempool_dump(stdout, mp);
9539         }
9540 }
9541
9542 cmdline_parse_token_string_t cmd_dump_one_dump =
9543         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9544                                  "dump_ring#dump_mempool");
9545
9546 cmdline_parse_token_string_t cmd_dump_one_name =
9547         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9548
9549 cmdline_parse_inst_t cmd_dump_one = {
9550         .f = cmd_dump_one_parsed,  /* function to call */
9551         .data = NULL,      /* 2nd arg of func */
9552         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9553         .tokens = {        /* token list, NULL terminated */
9554                 (void *)&cmd_dump_one_dump,
9555                 (void *)&cmd_dump_one_name,
9556                 NULL,
9557         },
9558 };
9559
9560 /* *** Add/Del syn filter *** */
9561 struct cmd_syn_filter_result {
9562         cmdline_fixed_string_t filter;
9563         portid_t port_id;
9564         cmdline_fixed_string_t ops;
9565         cmdline_fixed_string_t priority;
9566         cmdline_fixed_string_t high;
9567         cmdline_fixed_string_t queue;
9568         uint16_t queue_id;
9569 };
9570
9571 static void
9572 cmd_syn_filter_parsed(void *parsed_result,
9573                         __attribute__((unused)) struct cmdline *cl,
9574                         __attribute__((unused)) void *data)
9575 {
9576         struct cmd_syn_filter_result *res = parsed_result;
9577         struct rte_eth_syn_filter syn_filter;
9578         int ret = 0;
9579
9580         ret = rte_eth_dev_filter_supported(res->port_id,
9581                                         RTE_ETH_FILTER_SYN);
9582         if (ret < 0) {
9583                 printf("syn filter is not supported on port %u.\n",
9584                                 res->port_id);
9585                 return;
9586         }
9587
9588         memset(&syn_filter, 0, sizeof(syn_filter));
9589
9590         if (!strcmp(res->ops, "add")) {
9591                 if (!strcmp(res->high, "high"))
9592                         syn_filter.hig_pri = 1;
9593                 else
9594                         syn_filter.hig_pri = 0;
9595
9596                 syn_filter.queue = res->queue_id;
9597                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9598                                                 RTE_ETH_FILTER_SYN,
9599                                                 RTE_ETH_FILTER_ADD,
9600                                                 &syn_filter);
9601         } else
9602                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9603                                                 RTE_ETH_FILTER_SYN,
9604                                                 RTE_ETH_FILTER_DELETE,
9605                                                 &syn_filter);
9606
9607         if (ret < 0)
9608                 printf("syn filter programming error: (%s)\n",
9609                                 strerror(-ret));
9610 }
9611
9612 cmdline_parse_token_string_t cmd_syn_filter_filter =
9613         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9614         filter, "syn_filter");
9615 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9616         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9617         port_id, UINT16);
9618 cmdline_parse_token_string_t cmd_syn_filter_ops =
9619         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9620         ops, "add#del");
9621 cmdline_parse_token_string_t cmd_syn_filter_priority =
9622         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9623                                 priority, "priority");
9624 cmdline_parse_token_string_t cmd_syn_filter_high =
9625         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9626                                 high, "high#low");
9627 cmdline_parse_token_string_t cmd_syn_filter_queue =
9628         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9629                                 queue, "queue");
9630 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9631         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9632                                 queue_id, UINT16);
9633
9634 cmdline_parse_inst_t cmd_syn_filter = {
9635         .f = cmd_syn_filter_parsed,
9636         .data = NULL,
9637         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9638                 "<queue_id>: Add/Delete syn filter",
9639         .tokens = {
9640                 (void *)&cmd_syn_filter_filter,
9641                 (void *)&cmd_syn_filter_port_id,
9642                 (void *)&cmd_syn_filter_ops,
9643                 (void *)&cmd_syn_filter_priority,
9644                 (void *)&cmd_syn_filter_high,
9645                 (void *)&cmd_syn_filter_queue,
9646                 (void *)&cmd_syn_filter_queue_id,
9647                 NULL,
9648         },
9649 };
9650
9651 /* *** queue region set *** */
9652 struct cmd_queue_region_result {
9653         cmdline_fixed_string_t set;
9654         cmdline_fixed_string_t port;
9655         portid_t port_id;
9656         cmdline_fixed_string_t cmd;
9657         cmdline_fixed_string_t region;
9658         uint8_t  region_id;
9659         cmdline_fixed_string_t queue_start_index;
9660         uint8_t  queue_id;
9661         cmdline_fixed_string_t queue_num;
9662         uint8_t  queue_num_value;
9663 };
9664
9665 static void
9666 cmd_queue_region_parsed(void *parsed_result,
9667                         __attribute__((unused)) struct cmdline *cl,
9668                         __attribute__((unused)) void *data)
9669 {
9670         struct cmd_queue_region_result *res = parsed_result;
9671         int ret = -ENOTSUP;
9672 #ifdef RTE_LIBRTE_I40E_PMD
9673         struct rte_pmd_i40e_queue_region_conf region_conf;
9674         enum rte_pmd_i40e_queue_region_op op_type;
9675 #endif
9676
9677         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9678                 return;
9679
9680 #ifdef RTE_LIBRTE_I40E_PMD
9681         memset(&region_conf, 0, sizeof(region_conf));
9682         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9683         region_conf.region_id = res->region_id;
9684         region_conf.queue_num = res->queue_num_value;
9685         region_conf.queue_start_index = res->queue_id;
9686
9687         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9688                                 op_type, &region_conf);
9689 #endif
9690
9691         switch (ret) {
9692         case 0:
9693                 break;
9694         case -ENOTSUP:
9695                 printf("function not implemented or supported\n");
9696                 break;
9697         default:
9698                 printf("queue region config error: (%s)\n", strerror(-ret));
9699         }
9700 }
9701
9702 cmdline_parse_token_string_t cmd_queue_region_set =
9703 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9704                 set, "set");
9705 cmdline_parse_token_string_t cmd_queue_region_port =
9706         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9707 cmdline_parse_token_num_t cmd_queue_region_port_id =
9708         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9709                                 port_id, UINT16);
9710 cmdline_parse_token_string_t cmd_queue_region_cmd =
9711         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9712                                  cmd, "queue-region");
9713 cmdline_parse_token_string_t cmd_queue_region_id =
9714         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9715                                 region, "region_id");
9716 cmdline_parse_token_num_t cmd_queue_region_index =
9717         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9718                                 region_id, UINT8);
9719 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9720         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9721                                 queue_start_index, "queue_start_index");
9722 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9723         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9724                                 queue_id, UINT8);
9725 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9726         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9727                                 queue_num, "queue_num");
9728 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9729         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9730                                 queue_num_value, UINT8);
9731
9732 cmdline_parse_inst_t cmd_queue_region = {
9733         .f = cmd_queue_region_parsed,
9734         .data = NULL,
9735         .help_str = "set port <port_id> queue-region region_id <value> "
9736                 "queue_start_index <value> queue_num <value>: Set a queue region",
9737         .tokens = {
9738                 (void *)&cmd_queue_region_set,
9739                 (void *)&cmd_queue_region_port,
9740                 (void *)&cmd_queue_region_port_id,
9741                 (void *)&cmd_queue_region_cmd,
9742                 (void *)&cmd_queue_region_id,
9743                 (void *)&cmd_queue_region_index,
9744                 (void *)&cmd_queue_region_queue_start_index,
9745                 (void *)&cmd_queue_region_queue_id,
9746                 (void *)&cmd_queue_region_queue_num,
9747                 (void *)&cmd_queue_region_queue_num_value,
9748                 NULL,
9749         },
9750 };
9751
9752 /* *** queue region and flowtype set *** */
9753 struct cmd_region_flowtype_result {
9754         cmdline_fixed_string_t set;
9755         cmdline_fixed_string_t port;
9756         portid_t port_id;
9757         cmdline_fixed_string_t cmd;
9758         cmdline_fixed_string_t region;
9759         uint8_t  region_id;
9760         cmdline_fixed_string_t flowtype;
9761         uint8_t  flowtype_id;
9762 };
9763
9764 static void
9765 cmd_region_flowtype_parsed(void *parsed_result,
9766                         __attribute__((unused)) struct cmdline *cl,
9767                         __attribute__((unused)) void *data)
9768 {
9769         struct cmd_region_flowtype_result *res = parsed_result;
9770         int ret = -ENOTSUP;
9771 #ifdef RTE_LIBRTE_I40E_PMD
9772         struct rte_pmd_i40e_queue_region_conf region_conf;
9773         enum rte_pmd_i40e_queue_region_op op_type;
9774 #endif
9775
9776         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9777                 return;
9778
9779 #ifdef RTE_LIBRTE_I40E_PMD
9780         memset(&region_conf, 0, sizeof(region_conf));
9781
9782         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9783         region_conf.region_id = res->region_id;
9784         region_conf.hw_flowtype = res->flowtype_id;
9785
9786         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9787                         op_type, &region_conf);
9788 #endif
9789
9790         switch (ret) {
9791         case 0:
9792                 break;
9793         case -ENOTSUP:
9794                 printf("function not implemented or supported\n");
9795                 break;
9796         default:
9797                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9798         }
9799 }
9800
9801 cmdline_parse_token_string_t cmd_region_flowtype_set =
9802 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9803                                 set, "set");
9804 cmdline_parse_token_string_t cmd_region_flowtype_port =
9805         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9806                                 port, "port");
9807 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9808         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9809                                 port_id, UINT16);
9810 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9811         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9812                                 cmd, "queue-region");
9813 cmdline_parse_token_string_t cmd_region_flowtype_index =
9814         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9815                                 region, "region_id");
9816 cmdline_parse_token_num_t cmd_region_flowtype_id =
9817         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9818                                 region_id, UINT8);
9819 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9820         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9821                                 flowtype, "flowtype");
9822 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9823         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9824                                 flowtype_id, UINT8);
9825 cmdline_parse_inst_t cmd_region_flowtype = {
9826         .f = cmd_region_flowtype_parsed,
9827         .data = NULL,
9828         .help_str = "set port <port_id> queue-region region_id <value> "
9829                 "flowtype <value>: Set a flowtype region index",
9830         .tokens = {
9831                 (void *)&cmd_region_flowtype_set,
9832                 (void *)&cmd_region_flowtype_port,
9833                 (void *)&cmd_region_flowtype_port_index,
9834                 (void *)&cmd_region_flowtype_cmd,
9835                 (void *)&cmd_region_flowtype_index,
9836                 (void *)&cmd_region_flowtype_id,
9837                 (void *)&cmd_region_flowtype_flow_index,
9838                 (void *)&cmd_region_flowtype_flow_id,
9839                 NULL,
9840         },
9841 };
9842
9843 /* *** User Priority (UP) to queue region (region_id) set *** */
9844 struct cmd_user_priority_region_result {
9845         cmdline_fixed_string_t set;
9846         cmdline_fixed_string_t port;
9847         portid_t port_id;
9848         cmdline_fixed_string_t cmd;
9849         cmdline_fixed_string_t user_priority;
9850         uint8_t  user_priority_id;
9851         cmdline_fixed_string_t region;
9852         uint8_t  region_id;
9853 };
9854
9855 static void
9856 cmd_user_priority_region_parsed(void *parsed_result,
9857                         __attribute__((unused)) struct cmdline *cl,
9858                         __attribute__((unused)) void *data)
9859 {
9860         struct cmd_user_priority_region_result *res = parsed_result;
9861         int ret = -ENOTSUP;
9862 #ifdef RTE_LIBRTE_I40E_PMD
9863         struct rte_pmd_i40e_queue_region_conf region_conf;
9864         enum rte_pmd_i40e_queue_region_op op_type;
9865 #endif
9866
9867         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9868                 return;
9869
9870 #ifdef RTE_LIBRTE_I40E_PMD
9871         memset(&region_conf, 0, sizeof(region_conf));
9872         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9873         region_conf.user_priority = res->user_priority_id;
9874         region_conf.region_id = res->region_id;
9875
9876         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9877                                 op_type, &region_conf);
9878 #endif
9879
9880         switch (ret) {
9881         case 0:
9882                 break;
9883         case -ENOTSUP:
9884                 printf("function not implemented or supported\n");
9885                 break;
9886         default:
9887                 printf("user_priority region config error: (%s)\n",
9888                                 strerror(-ret));
9889         }
9890 }
9891
9892 cmdline_parse_token_string_t cmd_user_priority_region_set =
9893         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9894                                 set, "set");
9895 cmdline_parse_token_string_t cmd_user_priority_region_port =
9896         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9897                                 port, "port");
9898 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9899         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9900                                 port_id, UINT16);
9901 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9902         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9903                                 cmd, "queue-region");
9904 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9905         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9906                                 user_priority, "UP");
9907 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9908         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9909                                 user_priority_id, UINT8);
9910 cmdline_parse_token_string_t cmd_user_priority_region_region =
9911         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9912                                 region, "region_id");
9913 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9914         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9915                                 region_id, UINT8);
9916
9917 cmdline_parse_inst_t cmd_user_priority_region = {
9918         .f = cmd_user_priority_region_parsed,
9919         .data = NULL,
9920         .help_str = "set port <port_id> queue-region UP <value> "
9921                 "region_id <value>: Set the mapping of User Priority (UP) "
9922                 "to queue region (region_id) ",
9923         .tokens = {
9924                 (void *)&cmd_user_priority_region_set,
9925                 (void *)&cmd_user_priority_region_port,
9926                 (void *)&cmd_user_priority_region_port_index,
9927                 (void *)&cmd_user_priority_region_cmd,
9928                 (void *)&cmd_user_priority_region_UP,
9929                 (void *)&cmd_user_priority_region_UP_id,
9930                 (void *)&cmd_user_priority_region_region,
9931                 (void *)&cmd_user_priority_region_region_id,
9932                 NULL,
9933         },
9934 };
9935
9936 /* *** flush all queue region related configuration *** */
9937 struct cmd_flush_queue_region_result {
9938         cmdline_fixed_string_t set;
9939         cmdline_fixed_string_t port;
9940         portid_t port_id;
9941         cmdline_fixed_string_t cmd;
9942         cmdline_fixed_string_t flush;
9943         cmdline_fixed_string_t what;
9944 };
9945
9946 static void
9947 cmd_flush_queue_region_parsed(void *parsed_result,
9948                         __attribute__((unused)) struct cmdline *cl,
9949                         __attribute__((unused)) void *data)
9950 {
9951         struct cmd_flush_queue_region_result *res = parsed_result;
9952         int ret = -ENOTSUP;
9953 #ifdef RTE_LIBRTE_I40E_PMD
9954         struct rte_pmd_i40e_queue_region_conf region_conf;
9955         enum rte_pmd_i40e_queue_region_op op_type;
9956 #endif
9957
9958         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9959                 return;
9960
9961 #ifdef RTE_LIBRTE_I40E_PMD
9962         memset(&region_conf, 0, sizeof(region_conf));
9963
9964         if (strcmp(res->what, "on") == 0)
9965                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9966         else
9967                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9968
9969         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9970                                 op_type, &region_conf);
9971 #endif
9972
9973         switch (ret) {
9974         case 0:
9975                 break;
9976         case -ENOTSUP:
9977                 printf("function not implemented or supported\n");
9978                 break;
9979         default:
9980                 printf("queue region config flush error: (%s)\n",
9981                                 strerror(-ret));
9982         }
9983 }
9984
9985 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9986         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9987                                 set, "set");
9988 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9989         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9990                                 port, "port");
9991 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9992         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9993                                 port_id, UINT16);
9994 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9995         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9996                                 cmd, "queue-region");
9997 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9998         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9999                                 flush, "flush");
10000 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10001         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10002                                 what, "on#off");
10003
10004 cmdline_parse_inst_t cmd_flush_queue_region = {
10005         .f = cmd_flush_queue_region_parsed,
10006         .data = NULL,
10007         .help_str = "set port <port_id> queue-region flush on|off"
10008                 ": flush all queue region related configuration",
10009         .tokens = {
10010                 (void *)&cmd_flush_queue_region_set,
10011                 (void *)&cmd_flush_queue_region_port,
10012                 (void *)&cmd_flush_queue_region_port_index,
10013                 (void *)&cmd_flush_queue_region_cmd,
10014                 (void *)&cmd_flush_queue_region_flush,
10015                 (void *)&cmd_flush_queue_region_what,
10016                 NULL,
10017         },
10018 };
10019
10020 /* *** get all queue region related configuration info *** */
10021 struct cmd_show_queue_region_info {
10022         cmdline_fixed_string_t show;
10023         cmdline_fixed_string_t port;
10024         portid_t port_id;
10025         cmdline_fixed_string_t cmd;
10026 };
10027
10028 static void
10029 cmd_show_queue_region_info_parsed(void *parsed_result,
10030                         __attribute__((unused)) struct cmdline *cl,
10031                         __attribute__((unused)) void *data)
10032 {
10033         struct cmd_show_queue_region_info *res = parsed_result;
10034         int ret = -ENOTSUP;
10035 #ifdef RTE_LIBRTE_I40E_PMD
10036         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10037         enum rte_pmd_i40e_queue_region_op op_type;
10038 #endif
10039
10040         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10041                 return;
10042
10043 #ifdef RTE_LIBRTE_I40E_PMD
10044         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10045
10046         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10047
10048         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10049                                         op_type, &rte_pmd_regions);
10050
10051         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10052 #endif
10053
10054         switch (ret) {
10055         case 0:
10056                 break;
10057         case -ENOTSUP:
10058                 printf("function not implemented or supported\n");
10059                 break;
10060         default:
10061                 printf("queue region config info show error: (%s)\n",
10062                                 strerror(-ret));
10063         }
10064 }
10065
10066 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10067 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10068                                 show, "show");
10069 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10070         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10071                                 port, "port");
10072 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10073         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10074                                 port_id, UINT16);
10075 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10076         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10077                                 cmd, "queue-region");
10078
10079 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10080         .f = cmd_show_queue_region_info_parsed,
10081         .data = NULL,
10082         .help_str = "show port <port_id> queue-region"
10083                 ": show all queue region related configuration info",
10084         .tokens = {
10085                 (void *)&cmd_show_queue_region_info_get,
10086                 (void *)&cmd_show_queue_region_info_port,
10087                 (void *)&cmd_show_queue_region_info_port_index,
10088                 (void *)&cmd_show_queue_region_info_cmd,
10089                 NULL,
10090         },
10091 };
10092
10093 /* *** ADD/REMOVE A 2tuple FILTER *** */
10094 struct cmd_2tuple_filter_result {
10095         cmdline_fixed_string_t filter;
10096         portid_t port_id;
10097         cmdline_fixed_string_t ops;
10098         cmdline_fixed_string_t dst_port;
10099         uint16_t dst_port_value;
10100         cmdline_fixed_string_t protocol;
10101         uint8_t protocol_value;
10102         cmdline_fixed_string_t mask;
10103         uint8_t  mask_value;
10104         cmdline_fixed_string_t tcp_flags;
10105         uint8_t tcp_flags_value;
10106         cmdline_fixed_string_t priority;
10107         uint8_t  priority_value;
10108         cmdline_fixed_string_t queue;
10109         uint16_t  queue_id;
10110 };
10111
10112 static void
10113 cmd_2tuple_filter_parsed(void *parsed_result,
10114                         __attribute__((unused)) struct cmdline *cl,
10115                         __attribute__((unused)) void *data)
10116 {
10117         struct rte_eth_ntuple_filter filter;
10118         struct cmd_2tuple_filter_result *res = parsed_result;
10119         int ret = 0;
10120
10121         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10122         if (ret < 0) {
10123                 printf("ntuple filter is not supported on port %u.\n",
10124                         res->port_id);
10125                 return;
10126         }
10127
10128         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10129
10130         filter.flags = RTE_2TUPLE_FLAGS;
10131         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10132         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10133         filter.proto = res->protocol_value;
10134         filter.priority = res->priority_value;
10135         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10136                 printf("nonzero tcp_flags is only meaningful"
10137                         " when protocol is TCP.\n");
10138                 return;
10139         }
10140         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10141                 printf("invalid TCP flags.\n");
10142                 return;
10143         }
10144
10145         if (res->tcp_flags_value != 0) {
10146                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10147                 filter.tcp_flags = res->tcp_flags_value;
10148         }
10149
10150         /* need convert to big endian. */
10151         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10152         filter.queue = res->queue_id;
10153
10154         if (!strcmp(res->ops, "add"))
10155                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10156                                 RTE_ETH_FILTER_NTUPLE,
10157                                 RTE_ETH_FILTER_ADD,
10158                                 &filter);
10159         else
10160                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10161                                 RTE_ETH_FILTER_NTUPLE,
10162                                 RTE_ETH_FILTER_DELETE,
10163                                 &filter);
10164         if (ret < 0)
10165                 printf("2tuple filter programming error: (%s)\n",
10166                         strerror(-ret));
10167
10168 }
10169
10170 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10171         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10172                                  filter, "2tuple_filter");
10173 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10174         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10175                                 port_id, UINT16);
10176 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10177         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10178                                  ops, "add#del");
10179 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10180         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10181                                 dst_port, "dst_port");
10182 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10183         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10184                                 dst_port_value, UINT16);
10185 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10186         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10187                                 protocol, "protocol");
10188 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10189         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10190                                 protocol_value, UINT8);
10191 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10192         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10193                                 mask, "mask");
10194 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10195         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10196                                 mask_value, INT8);
10197 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10198         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10199                                 tcp_flags, "tcp_flags");
10200 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10201         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10202                                 tcp_flags_value, UINT8);
10203 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10204         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10205                                 priority, "priority");
10206 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10207         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10208                                 priority_value, UINT8);
10209 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10210         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10211                                 queue, "queue");
10212 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10213         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10214                                 queue_id, UINT16);
10215
10216 cmdline_parse_inst_t cmd_2tuple_filter = {
10217         .f = cmd_2tuple_filter_parsed,
10218         .data = NULL,
10219         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10220                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10221                 "<queue_id>: Add a 2tuple filter",
10222         .tokens = {
10223                 (void *)&cmd_2tuple_filter_filter,
10224                 (void *)&cmd_2tuple_filter_port_id,
10225                 (void *)&cmd_2tuple_filter_ops,
10226                 (void *)&cmd_2tuple_filter_dst_port,
10227                 (void *)&cmd_2tuple_filter_dst_port_value,
10228                 (void *)&cmd_2tuple_filter_protocol,
10229                 (void *)&cmd_2tuple_filter_protocol_value,
10230                 (void *)&cmd_2tuple_filter_mask,
10231                 (void *)&cmd_2tuple_filter_mask_value,
10232                 (void *)&cmd_2tuple_filter_tcp_flags,
10233                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10234                 (void *)&cmd_2tuple_filter_priority,
10235                 (void *)&cmd_2tuple_filter_priority_value,
10236                 (void *)&cmd_2tuple_filter_queue,
10237                 (void *)&cmd_2tuple_filter_queue_id,
10238                 NULL,
10239         },
10240 };
10241
10242 /* *** ADD/REMOVE A 5tuple FILTER *** */
10243 struct cmd_5tuple_filter_result {
10244         cmdline_fixed_string_t filter;
10245         portid_t port_id;
10246         cmdline_fixed_string_t ops;
10247         cmdline_fixed_string_t dst_ip;
10248         cmdline_ipaddr_t dst_ip_value;
10249         cmdline_fixed_string_t src_ip;
10250         cmdline_ipaddr_t src_ip_value;
10251         cmdline_fixed_string_t dst_port;
10252         uint16_t dst_port_value;
10253         cmdline_fixed_string_t src_port;
10254         uint16_t src_port_value;
10255         cmdline_fixed_string_t protocol;
10256         uint8_t protocol_value;
10257         cmdline_fixed_string_t mask;
10258         uint8_t  mask_value;
10259         cmdline_fixed_string_t tcp_flags;
10260         uint8_t tcp_flags_value;
10261         cmdline_fixed_string_t priority;
10262         uint8_t  priority_value;
10263         cmdline_fixed_string_t queue;
10264         uint16_t  queue_id;
10265 };
10266
10267 static void
10268 cmd_5tuple_filter_parsed(void *parsed_result,
10269                         __attribute__((unused)) struct cmdline *cl,
10270                         __attribute__((unused)) void *data)
10271 {
10272         struct rte_eth_ntuple_filter filter;
10273         struct cmd_5tuple_filter_result *res = parsed_result;
10274         int ret = 0;
10275
10276         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10277         if (ret < 0) {
10278                 printf("ntuple filter is not supported on port %u.\n",
10279                         res->port_id);
10280                 return;
10281         }
10282
10283         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10284
10285         filter.flags = RTE_5TUPLE_FLAGS;
10286         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10287         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10288         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10289         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10290         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10291         filter.proto = res->protocol_value;
10292         filter.priority = res->priority_value;
10293         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10294                 printf("nonzero tcp_flags is only meaningful"
10295                         " when protocol is TCP.\n");
10296                 return;
10297         }
10298         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10299                 printf("invalid TCP flags.\n");
10300                 return;
10301         }
10302
10303         if (res->tcp_flags_value != 0) {
10304                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10305                 filter.tcp_flags = res->tcp_flags_value;
10306         }
10307
10308         if (res->dst_ip_value.family == AF_INET)
10309                 /* no need to convert, already big endian. */
10310                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10311         else {
10312                 if (filter.dst_ip_mask == 0) {
10313                         printf("can not support ipv6 involved compare.\n");
10314                         return;
10315                 }
10316                 filter.dst_ip = 0;
10317         }
10318
10319         if (res->src_ip_value.family == AF_INET)
10320                 /* no need to convert, already big endian. */
10321                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10322         else {
10323                 if (filter.src_ip_mask == 0) {
10324                         printf("can not support ipv6 involved compare.\n");
10325                         return;
10326                 }
10327                 filter.src_ip = 0;
10328         }
10329         /* need convert to big endian. */
10330         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10331         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10332         filter.queue = res->queue_id;
10333
10334         if (!strcmp(res->ops, "add"))
10335                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10336                                 RTE_ETH_FILTER_NTUPLE,
10337                                 RTE_ETH_FILTER_ADD,
10338                                 &filter);
10339         else
10340                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10341                                 RTE_ETH_FILTER_NTUPLE,
10342                                 RTE_ETH_FILTER_DELETE,
10343                                 &filter);
10344         if (ret < 0)
10345                 printf("5tuple filter programming error: (%s)\n",
10346                         strerror(-ret));
10347 }
10348
10349 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10350         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10351                                  filter, "5tuple_filter");
10352 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10353         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10354                                 port_id, UINT16);
10355 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10356         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10357                                  ops, "add#del");
10358 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10359         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10360                                 dst_ip, "dst_ip");
10361 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10362         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10363                                 dst_ip_value);
10364 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10365         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10366                                 src_ip, "src_ip");
10367 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10368         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10369                                 src_ip_value);
10370 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10371         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10372                                 dst_port, "dst_port");
10373 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10374         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10375                                 dst_port_value, UINT16);
10376 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10377         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10378                                 src_port, "src_port");
10379 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10380         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10381                                 src_port_value, UINT16);
10382 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10383         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10384                                 protocol, "protocol");
10385 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10386         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10387                                 protocol_value, UINT8);
10388 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10389         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10390                                 mask, "mask");
10391 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10392         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10393                                 mask_value, INT8);
10394 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10395         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10396                                 tcp_flags, "tcp_flags");
10397 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10398         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10399                                 tcp_flags_value, UINT8);
10400 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10401         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10402                                 priority, "priority");
10403 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10404         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10405                                 priority_value, UINT8);
10406 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10407         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10408                                 queue, "queue");
10409 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10410         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10411                                 queue_id, UINT16);
10412
10413 cmdline_parse_inst_t cmd_5tuple_filter = {
10414         .f = cmd_5tuple_filter_parsed,
10415         .data = NULL,
10416         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10417                 "src_ip <value> dst_port <value> src_port <value> "
10418                 "protocol <value>  mask <value> tcp_flags <value> "
10419                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10420         .tokens = {
10421                 (void *)&cmd_5tuple_filter_filter,
10422                 (void *)&cmd_5tuple_filter_port_id,
10423                 (void *)&cmd_5tuple_filter_ops,
10424                 (void *)&cmd_5tuple_filter_dst_ip,
10425                 (void *)&cmd_5tuple_filter_dst_ip_value,
10426                 (void *)&cmd_5tuple_filter_src_ip,
10427                 (void *)&cmd_5tuple_filter_src_ip_value,
10428                 (void *)&cmd_5tuple_filter_dst_port,
10429                 (void *)&cmd_5tuple_filter_dst_port_value,
10430                 (void *)&cmd_5tuple_filter_src_port,
10431                 (void *)&cmd_5tuple_filter_src_port_value,
10432                 (void *)&cmd_5tuple_filter_protocol,
10433                 (void *)&cmd_5tuple_filter_protocol_value,
10434                 (void *)&cmd_5tuple_filter_mask,
10435                 (void *)&cmd_5tuple_filter_mask_value,
10436                 (void *)&cmd_5tuple_filter_tcp_flags,
10437                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10438                 (void *)&cmd_5tuple_filter_priority,
10439                 (void *)&cmd_5tuple_filter_priority_value,
10440                 (void *)&cmd_5tuple_filter_queue,
10441                 (void *)&cmd_5tuple_filter_queue_id,
10442                 NULL,
10443         },
10444 };
10445
10446 /* *** ADD/REMOVE A flex FILTER *** */
10447 struct cmd_flex_filter_result {
10448         cmdline_fixed_string_t filter;
10449         cmdline_fixed_string_t ops;
10450         portid_t port_id;
10451         cmdline_fixed_string_t len;
10452         uint8_t len_value;
10453         cmdline_fixed_string_t bytes;
10454         cmdline_fixed_string_t bytes_value;
10455         cmdline_fixed_string_t mask;
10456         cmdline_fixed_string_t mask_value;
10457         cmdline_fixed_string_t priority;
10458         uint8_t priority_value;
10459         cmdline_fixed_string_t queue;
10460         uint16_t queue_id;
10461 };
10462
10463 static int xdigit2val(unsigned char c)
10464 {
10465         int val;
10466         if (isdigit(c))
10467                 val = c - '0';
10468         else if (isupper(c))
10469                 val = c - 'A' + 10;
10470         else
10471                 val = c - 'a' + 10;
10472         return val;
10473 }
10474
10475 static void
10476 cmd_flex_filter_parsed(void *parsed_result,
10477                           __attribute__((unused)) struct cmdline *cl,
10478                           __attribute__((unused)) void *data)
10479 {
10480         int ret = 0;
10481         struct rte_eth_flex_filter filter;
10482         struct cmd_flex_filter_result *res = parsed_result;
10483         char *bytes_ptr, *mask_ptr;
10484         uint16_t len, i, j = 0;
10485         char c;
10486         int val;
10487         uint8_t byte = 0;
10488
10489         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10490                 printf("the len exceed the max length 128\n");
10491                 return;
10492         }
10493         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10494         filter.len = res->len_value;
10495         filter.priority = res->priority_value;
10496         filter.queue = res->queue_id;
10497         bytes_ptr = res->bytes_value;
10498         mask_ptr = res->mask_value;
10499
10500          /* translate bytes string to array. */
10501         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10502                 (bytes_ptr[1] == 'X')))
10503                 bytes_ptr += 2;
10504         len = strnlen(bytes_ptr, res->len_value * 2);
10505         if (len == 0 || (len % 8 != 0)) {
10506                 printf("please check len and bytes input\n");
10507                 return;
10508         }
10509         for (i = 0; i < len; i++) {
10510                 c = bytes_ptr[i];
10511                 if (isxdigit(c) == 0) {
10512                         /* invalid characters. */
10513                         printf("invalid input\n");
10514                         return;
10515                 }
10516                 val = xdigit2val(c);
10517                 if (i % 2) {
10518                         byte |= val;
10519                         filter.bytes[j] = byte;
10520                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10521                         j++;
10522                         byte = 0;
10523                 } else
10524                         byte |= val << 4;
10525         }
10526         printf("\n");
10527          /* translate mask string to uint8_t array. */
10528         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10529                 (mask_ptr[1] == 'X')))
10530                 mask_ptr += 2;
10531         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10532         if (len == 0) {
10533                 printf("invalid input\n");
10534                 return;
10535         }
10536         j = 0;
10537         byte = 0;
10538         for (i = 0; i < len; i++) {
10539                 c = mask_ptr[i];
10540                 if (isxdigit(c) == 0) {
10541                         /* invalid characters. */
10542                         printf("invalid input\n");
10543                         return;
10544                 }
10545                 val = xdigit2val(c);
10546                 if (i % 2) {
10547                         byte |= val;
10548                         filter.mask[j] = byte;
10549                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10550                         j++;
10551                         byte = 0;
10552                 } else
10553                         byte |= val << 4;
10554         }
10555         printf("\n");
10556
10557         if (!strcmp(res->ops, "add"))
10558                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10559                                 RTE_ETH_FILTER_FLEXIBLE,
10560                                 RTE_ETH_FILTER_ADD,
10561                                 &filter);
10562         else
10563                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10564                                 RTE_ETH_FILTER_FLEXIBLE,
10565                                 RTE_ETH_FILTER_DELETE,
10566                                 &filter);
10567
10568         if (ret < 0)
10569                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10570 }
10571
10572 cmdline_parse_token_string_t cmd_flex_filter_filter =
10573         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10574                                 filter, "flex_filter");
10575 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10576         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10577                                 port_id, UINT16);
10578 cmdline_parse_token_string_t cmd_flex_filter_ops =
10579         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10580                                 ops, "add#del");
10581 cmdline_parse_token_string_t cmd_flex_filter_len =
10582         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10583                                 len, "len");
10584 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10585         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10586                                 len_value, UINT8);
10587 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10588         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10589                                 bytes, "bytes");
10590 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10591         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10592                                 bytes_value, NULL);
10593 cmdline_parse_token_string_t cmd_flex_filter_mask =
10594         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10595                                 mask, "mask");
10596 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10597         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10598                                 mask_value, NULL);
10599 cmdline_parse_token_string_t cmd_flex_filter_priority =
10600         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10601                                 priority, "priority");
10602 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10603         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10604                                 priority_value, UINT8);
10605 cmdline_parse_token_string_t cmd_flex_filter_queue =
10606         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10607                                 queue, "queue");
10608 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10609         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10610                                 queue_id, UINT16);
10611 cmdline_parse_inst_t cmd_flex_filter = {
10612         .f = cmd_flex_filter_parsed,
10613         .data = NULL,
10614         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10615                 "<value> mask <value> priority <value> queue <queue_id>: "
10616                 "Add/Del a flex filter",
10617         .tokens = {
10618                 (void *)&cmd_flex_filter_filter,
10619                 (void *)&cmd_flex_filter_port_id,
10620                 (void *)&cmd_flex_filter_ops,
10621                 (void *)&cmd_flex_filter_len,
10622                 (void *)&cmd_flex_filter_len_value,
10623                 (void *)&cmd_flex_filter_bytes,
10624                 (void *)&cmd_flex_filter_bytes_value,
10625                 (void *)&cmd_flex_filter_mask,
10626                 (void *)&cmd_flex_filter_mask_value,
10627                 (void *)&cmd_flex_filter_priority,
10628                 (void *)&cmd_flex_filter_priority_value,
10629                 (void *)&cmd_flex_filter_queue,
10630                 (void *)&cmd_flex_filter_queue_id,
10631                 NULL,
10632         },
10633 };
10634
10635 /* *** Filters Control *** */
10636
10637 /* *** deal with ethertype filter *** */
10638 struct cmd_ethertype_filter_result {
10639         cmdline_fixed_string_t filter;
10640         portid_t port_id;
10641         cmdline_fixed_string_t ops;
10642         cmdline_fixed_string_t mac;
10643         struct rte_ether_addr mac_addr;
10644         cmdline_fixed_string_t ethertype;
10645         uint16_t ethertype_value;
10646         cmdline_fixed_string_t drop;
10647         cmdline_fixed_string_t queue;
10648         uint16_t  queue_id;
10649 };
10650
10651 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10652         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10653                                  filter, "ethertype_filter");
10654 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10655         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10656                               port_id, UINT16);
10657 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10658         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10659                                  ops, "add#del");
10660 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10661         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10662                                  mac, "mac_addr#mac_ignr");
10663 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10664         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10665                                      mac_addr);
10666 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10667         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10668                                  ethertype, "ethertype");
10669 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10670         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10671                               ethertype_value, UINT16);
10672 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10673         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10674                                  drop, "drop#fwd");
10675 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10676         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10677                                  queue, "queue");
10678 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10679         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10680                               queue_id, UINT16);
10681
10682 static void
10683 cmd_ethertype_filter_parsed(void *parsed_result,
10684                           __attribute__((unused)) struct cmdline *cl,
10685                           __attribute__((unused)) void *data)
10686 {
10687         struct cmd_ethertype_filter_result *res = parsed_result;
10688         struct rte_eth_ethertype_filter filter;
10689         int ret = 0;
10690
10691         ret = rte_eth_dev_filter_supported(res->port_id,
10692                         RTE_ETH_FILTER_ETHERTYPE);
10693         if (ret < 0) {
10694                 printf("ethertype filter is not supported on port %u.\n",
10695                         res->port_id);
10696                 return;
10697         }
10698
10699         memset(&filter, 0, sizeof(filter));
10700         if (!strcmp(res->mac, "mac_addr")) {
10701                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10702                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10703                         sizeof(struct rte_ether_addr));
10704         }
10705         if (!strcmp(res->drop, "drop"))
10706                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10707         filter.ether_type = res->ethertype_value;
10708         filter.queue = res->queue_id;
10709
10710         if (!strcmp(res->ops, "add"))
10711                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10712                                 RTE_ETH_FILTER_ETHERTYPE,
10713                                 RTE_ETH_FILTER_ADD,
10714                                 &filter);
10715         else
10716                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10717                                 RTE_ETH_FILTER_ETHERTYPE,
10718                                 RTE_ETH_FILTER_DELETE,
10719                                 &filter);
10720         if (ret < 0)
10721                 printf("ethertype filter programming error: (%s)\n",
10722                         strerror(-ret));
10723 }
10724
10725 cmdline_parse_inst_t cmd_ethertype_filter = {
10726         .f = cmd_ethertype_filter_parsed,
10727         .data = NULL,
10728         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10729                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10730                 "Add or delete an ethertype filter entry",
10731         .tokens = {
10732                 (void *)&cmd_ethertype_filter_filter,
10733                 (void *)&cmd_ethertype_filter_port_id,
10734                 (void *)&cmd_ethertype_filter_ops,
10735                 (void *)&cmd_ethertype_filter_mac,
10736                 (void *)&cmd_ethertype_filter_mac_addr,
10737                 (void *)&cmd_ethertype_filter_ethertype,
10738                 (void *)&cmd_ethertype_filter_ethertype_value,
10739                 (void *)&cmd_ethertype_filter_drop,
10740                 (void *)&cmd_ethertype_filter_queue,
10741                 (void *)&cmd_ethertype_filter_queue_id,
10742                 NULL,
10743         },
10744 };
10745
10746 /* *** deal with flow director filter *** */
10747 struct cmd_flow_director_result {
10748         cmdline_fixed_string_t flow_director_filter;
10749         portid_t port_id;
10750         cmdline_fixed_string_t mode;
10751         cmdline_fixed_string_t mode_value;
10752         cmdline_fixed_string_t ops;
10753         cmdline_fixed_string_t flow;
10754         cmdline_fixed_string_t flow_type;
10755         cmdline_fixed_string_t ether;
10756         uint16_t ether_type;
10757         cmdline_fixed_string_t src;
10758         cmdline_ipaddr_t ip_src;
10759         uint16_t port_src;
10760         cmdline_fixed_string_t dst;
10761         cmdline_ipaddr_t ip_dst;
10762         uint16_t port_dst;
10763         cmdline_fixed_string_t verify_tag;
10764         uint32_t verify_tag_value;
10765         cmdline_fixed_string_t tos;
10766         uint8_t tos_value;
10767         cmdline_fixed_string_t proto;
10768         uint8_t proto_value;
10769         cmdline_fixed_string_t ttl;
10770         uint8_t ttl_value;
10771         cmdline_fixed_string_t vlan;
10772         uint16_t vlan_value;
10773         cmdline_fixed_string_t flexbytes;
10774         cmdline_fixed_string_t flexbytes_value;
10775         cmdline_fixed_string_t pf_vf;
10776         cmdline_fixed_string_t drop;
10777         cmdline_fixed_string_t queue;
10778         uint16_t  queue_id;
10779         cmdline_fixed_string_t fd_id;
10780         uint32_t  fd_id_value;
10781         cmdline_fixed_string_t mac;
10782         struct rte_ether_addr mac_addr;
10783         cmdline_fixed_string_t tunnel;
10784         cmdline_fixed_string_t tunnel_type;
10785         cmdline_fixed_string_t tunnel_id;
10786         uint32_t tunnel_id_value;
10787         cmdline_fixed_string_t packet;
10788         char filepath[];
10789 };
10790
10791 static inline int
10792 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10793 {
10794         char s[256];
10795         const char *p, *p0 = q_arg;
10796         char *end;
10797         unsigned long int_fld;
10798         char *str_fld[max_num];
10799         int i;
10800         unsigned size;
10801         int ret = -1;
10802
10803         p = strchr(p0, '(');
10804         if (p == NULL)
10805                 return -1;
10806         ++p;
10807         p0 = strchr(p, ')');
10808         if (p0 == NULL)
10809                 return -1;
10810
10811         size = p0 - p;
10812         if (size >= sizeof(s))
10813                 return -1;
10814
10815         snprintf(s, sizeof(s), "%.*s", size, p);
10816         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10817         if (ret < 0 || ret > max_num)
10818                 return -1;
10819         for (i = 0; i < ret; i++) {
10820                 errno = 0;
10821                 int_fld = strtoul(str_fld[i], &end, 0);
10822                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10823                         return -1;
10824                 flexbytes[i] = (uint8_t)int_fld;
10825         }
10826         return ret;
10827 }
10828
10829 static uint16_t
10830 str2flowtype(char *string)
10831 {
10832         uint8_t i = 0;
10833         static const struct {
10834                 char str[32];
10835                 uint16_t type;
10836         } flowtype_str[] = {
10837                 {"raw", RTE_ETH_FLOW_RAW},
10838                 {"ipv4", RTE_ETH_FLOW_IPV4},
10839                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10840                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10841                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10842                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10843                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10844                 {"ipv6", RTE_ETH_FLOW_IPV6},
10845                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10846                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10847                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10848                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10849                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10850                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10851         };
10852
10853         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10854                 if (!strcmp(flowtype_str[i].str, string))
10855                         return flowtype_str[i].type;
10856         }
10857
10858         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10859                 return (uint16_t)atoi(string);
10860
10861         return RTE_ETH_FLOW_UNKNOWN;
10862 }
10863
10864 static enum rte_eth_fdir_tunnel_type
10865 str2fdir_tunneltype(char *string)
10866 {
10867         uint8_t i = 0;
10868
10869         static const struct {
10870                 char str[32];
10871                 enum rte_eth_fdir_tunnel_type type;
10872         } tunneltype_str[] = {
10873                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10874                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10875         };
10876
10877         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10878                 if (!strcmp(tunneltype_str[i].str, string))
10879                         return tunneltype_str[i].type;
10880         }
10881         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10882 }
10883
10884 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10885 do { \
10886         if ((ip_addr).family == AF_INET) \
10887                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10888         else { \
10889                 printf("invalid parameter.\n"); \
10890                 return; \
10891         } \
10892 } while (0)
10893
10894 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10895 do { \
10896         if ((ip_addr).family == AF_INET6) \
10897                 rte_memcpy(&(ip), \
10898                                  &((ip_addr).addr.ipv6), \
10899                                  sizeof(struct in6_addr)); \
10900         else { \
10901                 printf("invalid parameter.\n"); \
10902                 return; \
10903         } \
10904 } while (0)
10905
10906 static void
10907 cmd_flow_director_filter_parsed(void *parsed_result,
10908                           __attribute__((unused)) struct cmdline *cl,
10909                           __attribute__((unused)) void *data)
10910 {
10911         struct cmd_flow_director_result *res = parsed_result;
10912         struct rte_eth_fdir_filter entry;
10913         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10914         char *end;
10915         unsigned long vf_id;
10916         int ret = 0;
10917
10918         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10919         if (ret < 0) {
10920                 printf("flow director is not supported on port %u.\n",
10921                         res->port_id);
10922                 return;
10923         }
10924         memset(flexbytes, 0, sizeof(flexbytes));
10925         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10926
10927         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10928                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10929                         printf("Please set mode to MAC-VLAN.\n");
10930                         return;
10931                 }
10932         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10933                 if (strcmp(res->mode_value, "Tunnel")) {
10934                         printf("Please set mode to Tunnel.\n");
10935                         return;
10936                 }
10937         } else {
10938                 if (!strcmp(res->mode_value, "raw")) {
10939 #ifdef RTE_LIBRTE_I40E_PMD
10940                         struct rte_pmd_i40e_flow_type_mapping
10941                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10942                         struct rte_pmd_i40e_pkt_template_conf conf;
10943                         uint16_t flow_type = str2flowtype(res->flow_type);
10944                         uint16_t i, port = res->port_id;
10945                         uint8_t add;
10946
10947                         memset(&conf, 0, sizeof(conf));
10948
10949                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10950                                 printf("Invalid flow type specified.\n");
10951                                 return;
10952                         }
10953                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10954                                                                  mapping);
10955                         if (ret)
10956                                 return;
10957                         if (mapping[flow_type].pctype == 0ULL) {
10958                                 printf("Invalid flow type specified.\n");
10959                                 return;
10960                         }
10961                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10962                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10963                                         conf.input.pctype = i;
10964                                         break;
10965                                 }
10966                         }
10967
10968                         conf.input.packet = open_file(res->filepath,
10969                                                 &conf.input.length);
10970                         if (!conf.input.packet)
10971                                 return;
10972                         if (!strcmp(res->drop, "drop"))
10973                                 conf.action.behavior =
10974                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10975                         else
10976                                 conf.action.behavior =
10977                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10978                         conf.action.report_status =
10979                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10980                         conf.action.rx_queue = res->queue_id;
10981                         conf.soft_id = res->fd_id_value;
10982                         add  = strcmp(res->ops, "del") ? 1 : 0;
10983                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10984                                                                         &conf,
10985                                                                         add);
10986                         if (ret < 0)
10987                                 printf("flow director config error: (%s)\n",
10988                                        strerror(-ret));
10989                         close_file(conf.input.packet);
10990 #endif
10991                         return;
10992                 } else if (strcmp(res->mode_value, "IP")) {
10993                         printf("Please set mode to IP or raw.\n");
10994                         return;
10995                 }
10996                 entry.input.flow_type = str2flowtype(res->flow_type);
10997         }
10998
10999         ret = parse_flexbytes(res->flexbytes_value,
11000                                         flexbytes,
11001                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11002         if (ret < 0) {
11003                 printf("error: Cannot parse flexbytes input.\n");
11004                 return;
11005         }
11006
11007         switch (entry.input.flow_type) {
11008         case RTE_ETH_FLOW_FRAG_IPV4:
11009         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11010                 entry.input.flow.ip4_flow.proto = res->proto_value;
11011                 /* fall-through */
11012         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11013         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11014                 IPV4_ADDR_TO_UINT(res->ip_dst,
11015                         entry.input.flow.ip4_flow.dst_ip);
11016                 IPV4_ADDR_TO_UINT(res->ip_src,
11017                         entry.input.flow.ip4_flow.src_ip);
11018                 entry.input.flow.ip4_flow.tos = res->tos_value;
11019                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11020                 /* need convert to big endian. */
11021                 entry.input.flow.udp4_flow.dst_port =
11022                                 rte_cpu_to_be_16(res->port_dst);
11023                 entry.input.flow.udp4_flow.src_port =
11024                                 rte_cpu_to_be_16(res->port_src);
11025                 break;
11026         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11027                 IPV4_ADDR_TO_UINT(res->ip_dst,
11028                         entry.input.flow.sctp4_flow.ip.dst_ip);
11029                 IPV4_ADDR_TO_UINT(res->ip_src,
11030                         entry.input.flow.sctp4_flow.ip.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.sctp4_flow.dst_port =
11035                                 rte_cpu_to_be_16(res->port_dst);
11036                 entry.input.flow.sctp4_flow.src_port =
11037                                 rte_cpu_to_be_16(res->port_src);
11038                 entry.input.flow.sctp4_flow.verify_tag =
11039                                 rte_cpu_to_be_32(res->verify_tag_value);
11040                 break;
11041         case RTE_ETH_FLOW_FRAG_IPV6:
11042         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11043                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11044                 /* fall-through */
11045         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11046         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11047                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11048                         entry.input.flow.ipv6_flow.dst_ip);
11049                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11050                         entry.input.flow.ipv6_flow.src_ip);
11051                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11052                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11053                 /* need convert to big endian. */
11054                 entry.input.flow.udp6_flow.dst_port =
11055                                 rte_cpu_to_be_16(res->port_dst);
11056                 entry.input.flow.udp6_flow.src_port =
11057                                 rte_cpu_to_be_16(res->port_src);
11058                 break;
11059         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11060                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11061                         entry.input.flow.sctp6_flow.ip.dst_ip);
11062                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11063                         entry.input.flow.sctp6_flow.ip.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.sctp6_flow.dst_port =
11068                                 rte_cpu_to_be_16(res->port_dst);
11069                 entry.input.flow.sctp6_flow.src_port =
11070                                 rte_cpu_to_be_16(res->port_src);
11071                 entry.input.flow.sctp6_flow.verify_tag =
11072                                 rte_cpu_to_be_32(res->verify_tag_value);
11073                 break;
11074         case RTE_ETH_FLOW_L2_PAYLOAD:
11075                 entry.input.flow.l2_flow.ether_type =
11076                         rte_cpu_to_be_16(res->ether_type);
11077                 break;
11078         default:
11079                 break;
11080         }
11081
11082         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11083                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11084                                  &res->mac_addr,
11085                                  sizeof(struct rte_ether_addr));
11086
11087         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11088                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11089                                  &res->mac_addr,
11090                                  sizeof(struct rte_ether_addr));
11091                 entry.input.flow.tunnel_flow.tunnel_type =
11092                         str2fdir_tunneltype(res->tunnel_type);
11093                 entry.input.flow.tunnel_flow.tunnel_id =
11094                         rte_cpu_to_be_32(res->tunnel_id_value);
11095         }
11096
11097         rte_memcpy(entry.input.flow_ext.flexbytes,
11098                    flexbytes,
11099                    RTE_ETH_FDIR_MAX_FLEXLEN);
11100
11101         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11102
11103         entry.action.flex_off = 0;  /*use 0 by default */
11104         if (!strcmp(res->drop, "drop"))
11105                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11106         else
11107                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11108
11109         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11110             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11111                 if (!strcmp(res->pf_vf, "pf"))
11112                         entry.input.flow_ext.is_vf = 0;
11113                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11114                         struct rte_eth_dev_info dev_info;
11115
11116                         ret = eth_dev_info_get_print_err(res->port_id,
11117                                                 &dev_info);
11118                         if (ret != 0)
11119                                 return;
11120
11121                         errno = 0;
11122                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11123                         if (errno != 0 || *end != '\0' ||
11124                             vf_id >= dev_info.max_vfs) {
11125                                 printf("invalid parameter %s.\n", res->pf_vf);
11126                                 return;
11127                         }
11128                         entry.input.flow_ext.is_vf = 1;
11129                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11130                 } else {
11131                         printf("invalid parameter %s.\n", res->pf_vf);
11132                         return;
11133                 }
11134         }
11135
11136         /* set to report FD ID by default */
11137         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11138         entry.action.rx_queue = res->queue_id;
11139         entry.soft_id = res->fd_id_value;
11140         if (!strcmp(res->ops, "add"))
11141                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11142                                              RTE_ETH_FILTER_ADD, &entry);
11143         else if (!strcmp(res->ops, "del"))
11144                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11145                                              RTE_ETH_FILTER_DELETE, &entry);
11146         else
11147                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11148                                              RTE_ETH_FILTER_UPDATE, &entry);
11149         if (ret < 0)
11150                 printf("flow director programming error: (%s)\n",
11151                         strerror(-ret));
11152 }
11153
11154 cmdline_parse_token_string_t cmd_flow_director_filter =
11155         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11156                                  flow_director_filter, "flow_director_filter");
11157 cmdline_parse_token_num_t cmd_flow_director_port_id =
11158         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11159                               port_id, UINT16);
11160 cmdline_parse_token_string_t cmd_flow_director_ops =
11161         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11162                                  ops, "add#del#update");
11163 cmdline_parse_token_string_t cmd_flow_director_flow =
11164         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11165                                  flow, "flow");
11166 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11167         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11168                 flow_type, NULL);
11169 cmdline_parse_token_string_t cmd_flow_director_ether =
11170         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11171                                  ether, "ether");
11172 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11173         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11174                               ether_type, UINT16);
11175 cmdline_parse_token_string_t cmd_flow_director_src =
11176         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11177                                  src, "src");
11178 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11179         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11180                                  ip_src);
11181 cmdline_parse_token_num_t cmd_flow_director_port_src =
11182         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11183                               port_src, UINT16);
11184 cmdline_parse_token_string_t cmd_flow_director_dst =
11185         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11186                                  dst, "dst");
11187 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11188         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11189                                  ip_dst);
11190 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11191         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11192                               port_dst, UINT16);
11193 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11194         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11195                                   verify_tag, "verify_tag");
11196 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11197         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11198                               verify_tag_value, UINT32);
11199 cmdline_parse_token_string_t cmd_flow_director_tos =
11200         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11201                                  tos, "tos");
11202 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11203         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11204                               tos_value, UINT8);
11205 cmdline_parse_token_string_t cmd_flow_director_proto =
11206         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11207                                  proto, "proto");
11208 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11209         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11210                               proto_value, UINT8);
11211 cmdline_parse_token_string_t cmd_flow_director_ttl =
11212         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11213                                  ttl, "ttl");
11214 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11215         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11216                               ttl_value, UINT8);
11217 cmdline_parse_token_string_t cmd_flow_director_vlan =
11218         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11219                                  vlan, "vlan");
11220 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11221         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11222                               vlan_value, UINT16);
11223 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11224         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11225                                  flexbytes, "flexbytes");
11226 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11227         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11228                               flexbytes_value, NULL);
11229 cmdline_parse_token_string_t cmd_flow_director_drop =
11230         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11231                                  drop, "drop#fwd");
11232 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11233         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11234                               pf_vf, NULL);
11235 cmdline_parse_token_string_t cmd_flow_director_queue =
11236         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11237                                  queue, "queue");
11238 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11239         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11240                               queue_id, UINT16);
11241 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11242         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11243                                  fd_id, "fd_id");
11244 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11245         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11246                               fd_id_value, UINT32);
11247
11248 cmdline_parse_token_string_t cmd_flow_director_mode =
11249         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11250                                  mode, "mode");
11251 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11252         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11253                                  mode_value, "IP");
11254 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11255         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11256                                  mode_value, "MAC-VLAN");
11257 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11258         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11259                                  mode_value, "Tunnel");
11260 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11261         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11262                                  mode_value, "raw");
11263 cmdline_parse_token_string_t cmd_flow_director_mac =
11264         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11265                                  mac, "mac");
11266 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11267         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11268                                     mac_addr);
11269 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11270         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11271                                  tunnel, "tunnel");
11272 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11273         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11274                                  tunnel_type, "NVGRE#VxLAN");
11275 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11276         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11277                                  tunnel_id, "tunnel-id");
11278 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11279         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11280                               tunnel_id_value, UINT32);
11281 cmdline_parse_token_string_t cmd_flow_director_packet =
11282         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11283                                  packet, "packet");
11284 cmdline_parse_token_string_t cmd_flow_director_filepath =
11285         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11286                                  filepath, NULL);
11287
11288 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11289         .f = cmd_flow_director_filter_parsed,
11290         .data = NULL,
11291         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11292                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11293                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11294                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11295                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11296                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11297                 "fd_id <fd_id_value>: "
11298                 "Add or delete an ip flow director entry on NIC",
11299         .tokens = {
11300                 (void *)&cmd_flow_director_filter,
11301                 (void *)&cmd_flow_director_port_id,
11302                 (void *)&cmd_flow_director_mode,
11303                 (void *)&cmd_flow_director_mode_ip,
11304                 (void *)&cmd_flow_director_ops,
11305                 (void *)&cmd_flow_director_flow,
11306                 (void *)&cmd_flow_director_flow_type,
11307                 (void *)&cmd_flow_director_src,
11308                 (void *)&cmd_flow_director_ip_src,
11309                 (void *)&cmd_flow_director_dst,
11310                 (void *)&cmd_flow_director_ip_dst,
11311                 (void *)&cmd_flow_director_tos,
11312                 (void *)&cmd_flow_director_tos_value,
11313                 (void *)&cmd_flow_director_proto,
11314                 (void *)&cmd_flow_director_proto_value,
11315                 (void *)&cmd_flow_director_ttl,
11316                 (void *)&cmd_flow_director_ttl_value,
11317                 (void *)&cmd_flow_director_vlan,
11318                 (void *)&cmd_flow_director_vlan_value,
11319                 (void *)&cmd_flow_director_flexbytes,
11320                 (void *)&cmd_flow_director_flexbytes_value,
11321                 (void *)&cmd_flow_director_drop,
11322                 (void *)&cmd_flow_director_pf_vf,
11323                 (void *)&cmd_flow_director_queue,
11324                 (void *)&cmd_flow_director_queue_id,
11325                 (void *)&cmd_flow_director_fd_id,
11326                 (void *)&cmd_flow_director_fd_id_value,
11327                 NULL,
11328         },
11329 };
11330
11331 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11332         .f = cmd_flow_director_filter_parsed,
11333         .data = NULL,
11334         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11335                 "director entry on NIC",
11336         .tokens = {
11337                 (void *)&cmd_flow_director_filter,
11338                 (void *)&cmd_flow_director_port_id,
11339                 (void *)&cmd_flow_director_mode,
11340                 (void *)&cmd_flow_director_mode_ip,
11341                 (void *)&cmd_flow_director_ops,
11342                 (void *)&cmd_flow_director_flow,
11343                 (void *)&cmd_flow_director_flow_type,
11344                 (void *)&cmd_flow_director_src,
11345                 (void *)&cmd_flow_director_ip_src,
11346                 (void *)&cmd_flow_director_port_src,
11347                 (void *)&cmd_flow_director_dst,
11348                 (void *)&cmd_flow_director_ip_dst,
11349                 (void *)&cmd_flow_director_port_dst,
11350                 (void *)&cmd_flow_director_tos,
11351                 (void *)&cmd_flow_director_tos_value,
11352                 (void *)&cmd_flow_director_ttl,
11353                 (void *)&cmd_flow_director_ttl_value,
11354                 (void *)&cmd_flow_director_vlan,
11355                 (void *)&cmd_flow_director_vlan_value,
11356                 (void *)&cmd_flow_director_flexbytes,
11357                 (void *)&cmd_flow_director_flexbytes_value,
11358                 (void *)&cmd_flow_director_drop,
11359                 (void *)&cmd_flow_director_pf_vf,
11360                 (void *)&cmd_flow_director_queue,
11361                 (void *)&cmd_flow_director_queue_id,
11362                 (void *)&cmd_flow_director_fd_id,
11363                 (void *)&cmd_flow_director_fd_id_value,
11364                 NULL,
11365         },
11366 };
11367
11368 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11369         .f = cmd_flow_director_filter_parsed,
11370         .data = NULL,
11371         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11372                 "director entry on NIC",
11373         .tokens = {
11374                 (void *)&cmd_flow_director_filter,
11375                 (void *)&cmd_flow_director_port_id,
11376                 (void *)&cmd_flow_director_mode,
11377                 (void *)&cmd_flow_director_mode_ip,
11378                 (void *)&cmd_flow_director_ops,
11379                 (void *)&cmd_flow_director_flow,
11380                 (void *)&cmd_flow_director_flow_type,
11381                 (void *)&cmd_flow_director_src,
11382                 (void *)&cmd_flow_director_ip_src,
11383                 (void *)&cmd_flow_director_port_src,
11384                 (void *)&cmd_flow_director_dst,
11385                 (void *)&cmd_flow_director_ip_dst,
11386                 (void *)&cmd_flow_director_port_dst,
11387                 (void *)&cmd_flow_director_verify_tag,
11388                 (void *)&cmd_flow_director_verify_tag_value,
11389                 (void *)&cmd_flow_director_tos,
11390                 (void *)&cmd_flow_director_tos_value,
11391                 (void *)&cmd_flow_director_ttl,
11392                 (void *)&cmd_flow_director_ttl_value,
11393                 (void *)&cmd_flow_director_vlan,
11394                 (void *)&cmd_flow_director_vlan_value,
11395                 (void *)&cmd_flow_director_flexbytes,
11396                 (void *)&cmd_flow_director_flexbytes_value,
11397                 (void *)&cmd_flow_director_drop,
11398                 (void *)&cmd_flow_director_pf_vf,
11399                 (void *)&cmd_flow_director_queue,
11400                 (void *)&cmd_flow_director_queue_id,
11401                 (void *)&cmd_flow_director_fd_id,
11402                 (void *)&cmd_flow_director_fd_id_value,
11403                 NULL,
11404         },
11405 };
11406
11407 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11408         .f = cmd_flow_director_filter_parsed,
11409         .data = NULL,
11410         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11411                 "director entry on NIC",
11412         .tokens = {
11413                 (void *)&cmd_flow_director_filter,
11414                 (void *)&cmd_flow_director_port_id,
11415                 (void *)&cmd_flow_director_mode,
11416                 (void *)&cmd_flow_director_mode_ip,
11417                 (void *)&cmd_flow_director_ops,
11418                 (void *)&cmd_flow_director_flow,
11419                 (void *)&cmd_flow_director_flow_type,
11420                 (void *)&cmd_flow_director_ether,
11421                 (void *)&cmd_flow_director_ether_type,
11422                 (void *)&cmd_flow_director_flexbytes,
11423                 (void *)&cmd_flow_director_flexbytes_value,
11424                 (void *)&cmd_flow_director_drop,
11425                 (void *)&cmd_flow_director_pf_vf,
11426                 (void *)&cmd_flow_director_queue,
11427                 (void *)&cmd_flow_director_queue_id,
11428                 (void *)&cmd_flow_director_fd_id,
11429                 (void *)&cmd_flow_director_fd_id_value,
11430                 NULL,
11431         },
11432 };
11433
11434 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11435         .f = cmd_flow_director_filter_parsed,
11436         .data = NULL,
11437         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11438                 "director entry on NIC",
11439         .tokens = {
11440                 (void *)&cmd_flow_director_filter,
11441                 (void *)&cmd_flow_director_port_id,
11442                 (void *)&cmd_flow_director_mode,
11443                 (void *)&cmd_flow_director_mode_mac_vlan,
11444                 (void *)&cmd_flow_director_ops,
11445                 (void *)&cmd_flow_director_mac,
11446                 (void *)&cmd_flow_director_mac_addr,
11447                 (void *)&cmd_flow_director_vlan,
11448                 (void *)&cmd_flow_director_vlan_value,
11449                 (void *)&cmd_flow_director_flexbytes,
11450                 (void *)&cmd_flow_director_flexbytes_value,
11451                 (void *)&cmd_flow_director_drop,
11452                 (void *)&cmd_flow_director_queue,
11453                 (void *)&cmd_flow_director_queue_id,
11454                 (void *)&cmd_flow_director_fd_id,
11455                 (void *)&cmd_flow_director_fd_id_value,
11456                 NULL,
11457         },
11458 };
11459
11460 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11461         .f = cmd_flow_director_filter_parsed,
11462         .data = NULL,
11463         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11464                 "director entry on NIC",
11465         .tokens = {
11466                 (void *)&cmd_flow_director_filter,
11467                 (void *)&cmd_flow_director_port_id,
11468                 (void *)&cmd_flow_director_mode,
11469                 (void *)&cmd_flow_director_mode_tunnel,
11470                 (void *)&cmd_flow_director_ops,
11471                 (void *)&cmd_flow_director_mac,
11472                 (void *)&cmd_flow_director_mac_addr,
11473                 (void *)&cmd_flow_director_vlan,
11474                 (void *)&cmd_flow_director_vlan_value,
11475                 (void *)&cmd_flow_director_tunnel,
11476                 (void *)&cmd_flow_director_tunnel_type,
11477                 (void *)&cmd_flow_director_tunnel_id,
11478                 (void *)&cmd_flow_director_tunnel_id_value,
11479                 (void *)&cmd_flow_director_flexbytes,
11480                 (void *)&cmd_flow_director_flexbytes_value,
11481                 (void *)&cmd_flow_director_drop,
11482                 (void *)&cmd_flow_director_queue,
11483                 (void *)&cmd_flow_director_queue_id,
11484                 (void *)&cmd_flow_director_fd_id,
11485                 (void *)&cmd_flow_director_fd_id_value,
11486                 NULL,
11487         },
11488 };
11489
11490 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11491         .f = cmd_flow_director_filter_parsed,
11492         .data = NULL,
11493         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11494                 "director entry on NIC",
11495         .tokens = {
11496                 (void *)&cmd_flow_director_filter,
11497                 (void *)&cmd_flow_director_port_id,
11498                 (void *)&cmd_flow_director_mode,
11499                 (void *)&cmd_flow_director_mode_raw,
11500                 (void *)&cmd_flow_director_ops,
11501                 (void *)&cmd_flow_director_flow,
11502                 (void *)&cmd_flow_director_flow_type,
11503                 (void *)&cmd_flow_director_drop,
11504                 (void *)&cmd_flow_director_queue,
11505                 (void *)&cmd_flow_director_queue_id,
11506                 (void *)&cmd_flow_director_fd_id,
11507                 (void *)&cmd_flow_director_fd_id_value,
11508                 (void *)&cmd_flow_director_packet,
11509                 (void *)&cmd_flow_director_filepath,
11510                 NULL,
11511         },
11512 };
11513
11514 struct cmd_flush_flow_director_result {
11515         cmdline_fixed_string_t flush_flow_director;
11516         portid_t port_id;
11517 };
11518
11519 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11520         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11521                                  flush_flow_director, "flush_flow_director");
11522 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11523         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11524                               port_id, UINT16);
11525
11526 static void
11527 cmd_flush_flow_director_parsed(void *parsed_result,
11528                           __attribute__((unused)) struct cmdline *cl,
11529                           __attribute__((unused)) void *data)
11530 {
11531         struct cmd_flow_director_result *res = parsed_result;
11532         int ret = 0;
11533
11534         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11535         if (ret < 0) {
11536                 printf("flow director is not supported on port %u.\n",
11537                         res->port_id);
11538                 return;
11539         }
11540
11541         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11542                         RTE_ETH_FILTER_FLUSH, NULL);
11543         if (ret < 0)
11544                 printf("flow director table flushing error: (%s)\n",
11545                         strerror(-ret));
11546 }
11547
11548 cmdline_parse_inst_t cmd_flush_flow_director = {
11549         .f = cmd_flush_flow_director_parsed,
11550         .data = NULL,
11551         .help_str = "flush_flow_director <port_id>: "
11552                 "Flush all flow director entries of a device on NIC",
11553         .tokens = {
11554                 (void *)&cmd_flush_flow_director_flush,
11555                 (void *)&cmd_flush_flow_director_port_id,
11556                 NULL,
11557         },
11558 };
11559
11560 /* *** deal with flow director mask *** */
11561 struct cmd_flow_director_mask_result {
11562         cmdline_fixed_string_t flow_director_mask;
11563         portid_t port_id;
11564         cmdline_fixed_string_t mode;
11565         cmdline_fixed_string_t mode_value;
11566         cmdline_fixed_string_t vlan;
11567         uint16_t vlan_mask;
11568         cmdline_fixed_string_t src_mask;
11569         cmdline_ipaddr_t ipv4_src;
11570         cmdline_ipaddr_t ipv6_src;
11571         uint16_t port_src;
11572         cmdline_fixed_string_t dst_mask;
11573         cmdline_ipaddr_t ipv4_dst;
11574         cmdline_ipaddr_t ipv6_dst;
11575         uint16_t port_dst;
11576         cmdline_fixed_string_t mac;
11577         uint8_t mac_addr_byte_mask;
11578         cmdline_fixed_string_t tunnel_id;
11579         uint32_t tunnel_id_mask;
11580         cmdline_fixed_string_t tunnel_type;
11581         uint8_t tunnel_type_mask;
11582 };
11583
11584 static void
11585 cmd_flow_director_mask_parsed(void *parsed_result,
11586                           __attribute__((unused)) struct cmdline *cl,
11587                           __attribute__((unused)) void *data)
11588 {
11589         struct cmd_flow_director_mask_result *res = parsed_result;
11590         struct rte_eth_fdir_masks *mask;
11591         struct rte_port *port;
11592
11593         port = &ports[res->port_id];
11594         /** Check if the port is not started **/
11595         if (port->port_status != RTE_PORT_STOPPED) {
11596                 printf("Please stop port %d first\n", res->port_id);
11597                 return;
11598         }
11599
11600         mask = &port->dev_conf.fdir_conf.mask;
11601
11602         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11603                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11604                         printf("Please set mode to MAC-VLAN.\n");
11605                         return;
11606                 }
11607
11608                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11609         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11610                 if (strcmp(res->mode_value, "Tunnel")) {
11611                         printf("Please set mode to Tunnel.\n");
11612                         return;
11613                 }
11614
11615                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11616                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11617                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11618                 mask->tunnel_type_mask = res->tunnel_type_mask;
11619         } else {
11620                 if (strcmp(res->mode_value, "IP")) {
11621                         printf("Please set mode to IP.\n");
11622                         return;
11623                 }
11624
11625                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11626                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11627                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11628                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11629                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11630                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11631                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11632         }
11633
11634         cmd_reconfig_device_queue(res->port_id, 1, 1);
11635 }
11636
11637 cmdline_parse_token_string_t cmd_flow_director_mask =
11638         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11639                                  flow_director_mask, "flow_director_mask");
11640 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11641         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11642                               port_id, UINT16);
11643 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11644         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11645                                  vlan, "vlan");
11646 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11647         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11648                               vlan_mask, UINT16);
11649 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11650         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11651                                  src_mask, "src_mask");
11652 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11653         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11654                                  ipv4_src);
11655 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11656         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11657                                  ipv6_src);
11658 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11659         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11660                               port_src, UINT16);
11661 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11662         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11663                                  dst_mask, "dst_mask");
11664 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11665         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11666                                  ipv4_dst);
11667 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11668         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11669                                  ipv6_dst);
11670 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11671         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11672                               port_dst, UINT16);
11673
11674 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11675         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11676                                  mode, "mode");
11677 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11678         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11679                                  mode_value, "IP");
11680 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11681         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11682                                  mode_value, "MAC-VLAN");
11683 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11684         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11685                                  mode_value, "Tunnel");
11686 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11687         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11688                                  mac, "mac");
11689 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11690         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11691                               mac_addr_byte_mask, UINT8);
11692 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11693         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11694                                  tunnel_type, "tunnel-type");
11695 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11696         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11697                               tunnel_type_mask, UINT8);
11698 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11699         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11700                                  tunnel_id, "tunnel-id");
11701 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11702         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11703                               tunnel_id_mask, UINT32);
11704
11705 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11706         .f = cmd_flow_director_mask_parsed,
11707         .data = NULL,
11708         .help_str = "flow_director_mask ... : "
11709                 "Set IP mode flow director's mask on NIC",
11710         .tokens = {
11711                 (void *)&cmd_flow_director_mask,
11712                 (void *)&cmd_flow_director_mask_port_id,
11713                 (void *)&cmd_flow_director_mask_mode,
11714                 (void *)&cmd_flow_director_mask_mode_ip,
11715                 (void *)&cmd_flow_director_mask_vlan,
11716                 (void *)&cmd_flow_director_mask_vlan_value,
11717                 (void *)&cmd_flow_director_mask_src,
11718                 (void *)&cmd_flow_director_mask_ipv4_src,
11719                 (void *)&cmd_flow_director_mask_ipv6_src,
11720                 (void *)&cmd_flow_director_mask_port_src,
11721                 (void *)&cmd_flow_director_mask_dst,
11722                 (void *)&cmd_flow_director_mask_ipv4_dst,
11723                 (void *)&cmd_flow_director_mask_ipv6_dst,
11724                 (void *)&cmd_flow_director_mask_port_dst,
11725                 NULL,
11726         },
11727 };
11728
11729 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11730         .f = cmd_flow_director_mask_parsed,
11731         .data = NULL,
11732         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11733                 "flow director's mask on NIC",
11734         .tokens = {
11735                 (void *)&cmd_flow_director_mask,
11736                 (void *)&cmd_flow_director_mask_port_id,
11737                 (void *)&cmd_flow_director_mask_mode,
11738                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11739                 (void *)&cmd_flow_director_mask_vlan,
11740                 (void *)&cmd_flow_director_mask_vlan_value,
11741                 NULL,
11742         },
11743 };
11744
11745 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11746         .f = cmd_flow_director_mask_parsed,
11747         .data = NULL,
11748         .help_str = "flow_director_mask ... : Set tunnel mode "
11749                 "flow director's mask on NIC",
11750         .tokens = {
11751                 (void *)&cmd_flow_director_mask,
11752                 (void *)&cmd_flow_director_mask_port_id,
11753                 (void *)&cmd_flow_director_mask_mode,
11754                 (void *)&cmd_flow_director_mask_mode_tunnel,
11755                 (void *)&cmd_flow_director_mask_vlan,
11756                 (void *)&cmd_flow_director_mask_vlan_value,
11757                 (void *)&cmd_flow_director_mask_mac,
11758                 (void *)&cmd_flow_director_mask_mac_value,
11759                 (void *)&cmd_flow_director_mask_tunnel_type,
11760                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11761                 (void *)&cmd_flow_director_mask_tunnel_id,
11762                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11763                 NULL,
11764         },
11765 };
11766
11767 /* *** deal with flow director mask on flexible payload *** */
11768 struct cmd_flow_director_flex_mask_result {
11769         cmdline_fixed_string_t flow_director_flexmask;
11770         portid_t port_id;
11771         cmdline_fixed_string_t flow;
11772         cmdline_fixed_string_t flow_type;
11773         cmdline_fixed_string_t mask;
11774 };
11775
11776 static void
11777 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11778                           __attribute__((unused)) struct cmdline *cl,
11779                           __attribute__((unused)) void *data)
11780 {
11781         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11782         struct rte_eth_fdir_info fdir_info;
11783         struct rte_eth_fdir_flex_mask flex_mask;
11784         struct rte_port *port;
11785         uint64_t flow_type_mask;
11786         uint16_t i;
11787         int ret;
11788
11789         port = &ports[res->port_id];
11790         /** Check if the port is not started **/
11791         if (port->port_status != RTE_PORT_STOPPED) {
11792                 printf("Please stop port %d first\n", res->port_id);
11793                 return;
11794         }
11795
11796         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11797         ret = parse_flexbytes(res->mask,
11798                         flex_mask.mask,
11799                         RTE_ETH_FDIR_MAX_FLEXLEN);
11800         if (ret < 0) {
11801                 printf("error: Cannot parse mask input.\n");
11802                 return;
11803         }
11804
11805         memset(&fdir_info, 0, sizeof(fdir_info));
11806         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11807                                 RTE_ETH_FILTER_INFO, &fdir_info);
11808         if (ret < 0) {
11809                 printf("Cannot get FDir filter info\n");
11810                 return;
11811         }
11812
11813         if (!strcmp(res->flow_type, "none")) {
11814                 /* means don't specify the flow type */
11815                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11816                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11817                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11818                                0, sizeof(struct rte_eth_fdir_flex_mask));
11819                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11820                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11821                                  &flex_mask,
11822                                  sizeof(struct rte_eth_fdir_flex_mask));
11823                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11824                 return;
11825         }
11826         flow_type_mask = fdir_info.flow_types_mask[0];
11827         if (!strcmp(res->flow_type, "all")) {
11828                 if (!flow_type_mask) {
11829                         printf("No flow type supported\n");
11830                         return;
11831                 }
11832                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11833                         if (flow_type_mask & (1ULL << i)) {
11834                                 flex_mask.flow_type = i;
11835                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11836                         }
11837                 }
11838                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11839                 return;
11840         }
11841         flex_mask.flow_type = str2flowtype(res->flow_type);
11842         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11843                 printf("Flow type %s not supported on port %d\n",
11844                                 res->flow_type, res->port_id);
11845                 return;
11846         }
11847         fdir_set_flex_mask(res->port_id, &flex_mask);
11848         cmd_reconfig_device_queue(res->port_id, 1, 1);
11849 }
11850
11851 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11852         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11853                                  flow_director_flexmask,
11854                                  "flow_director_flex_mask");
11855 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11856         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11857                               port_id, UINT16);
11858 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11859         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11860                                  flow, "flow");
11861 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11862         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11863                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11864                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11865 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11866         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11867                                  mask, NULL);
11868
11869 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11870         .f = cmd_flow_director_flex_mask_parsed,
11871         .data = NULL,
11872         .help_str = "flow_director_flex_mask ... : "
11873                 "Set flow director's flex mask on NIC",
11874         .tokens = {
11875                 (void *)&cmd_flow_director_flexmask,
11876                 (void *)&cmd_flow_director_flexmask_port_id,
11877                 (void *)&cmd_flow_director_flexmask_flow,
11878                 (void *)&cmd_flow_director_flexmask_flow_type,
11879                 (void *)&cmd_flow_director_flexmask_mask,
11880                 NULL,
11881         },
11882 };
11883
11884 /* *** deal with flow director flexible payload configuration *** */
11885 struct cmd_flow_director_flexpayload_result {
11886         cmdline_fixed_string_t flow_director_flexpayload;
11887         portid_t port_id;
11888         cmdline_fixed_string_t payload_layer;
11889         cmdline_fixed_string_t payload_cfg;
11890 };
11891
11892 static inline int
11893 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11894 {
11895         char s[256];
11896         const char *p, *p0 = q_arg;
11897         char *end;
11898         unsigned long int_fld;
11899         char *str_fld[max_num];
11900         int i;
11901         unsigned size;
11902         int ret = -1;
11903
11904         p = strchr(p0, '(');
11905         if (p == NULL)
11906                 return -1;
11907         ++p;
11908         p0 = strchr(p, ')');
11909         if (p0 == NULL)
11910                 return -1;
11911
11912         size = p0 - p;
11913         if (size >= sizeof(s))
11914                 return -1;
11915
11916         snprintf(s, sizeof(s), "%.*s", size, p);
11917         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11918         if (ret < 0 || ret > max_num)
11919                 return -1;
11920         for (i = 0; i < ret; i++) {
11921                 errno = 0;
11922                 int_fld = strtoul(str_fld[i], &end, 0);
11923                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11924                         return -1;
11925                 offsets[i] = (uint16_t)int_fld;
11926         }
11927         return ret;
11928 }
11929
11930 static void
11931 cmd_flow_director_flxpld_parsed(void *parsed_result,
11932                           __attribute__((unused)) struct cmdline *cl,
11933                           __attribute__((unused)) void *data)
11934 {
11935         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11936         struct rte_eth_flex_payload_cfg flex_cfg;
11937         struct rte_port *port;
11938         int ret = 0;
11939
11940         port = &ports[res->port_id];
11941         /** Check if the port is not started **/
11942         if (port->port_status != RTE_PORT_STOPPED) {
11943                 printf("Please stop port %d first\n", res->port_id);
11944                 return;
11945         }
11946
11947         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11948
11949         if (!strcmp(res->payload_layer, "raw"))
11950                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11951         else if (!strcmp(res->payload_layer, "l2"))
11952                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11953         else if (!strcmp(res->payload_layer, "l3"))
11954                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11955         else if (!strcmp(res->payload_layer, "l4"))
11956                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11957
11958         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11959                             RTE_ETH_FDIR_MAX_FLEXLEN);
11960         if (ret < 0) {
11961                 printf("error: Cannot parse flex payload input.\n");
11962                 return;
11963         }
11964
11965         fdir_set_flex_payload(res->port_id, &flex_cfg);
11966         cmd_reconfig_device_queue(res->port_id, 1, 1);
11967 }
11968
11969 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11970         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11971                                  flow_director_flexpayload,
11972                                  "flow_director_flex_payload");
11973 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11974         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11975                               port_id, UINT16);
11976 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11977         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11978                                  payload_layer, "raw#l2#l3#l4");
11979 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11980         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11981                                  payload_cfg, NULL);
11982
11983 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11984         .f = cmd_flow_director_flxpld_parsed,
11985         .data = NULL,
11986         .help_str = "flow_director_flexpayload ... : "
11987                 "Set flow director's flex payload on NIC",
11988         .tokens = {
11989                 (void *)&cmd_flow_director_flexpayload,
11990                 (void *)&cmd_flow_director_flexpayload_port_id,
11991                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11992                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11993                 NULL,
11994         },
11995 };
11996
11997 /* Generic flow interface command. */
11998 extern cmdline_parse_inst_t cmd_flow;
11999
12000 /* *** Classification Filters Control *** */
12001 /* *** Get symmetric hash enable per port *** */
12002 struct cmd_get_sym_hash_ena_per_port_result {
12003         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12004         portid_t port_id;
12005 };
12006
12007 static void
12008 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12009                                  __rte_unused struct cmdline *cl,
12010                                  __rte_unused void *data)
12011 {
12012         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12013         struct rte_eth_hash_filter_info info;
12014         int ret;
12015
12016         if (rte_eth_dev_filter_supported(res->port_id,
12017                                 RTE_ETH_FILTER_HASH) < 0) {
12018                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12019                                                         res->port_id);
12020                 return;
12021         }
12022
12023         memset(&info, 0, sizeof(info));
12024         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12025         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12026                                                 RTE_ETH_FILTER_GET, &info);
12027
12028         if (ret < 0) {
12029                 printf("Cannot get symmetric hash enable per port "
12030                                         "on port %u\n", res->port_id);
12031                 return;
12032         }
12033
12034         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12035                                 "enabled" : "disabled", res->port_id);
12036 }
12037
12038 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12039         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12040                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12041 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12042         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12043                 port_id, UINT16);
12044
12045 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12046         .f = cmd_get_sym_hash_per_port_parsed,
12047         .data = NULL,
12048         .help_str = "get_sym_hash_ena_per_port <port_id>",
12049         .tokens = {
12050                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12051                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12052                 NULL,
12053         },
12054 };
12055
12056 /* *** Set symmetric hash enable per port *** */
12057 struct cmd_set_sym_hash_ena_per_port_result {
12058         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12059         cmdline_fixed_string_t enable;
12060         portid_t port_id;
12061 };
12062
12063 static void
12064 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12065                                  __rte_unused struct cmdline *cl,
12066                                  __rte_unused void *data)
12067 {
12068         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12069         struct rte_eth_hash_filter_info info;
12070         int ret;
12071
12072         if (rte_eth_dev_filter_supported(res->port_id,
12073                                 RTE_ETH_FILTER_HASH) < 0) {
12074                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12075                                                         res->port_id);
12076                 return;
12077         }
12078
12079         memset(&info, 0, sizeof(info));
12080         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12081         if (!strcmp(res->enable, "enable"))
12082                 info.info.enable = 1;
12083         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12084                                         RTE_ETH_FILTER_SET, &info);
12085         if (ret < 0) {
12086                 printf("Cannot set symmetric hash enable per port on "
12087                                         "port %u\n", res->port_id);
12088                 return;
12089         }
12090         printf("Symmetric hash has been set to %s on port %u\n",
12091                                         res->enable, res->port_id);
12092 }
12093
12094 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12095         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12096                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12097 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12098         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12099                 port_id, UINT16);
12100 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12101         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12102                 enable, "enable#disable");
12103
12104 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12105         .f = cmd_set_sym_hash_per_port_parsed,
12106         .data = NULL,
12107         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12108         .tokens = {
12109                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12110                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12111                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12112                 NULL,
12113         },
12114 };
12115
12116 /* Get global config of hash function */
12117 struct cmd_get_hash_global_config_result {
12118         cmdline_fixed_string_t get_hash_global_config;
12119         portid_t port_id;
12120 };
12121
12122 static char *
12123 flowtype_to_str(uint16_t ftype)
12124 {
12125         uint16_t i;
12126         static struct {
12127                 char str[16];
12128                 uint16_t ftype;
12129         } ftype_table[] = {
12130                 {"ipv4", RTE_ETH_FLOW_IPV4},
12131                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12132                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12133                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12134                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12135                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12136                 {"ipv6", RTE_ETH_FLOW_IPV6},
12137                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12138                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12139                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12140                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12141                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12142                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12143                 {"port", RTE_ETH_FLOW_PORT},
12144                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12145                 {"geneve", RTE_ETH_FLOW_GENEVE},
12146                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12147                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12148         };
12149
12150         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12151                 if (ftype_table[i].ftype == ftype)
12152                         return ftype_table[i].str;
12153         }
12154
12155         return NULL;
12156 }
12157
12158 static void
12159 cmd_get_hash_global_config_parsed(void *parsed_result,
12160                                   __rte_unused struct cmdline *cl,
12161                                   __rte_unused void *data)
12162 {
12163         struct cmd_get_hash_global_config_result *res = parsed_result;
12164         struct rte_eth_hash_filter_info info;
12165         uint32_t idx, offset;
12166         uint16_t i;
12167         char *str;
12168         int ret;
12169
12170         if (rte_eth_dev_filter_supported(res->port_id,
12171                         RTE_ETH_FILTER_HASH) < 0) {
12172                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12173                                                         res->port_id);
12174                 return;
12175         }
12176
12177         memset(&info, 0, sizeof(info));
12178         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12179         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12180                                         RTE_ETH_FILTER_GET, &info);
12181         if (ret < 0) {
12182                 printf("Cannot get hash global configurations by port %d\n",
12183                                                         res->port_id);
12184                 return;
12185         }
12186
12187         switch (info.info.global_conf.hash_func) {
12188         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12189                 printf("Hash function is Toeplitz\n");
12190                 break;
12191         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12192                 printf("Hash function is Simple XOR\n");
12193                 break;
12194         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12195                 printf("Hash function is Symmetric Toeplitz\n");
12196                 break;
12197         default:
12198                 printf("Unknown hash function\n");
12199                 break;
12200         }
12201
12202         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12203                 idx = i / UINT64_BIT;
12204                 offset = i % UINT64_BIT;
12205                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12206                                                 (1ULL << offset)))
12207                         continue;
12208                 str = flowtype_to_str(i);
12209                 if (!str)
12210                         continue;
12211                 printf("Symmetric hash is %s globally for flow type %s "
12212                                                         "by port %d\n",
12213                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12214                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12215                                                         res->port_id);
12216         }
12217 }
12218
12219 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12220         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12221                 get_hash_global_config, "get_hash_global_config");
12222 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12223         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12224                 port_id, UINT16);
12225
12226 cmdline_parse_inst_t cmd_get_hash_global_config = {
12227         .f = cmd_get_hash_global_config_parsed,
12228         .data = NULL,
12229         .help_str = "get_hash_global_config <port_id>",
12230         .tokens = {
12231                 (void *)&cmd_get_hash_global_config_all,
12232                 (void *)&cmd_get_hash_global_config_port_id,
12233                 NULL,
12234         },
12235 };
12236
12237 /* Set global config of hash function */
12238 struct cmd_set_hash_global_config_result {
12239         cmdline_fixed_string_t set_hash_global_config;
12240         portid_t port_id;
12241         cmdline_fixed_string_t hash_func;
12242         cmdline_fixed_string_t flow_type;
12243         cmdline_fixed_string_t enable;
12244 };
12245
12246 static void
12247 cmd_set_hash_global_config_parsed(void *parsed_result,
12248                                   __rte_unused struct cmdline *cl,
12249                                   __rte_unused void *data)
12250 {
12251         struct cmd_set_hash_global_config_result *res = parsed_result;
12252         struct rte_eth_hash_filter_info info;
12253         uint32_t ftype, idx, offset;
12254         int ret;
12255
12256         if (rte_eth_dev_filter_supported(res->port_id,
12257                                 RTE_ETH_FILTER_HASH) < 0) {
12258                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12259                                                         res->port_id);
12260                 return;
12261         }
12262         memset(&info, 0, sizeof(info));
12263         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12264         if (!strcmp(res->hash_func, "toeplitz"))
12265                 info.info.global_conf.hash_func =
12266                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12267         else if (!strcmp(res->hash_func, "simple_xor"))
12268                 info.info.global_conf.hash_func =
12269                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12270         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12271                 info.info.global_conf.hash_func =
12272                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12273         else if (!strcmp(res->hash_func, "default"))
12274                 info.info.global_conf.hash_func =
12275                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12276
12277         ftype = str2flowtype(res->flow_type);
12278         idx = ftype / UINT64_BIT;
12279         offset = ftype % UINT64_BIT;
12280         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12281         if (!strcmp(res->enable, "enable"))
12282                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12283                                                 (1ULL << offset);
12284         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12285                                         RTE_ETH_FILTER_SET, &info);
12286         if (ret < 0)
12287                 printf("Cannot set global hash configurations by port %d\n",
12288                                                         res->port_id);
12289         else
12290                 printf("Global hash configurations have been set "
12291                         "successfully by port %d\n", res->port_id);
12292 }
12293
12294 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12295         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12296                 set_hash_global_config, "set_hash_global_config");
12297 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12298         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12299                 port_id, UINT16);
12300 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12301         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12302                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12303 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12304         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12305                 flow_type,
12306                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12307                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12308 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12309         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12310                 enable, "enable#disable");
12311
12312 cmdline_parse_inst_t cmd_set_hash_global_config = {
12313         .f = cmd_set_hash_global_config_parsed,
12314         .data = NULL,
12315         .help_str = "set_hash_global_config <port_id> "
12316                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12317                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12318                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12319                 "l2_payload enable|disable",
12320         .tokens = {
12321                 (void *)&cmd_set_hash_global_config_all,
12322                 (void *)&cmd_set_hash_global_config_port_id,
12323                 (void *)&cmd_set_hash_global_config_hash_func,
12324                 (void *)&cmd_set_hash_global_config_flow_type,
12325                 (void *)&cmd_set_hash_global_config_enable,
12326                 NULL,
12327         },
12328 };
12329
12330 /* Set hash input set */
12331 struct cmd_set_hash_input_set_result {
12332         cmdline_fixed_string_t set_hash_input_set;
12333         portid_t port_id;
12334         cmdline_fixed_string_t flow_type;
12335         cmdline_fixed_string_t inset_field;
12336         cmdline_fixed_string_t select;
12337 };
12338
12339 static enum rte_eth_input_set_field
12340 str2inset(char *string)
12341 {
12342         uint16_t i;
12343
12344         static const struct {
12345                 char str[32];
12346                 enum rte_eth_input_set_field inset;
12347         } inset_table[] = {
12348                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12349                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12350                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12351                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12352                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12353                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12354                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12355                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12356                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12357                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12358                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12359                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12360                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12361                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12362                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12363                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12364                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12365                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12366                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12367                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12368                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12369                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12370                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12371                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12372                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12373                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12374                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12375                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12376                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12377                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12378                 {"none", RTE_ETH_INPUT_SET_NONE},
12379         };
12380
12381         for (i = 0; i < RTE_DIM(inset_table); i++) {
12382                 if (!strcmp(string, inset_table[i].str))
12383                         return inset_table[i].inset;
12384         }
12385
12386         return RTE_ETH_INPUT_SET_UNKNOWN;
12387 }
12388
12389 static void
12390 cmd_set_hash_input_set_parsed(void *parsed_result,
12391                               __rte_unused struct cmdline *cl,
12392                               __rte_unused void *data)
12393 {
12394         struct cmd_set_hash_input_set_result *res = parsed_result;
12395         struct rte_eth_hash_filter_info info;
12396
12397         memset(&info, 0, sizeof(info));
12398         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12399         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12400         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12401         info.info.input_set_conf.inset_size = 1;
12402         if (!strcmp(res->select, "select"))
12403                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12404         else if (!strcmp(res->select, "add"))
12405                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12406         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12407                                 RTE_ETH_FILTER_SET, &info);
12408 }
12409
12410 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12411         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12412                 set_hash_input_set, "set_hash_input_set");
12413 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12414         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12415                 port_id, UINT16);
12416 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12417         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12418                 flow_type, NULL);
12419 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12420         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12421                 inset_field,
12422                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12423                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12424                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12425                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12426                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12427                 "fld-8th#none");
12428 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12429         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12430                 select, "select#add");
12431
12432 cmdline_parse_inst_t cmd_set_hash_input_set = {
12433         .f = cmd_set_hash_input_set_parsed,
12434         .data = NULL,
12435         .help_str = "set_hash_input_set <port_id> "
12436         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12437         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12438         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12439         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12440         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12441         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12442         "fld-7th|fld-8th|none select|add",
12443         .tokens = {
12444                 (void *)&cmd_set_hash_input_set_cmd,
12445                 (void *)&cmd_set_hash_input_set_port_id,
12446                 (void *)&cmd_set_hash_input_set_flow_type,
12447                 (void *)&cmd_set_hash_input_set_field,
12448                 (void *)&cmd_set_hash_input_set_select,
12449                 NULL,
12450         },
12451 };
12452
12453 /* Set flow director input set */
12454 struct cmd_set_fdir_input_set_result {
12455         cmdline_fixed_string_t set_fdir_input_set;
12456         portid_t port_id;
12457         cmdline_fixed_string_t flow_type;
12458         cmdline_fixed_string_t inset_field;
12459         cmdline_fixed_string_t select;
12460 };
12461
12462 static void
12463 cmd_set_fdir_input_set_parsed(void *parsed_result,
12464         __rte_unused struct cmdline *cl,
12465         __rte_unused void *data)
12466 {
12467         struct cmd_set_fdir_input_set_result *res = parsed_result;
12468         struct rte_eth_fdir_filter_info info;
12469
12470         memset(&info, 0, sizeof(info));
12471         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12472         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12473         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12474         info.info.input_set_conf.inset_size = 1;
12475         if (!strcmp(res->select, "select"))
12476                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12477         else if (!strcmp(res->select, "add"))
12478                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12479         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12480                 RTE_ETH_FILTER_SET, &info);
12481 }
12482
12483 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12484         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12485         set_fdir_input_set, "set_fdir_input_set");
12486 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12487         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12488         port_id, UINT16);
12489 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12490         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12491         flow_type,
12492         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12493         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12494 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12495         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12496         inset_field,
12497         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12498         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12499         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12500         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12501         "sctp-veri-tag#none");
12502 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12503         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12504         select, "select#add");
12505
12506 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12507         .f = cmd_set_fdir_input_set_parsed,
12508         .data = NULL,
12509         .help_str = "set_fdir_input_set <port_id> "
12510         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12511         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12512         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12513         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12514         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12515         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12516         "sctp-veri-tag|none select|add",
12517         .tokens = {
12518                 (void *)&cmd_set_fdir_input_set_cmd,
12519                 (void *)&cmd_set_fdir_input_set_port_id,
12520                 (void *)&cmd_set_fdir_input_set_flow_type,
12521                 (void *)&cmd_set_fdir_input_set_field,
12522                 (void *)&cmd_set_fdir_input_set_select,
12523                 NULL,
12524         },
12525 };
12526
12527 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12528 struct cmd_mcast_addr_result {
12529         cmdline_fixed_string_t mcast_addr_cmd;
12530         cmdline_fixed_string_t what;
12531         uint16_t port_num;
12532         struct rte_ether_addr mc_addr;
12533 };
12534
12535 static void cmd_mcast_addr_parsed(void *parsed_result,
12536                 __attribute__((unused)) struct cmdline *cl,
12537                 __attribute__((unused)) void *data)
12538 {
12539         struct cmd_mcast_addr_result *res = parsed_result;
12540
12541         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12542                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12543                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12544                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12545                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12546                 return;
12547         }
12548         if (strcmp(res->what, "add") == 0)
12549                 mcast_addr_add(res->port_num, &res->mc_addr);
12550         else
12551                 mcast_addr_remove(res->port_num, &res->mc_addr);
12552 }
12553
12554 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12555         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12556                                  mcast_addr_cmd, "mcast_addr");
12557 cmdline_parse_token_string_t cmd_mcast_addr_what =
12558         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12559                                  "add#remove");
12560 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12561         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12562 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12563         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12564
12565 cmdline_parse_inst_t cmd_mcast_addr = {
12566         .f = cmd_mcast_addr_parsed,
12567         .data = (void *)0,
12568         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12569                 "Add/Remove multicast MAC address on port_id",
12570         .tokens = {
12571                 (void *)&cmd_mcast_addr_cmd,
12572                 (void *)&cmd_mcast_addr_what,
12573                 (void *)&cmd_mcast_addr_portnum,
12574                 (void *)&cmd_mcast_addr_addr,
12575                 NULL,
12576         },
12577 };
12578
12579 /* l2 tunnel config
12580  * only support E-tag now.
12581  */
12582
12583 /* Ether type config */
12584 struct cmd_config_l2_tunnel_eth_type_result {
12585         cmdline_fixed_string_t port;
12586         cmdline_fixed_string_t config;
12587         cmdline_fixed_string_t all;
12588         portid_t id;
12589         cmdline_fixed_string_t l2_tunnel;
12590         cmdline_fixed_string_t l2_tunnel_type;
12591         cmdline_fixed_string_t eth_type;
12592         uint16_t eth_type_val;
12593 };
12594
12595 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12596         TOKEN_STRING_INITIALIZER
12597                 (struct cmd_config_l2_tunnel_eth_type_result,
12598                  port, "port");
12599 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12600         TOKEN_STRING_INITIALIZER
12601                 (struct cmd_config_l2_tunnel_eth_type_result,
12602                  config, "config");
12603 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12604         TOKEN_STRING_INITIALIZER
12605                 (struct cmd_config_l2_tunnel_eth_type_result,
12606                  all, "all");
12607 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12608         TOKEN_NUM_INITIALIZER
12609                 (struct cmd_config_l2_tunnel_eth_type_result,
12610                  id, UINT16);
12611 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12612         TOKEN_STRING_INITIALIZER
12613                 (struct cmd_config_l2_tunnel_eth_type_result,
12614                  l2_tunnel, "l2-tunnel");
12615 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12616         TOKEN_STRING_INITIALIZER
12617                 (struct cmd_config_l2_tunnel_eth_type_result,
12618                  l2_tunnel_type, "E-tag");
12619 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12620         TOKEN_STRING_INITIALIZER
12621                 (struct cmd_config_l2_tunnel_eth_type_result,
12622                  eth_type, "ether-type");
12623 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12624         TOKEN_NUM_INITIALIZER
12625                 (struct cmd_config_l2_tunnel_eth_type_result,
12626                  eth_type_val, UINT16);
12627
12628 static enum rte_eth_tunnel_type
12629 str2fdir_l2_tunnel_type(char *string)
12630 {
12631         uint32_t i = 0;
12632
12633         static const struct {
12634                 char str[32];
12635                 enum rte_eth_tunnel_type type;
12636         } l2_tunnel_type_str[] = {
12637                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12638         };
12639
12640         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12641                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12642                         return l2_tunnel_type_str[i].type;
12643         }
12644         return RTE_TUNNEL_TYPE_NONE;
12645 }
12646
12647 /* ether type config for all ports */
12648 static void
12649 cmd_config_l2_tunnel_eth_type_all_parsed
12650         (void *parsed_result,
12651          __attribute__((unused)) struct cmdline *cl,
12652          __attribute__((unused)) void *data)
12653 {
12654         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12655         struct rte_eth_l2_tunnel_conf entry;
12656         portid_t pid;
12657
12658         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12659         entry.ether_type = res->eth_type_val;
12660
12661         RTE_ETH_FOREACH_DEV(pid) {
12662                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12663         }
12664 }
12665
12666 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12667         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12668         .data = NULL,
12669         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12670         .tokens = {
12671                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12672                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12673                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12674                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12675                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12676                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12677                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12678                 NULL,
12679         },
12680 };
12681
12682 /* ether type config for a specific port */
12683 static void
12684 cmd_config_l2_tunnel_eth_type_specific_parsed(
12685         void *parsed_result,
12686         __attribute__((unused)) struct cmdline *cl,
12687         __attribute__((unused)) void *data)
12688 {
12689         struct cmd_config_l2_tunnel_eth_type_result *res =
12690                  parsed_result;
12691         struct rte_eth_l2_tunnel_conf entry;
12692
12693         if (port_id_is_invalid(res->id, ENABLED_WARN))
12694                 return;
12695
12696         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12697         entry.ether_type = res->eth_type_val;
12698
12699         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12700 }
12701
12702 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12703         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12704         .data = NULL,
12705         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12706         .tokens = {
12707                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12708                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12709                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12710                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12711                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12712                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12713                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12714                 NULL,
12715         },
12716 };
12717
12718 /* Enable/disable l2 tunnel */
12719 struct cmd_config_l2_tunnel_en_dis_result {
12720         cmdline_fixed_string_t port;
12721         cmdline_fixed_string_t config;
12722         cmdline_fixed_string_t all;
12723         portid_t id;
12724         cmdline_fixed_string_t l2_tunnel;
12725         cmdline_fixed_string_t l2_tunnel_type;
12726         cmdline_fixed_string_t en_dis;
12727 };
12728
12729 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12730         TOKEN_STRING_INITIALIZER
12731                 (struct cmd_config_l2_tunnel_en_dis_result,
12732                  port, "port");
12733 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12734         TOKEN_STRING_INITIALIZER
12735                 (struct cmd_config_l2_tunnel_en_dis_result,
12736                  config, "config");
12737 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12738         TOKEN_STRING_INITIALIZER
12739                 (struct cmd_config_l2_tunnel_en_dis_result,
12740                  all, "all");
12741 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12742         TOKEN_NUM_INITIALIZER
12743                 (struct cmd_config_l2_tunnel_en_dis_result,
12744                  id, UINT16);
12745 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12746         TOKEN_STRING_INITIALIZER
12747                 (struct cmd_config_l2_tunnel_en_dis_result,
12748                  l2_tunnel, "l2-tunnel");
12749 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12750         TOKEN_STRING_INITIALIZER
12751                 (struct cmd_config_l2_tunnel_en_dis_result,
12752                  l2_tunnel_type, "E-tag");
12753 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12754         TOKEN_STRING_INITIALIZER
12755                 (struct cmd_config_l2_tunnel_en_dis_result,
12756                  en_dis, "enable#disable");
12757
12758 /* enable/disable l2 tunnel for all ports */
12759 static void
12760 cmd_config_l2_tunnel_en_dis_all_parsed(
12761         void *parsed_result,
12762         __attribute__((unused)) struct cmdline *cl,
12763         __attribute__((unused)) void *data)
12764 {
12765         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12766         struct rte_eth_l2_tunnel_conf entry;
12767         portid_t pid;
12768         uint8_t en;
12769
12770         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12771
12772         if (!strcmp("enable", res->en_dis))
12773                 en = 1;
12774         else
12775                 en = 0;
12776
12777         RTE_ETH_FOREACH_DEV(pid) {
12778                 rte_eth_dev_l2_tunnel_offload_set(pid,
12779                                                   &entry,
12780                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12781                                                   en);
12782         }
12783 }
12784
12785 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12786         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12787         .data = NULL,
12788         .help_str = "port config all l2-tunnel E-tag enable|disable",
12789         .tokens = {
12790                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12791                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12792                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12793                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12794                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12795                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12796                 NULL,
12797         },
12798 };
12799
12800 /* enable/disable l2 tunnel for a port */
12801 static void
12802 cmd_config_l2_tunnel_en_dis_specific_parsed(
12803         void *parsed_result,
12804         __attribute__((unused)) struct cmdline *cl,
12805         __attribute__((unused)) void *data)
12806 {
12807         struct cmd_config_l2_tunnel_en_dis_result *res =
12808                 parsed_result;
12809         struct rte_eth_l2_tunnel_conf entry;
12810
12811         if (port_id_is_invalid(res->id, ENABLED_WARN))
12812                 return;
12813
12814         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12815
12816         if (!strcmp("enable", res->en_dis))
12817                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12818                                                   &entry,
12819                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12820                                                   1);
12821         else
12822                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12823                                                   &entry,
12824                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12825                                                   0);
12826 }
12827
12828 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12829         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12830         .data = NULL,
12831         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12832         .tokens = {
12833                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12834                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12835                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12836                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12837                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12838                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12839                 NULL,
12840         },
12841 };
12842
12843 /* E-tag configuration */
12844
12845 /* Common result structure for all E-tag configuration */
12846 struct cmd_config_e_tag_result {
12847         cmdline_fixed_string_t e_tag;
12848         cmdline_fixed_string_t set;
12849         cmdline_fixed_string_t insertion;
12850         cmdline_fixed_string_t stripping;
12851         cmdline_fixed_string_t forwarding;
12852         cmdline_fixed_string_t filter;
12853         cmdline_fixed_string_t add;
12854         cmdline_fixed_string_t del;
12855         cmdline_fixed_string_t on;
12856         cmdline_fixed_string_t off;
12857         cmdline_fixed_string_t on_off;
12858         cmdline_fixed_string_t port_tag_id;
12859         uint32_t port_tag_id_val;
12860         cmdline_fixed_string_t e_tag_id;
12861         uint16_t e_tag_id_val;
12862         cmdline_fixed_string_t dst_pool;
12863         uint8_t dst_pool_val;
12864         cmdline_fixed_string_t port;
12865         portid_t port_id;
12866         cmdline_fixed_string_t vf;
12867         uint8_t vf_id;
12868 };
12869
12870 /* Common CLI fields for all E-tag configuration */
12871 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12872         TOKEN_STRING_INITIALIZER
12873                 (struct cmd_config_e_tag_result,
12874                  e_tag, "E-tag");
12875 cmdline_parse_token_string_t cmd_config_e_tag_set =
12876         TOKEN_STRING_INITIALIZER
12877                 (struct cmd_config_e_tag_result,
12878                  set, "set");
12879 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12880         TOKEN_STRING_INITIALIZER
12881                 (struct cmd_config_e_tag_result,
12882                  insertion, "insertion");
12883 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12884         TOKEN_STRING_INITIALIZER
12885                 (struct cmd_config_e_tag_result,
12886                  stripping, "stripping");
12887 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12888         TOKEN_STRING_INITIALIZER
12889                 (struct cmd_config_e_tag_result,
12890                  forwarding, "forwarding");
12891 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12892         TOKEN_STRING_INITIALIZER
12893                 (struct cmd_config_e_tag_result,
12894                  filter, "filter");
12895 cmdline_parse_token_string_t cmd_config_e_tag_add =
12896         TOKEN_STRING_INITIALIZER
12897                 (struct cmd_config_e_tag_result,
12898                  add, "add");
12899 cmdline_parse_token_string_t cmd_config_e_tag_del =
12900         TOKEN_STRING_INITIALIZER
12901                 (struct cmd_config_e_tag_result,
12902                  del, "del");
12903 cmdline_parse_token_string_t cmd_config_e_tag_on =
12904         TOKEN_STRING_INITIALIZER
12905                 (struct cmd_config_e_tag_result,
12906                  on, "on");
12907 cmdline_parse_token_string_t cmd_config_e_tag_off =
12908         TOKEN_STRING_INITIALIZER
12909                 (struct cmd_config_e_tag_result,
12910                  off, "off");
12911 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12912         TOKEN_STRING_INITIALIZER
12913                 (struct cmd_config_e_tag_result,
12914                  on_off, "on#off");
12915 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12916         TOKEN_STRING_INITIALIZER
12917                 (struct cmd_config_e_tag_result,
12918                  port_tag_id, "port-tag-id");
12919 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12920         TOKEN_NUM_INITIALIZER
12921                 (struct cmd_config_e_tag_result,
12922                  port_tag_id_val, UINT32);
12923 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12924         TOKEN_STRING_INITIALIZER
12925                 (struct cmd_config_e_tag_result,
12926                  e_tag_id, "e-tag-id");
12927 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12928         TOKEN_NUM_INITIALIZER
12929                 (struct cmd_config_e_tag_result,
12930                  e_tag_id_val, UINT16);
12931 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12932         TOKEN_STRING_INITIALIZER
12933                 (struct cmd_config_e_tag_result,
12934                  dst_pool, "dst-pool");
12935 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12936         TOKEN_NUM_INITIALIZER
12937                 (struct cmd_config_e_tag_result,
12938                  dst_pool_val, UINT8);
12939 cmdline_parse_token_string_t cmd_config_e_tag_port =
12940         TOKEN_STRING_INITIALIZER
12941                 (struct cmd_config_e_tag_result,
12942                  port, "port");
12943 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12944         TOKEN_NUM_INITIALIZER
12945                 (struct cmd_config_e_tag_result,
12946                  port_id, UINT16);
12947 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12948         TOKEN_STRING_INITIALIZER
12949                 (struct cmd_config_e_tag_result,
12950                  vf, "vf");
12951 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12952         TOKEN_NUM_INITIALIZER
12953                 (struct cmd_config_e_tag_result,
12954                  vf_id, UINT8);
12955
12956 /* E-tag insertion configuration */
12957 static void
12958 cmd_config_e_tag_insertion_en_parsed(
12959         void *parsed_result,
12960         __attribute__((unused)) struct cmdline *cl,
12961         __attribute__((unused)) void *data)
12962 {
12963         struct cmd_config_e_tag_result *res =
12964                 parsed_result;
12965         struct rte_eth_l2_tunnel_conf entry;
12966
12967         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12968                 return;
12969
12970         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12971         entry.tunnel_id = res->port_tag_id_val;
12972         entry.vf_id = res->vf_id;
12973         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12974                                           &entry,
12975                                           ETH_L2_TUNNEL_INSERTION_MASK,
12976                                           1);
12977 }
12978
12979 static void
12980 cmd_config_e_tag_insertion_dis_parsed(
12981         void *parsed_result,
12982         __attribute__((unused)) struct cmdline *cl,
12983         __attribute__((unused)) void *data)
12984 {
12985         struct cmd_config_e_tag_result *res =
12986                 parsed_result;
12987         struct rte_eth_l2_tunnel_conf entry;
12988
12989         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12990                 return;
12991
12992         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12993         entry.vf_id = res->vf_id;
12994
12995         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12996                                           &entry,
12997                                           ETH_L2_TUNNEL_INSERTION_MASK,
12998                                           0);
12999 }
13000
13001 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13002         .f = cmd_config_e_tag_insertion_en_parsed,
13003         .data = NULL,
13004         .help_str = "E-tag ... : E-tag insertion enable",
13005         .tokens = {
13006                 (void *)&cmd_config_e_tag_e_tag,
13007                 (void *)&cmd_config_e_tag_set,
13008                 (void *)&cmd_config_e_tag_insertion,
13009                 (void *)&cmd_config_e_tag_on,
13010                 (void *)&cmd_config_e_tag_port_tag_id,
13011                 (void *)&cmd_config_e_tag_port_tag_id_val,
13012                 (void *)&cmd_config_e_tag_port,
13013                 (void *)&cmd_config_e_tag_port_id,
13014                 (void *)&cmd_config_e_tag_vf,
13015                 (void *)&cmd_config_e_tag_vf_id,
13016                 NULL,
13017         },
13018 };
13019
13020 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13021         .f = cmd_config_e_tag_insertion_dis_parsed,
13022         .data = NULL,
13023         .help_str = "E-tag ... : E-tag insertion disable",
13024         .tokens = {
13025                 (void *)&cmd_config_e_tag_e_tag,
13026                 (void *)&cmd_config_e_tag_set,
13027                 (void *)&cmd_config_e_tag_insertion,
13028                 (void *)&cmd_config_e_tag_off,
13029                 (void *)&cmd_config_e_tag_port,
13030                 (void *)&cmd_config_e_tag_port_id,
13031                 (void *)&cmd_config_e_tag_vf,
13032                 (void *)&cmd_config_e_tag_vf_id,
13033                 NULL,
13034         },
13035 };
13036
13037 /* E-tag stripping configuration */
13038 static void
13039 cmd_config_e_tag_stripping_parsed(
13040         void *parsed_result,
13041         __attribute__((unused)) struct cmdline *cl,
13042         __attribute__((unused)) void *data)
13043 {
13044         struct cmd_config_e_tag_result *res =
13045                 parsed_result;
13046         struct rte_eth_l2_tunnel_conf entry;
13047
13048         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13049                 return;
13050
13051         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13052
13053         if (!strcmp(res->on_off, "on"))
13054                 rte_eth_dev_l2_tunnel_offload_set
13055                         (res->port_id,
13056                          &entry,
13057                          ETH_L2_TUNNEL_STRIPPING_MASK,
13058                          1);
13059         else
13060                 rte_eth_dev_l2_tunnel_offload_set
13061                         (res->port_id,
13062                          &entry,
13063                          ETH_L2_TUNNEL_STRIPPING_MASK,
13064                          0);
13065 }
13066
13067 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13068         .f = cmd_config_e_tag_stripping_parsed,
13069         .data = NULL,
13070         .help_str = "E-tag ... : E-tag stripping enable/disable",
13071         .tokens = {
13072                 (void *)&cmd_config_e_tag_e_tag,
13073                 (void *)&cmd_config_e_tag_set,
13074                 (void *)&cmd_config_e_tag_stripping,
13075                 (void *)&cmd_config_e_tag_on_off,
13076                 (void *)&cmd_config_e_tag_port,
13077                 (void *)&cmd_config_e_tag_port_id,
13078                 NULL,
13079         },
13080 };
13081
13082 /* E-tag forwarding configuration */
13083 static void
13084 cmd_config_e_tag_forwarding_parsed(
13085         void *parsed_result,
13086         __attribute__((unused)) struct cmdline *cl,
13087         __attribute__((unused)) void *data)
13088 {
13089         struct cmd_config_e_tag_result *res = parsed_result;
13090         struct rte_eth_l2_tunnel_conf entry;
13091
13092         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13093                 return;
13094
13095         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13096
13097         if (!strcmp(res->on_off, "on"))
13098                 rte_eth_dev_l2_tunnel_offload_set
13099                         (res->port_id,
13100                          &entry,
13101                          ETH_L2_TUNNEL_FORWARDING_MASK,
13102                          1);
13103         else
13104                 rte_eth_dev_l2_tunnel_offload_set
13105                         (res->port_id,
13106                          &entry,
13107                          ETH_L2_TUNNEL_FORWARDING_MASK,
13108                          0);
13109 }
13110
13111 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13112         .f = cmd_config_e_tag_forwarding_parsed,
13113         .data = NULL,
13114         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13115         .tokens = {
13116                 (void *)&cmd_config_e_tag_e_tag,
13117                 (void *)&cmd_config_e_tag_set,
13118                 (void *)&cmd_config_e_tag_forwarding,
13119                 (void *)&cmd_config_e_tag_on_off,
13120                 (void *)&cmd_config_e_tag_port,
13121                 (void *)&cmd_config_e_tag_port_id,
13122                 NULL,
13123         },
13124 };
13125
13126 /* E-tag filter configuration */
13127 static void
13128 cmd_config_e_tag_filter_add_parsed(
13129         void *parsed_result,
13130         __attribute__((unused)) struct cmdline *cl,
13131         __attribute__((unused)) void *data)
13132 {
13133         struct cmd_config_e_tag_result *res = parsed_result;
13134         struct rte_eth_l2_tunnel_conf entry;
13135         int ret = 0;
13136
13137         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13138                 return;
13139
13140         if (res->e_tag_id_val > 0x3fff) {
13141                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13142                 return;
13143         }
13144
13145         ret = rte_eth_dev_filter_supported(res->port_id,
13146                                            RTE_ETH_FILTER_L2_TUNNEL);
13147         if (ret < 0) {
13148                 printf("E-tag filter is not supported on port %u.\n",
13149                        res->port_id);
13150                 return;
13151         }
13152
13153         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13154         entry.tunnel_id = res->e_tag_id_val;
13155         entry.pool = res->dst_pool_val;
13156
13157         ret = rte_eth_dev_filter_ctrl(res->port_id,
13158                                       RTE_ETH_FILTER_L2_TUNNEL,
13159                                       RTE_ETH_FILTER_ADD,
13160                                       &entry);
13161         if (ret < 0)
13162                 printf("E-tag filter programming error: (%s)\n",
13163                        strerror(-ret));
13164 }
13165
13166 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13167         .f = cmd_config_e_tag_filter_add_parsed,
13168         .data = NULL,
13169         .help_str = "E-tag ... : E-tag filter add",
13170         .tokens = {
13171                 (void *)&cmd_config_e_tag_e_tag,
13172                 (void *)&cmd_config_e_tag_set,
13173                 (void *)&cmd_config_e_tag_filter,
13174                 (void *)&cmd_config_e_tag_add,
13175                 (void *)&cmd_config_e_tag_e_tag_id,
13176                 (void *)&cmd_config_e_tag_e_tag_id_val,
13177                 (void *)&cmd_config_e_tag_dst_pool,
13178                 (void *)&cmd_config_e_tag_dst_pool_val,
13179                 (void *)&cmd_config_e_tag_port,
13180                 (void *)&cmd_config_e_tag_port_id,
13181                 NULL,
13182         },
13183 };
13184
13185 static void
13186 cmd_config_e_tag_filter_del_parsed(
13187         void *parsed_result,
13188         __attribute__((unused)) struct cmdline *cl,
13189         __attribute__((unused)) void *data)
13190 {
13191         struct cmd_config_e_tag_result *res = parsed_result;
13192         struct rte_eth_l2_tunnel_conf entry;
13193         int ret = 0;
13194
13195         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13196                 return;
13197
13198         if (res->e_tag_id_val > 0x3fff) {
13199                 printf("e-tag-id must be less than 0x3fff.\n");
13200                 return;
13201         }
13202
13203         ret = rte_eth_dev_filter_supported(res->port_id,
13204                                            RTE_ETH_FILTER_L2_TUNNEL);
13205         if (ret < 0) {
13206                 printf("E-tag filter is not supported on port %u.\n",
13207                        res->port_id);
13208                 return;
13209         }
13210
13211         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13212         entry.tunnel_id = res->e_tag_id_val;
13213
13214         ret = rte_eth_dev_filter_ctrl(res->port_id,
13215                                       RTE_ETH_FILTER_L2_TUNNEL,
13216                                       RTE_ETH_FILTER_DELETE,
13217                                       &entry);
13218         if (ret < 0)
13219                 printf("E-tag filter programming error: (%s)\n",
13220                        strerror(-ret));
13221 }
13222
13223 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13224         .f = cmd_config_e_tag_filter_del_parsed,
13225         .data = NULL,
13226         .help_str = "E-tag ... : E-tag filter delete",
13227         .tokens = {
13228                 (void *)&cmd_config_e_tag_e_tag,
13229                 (void *)&cmd_config_e_tag_set,
13230                 (void *)&cmd_config_e_tag_filter,
13231                 (void *)&cmd_config_e_tag_del,
13232                 (void *)&cmd_config_e_tag_e_tag_id,
13233                 (void *)&cmd_config_e_tag_e_tag_id_val,
13234                 (void *)&cmd_config_e_tag_port,
13235                 (void *)&cmd_config_e_tag_port_id,
13236                 NULL,
13237         },
13238 };
13239
13240 /* vf vlan anti spoof configuration */
13241
13242 /* Common result structure for vf vlan anti spoof */
13243 struct cmd_vf_vlan_anti_spoof_result {
13244         cmdline_fixed_string_t set;
13245         cmdline_fixed_string_t vf;
13246         cmdline_fixed_string_t vlan;
13247         cmdline_fixed_string_t antispoof;
13248         portid_t port_id;
13249         uint32_t vf_id;
13250         cmdline_fixed_string_t on_off;
13251 };
13252
13253 /* Common CLI fields for vf vlan anti spoof enable disable */
13254 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13255         TOKEN_STRING_INITIALIZER
13256                 (struct cmd_vf_vlan_anti_spoof_result,
13257                  set, "set");
13258 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13259         TOKEN_STRING_INITIALIZER
13260                 (struct cmd_vf_vlan_anti_spoof_result,
13261                  vf, "vf");
13262 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13263         TOKEN_STRING_INITIALIZER
13264                 (struct cmd_vf_vlan_anti_spoof_result,
13265                  vlan, "vlan");
13266 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13267         TOKEN_STRING_INITIALIZER
13268                 (struct cmd_vf_vlan_anti_spoof_result,
13269                  antispoof, "antispoof");
13270 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13271         TOKEN_NUM_INITIALIZER
13272                 (struct cmd_vf_vlan_anti_spoof_result,
13273                  port_id, UINT16);
13274 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13275         TOKEN_NUM_INITIALIZER
13276                 (struct cmd_vf_vlan_anti_spoof_result,
13277                  vf_id, UINT32);
13278 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13279         TOKEN_STRING_INITIALIZER
13280                 (struct cmd_vf_vlan_anti_spoof_result,
13281                  on_off, "on#off");
13282
13283 static void
13284 cmd_set_vf_vlan_anti_spoof_parsed(
13285         void *parsed_result,
13286         __attribute__((unused)) struct cmdline *cl,
13287         __attribute__((unused)) void *data)
13288 {
13289         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13290         int ret = -ENOTSUP;
13291
13292         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13293
13294         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13295                 return;
13296
13297 #ifdef RTE_LIBRTE_IXGBE_PMD
13298         if (ret == -ENOTSUP)
13299                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13300                                 res->vf_id, is_on);
13301 #endif
13302 #ifdef RTE_LIBRTE_I40E_PMD
13303         if (ret == -ENOTSUP)
13304                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13305                                 res->vf_id, is_on);
13306 #endif
13307 #ifdef RTE_LIBRTE_BNXT_PMD
13308         if (ret == -ENOTSUP)
13309                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13310                                 res->vf_id, is_on);
13311 #endif
13312
13313         switch (ret) {
13314         case 0:
13315                 break;
13316         case -EINVAL:
13317                 printf("invalid vf_id %d\n", res->vf_id);
13318                 break;
13319         case -ENODEV:
13320                 printf("invalid port_id %d\n", res->port_id);
13321                 break;
13322         case -ENOTSUP:
13323                 printf("function not implemented\n");
13324                 break;
13325         default:
13326                 printf("programming error: (%s)\n", strerror(-ret));
13327         }
13328 }
13329
13330 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13331         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13332         .data = NULL,
13333         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13334         .tokens = {
13335                 (void *)&cmd_vf_vlan_anti_spoof_set,
13336                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13337                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13338                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13339                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13340                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13341                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13342                 NULL,
13343         },
13344 };
13345
13346 /* vf mac anti spoof configuration */
13347
13348 /* Common result structure for vf mac anti spoof */
13349 struct cmd_vf_mac_anti_spoof_result {
13350         cmdline_fixed_string_t set;
13351         cmdline_fixed_string_t vf;
13352         cmdline_fixed_string_t mac;
13353         cmdline_fixed_string_t antispoof;
13354         portid_t port_id;
13355         uint32_t vf_id;
13356         cmdline_fixed_string_t on_off;
13357 };
13358
13359 /* Common CLI fields for vf mac anti spoof enable disable */
13360 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13361         TOKEN_STRING_INITIALIZER
13362                 (struct cmd_vf_mac_anti_spoof_result,
13363                  set, "set");
13364 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13365         TOKEN_STRING_INITIALIZER
13366                 (struct cmd_vf_mac_anti_spoof_result,
13367                  vf, "vf");
13368 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13369         TOKEN_STRING_INITIALIZER
13370                 (struct cmd_vf_mac_anti_spoof_result,
13371                  mac, "mac");
13372 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13373         TOKEN_STRING_INITIALIZER
13374                 (struct cmd_vf_mac_anti_spoof_result,
13375                  antispoof, "antispoof");
13376 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13377         TOKEN_NUM_INITIALIZER
13378                 (struct cmd_vf_mac_anti_spoof_result,
13379                  port_id, UINT16);
13380 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13381         TOKEN_NUM_INITIALIZER
13382                 (struct cmd_vf_mac_anti_spoof_result,
13383                  vf_id, UINT32);
13384 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13385         TOKEN_STRING_INITIALIZER
13386                 (struct cmd_vf_mac_anti_spoof_result,
13387                  on_off, "on#off");
13388
13389 static void
13390 cmd_set_vf_mac_anti_spoof_parsed(
13391         void *parsed_result,
13392         __attribute__((unused)) struct cmdline *cl,
13393         __attribute__((unused)) void *data)
13394 {
13395         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13396         int ret = -ENOTSUP;
13397
13398         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13399
13400         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13401                 return;
13402
13403 #ifdef RTE_LIBRTE_IXGBE_PMD
13404         if (ret == -ENOTSUP)
13405                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13406                         res->vf_id, is_on);
13407 #endif
13408 #ifdef RTE_LIBRTE_I40E_PMD
13409         if (ret == -ENOTSUP)
13410                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13411                         res->vf_id, is_on);
13412 #endif
13413 #ifdef RTE_LIBRTE_BNXT_PMD
13414         if (ret == -ENOTSUP)
13415                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13416                         res->vf_id, is_on);
13417 #endif
13418
13419         switch (ret) {
13420         case 0:
13421                 break;
13422         case -EINVAL:
13423                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13424                 break;
13425         case -ENODEV:
13426                 printf("invalid port_id %d\n", res->port_id);
13427                 break;
13428         case -ENOTSUP:
13429                 printf("function not implemented\n");
13430                 break;
13431         default:
13432                 printf("programming error: (%s)\n", strerror(-ret));
13433         }
13434 }
13435
13436 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13437         .f = cmd_set_vf_mac_anti_spoof_parsed,
13438         .data = NULL,
13439         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13440         .tokens = {
13441                 (void *)&cmd_vf_mac_anti_spoof_set,
13442                 (void *)&cmd_vf_mac_anti_spoof_vf,
13443                 (void *)&cmd_vf_mac_anti_spoof_mac,
13444                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13445                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13446                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13447                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13448                 NULL,
13449         },
13450 };
13451
13452 /* vf vlan strip queue configuration */
13453
13454 /* Common result structure for vf mac anti spoof */
13455 struct cmd_vf_vlan_stripq_result {
13456         cmdline_fixed_string_t set;
13457         cmdline_fixed_string_t vf;
13458         cmdline_fixed_string_t vlan;
13459         cmdline_fixed_string_t stripq;
13460         portid_t port_id;
13461         uint16_t vf_id;
13462         cmdline_fixed_string_t on_off;
13463 };
13464
13465 /* Common CLI fields for vf vlan strip enable disable */
13466 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13467         TOKEN_STRING_INITIALIZER
13468                 (struct cmd_vf_vlan_stripq_result,
13469                  set, "set");
13470 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13471         TOKEN_STRING_INITIALIZER
13472                 (struct cmd_vf_vlan_stripq_result,
13473                  vf, "vf");
13474 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13475         TOKEN_STRING_INITIALIZER
13476                 (struct cmd_vf_vlan_stripq_result,
13477                  vlan, "vlan");
13478 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13479         TOKEN_STRING_INITIALIZER
13480                 (struct cmd_vf_vlan_stripq_result,
13481                  stripq, "stripq");
13482 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13483         TOKEN_NUM_INITIALIZER
13484                 (struct cmd_vf_vlan_stripq_result,
13485                  port_id, UINT16);
13486 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13487         TOKEN_NUM_INITIALIZER
13488                 (struct cmd_vf_vlan_stripq_result,
13489                  vf_id, UINT16);
13490 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13491         TOKEN_STRING_INITIALIZER
13492                 (struct cmd_vf_vlan_stripq_result,
13493                  on_off, "on#off");
13494
13495 static void
13496 cmd_set_vf_vlan_stripq_parsed(
13497         void *parsed_result,
13498         __attribute__((unused)) struct cmdline *cl,
13499         __attribute__((unused)) void *data)
13500 {
13501         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13502         int ret = -ENOTSUP;
13503
13504         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13505
13506         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13507                 return;
13508
13509 #ifdef RTE_LIBRTE_IXGBE_PMD
13510         if (ret == -ENOTSUP)
13511                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13512                         res->vf_id, is_on);
13513 #endif
13514 #ifdef RTE_LIBRTE_I40E_PMD
13515         if (ret == -ENOTSUP)
13516                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13517                         res->vf_id, is_on);
13518 #endif
13519 #ifdef RTE_LIBRTE_BNXT_PMD
13520         if (ret == -ENOTSUP)
13521                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13522                         res->vf_id, is_on);
13523 #endif
13524
13525         switch (ret) {
13526         case 0:
13527                 break;
13528         case -EINVAL:
13529                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13530                 break;
13531         case -ENODEV:
13532                 printf("invalid port_id %d\n", res->port_id);
13533                 break;
13534         case -ENOTSUP:
13535                 printf("function not implemented\n");
13536                 break;
13537         default:
13538                 printf("programming error: (%s)\n", strerror(-ret));
13539         }
13540 }
13541
13542 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13543         .f = cmd_set_vf_vlan_stripq_parsed,
13544         .data = NULL,
13545         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13546         .tokens = {
13547                 (void *)&cmd_vf_vlan_stripq_set,
13548                 (void *)&cmd_vf_vlan_stripq_vf,
13549                 (void *)&cmd_vf_vlan_stripq_vlan,
13550                 (void *)&cmd_vf_vlan_stripq_stripq,
13551                 (void *)&cmd_vf_vlan_stripq_port_id,
13552                 (void *)&cmd_vf_vlan_stripq_vf_id,
13553                 (void *)&cmd_vf_vlan_stripq_on_off,
13554                 NULL,
13555         },
13556 };
13557
13558 /* vf vlan insert configuration */
13559
13560 /* Common result structure for vf vlan insert */
13561 struct cmd_vf_vlan_insert_result {
13562         cmdline_fixed_string_t set;
13563         cmdline_fixed_string_t vf;
13564         cmdline_fixed_string_t vlan;
13565         cmdline_fixed_string_t insert;
13566         portid_t port_id;
13567         uint16_t vf_id;
13568         uint16_t vlan_id;
13569 };
13570
13571 /* Common CLI fields for vf vlan insert enable disable */
13572 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13573         TOKEN_STRING_INITIALIZER
13574                 (struct cmd_vf_vlan_insert_result,
13575                  set, "set");
13576 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13577         TOKEN_STRING_INITIALIZER
13578                 (struct cmd_vf_vlan_insert_result,
13579                  vf, "vf");
13580 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13581         TOKEN_STRING_INITIALIZER
13582                 (struct cmd_vf_vlan_insert_result,
13583                  vlan, "vlan");
13584 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13585         TOKEN_STRING_INITIALIZER
13586                 (struct cmd_vf_vlan_insert_result,
13587                  insert, "insert");
13588 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13589         TOKEN_NUM_INITIALIZER
13590                 (struct cmd_vf_vlan_insert_result,
13591                  port_id, UINT16);
13592 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13593         TOKEN_NUM_INITIALIZER
13594                 (struct cmd_vf_vlan_insert_result,
13595                  vf_id, UINT16);
13596 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13597         TOKEN_NUM_INITIALIZER
13598                 (struct cmd_vf_vlan_insert_result,
13599                  vlan_id, UINT16);
13600
13601 static void
13602 cmd_set_vf_vlan_insert_parsed(
13603         void *parsed_result,
13604         __attribute__((unused)) struct cmdline *cl,
13605         __attribute__((unused)) void *data)
13606 {
13607         struct cmd_vf_vlan_insert_result *res = parsed_result;
13608         int ret = -ENOTSUP;
13609
13610         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13611                 return;
13612
13613 #ifdef RTE_LIBRTE_IXGBE_PMD
13614         if (ret == -ENOTSUP)
13615                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13616                         res->vlan_id);
13617 #endif
13618 #ifdef RTE_LIBRTE_I40E_PMD
13619         if (ret == -ENOTSUP)
13620                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13621                         res->vlan_id);
13622 #endif
13623 #ifdef RTE_LIBRTE_BNXT_PMD
13624         if (ret == -ENOTSUP)
13625                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13626                         res->vlan_id);
13627 #endif
13628
13629         switch (ret) {
13630         case 0:
13631                 break;
13632         case -EINVAL:
13633                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13634                 break;
13635         case -ENODEV:
13636                 printf("invalid port_id %d\n", res->port_id);
13637                 break;
13638         case -ENOTSUP:
13639                 printf("function not implemented\n");
13640                 break;
13641         default:
13642                 printf("programming error: (%s)\n", strerror(-ret));
13643         }
13644 }
13645
13646 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13647         .f = cmd_set_vf_vlan_insert_parsed,
13648         .data = NULL,
13649         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13650         .tokens = {
13651                 (void *)&cmd_vf_vlan_insert_set,
13652                 (void *)&cmd_vf_vlan_insert_vf,
13653                 (void *)&cmd_vf_vlan_insert_vlan,
13654                 (void *)&cmd_vf_vlan_insert_insert,
13655                 (void *)&cmd_vf_vlan_insert_port_id,
13656                 (void *)&cmd_vf_vlan_insert_vf_id,
13657                 (void *)&cmd_vf_vlan_insert_vlan_id,
13658                 NULL,
13659         },
13660 };
13661
13662 /* tx loopback configuration */
13663
13664 /* Common result structure for tx loopback */
13665 struct cmd_tx_loopback_result {
13666         cmdline_fixed_string_t set;
13667         cmdline_fixed_string_t tx;
13668         cmdline_fixed_string_t loopback;
13669         portid_t port_id;
13670         cmdline_fixed_string_t on_off;
13671 };
13672
13673 /* Common CLI fields for tx loopback enable disable */
13674 cmdline_parse_token_string_t cmd_tx_loopback_set =
13675         TOKEN_STRING_INITIALIZER
13676                 (struct cmd_tx_loopback_result,
13677                  set, "set");
13678 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13679         TOKEN_STRING_INITIALIZER
13680                 (struct cmd_tx_loopback_result,
13681                  tx, "tx");
13682 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13683         TOKEN_STRING_INITIALIZER
13684                 (struct cmd_tx_loopback_result,
13685                  loopback, "loopback");
13686 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13687         TOKEN_NUM_INITIALIZER
13688                 (struct cmd_tx_loopback_result,
13689                  port_id, UINT16);
13690 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13691         TOKEN_STRING_INITIALIZER
13692                 (struct cmd_tx_loopback_result,
13693                  on_off, "on#off");
13694
13695 static void
13696 cmd_set_tx_loopback_parsed(
13697         void *parsed_result,
13698         __attribute__((unused)) struct cmdline *cl,
13699         __attribute__((unused)) void *data)
13700 {
13701         struct cmd_tx_loopback_result *res = parsed_result;
13702         int ret = -ENOTSUP;
13703
13704         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13705
13706         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13707                 return;
13708
13709 #ifdef RTE_LIBRTE_IXGBE_PMD
13710         if (ret == -ENOTSUP)
13711                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13712 #endif
13713 #ifdef RTE_LIBRTE_I40E_PMD
13714         if (ret == -ENOTSUP)
13715                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13716 #endif
13717 #ifdef RTE_LIBRTE_BNXT_PMD
13718         if (ret == -ENOTSUP)
13719                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13720 #endif
13721 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13722         if (ret == -ENOTSUP)
13723                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13724 #endif
13725
13726         switch (ret) {
13727         case 0:
13728                 break;
13729         case -EINVAL:
13730                 printf("invalid is_on %d\n", is_on);
13731                 break;
13732         case -ENODEV:
13733                 printf("invalid port_id %d\n", res->port_id);
13734                 break;
13735         case -ENOTSUP:
13736                 printf("function not implemented\n");
13737                 break;
13738         default:
13739                 printf("programming error: (%s)\n", strerror(-ret));
13740         }
13741 }
13742
13743 cmdline_parse_inst_t cmd_set_tx_loopback = {
13744         .f = cmd_set_tx_loopback_parsed,
13745         .data = NULL,
13746         .help_str = "set tx loopback <port_id> on|off",
13747         .tokens = {
13748                 (void *)&cmd_tx_loopback_set,
13749                 (void *)&cmd_tx_loopback_tx,
13750                 (void *)&cmd_tx_loopback_loopback,
13751                 (void *)&cmd_tx_loopback_port_id,
13752                 (void *)&cmd_tx_loopback_on_off,
13753                 NULL,
13754         },
13755 };
13756
13757 /* all queues drop enable configuration */
13758
13759 /* Common result structure for all queues drop enable */
13760 struct cmd_all_queues_drop_en_result {
13761         cmdline_fixed_string_t set;
13762         cmdline_fixed_string_t all;
13763         cmdline_fixed_string_t queues;
13764         cmdline_fixed_string_t drop;
13765         portid_t port_id;
13766         cmdline_fixed_string_t on_off;
13767 };
13768
13769 /* Common CLI fields for tx loopback enable disable */
13770 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13771         TOKEN_STRING_INITIALIZER
13772                 (struct cmd_all_queues_drop_en_result,
13773                  set, "set");
13774 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13775         TOKEN_STRING_INITIALIZER
13776                 (struct cmd_all_queues_drop_en_result,
13777                  all, "all");
13778 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13779         TOKEN_STRING_INITIALIZER
13780                 (struct cmd_all_queues_drop_en_result,
13781                  queues, "queues");
13782 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13783         TOKEN_STRING_INITIALIZER
13784                 (struct cmd_all_queues_drop_en_result,
13785                  drop, "drop");
13786 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13787         TOKEN_NUM_INITIALIZER
13788                 (struct cmd_all_queues_drop_en_result,
13789                  port_id, UINT16);
13790 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13791         TOKEN_STRING_INITIALIZER
13792                 (struct cmd_all_queues_drop_en_result,
13793                  on_off, "on#off");
13794
13795 static void
13796 cmd_set_all_queues_drop_en_parsed(
13797         void *parsed_result,
13798         __attribute__((unused)) struct cmdline *cl,
13799         __attribute__((unused)) void *data)
13800 {
13801         struct cmd_all_queues_drop_en_result *res = parsed_result;
13802         int ret = -ENOTSUP;
13803         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13804
13805         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13806                 return;
13807
13808 #ifdef RTE_LIBRTE_IXGBE_PMD
13809         if (ret == -ENOTSUP)
13810                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13811 #endif
13812 #ifdef RTE_LIBRTE_BNXT_PMD
13813         if (ret == -ENOTSUP)
13814                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13815 #endif
13816         switch (ret) {
13817         case 0:
13818                 break;
13819         case -EINVAL:
13820                 printf("invalid is_on %d\n", is_on);
13821                 break;
13822         case -ENODEV:
13823                 printf("invalid port_id %d\n", res->port_id);
13824                 break;
13825         case -ENOTSUP:
13826                 printf("function not implemented\n");
13827                 break;
13828         default:
13829                 printf("programming error: (%s)\n", strerror(-ret));
13830         }
13831 }
13832
13833 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13834         .f = cmd_set_all_queues_drop_en_parsed,
13835         .data = NULL,
13836         .help_str = "set all queues drop <port_id> on|off",
13837         .tokens = {
13838                 (void *)&cmd_all_queues_drop_en_set,
13839                 (void *)&cmd_all_queues_drop_en_all,
13840                 (void *)&cmd_all_queues_drop_en_queues,
13841                 (void *)&cmd_all_queues_drop_en_drop,
13842                 (void *)&cmd_all_queues_drop_en_port_id,
13843                 (void *)&cmd_all_queues_drop_en_on_off,
13844                 NULL,
13845         },
13846 };
13847
13848 /* vf split drop enable configuration */
13849
13850 /* Common result structure for vf split drop enable */
13851 struct cmd_vf_split_drop_en_result {
13852         cmdline_fixed_string_t set;
13853         cmdline_fixed_string_t vf;
13854         cmdline_fixed_string_t split;
13855         cmdline_fixed_string_t drop;
13856         portid_t port_id;
13857         uint16_t vf_id;
13858         cmdline_fixed_string_t on_off;
13859 };
13860
13861 /* Common CLI fields for vf split drop enable disable */
13862 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13863         TOKEN_STRING_INITIALIZER
13864                 (struct cmd_vf_split_drop_en_result,
13865                  set, "set");
13866 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13867         TOKEN_STRING_INITIALIZER
13868                 (struct cmd_vf_split_drop_en_result,
13869                  vf, "vf");
13870 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13871         TOKEN_STRING_INITIALIZER
13872                 (struct cmd_vf_split_drop_en_result,
13873                  split, "split");
13874 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13875         TOKEN_STRING_INITIALIZER
13876                 (struct cmd_vf_split_drop_en_result,
13877                  drop, "drop");
13878 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13879         TOKEN_NUM_INITIALIZER
13880                 (struct cmd_vf_split_drop_en_result,
13881                  port_id, UINT16);
13882 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13883         TOKEN_NUM_INITIALIZER
13884                 (struct cmd_vf_split_drop_en_result,
13885                  vf_id, UINT16);
13886 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13887         TOKEN_STRING_INITIALIZER
13888                 (struct cmd_vf_split_drop_en_result,
13889                  on_off, "on#off");
13890
13891 static void
13892 cmd_set_vf_split_drop_en_parsed(
13893         void *parsed_result,
13894         __attribute__((unused)) struct cmdline *cl,
13895         __attribute__((unused)) void *data)
13896 {
13897         struct cmd_vf_split_drop_en_result *res = parsed_result;
13898         int ret = -ENOTSUP;
13899         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13900
13901         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13902                 return;
13903
13904 #ifdef RTE_LIBRTE_IXGBE_PMD
13905         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13906                         is_on);
13907 #endif
13908         switch (ret) {
13909         case 0:
13910                 break;
13911         case -EINVAL:
13912                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13913                 break;
13914         case -ENODEV:
13915                 printf("invalid port_id %d\n", res->port_id);
13916                 break;
13917         case -ENOTSUP:
13918                 printf("not supported on port %d\n", res->port_id);
13919                 break;
13920         default:
13921                 printf("programming error: (%s)\n", strerror(-ret));
13922         }
13923 }
13924
13925 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13926         .f = cmd_set_vf_split_drop_en_parsed,
13927         .data = NULL,
13928         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13929         .tokens = {
13930                 (void *)&cmd_vf_split_drop_en_set,
13931                 (void *)&cmd_vf_split_drop_en_vf,
13932                 (void *)&cmd_vf_split_drop_en_split,
13933                 (void *)&cmd_vf_split_drop_en_drop,
13934                 (void *)&cmd_vf_split_drop_en_port_id,
13935                 (void *)&cmd_vf_split_drop_en_vf_id,
13936                 (void *)&cmd_vf_split_drop_en_on_off,
13937                 NULL,
13938         },
13939 };
13940
13941 /* vf mac address configuration */
13942
13943 /* Common result structure for vf mac address */
13944 struct cmd_set_vf_mac_addr_result {
13945         cmdline_fixed_string_t set;
13946         cmdline_fixed_string_t vf;
13947         cmdline_fixed_string_t mac;
13948         cmdline_fixed_string_t addr;
13949         portid_t port_id;
13950         uint16_t vf_id;
13951         struct rte_ether_addr mac_addr;
13952
13953 };
13954
13955 /* Common CLI fields for vf split drop enable disable */
13956 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13957         TOKEN_STRING_INITIALIZER
13958                 (struct cmd_set_vf_mac_addr_result,
13959                  set, "set");
13960 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13961         TOKEN_STRING_INITIALIZER
13962                 (struct cmd_set_vf_mac_addr_result,
13963                  vf, "vf");
13964 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13965         TOKEN_STRING_INITIALIZER
13966                 (struct cmd_set_vf_mac_addr_result,
13967                  mac, "mac");
13968 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13969         TOKEN_STRING_INITIALIZER
13970                 (struct cmd_set_vf_mac_addr_result,
13971                  addr, "addr");
13972 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13973         TOKEN_NUM_INITIALIZER
13974                 (struct cmd_set_vf_mac_addr_result,
13975                  port_id, UINT16);
13976 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13977         TOKEN_NUM_INITIALIZER
13978                 (struct cmd_set_vf_mac_addr_result,
13979                  vf_id, UINT16);
13980 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13981         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13982                  mac_addr);
13983
13984 static void
13985 cmd_set_vf_mac_addr_parsed(
13986         void *parsed_result,
13987         __attribute__((unused)) struct cmdline *cl,
13988         __attribute__((unused)) void *data)
13989 {
13990         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13991         int ret = -ENOTSUP;
13992
13993         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13994                 return;
13995
13996 #ifdef RTE_LIBRTE_IXGBE_PMD
13997         if (ret == -ENOTSUP)
13998                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13999                                 &res->mac_addr);
14000 #endif
14001 #ifdef RTE_LIBRTE_I40E_PMD
14002         if (ret == -ENOTSUP)
14003                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14004                                 &res->mac_addr);
14005 #endif
14006 #ifdef RTE_LIBRTE_BNXT_PMD
14007         if (ret == -ENOTSUP)
14008                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14009                                 &res->mac_addr);
14010 #endif
14011
14012         switch (ret) {
14013         case 0:
14014                 break;
14015         case -EINVAL:
14016                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14017                 break;
14018         case -ENODEV:
14019                 printf("invalid port_id %d\n", res->port_id);
14020                 break;
14021         case -ENOTSUP:
14022                 printf("function not implemented\n");
14023                 break;
14024         default:
14025                 printf("programming error: (%s)\n", strerror(-ret));
14026         }
14027 }
14028
14029 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14030         .f = cmd_set_vf_mac_addr_parsed,
14031         .data = NULL,
14032         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14033         .tokens = {
14034                 (void *)&cmd_set_vf_mac_addr_set,
14035                 (void *)&cmd_set_vf_mac_addr_vf,
14036                 (void *)&cmd_set_vf_mac_addr_mac,
14037                 (void *)&cmd_set_vf_mac_addr_addr,
14038                 (void *)&cmd_set_vf_mac_addr_port_id,
14039                 (void *)&cmd_set_vf_mac_addr_vf_id,
14040                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14041                 NULL,
14042         },
14043 };
14044
14045 /* MACsec configuration */
14046
14047 /* Common result structure for MACsec offload enable */
14048 struct cmd_macsec_offload_on_result {
14049         cmdline_fixed_string_t set;
14050         cmdline_fixed_string_t macsec;
14051         cmdline_fixed_string_t offload;
14052         portid_t port_id;
14053         cmdline_fixed_string_t on;
14054         cmdline_fixed_string_t encrypt;
14055         cmdline_fixed_string_t en_on_off;
14056         cmdline_fixed_string_t replay_protect;
14057         cmdline_fixed_string_t rp_on_off;
14058 };
14059
14060 /* Common CLI fields for MACsec offload disable */
14061 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14062         TOKEN_STRING_INITIALIZER
14063                 (struct cmd_macsec_offload_on_result,
14064                  set, "set");
14065 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14066         TOKEN_STRING_INITIALIZER
14067                 (struct cmd_macsec_offload_on_result,
14068                  macsec, "macsec");
14069 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14070         TOKEN_STRING_INITIALIZER
14071                 (struct cmd_macsec_offload_on_result,
14072                  offload, "offload");
14073 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14074         TOKEN_NUM_INITIALIZER
14075                 (struct cmd_macsec_offload_on_result,
14076                  port_id, UINT16);
14077 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14078         TOKEN_STRING_INITIALIZER
14079                 (struct cmd_macsec_offload_on_result,
14080                  on, "on");
14081 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14082         TOKEN_STRING_INITIALIZER
14083                 (struct cmd_macsec_offload_on_result,
14084                  encrypt, "encrypt");
14085 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14086         TOKEN_STRING_INITIALIZER
14087                 (struct cmd_macsec_offload_on_result,
14088                  en_on_off, "on#off");
14089 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14090         TOKEN_STRING_INITIALIZER
14091                 (struct cmd_macsec_offload_on_result,
14092                  replay_protect, "replay-protect");
14093 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14094         TOKEN_STRING_INITIALIZER
14095                 (struct cmd_macsec_offload_on_result,
14096                  rp_on_off, "on#off");
14097
14098 static void
14099 cmd_set_macsec_offload_on_parsed(
14100         void *parsed_result,
14101         __attribute__((unused)) struct cmdline *cl,
14102         __attribute__((unused)) void *data)
14103 {
14104         struct cmd_macsec_offload_on_result *res = parsed_result;
14105         int ret = -ENOTSUP;
14106         portid_t port_id = res->port_id;
14107         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14108         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14109         struct rte_eth_dev_info dev_info;
14110
14111         if (port_id_is_invalid(port_id, ENABLED_WARN))
14112                 return;
14113         if (!port_is_stopped(port_id)) {
14114                 printf("Please stop port %d first\n", port_id);
14115                 return;
14116         }
14117
14118         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14119         if (ret != 0)
14120                 return;
14121
14122         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14123 #ifdef RTE_LIBRTE_IXGBE_PMD
14124                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14125 #endif
14126         }
14127         RTE_SET_USED(en);
14128         RTE_SET_USED(rp);
14129
14130         switch (ret) {
14131         case 0:
14132                 ports[port_id].dev_conf.txmode.offloads |=
14133                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14134                 cmd_reconfig_device_queue(port_id, 1, 1);
14135                 break;
14136         case -ENODEV:
14137                 printf("invalid port_id %d\n", port_id);
14138                 break;
14139         case -ENOTSUP:
14140                 printf("not supported on port %d\n", port_id);
14141                 break;
14142         default:
14143                 printf("programming error: (%s)\n", strerror(-ret));
14144         }
14145 }
14146
14147 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14148         .f = cmd_set_macsec_offload_on_parsed,
14149         .data = NULL,
14150         .help_str = "set macsec offload <port_id> on "
14151                 "encrypt on|off replay-protect on|off",
14152         .tokens = {
14153                 (void *)&cmd_macsec_offload_on_set,
14154                 (void *)&cmd_macsec_offload_on_macsec,
14155                 (void *)&cmd_macsec_offload_on_offload,
14156                 (void *)&cmd_macsec_offload_on_port_id,
14157                 (void *)&cmd_macsec_offload_on_on,
14158                 (void *)&cmd_macsec_offload_on_encrypt,
14159                 (void *)&cmd_macsec_offload_on_en_on_off,
14160                 (void *)&cmd_macsec_offload_on_replay_protect,
14161                 (void *)&cmd_macsec_offload_on_rp_on_off,
14162                 NULL,
14163         },
14164 };
14165
14166 /* Common result structure for MACsec offload disable */
14167 struct cmd_macsec_offload_off_result {
14168         cmdline_fixed_string_t set;
14169         cmdline_fixed_string_t macsec;
14170         cmdline_fixed_string_t offload;
14171         portid_t port_id;
14172         cmdline_fixed_string_t off;
14173 };
14174
14175 /* Common CLI fields for MACsec offload disable */
14176 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14177         TOKEN_STRING_INITIALIZER
14178                 (struct cmd_macsec_offload_off_result,
14179                  set, "set");
14180 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14181         TOKEN_STRING_INITIALIZER
14182                 (struct cmd_macsec_offload_off_result,
14183                  macsec, "macsec");
14184 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14185         TOKEN_STRING_INITIALIZER
14186                 (struct cmd_macsec_offload_off_result,
14187                  offload, "offload");
14188 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14189         TOKEN_NUM_INITIALIZER
14190                 (struct cmd_macsec_offload_off_result,
14191                  port_id, UINT16);
14192 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14193         TOKEN_STRING_INITIALIZER
14194                 (struct cmd_macsec_offload_off_result,
14195                  off, "off");
14196
14197 static void
14198 cmd_set_macsec_offload_off_parsed(
14199         void *parsed_result,
14200         __attribute__((unused)) struct cmdline *cl,
14201         __attribute__((unused)) void *data)
14202 {
14203         struct cmd_macsec_offload_off_result *res = parsed_result;
14204         int ret = -ENOTSUP;
14205         struct rte_eth_dev_info dev_info;
14206         portid_t port_id = res->port_id;
14207
14208         if (port_id_is_invalid(port_id, ENABLED_WARN))
14209                 return;
14210         if (!port_is_stopped(port_id)) {
14211                 printf("Please stop port %d first\n", port_id);
14212                 return;
14213         }
14214
14215         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14216         if (ret != 0)
14217                 return;
14218
14219         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14220 #ifdef RTE_LIBRTE_IXGBE_PMD
14221                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14222 #endif
14223         }
14224         switch (ret) {
14225         case 0:
14226                 ports[port_id].dev_conf.txmode.offloads &=
14227                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14228                 cmd_reconfig_device_queue(port_id, 1, 1);
14229                 break;
14230         case -ENODEV:
14231                 printf("invalid port_id %d\n", port_id);
14232                 break;
14233         case -ENOTSUP:
14234                 printf("not supported on port %d\n", port_id);
14235                 break;
14236         default:
14237                 printf("programming error: (%s)\n", strerror(-ret));
14238         }
14239 }
14240
14241 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14242         .f = cmd_set_macsec_offload_off_parsed,
14243         .data = NULL,
14244         .help_str = "set macsec offload <port_id> off",
14245         .tokens = {
14246                 (void *)&cmd_macsec_offload_off_set,
14247                 (void *)&cmd_macsec_offload_off_macsec,
14248                 (void *)&cmd_macsec_offload_off_offload,
14249                 (void *)&cmd_macsec_offload_off_port_id,
14250                 (void *)&cmd_macsec_offload_off_off,
14251                 NULL,
14252         },
14253 };
14254
14255 /* Common result structure for MACsec secure connection configure */
14256 struct cmd_macsec_sc_result {
14257         cmdline_fixed_string_t set;
14258         cmdline_fixed_string_t macsec;
14259         cmdline_fixed_string_t sc;
14260         cmdline_fixed_string_t tx_rx;
14261         portid_t port_id;
14262         struct rte_ether_addr mac;
14263         uint16_t pi;
14264 };
14265
14266 /* Common CLI fields for MACsec secure connection configure */
14267 cmdline_parse_token_string_t cmd_macsec_sc_set =
14268         TOKEN_STRING_INITIALIZER
14269                 (struct cmd_macsec_sc_result,
14270                  set, "set");
14271 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14272         TOKEN_STRING_INITIALIZER
14273                 (struct cmd_macsec_sc_result,
14274                  macsec, "macsec");
14275 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14276         TOKEN_STRING_INITIALIZER
14277                 (struct cmd_macsec_sc_result,
14278                  sc, "sc");
14279 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14280         TOKEN_STRING_INITIALIZER
14281                 (struct cmd_macsec_sc_result,
14282                  tx_rx, "tx#rx");
14283 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14284         TOKEN_NUM_INITIALIZER
14285                 (struct cmd_macsec_sc_result,
14286                  port_id, UINT16);
14287 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14288         TOKEN_ETHERADDR_INITIALIZER
14289                 (struct cmd_macsec_sc_result,
14290                  mac);
14291 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14292         TOKEN_NUM_INITIALIZER
14293                 (struct cmd_macsec_sc_result,
14294                  pi, UINT16);
14295
14296 static void
14297 cmd_set_macsec_sc_parsed(
14298         void *parsed_result,
14299         __attribute__((unused)) struct cmdline *cl,
14300         __attribute__((unused)) void *data)
14301 {
14302         struct cmd_macsec_sc_result *res = parsed_result;
14303         int ret = -ENOTSUP;
14304         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14305
14306 #ifdef RTE_LIBRTE_IXGBE_PMD
14307         ret = is_tx ?
14308                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14309                                 res->mac.addr_bytes) :
14310                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14311                                 res->mac.addr_bytes, res->pi);
14312 #endif
14313         RTE_SET_USED(is_tx);
14314
14315         switch (ret) {
14316         case 0:
14317                 break;
14318         case -ENODEV:
14319                 printf("invalid port_id %d\n", res->port_id);
14320                 break;
14321         case -ENOTSUP:
14322                 printf("not supported on port %d\n", res->port_id);
14323                 break;
14324         default:
14325                 printf("programming error: (%s)\n", strerror(-ret));
14326         }
14327 }
14328
14329 cmdline_parse_inst_t cmd_set_macsec_sc = {
14330         .f = cmd_set_macsec_sc_parsed,
14331         .data = NULL,
14332         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14333         .tokens = {
14334                 (void *)&cmd_macsec_sc_set,
14335                 (void *)&cmd_macsec_sc_macsec,
14336                 (void *)&cmd_macsec_sc_sc,
14337                 (void *)&cmd_macsec_sc_tx_rx,
14338                 (void *)&cmd_macsec_sc_port_id,
14339                 (void *)&cmd_macsec_sc_mac,
14340                 (void *)&cmd_macsec_sc_pi,
14341                 NULL,
14342         },
14343 };
14344
14345 /* Common result structure for MACsec secure connection configure */
14346 struct cmd_macsec_sa_result {
14347         cmdline_fixed_string_t set;
14348         cmdline_fixed_string_t macsec;
14349         cmdline_fixed_string_t sa;
14350         cmdline_fixed_string_t tx_rx;
14351         portid_t port_id;
14352         uint8_t idx;
14353         uint8_t an;
14354         uint32_t pn;
14355         cmdline_fixed_string_t key;
14356 };
14357
14358 /* Common CLI fields for MACsec secure connection configure */
14359 cmdline_parse_token_string_t cmd_macsec_sa_set =
14360         TOKEN_STRING_INITIALIZER
14361                 (struct cmd_macsec_sa_result,
14362                  set, "set");
14363 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14364         TOKEN_STRING_INITIALIZER
14365                 (struct cmd_macsec_sa_result,
14366                  macsec, "macsec");
14367 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14368         TOKEN_STRING_INITIALIZER
14369                 (struct cmd_macsec_sa_result,
14370                  sa, "sa");
14371 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14372         TOKEN_STRING_INITIALIZER
14373                 (struct cmd_macsec_sa_result,
14374                  tx_rx, "tx#rx");
14375 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14376         TOKEN_NUM_INITIALIZER
14377                 (struct cmd_macsec_sa_result,
14378                  port_id, UINT16);
14379 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14380         TOKEN_NUM_INITIALIZER
14381                 (struct cmd_macsec_sa_result,
14382                  idx, UINT8);
14383 cmdline_parse_token_num_t cmd_macsec_sa_an =
14384         TOKEN_NUM_INITIALIZER
14385                 (struct cmd_macsec_sa_result,
14386                  an, UINT8);
14387 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14388         TOKEN_NUM_INITIALIZER
14389                 (struct cmd_macsec_sa_result,
14390                  pn, UINT32);
14391 cmdline_parse_token_string_t cmd_macsec_sa_key =
14392         TOKEN_STRING_INITIALIZER
14393                 (struct cmd_macsec_sa_result,
14394                  key, NULL);
14395
14396 static void
14397 cmd_set_macsec_sa_parsed(
14398         void *parsed_result,
14399         __attribute__((unused)) struct cmdline *cl,
14400         __attribute__((unused)) void *data)
14401 {
14402         struct cmd_macsec_sa_result *res = parsed_result;
14403         int ret = -ENOTSUP;
14404         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14405         uint8_t key[16] = { 0 };
14406         uint8_t xdgt0;
14407         uint8_t xdgt1;
14408         int key_len;
14409         int i;
14410
14411         key_len = strlen(res->key) / 2;
14412         if (key_len > 16)
14413                 key_len = 16;
14414
14415         for (i = 0; i < key_len; i++) {
14416                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14417                 if (xdgt0 == 0xFF)
14418                         return;
14419                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14420                 if (xdgt1 == 0xFF)
14421                         return;
14422                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14423         }
14424
14425 #ifdef RTE_LIBRTE_IXGBE_PMD
14426         ret = is_tx ?
14427                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14428                         res->idx, res->an, res->pn, key) :
14429                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14430                         res->idx, res->an, res->pn, key);
14431 #endif
14432         RTE_SET_USED(is_tx);
14433         RTE_SET_USED(key);
14434
14435         switch (ret) {
14436         case 0:
14437                 break;
14438         case -EINVAL:
14439                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14440                 break;
14441         case -ENODEV:
14442                 printf("invalid port_id %d\n", res->port_id);
14443                 break;
14444         case -ENOTSUP:
14445                 printf("not supported on port %d\n", res->port_id);
14446                 break;
14447         default:
14448                 printf("programming error: (%s)\n", strerror(-ret));
14449         }
14450 }
14451
14452 cmdline_parse_inst_t cmd_set_macsec_sa = {
14453         .f = cmd_set_macsec_sa_parsed,
14454         .data = NULL,
14455         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14456         .tokens = {
14457                 (void *)&cmd_macsec_sa_set,
14458                 (void *)&cmd_macsec_sa_macsec,
14459                 (void *)&cmd_macsec_sa_sa,
14460                 (void *)&cmd_macsec_sa_tx_rx,
14461                 (void *)&cmd_macsec_sa_port_id,
14462                 (void *)&cmd_macsec_sa_idx,
14463                 (void *)&cmd_macsec_sa_an,
14464                 (void *)&cmd_macsec_sa_pn,
14465                 (void *)&cmd_macsec_sa_key,
14466                 NULL,
14467         },
14468 };
14469
14470 /* VF unicast promiscuous mode configuration */
14471
14472 /* Common result structure for VF unicast promiscuous mode */
14473 struct cmd_vf_promisc_result {
14474         cmdline_fixed_string_t set;
14475         cmdline_fixed_string_t vf;
14476         cmdline_fixed_string_t promisc;
14477         portid_t port_id;
14478         uint32_t vf_id;
14479         cmdline_fixed_string_t on_off;
14480 };
14481
14482 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14483 cmdline_parse_token_string_t cmd_vf_promisc_set =
14484         TOKEN_STRING_INITIALIZER
14485                 (struct cmd_vf_promisc_result,
14486                  set, "set");
14487 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14488         TOKEN_STRING_INITIALIZER
14489                 (struct cmd_vf_promisc_result,
14490                  vf, "vf");
14491 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14492         TOKEN_STRING_INITIALIZER
14493                 (struct cmd_vf_promisc_result,
14494                  promisc, "promisc");
14495 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14496         TOKEN_NUM_INITIALIZER
14497                 (struct cmd_vf_promisc_result,
14498                  port_id, UINT16);
14499 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14500         TOKEN_NUM_INITIALIZER
14501                 (struct cmd_vf_promisc_result,
14502                  vf_id, UINT32);
14503 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14504         TOKEN_STRING_INITIALIZER
14505                 (struct cmd_vf_promisc_result,
14506                  on_off, "on#off");
14507
14508 static void
14509 cmd_set_vf_promisc_parsed(
14510         void *parsed_result,
14511         __attribute__((unused)) struct cmdline *cl,
14512         __attribute__((unused)) void *data)
14513 {
14514         struct cmd_vf_promisc_result *res = parsed_result;
14515         int ret = -ENOTSUP;
14516
14517         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14518
14519         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14520                 return;
14521
14522 #ifdef RTE_LIBRTE_I40E_PMD
14523         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14524                                                   res->vf_id, is_on);
14525 #endif
14526
14527         switch (ret) {
14528         case 0:
14529                 break;
14530         case -EINVAL:
14531                 printf("invalid vf_id %d\n", res->vf_id);
14532                 break;
14533         case -ENODEV:
14534                 printf("invalid port_id %d\n", res->port_id);
14535                 break;
14536         case -ENOTSUP:
14537                 printf("function not implemented\n");
14538                 break;
14539         default:
14540                 printf("programming error: (%s)\n", strerror(-ret));
14541         }
14542 }
14543
14544 cmdline_parse_inst_t cmd_set_vf_promisc = {
14545         .f = cmd_set_vf_promisc_parsed,
14546         .data = NULL,
14547         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14548                 "Set unicast promiscuous mode for a VF from the PF",
14549         .tokens = {
14550                 (void *)&cmd_vf_promisc_set,
14551                 (void *)&cmd_vf_promisc_vf,
14552                 (void *)&cmd_vf_promisc_promisc,
14553                 (void *)&cmd_vf_promisc_port_id,
14554                 (void *)&cmd_vf_promisc_vf_id,
14555                 (void *)&cmd_vf_promisc_on_off,
14556                 NULL,
14557         },
14558 };
14559
14560 /* VF multicast promiscuous mode configuration */
14561
14562 /* Common result structure for VF multicast promiscuous mode */
14563 struct cmd_vf_allmulti_result {
14564         cmdline_fixed_string_t set;
14565         cmdline_fixed_string_t vf;
14566         cmdline_fixed_string_t allmulti;
14567         portid_t port_id;
14568         uint32_t vf_id;
14569         cmdline_fixed_string_t on_off;
14570 };
14571
14572 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14573 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14574         TOKEN_STRING_INITIALIZER
14575                 (struct cmd_vf_allmulti_result,
14576                  set, "set");
14577 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14578         TOKEN_STRING_INITIALIZER
14579                 (struct cmd_vf_allmulti_result,
14580                  vf, "vf");
14581 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14582         TOKEN_STRING_INITIALIZER
14583                 (struct cmd_vf_allmulti_result,
14584                  allmulti, "allmulti");
14585 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14586         TOKEN_NUM_INITIALIZER
14587                 (struct cmd_vf_allmulti_result,
14588                  port_id, UINT16);
14589 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14590         TOKEN_NUM_INITIALIZER
14591                 (struct cmd_vf_allmulti_result,
14592                  vf_id, UINT32);
14593 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14594         TOKEN_STRING_INITIALIZER
14595                 (struct cmd_vf_allmulti_result,
14596                  on_off, "on#off");
14597
14598 static void
14599 cmd_set_vf_allmulti_parsed(
14600         void *parsed_result,
14601         __attribute__((unused)) struct cmdline *cl,
14602         __attribute__((unused)) void *data)
14603 {
14604         struct cmd_vf_allmulti_result *res = parsed_result;
14605         int ret = -ENOTSUP;
14606
14607         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14608
14609         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14610                 return;
14611
14612 #ifdef RTE_LIBRTE_I40E_PMD
14613         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14614                                                     res->vf_id, is_on);
14615 #endif
14616
14617         switch (ret) {
14618         case 0:
14619                 break;
14620         case -EINVAL:
14621                 printf("invalid vf_id %d\n", res->vf_id);
14622                 break;
14623         case -ENODEV:
14624                 printf("invalid port_id %d\n", res->port_id);
14625                 break;
14626         case -ENOTSUP:
14627                 printf("function not implemented\n");
14628                 break;
14629         default:
14630                 printf("programming error: (%s)\n", strerror(-ret));
14631         }
14632 }
14633
14634 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14635         .f = cmd_set_vf_allmulti_parsed,
14636         .data = NULL,
14637         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14638                 "Set multicast promiscuous mode for a VF from the PF",
14639         .tokens = {
14640                 (void *)&cmd_vf_allmulti_set,
14641                 (void *)&cmd_vf_allmulti_vf,
14642                 (void *)&cmd_vf_allmulti_allmulti,
14643                 (void *)&cmd_vf_allmulti_port_id,
14644                 (void *)&cmd_vf_allmulti_vf_id,
14645                 (void *)&cmd_vf_allmulti_on_off,
14646                 NULL,
14647         },
14648 };
14649
14650 /* vf broadcast mode configuration */
14651
14652 /* Common result structure for vf broadcast */
14653 struct cmd_set_vf_broadcast_result {
14654         cmdline_fixed_string_t set;
14655         cmdline_fixed_string_t vf;
14656         cmdline_fixed_string_t broadcast;
14657         portid_t port_id;
14658         uint16_t vf_id;
14659         cmdline_fixed_string_t on_off;
14660 };
14661
14662 /* Common CLI fields for vf broadcast enable disable */
14663 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14664         TOKEN_STRING_INITIALIZER
14665                 (struct cmd_set_vf_broadcast_result,
14666                  set, "set");
14667 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14668         TOKEN_STRING_INITIALIZER
14669                 (struct cmd_set_vf_broadcast_result,
14670                  vf, "vf");
14671 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14672         TOKEN_STRING_INITIALIZER
14673                 (struct cmd_set_vf_broadcast_result,
14674                  broadcast, "broadcast");
14675 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14676         TOKEN_NUM_INITIALIZER
14677                 (struct cmd_set_vf_broadcast_result,
14678                  port_id, UINT16);
14679 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14680         TOKEN_NUM_INITIALIZER
14681                 (struct cmd_set_vf_broadcast_result,
14682                  vf_id, UINT16);
14683 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14684         TOKEN_STRING_INITIALIZER
14685                 (struct cmd_set_vf_broadcast_result,
14686                  on_off, "on#off");
14687
14688 static void
14689 cmd_set_vf_broadcast_parsed(
14690         void *parsed_result,
14691         __attribute__((unused)) struct cmdline *cl,
14692         __attribute__((unused)) void *data)
14693 {
14694         struct cmd_set_vf_broadcast_result *res = parsed_result;
14695         int ret = -ENOTSUP;
14696
14697         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14698
14699         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14700                 return;
14701
14702 #ifdef RTE_LIBRTE_I40E_PMD
14703         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14704                                             res->vf_id, is_on);
14705 #endif
14706
14707         switch (ret) {
14708         case 0:
14709                 break;
14710         case -EINVAL:
14711                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14712                 break;
14713         case -ENODEV:
14714                 printf("invalid port_id %d\n", res->port_id);
14715                 break;
14716         case -ENOTSUP:
14717                 printf("function not implemented\n");
14718                 break;
14719         default:
14720                 printf("programming error: (%s)\n", strerror(-ret));
14721         }
14722 }
14723
14724 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14725         .f = cmd_set_vf_broadcast_parsed,
14726         .data = NULL,
14727         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14728         .tokens = {
14729                 (void *)&cmd_set_vf_broadcast_set,
14730                 (void *)&cmd_set_vf_broadcast_vf,
14731                 (void *)&cmd_set_vf_broadcast_broadcast,
14732                 (void *)&cmd_set_vf_broadcast_port_id,
14733                 (void *)&cmd_set_vf_broadcast_vf_id,
14734                 (void *)&cmd_set_vf_broadcast_on_off,
14735                 NULL,
14736         },
14737 };
14738
14739 /* vf vlan tag configuration */
14740
14741 /* Common result structure for vf vlan tag */
14742 struct cmd_set_vf_vlan_tag_result {
14743         cmdline_fixed_string_t set;
14744         cmdline_fixed_string_t vf;
14745         cmdline_fixed_string_t vlan;
14746         cmdline_fixed_string_t tag;
14747         portid_t port_id;
14748         uint16_t vf_id;
14749         cmdline_fixed_string_t on_off;
14750 };
14751
14752 /* Common CLI fields for vf vlan tag enable disable */
14753 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14754         TOKEN_STRING_INITIALIZER
14755                 (struct cmd_set_vf_vlan_tag_result,
14756                  set, "set");
14757 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14758         TOKEN_STRING_INITIALIZER
14759                 (struct cmd_set_vf_vlan_tag_result,
14760                  vf, "vf");
14761 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14762         TOKEN_STRING_INITIALIZER
14763                 (struct cmd_set_vf_vlan_tag_result,
14764                  vlan, "vlan");
14765 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14766         TOKEN_STRING_INITIALIZER
14767                 (struct cmd_set_vf_vlan_tag_result,
14768                  tag, "tag");
14769 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14770         TOKEN_NUM_INITIALIZER
14771                 (struct cmd_set_vf_vlan_tag_result,
14772                  port_id, UINT16);
14773 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14774         TOKEN_NUM_INITIALIZER
14775                 (struct cmd_set_vf_vlan_tag_result,
14776                  vf_id, UINT16);
14777 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14778         TOKEN_STRING_INITIALIZER
14779                 (struct cmd_set_vf_vlan_tag_result,
14780                  on_off, "on#off");
14781
14782 static void
14783 cmd_set_vf_vlan_tag_parsed(
14784         void *parsed_result,
14785         __attribute__((unused)) struct cmdline *cl,
14786         __attribute__((unused)) void *data)
14787 {
14788         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14789         int ret = -ENOTSUP;
14790
14791         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14792
14793         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14794                 return;
14795
14796 #ifdef RTE_LIBRTE_I40E_PMD
14797         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14798                                            res->vf_id, is_on);
14799 #endif
14800
14801         switch (ret) {
14802         case 0:
14803                 break;
14804         case -EINVAL:
14805                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14806                 break;
14807         case -ENODEV:
14808                 printf("invalid port_id %d\n", res->port_id);
14809                 break;
14810         case -ENOTSUP:
14811                 printf("function not implemented\n");
14812                 break;
14813         default:
14814                 printf("programming error: (%s)\n", strerror(-ret));
14815         }
14816 }
14817
14818 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14819         .f = cmd_set_vf_vlan_tag_parsed,
14820         .data = NULL,
14821         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14822         .tokens = {
14823                 (void *)&cmd_set_vf_vlan_tag_set,
14824                 (void *)&cmd_set_vf_vlan_tag_vf,
14825                 (void *)&cmd_set_vf_vlan_tag_vlan,
14826                 (void *)&cmd_set_vf_vlan_tag_tag,
14827                 (void *)&cmd_set_vf_vlan_tag_port_id,
14828                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14829                 (void *)&cmd_set_vf_vlan_tag_on_off,
14830                 NULL,
14831         },
14832 };
14833
14834 /* Common definition of VF and TC TX bandwidth configuration */
14835 struct cmd_vf_tc_bw_result {
14836         cmdline_fixed_string_t set;
14837         cmdline_fixed_string_t vf;
14838         cmdline_fixed_string_t tc;
14839         cmdline_fixed_string_t tx;
14840         cmdline_fixed_string_t min_bw;
14841         cmdline_fixed_string_t max_bw;
14842         cmdline_fixed_string_t strict_link_prio;
14843         portid_t port_id;
14844         uint16_t vf_id;
14845         uint8_t tc_no;
14846         uint32_t bw;
14847         cmdline_fixed_string_t bw_list;
14848         uint8_t tc_map;
14849 };
14850
14851 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14852         TOKEN_STRING_INITIALIZER
14853                 (struct cmd_vf_tc_bw_result,
14854                  set, "set");
14855 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14856         TOKEN_STRING_INITIALIZER
14857                 (struct cmd_vf_tc_bw_result,
14858                  vf, "vf");
14859 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14860         TOKEN_STRING_INITIALIZER
14861                 (struct cmd_vf_tc_bw_result,
14862                  tc, "tc");
14863 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14864         TOKEN_STRING_INITIALIZER
14865                 (struct cmd_vf_tc_bw_result,
14866                  tx, "tx");
14867 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14868         TOKEN_STRING_INITIALIZER
14869                 (struct cmd_vf_tc_bw_result,
14870                  strict_link_prio, "strict-link-priority");
14871 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14872         TOKEN_STRING_INITIALIZER
14873                 (struct cmd_vf_tc_bw_result,
14874                  min_bw, "min-bandwidth");
14875 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14876         TOKEN_STRING_INITIALIZER
14877                 (struct cmd_vf_tc_bw_result,
14878                  max_bw, "max-bandwidth");
14879 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14880         TOKEN_NUM_INITIALIZER
14881                 (struct cmd_vf_tc_bw_result,
14882                  port_id, UINT16);
14883 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14884         TOKEN_NUM_INITIALIZER
14885                 (struct cmd_vf_tc_bw_result,
14886                  vf_id, UINT16);
14887 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14888         TOKEN_NUM_INITIALIZER
14889                 (struct cmd_vf_tc_bw_result,
14890                  tc_no, UINT8);
14891 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14892         TOKEN_NUM_INITIALIZER
14893                 (struct cmd_vf_tc_bw_result,
14894                  bw, UINT32);
14895 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14896         TOKEN_STRING_INITIALIZER
14897                 (struct cmd_vf_tc_bw_result,
14898                  bw_list, NULL);
14899 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14900         TOKEN_NUM_INITIALIZER
14901                 (struct cmd_vf_tc_bw_result,
14902                  tc_map, UINT8);
14903
14904 /* VF max bandwidth setting */
14905 static void
14906 cmd_vf_max_bw_parsed(
14907         void *parsed_result,
14908         __attribute__((unused)) struct cmdline *cl,
14909         __attribute__((unused)) void *data)
14910 {
14911         struct cmd_vf_tc_bw_result *res = parsed_result;
14912         int ret = -ENOTSUP;
14913
14914         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14915                 return;
14916
14917 #ifdef RTE_LIBRTE_I40E_PMD
14918         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14919                                          res->vf_id, res->bw);
14920 #endif
14921
14922         switch (ret) {
14923         case 0:
14924                 break;
14925         case -EINVAL:
14926                 printf("invalid vf_id %d or bandwidth %d\n",
14927                        res->vf_id, res->bw);
14928                 break;
14929         case -ENODEV:
14930                 printf("invalid port_id %d\n", res->port_id);
14931                 break;
14932         case -ENOTSUP:
14933                 printf("function not implemented\n");
14934                 break;
14935         default:
14936                 printf("programming error: (%s)\n", strerror(-ret));
14937         }
14938 }
14939
14940 cmdline_parse_inst_t cmd_vf_max_bw = {
14941         .f = cmd_vf_max_bw_parsed,
14942         .data = NULL,
14943         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14944         .tokens = {
14945                 (void *)&cmd_vf_tc_bw_set,
14946                 (void *)&cmd_vf_tc_bw_vf,
14947                 (void *)&cmd_vf_tc_bw_tx,
14948                 (void *)&cmd_vf_tc_bw_max_bw,
14949                 (void *)&cmd_vf_tc_bw_port_id,
14950                 (void *)&cmd_vf_tc_bw_vf_id,
14951                 (void *)&cmd_vf_tc_bw_bw,
14952                 NULL,
14953         },
14954 };
14955
14956 static int
14957 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14958                            uint8_t *tc_num,
14959                            char *str)
14960 {
14961         uint32_t size;
14962         const char *p, *p0 = str;
14963         char s[256];
14964         char *end;
14965         char *str_fld[16];
14966         uint16_t i;
14967         int ret;
14968
14969         p = strchr(p0, '(');
14970         if (p == NULL) {
14971                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14972                 return -1;
14973         }
14974         p++;
14975         p0 = strchr(p, ')');
14976         if (p0 == NULL) {
14977                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14978                 return -1;
14979         }
14980         size = p0 - p;
14981         if (size >= sizeof(s)) {
14982                 printf("The string size exceeds the internal buffer size\n");
14983                 return -1;
14984         }
14985         snprintf(s, sizeof(s), "%.*s", size, p);
14986         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14987         if (ret <= 0) {
14988                 printf("Failed to get the bandwidth list. ");
14989                 return -1;
14990         }
14991         *tc_num = ret;
14992         for (i = 0; i < ret; i++)
14993                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14994
14995         return 0;
14996 }
14997
14998 /* TC min bandwidth setting */
14999 static void
15000 cmd_vf_tc_min_bw_parsed(
15001         void *parsed_result,
15002         __attribute__((unused)) struct cmdline *cl,
15003         __attribute__((unused)) void *data)
15004 {
15005         struct cmd_vf_tc_bw_result *res = parsed_result;
15006         uint8_t tc_num;
15007         uint8_t bw[16];
15008         int ret = -ENOTSUP;
15009
15010         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15011                 return;
15012
15013         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15014         if (ret)
15015                 return;
15016
15017 #ifdef RTE_LIBRTE_I40E_PMD
15018         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15019                                               tc_num, bw);
15020 #endif
15021
15022         switch (ret) {
15023         case 0:
15024                 break;
15025         case -EINVAL:
15026                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15027                 break;
15028         case -ENODEV:
15029                 printf("invalid port_id %d\n", res->port_id);
15030                 break;
15031         case -ENOTSUP:
15032                 printf("function not implemented\n");
15033                 break;
15034         default:
15035                 printf("programming error: (%s)\n", strerror(-ret));
15036         }
15037 }
15038
15039 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15040         .f = cmd_vf_tc_min_bw_parsed,
15041         .data = NULL,
15042         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15043                     " <bw1, bw2, ...>",
15044         .tokens = {
15045                 (void *)&cmd_vf_tc_bw_set,
15046                 (void *)&cmd_vf_tc_bw_vf,
15047                 (void *)&cmd_vf_tc_bw_tc,
15048                 (void *)&cmd_vf_tc_bw_tx,
15049                 (void *)&cmd_vf_tc_bw_min_bw,
15050                 (void *)&cmd_vf_tc_bw_port_id,
15051                 (void *)&cmd_vf_tc_bw_vf_id,
15052                 (void *)&cmd_vf_tc_bw_bw_list,
15053                 NULL,
15054         },
15055 };
15056
15057 static void
15058 cmd_tc_min_bw_parsed(
15059         void *parsed_result,
15060         __attribute__((unused)) struct cmdline *cl,
15061         __attribute__((unused)) void *data)
15062 {
15063         struct cmd_vf_tc_bw_result *res = parsed_result;
15064         struct rte_port *port;
15065         uint8_t tc_num;
15066         uint8_t bw[16];
15067         int ret = -ENOTSUP;
15068
15069         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15070                 return;
15071
15072         port = &ports[res->port_id];
15073         /** Check if the port is not started **/
15074         if (port->port_status != RTE_PORT_STOPPED) {
15075                 printf("Please stop port %d first\n", res->port_id);
15076                 return;
15077         }
15078
15079         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15080         if (ret)
15081                 return;
15082
15083 #ifdef RTE_LIBRTE_IXGBE_PMD
15084         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15085 #endif
15086
15087         switch (ret) {
15088         case 0:
15089                 break;
15090         case -EINVAL:
15091                 printf("invalid bandwidth\n");
15092                 break;
15093         case -ENODEV:
15094                 printf("invalid port_id %d\n", res->port_id);
15095                 break;
15096         case -ENOTSUP:
15097                 printf("function not implemented\n");
15098                 break;
15099         default:
15100                 printf("programming error: (%s)\n", strerror(-ret));
15101         }
15102 }
15103
15104 cmdline_parse_inst_t cmd_tc_min_bw = {
15105         .f = cmd_tc_min_bw_parsed,
15106         .data = NULL,
15107         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15108         .tokens = {
15109                 (void *)&cmd_vf_tc_bw_set,
15110                 (void *)&cmd_vf_tc_bw_tc,
15111                 (void *)&cmd_vf_tc_bw_tx,
15112                 (void *)&cmd_vf_tc_bw_min_bw,
15113                 (void *)&cmd_vf_tc_bw_port_id,
15114                 (void *)&cmd_vf_tc_bw_bw_list,
15115                 NULL,
15116         },
15117 };
15118
15119 /* TC max bandwidth setting */
15120 static void
15121 cmd_vf_tc_max_bw_parsed(
15122         void *parsed_result,
15123         __attribute__((unused)) struct cmdline *cl,
15124         __attribute__((unused)) void *data)
15125 {
15126         struct cmd_vf_tc_bw_result *res = parsed_result;
15127         int ret = -ENOTSUP;
15128
15129         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15130                 return;
15131
15132 #ifdef RTE_LIBRTE_I40E_PMD
15133         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15134                                             res->tc_no, res->bw);
15135 #endif
15136
15137         switch (ret) {
15138         case 0:
15139                 break;
15140         case -EINVAL:
15141                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15142                        res->vf_id, res->tc_no, res->bw);
15143                 break;
15144         case -ENODEV:
15145                 printf("invalid port_id %d\n", res->port_id);
15146                 break;
15147         case -ENOTSUP:
15148                 printf("function not implemented\n");
15149                 break;
15150         default:
15151                 printf("programming error: (%s)\n", strerror(-ret));
15152         }
15153 }
15154
15155 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15156         .f = cmd_vf_tc_max_bw_parsed,
15157         .data = NULL,
15158         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15159                     " <bandwidth>",
15160         .tokens = {
15161                 (void *)&cmd_vf_tc_bw_set,
15162                 (void *)&cmd_vf_tc_bw_vf,
15163                 (void *)&cmd_vf_tc_bw_tc,
15164                 (void *)&cmd_vf_tc_bw_tx,
15165                 (void *)&cmd_vf_tc_bw_max_bw,
15166                 (void *)&cmd_vf_tc_bw_port_id,
15167                 (void *)&cmd_vf_tc_bw_vf_id,
15168                 (void *)&cmd_vf_tc_bw_tc_no,
15169                 (void *)&cmd_vf_tc_bw_bw,
15170                 NULL,
15171         },
15172 };
15173
15174
15175 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15176
15177 /* *** Set Port default Traffic Management Hierarchy *** */
15178 struct cmd_set_port_tm_hierarchy_default_result {
15179         cmdline_fixed_string_t set;
15180         cmdline_fixed_string_t port;
15181         cmdline_fixed_string_t tm;
15182         cmdline_fixed_string_t hierarchy;
15183         cmdline_fixed_string_t def;
15184         portid_t port_id;
15185 };
15186
15187 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15188         TOKEN_STRING_INITIALIZER(
15189                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15190 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15191         TOKEN_STRING_INITIALIZER(
15192                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15193 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15194         TOKEN_STRING_INITIALIZER(
15195                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15196 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15197         TOKEN_STRING_INITIALIZER(
15198                 struct cmd_set_port_tm_hierarchy_default_result,
15199                         hierarchy, "hierarchy");
15200 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15201         TOKEN_STRING_INITIALIZER(
15202                 struct cmd_set_port_tm_hierarchy_default_result,
15203                         def, "default");
15204 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15205         TOKEN_NUM_INITIALIZER(
15206                 struct cmd_set_port_tm_hierarchy_default_result,
15207                         port_id, UINT16);
15208
15209 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15210         __attribute__((unused)) struct cmdline *cl,
15211         __attribute__((unused)) void *data)
15212 {
15213         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15214         struct rte_port *p;
15215         portid_t port_id = res->port_id;
15216
15217         if (port_id_is_invalid(port_id, ENABLED_WARN))
15218                 return;
15219
15220         p = &ports[port_id];
15221
15222         /* Forward mode: tm */
15223         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15224                 printf("  softnicfwd mode not enabled(error)\n");
15225                 return;
15226         }
15227
15228         /* Set the default tm hierarchy */
15229         p->softport.default_tm_hierarchy_enable = 1;
15230 }
15231
15232 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15233         .f = cmd_set_port_tm_hierarchy_default_parsed,
15234         .data = NULL,
15235         .help_str = "set port tm hierarchy default <port_id>",
15236         .tokens = {
15237                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15238                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15239                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15240                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15241                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15242                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15243                 NULL,
15244         },
15245 };
15246 #endif
15247
15248 /** Set VXLAN encapsulation details */
15249 struct cmd_set_vxlan_result {
15250         cmdline_fixed_string_t set;
15251         cmdline_fixed_string_t vxlan;
15252         cmdline_fixed_string_t pos_token;
15253         cmdline_fixed_string_t ip_version;
15254         uint32_t vlan_present:1;
15255         uint32_t vni;
15256         uint16_t udp_src;
15257         uint16_t udp_dst;
15258         cmdline_ipaddr_t ip_src;
15259         cmdline_ipaddr_t ip_dst;
15260         uint16_t tci;
15261         uint8_t tos;
15262         uint8_t ttl;
15263         struct rte_ether_addr eth_src;
15264         struct rte_ether_addr eth_dst;
15265 };
15266
15267 cmdline_parse_token_string_t cmd_set_vxlan_set =
15268         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15269 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15270         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15271 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15272         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15273                                  "vxlan-tos-ttl");
15274 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15275         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15276                                  "vxlan-with-vlan");
15277 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15278         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15279                                  "ip-version");
15280 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15281         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15282                                  "ipv4#ipv6");
15283 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15284         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15285                                  "vni");
15286 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15287         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15288 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15289         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15290                                  "udp-src");
15291 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15292         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15293 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15294         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15295                                  "udp-dst");
15296 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15297         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15298 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15299         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15300                                  "ip-tos");
15301 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15302         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15303 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15304         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15305                                  "ip-ttl");
15306 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15307         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15308 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15309         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15310                                  "ip-src");
15311 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15312         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15313 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15314         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15315                                  "ip-dst");
15316 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15317         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15318 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15319         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15320                                  "vlan-tci");
15321 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15322         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15323 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15324         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15325                                  "eth-src");
15326 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15327         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15328 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15329         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15330                                  "eth-dst");
15331 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15332         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15333
15334 static void cmd_set_vxlan_parsed(void *parsed_result,
15335         __attribute__((unused)) struct cmdline *cl,
15336         __attribute__((unused)) void *data)
15337 {
15338         struct cmd_set_vxlan_result *res = parsed_result;
15339         union {
15340                 uint32_t vxlan_id;
15341                 uint8_t vni[4];
15342         } id = {
15343                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15344         };
15345
15346         vxlan_encap_conf.select_tos_ttl = 0;
15347         if (strcmp(res->vxlan, "vxlan") == 0)
15348                 vxlan_encap_conf.select_vlan = 0;
15349         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15350                 vxlan_encap_conf.select_vlan = 1;
15351         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15352                 vxlan_encap_conf.select_vlan = 0;
15353                 vxlan_encap_conf.select_tos_ttl = 1;
15354         }
15355         if (strcmp(res->ip_version, "ipv4") == 0)
15356                 vxlan_encap_conf.select_ipv4 = 1;
15357         else if (strcmp(res->ip_version, "ipv6") == 0)
15358                 vxlan_encap_conf.select_ipv4 = 0;
15359         else
15360                 return;
15361         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15362         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15363         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15364         vxlan_encap_conf.ip_tos = res->tos;
15365         vxlan_encap_conf.ip_ttl = res->ttl;
15366         if (vxlan_encap_conf.select_ipv4) {
15367                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15368                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15369         } else {
15370                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15371                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15372         }
15373         if (vxlan_encap_conf.select_vlan)
15374                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15375         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15376                    RTE_ETHER_ADDR_LEN);
15377         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15378                    RTE_ETHER_ADDR_LEN);
15379 }
15380
15381 cmdline_parse_inst_t cmd_set_vxlan = {
15382         .f = cmd_set_vxlan_parsed,
15383         .data = NULL,
15384         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15385                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15386                 " eth-src <eth-src> eth-dst <eth-dst>",
15387         .tokens = {
15388                 (void *)&cmd_set_vxlan_set,
15389                 (void *)&cmd_set_vxlan_vxlan,
15390                 (void *)&cmd_set_vxlan_ip_version,
15391                 (void *)&cmd_set_vxlan_ip_version_value,
15392                 (void *)&cmd_set_vxlan_vni,
15393                 (void *)&cmd_set_vxlan_vni_value,
15394                 (void *)&cmd_set_vxlan_udp_src,
15395                 (void *)&cmd_set_vxlan_udp_src_value,
15396                 (void *)&cmd_set_vxlan_udp_dst,
15397                 (void *)&cmd_set_vxlan_udp_dst_value,
15398                 (void *)&cmd_set_vxlan_ip_src,
15399                 (void *)&cmd_set_vxlan_ip_src_value,
15400                 (void *)&cmd_set_vxlan_ip_dst,
15401                 (void *)&cmd_set_vxlan_ip_dst_value,
15402                 (void *)&cmd_set_vxlan_eth_src,
15403                 (void *)&cmd_set_vxlan_eth_src_value,
15404                 (void *)&cmd_set_vxlan_eth_dst,
15405                 (void *)&cmd_set_vxlan_eth_dst_value,
15406                 NULL,
15407         },
15408 };
15409
15410 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15411         .f = cmd_set_vxlan_parsed,
15412         .data = NULL,
15413         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15414                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15415                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15416                 " eth-dst <eth-dst>",
15417         .tokens = {
15418                 (void *)&cmd_set_vxlan_set,
15419                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15420                 (void *)&cmd_set_vxlan_ip_version,
15421                 (void *)&cmd_set_vxlan_ip_version_value,
15422                 (void *)&cmd_set_vxlan_vni,
15423                 (void *)&cmd_set_vxlan_vni_value,
15424                 (void *)&cmd_set_vxlan_udp_src,
15425                 (void *)&cmd_set_vxlan_udp_src_value,
15426                 (void *)&cmd_set_vxlan_udp_dst,
15427                 (void *)&cmd_set_vxlan_udp_dst_value,
15428                 (void *)&cmd_set_vxlan_ip_tos,
15429                 (void *)&cmd_set_vxlan_ip_tos_value,
15430                 (void *)&cmd_set_vxlan_ip_ttl,
15431                 (void *)&cmd_set_vxlan_ip_ttl_value,
15432                 (void *)&cmd_set_vxlan_ip_src,
15433                 (void *)&cmd_set_vxlan_ip_src_value,
15434                 (void *)&cmd_set_vxlan_ip_dst,
15435                 (void *)&cmd_set_vxlan_ip_dst_value,
15436                 (void *)&cmd_set_vxlan_eth_src,
15437                 (void *)&cmd_set_vxlan_eth_src_value,
15438                 (void *)&cmd_set_vxlan_eth_dst,
15439                 (void *)&cmd_set_vxlan_eth_dst_value,
15440                 NULL,
15441         },
15442 };
15443
15444 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15445         .f = cmd_set_vxlan_parsed,
15446         .data = NULL,
15447         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15448                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15449                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15450                 " <eth-dst>",
15451         .tokens = {
15452                 (void *)&cmd_set_vxlan_set,
15453                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15454                 (void *)&cmd_set_vxlan_ip_version,
15455                 (void *)&cmd_set_vxlan_ip_version_value,
15456                 (void *)&cmd_set_vxlan_vni,
15457                 (void *)&cmd_set_vxlan_vni_value,
15458                 (void *)&cmd_set_vxlan_udp_src,
15459                 (void *)&cmd_set_vxlan_udp_src_value,
15460                 (void *)&cmd_set_vxlan_udp_dst,
15461                 (void *)&cmd_set_vxlan_udp_dst_value,
15462                 (void *)&cmd_set_vxlan_ip_src,
15463                 (void *)&cmd_set_vxlan_ip_src_value,
15464                 (void *)&cmd_set_vxlan_ip_dst,
15465                 (void *)&cmd_set_vxlan_ip_dst_value,
15466                 (void *)&cmd_set_vxlan_vlan,
15467                 (void *)&cmd_set_vxlan_vlan_value,
15468                 (void *)&cmd_set_vxlan_eth_src,
15469                 (void *)&cmd_set_vxlan_eth_src_value,
15470                 (void *)&cmd_set_vxlan_eth_dst,
15471                 (void *)&cmd_set_vxlan_eth_dst_value,
15472                 NULL,
15473         },
15474 };
15475
15476 /** Set NVGRE encapsulation details */
15477 struct cmd_set_nvgre_result {
15478         cmdline_fixed_string_t set;
15479         cmdline_fixed_string_t nvgre;
15480         cmdline_fixed_string_t pos_token;
15481         cmdline_fixed_string_t ip_version;
15482         uint32_t tni;
15483         cmdline_ipaddr_t ip_src;
15484         cmdline_ipaddr_t ip_dst;
15485         uint16_t tci;
15486         struct rte_ether_addr eth_src;
15487         struct rte_ether_addr eth_dst;
15488 };
15489
15490 cmdline_parse_token_string_t cmd_set_nvgre_set =
15491         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15492 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15493         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15494 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15495         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15496                                  "nvgre-with-vlan");
15497 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15498         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15499                                  "ip-version");
15500 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15501         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15502                                  "ipv4#ipv6");
15503 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15504         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15505                                  "tni");
15506 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15507         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15508 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15509         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15510                                  "ip-src");
15511 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15512         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15513 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15514         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15515                                  "ip-dst");
15516 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15517         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15518 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15519         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15520                                  "vlan-tci");
15521 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15522         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15523 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15524         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15525                                  "eth-src");
15526 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15527         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15528 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15529         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15530                                  "eth-dst");
15531 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15532         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15533
15534 static void cmd_set_nvgre_parsed(void *parsed_result,
15535         __attribute__((unused)) struct cmdline *cl,
15536         __attribute__((unused)) void *data)
15537 {
15538         struct cmd_set_nvgre_result *res = parsed_result;
15539         union {
15540                 uint32_t nvgre_tni;
15541                 uint8_t tni[4];
15542         } id = {
15543                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15544         };
15545
15546         if (strcmp(res->nvgre, "nvgre") == 0)
15547                 nvgre_encap_conf.select_vlan = 0;
15548         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15549                 nvgre_encap_conf.select_vlan = 1;
15550         if (strcmp(res->ip_version, "ipv4") == 0)
15551                 nvgre_encap_conf.select_ipv4 = 1;
15552         else if (strcmp(res->ip_version, "ipv6") == 0)
15553                 nvgre_encap_conf.select_ipv4 = 0;
15554         else
15555                 return;
15556         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15557         if (nvgre_encap_conf.select_ipv4) {
15558                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15559                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15560         } else {
15561                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15562                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15563         }
15564         if (nvgre_encap_conf.select_vlan)
15565                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15566         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15567                    RTE_ETHER_ADDR_LEN);
15568         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15569                    RTE_ETHER_ADDR_LEN);
15570 }
15571
15572 cmdline_parse_inst_t cmd_set_nvgre = {
15573         .f = cmd_set_nvgre_parsed,
15574         .data = NULL,
15575         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15576                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15577                 " eth-dst <eth-dst>",
15578         .tokens = {
15579                 (void *)&cmd_set_nvgre_set,
15580                 (void *)&cmd_set_nvgre_nvgre,
15581                 (void *)&cmd_set_nvgre_ip_version,
15582                 (void *)&cmd_set_nvgre_ip_version_value,
15583                 (void *)&cmd_set_nvgre_tni,
15584                 (void *)&cmd_set_nvgre_tni_value,
15585                 (void *)&cmd_set_nvgre_ip_src,
15586                 (void *)&cmd_set_nvgre_ip_src_value,
15587                 (void *)&cmd_set_nvgre_ip_dst,
15588                 (void *)&cmd_set_nvgre_ip_dst_value,
15589                 (void *)&cmd_set_nvgre_eth_src,
15590                 (void *)&cmd_set_nvgre_eth_src_value,
15591                 (void *)&cmd_set_nvgre_eth_dst,
15592                 (void *)&cmd_set_nvgre_eth_dst_value,
15593                 NULL,
15594         },
15595 };
15596
15597 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15598         .f = cmd_set_nvgre_parsed,
15599         .data = NULL,
15600         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15601                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15602                 " eth-src <eth-src> eth-dst <eth-dst>",
15603         .tokens = {
15604                 (void *)&cmd_set_nvgre_set,
15605                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15606                 (void *)&cmd_set_nvgre_ip_version,
15607                 (void *)&cmd_set_nvgre_ip_version_value,
15608                 (void *)&cmd_set_nvgre_tni,
15609                 (void *)&cmd_set_nvgre_tni_value,
15610                 (void *)&cmd_set_nvgre_ip_src,
15611                 (void *)&cmd_set_nvgre_ip_src_value,
15612                 (void *)&cmd_set_nvgre_ip_dst,
15613                 (void *)&cmd_set_nvgre_ip_dst_value,
15614                 (void *)&cmd_set_nvgre_vlan,
15615                 (void *)&cmd_set_nvgre_vlan_value,
15616                 (void *)&cmd_set_nvgre_eth_src,
15617                 (void *)&cmd_set_nvgre_eth_src_value,
15618                 (void *)&cmd_set_nvgre_eth_dst,
15619                 (void *)&cmd_set_nvgre_eth_dst_value,
15620                 NULL,
15621         },
15622 };
15623
15624 /** Set L2 encapsulation details */
15625 struct cmd_set_l2_encap_result {
15626         cmdline_fixed_string_t set;
15627         cmdline_fixed_string_t l2_encap;
15628         cmdline_fixed_string_t pos_token;
15629         cmdline_fixed_string_t ip_version;
15630         uint32_t vlan_present:1;
15631         uint16_t tci;
15632         struct rte_ether_addr eth_src;
15633         struct rte_ether_addr eth_dst;
15634 };
15635
15636 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15637         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15638 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15639         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15640 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15641         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15642                                  "l2_encap-with-vlan");
15643 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15644         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15645                                  "ip-version");
15646 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15647         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15648                                  "ipv4#ipv6");
15649 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15650         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15651                                  "vlan-tci");
15652 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15653         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15654 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15655         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15656                                  "eth-src");
15657 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15658         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15659 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15660         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15661                                  "eth-dst");
15662 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15663         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15664
15665 static void cmd_set_l2_encap_parsed(void *parsed_result,
15666         __attribute__((unused)) struct cmdline *cl,
15667         __attribute__((unused)) void *data)
15668 {
15669         struct cmd_set_l2_encap_result *res = parsed_result;
15670
15671         if (strcmp(res->l2_encap, "l2_encap") == 0)
15672                 l2_encap_conf.select_vlan = 0;
15673         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15674                 l2_encap_conf.select_vlan = 1;
15675         if (strcmp(res->ip_version, "ipv4") == 0)
15676                 l2_encap_conf.select_ipv4 = 1;
15677         else if (strcmp(res->ip_version, "ipv6") == 0)
15678                 l2_encap_conf.select_ipv4 = 0;
15679         else
15680                 return;
15681         if (l2_encap_conf.select_vlan)
15682                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15683         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15684                    RTE_ETHER_ADDR_LEN);
15685         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15686                    RTE_ETHER_ADDR_LEN);
15687 }
15688
15689 cmdline_parse_inst_t cmd_set_l2_encap = {
15690         .f = cmd_set_l2_encap_parsed,
15691         .data = NULL,
15692         .help_str = "set l2_encap ip-version ipv4|ipv6"
15693                 " eth-src <eth-src> eth-dst <eth-dst>",
15694         .tokens = {
15695                 (void *)&cmd_set_l2_encap_set,
15696                 (void *)&cmd_set_l2_encap_l2_encap,
15697                 (void *)&cmd_set_l2_encap_ip_version,
15698                 (void *)&cmd_set_l2_encap_ip_version_value,
15699                 (void *)&cmd_set_l2_encap_eth_src,
15700                 (void *)&cmd_set_l2_encap_eth_src_value,
15701                 (void *)&cmd_set_l2_encap_eth_dst,
15702                 (void *)&cmd_set_l2_encap_eth_dst_value,
15703                 NULL,
15704         },
15705 };
15706
15707 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15708         .f = cmd_set_l2_encap_parsed,
15709         .data = NULL,
15710         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15711                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15712         .tokens = {
15713                 (void *)&cmd_set_l2_encap_set,
15714                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15715                 (void *)&cmd_set_l2_encap_ip_version,
15716                 (void *)&cmd_set_l2_encap_ip_version_value,
15717                 (void *)&cmd_set_l2_encap_vlan,
15718                 (void *)&cmd_set_l2_encap_vlan_value,
15719                 (void *)&cmd_set_l2_encap_eth_src,
15720                 (void *)&cmd_set_l2_encap_eth_src_value,
15721                 (void *)&cmd_set_l2_encap_eth_dst,
15722                 (void *)&cmd_set_l2_encap_eth_dst_value,
15723                 NULL,
15724         },
15725 };
15726
15727 /** Set L2 decapsulation details */
15728 struct cmd_set_l2_decap_result {
15729         cmdline_fixed_string_t set;
15730         cmdline_fixed_string_t l2_decap;
15731         cmdline_fixed_string_t pos_token;
15732         uint32_t vlan_present:1;
15733 };
15734
15735 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15736         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15737 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15738         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15739                                  "l2_decap");
15740 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15741         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15742                                  "l2_decap-with-vlan");
15743
15744 static void cmd_set_l2_decap_parsed(void *parsed_result,
15745         __attribute__((unused)) struct cmdline *cl,
15746         __attribute__((unused)) void *data)
15747 {
15748         struct cmd_set_l2_decap_result *res = parsed_result;
15749
15750         if (strcmp(res->l2_decap, "l2_decap") == 0)
15751                 l2_decap_conf.select_vlan = 0;
15752         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15753                 l2_decap_conf.select_vlan = 1;
15754 }
15755
15756 cmdline_parse_inst_t cmd_set_l2_decap = {
15757         .f = cmd_set_l2_decap_parsed,
15758         .data = NULL,
15759         .help_str = "set l2_decap",
15760         .tokens = {
15761                 (void *)&cmd_set_l2_decap_set,
15762                 (void *)&cmd_set_l2_decap_l2_decap,
15763                 NULL,
15764         },
15765 };
15766
15767 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15768         .f = cmd_set_l2_decap_parsed,
15769         .data = NULL,
15770         .help_str = "set l2_decap-with-vlan",
15771         .tokens = {
15772                 (void *)&cmd_set_l2_decap_set,
15773                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15774                 NULL,
15775         },
15776 };
15777
15778 /** Set MPLSoGRE encapsulation details */
15779 struct cmd_set_mplsogre_encap_result {
15780         cmdline_fixed_string_t set;
15781         cmdline_fixed_string_t mplsogre;
15782         cmdline_fixed_string_t pos_token;
15783         cmdline_fixed_string_t ip_version;
15784         uint32_t vlan_present:1;
15785         uint32_t label;
15786         cmdline_ipaddr_t ip_src;
15787         cmdline_ipaddr_t ip_dst;
15788         uint16_t tci;
15789         struct rte_ether_addr eth_src;
15790         struct rte_ether_addr eth_dst;
15791 };
15792
15793 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15794         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15795                                  "set");
15796 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15797         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15798                                  "mplsogre_encap");
15799 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15800         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15801                                  mplsogre, "mplsogre_encap-with-vlan");
15802 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15803         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15804                                  pos_token, "ip-version");
15805 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15806         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15807                                  ip_version, "ipv4#ipv6");
15808 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15809         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15810                                  pos_token, "label");
15811 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15812         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15813                               UINT32);
15814 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15815         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15816                                  pos_token, "ip-src");
15817 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15818         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15819 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15820         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15821                                  pos_token, "ip-dst");
15822 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15823         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15824 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15825         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15826                                  pos_token, "vlan-tci");
15827 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15828         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15829                               UINT16);
15830 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15831         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15832                                  pos_token, "eth-src");
15833 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15834         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15835                                     eth_src);
15836 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15837         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15838                                  pos_token, "eth-dst");
15839 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15840         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15841                                     eth_dst);
15842
15843 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15844         __attribute__((unused)) struct cmdline *cl,
15845         __attribute__((unused)) void *data)
15846 {
15847         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15848         union {
15849                 uint32_t mplsogre_label;
15850                 uint8_t label[4];
15851         } id = {
15852                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15853         };
15854
15855         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15856                 mplsogre_encap_conf.select_vlan = 0;
15857         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15858                 mplsogre_encap_conf.select_vlan = 1;
15859         if (strcmp(res->ip_version, "ipv4") == 0)
15860                 mplsogre_encap_conf.select_ipv4 = 1;
15861         else if (strcmp(res->ip_version, "ipv6") == 0)
15862                 mplsogre_encap_conf.select_ipv4 = 0;
15863         else
15864                 return;
15865         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15866         if (mplsogre_encap_conf.select_ipv4) {
15867                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15868                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15869         } else {
15870                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15871                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15872         }
15873         if (mplsogre_encap_conf.select_vlan)
15874                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15875         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15876                    RTE_ETHER_ADDR_LEN);
15877         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15878                    RTE_ETHER_ADDR_LEN);
15879 }
15880
15881 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15882         .f = cmd_set_mplsogre_encap_parsed,
15883         .data = NULL,
15884         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15885                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15886                 " eth-dst <eth-dst>",
15887         .tokens = {
15888                 (void *)&cmd_set_mplsogre_encap_set,
15889                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15890                 (void *)&cmd_set_mplsogre_encap_ip_version,
15891                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15892                 (void *)&cmd_set_mplsogre_encap_label,
15893                 (void *)&cmd_set_mplsogre_encap_label_value,
15894                 (void *)&cmd_set_mplsogre_encap_ip_src,
15895                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15896                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15897                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15898                 (void *)&cmd_set_mplsogre_encap_eth_src,
15899                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15900                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15901                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15902                 NULL,
15903         },
15904 };
15905
15906 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15907         .f = cmd_set_mplsogre_encap_parsed,
15908         .data = NULL,
15909         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15910                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15911                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15912         .tokens = {
15913                 (void *)&cmd_set_mplsogre_encap_set,
15914                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15915                 (void *)&cmd_set_mplsogre_encap_ip_version,
15916                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15917                 (void *)&cmd_set_mplsogre_encap_label,
15918                 (void *)&cmd_set_mplsogre_encap_label_value,
15919                 (void *)&cmd_set_mplsogre_encap_ip_src,
15920                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15921                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15922                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15923                 (void *)&cmd_set_mplsogre_encap_vlan,
15924                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15925                 (void *)&cmd_set_mplsogre_encap_eth_src,
15926                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15927                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15928                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15929                 NULL,
15930         },
15931 };
15932
15933 /** Set MPLSoGRE decapsulation details */
15934 struct cmd_set_mplsogre_decap_result {
15935         cmdline_fixed_string_t set;
15936         cmdline_fixed_string_t mplsogre;
15937         cmdline_fixed_string_t pos_token;
15938         cmdline_fixed_string_t ip_version;
15939         uint32_t vlan_present:1;
15940 };
15941
15942 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15943         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15944                                  "set");
15945 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15946         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15947                                  "mplsogre_decap");
15948 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15949         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15950                                  mplsogre, "mplsogre_decap-with-vlan");
15951 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15952         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15953                                  pos_token, "ip-version");
15954 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15955         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15956                                  ip_version, "ipv4#ipv6");
15957
15958 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15959         __attribute__((unused)) struct cmdline *cl,
15960         __attribute__((unused)) void *data)
15961 {
15962         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15963
15964         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15965                 mplsogre_decap_conf.select_vlan = 0;
15966         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15967                 mplsogre_decap_conf.select_vlan = 1;
15968         if (strcmp(res->ip_version, "ipv4") == 0)
15969                 mplsogre_decap_conf.select_ipv4 = 1;
15970         else if (strcmp(res->ip_version, "ipv6") == 0)
15971                 mplsogre_decap_conf.select_ipv4 = 0;
15972 }
15973
15974 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15975         .f = cmd_set_mplsogre_decap_parsed,
15976         .data = NULL,
15977         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15978         .tokens = {
15979                 (void *)&cmd_set_mplsogre_decap_set,
15980                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15981                 (void *)&cmd_set_mplsogre_decap_ip_version,
15982                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15983                 NULL,
15984         },
15985 };
15986
15987 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15988         .f = cmd_set_mplsogre_decap_parsed,
15989         .data = NULL,
15990         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15991         .tokens = {
15992                 (void *)&cmd_set_mplsogre_decap_set,
15993                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15994                 (void *)&cmd_set_mplsogre_decap_ip_version,
15995                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15996                 NULL,
15997         },
15998 };
15999
16000 /** Set MPLSoUDP encapsulation details */
16001 struct cmd_set_mplsoudp_encap_result {
16002         cmdline_fixed_string_t set;
16003         cmdline_fixed_string_t mplsoudp;
16004         cmdline_fixed_string_t pos_token;
16005         cmdline_fixed_string_t ip_version;
16006         uint32_t vlan_present:1;
16007         uint32_t label;
16008         uint16_t udp_src;
16009         uint16_t udp_dst;
16010         cmdline_ipaddr_t ip_src;
16011         cmdline_ipaddr_t ip_dst;
16012         uint16_t tci;
16013         struct rte_ether_addr eth_src;
16014         struct rte_ether_addr eth_dst;
16015 };
16016
16017 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16018         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16019                                  "set");
16020 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16021         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16022                                  "mplsoudp_encap");
16023 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16024         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16025                                  mplsoudp, "mplsoudp_encap-with-vlan");
16026 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16027         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16028                                  pos_token, "ip-version");
16029 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16030         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16031                                  ip_version, "ipv4#ipv6");
16032 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16033         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16034                                  pos_token, "label");
16035 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16036         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16037                               UINT32);
16038 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16039         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16040                                  pos_token, "udp-src");
16041 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16042         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16043                               UINT16);
16044 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16045         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16046                                  pos_token, "udp-dst");
16047 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16048         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16049                               UINT16);
16050 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16051         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16052                                  pos_token, "ip-src");
16053 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16054         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16055 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16056         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16057                                  pos_token, "ip-dst");
16058 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16059         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16060 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16061         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16062                                  pos_token, "vlan-tci");
16063 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16064         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16065                               UINT16);
16066 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16067         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16068                                  pos_token, "eth-src");
16069 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16070         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16071                                     eth_src);
16072 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16073         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16074                                  pos_token, "eth-dst");
16075 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16076         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16077                                     eth_dst);
16078
16079 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16080         __attribute__((unused)) struct cmdline *cl,
16081         __attribute__((unused)) void *data)
16082 {
16083         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16084         union {
16085                 uint32_t mplsoudp_label;
16086                 uint8_t label[4];
16087         } id = {
16088                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16089         };
16090
16091         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16092                 mplsoudp_encap_conf.select_vlan = 0;
16093         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16094                 mplsoudp_encap_conf.select_vlan = 1;
16095         if (strcmp(res->ip_version, "ipv4") == 0)
16096                 mplsoudp_encap_conf.select_ipv4 = 1;
16097         else if (strcmp(res->ip_version, "ipv6") == 0)
16098                 mplsoudp_encap_conf.select_ipv4 = 0;
16099         else
16100                 return;
16101         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16102         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16103         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16104         if (mplsoudp_encap_conf.select_ipv4) {
16105                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16106                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16107         } else {
16108                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16109                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16110         }
16111         if (mplsoudp_encap_conf.select_vlan)
16112                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16113         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16114                    RTE_ETHER_ADDR_LEN);
16115         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16116                    RTE_ETHER_ADDR_LEN);
16117 }
16118
16119 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16120         .f = cmd_set_mplsoudp_encap_parsed,
16121         .data = NULL,
16122         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16123                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16124                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16125         .tokens = {
16126                 (void *)&cmd_set_mplsoudp_encap_set,
16127                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16128                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16129                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16130                 (void *)&cmd_set_mplsoudp_encap_label,
16131                 (void *)&cmd_set_mplsoudp_encap_label_value,
16132                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16133                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16134                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16135                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16136                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16137                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16138                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16139                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16140                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16141                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16142                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16143                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16144                 NULL,
16145         },
16146 };
16147
16148 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16149         .f = cmd_set_mplsoudp_encap_parsed,
16150         .data = NULL,
16151         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16152                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16153                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16154                 " eth-src <eth-src> eth-dst <eth-dst>",
16155         .tokens = {
16156                 (void *)&cmd_set_mplsoudp_encap_set,
16157                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16158                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16159                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16160                 (void *)&cmd_set_mplsoudp_encap_label,
16161                 (void *)&cmd_set_mplsoudp_encap_label_value,
16162                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16163                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16164                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16165                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16166                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16167                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16168                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16169                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16170                 (void *)&cmd_set_mplsoudp_encap_vlan,
16171                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16172                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16173                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16174                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16175                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16176                 NULL,
16177         },
16178 };
16179
16180 /** Set MPLSoUDP decapsulation details */
16181 struct cmd_set_mplsoudp_decap_result {
16182         cmdline_fixed_string_t set;
16183         cmdline_fixed_string_t mplsoudp;
16184         cmdline_fixed_string_t pos_token;
16185         cmdline_fixed_string_t ip_version;
16186         uint32_t vlan_present:1;
16187 };
16188
16189 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16190         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16191                                  "set");
16192 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16193         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16194                                  "mplsoudp_decap");
16195 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16196         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16197                                  mplsoudp, "mplsoudp_decap-with-vlan");
16198 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16199         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16200                                  pos_token, "ip-version");
16201 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16202         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16203                                  ip_version, "ipv4#ipv6");
16204
16205 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16206         __attribute__((unused)) struct cmdline *cl,
16207         __attribute__((unused)) void *data)
16208 {
16209         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16210
16211         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16212                 mplsoudp_decap_conf.select_vlan = 0;
16213         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16214                 mplsoudp_decap_conf.select_vlan = 1;
16215         if (strcmp(res->ip_version, "ipv4") == 0)
16216                 mplsoudp_decap_conf.select_ipv4 = 1;
16217         else if (strcmp(res->ip_version, "ipv6") == 0)
16218                 mplsoudp_decap_conf.select_ipv4 = 0;
16219 }
16220
16221 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16222         .f = cmd_set_mplsoudp_decap_parsed,
16223         .data = NULL,
16224         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16225         .tokens = {
16226                 (void *)&cmd_set_mplsoudp_decap_set,
16227                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16228                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16229                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16230                 NULL,
16231         },
16232 };
16233
16234 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16235         .f = cmd_set_mplsoudp_decap_parsed,
16236         .data = NULL,
16237         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16238         .tokens = {
16239                 (void *)&cmd_set_mplsoudp_decap_set,
16240                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16241                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16242                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16243                 NULL,
16244         },
16245 };
16246
16247 /* Strict link priority scheduling mode setting */
16248 static void
16249 cmd_strict_link_prio_parsed(
16250         void *parsed_result,
16251         __attribute__((unused)) struct cmdline *cl,
16252         __attribute__((unused)) void *data)
16253 {
16254         struct cmd_vf_tc_bw_result *res = parsed_result;
16255         int ret = -ENOTSUP;
16256
16257         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16258                 return;
16259
16260 #ifdef RTE_LIBRTE_I40E_PMD
16261         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16262 #endif
16263
16264         switch (ret) {
16265         case 0:
16266                 break;
16267         case -EINVAL:
16268                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16269                 break;
16270         case -ENODEV:
16271                 printf("invalid port_id %d\n", res->port_id);
16272                 break;
16273         case -ENOTSUP:
16274                 printf("function not implemented\n");
16275                 break;
16276         default:
16277                 printf("programming error: (%s)\n", strerror(-ret));
16278         }
16279 }
16280
16281 cmdline_parse_inst_t cmd_strict_link_prio = {
16282         .f = cmd_strict_link_prio_parsed,
16283         .data = NULL,
16284         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16285         .tokens = {
16286                 (void *)&cmd_vf_tc_bw_set,
16287                 (void *)&cmd_vf_tc_bw_tx,
16288                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16289                 (void *)&cmd_vf_tc_bw_port_id,
16290                 (void *)&cmd_vf_tc_bw_tc_map,
16291                 NULL,
16292         },
16293 };
16294
16295 /* Load dynamic device personalization*/
16296 struct cmd_ddp_add_result {
16297         cmdline_fixed_string_t ddp;
16298         cmdline_fixed_string_t add;
16299         portid_t port_id;
16300         char filepath[];
16301 };
16302
16303 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16304         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16305 cmdline_parse_token_string_t cmd_ddp_add_add =
16306         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16307 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16308         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16309 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16310         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16311
16312 static void
16313 cmd_ddp_add_parsed(
16314         void *parsed_result,
16315         __attribute__((unused)) struct cmdline *cl,
16316         __attribute__((unused)) void *data)
16317 {
16318         struct cmd_ddp_add_result *res = parsed_result;
16319         uint8_t *buff;
16320         uint32_t size;
16321         char *filepath;
16322         char *file_fld[2];
16323         int file_num;
16324         int ret = -ENOTSUP;
16325
16326         if (!all_ports_stopped()) {
16327                 printf("Please stop all ports first\n");
16328                 return;
16329         }
16330
16331         filepath = strdup(res->filepath);
16332         if (filepath == NULL) {
16333                 printf("Failed to allocate memory\n");
16334                 return;
16335         }
16336         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16337
16338         buff = open_file(file_fld[0], &size);
16339         if (!buff) {
16340                 free((void *)filepath);
16341                 return;
16342         }
16343
16344 #ifdef RTE_LIBRTE_I40E_PMD
16345         if (ret == -ENOTSUP)
16346                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16347                                                buff, size,
16348                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16349 #endif
16350
16351         if (ret == -EEXIST)
16352                 printf("Profile has already existed.\n");
16353         else if (ret < 0)
16354                 printf("Failed to load profile.\n");
16355         else if (file_num == 2)
16356                 save_file(file_fld[1], buff, size);
16357
16358         close_file(buff);
16359         free((void *)filepath);
16360 }
16361
16362 cmdline_parse_inst_t cmd_ddp_add = {
16363         .f = cmd_ddp_add_parsed,
16364         .data = NULL,
16365         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16366         .tokens = {
16367                 (void *)&cmd_ddp_add_ddp,
16368                 (void *)&cmd_ddp_add_add,
16369                 (void *)&cmd_ddp_add_port_id,
16370                 (void *)&cmd_ddp_add_filepath,
16371                 NULL,
16372         },
16373 };
16374
16375 /* Delete dynamic device personalization*/
16376 struct cmd_ddp_del_result {
16377         cmdline_fixed_string_t ddp;
16378         cmdline_fixed_string_t del;
16379         portid_t port_id;
16380         char filepath[];
16381 };
16382
16383 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16384         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16385 cmdline_parse_token_string_t cmd_ddp_del_del =
16386         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16387 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16388         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16389 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16390         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16391
16392 static void
16393 cmd_ddp_del_parsed(
16394         void *parsed_result,
16395         __attribute__((unused)) struct cmdline *cl,
16396         __attribute__((unused)) void *data)
16397 {
16398         struct cmd_ddp_del_result *res = parsed_result;
16399         uint8_t *buff;
16400         uint32_t size;
16401         int ret = -ENOTSUP;
16402
16403         if (!all_ports_stopped()) {
16404                 printf("Please stop all ports first\n");
16405                 return;
16406         }
16407
16408         buff = open_file(res->filepath, &size);
16409         if (!buff)
16410                 return;
16411
16412 #ifdef RTE_LIBRTE_I40E_PMD
16413         if (ret == -ENOTSUP)
16414                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16415                                                buff, size,
16416                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16417 #endif
16418
16419         if (ret == -EACCES)
16420                 printf("Profile does not exist.\n");
16421         else if (ret < 0)
16422                 printf("Failed to delete profile.\n");
16423
16424         close_file(buff);
16425 }
16426
16427 cmdline_parse_inst_t cmd_ddp_del = {
16428         .f = cmd_ddp_del_parsed,
16429         .data = NULL,
16430         .help_str = "ddp del <port_id> <backup_profile_path>",
16431         .tokens = {
16432                 (void *)&cmd_ddp_del_ddp,
16433                 (void *)&cmd_ddp_del_del,
16434                 (void *)&cmd_ddp_del_port_id,
16435                 (void *)&cmd_ddp_del_filepath,
16436                 NULL,
16437         },
16438 };
16439
16440 /* Get dynamic device personalization profile info */
16441 struct cmd_ddp_info_result {
16442         cmdline_fixed_string_t ddp;
16443         cmdline_fixed_string_t get;
16444         cmdline_fixed_string_t info;
16445         char filepath[];
16446 };
16447
16448 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16449         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16450 cmdline_parse_token_string_t cmd_ddp_info_get =
16451         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16452 cmdline_parse_token_string_t cmd_ddp_info_info =
16453         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16454 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16455         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16456
16457 static void
16458 cmd_ddp_info_parsed(
16459         void *parsed_result,
16460         __attribute__((unused)) struct cmdline *cl,
16461         __attribute__((unused)) void *data)
16462 {
16463         struct cmd_ddp_info_result *res = parsed_result;
16464         uint8_t *pkg;
16465         uint32_t pkg_size;
16466         int ret = -ENOTSUP;
16467 #ifdef RTE_LIBRTE_I40E_PMD
16468         uint32_t i, j, n;
16469         uint8_t *buff;
16470         uint32_t buff_size = 0;
16471         struct rte_pmd_i40e_profile_info info;
16472         uint32_t dev_num = 0;
16473         struct rte_pmd_i40e_ddp_device_id *devs;
16474         uint32_t proto_num = 0;
16475         struct rte_pmd_i40e_proto_info *proto = NULL;
16476         uint32_t pctype_num = 0;
16477         struct rte_pmd_i40e_ptype_info *pctype;
16478         uint32_t ptype_num = 0;
16479         struct rte_pmd_i40e_ptype_info *ptype;
16480         uint8_t proto_id;
16481
16482 #endif
16483
16484         pkg = open_file(res->filepath, &pkg_size);
16485         if (!pkg)
16486                 return;
16487
16488 #ifdef RTE_LIBRTE_I40E_PMD
16489         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16490                                 (uint8_t *)&info, sizeof(info),
16491                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16492         if (!ret) {
16493                 printf("Global Track id:       0x%x\n", info.track_id);
16494                 printf("Global Version:        %d.%d.%d.%d\n",
16495                         info.version.major,
16496                         info.version.minor,
16497                         info.version.update,
16498                         info.version.draft);
16499                 printf("Global Package name:   %s\n\n", info.name);
16500         }
16501
16502         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16503                                 (uint8_t *)&info, sizeof(info),
16504                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16505         if (!ret) {
16506                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16507                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16508                         info.version.major,
16509                         info.version.minor,
16510                         info.version.update,
16511                         info.version.draft);
16512                 printf("i40e Profile name:     %s\n\n", info.name);
16513         }
16514
16515         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16516                                 (uint8_t *)&buff_size, sizeof(buff_size),
16517                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16518         if (!ret && buff_size) {
16519                 buff = (uint8_t *)malloc(buff_size);
16520                 if (buff) {
16521                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16522                                                 buff, buff_size,
16523                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16524                         if (!ret)
16525                                 printf("Package Notes:\n%s\n\n", buff);
16526                         free(buff);
16527                 }
16528         }
16529
16530         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16531                                 (uint8_t *)&dev_num, sizeof(dev_num),
16532                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16533         if (!ret && dev_num) {
16534                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16535                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16536                 if (devs) {
16537                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16538                                                 (uint8_t *)devs, buff_size,
16539                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16540                         if (!ret) {
16541                                 printf("List of supported devices:\n");
16542                                 for (i = 0; i < dev_num; i++) {
16543                                         printf("  %04X:%04X %04X:%04X\n",
16544                                                 devs[i].vendor_dev_id >> 16,
16545                                                 devs[i].vendor_dev_id & 0xFFFF,
16546                                                 devs[i].sub_vendor_dev_id >> 16,
16547                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16548                                 }
16549                                 printf("\n");
16550                         }
16551                         free(devs);
16552                 }
16553         }
16554
16555         /* get information about protocols and packet types */
16556         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16557                 (uint8_t *)&proto_num, sizeof(proto_num),
16558                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16559         if (ret || !proto_num)
16560                 goto no_print_return;
16561
16562         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16563         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16564         if (!proto)
16565                 goto no_print_return;
16566
16567         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16568                                         buff_size,
16569                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16570         if (!ret) {
16571                 printf("List of used protocols:\n");
16572                 for (i = 0; i < proto_num; i++)
16573                         printf("  %2u: %s\n", proto[i].proto_id,
16574                                proto[i].name);
16575                 printf("\n");
16576         }
16577         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16578                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16579                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16580         if (ret || !pctype_num)
16581                 goto no_print_pctypes;
16582
16583         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16584         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16585         if (!pctype)
16586                 goto no_print_pctypes;
16587
16588         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16589                                         buff_size,
16590                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16591         if (ret) {
16592                 free(pctype);
16593                 goto no_print_pctypes;
16594         }
16595
16596         printf("List of defined packet classification types:\n");
16597         for (i = 0; i < pctype_num; i++) {
16598                 printf("  %2u:", pctype[i].ptype_id);
16599                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16600                         proto_id = pctype[i].protocols[j];
16601                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16602                                 for (n = 0; n < proto_num; n++) {
16603                                         if (proto[n].proto_id == proto_id) {
16604                                                 printf(" %s", proto[n].name);
16605                                                 break;
16606                                         }
16607                                 }
16608                         }
16609                 }
16610                 printf("\n");
16611         }
16612         printf("\n");
16613         free(pctype);
16614
16615 no_print_pctypes:
16616
16617         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16618                                         sizeof(ptype_num),
16619                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16620         if (ret || !ptype_num)
16621                 goto no_print_return;
16622
16623         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16624         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16625         if (!ptype)
16626                 goto no_print_return;
16627
16628         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16629                                         buff_size,
16630                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16631         if (ret) {
16632                 free(ptype);
16633                 goto no_print_return;
16634         }
16635         printf("List of defined packet types:\n");
16636         for (i = 0; i < ptype_num; i++) {
16637                 printf("  %2u:", ptype[i].ptype_id);
16638                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16639                         proto_id = ptype[i].protocols[j];
16640                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16641                                 for (n = 0; n < proto_num; n++) {
16642                                         if (proto[n].proto_id == proto_id) {
16643                                                 printf(" %s", proto[n].name);
16644                                                 break;
16645                                         }
16646                                 }
16647                         }
16648                 }
16649                 printf("\n");
16650         }
16651         free(ptype);
16652         printf("\n");
16653
16654         ret = 0;
16655 no_print_return:
16656         if (proto)
16657                 free(proto);
16658 #endif
16659         if (ret == -ENOTSUP)
16660                 printf("Function not supported in PMD driver\n");
16661         close_file(pkg);
16662 }
16663
16664 cmdline_parse_inst_t cmd_ddp_get_info = {
16665         .f = cmd_ddp_info_parsed,
16666         .data = NULL,
16667         .help_str = "ddp get info <profile_path>",
16668         .tokens = {
16669                 (void *)&cmd_ddp_info_ddp,
16670                 (void *)&cmd_ddp_info_get,
16671                 (void *)&cmd_ddp_info_info,
16672                 (void *)&cmd_ddp_info_filepath,
16673                 NULL,
16674         },
16675 };
16676
16677 /* Get dynamic device personalization profile info list*/
16678 #define PROFILE_INFO_SIZE 48
16679 #define MAX_PROFILE_NUM 16
16680
16681 struct cmd_ddp_get_list_result {
16682         cmdline_fixed_string_t ddp;
16683         cmdline_fixed_string_t get;
16684         cmdline_fixed_string_t list;
16685         portid_t port_id;
16686 };
16687
16688 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16689         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16690 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16691         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16692 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16693         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16694 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16695         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16696
16697 static void
16698 cmd_ddp_get_list_parsed(
16699         __attribute__((unused)) void *parsed_result,
16700         __attribute__((unused)) struct cmdline *cl,
16701         __attribute__((unused)) void *data)
16702 {
16703 #ifdef RTE_LIBRTE_I40E_PMD
16704         struct cmd_ddp_get_list_result *res = parsed_result;
16705         struct rte_pmd_i40e_profile_list *p_list;
16706         struct rte_pmd_i40e_profile_info *p_info;
16707         uint32_t p_num;
16708         uint32_t size;
16709         uint32_t i;
16710 #endif
16711         int ret = -ENOTSUP;
16712
16713 #ifdef RTE_LIBRTE_I40E_PMD
16714         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16715         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16716         if (!p_list)
16717                 printf("%s: Failed to malloc buffer\n", __func__);
16718
16719         if (ret == -ENOTSUP)
16720                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16721                                                 (uint8_t *)p_list, size);
16722
16723         if (!ret) {
16724                 p_num = p_list->p_count;
16725                 printf("Profile number is: %d\n\n", p_num);
16726
16727                 for (i = 0; i < p_num; i++) {
16728                         p_info = &p_list->p_info[i];
16729                         printf("Profile %d:\n", i);
16730                         printf("Track id:     0x%x\n", p_info->track_id);
16731                         printf("Version:      %d.%d.%d.%d\n",
16732                                p_info->version.major,
16733                                p_info->version.minor,
16734                                p_info->version.update,
16735                                p_info->version.draft);
16736                         printf("Profile name: %s\n\n", p_info->name);
16737                 }
16738         }
16739
16740         free(p_list);
16741 #endif
16742
16743         if (ret < 0)
16744                 printf("Failed to get ddp list\n");
16745 }
16746
16747 cmdline_parse_inst_t cmd_ddp_get_list = {
16748         .f = cmd_ddp_get_list_parsed,
16749         .data = NULL,
16750         .help_str = "ddp get list <port_id>",
16751         .tokens = {
16752                 (void *)&cmd_ddp_get_list_ddp,
16753                 (void *)&cmd_ddp_get_list_get,
16754                 (void *)&cmd_ddp_get_list_list,
16755                 (void *)&cmd_ddp_get_list_port_id,
16756                 NULL,
16757         },
16758 };
16759
16760 /* Configure input set */
16761 struct cmd_cfg_input_set_result {
16762         cmdline_fixed_string_t port;
16763         cmdline_fixed_string_t cfg;
16764         portid_t port_id;
16765         cmdline_fixed_string_t pctype;
16766         uint8_t pctype_id;
16767         cmdline_fixed_string_t inset_type;
16768         cmdline_fixed_string_t opt;
16769         cmdline_fixed_string_t field;
16770         uint8_t field_idx;
16771 };
16772
16773 static void
16774 cmd_cfg_input_set_parsed(
16775         __attribute__((unused)) void *parsed_result,
16776         __attribute__((unused)) struct cmdline *cl,
16777         __attribute__((unused)) void *data)
16778 {
16779 #ifdef RTE_LIBRTE_I40E_PMD
16780         struct cmd_cfg_input_set_result *res = parsed_result;
16781         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16782         struct rte_pmd_i40e_inset inset;
16783 #endif
16784         int ret = -ENOTSUP;
16785
16786         if (!all_ports_stopped()) {
16787                 printf("Please stop all ports first\n");
16788                 return;
16789         }
16790
16791 #ifdef RTE_LIBRTE_I40E_PMD
16792         if (!strcmp(res->inset_type, "hash_inset"))
16793                 inset_type = INSET_HASH;
16794         else if (!strcmp(res->inset_type, "fdir_inset"))
16795                 inset_type = INSET_FDIR;
16796         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16797                 inset_type = INSET_FDIR_FLX;
16798         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16799                                      &inset, inset_type);
16800         if (ret) {
16801                 printf("Failed to get input set.\n");
16802                 return;
16803         }
16804
16805         if (!strcmp(res->opt, "get")) {
16806                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16807                                                    res->field_idx);
16808                 if (ret)
16809                         printf("Field index %d is enabled.\n", res->field_idx);
16810                 else
16811                         printf("Field index %d is disabled.\n", res->field_idx);
16812                 return;
16813         } else if (!strcmp(res->opt, "set"))
16814                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16815                                                    res->field_idx);
16816         else if (!strcmp(res->opt, "clear"))
16817                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16818                                                      res->field_idx);
16819         if (ret) {
16820                 printf("Failed to configure input set field.\n");
16821                 return;
16822         }
16823
16824         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16825                                      &inset, inset_type);
16826         if (ret) {
16827                 printf("Failed to set input set.\n");
16828                 return;
16829         }
16830 #endif
16831
16832         if (ret == -ENOTSUP)
16833                 printf("Function not supported\n");
16834 }
16835
16836 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16837         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16838                                  port, "port");
16839 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16840         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16841                                  cfg, "config");
16842 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16843         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16844                               port_id, UINT16);
16845 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16846         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16847                                  pctype, "pctype");
16848 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16849         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16850                               pctype_id, UINT8);
16851 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16852         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16853                                  inset_type,
16854                                  "hash_inset#fdir_inset#fdir_flx_inset");
16855 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16856         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16857                                  opt, "get#set#clear");
16858 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16859         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16860                                  field, "field");
16861 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16862         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16863                               field_idx, UINT8);
16864
16865 cmdline_parse_inst_t cmd_cfg_input_set = {
16866         .f = cmd_cfg_input_set_parsed,
16867         .data = NULL,
16868         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16869                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16870         .tokens = {
16871                 (void *)&cmd_cfg_input_set_port,
16872                 (void *)&cmd_cfg_input_set_cfg,
16873                 (void *)&cmd_cfg_input_set_port_id,
16874                 (void *)&cmd_cfg_input_set_pctype,
16875                 (void *)&cmd_cfg_input_set_pctype_id,
16876                 (void *)&cmd_cfg_input_set_inset_type,
16877                 (void *)&cmd_cfg_input_set_opt,
16878                 (void *)&cmd_cfg_input_set_field,
16879                 (void *)&cmd_cfg_input_set_field_idx,
16880                 NULL,
16881         },
16882 };
16883
16884 /* Clear input set */
16885 struct cmd_clear_input_set_result {
16886         cmdline_fixed_string_t port;
16887         cmdline_fixed_string_t cfg;
16888         portid_t port_id;
16889         cmdline_fixed_string_t pctype;
16890         uint8_t pctype_id;
16891         cmdline_fixed_string_t inset_type;
16892         cmdline_fixed_string_t clear;
16893         cmdline_fixed_string_t all;
16894 };
16895
16896 static void
16897 cmd_clear_input_set_parsed(
16898         __attribute__((unused)) void *parsed_result,
16899         __attribute__((unused)) struct cmdline *cl,
16900         __attribute__((unused)) void *data)
16901 {
16902 #ifdef RTE_LIBRTE_I40E_PMD
16903         struct cmd_clear_input_set_result *res = parsed_result;
16904         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16905         struct rte_pmd_i40e_inset inset;
16906 #endif
16907         int ret = -ENOTSUP;
16908
16909         if (!all_ports_stopped()) {
16910                 printf("Please stop all ports first\n");
16911                 return;
16912         }
16913
16914 #ifdef RTE_LIBRTE_I40E_PMD
16915         if (!strcmp(res->inset_type, "hash_inset"))
16916                 inset_type = INSET_HASH;
16917         else if (!strcmp(res->inset_type, "fdir_inset"))
16918                 inset_type = INSET_FDIR;
16919         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16920                 inset_type = INSET_FDIR_FLX;
16921
16922         memset(&inset, 0, sizeof(inset));
16923
16924         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16925                                      &inset, inset_type);
16926         if (ret) {
16927                 printf("Failed to clear input set.\n");
16928                 return;
16929         }
16930
16931 #endif
16932
16933         if (ret == -ENOTSUP)
16934                 printf("Function not supported\n");
16935 }
16936
16937 cmdline_parse_token_string_t cmd_clear_input_set_port =
16938         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16939                                  port, "port");
16940 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16941         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16942                                  cfg, "config");
16943 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16944         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16945                               port_id, UINT16);
16946 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16947         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16948                                  pctype, "pctype");
16949 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16950         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16951                               pctype_id, UINT8);
16952 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16953         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16954                                  inset_type,
16955                                  "hash_inset#fdir_inset#fdir_flx_inset");
16956 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16957         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16958                                  clear, "clear");
16959 cmdline_parse_token_string_t cmd_clear_input_set_all =
16960         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16961                                  all, "all");
16962
16963 cmdline_parse_inst_t cmd_clear_input_set = {
16964         .f = cmd_clear_input_set_parsed,
16965         .data = NULL,
16966         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16967                     "fdir_inset|fdir_flx_inset clear all",
16968         .tokens = {
16969                 (void *)&cmd_clear_input_set_port,
16970                 (void *)&cmd_clear_input_set_cfg,
16971                 (void *)&cmd_clear_input_set_port_id,
16972                 (void *)&cmd_clear_input_set_pctype,
16973                 (void *)&cmd_clear_input_set_pctype_id,
16974                 (void *)&cmd_clear_input_set_inset_type,
16975                 (void *)&cmd_clear_input_set_clear,
16976                 (void *)&cmd_clear_input_set_all,
16977                 NULL,
16978         },
16979 };
16980
16981 /* show vf stats */
16982
16983 /* Common result structure for show vf stats */
16984 struct cmd_show_vf_stats_result {
16985         cmdline_fixed_string_t show;
16986         cmdline_fixed_string_t vf;
16987         cmdline_fixed_string_t stats;
16988         portid_t port_id;
16989         uint16_t vf_id;
16990 };
16991
16992 /* Common CLI fields show vf stats*/
16993 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16994         TOKEN_STRING_INITIALIZER
16995                 (struct cmd_show_vf_stats_result,
16996                  show, "show");
16997 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16998         TOKEN_STRING_INITIALIZER
16999                 (struct cmd_show_vf_stats_result,
17000                  vf, "vf");
17001 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17002         TOKEN_STRING_INITIALIZER
17003                 (struct cmd_show_vf_stats_result,
17004                  stats, "stats");
17005 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17006         TOKEN_NUM_INITIALIZER
17007                 (struct cmd_show_vf_stats_result,
17008                  port_id, UINT16);
17009 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17010         TOKEN_NUM_INITIALIZER
17011                 (struct cmd_show_vf_stats_result,
17012                  vf_id, UINT16);
17013
17014 static void
17015 cmd_show_vf_stats_parsed(
17016         void *parsed_result,
17017         __attribute__((unused)) struct cmdline *cl,
17018         __attribute__((unused)) void *data)
17019 {
17020         struct cmd_show_vf_stats_result *res = parsed_result;
17021         struct rte_eth_stats stats;
17022         int ret = -ENOTSUP;
17023         static const char *nic_stats_border = "########################";
17024
17025         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17026                 return;
17027
17028         memset(&stats, 0, sizeof(stats));
17029
17030 #ifdef RTE_LIBRTE_I40E_PMD
17031         if (ret == -ENOTSUP)
17032                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17033                                                 res->vf_id,
17034                                                 &stats);
17035 #endif
17036 #ifdef RTE_LIBRTE_BNXT_PMD
17037         if (ret == -ENOTSUP)
17038                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17039                                                 res->vf_id,
17040                                                 &stats);
17041 #endif
17042
17043         switch (ret) {
17044         case 0:
17045                 break;
17046         case -EINVAL:
17047                 printf("invalid vf_id %d\n", res->vf_id);
17048                 break;
17049         case -ENODEV:
17050                 printf("invalid port_id %d\n", res->port_id);
17051                 break;
17052         case -ENOTSUP:
17053                 printf("function not implemented\n");
17054                 break;
17055         default:
17056                 printf("programming error: (%s)\n", strerror(-ret));
17057         }
17058
17059         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17060                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17061
17062         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17063                "%-"PRIu64"\n",
17064                stats.ipackets, stats.imissed, stats.ibytes);
17065         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17066         printf("  RX-nombuf:  %-10"PRIu64"\n",
17067                stats.rx_nombuf);
17068         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17069                "%-"PRIu64"\n",
17070                stats.opackets, stats.oerrors, stats.obytes);
17071
17072         printf("  %s############################%s\n",
17073                                nic_stats_border, nic_stats_border);
17074 }
17075
17076 cmdline_parse_inst_t cmd_show_vf_stats = {
17077         .f = cmd_show_vf_stats_parsed,
17078         .data = NULL,
17079         .help_str = "show vf stats <port_id> <vf_id>",
17080         .tokens = {
17081                 (void *)&cmd_show_vf_stats_show,
17082                 (void *)&cmd_show_vf_stats_vf,
17083                 (void *)&cmd_show_vf_stats_stats,
17084                 (void *)&cmd_show_vf_stats_port_id,
17085                 (void *)&cmd_show_vf_stats_vf_id,
17086                 NULL,
17087         },
17088 };
17089
17090 /* clear vf stats */
17091
17092 /* Common result structure for clear vf stats */
17093 struct cmd_clear_vf_stats_result {
17094         cmdline_fixed_string_t clear;
17095         cmdline_fixed_string_t vf;
17096         cmdline_fixed_string_t stats;
17097         portid_t port_id;
17098         uint16_t vf_id;
17099 };
17100
17101 /* Common CLI fields clear vf stats*/
17102 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17103         TOKEN_STRING_INITIALIZER
17104                 (struct cmd_clear_vf_stats_result,
17105                  clear, "clear");
17106 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17107         TOKEN_STRING_INITIALIZER
17108                 (struct cmd_clear_vf_stats_result,
17109                  vf, "vf");
17110 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17111         TOKEN_STRING_INITIALIZER
17112                 (struct cmd_clear_vf_stats_result,
17113                  stats, "stats");
17114 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17115         TOKEN_NUM_INITIALIZER
17116                 (struct cmd_clear_vf_stats_result,
17117                  port_id, UINT16);
17118 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17119         TOKEN_NUM_INITIALIZER
17120                 (struct cmd_clear_vf_stats_result,
17121                  vf_id, UINT16);
17122
17123 static void
17124 cmd_clear_vf_stats_parsed(
17125         void *parsed_result,
17126         __attribute__((unused)) struct cmdline *cl,
17127         __attribute__((unused)) void *data)
17128 {
17129         struct cmd_clear_vf_stats_result *res = parsed_result;
17130         int ret = -ENOTSUP;
17131
17132         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17133                 return;
17134
17135 #ifdef RTE_LIBRTE_I40E_PMD
17136         if (ret == -ENOTSUP)
17137                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17138                                                   res->vf_id);
17139 #endif
17140 #ifdef RTE_LIBRTE_BNXT_PMD
17141         if (ret == -ENOTSUP)
17142                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17143                                                   res->vf_id);
17144 #endif
17145
17146         switch (ret) {
17147         case 0:
17148                 break;
17149         case -EINVAL:
17150                 printf("invalid vf_id %d\n", res->vf_id);
17151                 break;
17152         case -ENODEV:
17153                 printf("invalid port_id %d\n", res->port_id);
17154                 break;
17155         case -ENOTSUP:
17156                 printf("function not implemented\n");
17157                 break;
17158         default:
17159                 printf("programming error: (%s)\n", strerror(-ret));
17160         }
17161 }
17162
17163 cmdline_parse_inst_t cmd_clear_vf_stats = {
17164         .f = cmd_clear_vf_stats_parsed,
17165         .data = NULL,
17166         .help_str = "clear vf stats <port_id> <vf_id>",
17167         .tokens = {
17168                 (void *)&cmd_clear_vf_stats_clear,
17169                 (void *)&cmd_clear_vf_stats_vf,
17170                 (void *)&cmd_clear_vf_stats_stats,
17171                 (void *)&cmd_clear_vf_stats_port_id,
17172                 (void *)&cmd_clear_vf_stats_vf_id,
17173                 NULL,
17174         },
17175 };
17176
17177 /* port config pctype mapping reset */
17178
17179 /* Common result structure for port config pctype mapping reset */
17180 struct cmd_pctype_mapping_reset_result {
17181         cmdline_fixed_string_t port;
17182         cmdline_fixed_string_t config;
17183         portid_t port_id;
17184         cmdline_fixed_string_t pctype;
17185         cmdline_fixed_string_t mapping;
17186         cmdline_fixed_string_t reset;
17187 };
17188
17189 /* Common CLI fields for port config pctype mapping reset*/
17190 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17191         TOKEN_STRING_INITIALIZER
17192                 (struct cmd_pctype_mapping_reset_result,
17193                  port, "port");
17194 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17195         TOKEN_STRING_INITIALIZER
17196                 (struct cmd_pctype_mapping_reset_result,
17197                  config, "config");
17198 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17199         TOKEN_NUM_INITIALIZER
17200                 (struct cmd_pctype_mapping_reset_result,
17201                  port_id, UINT16);
17202 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17203         TOKEN_STRING_INITIALIZER
17204                 (struct cmd_pctype_mapping_reset_result,
17205                  pctype, "pctype");
17206 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17207         TOKEN_STRING_INITIALIZER
17208                 (struct cmd_pctype_mapping_reset_result,
17209                  mapping, "mapping");
17210 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17211         TOKEN_STRING_INITIALIZER
17212                 (struct cmd_pctype_mapping_reset_result,
17213                  reset, "reset");
17214
17215 static void
17216 cmd_pctype_mapping_reset_parsed(
17217         void *parsed_result,
17218         __attribute__((unused)) struct cmdline *cl,
17219         __attribute__((unused)) void *data)
17220 {
17221         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17222         int ret = -ENOTSUP;
17223
17224         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17225                 return;
17226
17227 #ifdef RTE_LIBRTE_I40E_PMD
17228         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17229 #endif
17230
17231         switch (ret) {
17232         case 0:
17233                 break;
17234         case -ENODEV:
17235                 printf("invalid port_id %d\n", res->port_id);
17236                 break;
17237         case -ENOTSUP:
17238                 printf("function not implemented\n");
17239                 break;
17240         default:
17241                 printf("programming error: (%s)\n", strerror(-ret));
17242         }
17243 }
17244
17245 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17246         .f = cmd_pctype_mapping_reset_parsed,
17247         .data = NULL,
17248         .help_str = "port config <port_id> pctype mapping reset",
17249         .tokens = {
17250                 (void *)&cmd_pctype_mapping_reset_port,
17251                 (void *)&cmd_pctype_mapping_reset_config,
17252                 (void *)&cmd_pctype_mapping_reset_port_id,
17253                 (void *)&cmd_pctype_mapping_reset_pctype,
17254                 (void *)&cmd_pctype_mapping_reset_mapping,
17255                 (void *)&cmd_pctype_mapping_reset_reset,
17256                 NULL,
17257         },
17258 };
17259
17260 /* show port pctype mapping */
17261
17262 /* Common result structure for show port pctype mapping */
17263 struct cmd_pctype_mapping_get_result {
17264         cmdline_fixed_string_t show;
17265         cmdline_fixed_string_t port;
17266         portid_t port_id;
17267         cmdline_fixed_string_t pctype;
17268         cmdline_fixed_string_t mapping;
17269 };
17270
17271 /* Common CLI fields for pctype mapping get */
17272 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17273         TOKEN_STRING_INITIALIZER
17274                 (struct cmd_pctype_mapping_get_result,
17275                  show, "show");
17276 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17277         TOKEN_STRING_INITIALIZER
17278                 (struct cmd_pctype_mapping_get_result,
17279                  port, "port");
17280 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17281         TOKEN_NUM_INITIALIZER
17282                 (struct cmd_pctype_mapping_get_result,
17283                  port_id, UINT16);
17284 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17285         TOKEN_STRING_INITIALIZER
17286                 (struct cmd_pctype_mapping_get_result,
17287                  pctype, "pctype");
17288 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17289         TOKEN_STRING_INITIALIZER
17290                 (struct cmd_pctype_mapping_get_result,
17291                  mapping, "mapping");
17292
17293 static void
17294 cmd_pctype_mapping_get_parsed(
17295         void *parsed_result,
17296         __attribute__((unused)) struct cmdline *cl,
17297         __attribute__((unused)) void *data)
17298 {
17299         struct cmd_pctype_mapping_get_result *res = parsed_result;
17300         int ret = -ENOTSUP;
17301 #ifdef RTE_LIBRTE_I40E_PMD
17302         struct rte_pmd_i40e_flow_type_mapping
17303                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17304         int i, j, first_pctype;
17305 #endif
17306
17307         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17308                 return;
17309
17310 #ifdef RTE_LIBRTE_I40E_PMD
17311         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17312 #endif
17313
17314         switch (ret) {
17315         case 0:
17316                 break;
17317         case -ENODEV:
17318                 printf("invalid port_id %d\n", res->port_id);
17319                 return;
17320         case -ENOTSUP:
17321                 printf("function not implemented\n");
17322                 return;
17323         default:
17324                 printf("programming error: (%s)\n", strerror(-ret));
17325                 return;
17326         }
17327
17328 #ifdef RTE_LIBRTE_I40E_PMD
17329         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17330                 if (mapping[i].pctype != 0ULL) {
17331                         first_pctype = 1;
17332
17333                         printf("pctype: ");
17334                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17335                                 if (mapping[i].pctype & (1ULL << j)) {
17336                                         printf(first_pctype ?
17337                                                "%02d" : ",%02d", j);
17338                                         first_pctype = 0;
17339                                 }
17340                         }
17341                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17342                 }
17343         }
17344 #endif
17345 }
17346
17347 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17348         .f = cmd_pctype_mapping_get_parsed,
17349         .data = NULL,
17350         .help_str = "show port <port_id> pctype mapping",
17351         .tokens = {
17352                 (void *)&cmd_pctype_mapping_get_show,
17353                 (void *)&cmd_pctype_mapping_get_port,
17354                 (void *)&cmd_pctype_mapping_get_port_id,
17355                 (void *)&cmd_pctype_mapping_get_pctype,
17356                 (void *)&cmd_pctype_mapping_get_mapping,
17357                 NULL,
17358         },
17359 };
17360
17361 /* port config pctype mapping update */
17362
17363 /* Common result structure for port config pctype mapping update */
17364 struct cmd_pctype_mapping_update_result {
17365         cmdline_fixed_string_t port;
17366         cmdline_fixed_string_t config;
17367         portid_t port_id;
17368         cmdline_fixed_string_t pctype;
17369         cmdline_fixed_string_t mapping;
17370         cmdline_fixed_string_t update;
17371         cmdline_fixed_string_t pctype_list;
17372         uint16_t flow_type;
17373 };
17374
17375 /* Common CLI fields for pctype mapping update*/
17376 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17377         TOKEN_STRING_INITIALIZER
17378                 (struct cmd_pctype_mapping_update_result,
17379                  port, "port");
17380 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17381         TOKEN_STRING_INITIALIZER
17382                 (struct cmd_pctype_mapping_update_result,
17383                  config, "config");
17384 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17385         TOKEN_NUM_INITIALIZER
17386                 (struct cmd_pctype_mapping_update_result,
17387                  port_id, UINT16);
17388 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17389         TOKEN_STRING_INITIALIZER
17390                 (struct cmd_pctype_mapping_update_result,
17391                  pctype, "pctype");
17392 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17393         TOKEN_STRING_INITIALIZER
17394                 (struct cmd_pctype_mapping_update_result,
17395                  mapping, "mapping");
17396 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17397         TOKEN_STRING_INITIALIZER
17398                 (struct cmd_pctype_mapping_update_result,
17399                  update, "update");
17400 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17401         TOKEN_STRING_INITIALIZER
17402                 (struct cmd_pctype_mapping_update_result,
17403                  pctype_list, NULL);
17404 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17405         TOKEN_NUM_INITIALIZER
17406                 (struct cmd_pctype_mapping_update_result,
17407                  flow_type, UINT16);
17408
17409 static void
17410 cmd_pctype_mapping_update_parsed(
17411         void *parsed_result,
17412         __attribute__((unused)) struct cmdline *cl,
17413         __attribute__((unused)) void *data)
17414 {
17415         struct cmd_pctype_mapping_update_result *res = parsed_result;
17416         int ret = -ENOTSUP;
17417 #ifdef RTE_LIBRTE_I40E_PMD
17418         struct rte_pmd_i40e_flow_type_mapping mapping;
17419         unsigned int i;
17420         unsigned int nb_item;
17421         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17422 #endif
17423
17424         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17425                 return;
17426
17427 #ifdef RTE_LIBRTE_I40E_PMD
17428         nb_item = parse_item_list(res->pctype_list, "pctypes",
17429                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17430         mapping.flow_type = res->flow_type;
17431         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17432                 mapping.pctype |= (1ULL << pctype_list[i]);
17433         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17434                                                 &mapping,
17435                                                 1,
17436                                                 0);
17437 #endif
17438
17439         switch (ret) {
17440         case 0:
17441                 break;
17442         case -EINVAL:
17443                 printf("invalid pctype or flow type\n");
17444                 break;
17445         case -ENODEV:
17446                 printf("invalid port_id %d\n", res->port_id);
17447                 break;
17448         case -ENOTSUP:
17449                 printf("function not implemented\n");
17450                 break;
17451         default:
17452                 printf("programming error: (%s)\n", strerror(-ret));
17453         }
17454 }
17455
17456 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17457         .f = cmd_pctype_mapping_update_parsed,
17458         .data = NULL,
17459         .help_str = "port config <port_id> pctype mapping update"
17460         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17461         .tokens = {
17462                 (void *)&cmd_pctype_mapping_update_port,
17463                 (void *)&cmd_pctype_mapping_update_config,
17464                 (void *)&cmd_pctype_mapping_update_port_id,
17465                 (void *)&cmd_pctype_mapping_update_pctype,
17466                 (void *)&cmd_pctype_mapping_update_mapping,
17467                 (void *)&cmd_pctype_mapping_update_update,
17468                 (void *)&cmd_pctype_mapping_update_pc_type,
17469                 (void *)&cmd_pctype_mapping_update_flow_type,
17470                 NULL,
17471         },
17472 };
17473
17474 /* ptype mapping get */
17475
17476 /* Common result structure for ptype mapping get */
17477 struct cmd_ptype_mapping_get_result {
17478         cmdline_fixed_string_t ptype;
17479         cmdline_fixed_string_t mapping;
17480         cmdline_fixed_string_t get;
17481         portid_t port_id;
17482         uint8_t valid_only;
17483 };
17484
17485 /* Common CLI fields for ptype mapping get */
17486 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17487         TOKEN_STRING_INITIALIZER
17488                 (struct cmd_ptype_mapping_get_result,
17489                  ptype, "ptype");
17490 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17491         TOKEN_STRING_INITIALIZER
17492                 (struct cmd_ptype_mapping_get_result,
17493                  mapping, "mapping");
17494 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17495         TOKEN_STRING_INITIALIZER
17496                 (struct cmd_ptype_mapping_get_result,
17497                  get, "get");
17498 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17499         TOKEN_NUM_INITIALIZER
17500                 (struct cmd_ptype_mapping_get_result,
17501                  port_id, UINT16);
17502 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17503         TOKEN_NUM_INITIALIZER
17504                 (struct cmd_ptype_mapping_get_result,
17505                  valid_only, UINT8);
17506
17507 static void
17508 cmd_ptype_mapping_get_parsed(
17509         void *parsed_result,
17510         __attribute__((unused)) struct cmdline *cl,
17511         __attribute__((unused)) void *data)
17512 {
17513         struct cmd_ptype_mapping_get_result *res = parsed_result;
17514         int ret = -ENOTSUP;
17515 #ifdef RTE_LIBRTE_I40E_PMD
17516         int max_ptype_num = 256;
17517         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17518         uint16_t count;
17519         int i;
17520 #endif
17521
17522         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17523                 return;
17524
17525 #ifdef RTE_LIBRTE_I40E_PMD
17526         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17527                                         mapping,
17528                                         max_ptype_num,
17529                                         &count,
17530                                         res->valid_only);
17531 #endif
17532
17533         switch (ret) {
17534         case 0:
17535                 break;
17536         case -ENODEV:
17537                 printf("invalid port_id %d\n", res->port_id);
17538                 break;
17539         case -ENOTSUP:
17540                 printf("function not implemented\n");
17541                 break;
17542         default:
17543                 printf("programming error: (%s)\n", strerror(-ret));
17544         }
17545
17546 #ifdef RTE_LIBRTE_I40E_PMD
17547         if (!ret) {
17548                 for (i = 0; i < count; i++)
17549                         printf("%3d\t0x%08x\n",
17550                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17551         }
17552 #endif
17553 }
17554
17555 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17556         .f = cmd_ptype_mapping_get_parsed,
17557         .data = NULL,
17558         .help_str = "ptype mapping get <port_id> <valid_only>",
17559         .tokens = {
17560                 (void *)&cmd_ptype_mapping_get_ptype,
17561                 (void *)&cmd_ptype_mapping_get_mapping,
17562                 (void *)&cmd_ptype_mapping_get_get,
17563                 (void *)&cmd_ptype_mapping_get_port_id,
17564                 (void *)&cmd_ptype_mapping_get_valid_only,
17565                 NULL,
17566         },
17567 };
17568
17569 /* ptype mapping replace */
17570
17571 /* Common result structure for ptype mapping replace */
17572 struct cmd_ptype_mapping_replace_result {
17573         cmdline_fixed_string_t ptype;
17574         cmdline_fixed_string_t mapping;
17575         cmdline_fixed_string_t replace;
17576         portid_t port_id;
17577         uint32_t target;
17578         uint8_t mask;
17579         uint32_t pkt_type;
17580 };
17581
17582 /* Common CLI fields for ptype mapping replace */
17583 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17584         TOKEN_STRING_INITIALIZER
17585                 (struct cmd_ptype_mapping_replace_result,
17586                  ptype, "ptype");
17587 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17588         TOKEN_STRING_INITIALIZER
17589                 (struct cmd_ptype_mapping_replace_result,
17590                  mapping, "mapping");
17591 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17592         TOKEN_STRING_INITIALIZER
17593                 (struct cmd_ptype_mapping_replace_result,
17594                  replace, "replace");
17595 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17596         TOKEN_NUM_INITIALIZER
17597                 (struct cmd_ptype_mapping_replace_result,
17598                  port_id, UINT16);
17599 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17600         TOKEN_NUM_INITIALIZER
17601                 (struct cmd_ptype_mapping_replace_result,
17602                  target, UINT32);
17603 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17604         TOKEN_NUM_INITIALIZER
17605                 (struct cmd_ptype_mapping_replace_result,
17606                  mask, UINT8);
17607 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17608         TOKEN_NUM_INITIALIZER
17609                 (struct cmd_ptype_mapping_replace_result,
17610                  pkt_type, UINT32);
17611
17612 static void
17613 cmd_ptype_mapping_replace_parsed(
17614         void *parsed_result,
17615         __attribute__((unused)) struct cmdline *cl,
17616         __attribute__((unused)) void *data)
17617 {
17618         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17619         int ret = -ENOTSUP;
17620
17621         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17622                 return;
17623
17624 #ifdef RTE_LIBRTE_I40E_PMD
17625         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17626                                         res->target,
17627                                         res->mask,
17628                                         res->pkt_type);
17629 #endif
17630
17631         switch (ret) {
17632         case 0:
17633                 break;
17634         case -EINVAL:
17635                 printf("invalid ptype 0x%8x or 0x%8x\n",
17636                                 res->target, res->pkt_type);
17637                 break;
17638         case -ENODEV:
17639                 printf("invalid port_id %d\n", res->port_id);
17640                 break;
17641         case -ENOTSUP:
17642                 printf("function not implemented\n");
17643                 break;
17644         default:
17645                 printf("programming error: (%s)\n", strerror(-ret));
17646         }
17647 }
17648
17649 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17650         .f = cmd_ptype_mapping_replace_parsed,
17651         .data = NULL,
17652         .help_str =
17653                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17654         .tokens = {
17655                 (void *)&cmd_ptype_mapping_replace_ptype,
17656                 (void *)&cmd_ptype_mapping_replace_mapping,
17657                 (void *)&cmd_ptype_mapping_replace_replace,
17658                 (void *)&cmd_ptype_mapping_replace_port_id,
17659                 (void *)&cmd_ptype_mapping_replace_target,
17660                 (void *)&cmd_ptype_mapping_replace_mask,
17661                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17662                 NULL,
17663         },
17664 };
17665
17666 /* ptype mapping reset */
17667
17668 /* Common result structure for ptype mapping reset */
17669 struct cmd_ptype_mapping_reset_result {
17670         cmdline_fixed_string_t ptype;
17671         cmdline_fixed_string_t mapping;
17672         cmdline_fixed_string_t reset;
17673         portid_t port_id;
17674 };
17675
17676 /* Common CLI fields for ptype mapping reset*/
17677 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17678         TOKEN_STRING_INITIALIZER
17679                 (struct cmd_ptype_mapping_reset_result,
17680                  ptype, "ptype");
17681 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17682         TOKEN_STRING_INITIALIZER
17683                 (struct cmd_ptype_mapping_reset_result,
17684                  mapping, "mapping");
17685 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17686         TOKEN_STRING_INITIALIZER
17687                 (struct cmd_ptype_mapping_reset_result,
17688                  reset, "reset");
17689 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17690         TOKEN_NUM_INITIALIZER
17691                 (struct cmd_ptype_mapping_reset_result,
17692                  port_id, UINT16);
17693
17694 static void
17695 cmd_ptype_mapping_reset_parsed(
17696         void *parsed_result,
17697         __attribute__((unused)) struct cmdline *cl,
17698         __attribute__((unused)) void *data)
17699 {
17700         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17701         int ret = -ENOTSUP;
17702
17703         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17704                 return;
17705
17706 #ifdef RTE_LIBRTE_I40E_PMD
17707         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17708 #endif
17709
17710         switch (ret) {
17711         case 0:
17712                 break;
17713         case -ENODEV:
17714                 printf("invalid port_id %d\n", res->port_id);
17715                 break;
17716         case -ENOTSUP:
17717                 printf("function not implemented\n");
17718                 break;
17719         default:
17720                 printf("programming error: (%s)\n", strerror(-ret));
17721         }
17722 }
17723
17724 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17725         .f = cmd_ptype_mapping_reset_parsed,
17726         .data = NULL,
17727         .help_str = "ptype mapping reset <port_id>",
17728         .tokens = {
17729                 (void *)&cmd_ptype_mapping_reset_ptype,
17730                 (void *)&cmd_ptype_mapping_reset_mapping,
17731                 (void *)&cmd_ptype_mapping_reset_reset,
17732                 (void *)&cmd_ptype_mapping_reset_port_id,
17733                 NULL,
17734         },
17735 };
17736
17737 /* ptype mapping update */
17738
17739 /* Common result structure for ptype mapping update */
17740 struct cmd_ptype_mapping_update_result {
17741         cmdline_fixed_string_t ptype;
17742         cmdline_fixed_string_t mapping;
17743         cmdline_fixed_string_t reset;
17744         portid_t port_id;
17745         uint8_t hw_ptype;
17746         uint32_t sw_ptype;
17747 };
17748
17749 /* Common CLI fields for ptype mapping update*/
17750 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17751         TOKEN_STRING_INITIALIZER
17752                 (struct cmd_ptype_mapping_update_result,
17753                  ptype, "ptype");
17754 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17755         TOKEN_STRING_INITIALIZER
17756                 (struct cmd_ptype_mapping_update_result,
17757                  mapping, "mapping");
17758 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17759         TOKEN_STRING_INITIALIZER
17760                 (struct cmd_ptype_mapping_update_result,
17761                  reset, "update");
17762 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17763         TOKEN_NUM_INITIALIZER
17764                 (struct cmd_ptype_mapping_update_result,
17765                  port_id, UINT16);
17766 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17767         TOKEN_NUM_INITIALIZER
17768                 (struct cmd_ptype_mapping_update_result,
17769                  hw_ptype, UINT8);
17770 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17771         TOKEN_NUM_INITIALIZER
17772                 (struct cmd_ptype_mapping_update_result,
17773                  sw_ptype, UINT32);
17774
17775 static void
17776 cmd_ptype_mapping_update_parsed(
17777         void *parsed_result,
17778         __attribute__((unused)) struct cmdline *cl,
17779         __attribute__((unused)) void *data)
17780 {
17781         struct cmd_ptype_mapping_update_result *res = parsed_result;
17782         int ret = -ENOTSUP;
17783 #ifdef RTE_LIBRTE_I40E_PMD
17784         struct rte_pmd_i40e_ptype_mapping mapping;
17785 #endif
17786         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17787                 return;
17788
17789 #ifdef RTE_LIBRTE_I40E_PMD
17790         mapping.hw_ptype = res->hw_ptype;
17791         mapping.sw_ptype = res->sw_ptype;
17792         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17793                                                 &mapping,
17794                                                 1,
17795                                                 0);
17796 #endif
17797
17798         switch (ret) {
17799         case 0:
17800                 break;
17801         case -EINVAL:
17802                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17803                 break;
17804         case -ENODEV:
17805                 printf("invalid port_id %d\n", res->port_id);
17806                 break;
17807         case -ENOTSUP:
17808                 printf("function not implemented\n");
17809                 break;
17810         default:
17811                 printf("programming error: (%s)\n", strerror(-ret));
17812         }
17813 }
17814
17815 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17816         .f = cmd_ptype_mapping_update_parsed,
17817         .data = NULL,
17818         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17819         .tokens = {
17820                 (void *)&cmd_ptype_mapping_update_ptype,
17821                 (void *)&cmd_ptype_mapping_update_mapping,
17822                 (void *)&cmd_ptype_mapping_update_update,
17823                 (void *)&cmd_ptype_mapping_update_port_id,
17824                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17825                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17826                 NULL,
17827         },
17828 };
17829
17830 /* Common result structure for file commands */
17831 struct cmd_cmdfile_result {
17832         cmdline_fixed_string_t load;
17833         cmdline_fixed_string_t filename;
17834 };
17835
17836 /* Common CLI fields for file commands */
17837 cmdline_parse_token_string_t cmd_load_cmdfile =
17838         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17839 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17840         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17841
17842 static void
17843 cmd_load_from_file_parsed(
17844         void *parsed_result,
17845         __attribute__((unused)) struct cmdline *cl,
17846         __attribute__((unused)) void *data)
17847 {
17848         struct cmd_cmdfile_result *res = parsed_result;
17849
17850         cmdline_read_from_file(res->filename);
17851 }
17852
17853 cmdline_parse_inst_t cmd_load_from_file = {
17854         .f = cmd_load_from_file_parsed,
17855         .data = NULL,
17856         .help_str = "load <filename>",
17857         .tokens = {
17858                 (void *)&cmd_load_cmdfile,
17859                 (void *)&cmd_load_cmdfile_filename,
17860                 NULL,
17861         },
17862 };
17863
17864 /* Get Rx offloads capabilities */
17865 struct cmd_rx_offload_get_capa_result {
17866         cmdline_fixed_string_t show;
17867         cmdline_fixed_string_t port;
17868         portid_t port_id;
17869         cmdline_fixed_string_t rx_offload;
17870         cmdline_fixed_string_t capabilities;
17871 };
17872
17873 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17874         TOKEN_STRING_INITIALIZER
17875                 (struct cmd_rx_offload_get_capa_result,
17876                  show, "show");
17877 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17878         TOKEN_STRING_INITIALIZER
17879                 (struct cmd_rx_offload_get_capa_result,
17880                  port, "port");
17881 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17882         TOKEN_NUM_INITIALIZER
17883                 (struct cmd_rx_offload_get_capa_result,
17884                  port_id, UINT16);
17885 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17886         TOKEN_STRING_INITIALIZER
17887                 (struct cmd_rx_offload_get_capa_result,
17888                  rx_offload, "rx_offload");
17889 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17890         TOKEN_STRING_INITIALIZER
17891                 (struct cmd_rx_offload_get_capa_result,
17892                  capabilities, "capabilities");
17893
17894 static void
17895 print_rx_offloads(uint64_t offloads)
17896 {
17897         uint64_t single_offload;
17898         int begin;
17899         int end;
17900         int bit;
17901
17902         if (offloads == 0)
17903                 return;
17904
17905         begin = __builtin_ctzll(offloads);
17906         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17907
17908         single_offload = 1ULL << begin;
17909         for (bit = begin; bit < end; bit++) {
17910                 if (offloads & single_offload)
17911                         printf(" %s",
17912                                rte_eth_dev_rx_offload_name(single_offload));
17913                 single_offload <<= 1;
17914         }
17915 }
17916
17917 static void
17918 cmd_rx_offload_get_capa_parsed(
17919         void *parsed_result,
17920         __attribute__((unused)) struct cmdline *cl,
17921         __attribute__((unused)) void *data)
17922 {
17923         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17924         struct rte_eth_dev_info dev_info;
17925         portid_t port_id = res->port_id;
17926         uint64_t queue_offloads;
17927         uint64_t port_offloads;
17928         int ret;
17929
17930         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17931         if (ret != 0)
17932                 return;
17933
17934         queue_offloads = dev_info.rx_queue_offload_capa;
17935         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17936
17937         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17938         printf("  Per Queue :");
17939         print_rx_offloads(queue_offloads);
17940
17941         printf("\n");
17942         printf("  Per Port  :");
17943         print_rx_offloads(port_offloads);
17944         printf("\n\n");
17945 }
17946
17947 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17948         .f = cmd_rx_offload_get_capa_parsed,
17949         .data = NULL,
17950         .help_str = "show port <port_id> rx_offload capabilities",
17951         .tokens = {
17952                 (void *)&cmd_rx_offload_get_capa_show,
17953                 (void *)&cmd_rx_offload_get_capa_port,
17954                 (void *)&cmd_rx_offload_get_capa_port_id,
17955                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17956                 (void *)&cmd_rx_offload_get_capa_capabilities,
17957                 NULL,
17958         }
17959 };
17960
17961 /* Get Rx offloads configuration */
17962 struct cmd_rx_offload_get_configuration_result {
17963         cmdline_fixed_string_t show;
17964         cmdline_fixed_string_t port;
17965         portid_t port_id;
17966         cmdline_fixed_string_t rx_offload;
17967         cmdline_fixed_string_t configuration;
17968 };
17969
17970 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17971         TOKEN_STRING_INITIALIZER
17972                 (struct cmd_rx_offload_get_configuration_result,
17973                  show, "show");
17974 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17975         TOKEN_STRING_INITIALIZER
17976                 (struct cmd_rx_offload_get_configuration_result,
17977                  port, "port");
17978 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17979         TOKEN_NUM_INITIALIZER
17980                 (struct cmd_rx_offload_get_configuration_result,
17981                  port_id, UINT16);
17982 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17983         TOKEN_STRING_INITIALIZER
17984                 (struct cmd_rx_offload_get_configuration_result,
17985                  rx_offload, "rx_offload");
17986 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17987         TOKEN_STRING_INITIALIZER
17988                 (struct cmd_rx_offload_get_configuration_result,
17989                  configuration, "configuration");
17990
17991 static void
17992 cmd_rx_offload_get_configuration_parsed(
17993         void *parsed_result,
17994         __attribute__((unused)) struct cmdline *cl,
17995         __attribute__((unused)) void *data)
17996 {
17997         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17998         struct rte_eth_dev_info dev_info;
17999         portid_t port_id = res->port_id;
18000         struct rte_port *port = &ports[port_id];
18001         uint64_t port_offloads;
18002         uint64_t queue_offloads;
18003         uint16_t nb_rx_queues;
18004         int q;
18005         int ret;
18006
18007         printf("Rx Offloading Configuration of port %d :\n", port_id);
18008
18009         port_offloads = port->dev_conf.rxmode.offloads;
18010         printf("  Port :");
18011         print_rx_offloads(port_offloads);
18012         printf("\n");
18013
18014         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18015         if (ret != 0)
18016                 return;
18017
18018         nb_rx_queues = dev_info.nb_rx_queues;
18019         for (q = 0; q < nb_rx_queues; q++) {
18020                 queue_offloads = port->rx_conf[q].offloads;
18021                 printf("  Queue[%2d] :", q);
18022                 print_rx_offloads(queue_offloads);
18023                 printf("\n");
18024         }
18025         printf("\n");
18026 }
18027
18028 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18029         .f = cmd_rx_offload_get_configuration_parsed,
18030         .data = NULL,
18031         .help_str = "show port <port_id> rx_offload configuration",
18032         .tokens = {
18033                 (void *)&cmd_rx_offload_get_configuration_show,
18034                 (void *)&cmd_rx_offload_get_configuration_port,
18035                 (void *)&cmd_rx_offload_get_configuration_port_id,
18036                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18037                 (void *)&cmd_rx_offload_get_configuration_configuration,
18038                 NULL,
18039         }
18040 };
18041
18042 /* Enable/Disable a per port offloading */
18043 struct cmd_config_per_port_rx_offload_result {
18044         cmdline_fixed_string_t port;
18045         cmdline_fixed_string_t config;
18046         portid_t port_id;
18047         cmdline_fixed_string_t rx_offload;
18048         cmdline_fixed_string_t offload;
18049         cmdline_fixed_string_t on_off;
18050 };
18051
18052 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18053         TOKEN_STRING_INITIALIZER
18054                 (struct cmd_config_per_port_rx_offload_result,
18055                  port, "port");
18056 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18057         TOKEN_STRING_INITIALIZER
18058                 (struct cmd_config_per_port_rx_offload_result,
18059                  config, "config");
18060 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18061         TOKEN_NUM_INITIALIZER
18062                 (struct cmd_config_per_port_rx_offload_result,
18063                  port_id, UINT16);
18064 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18065         TOKEN_STRING_INITIALIZER
18066                 (struct cmd_config_per_port_rx_offload_result,
18067                  rx_offload, "rx_offload");
18068 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18069         TOKEN_STRING_INITIALIZER
18070                 (struct cmd_config_per_port_rx_offload_result,
18071                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18072                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18073                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18074                            "crc_strip#scatter#timestamp#security#keep_crc");
18075 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18076         TOKEN_STRING_INITIALIZER
18077                 (struct cmd_config_per_port_rx_offload_result,
18078                  on_off, "on#off");
18079
18080 static uint64_t
18081 search_rx_offload(const char *name)
18082 {
18083         uint64_t single_offload;
18084         const char *single_name;
18085         int found = 0;
18086         unsigned int bit;
18087
18088         single_offload = 1;
18089         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18090                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18091                 if (!strcasecmp(single_name, name)) {
18092                         found = 1;
18093                         break;
18094                 }
18095                 single_offload <<= 1;
18096         }
18097
18098         if (found)
18099                 return single_offload;
18100
18101         return 0;
18102 }
18103
18104 static void
18105 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18106                                 __attribute__((unused)) struct cmdline *cl,
18107                                 __attribute__((unused)) void *data)
18108 {
18109         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18110         portid_t port_id = res->port_id;
18111         struct rte_eth_dev_info dev_info;
18112         struct rte_port *port = &ports[port_id];
18113         uint64_t single_offload;
18114         uint16_t nb_rx_queues;
18115         int q;
18116         int ret;
18117
18118         if (port->port_status != RTE_PORT_STOPPED) {
18119                 printf("Error: Can't config offload when Port %d "
18120                        "is not stopped\n", port_id);
18121                 return;
18122         }
18123
18124         single_offload = search_rx_offload(res->offload);
18125         if (single_offload == 0) {
18126                 printf("Unknown offload name: %s\n", res->offload);
18127                 return;
18128         }
18129
18130         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18131         if (ret != 0)
18132                 return;
18133
18134         nb_rx_queues = dev_info.nb_rx_queues;
18135         if (!strcmp(res->on_off, "on")) {
18136                 port->dev_conf.rxmode.offloads |= single_offload;
18137                 for (q = 0; q < nb_rx_queues; q++)
18138                         port->rx_conf[q].offloads |= single_offload;
18139         } else {
18140                 port->dev_conf.rxmode.offloads &= ~single_offload;
18141                 for (q = 0; q < nb_rx_queues; q++)
18142                         port->rx_conf[q].offloads &= ~single_offload;
18143         }
18144
18145         cmd_reconfig_device_queue(port_id, 1, 1);
18146 }
18147
18148 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18149         .f = cmd_config_per_port_rx_offload_parsed,
18150         .data = NULL,
18151         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18152                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18153                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18154                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18155                     "on|off",
18156         .tokens = {
18157                 (void *)&cmd_config_per_port_rx_offload_result_port,
18158                 (void *)&cmd_config_per_port_rx_offload_result_config,
18159                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18160                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18161                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18162                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18163                 NULL,
18164         }
18165 };
18166
18167 /* Enable/Disable a per queue offloading */
18168 struct cmd_config_per_queue_rx_offload_result {
18169         cmdline_fixed_string_t port;
18170         portid_t port_id;
18171         cmdline_fixed_string_t rxq;
18172         uint16_t queue_id;
18173         cmdline_fixed_string_t rx_offload;
18174         cmdline_fixed_string_t offload;
18175         cmdline_fixed_string_t on_off;
18176 };
18177
18178 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18179         TOKEN_STRING_INITIALIZER
18180                 (struct cmd_config_per_queue_rx_offload_result,
18181                  port, "port");
18182 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18183         TOKEN_NUM_INITIALIZER
18184                 (struct cmd_config_per_queue_rx_offload_result,
18185                  port_id, UINT16);
18186 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18187         TOKEN_STRING_INITIALIZER
18188                 (struct cmd_config_per_queue_rx_offload_result,
18189                  rxq, "rxq");
18190 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18191         TOKEN_NUM_INITIALIZER
18192                 (struct cmd_config_per_queue_rx_offload_result,
18193                  queue_id, UINT16);
18194 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18195         TOKEN_STRING_INITIALIZER
18196                 (struct cmd_config_per_queue_rx_offload_result,
18197                  rx_offload, "rx_offload");
18198 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18199         TOKEN_STRING_INITIALIZER
18200                 (struct cmd_config_per_queue_rx_offload_result,
18201                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18202                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18203                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18204                            "crc_strip#scatter#timestamp#security#keep_crc");
18205 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18206         TOKEN_STRING_INITIALIZER
18207                 (struct cmd_config_per_queue_rx_offload_result,
18208                  on_off, "on#off");
18209
18210 static void
18211 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18212                                 __attribute__((unused)) struct cmdline *cl,
18213                                 __attribute__((unused)) void *data)
18214 {
18215         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18216         struct rte_eth_dev_info dev_info;
18217         portid_t port_id = res->port_id;
18218         uint16_t queue_id = res->queue_id;
18219         struct rte_port *port = &ports[port_id];
18220         uint64_t single_offload;
18221         int ret;
18222
18223         if (port->port_status != RTE_PORT_STOPPED) {
18224                 printf("Error: Can't config offload when Port %d "
18225                        "is not stopped\n", port_id);
18226                 return;
18227         }
18228
18229         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18230         if (ret != 0)
18231                 return;
18232
18233         if (queue_id >= dev_info.nb_rx_queues) {
18234                 printf("Error: input queue_id should be 0 ... "
18235                        "%d\n", dev_info.nb_rx_queues - 1);
18236                 return;
18237         }
18238
18239         single_offload = search_rx_offload(res->offload);
18240         if (single_offload == 0) {
18241                 printf("Unknown offload name: %s\n", res->offload);
18242                 return;
18243         }
18244
18245         if (!strcmp(res->on_off, "on"))
18246                 port->rx_conf[queue_id].offloads |= single_offload;
18247         else
18248                 port->rx_conf[queue_id].offloads &= ~single_offload;
18249
18250         cmd_reconfig_device_queue(port_id, 1, 1);
18251 }
18252
18253 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18254         .f = cmd_config_per_queue_rx_offload_parsed,
18255         .data = NULL,
18256         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18257                     "vlan_strip|ipv4_cksum|"
18258                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18259                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18260                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18261                     "on|off",
18262         .tokens = {
18263                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18264                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18265                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18266                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18267                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18268                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18269                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18270                 NULL,
18271         }
18272 };
18273
18274 /* Get Tx offloads capabilities */
18275 struct cmd_tx_offload_get_capa_result {
18276         cmdline_fixed_string_t show;
18277         cmdline_fixed_string_t port;
18278         portid_t port_id;
18279         cmdline_fixed_string_t tx_offload;
18280         cmdline_fixed_string_t capabilities;
18281 };
18282
18283 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18284         TOKEN_STRING_INITIALIZER
18285                 (struct cmd_tx_offload_get_capa_result,
18286                  show, "show");
18287 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18288         TOKEN_STRING_INITIALIZER
18289                 (struct cmd_tx_offload_get_capa_result,
18290                  port, "port");
18291 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18292         TOKEN_NUM_INITIALIZER
18293                 (struct cmd_tx_offload_get_capa_result,
18294                  port_id, UINT16);
18295 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18296         TOKEN_STRING_INITIALIZER
18297                 (struct cmd_tx_offload_get_capa_result,
18298                  tx_offload, "tx_offload");
18299 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18300         TOKEN_STRING_INITIALIZER
18301                 (struct cmd_tx_offload_get_capa_result,
18302                  capabilities, "capabilities");
18303
18304 static void
18305 print_tx_offloads(uint64_t offloads)
18306 {
18307         uint64_t single_offload;
18308         int begin;
18309         int end;
18310         int bit;
18311
18312         if (offloads == 0)
18313                 return;
18314
18315         begin = __builtin_ctzll(offloads);
18316         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18317
18318         single_offload = 1ULL << begin;
18319         for (bit = begin; bit < end; bit++) {
18320                 if (offloads & single_offload)
18321                         printf(" %s",
18322                                rte_eth_dev_tx_offload_name(single_offload));
18323                 single_offload <<= 1;
18324         }
18325 }
18326
18327 static void
18328 cmd_tx_offload_get_capa_parsed(
18329         void *parsed_result,
18330         __attribute__((unused)) struct cmdline *cl,
18331         __attribute__((unused)) void *data)
18332 {
18333         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18334         struct rte_eth_dev_info dev_info;
18335         portid_t port_id = res->port_id;
18336         uint64_t queue_offloads;
18337         uint64_t port_offloads;
18338         int ret;
18339
18340         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18341         if (ret != 0)
18342                 return;
18343
18344         queue_offloads = dev_info.tx_queue_offload_capa;
18345         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18346
18347         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18348         printf("  Per Queue :");
18349         print_tx_offloads(queue_offloads);
18350
18351         printf("\n");
18352         printf("  Per Port  :");
18353         print_tx_offloads(port_offloads);
18354         printf("\n\n");
18355 }
18356
18357 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18358         .f = cmd_tx_offload_get_capa_parsed,
18359         .data = NULL,
18360         .help_str = "show port <port_id> tx_offload capabilities",
18361         .tokens = {
18362                 (void *)&cmd_tx_offload_get_capa_show,
18363                 (void *)&cmd_tx_offload_get_capa_port,
18364                 (void *)&cmd_tx_offload_get_capa_port_id,
18365                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18366                 (void *)&cmd_tx_offload_get_capa_capabilities,
18367                 NULL,
18368         }
18369 };
18370
18371 /* Get Tx offloads configuration */
18372 struct cmd_tx_offload_get_configuration_result {
18373         cmdline_fixed_string_t show;
18374         cmdline_fixed_string_t port;
18375         portid_t port_id;
18376         cmdline_fixed_string_t tx_offload;
18377         cmdline_fixed_string_t configuration;
18378 };
18379
18380 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18381         TOKEN_STRING_INITIALIZER
18382                 (struct cmd_tx_offload_get_configuration_result,
18383                  show, "show");
18384 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18385         TOKEN_STRING_INITIALIZER
18386                 (struct cmd_tx_offload_get_configuration_result,
18387                  port, "port");
18388 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18389         TOKEN_NUM_INITIALIZER
18390                 (struct cmd_tx_offload_get_configuration_result,
18391                  port_id, UINT16);
18392 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18393         TOKEN_STRING_INITIALIZER
18394                 (struct cmd_tx_offload_get_configuration_result,
18395                  tx_offload, "tx_offload");
18396 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18397         TOKEN_STRING_INITIALIZER
18398                 (struct cmd_tx_offload_get_configuration_result,
18399                  configuration, "configuration");
18400
18401 static void
18402 cmd_tx_offload_get_configuration_parsed(
18403         void *parsed_result,
18404         __attribute__((unused)) struct cmdline *cl,
18405         __attribute__((unused)) void *data)
18406 {
18407         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18408         struct rte_eth_dev_info dev_info;
18409         portid_t port_id = res->port_id;
18410         struct rte_port *port = &ports[port_id];
18411         uint64_t port_offloads;
18412         uint64_t queue_offloads;
18413         uint16_t nb_tx_queues;
18414         int q;
18415         int ret;
18416
18417         printf("Tx Offloading Configuration of port %d :\n", port_id);
18418
18419         port_offloads = port->dev_conf.txmode.offloads;
18420         printf("  Port :");
18421         print_tx_offloads(port_offloads);
18422         printf("\n");
18423
18424         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18425         if (ret != 0)
18426                 return;
18427
18428         nb_tx_queues = dev_info.nb_tx_queues;
18429         for (q = 0; q < nb_tx_queues; q++) {
18430                 queue_offloads = port->tx_conf[q].offloads;
18431                 printf("  Queue[%2d] :", q);
18432                 print_tx_offloads(queue_offloads);
18433                 printf("\n");
18434         }
18435         printf("\n");
18436 }
18437
18438 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18439         .f = cmd_tx_offload_get_configuration_parsed,
18440         .data = NULL,
18441         .help_str = "show port <port_id> tx_offload configuration",
18442         .tokens = {
18443                 (void *)&cmd_tx_offload_get_configuration_show,
18444                 (void *)&cmd_tx_offload_get_configuration_port,
18445                 (void *)&cmd_tx_offload_get_configuration_port_id,
18446                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18447                 (void *)&cmd_tx_offload_get_configuration_configuration,
18448                 NULL,
18449         }
18450 };
18451
18452 /* Enable/Disable a per port offloading */
18453 struct cmd_config_per_port_tx_offload_result {
18454         cmdline_fixed_string_t port;
18455         cmdline_fixed_string_t config;
18456         portid_t port_id;
18457         cmdline_fixed_string_t tx_offload;
18458         cmdline_fixed_string_t offload;
18459         cmdline_fixed_string_t on_off;
18460 };
18461
18462 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18463         TOKEN_STRING_INITIALIZER
18464                 (struct cmd_config_per_port_tx_offload_result,
18465                  port, "port");
18466 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18467         TOKEN_STRING_INITIALIZER
18468                 (struct cmd_config_per_port_tx_offload_result,
18469                  config, "config");
18470 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18471         TOKEN_NUM_INITIALIZER
18472                 (struct cmd_config_per_port_tx_offload_result,
18473                  port_id, UINT16);
18474 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18475         TOKEN_STRING_INITIALIZER
18476                 (struct cmd_config_per_port_tx_offload_result,
18477                  tx_offload, "tx_offload");
18478 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18479         TOKEN_STRING_INITIALIZER
18480                 (struct cmd_config_per_port_tx_offload_result,
18481                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18482                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18483                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18484                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18485                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18486                           "match_metadata");
18487 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18488         TOKEN_STRING_INITIALIZER
18489                 (struct cmd_config_per_port_tx_offload_result,
18490                  on_off, "on#off");
18491
18492 static uint64_t
18493 search_tx_offload(const char *name)
18494 {
18495         uint64_t single_offload;
18496         const char *single_name;
18497         int found = 0;
18498         unsigned int bit;
18499
18500         single_offload = 1;
18501         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18502                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18503                 if (single_name == NULL)
18504                         break;
18505                 if (!strcasecmp(single_name, name)) {
18506                         found = 1;
18507                         break;
18508                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18509                         break;
18510                 single_offload <<= 1;
18511         }
18512
18513         if (found)
18514                 return single_offload;
18515
18516         return 0;
18517 }
18518
18519 static void
18520 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18521                                 __attribute__((unused)) struct cmdline *cl,
18522                                 __attribute__((unused)) void *data)
18523 {
18524         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18525         portid_t port_id = res->port_id;
18526         struct rte_eth_dev_info dev_info;
18527         struct rte_port *port = &ports[port_id];
18528         uint64_t single_offload;
18529         uint16_t nb_tx_queues;
18530         int q;
18531         int ret;
18532
18533         if (port->port_status != RTE_PORT_STOPPED) {
18534                 printf("Error: Can't config offload when Port %d "
18535                        "is not stopped\n", port_id);
18536                 return;
18537         }
18538
18539         single_offload = search_tx_offload(res->offload);
18540         if (single_offload == 0) {
18541                 printf("Unknown offload name: %s\n", res->offload);
18542                 return;
18543         }
18544
18545         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18546         if (ret != 0)
18547                 return;
18548
18549         nb_tx_queues = dev_info.nb_tx_queues;
18550         if (!strcmp(res->on_off, "on")) {
18551                 port->dev_conf.txmode.offloads |= single_offload;
18552                 for (q = 0; q < nb_tx_queues; q++)
18553                         port->tx_conf[q].offloads |= single_offload;
18554         } else {
18555                 port->dev_conf.txmode.offloads &= ~single_offload;
18556                 for (q = 0; q < nb_tx_queues; q++)
18557                         port->tx_conf[q].offloads &= ~single_offload;
18558         }
18559
18560         cmd_reconfig_device_queue(port_id, 1, 1);
18561 }
18562
18563 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18564         .f = cmd_config_per_port_tx_offload_parsed,
18565         .data = NULL,
18566         .help_str = "port config <port_id> tx_offload "
18567                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18568                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18569                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18570                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18571                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18572                     "match_metadata on|off",
18573         .tokens = {
18574                 (void *)&cmd_config_per_port_tx_offload_result_port,
18575                 (void *)&cmd_config_per_port_tx_offload_result_config,
18576                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18577                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18578                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18579                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18580                 NULL,
18581         }
18582 };
18583
18584 /* Enable/Disable a per queue offloading */
18585 struct cmd_config_per_queue_tx_offload_result {
18586         cmdline_fixed_string_t port;
18587         portid_t port_id;
18588         cmdline_fixed_string_t txq;
18589         uint16_t queue_id;
18590         cmdline_fixed_string_t tx_offload;
18591         cmdline_fixed_string_t offload;
18592         cmdline_fixed_string_t on_off;
18593 };
18594
18595 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18596         TOKEN_STRING_INITIALIZER
18597                 (struct cmd_config_per_queue_tx_offload_result,
18598                  port, "port");
18599 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18600         TOKEN_NUM_INITIALIZER
18601                 (struct cmd_config_per_queue_tx_offload_result,
18602                  port_id, UINT16);
18603 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18604         TOKEN_STRING_INITIALIZER
18605                 (struct cmd_config_per_queue_tx_offload_result,
18606                  txq, "txq");
18607 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18608         TOKEN_NUM_INITIALIZER
18609                 (struct cmd_config_per_queue_tx_offload_result,
18610                  queue_id, UINT16);
18611 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18612         TOKEN_STRING_INITIALIZER
18613                 (struct cmd_config_per_queue_tx_offload_result,
18614                  tx_offload, "tx_offload");
18615 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18616         TOKEN_STRING_INITIALIZER
18617                 (struct cmd_config_per_queue_tx_offload_result,
18618                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18619                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18620                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18621                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18622                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18623 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18624         TOKEN_STRING_INITIALIZER
18625                 (struct cmd_config_per_queue_tx_offload_result,
18626                  on_off, "on#off");
18627
18628 static void
18629 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18630                                 __attribute__((unused)) struct cmdline *cl,
18631                                 __attribute__((unused)) void *data)
18632 {
18633         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18634         struct rte_eth_dev_info dev_info;
18635         portid_t port_id = res->port_id;
18636         uint16_t queue_id = res->queue_id;
18637         struct rte_port *port = &ports[port_id];
18638         uint64_t single_offload;
18639         int ret;
18640
18641         if (port->port_status != RTE_PORT_STOPPED) {
18642                 printf("Error: Can't config offload when Port %d "
18643                        "is not stopped\n", port_id);
18644                 return;
18645         }
18646
18647         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18648         if (ret != 0)
18649                 return;
18650
18651         if (queue_id >= dev_info.nb_tx_queues) {
18652                 printf("Error: input queue_id should be 0 ... "
18653                        "%d\n", dev_info.nb_tx_queues - 1);
18654                 return;
18655         }
18656
18657         single_offload = search_tx_offload(res->offload);
18658         if (single_offload == 0) {
18659                 printf("Unknown offload name: %s\n", res->offload);
18660                 return;
18661         }
18662
18663         if (!strcmp(res->on_off, "on"))
18664                 port->tx_conf[queue_id].offloads |= single_offload;
18665         else
18666                 port->tx_conf[queue_id].offloads &= ~single_offload;
18667
18668         cmd_reconfig_device_queue(port_id, 1, 1);
18669 }
18670
18671 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18672         .f = cmd_config_per_queue_tx_offload_parsed,
18673         .data = NULL,
18674         .help_str = "port <port_id> txq <queue_id> tx_offload "
18675                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18676                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18677                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18678                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18679                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18680                     "on|off",
18681         .tokens = {
18682                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18683                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18684                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18685                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18686                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18687                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18688                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18689                 NULL,
18690         }
18691 };
18692
18693 /* *** configure tx_metadata for specific port *** */
18694 struct cmd_config_tx_metadata_specific_result {
18695         cmdline_fixed_string_t port;
18696         cmdline_fixed_string_t keyword;
18697         uint16_t port_id;
18698         cmdline_fixed_string_t item;
18699         uint32_t value;
18700 };
18701
18702 static void
18703 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18704                                 __attribute__((unused)) struct cmdline *cl,
18705                                 __attribute__((unused)) void *data)
18706 {
18707         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18708
18709         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18710                 return;
18711         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18712         /* Add/remove callback to insert valid metadata in every Tx packet. */
18713         if (ports[res->port_id].tx_metadata)
18714                 add_tx_md_callback(res->port_id);
18715         else
18716                 remove_tx_md_callback(res->port_id);
18717 }
18718
18719 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18720         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18721                         port, "port");
18722 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18723         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18724                         keyword, "config");
18725 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18726         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18727                         port_id, UINT16);
18728 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18729         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18730                         item, "tx_metadata");
18731 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18732         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18733                         value, UINT32);
18734
18735 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18736         .f = cmd_config_tx_metadata_specific_parsed,
18737         .data = NULL,
18738         .help_str = "port config <port_id> tx_metadata <value>",
18739         .tokens = {
18740                 (void *)&cmd_config_tx_metadata_specific_port,
18741                 (void *)&cmd_config_tx_metadata_specific_keyword,
18742                 (void *)&cmd_config_tx_metadata_specific_id,
18743                 (void *)&cmd_config_tx_metadata_specific_item,
18744                 (void *)&cmd_config_tx_metadata_specific_value,
18745                 NULL,
18746         },
18747 };
18748
18749 /* *** display tx_metadata per port configuration *** */
18750 struct cmd_show_tx_metadata_result {
18751         cmdline_fixed_string_t cmd_show;
18752         cmdline_fixed_string_t cmd_port;
18753         cmdline_fixed_string_t cmd_keyword;
18754         portid_t cmd_pid;
18755 };
18756
18757 static void
18758 cmd_show_tx_metadata_parsed(void *parsed_result,
18759                 __attribute__((unused)) struct cmdline *cl,
18760                 __attribute__((unused)) void *data)
18761 {
18762         struct cmd_show_tx_metadata_result *res = parsed_result;
18763
18764         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18765                 printf("invalid port id %u\n", res->cmd_pid);
18766                 return;
18767         }
18768         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18769                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18770                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18771         }
18772 }
18773
18774 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18775         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18776                         cmd_show, "show");
18777 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18778         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18779                         cmd_port, "port");
18780 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18781         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18782                         cmd_pid, UINT16);
18783 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18784         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18785                         cmd_keyword, "tx_metadata");
18786
18787 cmdline_parse_inst_t cmd_show_tx_metadata = {
18788         .f = cmd_show_tx_metadata_parsed,
18789         .data = NULL,
18790         .help_str = "show port <port_id> tx_metadata",
18791         .tokens = {
18792                 (void *)&cmd_show_tx_metadata_show,
18793                 (void *)&cmd_show_tx_metadata_port,
18794                 (void *)&cmd_show_tx_metadata_pid,
18795                 (void *)&cmd_show_tx_metadata_keyword,
18796                 NULL,
18797         },
18798 };
18799
18800 /* show port supported ptypes */
18801
18802 /* Common result structure for show port ptypes */
18803 struct cmd_show_port_supported_ptypes_result {
18804         cmdline_fixed_string_t show;
18805         cmdline_fixed_string_t port;
18806         portid_t port_id;
18807         cmdline_fixed_string_t ptypes;
18808 };
18809
18810 /* Common CLI fields for show port ptypes */
18811 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
18812         TOKEN_STRING_INITIALIZER
18813                 (struct cmd_show_port_supported_ptypes_result,
18814                  show, "show");
18815 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
18816         TOKEN_STRING_INITIALIZER
18817                 (struct cmd_show_port_supported_ptypes_result,
18818                  port, "port");
18819 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
18820         TOKEN_NUM_INITIALIZER
18821                 (struct cmd_show_port_supported_ptypes_result,
18822                  port_id, UINT16);
18823 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
18824         TOKEN_STRING_INITIALIZER
18825                 (struct cmd_show_port_supported_ptypes_result,
18826                  ptypes, "ptypes");
18827
18828 static void
18829 cmd_show_port_supported_ptypes_parsed(
18830         void *parsed_result,
18831         __attribute__((unused)) struct cmdline *cl,
18832         __attribute__((unused)) void *data)
18833 {
18834 #define RSVD_PTYPE_MASK       0xf0000000
18835 #define MAX_PTYPES_PER_LAYER  16
18836 #define LTYPE_NAMESIZE        32
18837 #define PTYPE_NAMESIZE        256
18838         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
18839         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
18840         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
18841         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
18842         uint16_t port_id = res->port_id;
18843         int ret, i;
18844
18845         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
18846         if (ret < 0)
18847                 return;
18848
18849         while (ptype_mask != RSVD_PTYPE_MASK) {
18850
18851                 switch (ptype_mask) {
18852                 case RTE_PTYPE_L2_MASK:
18853                         strlcpy(ltype, "L2", sizeof(ltype));
18854                         break;
18855                 case RTE_PTYPE_L3_MASK:
18856                         strlcpy(ltype, "L3", sizeof(ltype));
18857                         break;
18858                 case RTE_PTYPE_L4_MASK:
18859                         strlcpy(ltype, "L4", sizeof(ltype));
18860                         break;
18861                 case RTE_PTYPE_TUNNEL_MASK:
18862                         strlcpy(ltype, "Tunnel", sizeof(ltype));
18863                         break;
18864                 case RTE_PTYPE_INNER_L2_MASK:
18865                         strlcpy(ltype, "Inner L2", sizeof(ltype));
18866                         break;
18867                 case RTE_PTYPE_INNER_L3_MASK:
18868                         strlcpy(ltype, "Inner L3", sizeof(ltype));
18869                         break;
18870                 case RTE_PTYPE_INNER_L4_MASK:
18871                         strlcpy(ltype, "Inner L4", sizeof(ltype));
18872                         break;
18873                 default:
18874                         return;
18875                 }
18876
18877                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
18878                                                        ptype_mask, ptypes,
18879                                                        MAX_PTYPES_PER_LAYER);
18880
18881                 if (ret > 0)
18882                         printf("Supported %s ptypes:\n", ltype);
18883                 else
18884                         printf("%s ptypes unsupported\n", ltype);
18885
18886                 for (i = 0; i < ret; ++i) {
18887                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
18888                         printf("%s\n", buf);
18889                 }
18890
18891                 ptype_mask <<= 4;
18892         }
18893 }
18894
18895 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
18896         .f = cmd_show_port_supported_ptypes_parsed,
18897         .data = NULL,
18898         .help_str = "show port <port_id> ptypes",
18899         .tokens = {
18900                 (void *)&cmd_show_port_supported_ptypes_show,
18901                 (void *)&cmd_show_port_supported_ptypes_port,
18902                 (void *)&cmd_show_port_supported_ptypes_port_id,
18903                 (void *)&cmd_show_port_supported_ptypes_ptypes,
18904                 NULL,
18905         },
18906 };
18907
18908 /* ******************************************************************************** */
18909
18910 /* list of instructions */
18911 cmdline_parse_ctx_t main_ctx[] = {
18912         (cmdline_parse_inst_t *)&cmd_help_brief,
18913         (cmdline_parse_inst_t *)&cmd_help_long,
18914         (cmdline_parse_inst_t *)&cmd_quit,
18915         (cmdline_parse_inst_t *)&cmd_load_from_file,
18916         (cmdline_parse_inst_t *)&cmd_showport,
18917         (cmdline_parse_inst_t *)&cmd_showqueue,
18918         (cmdline_parse_inst_t *)&cmd_showportall,
18919         (cmdline_parse_inst_t *)&cmd_showdevice,
18920         (cmdline_parse_inst_t *)&cmd_showcfg,
18921         (cmdline_parse_inst_t *)&cmd_showfwdall,
18922         (cmdline_parse_inst_t *)&cmd_start,
18923         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18924         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18925         (cmdline_parse_inst_t *)&cmd_set_link_up,
18926         (cmdline_parse_inst_t *)&cmd_set_link_down,
18927         (cmdline_parse_inst_t *)&cmd_reset,
18928         (cmdline_parse_inst_t *)&cmd_set_numbers,
18929         (cmdline_parse_inst_t *)&cmd_set_log,
18930         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18931         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18932         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18933         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18934         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18935         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18936         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18937         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18938         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18939         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18940         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18941         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18942         (cmdline_parse_inst_t *)&cmd_set_link_check,
18943         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18944         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18945         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18946         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18947 #ifdef RTE_LIBRTE_PMD_BOND
18948         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18949         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18950         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18951         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18952         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18953         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18954         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18955         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18956         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18957         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18958         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18959 #endif
18960         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18961         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18962         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18963         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18964         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18965         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18966         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18967         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18968         (cmdline_parse_inst_t *)&cmd_csum_set,
18969         (cmdline_parse_inst_t *)&cmd_csum_show,
18970         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18971         (cmdline_parse_inst_t *)&cmd_tso_set,
18972         (cmdline_parse_inst_t *)&cmd_tso_show,
18973         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18974         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18975         (cmdline_parse_inst_t *)&cmd_gro_enable,
18976         (cmdline_parse_inst_t *)&cmd_gro_flush,
18977         (cmdline_parse_inst_t *)&cmd_gro_show,
18978         (cmdline_parse_inst_t *)&cmd_gso_enable,
18979         (cmdline_parse_inst_t *)&cmd_gso_size,
18980         (cmdline_parse_inst_t *)&cmd_gso_show,
18981         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18982         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18983         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18984         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18985         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18986         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18987         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18988         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18989         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18990         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18991         (cmdline_parse_inst_t *)&cmd_config_dcb,
18992         (cmdline_parse_inst_t *)&cmd_read_reg,
18993         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18994         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18995         (cmdline_parse_inst_t *)&cmd_write_reg,
18996         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18997         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18998         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18999         (cmdline_parse_inst_t *)&cmd_stop,
19000         (cmdline_parse_inst_t *)&cmd_mac_addr,
19001         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19002         (cmdline_parse_inst_t *)&cmd_set_qmap,
19003         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19004         (cmdline_parse_inst_t *)&cmd_operate_port,
19005         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19006         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19007         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19008         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19009         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19010         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19011         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19012         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19013         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19014         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19015         (cmdline_parse_inst_t *)&cmd_config_mtu,
19016         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19017         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19018         (cmdline_parse_inst_t *)&cmd_config_rss,
19019         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19020         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19021         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19022         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19023         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19024         (cmdline_parse_inst_t *)&cmd_showport_reta,
19025         (cmdline_parse_inst_t *)&cmd_config_burst,
19026         (cmdline_parse_inst_t *)&cmd_config_thresh,
19027         (cmdline_parse_inst_t *)&cmd_config_threshold,
19028         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19029         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19030         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19031         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19032         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19033         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19034         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19035         (cmdline_parse_inst_t *)&cmd_global_config,
19036         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19037         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19038         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19039         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19040         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19041         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19042         (cmdline_parse_inst_t *)&cmd_dump,
19043         (cmdline_parse_inst_t *)&cmd_dump_one,
19044         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19045         (cmdline_parse_inst_t *)&cmd_syn_filter,
19046         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19047         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19048         (cmdline_parse_inst_t *)&cmd_flex_filter,
19049         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19050         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19051         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19052         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19053         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19054         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19055         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19056         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19057         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19058         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19059         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19060         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19061         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19062         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19063         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19064         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19065         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19066         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19067         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19068         (cmdline_parse_inst_t *)&cmd_flow,
19069         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19070         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19071         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19072         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19073         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19074         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19075         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19076         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19077         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19078         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19079         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19080         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19081         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19082         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19083         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19084         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19085         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19086         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19087         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19088         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19089         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19090         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19091         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19092         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19093         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19094         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19095         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19096         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19097         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19098         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19099         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19100         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19101         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19102         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19103         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19104         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19105         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19106         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19107         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19108         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19109         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19110         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19111         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19112         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19113         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19114         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19115         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19116         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19117         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19118 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19119         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19120 #endif
19121         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19122         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19123         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19124         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19125         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19126         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19127         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19128         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19129         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19130         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19131         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19132         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19133         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19134         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19135         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19136         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19137         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19138         (cmdline_parse_inst_t *)&cmd_ddp_add,
19139         (cmdline_parse_inst_t *)&cmd_ddp_del,
19140         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19141         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19142         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19143         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19144         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19145         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19146         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19147         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19148         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19149         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19150         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19151
19152         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19153         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19154         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19155         (cmdline_parse_inst_t *)&cmd_queue_region,
19156         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19157         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19158         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19159         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19160         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19161         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19162         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19163         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19164         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19165         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19166         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19167         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19168         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19169         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19170         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19171         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19172         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19173         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19174         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19175         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19176         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19177         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19178         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19179         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19180         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19181         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19182         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19183         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19184         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19185         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19186         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19187         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19188         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19189         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19190         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19191 #ifdef RTE_LIBRTE_BPF
19192         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19193         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19194 #endif
19195         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19196         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19197         (cmdline_parse_inst_t *)&cmd_set_raw,
19198         NULL,
19199 };
19200
19201 /* read cmdline commands from file */
19202 void
19203 cmdline_read_from_file(const char *filename)
19204 {
19205         struct cmdline *cl;
19206
19207         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19208         if (cl == NULL) {
19209                 printf("Failed to create file based cmdline context: %s\n",
19210                        filename);
19211                 return;
19212         }
19213
19214         cmdline_interact(cl);
19215         cmdline_quit(cl);
19216
19217         cmdline_free(cl);
19218
19219         printf("Read CLI commands from %s\n", filename);
19220 }
19221
19222 /* prompt function, called from main on MASTER lcore */
19223 void
19224 prompt(void)
19225 {
19226         /* initialize non-constant commands */
19227         cmd_set_fwd_mode_init();
19228         cmd_set_fwd_retry_mode_init();
19229
19230         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19231         if (testpmd_cl == NULL)
19232                 return;
19233         cmdline_interact(testpmd_cl);
19234         cmdline_stdin_exit(testpmd_cl);
19235 }
19236
19237 void
19238 prompt_exit(void)
19239 {
19240         if (testpmd_cl != NULL)
19241                 cmdline_quit(testpmd_cl);
19242 }
19243
19244 static void
19245 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19246 {
19247         if (id == (portid_t)RTE_PORT_ALL) {
19248                 portid_t pid;
19249
19250                 RTE_ETH_FOREACH_DEV(pid) {
19251                         /* check if need_reconfig has been set to 1 */
19252                         if (ports[pid].need_reconfig == 0)
19253                                 ports[pid].need_reconfig = dev;
19254                         /* check if need_reconfig_queues has been set to 1 */
19255                         if (ports[pid].need_reconfig_queues == 0)
19256                                 ports[pid].need_reconfig_queues = queue;
19257                 }
19258         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19259                 /* check if need_reconfig has been set to 1 */
19260                 if (ports[id].need_reconfig == 0)
19261                         ports[id].need_reconfig = dev;
19262                 /* check if need_reconfig_queues has been set to 1 */
19263                 if (ports[id].need_reconfig_queues == 0)
19264                         ports[id].need_reconfig_queues = queue;
19265         }
19266 }