New upstream version 18.11-rc1
[deb_dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22
23 #include <sys/queue.h>
24
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_eth_ctrl.h>
48 #include <rte_flow.h>
49 #include <rte_gro.h>
50
51 #include <cmdline_rdline.h>
52 #include <cmdline_parse.h>
53 #include <cmdline_parse_num.h>
54 #include <cmdline_parse_string.h>
55 #include <cmdline_parse_ipaddr.h>
56 #include <cmdline_parse_etheraddr.h>
57 #include <cmdline_socket.h>
58 #include <cmdline.h>
59 #ifdef RTE_LIBRTE_PMD_BOND
60 #include <rte_eth_bond.h>
61 #include <rte_eth_bond_8023ad.h>
62 #endif
63 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
64 #include <rte_pmd_dpaa.h>
65 #endif
66 #ifdef RTE_LIBRTE_IXGBE_PMD
67 #include <rte_pmd_ixgbe.h>
68 #endif
69 #ifdef RTE_LIBRTE_I40E_PMD
70 #include <rte_pmd_i40e.h>
71 #endif
72 #ifdef RTE_LIBRTE_BNXT_PMD
73 #include <rte_pmd_bnxt.h>
74 #endif
75 #include "testpmd.h"
76 #include "cmdline_mtr.h"
77 #include "cmdline_tm.h"
78 #include "bpf_cmd.h"
79
80 static struct cmdline *testpmd_cl;
81
82 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
83
84 /* *** Help command with introduction. *** */
85 struct cmd_help_brief_result {
86         cmdline_fixed_string_t help;
87 };
88
89 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
90                                   struct cmdline *cl,
91                                   __attribute__((unused)) void *data)
92 {
93         cmdline_printf(
94                 cl,
95                 "\n"
96                 "Help is available for the following sections:\n\n"
97                 "    help control    : Start and stop forwarding.\n"
98                 "    help display    : Displaying port, stats and config "
99                 "information.\n"
100                 "    help config     : Configuration information.\n"
101                 "    help ports      : Configuring ports.\n"
102                 "    help registers  : Reading and setting port registers.\n"
103                 "    help filters    : Filters configuration help.\n"
104                 "    help all        : All of the above sections.\n\n"
105         );
106
107 }
108
109 cmdline_parse_token_string_t cmd_help_brief_help =
110         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
111
112 cmdline_parse_inst_t cmd_help_brief = {
113         .f = cmd_help_brief_parsed,
114         .data = NULL,
115         .help_str = "help: Show help",
116         .tokens = {
117                 (void *)&cmd_help_brief_help,
118                 NULL,
119         },
120 };
121
122 /* *** Help command with help sections. *** */
123 struct cmd_help_long_result {
124         cmdline_fixed_string_t help;
125         cmdline_fixed_string_t section;
126 };
127
128 static void cmd_help_long_parsed(void *parsed_result,
129                                  struct cmdline *cl,
130                                  __attribute__((unused)) void *data)
131 {
132         int show_all = 0;
133         struct cmd_help_long_result *res = parsed_result;
134
135         if (!strcmp(res->section, "all"))
136                 show_all = 1;
137
138         if (show_all || !strcmp(res->section, "control")) {
139
140                 cmdline_printf(
141                         cl,
142                         "\n"
143                         "Control forwarding:\n"
144                         "-------------------\n\n"
145
146                         "start\n"
147                         "    Start packet forwarding with current configuration.\n\n"
148
149                         "start tx_first\n"
150                         "    Start packet forwarding with current config"
151                         " after sending one burst of packets.\n\n"
152
153                         "stop\n"
154                         "    Stop packet forwarding, and display accumulated"
155                         " statistics.\n\n"
156
157                         "quit\n"
158                         "    Quit to prompt.\n\n"
159                 );
160         }
161
162         if (show_all || !strcmp(res->section, "display")) {
163
164                 cmdline_printf(
165                         cl,
166                         "\n"
167                         "Display:\n"
168                         "--------\n\n"
169
170                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
171                         "    Display information for port_id, or all.\n\n"
172
173                         "show port X rss reta (size) (mask0,mask1,...)\n"
174                         "    Display the rss redirection table entry indicated"
175                         " by masks on port X. size is used to indicate the"
176                         " hardware supported reta size\n\n"
177
178                         "show port (port_id) rss-hash [key]\n"
179                         "    Display the RSS hash functions and RSS hash key of port\n\n"
180
181                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
182                         "    Clear information for port_id, or all.\n\n"
183
184                         "show (rxq|txq) info (port_id) (queue_id)\n"
185                         "    Display information for configured RX/TX queue.\n\n"
186
187                         "show config (rxtx|cores|fwd|txpkts)\n"
188                         "    Display the given configuration.\n\n"
189
190                         "read rxd (port_id) (queue_id) (rxd_id)\n"
191                         "    Display an RX descriptor of a port RX queue.\n\n"
192
193                         "read txd (port_id) (queue_id) (txd_id)\n"
194                         "    Display a TX descriptor of a port TX queue.\n\n"
195
196                         "ddp get list (port_id)\n"
197                         "    Get ddp profile info list\n\n"
198
199                         "ddp get info (profile_path)\n"
200                         "    Get ddp profile information.\n\n"
201
202                         "show vf stats (port_id) (vf_id)\n"
203                         "    Display a VF's statistics.\n\n"
204
205                         "clear vf stats (port_id) (vf_id)\n"
206                         "    Reset a VF's statistics.\n\n"
207
208                         "show port (port_id) pctype mapping\n"
209                         "    Get flow ptype to pctype mapping on a port\n\n"
210
211                         "show port meter stats (port_id) (meter_id) (clear)\n"
212                         "    Get meter stats on a port\n\n"
213                         "show port tm cap (port_id)\n"
214                         "       Display the port TM capability.\n\n"
215
216                         "show port tm level cap (port_id) (level_id)\n"
217                         "       Display the port TM hierarchical level capability.\n\n"
218
219                         "show port tm node cap (port_id) (node_id)\n"
220                         "       Display the port TM node capability.\n\n"
221
222                         "show port tm node type (port_id) (node_id)\n"
223                         "       Display the port TM node type.\n\n"
224
225                         "show port tm node stats (port_id) (node_id) (clear)\n"
226                         "       Display the port TM node stats.\n\n"
227
228                 );
229         }
230
231         if (show_all || !strcmp(res->section, "config")) {
232                 cmdline_printf(
233                         cl,
234                         "\n"
235                         "Configuration:\n"
236                         "--------------\n"
237                         "Configuration changes only become active when"
238                         " forwarding is started/restarted.\n\n"
239
240                         "set default\n"
241                         "    Reset forwarding to the default configuration.\n\n"
242
243                         "set verbose (level)\n"
244                         "    Set the debug verbosity level X.\n\n"
245
246                         "set log global|(type) (level)\n"
247                         "    Set the log level.\n\n"
248
249                         "set nbport (num)\n"
250                         "    Set number of ports.\n\n"
251
252                         "set nbcore (num)\n"
253                         "    Set number of cores.\n\n"
254
255                         "set coremask (mask)\n"
256                         "    Set the forwarding cores hexadecimal mask.\n\n"
257
258                         "set portmask (mask)\n"
259                         "    Set the forwarding ports hexadecimal mask.\n\n"
260
261                         "set burst (num)\n"
262                         "    Set number of packets per burst.\n\n"
263
264                         "set burst tx delay (microseconds) retry (num)\n"
265                         "    Set the transmit delay time and number of retries,"
266                         " effective when retry is enabled.\n\n"
267
268                         "set txpkts (x[,y]*)\n"
269                         "    Set the length of each segment of TXONLY"
270                         " and optionally CSUM packets.\n\n"
271
272                         "set txsplit (off|on|rand)\n"
273                         "    Set the split policy for the TX packets."
274                         " Right now only applicable for CSUM and TXONLY"
275                         " modes\n\n"
276
277                         "set corelist (x[,y]*)\n"
278                         "    Set the list of forwarding cores.\n\n"
279
280                         "set portlist (x[,y]*)\n"
281                         "    Set the list of forwarding ports.\n\n"
282
283                         "set port setup on (iterator|event)\n"
284                         "    Select how attached port is retrieved for setup.\n\n"
285
286                         "set tx loopback (port_id) (on|off)\n"
287                         "    Enable or disable tx loopback.\n\n"
288
289                         "set all queues drop (port_id) (on|off)\n"
290                         "    Set drop enable bit for all queues.\n\n"
291
292                         "set vf split drop (port_id) (vf_id) (on|off)\n"
293                         "    Set split drop enable bit for a VF from the PF.\n\n"
294
295                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
296                         "    Set MAC antispoof for a VF from the PF.\n\n"
297
298                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
299                         "    Enable MACsec offload.\n\n"
300
301                         "set macsec offload (port_id) off\n"
302                         "    Disable MACsec offload.\n\n"
303
304                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
305                         "    Configure MACsec secure connection (SC).\n\n"
306
307                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
308                         "    Configure MACsec secure association (SA).\n\n"
309
310                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
311                         "    Set VF broadcast for a VF from the PF.\n\n"
312
313                         "vlan set strip (on|off) (port_id)\n"
314                         "    Set the VLAN strip on a port.\n\n"
315
316                         "vlan set stripq (on|off) (port_id,queue_id)\n"
317                         "    Set the VLAN strip for a queue on a port.\n\n"
318
319                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
320                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
321
322                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
323                         "    Set VLAN insert for a VF from the PF.\n\n"
324
325                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
326                         "    Set VLAN antispoof for a VF from the PF.\n\n"
327
328                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN tag for a VF from the PF.\n\n"
330
331                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
332                         "    Set a VF's max bandwidth(Mbps).\n\n"
333
334                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
335                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
336
337                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
338                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
339
340                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
341                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
342
343                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
344                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
345
346                         "vlan set filter (on|off) (port_id)\n"
347                         "    Set the VLAN filter on a port.\n\n"
348
349                         "vlan set qinq (on|off) (port_id)\n"
350                         "    Set the VLAN QinQ (extended queue in queue)"
351                         " on a port.\n\n"
352
353                         "vlan set (inner|outer) tpid (value) (port_id)\n"
354                         "    Set the VLAN TPID for Packet Filtering on"
355                         " a port\n\n"
356
357                         "rx_vlan add (vlan_id|all) (port_id)\n"
358                         "    Add a vlan_id, or all identifiers, to the set"
359                         " of VLAN identifiers filtered by port_id.\n\n"
360
361                         "rx_vlan rm (vlan_id|all) (port_id)\n"
362                         "    Remove a vlan_id, or all identifiers, from the set"
363                         " of VLAN identifiers filtered by port_id.\n\n"
364
365                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
366                         "    Add a vlan_id, to the set of VLAN identifiers"
367                         "filtered for VF(s) from port_id.\n\n"
368
369                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
370                         "    Remove a vlan_id, to the set of VLAN identifiers"
371                         "filtered for VF(s) from port_id.\n\n"
372
373                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
374                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
375                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
376                         "   add a tunnel filter of a port.\n\n"
377
378                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
379                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
380                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
381                         "   remove a tunnel filter of a port.\n\n"
382
383                         "rx_vxlan_port add (udp_port) (port_id)\n"
384                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
385
386                         "rx_vxlan_port rm (udp_port) (port_id)\n"
387                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
390                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
391                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
392
393                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
394                         "    Set port based TX VLAN insertion.\n\n"
395
396                         "tx_vlan reset (port_id)\n"
397                         "    Disable hardware insertion of a VLAN header in"
398                         " packets sent on a port.\n\n"
399
400                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
401                         "    Select hardware or software calculation of the"
402                         " checksum when transmitting a packet using the"
403                         " csum forward engine.\n"
404                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
405                         "    outer-ip concerns the outer IP layer in"
406                         "    outer-udp concerns the outer UDP layer in"
407                         " case the packet is recognized as a tunnel packet by"
408                         " the forward engine (vxlan, gre and ipip are supported)\n"
409                         "    Please check the NIC datasheet for HW limits.\n\n"
410
411                         "csum parse-tunnel (on|off) (tx_port_id)\n"
412                         "    If disabled, treat tunnel packets as non-tunneled"
413                         " packets (treat inner headers as payload). The port\n"
414                         "    argument is the port used for TX in csum forward"
415                         " engine.\n\n"
416
417                         "csum show (port_id)\n"
418                         "    Display tx checksum offload configuration\n\n"
419
420                         "tso set (segsize) (portid)\n"
421                         "    Enable TCP Segmentation Offload in csum forward"
422                         " engine.\n"
423                         "    Please check the NIC datasheet for HW limits.\n\n"
424
425                         "tso show (portid)"
426                         "    Display the status of TCP Segmentation Offload.\n\n"
427
428                         "set port (port_id) gro on|off\n"
429                         "    Enable or disable Generic Receive Offload in"
430                         " csum forwarding engine.\n\n"
431
432                         "show port (port_id) gro\n"
433                         "    Display GRO configuration.\n\n"
434
435                         "set gro flush (cycles)\n"
436                         "    Set the cycle to flush GROed packets from"
437                         " reassembly tables.\n\n"
438
439                         "set port (port_id) gso (on|off)"
440                         "    Enable or disable Generic Segmentation Offload in"
441                         " csum forwarding engine.\n\n"
442
443                         "set gso segsz (length)\n"
444                         "    Set max packet length for output GSO segments,"
445                         " including packet header and payload.\n\n"
446
447                         "show port (port_id) gso\n"
448                         "    Show GSO configuration.\n\n"
449
450                         "set fwd (%s)\n"
451                         "    Set packet forwarding mode.\n\n"
452
453                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
454                         "    Add a MAC address on port_id.\n\n"
455
456                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
457                         "    Remove a MAC address from port_id.\n\n"
458
459                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
460                         "    Set the default MAC address for port_id.\n\n"
461
462                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
463                         "    Add a MAC address for a VF on the port.\n\n"
464
465                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
466                         "    Set the MAC address for a VF from the PF.\n\n"
467
468                         "set eth-peer (port_id) (peer_addr)\n"
469                         "    set the peer address for certain port.\n\n"
470
471                         "set port (port_id) uta (mac_address|all) (on|off)\n"
472                         "    Add/Remove a or all unicast hash filter(s)"
473                         "from port X.\n\n"
474
475                         "set promisc (port_id|all) (on|off)\n"
476                         "    Set the promiscuous mode on port_id, or all.\n\n"
477
478                         "set allmulti (port_id|all) (on|off)\n"
479                         "    Set the allmulti mode on port_id, or all.\n\n"
480
481                         "set vf promisc (port_id) (vf_id) (on|off)\n"
482                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
483
484                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
485                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
486
487                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
488                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
489                         " (on|off) autoneg (on|off) (port_id)\n"
490                         "set flow_ctrl rx (on|off) (portid)\n"
491                         "set flow_ctrl tx (on|off) (portid)\n"
492                         "set flow_ctrl high_water (high_water) (portid)\n"
493                         "set flow_ctrl low_water (low_water) (portid)\n"
494                         "set flow_ctrl pause_time (pause_time) (portid)\n"
495                         "set flow_ctrl send_xon (send_xon) (portid)\n"
496                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
497                         "set flow_ctrl autoneg (on|off) (port_id)\n"
498                         "    Set the link flow control parameter on a port.\n\n"
499
500                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
501                         " (low_water) (pause_time) (priority) (port_id)\n"
502                         "    Set the priority flow control parameter on a"
503                         " port.\n\n"
504
505                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
506                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
507                         " queue on port.\n"
508                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
509                         " on port 0 to mapping 5.\n\n"
510
511                         "set xstats-hide-zero on|off\n"
512                         "    Set the option to hide the zero values"
513                         " for xstats display.\n"
514
515                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
516                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
517
518                         "set port (port_id) vf (vf_id) (mac_addr)"
519                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
520                         "   Add/Remove unicast or multicast MAC addr filter"
521                         " for a VF.\n\n"
522
523                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
524                         "|MPE) (on|off)\n"
525                         "    AUPE:accepts untagged VLAN;"
526                         "ROPE:accept unicast hash\n\n"
527                         "    BAM:accepts broadcast packets;"
528                         "MPE:accepts all multicast packets\n\n"
529                         "    Enable/Disable a VF receive mode of a port\n\n"
530
531                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
532                         "    Set rate limit for a queue of a port\n\n"
533
534                         "set port (port_id) vf (vf_id) rate (rate_num) "
535                         "queue_mask (queue_mask_value)\n"
536                         "    Set rate limit for queues in VF of a port\n\n"
537
538                         "set port (port_id) mirror-rule (rule_id)"
539                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
540                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
541                         "   Set pool or vlan type mirror rule on a port.\n"
542                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
543                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
544                         " to pool 0.\n\n"
545
546                         "set port (port_id) mirror-rule (rule_id)"
547                         " (uplink-mirror|downlink-mirror) dst-pool"
548                         " (pool_id) (on|off)\n"
549                         "   Set uplink or downlink type mirror rule on a port.\n"
550                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
551                         " 0 on' enable mirror income traffic to pool 0.\n\n"
552
553                         "reset port (port_id) mirror-rule (rule_id)\n"
554                         "   Reset a mirror rule.\n\n"
555
556                         "set flush_rx (on|off)\n"
557                         "   Flush (default) or don't flush RX streams before"
558                         " forwarding. Mainly used with PCAP drivers.\n\n"
559
560                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
561                         "   Set the bypass mode for the lowest port on bypass enabled"
562                         " NIC.\n\n"
563
564                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
565                         "mode (normal|bypass|isolate) (port_id)\n"
566                         "   Set the event required to initiate specified bypass mode for"
567                         " the lowest port on a bypass enabled NIC where:\n"
568                         "       timeout   = enable bypass after watchdog timeout.\n"
569                         "       os_on     = enable bypass when OS/board is powered on.\n"
570                         "       os_off    = enable bypass when OS/board is powered off.\n"
571                         "       power_on  = enable bypass when power supply is turned on.\n"
572                         "       power_off = enable bypass when power supply is turned off."
573                         "\n\n"
574
575                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
576                         "   Set the bypass watchdog timeout to 'n' seconds"
577                         " where 0 = instant.\n\n"
578
579                         "show bypass config (port_id)\n"
580                         "   Show the bypass configuration for a bypass enabled NIC"
581                         " using the lowest port on the NIC.\n\n"
582
583 #ifdef RTE_LIBRTE_PMD_BOND
584                         "create bonded device (mode) (socket)\n"
585                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
586
587                         "add bonding slave (slave_id) (port_id)\n"
588                         "       Add a slave device to a bonded device.\n\n"
589
590                         "remove bonding slave (slave_id) (port_id)\n"
591                         "       Remove a slave device from a bonded device.\n\n"
592
593                         "set bonding mode (value) (port_id)\n"
594                         "       Set the bonding mode on a bonded device.\n\n"
595
596                         "set bonding primary (slave_id) (port_id)\n"
597                         "       Set the primary slave for a bonded device.\n\n"
598
599                         "show bonding config (port_id)\n"
600                         "       Show the bonding config for port_id.\n\n"
601
602                         "set bonding mac_addr (port_id) (address)\n"
603                         "       Set the MAC address of a bonded device.\n\n"
604
605                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
606                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
607
608                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
609                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
610
611                         "set bonding mon_period (port_id) (value)\n"
612                         "       Set the bonding link status monitoring polling period in ms.\n\n"
613
614                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
615                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
616
617 #endif
618                         "set link-up port (port_id)\n"
619                         "       Set link up for a port.\n\n"
620
621                         "set link-down port (port_id)\n"
622                         "       Set link down for a port.\n\n"
623
624                         "E-tag set insertion on port-tag-id (value)"
625                         " port (port_id) vf (vf_id)\n"
626                         "    Enable E-tag insertion for a VF on a port\n\n"
627
628                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
629                         "    Disable E-tag insertion for a VF on a port\n\n"
630
631                         "E-tag set stripping (on|off) port (port_id)\n"
632                         "    Enable/disable E-tag stripping on a port\n\n"
633
634                         "E-tag set forwarding (on|off) port (port_id)\n"
635                         "    Enable/disable E-tag based forwarding"
636                         " on a port\n\n"
637
638                         "E-tag set filter add e-tag-id (value) dst-pool"
639                         " (pool_id) port (port_id)\n"
640                         "    Add an E-tag forwarding filter on a port\n\n"
641
642                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
643                         "    Delete an E-tag forwarding filter on a port\n\n"
644
645 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
646                         "set port tm hierarchy default (port_id)\n"
647                         "       Set default traffic Management hierarchy on a port\n\n"
648
649 #endif
650                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
651                         "    Load a profile package on a port\n\n"
652
653                         "ddp del (port_id) (backup_profile_path)\n"
654                         "    Delete a profile package from a port\n\n"
655
656                         "ptype mapping get (port_id) (valid_only)\n"
657                         "    Get ptype mapping on a port\n\n"
658
659                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
660                         "    Replace target with the pkt_type in ptype mapping\n\n"
661
662                         "ptype mapping reset (port_id)\n"
663                         "    Reset ptype mapping on a port\n\n"
664
665                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
666                         "    Update a ptype mapping item on a port\n\n"
667
668                         "set port (port_id) queue-region region_id (value) "
669                         "queue_start_index (value) queue_num (value)\n"
670                         "    Set a queue region on a port\n\n"
671
672                         "set port (port_id) queue-region region_id (value) "
673                         "flowtype (value)\n"
674                         "    Set a flowtype region index on a port\n\n"
675
676                         "set port (port_id) queue-region UP (value) region_id (value)\n"
677                         "    Set the mapping of User Priority to "
678                         "queue region on a port\n\n"
679
680                         "set port (port_id) queue-region flush (on|off)\n"
681                         "    flush all queue region related configuration\n\n"
682
683                         "show port meter cap (port_id)\n"
684                         "    Show port meter capability information\n\n"
685
686                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
687                         "    meter profile add - srtcm rfc 2697\n\n"
688
689                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
690                         "    meter profile add - trtcm rfc 2698\n\n"
691
692                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
693                         "    meter profile add - trtcm rfc 4115\n\n"
694
695                         "del port meter profile (port_id) (profile_id)\n"
696                         "    meter profile delete\n\n"
697
698                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
699                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
700                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
701                         "(dscp_tbl_entry63)]\n"
702                         "    meter create\n\n"
703
704                         "enable port meter (port_id) (mtr_id)\n"
705                         "    meter enable\n\n"
706
707                         "disable port meter (port_id) (mtr_id)\n"
708                         "    meter disable\n\n"
709
710                         "del port meter (port_id) (mtr_id)\n"
711                         "    meter delete\n\n"
712
713                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
714                         "    meter update meter profile\n\n"
715
716                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
717                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
718                         "    update meter dscp table entries\n\n"
719
720                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
721                         "(action0) [(action1) (action2)]\n"
722                         "    meter update policer action\n\n"
723
724                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
725                         "    meter update stats\n\n"
726
727                         "show port (port_id) queue-region\n"
728                         "    show all queue region related configuration info\n\n"
729
730                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
731                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
732                         "       Add port tm node private shaper profile.\n\n"
733
734                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
735                         "       Delete port tm node private shaper profile.\n\n"
736
737                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
738                         " (shaper_profile_id)\n"
739                         "       Add/update port tm node shared shaper.\n\n"
740
741                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
742                         "       Delete port tm node shared shaper.\n\n"
743
744                         "set port tm node shaper profile (port_id) (node_id)"
745                         " (shaper_profile_id)\n"
746                         "       Set port tm node shaper profile.\n\n"
747
748                         "add port tm node wred profile (port_id) (wred_profile_id)"
749                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
750                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
751                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
752                         "       Add port tm node wred profile.\n\n"
753
754                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
755                         "       Delete port tm node wred profile.\n\n"
756
757                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
758                         " (priority) (weight) (level_id) (shaper_profile_id)"
759                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
760                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
761                         "       Add port tm nonleaf node.\n\n"
762
763                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
764                         " (priority) (weight) (level_id) (shaper_profile_id)"
765                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
766                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
767                         "       Add port tm leaf node.\n\n"
768
769                         "del port tm node (port_id) (node_id)\n"
770                         "       Delete port tm node.\n\n"
771
772                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
773                         " (priority) (weight)\n"
774                         "       Set port tm node parent.\n\n"
775
776                         "suspend port tm node (port_id) (node_id)"
777                         "       Suspend tm node.\n\n"
778
779                         "resume port tm node (port_id) (node_id)"
780                         "       Resume tm node.\n\n"
781
782                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
783                         "       Commit tm hierarchy.\n\n"
784
785                         "vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
786                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
787                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
788                         "       Configure the VXLAN encapsulation for flows.\n\n"
789
790                         "vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
791                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
792                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
793                         " eth-dst (eth-dst)\n"
794                         "       Configure the VXLAN encapsulation for flows.\n\n"
795
796                         "nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
797                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
798                         " (eth-dst)\n"
799                         "       Configure the NVGRE encapsulation for flows.\n\n"
800
801                         "nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
802                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
803                         " eth-src (eth-src) eth-dst (eth-dst)\n"
804                         "       Configure the NVGRE encapsulation for flows.\n\n"
805
806                         , list_pkt_forwarding_modes()
807                 );
808         }
809
810         if (show_all || !strcmp(res->section, "ports")) {
811
812                 cmdline_printf(
813                         cl,
814                         "\n"
815                         "Port Operations:\n"
816                         "----------------\n\n"
817
818                         "port start (port_id|all)\n"
819                         "    Start all ports or port_id.\n\n"
820
821                         "port stop (port_id|all)\n"
822                         "    Stop all ports or port_id.\n\n"
823
824                         "port close (port_id|all)\n"
825                         "    Close all ports or port_id.\n\n"
826
827                         "port attach (ident)\n"
828                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
829
830                         "port detach (port_id)\n"
831                         "    Detach physical or virtual dev by port_id\n\n"
832
833                         "port config (port_id|all)"
834                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
835                         " duplex (half|full|auto)\n"
836                         "    Set speed and duplex for all ports or port_id\n\n"
837
838                         "port config (port_id|all) loopback (mode)\n"
839                         "    Set loopback mode for all ports or port_id\n\n"
840
841                         "port config all (rxq|txq|rxd|txd) (value)\n"
842                         "    Set number for rxq/txq/rxd/txd.\n\n"
843
844                         "port config all max-pkt-len (value)\n"
845                         "    Set the max packet length.\n\n"
846
847                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
848                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
849                         " (on|off)\n"
850                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
851                         " for ports.\n\n"
852
853                         "port config all rss (all|default|ip|tcp|udp|sctp|"
854                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
855                         "    Set the RSS mode.\n\n"
856
857                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
858                         "    Set the RSS redirection table.\n\n"
859
860                         "port config (port_id) dcb vt (on|off) (traffic_class)"
861                         " pfc (on|off)\n"
862                         "    Set the DCB mode.\n\n"
863
864                         "port config all burst (value)\n"
865                         "    Set the number of packets per burst.\n\n"
866
867                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
868                         " (value)\n"
869                         "    Set the ring prefetch/host/writeback threshold"
870                         " for tx/rx queue.\n\n"
871
872                         "port config all (txfreet|txrst|rxfreet) (value)\n"
873                         "    Set free threshold for rx/tx, or set"
874                         " tx rs bit threshold.\n\n"
875                         "port config mtu X value\n"
876                         "    Set the MTU of port X to a given value\n\n"
877
878                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
879                         "    Set a rx/tx queue's ring size configuration, the new"
880                         " value will take effect after command that (re-)start the port"
881                         " or command that setup the specific queue\n\n"
882
883                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
884                         "    Start/stop a rx/tx queue of port X. Only take effect"
885                         " when port X is started\n\n"
886
887                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
888                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
889                         " take effect when port X is stopped.\n\n"
890
891                         "port (port_id) (rxq|txq) (queue_id) setup\n"
892                         "    Setup a rx/tx queue of port X.\n\n"
893
894                         "port config (port_id|all) l2-tunnel E-tag ether-type"
895                         " (value)\n"
896                         "    Set the value of E-tag ether-type.\n\n"
897
898                         "port config (port_id|all) l2-tunnel E-tag"
899                         " (enable|disable)\n"
900                         "    Enable/disable the E-tag support.\n\n"
901
902                         "port config (port_id) pctype mapping reset\n"
903                         "    Reset flow type to pctype mapping on a port\n\n"
904
905                         "port config (port_id) pctype mapping update"
906                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
907                         "    Update a flow type to pctype mapping item on a port\n\n"
908
909                         "port config (port_id) pctype (pctype_id) hash_inset|"
910                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
911                         " (field_idx)\n"
912                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
913
914                         "port config (port_id) pctype (pctype_id) hash_inset|"
915                         "fdir_inset|fdir_flx_inset clear all"
916                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
917
918                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
919                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
920                 );
921         }
922
923         if (show_all || !strcmp(res->section, "registers")) {
924
925                 cmdline_printf(
926                         cl,
927                         "\n"
928                         "Registers:\n"
929                         "----------\n\n"
930
931                         "read reg (port_id) (address)\n"
932                         "    Display value of a port register.\n\n"
933
934                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
935                         "    Display a port register bit field.\n\n"
936
937                         "read regbit (port_id) (address) (bit_x)\n"
938                         "    Display a single port register bit.\n\n"
939
940                         "write reg (port_id) (address) (value)\n"
941                         "    Set value of a port register.\n\n"
942
943                         "write regfield (port_id) (address) (bit_x) (bit_y)"
944                         " (value)\n"
945                         "    Set bit field of a port register.\n\n"
946
947                         "write regbit (port_id) (address) (bit_x) (value)\n"
948                         "    Set single bit value of a port register.\n\n"
949                 );
950         }
951         if (show_all || !strcmp(res->section, "filters")) {
952
953                 cmdline_printf(
954                         cl,
955                         "\n"
956                         "filters:\n"
957                         "--------\n\n"
958
959                         "ethertype_filter (port_id) (add|del)"
960                         " (mac_addr|mac_ignr) (mac_address) ethertype"
961                         " (ether_type) (drop|fwd) queue (queue_id)\n"
962                         "    Add/Del an ethertype filter.\n\n"
963
964                         "2tuple_filter (port_id) (add|del)"
965                         " dst_port (dst_port_value) protocol (protocol_value)"
966                         " mask (mask_value) tcp_flags (tcp_flags_value)"
967                         " priority (prio_value) queue (queue_id)\n"
968                         "    Add/Del a 2tuple filter.\n\n"
969
970                         "5tuple_filter (port_id) (add|del)"
971                         " dst_ip (dst_address) src_ip (src_address)"
972                         " dst_port (dst_port_value) src_port (src_port_value)"
973                         " protocol (protocol_value)"
974                         " mask (mask_value) tcp_flags (tcp_flags_value)"
975                         " priority (prio_value) queue (queue_id)\n"
976                         "    Add/Del a 5tuple filter.\n\n"
977
978                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
979                         "    Add/Del syn filter.\n\n"
980
981                         "flex_filter (port_id) (add|del) len (len_value)"
982                         " bytes (bytes_value) mask (mask_value)"
983                         " priority (prio_value) queue (queue_id)\n"
984                         "    Add/Del a flex filter.\n\n"
985
986                         "flow_director_filter (port_id) mode IP (add|del|update)"
987                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
988                         " src (src_ip_address) dst (dst_ip_address)"
989                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
990                         " vlan (vlan_value) flexbytes (flexbytes_value)"
991                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
992                         " fd_id (fd_id_value)\n"
993                         "    Add/Del an IP type flow director filter.\n\n"
994
995                         "flow_director_filter (port_id) mode IP (add|del|update)"
996                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
997                         " src (src_ip_address) (src_port)"
998                         " dst (dst_ip_address) (dst_port)"
999                         " tos (tos_value) ttl (ttl_value)"
1000                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1001                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1002                         " fd_id (fd_id_value)\n"
1003                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1004
1005                         "flow_director_filter (port_id) mode IP (add|del|update)"
1006                         " flow (ipv4-sctp|ipv6-sctp)"
1007                         " src (src_ip_address) (src_port)"
1008                         " dst (dst_ip_address) (dst_port)"
1009                         " tag (verification_tag) "
1010                         " tos (tos_value) ttl (ttl_value)"
1011                         " vlan (vlan_value)"
1012                         " flexbytes (flexbytes_value) (drop|fwd)"
1013                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1014                         "    Add/Del a SCTP type flow director filter.\n\n"
1015
1016                         "flow_director_filter (port_id) mode IP (add|del|update)"
1017                         " flow l2_payload ether (ethertype)"
1018                         " flexbytes (flexbytes_value) (drop|fwd)"
1019                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1020                         "    Add/Del a l2 payload type flow director filter.\n\n"
1021
1022                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1023                         " mac (mac_address) vlan (vlan_value)"
1024                         " flexbytes (flexbytes_value) (drop|fwd)"
1025                         " queue (queue_id) fd_id (fd_id_value)\n"
1026                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1027
1028                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1029                         " mac (mac_address) vlan (vlan_value)"
1030                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1031                         " flexbytes (flexbytes_value) (drop|fwd)"
1032                         " queue (queue_id) fd_id (fd_id_value)\n"
1033                         "    Add/Del a Tunnel flow director filter.\n\n"
1034
1035                         "flow_director_filter (port_id) mode raw (add|del|update)"
1036                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1037                         " fd_id (fd_id_value) packet (packet file name)\n"
1038                         "    Add/Del a raw type flow director filter.\n\n"
1039
1040                         "flush_flow_director (port_id)\n"
1041                         "    Flush all flow director entries of a device.\n\n"
1042
1043                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1044                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1045                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1046                         "    Set flow director IP mask.\n\n"
1047
1048                         "flow_director_mask (port_id) mode MAC-VLAN"
1049                         " vlan (vlan_value)\n"
1050                         "    Set flow director MAC-VLAN mask.\n\n"
1051
1052                         "flow_director_mask (port_id) mode Tunnel"
1053                         " vlan (vlan_value) mac (mac_value)"
1054                         " tunnel-type (tunnel_type_value)"
1055                         " tunnel-id (tunnel_id_value)\n"
1056                         "    Set flow director Tunnel mask.\n\n"
1057
1058                         "flow_director_flex_mask (port_id)"
1059                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1060                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1061                         " (mask)\n"
1062                         "    Configure mask of flex payload.\n\n"
1063
1064                         "flow_director_flex_payload (port_id)"
1065                         " (raw|l2|l3|l4) (config)\n"
1066                         "    Configure flex payload selection.\n\n"
1067
1068                         "get_sym_hash_ena_per_port (port_id)\n"
1069                         "    get symmetric hash enable configuration per port.\n\n"
1070
1071                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1072                         "    set symmetric hash enable configuration per port"
1073                         " to enable or disable.\n\n"
1074
1075                         "get_hash_global_config (port_id)\n"
1076                         "    Get the global configurations of hash filters.\n\n"
1077
1078                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1079                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1080                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1081                         " (enable|disable)\n"
1082                         "    Set the global configurations of hash filters.\n\n"
1083
1084                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1085                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1086                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1087                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1088                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1089                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1090                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1091                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1092                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1093                         "fld-8th|none) (select|add)\n"
1094                         "    Set the input set for hash.\n\n"
1095
1096                         "set_fdir_input_set (port_id) "
1097                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1098                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1099                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1100                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1101                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1102                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1103                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1104                         " (select|add)\n"
1105                         "    Set the input set for FDir.\n\n"
1106
1107                         "flow validate {port_id}"
1108                         " [group {group_id}] [priority {level}]"
1109                         " [ingress] [egress]"
1110                         " pattern {item} [/ {item} [...]] / end"
1111                         " actions {action} [/ {action} [...]] / end\n"
1112                         "    Check whether a flow rule can be created.\n\n"
1113
1114                         "flow create {port_id}"
1115                         " [group {group_id}] [priority {level}]"
1116                         " [ingress] [egress]"
1117                         " pattern {item} [/ {item} [...]] / end"
1118                         " actions {action} [/ {action} [...]] / end\n"
1119                         "    Create a flow rule.\n\n"
1120
1121                         "flow destroy {port_id} rule {rule_id} [...]\n"
1122                         "    Destroy specific flow rules.\n\n"
1123
1124                         "flow flush {port_id}\n"
1125                         "    Destroy all flow rules.\n\n"
1126
1127                         "flow query {port_id} {rule_id} {action}\n"
1128                         "    Query an existing flow rule.\n\n"
1129
1130                         "flow list {port_id} [group {group_id}] [...]\n"
1131                         "    List existing flow rules sorted by priority,"
1132                         " filtered by group identifiers.\n\n"
1133
1134                         "flow isolate {port_id} {boolean}\n"
1135                         "    Restrict ingress traffic to the defined"
1136                         " flow rules\n\n"
1137                 );
1138         }
1139 }
1140
1141 cmdline_parse_token_string_t cmd_help_long_help =
1142         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1143
1144 cmdline_parse_token_string_t cmd_help_long_section =
1145         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1146                         "all#control#display#config#"
1147                         "ports#registers#filters");
1148
1149 cmdline_parse_inst_t cmd_help_long = {
1150         .f = cmd_help_long_parsed,
1151         .data = NULL,
1152         .help_str = "help all|control|display|config|ports|register|filters: "
1153                 "Show help",
1154         .tokens = {
1155                 (void *)&cmd_help_long_help,
1156                 (void *)&cmd_help_long_section,
1157                 NULL,
1158         },
1159 };
1160
1161
1162 /* *** start/stop/close all ports *** */
1163 struct cmd_operate_port_result {
1164         cmdline_fixed_string_t keyword;
1165         cmdline_fixed_string_t name;
1166         cmdline_fixed_string_t value;
1167 };
1168
1169 static void cmd_operate_port_parsed(void *parsed_result,
1170                                 __attribute__((unused)) struct cmdline *cl,
1171                                 __attribute__((unused)) void *data)
1172 {
1173         struct cmd_operate_port_result *res = parsed_result;
1174
1175         if (!strcmp(res->name, "start"))
1176                 start_port(RTE_PORT_ALL);
1177         else if (!strcmp(res->name, "stop"))
1178                 stop_port(RTE_PORT_ALL);
1179         else if (!strcmp(res->name, "close"))
1180                 close_port(RTE_PORT_ALL);
1181         else if (!strcmp(res->name, "reset"))
1182                 reset_port(RTE_PORT_ALL);
1183         else
1184                 printf("Unknown parameter\n");
1185 }
1186
1187 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1188         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1189                                                                 "port");
1190 cmdline_parse_token_string_t cmd_operate_port_all_port =
1191         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1192                                                 "start#stop#close#reset");
1193 cmdline_parse_token_string_t cmd_operate_port_all_all =
1194         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1195
1196 cmdline_parse_inst_t cmd_operate_port = {
1197         .f = cmd_operate_port_parsed,
1198         .data = NULL,
1199         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1200         .tokens = {
1201                 (void *)&cmd_operate_port_all_cmd,
1202                 (void *)&cmd_operate_port_all_port,
1203                 (void *)&cmd_operate_port_all_all,
1204                 NULL,
1205         },
1206 };
1207
1208 /* *** start/stop/close specific port *** */
1209 struct cmd_operate_specific_port_result {
1210         cmdline_fixed_string_t keyword;
1211         cmdline_fixed_string_t name;
1212         uint8_t value;
1213 };
1214
1215 static void cmd_operate_specific_port_parsed(void *parsed_result,
1216                         __attribute__((unused)) struct cmdline *cl,
1217                                 __attribute__((unused)) void *data)
1218 {
1219         struct cmd_operate_specific_port_result *res = parsed_result;
1220
1221         if (!strcmp(res->name, "start"))
1222                 start_port(res->value);
1223         else if (!strcmp(res->name, "stop"))
1224                 stop_port(res->value);
1225         else if (!strcmp(res->name, "close"))
1226                 close_port(res->value);
1227         else if (!strcmp(res->name, "reset"))
1228                 reset_port(res->value);
1229         else
1230                 printf("Unknown parameter\n");
1231 }
1232
1233 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1235                                                         keyword, "port");
1236 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1238                                                 name, "start#stop#close#reset");
1239 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1240         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1241                                                         value, UINT8);
1242
1243 cmdline_parse_inst_t cmd_operate_specific_port = {
1244         .f = cmd_operate_specific_port_parsed,
1245         .data = NULL,
1246         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1247         .tokens = {
1248                 (void *)&cmd_operate_specific_port_cmd,
1249                 (void *)&cmd_operate_specific_port_port,
1250                 (void *)&cmd_operate_specific_port_id,
1251                 NULL,
1252         },
1253 };
1254
1255 /* *** enable port setup (after attach) via iterator or event *** */
1256 struct cmd_set_port_setup_on_result {
1257         cmdline_fixed_string_t set;
1258         cmdline_fixed_string_t port;
1259         cmdline_fixed_string_t setup;
1260         cmdline_fixed_string_t on;
1261         cmdline_fixed_string_t mode;
1262 };
1263
1264 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1265                                 __attribute__((unused)) struct cmdline *cl,
1266                                 __attribute__((unused)) void *data)
1267 {
1268         struct cmd_set_port_setup_on_result *res = parsed_result;
1269
1270         if (strcmp(res->mode, "event") == 0)
1271                 setup_on_probe_event = true;
1272         else if (strcmp(res->mode, "iterator") == 0)
1273                 setup_on_probe_event = false;
1274         else
1275                 printf("Unknown mode\n");
1276 }
1277
1278 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1279         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1280                         set, "set");
1281 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1282         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1283                         port, "port");
1284 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1285         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1286                         setup, "setup");
1287 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1288         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1289                         on, "on");
1290 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1291         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1292                         mode, "iterator#event");
1293
1294 cmdline_parse_inst_t cmd_set_port_setup_on = {
1295         .f = cmd_set_port_setup_on_parsed,
1296         .data = NULL,
1297         .help_str = "set port setup on iterator|event",
1298         .tokens = {
1299                 (void *)&cmd_set_port_setup_on_set,
1300                 (void *)&cmd_set_port_setup_on_port,
1301                 (void *)&cmd_set_port_setup_on_setup,
1302                 (void *)&cmd_set_port_setup_on_on,
1303                 (void *)&cmd_set_port_setup_on_mode,
1304                 NULL,
1305         },
1306 };
1307
1308 /* *** attach a specified port *** */
1309 struct cmd_operate_attach_port_result {
1310         cmdline_fixed_string_t port;
1311         cmdline_fixed_string_t keyword;
1312         cmdline_fixed_string_t identifier;
1313 };
1314
1315 static void cmd_operate_attach_port_parsed(void *parsed_result,
1316                                 __attribute__((unused)) struct cmdline *cl,
1317                                 __attribute__((unused)) void *data)
1318 {
1319         struct cmd_operate_attach_port_result *res = parsed_result;
1320
1321         if (!strcmp(res->keyword, "attach"))
1322                 attach_port(res->identifier);
1323         else
1324                 printf("Unknown parameter\n");
1325 }
1326
1327 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1328         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1329                         port, "port");
1330 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1331         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1332                         keyword, "attach");
1333 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1334         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1335                         identifier, NULL);
1336
1337 cmdline_parse_inst_t cmd_operate_attach_port = {
1338         .f = cmd_operate_attach_port_parsed,
1339         .data = NULL,
1340         .help_str = "port attach <identifier>: "
1341                 "(identifier: pci address or virtual dev name)",
1342         .tokens = {
1343                 (void *)&cmd_operate_attach_port_port,
1344                 (void *)&cmd_operate_attach_port_keyword,
1345                 (void *)&cmd_operate_attach_port_identifier,
1346                 NULL,
1347         },
1348 };
1349
1350 /* *** detach a specified port *** */
1351 struct cmd_operate_detach_port_result {
1352         cmdline_fixed_string_t port;
1353         cmdline_fixed_string_t keyword;
1354         portid_t port_id;
1355 };
1356
1357 static void cmd_operate_detach_port_parsed(void *parsed_result,
1358                                 __attribute__((unused)) struct cmdline *cl,
1359                                 __attribute__((unused)) void *data)
1360 {
1361         struct cmd_operate_detach_port_result *res = parsed_result;
1362
1363         if (!strcmp(res->keyword, "detach"))
1364                 detach_port_device(res->port_id);
1365         else
1366                 printf("Unknown parameter\n");
1367 }
1368
1369 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1370         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1371                         port, "port");
1372 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1373         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1374                         keyword, "detach");
1375 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1376         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1377                         port_id, UINT16);
1378
1379 cmdline_parse_inst_t cmd_operate_detach_port = {
1380         .f = cmd_operate_detach_port_parsed,
1381         .data = NULL,
1382         .help_str = "port detach <port_id>",
1383         .tokens = {
1384                 (void *)&cmd_operate_detach_port_port,
1385                 (void *)&cmd_operate_detach_port_keyword,
1386                 (void *)&cmd_operate_detach_port_port_id,
1387                 NULL,
1388         },
1389 };
1390
1391 /* *** configure speed for all ports *** */
1392 struct cmd_config_speed_all {
1393         cmdline_fixed_string_t port;
1394         cmdline_fixed_string_t keyword;
1395         cmdline_fixed_string_t all;
1396         cmdline_fixed_string_t item1;
1397         cmdline_fixed_string_t item2;
1398         cmdline_fixed_string_t value1;
1399         cmdline_fixed_string_t value2;
1400 };
1401
1402 static int
1403 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1404 {
1405
1406         int duplex;
1407
1408         if (!strcmp(duplexstr, "half")) {
1409                 duplex = ETH_LINK_HALF_DUPLEX;
1410         } else if (!strcmp(duplexstr, "full")) {
1411                 duplex = ETH_LINK_FULL_DUPLEX;
1412         } else if (!strcmp(duplexstr, "auto")) {
1413                 duplex = ETH_LINK_FULL_DUPLEX;
1414         } else {
1415                 printf("Unknown duplex parameter\n");
1416                 return -1;
1417         }
1418
1419         if (!strcmp(speedstr, "10")) {
1420                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1421                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1422         } else if (!strcmp(speedstr, "100")) {
1423                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1424                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1425         } else {
1426                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1427                         printf("Invalid speed/duplex parameters\n");
1428                         return -1;
1429                 }
1430                 if (!strcmp(speedstr, "1000")) {
1431                         *speed = ETH_LINK_SPEED_1G;
1432                 } else if (!strcmp(speedstr, "10000")) {
1433                         *speed = ETH_LINK_SPEED_10G;
1434                 } else if (!strcmp(speedstr, "25000")) {
1435                         *speed = ETH_LINK_SPEED_25G;
1436                 } else if (!strcmp(speedstr, "40000")) {
1437                         *speed = ETH_LINK_SPEED_40G;
1438                 } else if (!strcmp(speedstr, "50000")) {
1439                         *speed = ETH_LINK_SPEED_50G;
1440                 } else if (!strcmp(speedstr, "100000")) {
1441                         *speed = ETH_LINK_SPEED_100G;
1442                 } else if (!strcmp(speedstr, "auto")) {
1443                         *speed = ETH_LINK_SPEED_AUTONEG;
1444                 } else {
1445                         printf("Unknown speed parameter\n");
1446                         return -1;
1447                 }
1448         }
1449
1450         return 0;
1451 }
1452
1453 static void
1454 cmd_config_speed_all_parsed(void *parsed_result,
1455                         __attribute__((unused)) struct cmdline *cl,
1456                         __attribute__((unused)) void *data)
1457 {
1458         struct cmd_config_speed_all *res = parsed_result;
1459         uint32_t link_speed;
1460         portid_t pid;
1461
1462         if (!all_ports_stopped()) {
1463                 printf("Please stop all ports first\n");
1464                 return;
1465         }
1466
1467         if (parse_and_check_speed_duplex(res->value1, res->value2,
1468                         &link_speed) < 0)
1469                 return;
1470
1471         RTE_ETH_FOREACH_DEV(pid) {
1472                 ports[pid].dev_conf.link_speeds = link_speed;
1473         }
1474
1475         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1476 }
1477
1478 cmdline_parse_token_string_t cmd_config_speed_all_port =
1479         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1480 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1481         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1482                                                         "config");
1483 cmdline_parse_token_string_t cmd_config_speed_all_all =
1484         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1485 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1486         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1487 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1488         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1489                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1490 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1491         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1492 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1493         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1494                                                 "half#full#auto");
1495
1496 cmdline_parse_inst_t cmd_config_speed_all = {
1497         .f = cmd_config_speed_all_parsed,
1498         .data = NULL,
1499         .help_str = "port config all speed "
1500                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1501                                                         "half|full|auto",
1502         .tokens = {
1503                 (void *)&cmd_config_speed_all_port,
1504                 (void *)&cmd_config_speed_all_keyword,
1505                 (void *)&cmd_config_speed_all_all,
1506                 (void *)&cmd_config_speed_all_item1,
1507                 (void *)&cmd_config_speed_all_value1,
1508                 (void *)&cmd_config_speed_all_item2,
1509                 (void *)&cmd_config_speed_all_value2,
1510                 NULL,
1511         },
1512 };
1513
1514 /* *** configure speed for specific port *** */
1515 struct cmd_config_speed_specific {
1516         cmdline_fixed_string_t port;
1517         cmdline_fixed_string_t keyword;
1518         portid_t id;
1519         cmdline_fixed_string_t item1;
1520         cmdline_fixed_string_t item2;
1521         cmdline_fixed_string_t value1;
1522         cmdline_fixed_string_t value2;
1523 };
1524
1525 static void
1526 cmd_config_speed_specific_parsed(void *parsed_result,
1527                                 __attribute__((unused)) struct cmdline *cl,
1528                                 __attribute__((unused)) void *data)
1529 {
1530         struct cmd_config_speed_specific *res = parsed_result;
1531         uint32_t link_speed;
1532
1533         if (!all_ports_stopped()) {
1534                 printf("Please stop all ports first\n");
1535                 return;
1536         }
1537
1538         if (port_id_is_invalid(res->id, ENABLED_WARN))
1539                 return;
1540
1541         if (parse_and_check_speed_duplex(res->value1, res->value2,
1542                         &link_speed) < 0)
1543                 return;
1544
1545         ports[res->id].dev_conf.link_speeds = link_speed;
1546
1547         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1548 }
1549
1550
1551 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1552         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1553                                                                 "port");
1554 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1555         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1556                                                                 "config");
1557 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1558         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1559 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1560         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1561                                                                 "speed");
1562 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1563         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1564                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1565 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1566         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1567                                                                 "duplex");
1568 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1569         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1570                                                         "half#full#auto");
1571
1572 cmdline_parse_inst_t cmd_config_speed_specific = {
1573         .f = cmd_config_speed_specific_parsed,
1574         .data = NULL,
1575         .help_str = "port config <port_id> speed "
1576                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1577                                                         "half|full|auto",
1578         .tokens = {
1579                 (void *)&cmd_config_speed_specific_port,
1580                 (void *)&cmd_config_speed_specific_keyword,
1581                 (void *)&cmd_config_speed_specific_id,
1582                 (void *)&cmd_config_speed_specific_item1,
1583                 (void *)&cmd_config_speed_specific_value1,
1584                 (void *)&cmd_config_speed_specific_item2,
1585                 (void *)&cmd_config_speed_specific_value2,
1586                 NULL,
1587         },
1588 };
1589
1590 /* *** configure loopback for all ports *** */
1591 struct cmd_config_loopback_all {
1592         cmdline_fixed_string_t port;
1593         cmdline_fixed_string_t keyword;
1594         cmdline_fixed_string_t all;
1595         cmdline_fixed_string_t item;
1596         uint32_t mode;
1597 };
1598
1599 static void
1600 cmd_config_loopback_all_parsed(void *parsed_result,
1601                         __attribute__((unused)) struct cmdline *cl,
1602                         __attribute__((unused)) void *data)
1603 {
1604         struct cmd_config_loopback_all *res = parsed_result;
1605         portid_t pid;
1606
1607         if (!all_ports_stopped()) {
1608                 printf("Please stop all ports first\n");
1609                 return;
1610         }
1611
1612         RTE_ETH_FOREACH_DEV(pid) {
1613                 ports[pid].dev_conf.lpbk_mode = res->mode;
1614         }
1615
1616         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1617 }
1618
1619 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1620         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1621 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1622         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1623                                                         "config");
1624 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1625         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1626 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1627         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1628                                                         "loopback");
1629 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1630         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1631
1632 cmdline_parse_inst_t cmd_config_loopback_all = {
1633         .f = cmd_config_loopback_all_parsed,
1634         .data = NULL,
1635         .help_str = "port config all loopback <mode>",
1636         .tokens = {
1637                 (void *)&cmd_config_loopback_all_port,
1638                 (void *)&cmd_config_loopback_all_keyword,
1639                 (void *)&cmd_config_loopback_all_all,
1640                 (void *)&cmd_config_loopback_all_item,
1641                 (void *)&cmd_config_loopback_all_mode,
1642                 NULL,
1643         },
1644 };
1645
1646 /* *** configure loopback for specific port *** */
1647 struct cmd_config_loopback_specific {
1648         cmdline_fixed_string_t port;
1649         cmdline_fixed_string_t keyword;
1650         uint16_t port_id;
1651         cmdline_fixed_string_t item;
1652         uint32_t mode;
1653 };
1654
1655 static void
1656 cmd_config_loopback_specific_parsed(void *parsed_result,
1657                                 __attribute__((unused)) struct cmdline *cl,
1658                                 __attribute__((unused)) void *data)
1659 {
1660         struct cmd_config_loopback_specific *res = parsed_result;
1661
1662         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1663                 return;
1664
1665         if (!port_is_stopped(res->port_id)) {
1666                 printf("Please stop port %u first\n", res->port_id);
1667                 return;
1668         }
1669
1670         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1671
1672         cmd_reconfig_device_queue(res->port_id, 1, 1);
1673 }
1674
1675
1676 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1677         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1678                                                                 "port");
1679 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1680         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1681                                                                 "config");
1682 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1683         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1684                                                                 UINT16);
1685 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1686         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1687                                                                 "loopback");
1688 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1689         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1690                               UINT32);
1691
1692 cmdline_parse_inst_t cmd_config_loopback_specific = {
1693         .f = cmd_config_loopback_specific_parsed,
1694         .data = NULL,
1695         .help_str = "port config <port_id> loopback <mode>",
1696         .tokens = {
1697                 (void *)&cmd_config_loopback_specific_port,
1698                 (void *)&cmd_config_loopback_specific_keyword,
1699                 (void *)&cmd_config_loopback_specific_id,
1700                 (void *)&cmd_config_loopback_specific_item,
1701                 (void *)&cmd_config_loopback_specific_mode,
1702                 NULL,
1703         },
1704 };
1705
1706 /* *** configure txq/rxq, txd/rxd *** */
1707 struct cmd_config_rx_tx {
1708         cmdline_fixed_string_t port;
1709         cmdline_fixed_string_t keyword;
1710         cmdline_fixed_string_t all;
1711         cmdline_fixed_string_t name;
1712         uint16_t value;
1713 };
1714
1715 static void
1716 cmd_config_rx_tx_parsed(void *parsed_result,
1717                         __attribute__((unused)) struct cmdline *cl,
1718                         __attribute__((unused)) void *data)
1719 {
1720         struct cmd_config_rx_tx *res = parsed_result;
1721
1722         if (!all_ports_stopped()) {
1723                 printf("Please stop all ports first\n");
1724                 return;
1725         }
1726         if (!strcmp(res->name, "rxq")) {
1727                 if (!res->value && !nb_txq) {
1728                         printf("Warning: Either rx or tx queues should be non zero\n");
1729                         return;
1730                 }
1731                 if (check_nb_rxq(res->value) != 0)
1732                         return;
1733                 nb_rxq = res->value;
1734         }
1735         else if (!strcmp(res->name, "txq")) {
1736                 if (!res->value && !nb_rxq) {
1737                         printf("Warning: Either rx or tx queues should be non zero\n");
1738                         return;
1739                 }
1740                 if (check_nb_txq(res->value) != 0)
1741                         return;
1742                 nb_txq = res->value;
1743         }
1744         else if (!strcmp(res->name, "rxd")) {
1745                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1746                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1747                                         res->value, RTE_TEST_RX_DESC_MAX);
1748                         return;
1749                 }
1750                 nb_rxd = res->value;
1751         } else if (!strcmp(res->name, "txd")) {
1752                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1753                         printf("txd %d invalid - must be > 0 && <= %d\n",
1754                                         res->value, RTE_TEST_TX_DESC_MAX);
1755                         return;
1756                 }
1757                 nb_txd = res->value;
1758         } else {
1759                 printf("Unknown parameter\n");
1760                 return;
1761         }
1762
1763         fwd_config_setup();
1764
1765         init_port_config();
1766
1767         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1768 }
1769
1770 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1771         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1772 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1773         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1774 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1775         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1776 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1777         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1778                                                 "rxq#txq#rxd#txd");
1779 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1780         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1781
1782 cmdline_parse_inst_t cmd_config_rx_tx = {
1783         .f = cmd_config_rx_tx_parsed,
1784         .data = NULL,
1785         .help_str = "port config all rxq|txq|rxd|txd <value>",
1786         .tokens = {
1787                 (void *)&cmd_config_rx_tx_port,
1788                 (void *)&cmd_config_rx_tx_keyword,
1789                 (void *)&cmd_config_rx_tx_all,
1790                 (void *)&cmd_config_rx_tx_name,
1791                 (void *)&cmd_config_rx_tx_value,
1792                 NULL,
1793         },
1794 };
1795
1796 /* *** config max packet length *** */
1797 struct cmd_config_max_pkt_len_result {
1798         cmdline_fixed_string_t port;
1799         cmdline_fixed_string_t keyword;
1800         cmdline_fixed_string_t all;
1801         cmdline_fixed_string_t name;
1802         uint32_t value;
1803 };
1804
1805 static void
1806 cmd_config_max_pkt_len_parsed(void *parsed_result,
1807                                 __attribute__((unused)) struct cmdline *cl,
1808                                 __attribute__((unused)) void *data)
1809 {
1810         struct cmd_config_max_pkt_len_result *res = parsed_result;
1811         portid_t pid;
1812
1813         if (!all_ports_stopped()) {
1814                 printf("Please stop all ports first\n");
1815                 return;
1816         }
1817
1818         RTE_ETH_FOREACH_DEV(pid) {
1819                 struct rte_port *port = &ports[pid];
1820                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1821
1822                 if (!strcmp(res->name, "max-pkt-len")) {
1823                         if (res->value < ETHER_MIN_LEN) {
1824                                 printf("max-pkt-len can not be less than %d\n",
1825                                                 ETHER_MIN_LEN);
1826                                 return;
1827                         }
1828                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1829                                 return;
1830
1831                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1832                         if (res->value > ETHER_MAX_LEN)
1833                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1834                         else
1835                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1836                         port->dev_conf.rxmode.offloads = rx_offloads;
1837                 } else {
1838                         printf("Unknown parameter\n");
1839                         return;
1840                 }
1841         }
1842
1843         init_port_config();
1844
1845         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1846 }
1847
1848 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1850                                                                 "port");
1851 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1853                                                                 "config");
1854 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1855         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1856                                                                 "all");
1857 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1858         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1859                                                                 "max-pkt-len");
1860 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1861         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1862                                                                 UINT32);
1863
1864 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1865         .f = cmd_config_max_pkt_len_parsed,
1866         .data = NULL,
1867         .help_str = "port config all max-pkt-len <value>",
1868         .tokens = {
1869                 (void *)&cmd_config_max_pkt_len_port,
1870                 (void *)&cmd_config_max_pkt_len_keyword,
1871                 (void *)&cmd_config_max_pkt_len_all,
1872                 (void *)&cmd_config_max_pkt_len_name,
1873                 (void *)&cmd_config_max_pkt_len_value,
1874                 NULL,
1875         },
1876 };
1877
1878 /* *** configure port MTU *** */
1879 struct cmd_config_mtu_result {
1880         cmdline_fixed_string_t port;
1881         cmdline_fixed_string_t keyword;
1882         cmdline_fixed_string_t mtu;
1883         portid_t port_id;
1884         uint16_t value;
1885 };
1886
1887 static void
1888 cmd_config_mtu_parsed(void *parsed_result,
1889                       __attribute__((unused)) struct cmdline *cl,
1890                       __attribute__((unused)) void *data)
1891 {
1892         struct cmd_config_mtu_result *res = parsed_result;
1893
1894         if (res->value < ETHER_MIN_LEN) {
1895                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1896                 return;
1897         }
1898         port_mtu_set(res->port_id, res->value);
1899 }
1900
1901 cmdline_parse_token_string_t cmd_config_mtu_port =
1902         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1903                                  "port");
1904 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1905         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1906                                  "config");
1907 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1908         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1909                                  "mtu");
1910 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1911         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1912 cmdline_parse_token_num_t cmd_config_mtu_value =
1913         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1914
1915 cmdline_parse_inst_t cmd_config_mtu = {
1916         .f = cmd_config_mtu_parsed,
1917         .data = NULL,
1918         .help_str = "port config mtu <port_id> <value>",
1919         .tokens = {
1920                 (void *)&cmd_config_mtu_port,
1921                 (void *)&cmd_config_mtu_keyword,
1922                 (void *)&cmd_config_mtu_mtu,
1923                 (void *)&cmd_config_mtu_port_id,
1924                 (void *)&cmd_config_mtu_value,
1925                 NULL,
1926         },
1927 };
1928
1929 /* *** configure rx mode *** */
1930 struct cmd_config_rx_mode_flag {
1931         cmdline_fixed_string_t port;
1932         cmdline_fixed_string_t keyword;
1933         cmdline_fixed_string_t all;
1934         cmdline_fixed_string_t name;
1935         cmdline_fixed_string_t value;
1936 };
1937
1938 static void
1939 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1940                                 __attribute__((unused)) struct cmdline *cl,
1941                                 __attribute__((unused)) void *data)
1942 {
1943         struct cmd_config_rx_mode_flag *res = parsed_result;
1944         portid_t pid;
1945
1946         if (!all_ports_stopped()) {
1947                 printf("Please stop all ports first\n");
1948                 return;
1949         }
1950
1951         RTE_ETH_FOREACH_DEV(pid) {
1952                 struct rte_port *port;
1953                 uint64_t rx_offloads;
1954
1955                 port = &ports[pid];
1956                 rx_offloads = port->dev_conf.rxmode.offloads;
1957                 if (!strcmp(res->name, "crc-strip")) {
1958                         if (!strcmp(res->value, "on")) {
1959                                 rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
1960                         } else if (!strcmp(res->value, "off")) {
1961                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
1962                         } else {
1963                                 printf("Unknown parameter\n");
1964                                 return;
1965                         }
1966                 } else if (!strcmp(res->name, "scatter")) {
1967                         if (!strcmp(res->value, "on")) {
1968                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1969                         } else if (!strcmp(res->value, "off")) {
1970                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1971                         } else {
1972                                 printf("Unknown parameter\n");
1973                                 return;
1974                         }
1975                 } else if (!strcmp(res->name, "rx-cksum")) {
1976                         if (!strcmp(res->value, "on"))
1977                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1978                         else if (!strcmp(res->value, "off"))
1979                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1980                         else {
1981                                 printf("Unknown parameter\n");
1982                                 return;
1983                         }
1984                 } else if (!strcmp(res->name, "rx-timestamp")) {
1985                         if (!strcmp(res->value, "on"))
1986                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1987                         else if (!strcmp(res->value, "off"))
1988                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1989                         else {
1990                                 printf("Unknown parameter\n");
1991                                 return;
1992                         }
1993                 } else if (!strcmp(res->name, "hw-vlan")) {
1994                         if (!strcmp(res->value, "on")) {
1995                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1996                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1997                         } else if (!strcmp(res->value, "off")) {
1998                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1999                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2000                         } else {
2001                                 printf("Unknown parameter\n");
2002                                 return;
2003                         }
2004                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
2005                         if (!strcmp(res->value, "on"))
2006                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2007                         else if (!strcmp(res->value, "off"))
2008                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2009                         else {
2010                                 printf("Unknown parameter\n");
2011                                 return;
2012                         }
2013                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
2014                         if (!strcmp(res->value, "on"))
2015                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2016                         else if (!strcmp(res->value, "off"))
2017                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2018                         else {
2019                                 printf("Unknown parameter\n");
2020                                 return;
2021                         }
2022                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
2023                         if (!strcmp(res->value, "on"))
2024                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2025                         else if (!strcmp(res->value, "off"))
2026                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2027                         else {
2028                                 printf("Unknown parameter\n");
2029                                 return;
2030                         }
2031                 } else if (!strcmp(res->name, "drop-en")) {
2032                         if (!strcmp(res->value, "on"))
2033                                 rx_drop_en = 1;
2034                         else if (!strcmp(res->value, "off"))
2035                                 rx_drop_en = 0;
2036                         else {
2037                                 printf("Unknown parameter\n");
2038                                 return;
2039                         }
2040                 } else {
2041                         printf("Unknown parameter\n");
2042                         return;
2043                 }
2044                 port->dev_conf.rxmode.offloads = rx_offloads;
2045         }
2046
2047         init_port_config();
2048
2049         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2050 }
2051
2052 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2053         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2054 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2055         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2056                                                                 "config");
2057 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2058         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2059 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2060         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2061                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2062                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2063 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2064         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2065                                                         "on#off");
2066
2067 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2068         .f = cmd_config_rx_mode_flag_parsed,
2069         .data = NULL,
2070         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2071                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2072         .tokens = {
2073                 (void *)&cmd_config_rx_mode_flag_port,
2074                 (void *)&cmd_config_rx_mode_flag_keyword,
2075                 (void *)&cmd_config_rx_mode_flag_all,
2076                 (void *)&cmd_config_rx_mode_flag_name,
2077                 (void *)&cmd_config_rx_mode_flag_value,
2078                 NULL,
2079         },
2080 };
2081
2082 /* *** configure rss *** */
2083 struct cmd_config_rss {
2084         cmdline_fixed_string_t port;
2085         cmdline_fixed_string_t keyword;
2086         cmdline_fixed_string_t all;
2087         cmdline_fixed_string_t name;
2088         cmdline_fixed_string_t value;
2089 };
2090
2091 static void
2092 cmd_config_rss_parsed(void *parsed_result,
2093                         __attribute__((unused)) struct cmdline *cl,
2094                         __attribute__((unused)) void *data)
2095 {
2096         struct cmd_config_rss *res = parsed_result;
2097         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2098         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2099         int use_default = 0;
2100         int all_updated = 1;
2101         int diag;
2102         uint16_t i;
2103
2104         if (!strcmp(res->value, "all"))
2105                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2106                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2107                                         ETH_RSS_L2_PAYLOAD;
2108         else if (!strcmp(res->value, "ip"))
2109                 rss_conf.rss_hf = ETH_RSS_IP;
2110         else if (!strcmp(res->value, "udp"))
2111                 rss_conf.rss_hf = ETH_RSS_UDP;
2112         else if (!strcmp(res->value, "tcp"))
2113                 rss_conf.rss_hf = ETH_RSS_TCP;
2114         else if (!strcmp(res->value, "sctp"))
2115                 rss_conf.rss_hf = ETH_RSS_SCTP;
2116         else if (!strcmp(res->value, "ether"))
2117                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2118         else if (!strcmp(res->value, "port"))
2119                 rss_conf.rss_hf = ETH_RSS_PORT;
2120         else if (!strcmp(res->value, "vxlan"))
2121                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2122         else if (!strcmp(res->value, "geneve"))
2123                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2124         else if (!strcmp(res->value, "nvgre"))
2125                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2126         else if (!strcmp(res->value, "none"))
2127                 rss_conf.rss_hf = 0;
2128         else if (!strcmp(res->value, "default"))
2129                 use_default = 1;
2130         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2131                                                 atoi(res->value) < 64)
2132                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2133         else {
2134                 printf("Unknown parameter\n");
2135                 return;
2136         }
2137         rss_conf.rss_key = NULL;
2138         /* Update global configuration for RSS types. */
2139         RTE_ETH_FOREACH_DEV(i) {
2140                 struct rte_eth_rss_conf local_rss_conf;
2141
2142                 rte_eth_dev_info_get(i, &dev_info);
2143                 if (use_default)
2144                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2145
2146                 local_rss_conf = rss_conf;
2147                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2148                         dev_info.flow_type_rss_offloads;
2149                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2150                         printf("Port %u modified RSS hash function based on hardware support,"
2151                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2152                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2153                 }
2154                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2155                 if (diag < 0) {
2156                         all_updated = 0;
2157                         printf("Configuration of RSS hash at ethernet port %d "
2158                                 "failed with error (%d): %s.\n",
2159                                 i, -diag, strerror(-diag));
2160                 }
2161         }
2162         if (all_updated && !use_default)
2163                 rss_hf = rss_conf.rss_hf;
2164 }
2165
2166 cmdline_parse_token_string_t cmd_config_rss_port =
2167         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2168 cmdline_parse_token_string_t cmd_config_rss_keyword =
2169         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2170 cmdline_parse_token_string_t cmd_config_rss_all =
2171         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2172 cmdline_parse_token_string_t cmd_config_rss_name =
2173         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2174 cmdline_parse_token_string_t cmd_config_rss_value =
2175         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2176
2177 cmdline_parse_inst_t cmd_config_rss = {
2178         .f = cmd_config_rss_parsed,
2179         .data = NULL,
2180         .help_str = "port config all rss "
2181                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2182         .tokens = {
2183                 (void *)&cmd_config_rss_port,
2184                 (void *)&cmd_config_rss_keyword,
2185                 (void *)&cmd_config_rss_all,
2186                 (void *)&cmd_config_rss_name,
2187                 (void *)&cmd_config_rss_value,
2188                 NULL,
2189         },
2190 };
2191
2192 /* *** configure rss hash key *** */
2193 struct cmd_config_rss_hash_key {
2194         cmdline_fixed_string_t port;
2195         cmdline_fixed_string_t config;
2196         portid_t port_id;
2197         cmdline_fixed_string_t rss_hash_key;
2198         cmdline_fixed_string_t rss_type;
2199         cmdline_fixed_string_t key;
2200 };
2201
2202 static uint8_t
2203 hexa_digit_to_value(char hexa_digit)
2204 {
2205         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2206                 return (uint8_t) (hexa_digit - '0');
2207         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2208                 return (uint8_t) ((hexa_digit - 'a') + 10);
2209         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2210                 return (uint8_t) ((hexa_digit - 'A') + 10);
2211         /* Invalid hexa digit */
2212         return 0xFF;
2213 }
2214
2215 static uint8_t
2216 parse_and_check_key_hexa_digit(char *key, int idx)
2217 {
2218         uint8_t hexa_v;
2219
2220         hexa_v = hexa_digit_to_value(key[idx]);
2221         if (hexa_v == 0xFF)
2222                 printf("invalid key: character %c at position %d is not a "
2223                        "valid hexa digit\n", key[idx], idx);
2224         return hexa_v;
2225 }
2226
2227 static void
2228 cmd_config_rss_hash_key_parsed(void *parsed_result,
2229                                __attribute__((unused)) struct cmdline *cl,
2230                                __attribute__((unused)) void *data)
2231 {
2232         struct cmd_config_rss_hash_key *res = parsed_result;
2233         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2234         uint8_t xdgt0;
2235         uint8_t xdgt1;
2236         int i;
2237         struct rte_eth_dev_info dev_info;
2238         uint8_t hash_key_size;
2239         uint32_t key_len;
2240
2241         memset(&dev_info, 0, sizeof(dev_info));
2242         rte_eth_dev_info_get(res->port_id, &dev_info);
2243         if (dev_info.hash_key_size > 0 &&
2244                         dev_info.hash_key_size <= sizeof(hash_key))
2245                 hash_key_size = dev_info.hash_key_size;
2246         else {
2247                 printf("dev_info did not provide a valid hash key size\n");
2248                 return;
2249         }
2250         /* Check the length of the RSS hash key */
2251         key_len = strlen(res->key);
2252         if (key_len != (hash_key_size * 2)) {
2253                 printf("key length: %d invalid - key must be a string of %d"
2254                            " hexa-decimal numbers\n",
2255                            (int) key_len, hash_key_size * 2);
2256                 return;
2257         }
2258         /* Translate RSS hash key into binary representation */
2259         for (i = 0; i < hash_key_size; i++) {
2260                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2261                 if (xdgt0 == 0xFF)
2262                         return;
2263                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2264                 if (xdgt1 == 0xFF)
2265                         return;
2266                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2267         }
2268         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2269                         hash_key_size);
2270 }
2271
2272 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2273         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2274 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2275         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2276                                  "config");
2277 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2278         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2279 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2280         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2281                                  rss_hash_key, "rss-hash-key");
2282 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2283         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2284                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2285                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2286                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2287                                  "ipv6-tcp-ex#ipv6-udp-ex");
2288 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2289         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2290
2291 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2292         .f = cmd_config_rss_hash_key_parsed,
2293         .data = NULL,
2294         .help_str = "port config <port_id> rss-hash-key "
2295                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2296                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2297                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2298                 "<string of hex digits (variable length, NIC dependent)>",
2299         .tokens = {
2300                 (void *)&cmd_config_rss_hash_key_port,
2301                 (void *)&cmd_config_rss_hash_key_config,
2302                 (void *)&cmd_config_rss_hash_key_port_id,
2303                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2304                 (void *)&cmd_config_rss_hash_key_rss_type,
2305                 (void *)&cmd_config_rss_hash_key_value,
2306                 NULL,
2307         },
2308 };
2309
2310 /* *** configure port rxq/txq ring size *** */
2311 struct cmd_config_rxtx_ring_size {
2312         cmdline_fixed_string_t port;
2313         cmdline_fixed_string_t config;
2314         portid_t portid;
2315         cmdline_fixed_string_t rxtxq;
2316         uint16_t qid;
2317         cmdline_fixed_string_t rsize;
2318         uint16_t size;
2319 };
2320
2321 static void
2322 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2323                                  __attribute__((unused)) struct cmdline *cl,
2324                                  __attribute__((unused)) void *data)
2325 {
2326         struct cmd_config_rxtx_ring_size *res = parsed_result;
2327         struct rte_port *port;
2328         uint8_t isrx;
2329
2330         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2331                 return;
2332
2333         if (res->portid == (portid_t)RTE_PORT_ALL) {
2334                 printf("Invalid port id\n");
2335                 return;
2336         }
2337
2338         port = &ports[res->portid];
2339
2340         if (!strcmp(res->rxtxq, "rxq"))
2341                 isrx = 1;
2342         else if (!strcmp(res->rxtxq, "txq"))
2343                 isrx = 0;
2344         else {
2345                 printf("Unknown parameter\n");
2346                 return;
2347         }
2348
2349         if (isrx && rx_queue_id_is_invalid(res->qid))
2350                 return;
2351         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2352                 return;
2353
2354         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2355                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2356                        rx_free_thresh);
2357                 return;
2358         }
2359
2360         if (isrx)
2361                 port->nb_rx_desc[res->qid] = res->size;
2362         else
2363                 port->nb_tx_desc[res->qid] = res->size;
2364
2365         cmd_reconfig_device_queue(res->portid, 0, 1);
2366 }
2367
2368 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2369         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2370                                  port, "port");
2371 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2372         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2373                                  config, "config");
2374 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2375         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2376                                  portid, UINT16);
2377 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2378         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2379                                  rxtxq, "rxq#txq");
2380 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2381         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2382                               qid, UINT16);
2383 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2384         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2385                                  rsize, "ring_size");
2386 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2387         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2388                               size, UINT16);
2389
2390 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2391         .f = cmd_config_rxtx_ring_size_parsed,
2392         .data = NULL,
2393         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2394         .tokens = {
2395                 (void *)&cmd_config_rxtx_ring_size_port,
2396                 (void *)&cmd_config_rxtx_ring_size_config,
2397                 (void *)&cmd_config_rxtx_ring_size_portid,
2398                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2399                 (void *)&cmd_config_rxtx_ring_size_qid,
2400                 (void *)&cmd_config_rxtx_ring_size_rsize,
2401                 (void *)&cmd_config_rxtx_ring_size_size,
2402                 NULL,
2403         },
2404 };
2405
2406 /* *** configure port rxq/txq start/stop *** */
2407 struct cmd_config_rxtx_queue {
2408         cmdline_fixed_string_t port;
2409         portid_t portid;
2410         cmdline_fixed_string_t rxtxq;
2411         uint16_t qid;
2412         cmdline_fixed_string_t opname;
2413 };
2414
2415 static void
2416 cmd_config_rxtx_queue_parsed(void *parsed_result,
2417                         __attribute__((unused)) struct cmdline *cl,
2418                         __attribute__((unused)) void *data)
2419 {
2420         struct cmd_config_rxtx_queue *res = parsed_result;
2421         uint8_t isrx;
2422         uint8_t isstart;
2423         int ret = 0;
2424
2425         if (test_done == 0) {
2426                 printf("Please stop forwarding first\n");
2427                 return;
2428         }
2429
2430         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2431                 return;
2432
2433         if (port_is_started(res->portid) != 1) {
2434                 printf("Please start port %u first\n", res->portid);
2435                 return;
2436         }
2437
2438         if (!strcmp(res->rxtxq, "rxq"))
2439                 isrx = 1;
2440         else if (!strcmp(res->rxtxq, "txq"))
2441                 isrx = 0;
2442         else {
2443                 printf("Unknown parameter\n");
2444                 return;
2445         }
2446
2447         if (isrx && rx_queue_id_is_invalid(res->qid))
2448                 return;
2449         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2450                 return;
2451
2452         if (!strcmp(res->opname, "start"))
2453                 isstart = 1;
2454         else if (!strcmp(res->opname, "stop"))
2455                 isstart = 0;
2456         else {
2457                 printf("Unknown parameter\n");
2458                 return;
2459         }
2460
2461         if (isstart && isrx)
2462                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2463         else if (!isstart && isrx)
2464                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2465         else if (isstart && !isrx)
2466                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2467         else
2468                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2469
2470         if (ret == -ENOTSUP)
2471                 printf("Function not supported in PMD driver\n");
2472 }
2473
2474 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2475         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2476 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2477         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2478 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2479         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2480 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2481         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2482 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2483         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2484                                                 "start#stop");
2485
2486 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2487         .f = cmd_config_rxtx_queue_parsed,
2488         .data = NULL,
2489         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2490         .tokens = {
2491                 (void *)&cmd_config_rxtx_queue_port,
2492                 (void *)&cmd_config_rxtx_queue_portid,
2493                 (void *)&cmd_config_rxtx_queue_rxtxq,
2494                 (void *)&cmd_config_rxtx_queue_qid,
2495                 (void *)&cmd_config_rxtx_queue_opname,
2496                 NULL,
2497         },
2498 };
2499
2500 /* *** configure port rxq/txq deferred start on/off *** */
2501 struct cmd_config_deferred_start_rxtx_queue {
2502         cmdline_fixed_string_t port;
2503         portid_t port_id;
2504         cmdline_fixed_string_t rxtxq;
2505         uint16_t qid;
2506         cmdline_fixed_string_t opname;
2507         cmdline_fixed_string_t state;
2508 };
2509
2510 static void
2511 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2512                         __attribute__((unused)) struct cmdline *cl,
2513                         __attribute__((unused)) void *data)
2514 {
2515         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2516         struct rte_port *port;
2517         uint8_t isrx;
2518         uint8_t ison;
2519         uint8_t needreconfig = 0;
2520
2521         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2522                 return;
2523
2524         if (port_is_started(res->port_id) != 0) {
2525                 printf("Please stop port %u first\n", res->port_id);
2526                 return;
2527         }
2528
2529         port = &ports[res->port_id];
2530
2531         isrx = !strcmp(res->rxtxq, "rxq");
2532
2533         if (isrx && rx_queue_id_is_invalid(res->qid))
2534                 return;
2535         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2536                 return;
2537
2538         ison = !strcmp(res->state, "on");
2539
2540         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2541                 port->rx_conf[res->qid].rx_deferred_start = ison;
2542                 needreconfig = 1;
2543         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2544                 port->tx_conf[res->qid].tx_deferred_start = ison;
2545                 needreconfig = 1;
2546         }
2547
2548         if (needreconfig)
2549                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2550 }
2551
2552 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2553         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2554                                                 port, "port");
2555 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2556         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2557                                                 port_id, UINT16);
2558 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2559         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2560                                                 rxtxq, "rxq#txq");
2561 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2562         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2563                                                 qid, UINT16);
2564 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2565         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2566                                                 opname, "deferred_start");
2567 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2568         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2569                                                 state, "on#off");
2570
2571 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2572         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2573         .data = NULL,
2574         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2575         .tokens = {
2576                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2577                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2578                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2579                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2580                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2581                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2582                 NULL,
2583         },
2584 };
2585
2586 /* *** configure port rxq/txq setup *** */
2587 struct cmd_setup_rxtx_queue {
2588         cmdline_fixed_string_t port;
2589         portid_t portid;
2590         cmdline_fixed_string_t rxtxq;
2591         uint16_t qid;
2592         cmdline_fixed_string_t setup;
2593 };
2594
2595 /* Common CLI fields for queue setup */
2596 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2597         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2598 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2599         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2600 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2601         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2602 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2603         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2604 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2605         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2606
2607 static void
2608 cmd_setup_rxtx_queue_parsed(
2609         void *parsed_result,
2610         __attribute__((unused)) struct cmdline *cl,
2611         __attribute__((unused)) void *data)
2612 {
2613         struct cmd_setup_rxtx_queue *res = parsed_result;
2614         struct rte_port *port;
2615         struct rte_mempool *mp;
2616         unsigned int socket_id;
2617         uint8_t isrx = 0;
2618         int ret;
2619
2620         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2621                 return;
2622
2623         if (res->portid == (portid_t)RTE_PORT_ALL) {
2624                 printf("Invalid port id\n");
2625                 return;
2626         }
2627
2628         if (!strcmp(res->rxtxq, "rxq"))
2629                 isrx = 1;
2630         else if (!strcmp(res->rxtxq, "txq"))
2631                 isrx = 0;
2632         else {
2633                 printf("Unknown parameter\n");
2634                 return;
2635         }
2636
2637         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2638                 printf("Invalid rx queue\n");
2639                 return;
2640         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2641                 printf("Invalid tx queue\n");
2642                 return;
2643         }
2644
2645         port = &ports[res->portid];
2646         if (isrx) {
2647                 socket_id = rxring_numa[res->portid];
2648                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2649                         socket_id = port->socket_id;
2650
2651                 mp = mbuf_pool_find(socket_id);
2652                 if (mp == NULL) {
2653                         printf("Failed to setup RX queue: "
2654                                 "No mempool allocation"
2655                                 " on the socket %d\n",
2656                                 rxring_numa[res->portid]);
2657                         return;
2658                 }
2659                 ret = rte_eth_rx_queue_setup(res->portid,
2660                                              res->qid,
2661                                              port->nb_rx_desc[res->qid],
2662                                              socket_id,
2663                                              &port->rx_conf[res->qid],
2664                                              mp);
2665                 if (ret)
2666                         printf("Failed to setup RX queue\n");
2667         } else {
2668                 socket_id = txring_numa[res->portid];
2669                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2670                         socket_id = port->socket_id;
2671
2672                 ret = rte_eth_tx_queue_setup(res->portid,
2673                                              res->qid,
2674                                              port->nb_tx_desc[res->qid],
2675                                              socket_id,
2676                                              &port->tx_conf[res->qid]);
2677                 if (ret)
2678                         printf("Failed to setup TX queue\n");
2679         }
2680 }
2681
2682 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2683         .f = cmd_setup_rxtx_queue_parsed,
2684         .data = NULL,
2685         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2686         .tokens = {
2687                 (void *)&cmd_setup_rxtx_queue_port,
2688                 (void *)&cmd_setup_rxtx_queue_portid,
2689                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2690                 (void *)&cmd_setup_rxtx_queue_qid,
2691                 (void *)&cmd_setup_rxtx_queue_setup,
2692                 NULL,
2693         },
2694 };
2695
2696
2697 /* *** Configure RSS RETA *** */
2698 struct cmd_config_rss_reta {
2699         cmdline_fixed_string_t port;
2700         cmdline_fixed_string_t keyword;
2701         portid_t port_id;
2702         cmdline_fixed_string_t name;
2703         cmdline_fixed_string_t list_name;
2704         cmdline_fixed_string_t list_of_items;
2705 };
2706
2707 static int
2708 parse_reta_config(const char *str,
2709                   struct rte_eth_rss_reta_entry64 *reta_conf,
2710                   uint16_t nb_entries)
2711 {
2712         int i;
2713         unsigned size;
2714         uint16_t hash_index, idx, shift;
2715         uint16_t nb_queue;
2716         char s[256];
2717         const char *p, *p0 = str;
2718         char *end;
2719         enum fieldnames {
2720                 FLD_HASH_INDEX = 0,
2721                 FLD_QUEUE,
2722                 _NUM_FLD
2723         };
2724         unsigned long int_fld[_NUM_FLD];
2725         char *str_fld[_NUM_FLD];
2726
2727         while ((p = strchr(p0,'(')) != NULL) {
2728                 ++p;
2729                 if((p0 = strchr(p,')')) == NULL)
2730                         return -1;
2731
2732                 size = p0 - p;
2733                 if(size >= sizeof(s))
2734                         return -1;
2735
2736                 snprintf(s, sizeof(s), "%.*s", size, p);
2737                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2738                         return -1;
2739                 for (i = 0; i < _NUM_FLD; i++) {
2740                         errno = 0;
2741                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2742                         if (errno != 0 || end == str_fld[i] ||
2743                                         int_fld[i] > 65535)
2744                                 return -1;
2745                 }
2746
2747                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2748                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2749
2750                 if (hash_index >= nb_entries) {
2751                         printf("Invalid RETA hash index=%d\n", hash_index);
2752                         return -1;
2753                 }
2754
2755                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2756                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2757                 reta_conf[idx].mask |= (1ULL << shift);
2758                 reta_conf[idx].reta[shift] = nb_queue;
2759         }
2760
2761         return 0;
2762 }
2763
2764 static void
2765 cmd_set_rss_reta_parsed(void *parsed_result,
2766                         __attribute__((unused)) struct cmdline *cl,
2767                         __attribute__((unused)) void *data)
2768 {
2769         int ret;
2770         struct rte_eth_dev_info dev_info;
2771         struct rte_eth_rss_reta_entry64 reta_conf[8];
2772         struct cmd_config_rss_reta *res = parsed_result;
2773
2774         memset(&dev_info, 0, sizeof(dev_info));
2775         rte_eth_dev_info_get(res->port_id, &dev_info);
2776         if (dev_info.reta_size == 0) {
2777                 printf("Redirection table size is 0 which is "
2778                                         "invalid for RSS\n");
2779                 return;
2780         } else
2781                 printf("The reta size of port %d is %u\n",
2782                         res->port_id, dev_info.reta_size);
2783         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2784                 printf("Currently do not support more than %u entries of "
2785                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2786                 return;
2787         }
2788
2789         memset(reta_conf, 0, sizeof(reta_conf));
2790         if (!strcmp(res->list_name, "reta")) {
2791                 if (parse_reta_config(res->list_of_items, reta_conf,
2792                                                 dev_info.reta_size)) {
2793                         printf("Invalid RSS Redirection Table "
2794                                         "config entered\n");
2795                         return;
2796                 }
2797                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2798                                 reta_conf, dev_info.reta_size);
2799                 if (ret != 0)
2800                         printf("Bad redirection table parameter, "
2801                                         "return code = %d \n", ret);
2802         }
2803 }
2804
2805 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2806         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2807 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2808         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2809 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2810         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2811 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2812         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2813 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2814         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2815 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2816         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2817                                  NULL);
2818 cmdline_parse_inst_t cmd_config_rss_reta = {
2819         .f = cmd_set_rss_reta_parsed,
2820         .data = NULL,
2821         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2822         .tokens = {
2823                 (void *)&cmd_config_rss_reta_port,
2824                 (void *)&cmd_config_rss_reta_keyword,
2825                 (void *)&cmd_config_rss_reta_port_id,
2826                 (void *)&cmd_config_rss_reta_name,
2827                 (void *)&cmd_config_rss_reta_list_name,
2828                 (void *)&cmd_config_rss_reta_list_of_items,
2829                 NULL,
2830         },
2831 };
2832
2833 /* *** SHOW PORT RETA INFO *** */
2834 struct cmd_showport_reta {
2835         cmdline_fixed_string_t show;
2836         cmdline_fixed_string_t port;
2837         portid_t port_id;
2838         cmdline_fixed_string_t rss;
2839         cmdline_fixed_string_t reta;
2840         uint16_t size;
2841         cmdline_fixed_string_t list_of_items;
2842 };
2843
2844 static int
2845 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2846                            uint16_t nb_entries,
2847                            char *str)
2848 {
2849         uint32_t size;
2850         const char *p, *p0 = str;
2851         char s[256];
2852         char *end;
2853         char *str_fld[8];
2854         uint16_t i;
2855         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2856                         RTE_RETA_GROUP_SIZE;
2857         int ret;
2858
2859         p = strchr(p0, '(');
2860         if (p == NULL)
2861                 return -1;
2862         p++;
2863         p0 = strchr(p, ')');
2864         if (p0 == NULL)
2865                 return -1;
2866         size = p0 - p;
2867         if (size >= sizeof(s)) {
2868                 printf("The string size exceeds the internal buffer size\n");
2869                 return -1;
2870         }
2871         snprintf(s, sizeof(s), "%.*s", size, p);
2872         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2873         if (ret <= 0 || ret != num) {
2874                 printf("The bits of masks do not match the number of "
2875                                         "reta entries: %u\n", num);
2876                 return -1;
2877         }
2878         for (i = 0; i < ret; i++)
2879                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2880
2881         return 0;
2882 }
2883
2884 static void
2885 cmd_showport_reta_parsed(void *parsed_result,
2886                          __attribute__((unused)) struct cmdline *cl,
2887                          __attribute__((unused)) void *data)
2888 {
2889         struct cmd_showport_reta *res = parsed_result;
2890         struct rte_eth_rss_reta_entry64 reta_conf[8];
2891         struct rte_eth_dev_info dev_info;
2892         uint16_t max_reta_size;
2893
2894         memset(&dev_info, 0, sizeof(dev_info));
2895         rte_eth_dev_info_get(res->port_id, &dev_info);
2896         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2897         if (res->size == 0 || res->size > max_reta_size) {
2898                 printf("Invalid redirection table size: %u (1-%u)\n",
2899                         res->size, max_reta_size);
2900                 return;
2901         }
2902
2903         memset(reta_conf, 0, sizeof(reta_conf));
2904         if (showport_parse_reta_config(reta_conf, res->size,
2905                                 res->list_of_items) < 0) {
2906                 printf("Invalid string: %s for reta masks\n",
2907                                         res->list_of_items);
2908                 return;
2909         }
2910         port_rss_reta_info(res->port_id, reta_conf, res->size);
2911 }
2912
2913 cmdline_parse_token_string_t cmd_showport_reta_show =
2914         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2915 cmdline_parse_token_string_t cmd_showport_reta_port =
2916         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2917 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2918         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2919 cmdline_parse_token_string_t cmd_showport_reta_rss =
2920         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2921 cmdline_parse_token_string_t cmd_showport_reta_reta =
2922         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2923 cmdline_parse_token_num_t cmd_showport_reta_size =
2924         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2925 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2926         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2927                                         list_of_items, NULL);
2928
2929 cmdline_parse_inst_t cmd_showport_reta = {
2930         .f = cmd_showport_reta_parsed,
2931         .data = NULL,
2932         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2933         .tokens = {
2934                 (void *)&cmd_showport_reta_show,
2935                 (void *)&cmd_showport_reta_port,
2936                 (void *)&cmd_showport_reta_port_id,
2937                 (void *)&cmd_showport_reta_rss,
2938                 (void *)&cmd_showport_reta_reta,
2939                 (void *)&cmd_showport_reta_size,
2940                 (void *)&cmd_showport_reta_list_of_items,
2941                 NULL,
2942         },
2943 };
2944
2945 /* *** Show RSS hash configuration *** */
2946 struct cmd_showport_rss_hash {
2947         cmdline_fixed_string_t show;
2948         cmdline_fixed_string_t port;
2949         portid_t port_id;
2950         cmdline_fixed_string_t rss_hash;
2951         cmdline_fixed_string_t rss_type;
2952         cmdline_fixed_string_t key; /* optional argument */
2953 };
2954
2955 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2956                                 __attribute__((unused)) struct cmdline *cl,
2957                                 void *show_rss_key)
2958 {
2959         struct cmd_showport_rss_hash *res = parsed_result;
2960
2961         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
2962 }
2963
2964 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2965         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2966 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2967         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2968 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2969         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2970 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2971         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2972                                  "rss-hash");
2973 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2974         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2975
2976 cmdline_parse_inst_t cmd_showport_rss_hash = {
2977         .f = cmd_showport_rss_hash_parsed,
2978         .data = NULL,
2979         .help_str = "show port <port_id> rss-hash",
2980         .tokens = {
2981                 (void *)&cmd_showport_rss_hash_show,
2982                 (void *)&cmd_showport_rss_hash_port,
2983                 (void *)&cmd_showport_rss_hash_port_id,
2984                 (void *)&cmd_showport_rss_hash_rss_hash,
2985                 NULL,
2986         },
2987 };
2988
2989 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2990         .f = cmd_showport_rss_hash_parsed,
2991         .data = (void *)1,
2992         .help_str = "show port <port_id> rss-hash key",
2993         .tokens = {
2994                 (void *)&cmd_showport_rss_hash_show,
2995                 (void *)&cmd_showport_rss_hash_port,
2996                 (void *)&cmd_showport_rss_hash_port_id,
2997                 (void *)&cmd_showport_rss_hash_rss_hash,
2998                 (void *)&cmd_showport_rss_hash_rss_key,
2999                 NULL,
3000         },
3001 };
3002
3003 /* *** Configure DCB *** */
3004 struct cmd_config_dcb {
3005         cmdline_fixed_string_t port;
3006         cmdline_fixed_string_t config;
3007         portid_t port_id;
3008         cmdline_fixed_string_t dcb;
3009         cmdline_fixed_string_t vt;
3010         cmdline_fixed_string_t vt_en;
3011         uint8_t num_tcs;
3012         cmdline_fixed_string_t pfc;
3013         cmdline_fixed_string_t pfc_en;
3014 };
3015
3016 static void
3017 cmd_config_dcb_parsed(void *parsed_result,
3018                         __attribute__((unused)) struct cmdline *cl,
3019                         __attribute__((unused)) void *data)
3020 {
3021         struct cmd_config_dcb *res = parsed_result;
3022         portid_t port_id = res->port_id;
3023         struct rte_port *port;
3024         uint8_t pfc_en;
3025         int ret;
3026
3027         port = &ports[port_id];
3028         /** Check if the port is not started **/
3029         if (port->port_status != RTE_PORT_STOPPED) {
3030                 printf("Please stop port %d first\n", port_id);
3031                 return;
3032         }
3033
3034         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3035                 printf("The invalid number of traffic class,"
3036                         " only 4 or 8 allowed.\n");
3037                 return;
3038         }
3039
3040         if (nb_fwd_lcores < res->num_tcs) {
3041                 printf("nb_cores shouldn't be less than number of TCs.\n");
3042                 return;
3043         }
3044         if (!strncmp(res->pfc_en, "on", 2))
3045                 pfc_en = 1;
3046         else
3047                 pfc_en = 0;
3048
3049         /* DCB in VT mode */
3050         if (!strncmp(res->vt_en, "on", 2))
3051                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3052                                 (enum rte_eth_nb_tcs)res->num_tcs,
3053                                 pfc_en);
3054         else
3055                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3056                                 (enum rte_eth_nb_tcs)res->num_tcs,
3057                                 pfc_en);
3058
3059
3060         if (ret != 0) {
3061                 printf("Cannot initialize network ports.\n");
3062                 return;
3063         }
3064
3065         cmd_reconfig_device_queue(port_id, 1, 1);
3066 }
3067
3068 cmdline_parse_token_string_t cmd_config_dcb_port =
3069         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3070 cmdline_parse_token_string_t cmd_config_dcb_config =
3071         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3072 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3073         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3074 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3075         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3076 cmdline_parse_token_string_t cmd_config_dcb_vt =
3077         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3078 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3079         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3080 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3081         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3082 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3083         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3084 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3085         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3086
3087 cmdline_parse_inst_t cmd_config_dcb = {
3088         .f = cmd_config_dcb_parsed,
3089         .data = NULL,
3090         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3091         .tokens = {
3092                 (void *)&cmd_config_dcb_port,
3093                 (void *)&cmd_config_dcb_config,
3094                 (void *)&cmd_config_dcb_port_id,
3095                 (void *)&cmd_config_dcb_dcb,
3096                 (void *)&cmd_config_dcb_vt,
3097                 (void *)&cmd_config_dcb_vt_en,
3098                 (void *)&cmd_config_dcb_num_tcs,
3099                 (void *)&cmd_config_dcb_pfc,
3100                 (void *)&cmd_config_dcb_pfc_en,
3101                 NULL,
3102         },
3103 };
3104
3105 /* *** configure number of packets per burst *** */
3106 struct cmd_config_burst {
3107         cmdline_fixed_string_t port;
3108         cmdline_fixed_string_t keyword;
3109         cmdline_fixed_string_t all;
3110         cmdline_fixed_string_t name;
3111         uint16_t value;
3112 };
3113
3114 static void
3115 cmd_config_burst_parsed(void *parsed_result,
3116                         __attribute__((unused)) struct cmdline *cl,
3117                         __attribute__((unused)) void *data)
3118 {
3119         struct cmd_config_burst *res = parsed_result;
3120         struct rte_eth_dev_info dev_info;
3121         uint16_t rec_nb_pkts;
3122
3123         if (!all_ports_stopped()) {
3124                 printf("Please stop all ports first\n");
3125                 return;
3126         }
3127
3128         if (!strcmp(res->name, "burst")) {
3129                 if (res->value == 0) {
3130                         /* If user gives a value of zero, query the PMD for
3131                          * its recommended Rx burst size. Testpmd uses a single
3132                          * size for all ports, so assume all ports are the same
3133                          * NIC model and use the values from Port 0.
3134                          */
3135                         rte_eth_dev_info_get(0, &dev_info);
3136                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3137
3138                         if (rec_nb_pkts == 0) {
3139                                 printf("PMD does not recommend a burst size.\n"
3140                                         "User provided value must be between"
3141                                         " 1 and %d\n", MAX_PKT_BURST);
3142                                 return;
3143                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3144                                 printf("PMD recommended burst size of %d"
3145                                         " exceeds maximum value of %d\n",
3146                                         rec_nb_pkts, MAX_PKT_BURST);
3147                                 return;
3148                         }
3149                         printf("Using PMD-provided burst value of %d\n",
3150                                 rec_nb_pkts);
3151                         nb_pkt_per_burst = rec_nb_pkts;
3152                 } else if (res->value > MAX_PKT_BURST) {
3153                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3154                         return;
3155                 } else
3156                         nb_pkt_per_burst = res->value;
3157         } else {
3158                 printf("Unknown parameter\n");
3159                 return;
3160         }
3161
3162         init_port_config();
3163
3164         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3165 }
3166
3167 cmdline_parse_token_string_t cmd_config_burst_port =
3168         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3169 cmdline_parse_token_string_t cmd_config_burst_keyword =
3170         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3171 cmdline_parse_token_string_t cmd_config_burst_all =
3172         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3173 cmdline_parse_token_string_t cmd_config_burst_name =
3174         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3175 cmdline_parse_token_num_t cmd_config_burst_value =
3176         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3177
3178 cmdline_parse_inst_t cmd_config_burst = {
3179         .f = cmd_config_burst_parsed,
3180         .data = NULL,
3181         .help_str = "port config all burst <value>",
3182         .tokens = {
3183                 (void *)&cmd_config_burst_port,
3184                 (void *)&cmd_config_burst_keyword,
3185                 (void *)&cmd_config_burst_all,
3186                 (void *)&cmd_config_burst_name,
3187                 (void *)&cmd_config_burst_value,
3188                 NULL,
3189         },
3190 };
3191
3192 /* *** configure rx/tx queues *** */
3193 struct cmd_config_thresh {
3194         cmdline_fixed_string_t port;
3195         cmdline_fixed_string_t keyword;
3196         cmdline_fixed_string_t all;
3197         cmdline_fixed_string_t name;
3198         uint8_t value;
3199 };
3200
3201 static void
3202 cmd_config_thresh_parsed(void *parsed_result,
3203                         __attribute__((unused)) struct cmdline *cl,
3204                         __attribute__((unused)) void *data)
3205 {
3206         struct cmd_config_thresh *res = parsed_result;
3207
3208         if (!all_ports_stopped()) {
3209                 printf("Please stop all ports first\n");
3210                 return;
3211         }
3212
3213         if (!strcmp(res->name, "txpt"))
3214                 tx_pthresh = res->value;
3215         else if(!strcmp(res->name, "txht"))
3216                 tx_hthresh = res->value;
3217         else if(!strcmp(res->name, "txwt"))
3218                 tx_wthresh = res->value;
3219         else if(!strcmp(res->name, "rxpt"))
3220                 rx_pthresh = res->value;
3221         else if(!strcmp(res->name, "rxht"))
3222                 rx_hthresh = res->value;
3223         else if(!strcmp(res->name, "rxwt"))
3224                 rx_wthresh = res->value;
3225         else {
3226                 printf("Unknown parameter\n");
3227                 return;
3228         }
3229
3230         init_port_config();
3231
3232         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3233 }
3234
3235 cmdline_parse_token_string_t cmd_config_thresh_port =
3236         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3237 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3238         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3239 cmdline_parse_token_string_t cmd_config_thresh_all =
3240         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3241 cmdline_parse_token_string_t cmd_config_thresh_name =
3242         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3243                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3244 cmdline_parse_token_num_t cmd_config_thresh_value =
3245         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3246
3247 cmdline_parse_inst_t cmd_config_thresh = {
3248         .f = cmd_config_thresh_parsed,
3249         .data = NULL,
3250         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3251         .tokens = {
3252                 (void *)&cmd_config_thresh_port,
3253                 (void *)&cmd_config_thresh_keyword,
3254                 (void *)&cmd_config_thresh_all,
3255                 (void *)&cmd_config_thresh_name,
3256                 (void *)&cmd_config_thresh_value,
3257                 NULL,
3258         },
3259 };
3260
3261 /* *** configure free/rs threshold *** */
3262 struct cmd_config_threshold {
3263         cmdline_fixed_string_t port;
3264         cmdline_fixed_string_t keyword;
3265         cmdline_fixed_string_t all;
3266         cmdline_fixed_string_t name;
3267         uint16_t value;
3268 };
3269
3270 static void
3271 cmd_config_threshold_parsed(void *parsed_result,
3272                         __attribute__((unused)) struct cmdline *cl,
3273                         __attribute__((unused)) void *data)
3274 {
3275         struct cmd_config_threshold *res = parsed_result;
3276
3277         if (!all_ports_stopped()) {
3278                 printf("Please stop all ports first\n");
3279                 return;
3280         }
3281
3282         if (!strcmp(res->name, "txfreet"))
3283                 tx_free_thresh = res->value;
3284         else if (!strcmp(res->name, "txrst"))
3285                 tx_rs_thresh = res->value;
3286         else if (!strcmp(res->name, "rxfreet"))
3287                 rx_free_thresh = res->value;
3288         else {
3289                 printf("Unknown parameter\n");
3290                 return;
3291         }
3292
3293         init_port_config();
3294
3295         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3296 }
3297
3298 cmdline_parse_token_string_t cmd_config_threshold_port =
3299         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3300 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3301         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3302                                                                 "config");
3303 cmdline_parse_token_string_t cmd_config_threshold_all =
3304         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3305 cmdline_parse_token_string_t cmd_config_threshold_name =
3306         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3307                                                 "txfreet#txrst#rxfreet");
3308 cmdline_parse_token_num_t cmd_config_threshold_value =
3309         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3310
3311 cmdline_parse_inst_t cmd_config_threshold = {
3312         .f = cmd_config_threshold_parsed,
3313         .data = NULL,
3314         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3315         .tokens = {
3316                 (void *)&cmd_config_threshold_port,
3317                 (void *)&cmd_config_threshold_keyword,
3318                 (void *)&cmd_config_threshold_all,
3319                 (void *)&cmd_config_threshold_name,
3320                 (void *)&cmd_config_threshold_value,
3321                 NULL,
3322         },
3323 };
3324
3325 /* *** stop *** */
3326 struct cmd_stop_result {
3327         cmdline_fixed_string_t stop;
3328 };
3329
3330 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3331                             __attribute__((unused)) struct cmdline *cl,
3332                             __attribute__((unused)) void *data)
3333 {
3334         stop_packet_forwarding();
3335 }
3336
3337 cmdline_parse_token_string_t cmd_stop_stop =
3338         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3339
3340 cmdline_parse_inst_t cmd_stop = {
3341         .f = cmd_stop_parsed,
3342         .data = NULL,
3343         .help_str = "stop: Stop packet forwarding",
3344         .tokens = {
3345                 (void *)&cmd_stop_stop,
3346                 NULL,
3347         },
3348 };
3349
3350 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3351
3352 unsigned int
3353 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3354                 unsigned int *parsed_items, int check_unique_values)
3355 {
3356         unsigned int nb_item;
3357         unsigned int value;
3358         unsigned int i;
3359         unsigned int j;
3360         int value_ok;
3361         char c;
3362
3363         /*
3364          * First parse all items in the list and store their value.
3365          */
3366         value = 0;
3367         nb_item = 0;
3368         value_ok = 0;
3369         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3370                 c = str[i];
3371                 if ((c >= '0') && (c <= '9')) {
3372                         value = (unsigned int) (value * 10 + (c - '0'));
3373                         value_ok = 1;
3374                         continue;
3375                 }
3376                 if (c != ',') {
3377                         printf("character %c is not a decimal digit\n", c);
3378                         return 0;
3379                 }
3380                 if (! value_ok) {
3381                         printf("No valid value before comma\n");
3382                         return 0;
3383                 }
3384                 if (nb_item < max_items) {
3385                         parsed_items[nb_item] = value;
3386                         value_ok = 0;
3387                         value = 0;
3388                 }
3389                 nb_item++;
3390         }
3391         if (nb_item >= max_items) {
3392                 printf("Number of %s = %u > %u (maximum items)\n",
3393                        item_name, nb_item + 1, max_items);
3394                 return 0;
3395         }
3396         parsed_items[nb_item++] = value;
3397         if (! check_unique_values)
3398                 return nb_item;
3399
3400         /*
3401          * Then, check that all values in the list are differents.
3402          * No optimization here...
3403          */
3404         for (i = 0; i < nb_item; i++) {
3405                 for (j = i + 1; j < nb_item; j++) {
3406                         if (parsed_items[j] == parsed_items[i]) {
3407                                 printf("duplicated %s %u at index %u and %u\n",
3408                                        item_name, parsed_items[i], i, j);
3409                                 return 0;
3410                         }
3411                 }
3412         }
3413         return nb_item;
3414 }
3415
3416 struct cmd_set_list_result {
3417         cmdline_fixed_string_t cmd_keyword;
3418         cmdline_fixed_string_t list_name;
3419         cmdline_fixed_string_t list_of_items;
3420 };
3421
3422 static void cmd_set_list_parsed(void *parsed_result,
3423                                 __attribute__((unused)) struct cmdline *cl,
3424                                 __attribute__((unused)) void *data)
3425 {
3426         struct cmd_set_list_result *res;
3427         union {
3428                 unsigned int lcorelist[RTE_MAX_LCORE];
3429                 unsigned int portlist[RTE_MAX_ETHPORTS];
3430         } parsed_items;
3431         unsigned int nb_item;
3432
3433         if (test_done == 0) {
3434                 printf("Please stop forwarding first\n");
3435                 return;
3436         }
3437
3438         res = parsed_result;
3439         if (!strcmp(res->list_name, "corelist")) {
3440                 nb_item = parse_item_list(res->list_of_items, "core",
3441                                           RTE_MAX_LCORE,
3442                                           parsed_items.lcorelist, 1);
3443                 if (nb_item > 0) {
3444                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3445                         fwd_config_setup();
3446                 }
3447                 return;
3448         }
3449         if (!strcmp(res->list_name, "portlist")) {
3450                 nb_item = parse_item_list(res->list_of_items, "port",
3451                                           RTE_MAX_ETHPORTS,
3452                                           parsed_items.portlist, 1);
3453                 if (nb_item > 0) {
3454                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3455                         fwd_config_setup();
3456                 }
3457         }
3458 }
3459
3460 cmdline_parse_token_string_t cmd_set_list_keyword =
3461         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3462                                  "set");
3463 cmdline_parse_token_string_t cmd_set_list_name =
3464         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3465                                  "corelist#portlist");
3466 cmdline_parse_token_string_t cmd_set_list_of_items =
3467         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3468                                  NULL);
3469
3470 cmdline_parse_inst_t cmd_set_fwd_list = {
3471         .f = cmd_set_list_parsed,
3472         .data = NULL,
3473         .help_str = "set corelist|portlist <list0[,list1]*>",
3474         .tokens = {
3475                 (void *)&cmd_set_list_keyword,
3476                 (void *)&cmd_set_list_name,
3477                 (void *)&cmd_set_list_of_items,
3478                 NULL,
3479         },
3480 };
3481
3482 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3483
3484 struct cmd_setmask_result {
3485         cmdline_fixed_string_t set;
3486         cmdline_fixed_string_t mask;
3487         uint64_t hexavalue;
3488 };
3489
3490 static void cmd_set_mask_parsed(void *parsed_result,
3491                                 __attribute__((unused)) struct cmdline *cl,
3492                                 __attribute__((unused)) void *data)
3493 {
3494         struct cmd_setmask_result *res = parsed_result;
3495
3496         if (test_done == 0) {
3497                 printf("Please stop forwarding first\n");
3498                 return;
3499         }
3500         if (!strcmp(res->mask, "coremask")) {
3501                 set_fwd_lcores_mask(res->hexavalue);
3502                 fwd_config_setup();
3503         } else if (!strcmp(res->mask, "portmask")) {
3504                 set_fwd_ports_mask(res->hexavalue);
3505                 fwd_config_setup();
3506         }
3507 }
3508
3509 cmdline_parse_token_string_t cmd_setmask_set =
3510         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3511 cmdline_parse_token_string_t cmd_setmask_mask =
3512         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3513                                  "coremask#portmask");
3514 cmdline_parse_token_num_t cmd_setmask_value =
3515         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3516
3517 cmdline_parse_inst_t cmd_set_fwd_mask = {
3518         .f = cmd_set_mask_parsed,
3519         .data = NULL,
3520         .help_str = "set coremask|portmask <hexadecimal value>",
3521         .tokens = {
3522                 (void *)&cmd_setmask_set,
3523                 (void *)&cmd_setmask_mask,
3524                 (void *)&cmd_setmask_value,
3525                 NULL,
3526         },
3527 };
3528
3529 /*
3530  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3531  */
3532 struct cmd_set_result {
3533         cmdline_fixed_string_t set;
3534         cmdline_fixed_string_t what;
3535         uint16_t value;
3536 };
3537
3538 static void cmd_set_parsed(void *parsed_result,
3539                            __attribute__((unused)) struct cmdline *cl,
3540                            __attribute__((unused)) void *data)
3541 {
3542         struct cmd_set_result *res = parsed_result;
3543         if (!strcmp(res->what, "nbport")) {
3544                 set_fwd_ports_number(res->value);
3545                 fwd_config_setup();
3546         } else if (!strcmp(res->what, "nbcore")) {
3547                 set_fwd_lcores_number(res->value);
3548                 fwd_config_setup();
3549         } else if (!strcmp(res->what, "burst"))
3550                 set_nb_pkt_per_burst(res->value);
3551         else if (!strcmp(res->what, "verbose"))
3552                 set_verbose_level(res->value);
3553 }
3554
3555 cmdline_parse_token_string_t cmd_set_set =
3556         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3557 cmdline_parse_token_string_t cmd_set_what =
3558         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3559                                  "nbport#nbcore#burst#verbose");
3560 cmdline_parse_token_num_t cmd_set_value =
3561         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3562
3563 cmdline_parse_inst_t cmd_set_numbers = {
3564         .f = cmd_set_parsed,
3565         .data = NULL,
3566         .help_str = "set nbport|nbcore|burst|verbose <value>",
3567         .tokens = {
3568                 (void *)&cmd_set_set,
3569                 (void *)&cmd_set_what,
3570                 (void *)&cmd_set_value,
3571                 NULL,
3572         },
3573 };
3574
3575 /* *** SET LOG LEVEL CONFIGURATION *** */
3576
3577 struct cmd_set_log_result {
3578         cmdline_fixed_string_t set;
3579         cmdline_fixed_string_t log;
3580         cmdline_fixed_string_t type;
3581         uint32_t level;
3582 };
3583
3584 static void
3585 cmd_set_log_parsed(void *parsed_result,
3586                    __attribute__((unused)) struct cmdline *cl,
3587                    __attribute__((unused)) void *data)
3588 {
3589         struct cmd_set_log_result *res;
3590         int ret;
3591
3592         res = parsed_result;
3593         if (!strcmp(res->type, "global"))
3594                 rte_log_set_global_level(res->level);
3595         else {
3596                 ret = rte_log_set_level_regexp(res->type, res->level);
3597                 if (ret < 0)
3598                         printf("Unable to set log level\n");
3599         }
3600 }
3601
3602 cmdline_parse_token_string_t cmd_set_log_set =
3603         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3604 cmdline_parse_token_string_t cmd_set_log_log =
3605         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3606 cmdline_parse_token_string_t cmd_set_log_type =
3607         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3608 cmdline_parse_token_num_t cmd_set_log_level =
3609         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3610
3611 cmdline_parse_inst_t cmd_set_log = {
3612         .f = cmd_set_log_parsed,
3613         .data = NULL,
3614         .help_str = "set log global|<type> <level>",
3615         .tokens = {
3616                 (void *)&cmd_set_log_set,
3617                 (void *)&cmd_set_log_log,
3618                 (void *)&cmd_set_log_type,
3619                 (void *)&cmd_set_log_level,
3620                 NULL,
3621         },
3622 };
3623
3624 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3625
3626 struct cmd_set_txpkts_result {
3627         cmdline_fixed_string_t cmd_keyword;
3628         cmdline_fixed_string_t txpkts;
3629         cmdline_fixed_string_t seg_lengths;
3630 };
3631
3632 static void
3633 cmd_set_txpkts_parsed(void *parsed_result,
3634                       __attribute__((unused)) struct cmdline *cl,
3635                       __attribute__((unused)) void *data)
3636 {
3637         struct cmd_set_txpkts_result *res;
3638         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3639         unsigned int nb_segs;
3640
3641         res = parsed_result;
3642         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3643                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3644         if (nb_segs > 0)
3645                 set_tx_pkt_segments(seg_lengths, nb_segs);
3646 }
3647
3648 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3649         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3650                                  cmd_keyword, "set");
3651 cmdline_parse_token_string_t cmd_set_txpkts_name =
3652         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3653                                  txpkts, "txpkts");
3654 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3655         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3656                                  seg_lengths, NULL);
3657
3658 cmdline_parse_inst_t cmd_set_txpkts = {
3659         .f = cmd_set_txpkts_parsed,
3660         .data = NULL,
3661         .help_str = "set txpkts <len0[,len1]*>",
3662         .tokens = {
3663                 (void *)&cmd_set_txpkts_keyword,
3664                 (void *)&cmd_set_txpkts_name,
3665                 (void *)&cmd_set_txpkts_lengths,
3666                 NULL,
3667         },
3668 };
3669
3670 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3671
3672 struct cmd_set_txsplit_result {
3673         cmdline_fixed_string_t cmd_keyword;
3674         cmdline_fixed_string_t txsplit;
3675         cmdline_fixed_string_t mode;
3676 };
3677
3678 static void
3679 cmd_set_txsplit_parsed(void *parsed_result,
3680                       __attribute__((unused)) struct cmdline *cl,
3681                       __attribute__((unused)) void *data)
3682 {
3683         struct cmd_set_txsplit_result *res;
3684
3685         res = parsed_result;
3686         set_tx_pkt_split(res->mode);
3687 }
3688
3689 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3690         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3691                                  cmd_keyword, "set");
3692 cmdline_parse_token_string_t cmd_set_txsplit_name =
3693         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3694                                  txsplit, "txsplit");
3695 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3696         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3697                                  mode, NULL);
3698
3699 cmdline_parse_inst_t cmd_set_txsplit = {
3700         .f = cmd_set_txsplit_parsed,
3701         .data = NULL,
3702         .help_str = "set txsplit on|off|rand",
3703         .tokens = {
3704                 (void *)&cmd_set_txsplit_keyword,
3705                 (void *)&cmd_set_txsplit_name,
3706                 (void *)&cmd_set_txsplit_mode,
3707                 NULL,
3708         },
3709 };
3710
3711 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3712 struct cmd_rx_vlan_filter_all_result {
3713         cmdline_fixed_string_t rx_vlan;
3714         cmdline_fixed_string_t what;
3715         cmdline_fixed_string_t all;
3716         portid_t port_id;
3717 };
3718
3719 static void
3720 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3721                               __attribute__((unused)) struct cmdline *cl,
3722                               __attribute__((unused)) void *data)
3723 {
3724         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3725
3726         if (!strcmp(res->what, "add"))
3727                 rx_vlan_all_filter_set(res->port_id, 1);
3728         else
3729                 rx_vlan_all_filter_set(res->port_id, 0);
3730 }
3731
3732 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3733         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3734                                  rx_vlan, "rx_vlan");
3735 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3736         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3737                                  what, "add#rm");
3738 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3739         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3740                                  all, "all");
3741 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3742         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3743                               port_id, UINT16);
3744
3745 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3746         .f = cmd_rx_vlan_filter_all_parsed,
3747         .data = NULL,
3748         .help_str = "rx_vlan add|rm all <port_id>: "
3749                 "Add/Remove all identifiers to/from the set of VLAN "
3750                 "identifiers filtered by a port",
3751         .tokens = {
3752                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3753                 (void *)&cmd_rx_vlan_filter_all_what,
3754                 (void *)&cmd_rx_vlan_filter_all_all,
3755                 (void *)&cmd_rx_vlan_filter_all_portid,
3756                 NULL,
3757         },
3758 };
3759
3760 /* *** VLAN OFFLOAD SET ON A PORT *** */
3761 struct cmd_vlan_offload_result {
3762         cmdline_fixed_string_t vlan;
3763         cmdline_fixed_string_t set;
3764         cmdline_fixed_string_t vlan_type;
3765         cmdline_fixed_string_t what;
3766         cmdline_fixed_string_t on;
3767         cmdline_fixed_string_t port_id;
3768 };
3769
3770 static void
3771 cmd_vlan_offload_parsed(void *parsed_result,
3772                           __attribute__((unused)) struct cmdline *cl,
3773                           __attribute__((unused)) void *data)
3774 {
3775         int on;
3776         struct cmd_vlan_offload_result *res = parsed_result;
3777         char *str;
3778         int i, len = 0;
3779         portid_t port_id = 0;
3780         unsigned int tmp;
3781
3782         str = res->port_id;
3783         len = strnlen(str, STR_TOKEN_SIZE);
3784         i = 0;
3785         /* Get port_id first */
3786         while(i < len){
3787                 if(str[i] == ',')
3788                         break;
3789
3790                 i++;
3791         }
3792         str[i]='\0';
3793         tmp = strtoul(str, NULL, 0);
3794         /* If port_id greater that what portid_t can represent, return */
3795         if(tmp >= RTE_MAX_ETHPORTS)
3796                 return;
3797         port_id = (portid_t)tmp;
3798
3799         if (!strcmp(res->on, "on"))
3800                 on = 1;
3801         else
3802                 on = 0;
3803
3804         if (!strcmp(res->what, "strip"))
3805                 rx_vlan_strip_set(port_id,  on);
3806         else if(!strcmp(res->what, "stripq")){
3807                 uint16_t queue_id = 0;
3808
3809                 /* No queue_id, return */
3810                 if(i + 1 >= len) {
3811                         printf("must specify (port,queue_id)\n");
3812                         return;
3813                 }
3814                 tmp = strtoul(str + i + 1, NULL, 0);
3815                 /* If queue_id greater that what 16-bits can represent, return */
3816                 if(tmp > 0xffff)
3817                         return;
3818
3819                 queue_id = (uint16_t)tmp;
3820                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3821         }
3822         else if (!strcmp(res->what, "filter"))
3823                 rx_vlan_filter_set(port_id, on);
3824         else
3825                 vlan_extend_set(port_id, on);
3826
3827         return;
3828 }
3829
3830 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3831         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3832                                  vlan, "vlan");
3833 cmdline_parse_token_string_t cmd_vlan_offload_set =
3834         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3835                                  set, "set");
3836 cmdline_parse_token_string_t cmd_vlan_offload_what =
3837         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3838                                  what, "strip#filter#qinq#stripq");
3839 cmdline_parse_token_string_t cmd_vlan_offload_on =
3840         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3841                               on, "on#off");
3842 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3843         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3844                               port_id, NULL);
3845
3846 cmdline_parse_inst_t cmd_vlan_offload = {
3847         .f = cmd_vlan_offload_parsed,
3848         .data = NULL,
3849         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3850                 "<port_id[,queue_id]>: "
3851                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3852         .tokens = {
3853                 (void *)&cmd_vlan_offload_vlan,
3854                 (void *)&cmd_vlan_offload_set,
3855                 (void *)&cmd_vlan_offload_what,
3856                 (void *)&cmd_vlan_offload_on,
3857                 (void *)&cmd_vlan_offload_portid,
3858                 NULL,
3859         },
3860 };
3861
3862 /* *** VLAN TPID SET ON A PORT *** */
3863 struct cmd_vlan_tpid_result {
3864         cmdline_fixed_string_t vlan;
3865         cmdline_fixed_string_t set;
3866         cmdline_fixed_string_t vlan_type;
3867         cmdline_fixed_string_t what;
3868         uint16_t tp_id;
3869         portid_t port_id;
3870 };
3871
3872 static void
3873 cmd_vlan_tpid_parsed(void *parsed_result,
3874                           __attribute__((unused)) struct cmdline *cl,
3875                           __attribute__((unused)) void *data)
3876 {
3877         struct cmd_vlan_tpid_result *res = parsed_result;
3878         enum rte_vlan_type vlan_type;
3879
3880         if (!strcmp(res->vlan_type, "inner"))
3881                 vlan_type = ETH_VLAN_TYPE_INNER;
3882         else if (!strcmp(res->vlan_type, "outer"))
3883                 vlan_type = ETH_VLAN_TYPE_OUTER;
3884         else {
3885                 printf("Unknown vlan type\n");
3886                 return;
3887         }
3888         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3889 }
3890
3891 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3892         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3893                                  vlan, "vlan");
3894 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3895         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3896                                  set, "set");
3897 cmdline_parse_token_string_t cmd_vlan_type =
3898         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3899                                  vlan_type, "inner#outer");
3900 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3901         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3902                                  what, "tpid");
3903 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3904         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3905                               tp_id, UINT16);
3906 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3907         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3908                               port_id, UINT16);
3909
3910 cmdline_parse_inst_t cmd_vlan_tpid = {
3911         .f = cmd_vlan_tpid_parsed,
3912         .data = NULL,
3913         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3914                 "Set the VLAN Ether type",
3915         .tokens = {
3916                 (void *)&cmd_vlan_tpid_vlan,
3917                 (void *)&cmd_vlan_tpid_set,
3918                 (void *)&cmd_vlan_type,
3919                 (void *)&cmd_vlan_tpid_what,
3920                 (void *)&cmd_vlan_tpid_tpid,
3921                 (void *)&cmd_vlan_tpid_portid,
3922                 NULL,
3923         },
3924 };
3925
3926 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3927 struct cmd_rx_vlan_filter_result {
3928         cmdline_fixed_string_t rx_vlan;
3929         cmdline_fixed_string_t what;
3930         uint16_t vlan_id;
3931         portid_t port_id;
3932 };
3933
3934 static void
3935 cmd_rx_vlan_filter_parsed(void *parsed_result,
3936                           __attribute__((unused)) struct cmdline *cl,
3937                           __attribute__((unused)) void *data)
3938 {
3939         struct cmd_rx_vlan_filter_result *res = parsed_result;
3940
3941         if (!strcmp(res->what, "add"))
3942                 rx_vft_set(res->port_id, res->vlan_id, 1);
3943         else
3944                 rx_vft_set(res->port_id, res->vlan_id, 0);
3945 }
3946
3947 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3948         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3949                                  rx_vlan, "rx_vlan");
3950 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3951         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3952                                  what, "add#rm");
3953 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3954         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3955                               vlan_id, UINT16);
3956 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3957         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3958                               port_id, UINT16);
3959
3960 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3961         .f = cmd_rx_vlan_filter_parsed,
3962         .data = NULL,
3963         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3964                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3965                 "identifiers filtered by a port",
3966         .tokens = {
3967                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3968                 (void *)&cmd_rx_vlan_filter_what,
3969                 (void *)&cmd_rx_vlan_filter_vlanid,
3970                 (void *)&cmd_rx_vlan_filter_portid,
3971                 NULL,
3972         },
3973 };
3974
3975 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3976 struct cmd_tx_vlan_set_result {
3977         cmdline_fixed_string_t tx_vlan;
3978         cmdline_fixed_string_t set;
3979         portid_t port_id;
3980         uint16_t vlan_id;
3981 };
3982
3983 static void
3984 cmd_tx_vlan_set_parsed(void *parsed_result,
3985                        __attribute__((unused)) struct cmdline *cl,
3986                        __attribute__((unused)) void *data)
3987 {
3988         struct cmd_tx_vlan_set_result *res = parsed_result;
3989
3990         if (!port_is_stopped(res->port_id)) {
3991                 printf("Please stop port %d first\n", res->port_id);
3992                 return;
3993         }
3994
3995         tx_vlan_set(res->port_id, res->vlan_id);
3996
3997         cmd_reconfig_device_queue(res->port_id, 1, 1);
3998 }
3999
4000 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4001         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4002                                  tx_vlan, "tx_vlan");
4003 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4004         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4005                                  set, "set");
4006 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4007         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4008                               port_id, UINT16);
4009 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4010         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4011                               vlan_id, UINT16);
4012
4013 cmdline_parse_inst_t cmd_tx_vlan_set = {
4014         .f = cmd_tx_vlan_set_parsed,
4015         .data = NULL,
4016         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4017                 "Enable hardware insertion of a single VLAN header "
4018                 "with a given TAG Identifier in packets sent on a port",
4019         .tokens = {
4020                 (void *)&cmd_tx_vlan_set_tx_vlan,
4021                 (void *)&cmd_tx_vlan_set_set,
4022                 (void *)&cmd_tx_vlan_set_portid,
4023                 (void *)&cmd_tx_vlan_set_vlanid,
4024                 NULL,
4025         },
4026 };
4027
4028 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4029 struct cmd_tx_vlan_set_qinq_result {
4030         cmdline_fixed_string_t tx_vlan;
4031         cmdline_fixed_string_t set;
4032         portid_t port_id;
4033         uint16_t vlan_id;
4034         uint16_t vlan_id_outer;
4035 };
4036
4037 static void
4038 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4039                             __attribute__((unused)) struct cmdline *cl,
4040                             __attribute__((unused)) void *data)
4041 {
4042         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4043
4044         if (!port_is_stopped(res->port_id)) {
4045                 printf("Please stop port %d first\n", res->port_id);
4046                 return;
4047         }
4048
4049         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4050
4051         cmd_reconfig_device_queue(res->port_id, 1, 1);
4052 }
4053
4054 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4055         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4056                 tx_vlan, "tx_vlan");
4057 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4058         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4059                 set, "set");
4060 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4061         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4062                 port_id, UINT16);
4063 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4064         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4065                 vlan_id, UINT16);
4066 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4067         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4068                 vlan_id_outer, UINT16);
4069
4070 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4071         .f = cmd_tx_vlan_set_qinq_parsed,
4072         .data = NULL,
4073         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4074                 "Enable hardware insertion of double VLAN header "
4075                 "with given TAG Identifiers in packets sent on a port",
4076         .tokens = {
4077                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4078                 (void *)&cmd_tx_vlan_set_qinq_set,
4079                 (void *)&cmd_tx_vlan_set_qinq_portid,
4080                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4081                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4082                 NULL,
4083         },
4084 };
4085
4086 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4087 struct cmd_tx_vlan_set_pvid_result {
4088         cmdline_fixed_string_t tx_vlan;
4089         cmdline_fixed_string_t set;
4090         cmdline_fixed_string_t pvid;
4091         portid_t port_id;
4092         uint16_t vlan_id;
4093         cmdline_fixed_string_t mode;
4094 };
4095
4096 static void
4097 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4098                             __attribute__((unused)) struct cmdline *cl,
4099                             __attribute__((unused)) void *data)
4100 {
4101         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4102
4103         if (strcmp(res->mode, "on") == 0)
4104                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4105         else
4106                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4107 }
4108
4109 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4110         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4111                                  tx_vlan, "tx_vlan");
4112 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4113         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4114                                  set, "set");
4115 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4116         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4117                                  pvid, "pvid");
4118 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4119         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4120                              port_id, UINT16);
4121 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4122         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4123                               vlan_id, UINT16);
4124 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4125         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4126                                  mode, "on#off");
4127
4128 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4129         .f = cmd_tx_vlan_set_pvid_parsed,
4130         .data = NULL,
4131         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4132         .tokens = {
4133                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4134                 (void *)&cmd_tx_vlan_set_pvid_set,
4135                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4136                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4137                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4138                 (void *)&cmd_tx_vlan_set_pvid_mode,
4139                 NULL,
4140         },
4141 };
4142
4143 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4144 struct cmd_tx_vlan_reset_result {
4145         cmdline_fixed_string_t tx_vlan;
4146         cmdline_fixed_string_t reset;
4147         portid_t port_id;
4148 };
4149
4150 static void
4151 cmd_tx_vlan_reset_parsed(void *parsed_result,
4152                          __attribute__((unused)) struct cmdline *cl,
4153                          __attribute__((unused)) void *data)
4154 {
4155         struct cmd_tx_vlan_reset_result *res = parsed_result;
4156
4157         if (!port_is_stopped(res->port_id)) {
4158                 printf("Please stop port %d first\n", res->port_id);
4159                 return;
4160         }
4161
4162         tx_vlan_reset(res->port_id);
4163
4164         cmd_reconfig_device_queue(res->port_id, 1, 1);
4165 }
4166
4167 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4168         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4169                                  tx_vlan, "tx_vlan");
4170 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4171         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4172                                  reset, "reset");
4173 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4174         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4175                               port_id, UINT16);
4176
4177 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4178         .f = cmd_tx_vlan_reset_parsed,
4179         .data = NULL,
4180         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4181                 "VLAN header in packets sent on a port",
4182         .tokens = {
4183                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4184                 (void *)&cmd_tx_vlan_reset_reset,
4185                 (void *)&cmd_tx_vlan_reset_portid,
4186                 NULL,
4187         },
4188 };
4189
4190
4191 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4192 struct cmd_csum_result {
4193         cmdline_fixed_string_t csum;
4194         cmdline_fixed_string_t mode;
4195         cmdline_fixed_string_t proto;
4196         cmdline_fixed_string_t hwsw;
4197         portid_t port_id;
4198 };
4199
4200 static void
4201 csum_show(int port_id)
4202 {
4203         struct rte_eth_dev_info dev_info;
4204         uint64_t tx_offloads;
4205
4206         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4207         printf("Parse tunnel is %s\n",
4208                 (ports[port_id].parse_tunnel) ? "on" : "off");
4209         printf("IP checksum offload is %s\n",
4210                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4211         printf("UDP checksum offload is %s\n",
4212                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4213         printf("TCP checksum offload is %s\n",
4214                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4215         printf("SCTP checksum offload is %s\n",
4216                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4217         printf("Outer-Ip checksum offload is %s\n",
4218                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4219         printf("Outer-Udp checksum offload is %s\n",
4220                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4221
4222         /* display warnings if configuration is not supported by the NIC */
4223         rte_eth_dev_info_get(port_id, &dev_info);
4224         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4225                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4226                 printf("Warning: hardware IP checksum enabled but not "
4227                         "supported by port %d\n", port_id);
4228         }
4229         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4230                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4231                 printf("Warning: hardware UDP checksum enabled but not "
4232                         "supported by port %d\n", port_id);
4233         }
4234         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4235                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4236                 printf("Warning: hardware TCP checksum enabled but not "
4237                         "supported by port %d\n", port_id);
4238         }
4239         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4240                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4241                 printf("Warning: hardware SCTP checksum enabled but not "
4242                         "supported by port %d\n", port_id);
4243         }
4244         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4245                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4246                 printf("Warning: hardware outer IP checksum enabled but not "
4247                         "supported by port %d\n", port_id);
4248         }
4249         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4250                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4251                         == 0) {
4252                 printf("Warning: hardware outer UDP checksum enabled but not "
4253                         "supported by port %d\n", port_id);
4254         }
4255 }
4256
4257 static void
4258 cmd_csum_parsed(void *parsed_result,
4259                        __attribute__((unused)) struct cmdline *cl,
4260                        __attribute__((unused)) void *data)
4261 {
4262         struct cmd_csum_result *res = parsed_result;
4263         int hw = 0;
4264         uint64_t csum_offloads = 0;
4265         struct rte_eth_dev_info dev_info;
4266
4267         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4268                 printf("invalid port %d\n", res->port_id);
4269                 return;
4270         }
4271         if (!port_is_stopped(res->port_id)) {
4272                 printf("Please stop port %d first\n", res->port_id);
4273                 return;
4274         }
4275
4276         rte_eth_dev_info_get(res->port_id, &dev_info);
4277         if (!strcmp(res->mode, "set")) {
4278
4279                 if (!strcmp(res->hwsw, "hw"))
4280                         hw = 1;
4281
4282                 if (!strcmp(res->proto, "ip")) {
4283                         if (hw == 0 || (dev_info.tx_offload_capa &
4284                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4285                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4286                         } else {
4287                                 printf("IP checksum offload is not supported "
4288                                        "by port %u\n", res->port_id);
4289                         }
4290                 } else if (!strcmp(res->proto, "udp")) {
4291                         if (hw == 0 || (dev_info.tx_offload_capa &
4292                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4293                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4294                         } else {
4295                                 printf("UDP checksum offload is not supported "
4296                                        "by port %u\n", res->port_id);
4297                         }
4298                 } else if (!strcmp(res->proto, "tcp")) {
4299                         if (hw == 0 || (dev_info.tx_offload_capa &
4300                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4301                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4302                         } else {
4303                                 printf("TCP checksum offload is not supported "
4304                                        "by port %u\n", res->port_id);
4305                         }
4306                 } else if (!strcmp(res->proto, "sctp")) {
4307                         if (hw == 0 || (dev_info.tx_offload_capa &
4308                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4309                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4310                         } else {
4311                                 printf("SCTP checksum offload is not supported "
4312                                        "by port %u\n", res->port_id);
4313                         }
4314                 } else if (!strcmp(res->proto, "outer-ip")) {
4315                         if (hw == 0 || (dev_info.tx_offload_capa &
4316                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4317                                 csum_offloads |=
4318                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4319                         } else {
4320                                 printf("Outer IP checksum offload is not "
4321                                        "supported by port %u\n", res->port_id);
4322                         }
4323                 } else if (!strcmp(res->proto, "outer-udp")) {
4324                         if (hw == 0 || (dev_info.tx_offload_capa &
4325                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4326                                 csum_offloads |=
4327                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4328                         } else {
4329                                 printf("Outer UDP checksum offload is not "
4330                                        "supported by port %u\n", res->port_id);
4331                         }
4332                 }
4333
4334                 if (hw) {
4335                         ports[res->port_id].dev_conf.txmode.offloads |=
4336                                                         csum_offloads;
4337                 } else {
4338                         ports[res->port_id].dev_conf.txmode.offloads &=
4339                                                         (~csum_offloads);
4340                 }
4341         }
4342         csum_show(res->port_id);
4343
4344         cmd_reconfig_device_queue(res->port_id, 1, 1);
4345 }
4346
4347 cmdline_parse_token_string_t cmd_csum_csum =
4348         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4349                                 csum, "csum");
4350 cmdline_parse_token_string_t cmd_csum_mode =
4351         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4352                                 mode, "set");
4353 cmdline_parse_token_string_t cmd_csum_proto =
4354         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4355                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4356 cmdline_parse_token_string_t cmd_csum_hwsw =
4357         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4358                                 hwsw, "hw#sw");
4359 cmdline_parse_token_num_t cmd_csum_portid =
4360         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4361                                 port_id, UINT16);
4362
4363 cmdline_parse_inst_t cmd_csum_set = {
4364         .f = cmd_csum_parsed,
4365         .data = NULL,
4366         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4367                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4368                 "using csum forward engine",
4369         .tokens = {
4370                 (void *)&cmd_csum_csum,
4371                 (void *)&cmd_csum_mode,
4372                 (void *)&cmd_csum_proto,
4373                 (void *)&cmd_csum_hwsw,
4374                 (void *)&cmd_csum_portid,
4375                 NULL,
4376         },
4377 };
4378
4379 cmdline_parse_token_string_t cmd_csum_mode_show =
4380         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4381                                 mode, "show");
4382
4383 cmdline_parse_inst_t cmd_csum_show = {
4384         .f = cmd_csum_parsed,
4385         .data = NULL,
4386         .help_str = "csum show <port_id>: Show checksum offload configuration",
4387         .tokens = {
4388                 (void *)&cmd_csum_csum,
4389                 (void *)&cmd_csum_mode_show,
4390                 (void *)&cmd_csum_portid,
4391                 NULL,
4392         },
4393 };
4394
4395 /* Enable/disable tunnel parsing */
4396 struct cmd_csum_tunnel_result {
4397         cmdline_fixed_string_t csum;
4398         cmdline_fixed_string_t parse;
4399         cmdline_fixed_string_t onoff;
4400         portid_t port_id;
4401 };
4402
4403 static void
4404 cmd_csum_tunnel_parsed(void *parsed_result,
4405                        __attribute__((unused)) struct cmdline *cl,
4406                        __attribute__((unused)) void *data)
4407 {
4408         struct cmd_csum_tunnel_result *res = parsed_result;
4409
4410         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4411                 return;
4412
4413         if (!strcmp(res->onoff, "on"))
4414                 ports[res->port_id].parse_tunnel = 1;
4415         else
4416                 ports[res->port_id].parse_tunnel = 0;
4417
4418         csum_show(res->port_id);
4419 }
4420
4421 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4422         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4423                                 csum, "csum");
4424 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4425         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4426                                 parse, "parse-tunnel");
4427 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4428         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4429                                 onoff, "on#off");
4430 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4431         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4432                                 port_id, UINT16);
4433
4434 cmdline_parse_inst_t cmd_csum_tunnel = {
4435         .f = cmd_csum_tunnel_parsed,
4436         .data = NULL,
4437         .help_str = "csum parse-tunnel on|off <port_id>: "
4438                 "Enable/Disable parsing of tunnels for csum engine",
4439         .tokens = {
4440                 (void *)&cmd_csum_tunnel_csum,
4441                 (void *)&cmd_csum_tunnel_parse,
4442                 (void *)&cmd_csum_tunnel_onoff,
4443                 (void *)&cmd_csum_tunnel_portid,
4444                 NULL,
4445         },
4446 };
4447
4448 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4449 struct cmd_tso_set_result {
4450         cmdline_fixed_string_t tso;
4451         cmdline_fixed_string_t mode;
4452         uint16_t tso_segsz;
4453         portid_t port_id;
4454 };
4455
4456 static void
4457 cmd_tso_set_parsed(void *parsed_result,
4458                        __attribute__((unused)) struct cmdline *cl,
4459                        __attribute__((unused)) void *data)
4460 {
4461         struct cmd_tso_set_result *res = parsed_result;
4462         struct rte_eth_dev_info dev_info;
4463
4464         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4465                 return;
4466         if (!port_is_stopped(res->port_id)) {
4467                 printf("Please stop port %d first\n", res->port_id);
4468                 return;
4469         }
4470
4471         if (!strcmp(res->mode, "set"))
4472                 ports[res->port_id].tso_segsz = res->tso_segsz;
4473
4474         rte_eth_dev_info_get(res->port_id, &dev_info);
4475         if ((ports[res->port_id].tso_segsz != 0) &&
4476                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4477                 printf("Error: TSO is not supported by port %d\n",
4478                        res->port_id);
4479                 return;
4480         }
4481
4482         if (ports[res->port_id].tso_segsz == 0) {
4483                 ports[res->port_id].dev_conf.txmode.offloads &=
4484                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4485                 printf("TSO for non-tunneled packets is disabled\n");
4486         } else {
4487                 ports[res->port_id].dev_conf.txmode.offloads |=
4488                                                 DEV_TX_OFFLOAD_TCP_TSO;
4489                 printf("TSO segment size for non-tunneled packets is %d\n",
4490                         ports[res->port_id].tso_segsz);
4491         }
4492
4493         /* display warnings if configuration is not supported by the NIC */
4494         rte_eth_dev_info_get(res->port_id, &dev_info);
4495         if ((ports[res->port_id].tso_segsz != 0) &&
4496                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4497                 printf("Warning: TSO enabled but not "
4498                         "supported by port %d\n", res->port_id);
4499         }
4500
4501         cmd_reconfig_device_queue(res->port_id, 1, 1);
4502 }
4503
4504 cmdline_parse_token_string_t cmd_tso_set_tso =
4505         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4506                                 tso, "tso");
4507 cmdline_parse_token_string_t cmd_tso_set_mode =
4508         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4509                                 mode, "set");
4510 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4511         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4512                                 tso_segsz, UINT16);
4513 cmdline_parse_token_num_t cmd_tso_set_portid =
4514         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4515                                 port_id, UINT16);
4516
4517 cmdline_parse_inst_t cmd_tso_set = {
4518         .f = cmd_tso_set_parsed,
4519         .data = NULL,
4520         .help_str = "tso set <tso_segsz> <port_id>: "
4521                 "Set TSO segment size of non-tunneled packets for csum engine "
4522                 "(0 to disable)",
4523         .tokens = {
4524                 (void *)&cmd_tso_set_tso,
4525                 (void *)&cmd_tso_set_mode,
4526                 (void *)&cmd_tso_set_tso_segsz,
4527                 (void *)&cmd_tso_set_portid,
4528                 NULL,
4529         },
4530 };
4531
4532 cmdline_parse_token_string_t cmd_tso_show_mode =
4533         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4534                                 mode, "show");
4535
4536
4537 cmdline_parse_inst_t cmd_tso_show = {
4538         .f = cmd_tso_set_parsed,
4539         .data = NULL,
4540         .help_str = "tso show <port_id>: "
4541                 "Show TSO segment size of non-tunneled packets for csum engine",
4542         .tokens = {
4543                 (void *)&cmd_tso_set_tso,
4544                 (void *)&cmd_tso_show_mode,
4545                 (void *)&cmd_tso_set_portid,
4546                 NULL,
4547         },
4548 };
4549
4550 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4551 struct cmd_tunnel_tso_set_result {
4552         cmdline_fixed_string_t tso;
4553         cmdline_fixed_string_t mode;
4554         uint16_t tso_segsz;
4555         portid_t port_id;
4556 };
4557
4558 static struct rte_eth_dev_info
4559 check_tunnel_tso_nic_support(portid_t port_id)
4560 {
4561         struct rte_eth_dev_info dev_info;
4562
4563         rte_eth_dev_info_get(port_id, &dev_info);
4564         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4565                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4566                        "not enabled for port %d\n", port_id);
4567         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4568                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4569                        "not enabled for port %d\n", port_id);
4570         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4571                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4572                        "not enabled for port %d\n", port_id);
4573         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4574                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4575                        "not enabled for port %d\n", port_id);
4576         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4577                 printf("Warning: IP TUNNEL TSO not supported therefore "
4578                        "not enabled for port %d\n", port_id);
4579         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4580                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4581                        "not enabled for port %d\n", port_id);
4582         return dev_info;
4583 }
4584
4585 static void
4586 cmd_tunnel_tso_set_parsed(void *parsed_result,
4587                           __attribute__((unused)) struct cmdline *cl,
4588                           __attribute__((unused)) void *data)
4589 {
4590         struct cmd_tunnel_tso_set_result *res = parsed_result;
4591         struct rte_eth_dev_info dev_info;
4592
4593         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4594                 return;
4595         if (!port_is_stopped(res->port_id)) {
4596                 printf("Please stop port %d first\n", res->port_id);
4597                 return;
4598         }
4599
4600         if (!strcmp(res->mode, "set"))
4601                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4602
4603         dev_info = check_tunnel_tso_nic_support(res->port_id);
4604         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4605                 ports[res->port_id].dev_conf.txmode.offloads &=
4606                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4607                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4608                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4609                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4610                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4611                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4612                 printf("TSO for tunneled packets is disabled\n");
4613         } else {
4614                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4615                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4616                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4617                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4618                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4619                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4620
4621                 ports[res->port_id].dev_conf.txmode.offloads |=
4622                         (tso_offloads & dev_info.tx_offload_capa);
4623                 printf("TSO segment size for tunneled packets is %d\n",
4624                         ports[res->port_id].tunnel_tso_segsz);
4625
4626                 /* Below conditions are needed to make it work:
4627                  * (1) tunnel TSO is supported by the NIC;
4628                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4629                  * are recognized;
4630                  * (3) for tunneled pkts with outer L3 of IPv4,
4631                  * "csum set outer-ip" must be set to hw, because after tso,
4632                  * total_len of outer IP header is changed, and the checksum
4633                  * of outer IP header calculated by sw should be wrong; that
4634                  * is not necessary for IPv6 tunneled pkts because there's no
4635                  * checksum in IP header anymore.
4636                  */
4637
4638                 if (!ports[res->port_id].parse_tunnel)
4639                         printf("Warning: csum parse_tunnel must be set "
4640                                 "so that tunneled packets are recognized\n");
4641                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4642                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4643                         printf("Warning: csum set outer-ip must be set to hw "
4644                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4645         }
4646
4647         cmd_reconfig_device_queue(res->port_id, 1, 1);
4648 }
4649
4650 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4651         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4652                                 tso, "tunnel_tso");
4653 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4654         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4655                                 mode, "set");
4656 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4657         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4658                                 tso_segsz, UINT16);
4659 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4660         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4661                                 port_id, UINT16);
4662
4663 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4664         .f = cmd_tunnel_tso_set_parsed,
4665         .data = NULL,
4666         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4667                 "Set TSO segment size of tunneled packets for csum engine "
4668                 "(0 to disable)",
4669         .tokens = {
4670                 (void *)&cmd_tunnel_tso_set_tso,
4671                 (void *)&cmd_tunnel_tso_set_mode,
4672                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4673                 (void *)&cmd_tunnel_tso_set_portid,
4674                 NULL,
4675         },
4676 };
4677
4678 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4679         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4680                                 mode, "show");
4681
4682
4683 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4684         .f = cmd_tunnel_tso_set_parsed,
4685         .data = NULL,
4686         .help_str = "tunnel_tso show <port_id> "
4687                 "Show TSO segment size of tunneled packets for csum engine",
4688         .tokens = {
4689                 (void *)&cmd_tunnel_tso_set_tso,
4690                 (void *)&cmd_tunnel_tso_show_mode,
4691                 (void *)&cmd_tunnel_tso_set_portid,
4692                 NULL,
4693         },
4694 };
4695
4696 /* *** SET GRO FOR A PORT *** */
4697 struct cmd_gro_enable_result {
4698         cmdline_fixed_string_t cmd_set;
4699         cmdline_fixed_string_t cmd_port;
4700         cmdline_fixed_string_t cmd_keyword;
4701         cmdline_fixed_string_t cmd_onoff;
4702         portid_t cmd_pid;
4703 };
4704
4705 static void
4706 cmd_gro_enable_parsed(void *parsed_result,
4707                 __attribute__((unused)) struct cmdline *cl,
4708                 __attribute__((unused)) void *data)
4709 {
4710         struct cmd_gro_enable_result *res;
4711
4712         res = parsed_result;
4713         if (!strcmp(res->cmd_keyword, "gro"))
4714                 setup_gro(res->cmd_onoff, res->cmd_pid);
4715 }
4716
4717 cmdline_parse_token_string_t cmd_gro_enable_set =
4718         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4719                         cmd_set, "set");
4720 cmdline_parse_token_string_t cmd_gro_enable_port =
4721         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4722                         cmd_keyword, "port");
4723 cmdline_parse_token_num_t cmd_gro_enable_pid =
4724         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4725                         cmd_pid, UINT16);
4726 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4727         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4728                         cmd_keyword, "gro");
4729 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4730         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4731                         cmd_onoff, "on#off");
4732
4733 cmdline_parse_inst_t cmd_gro_enable = {
4734         .f = cmd_gro_enable_parsed,
4735         .data = NULL,
4736         .help_str = "set port <port_id> gro on|off",
4737         .tokens = {
4738                 (void *)&cmd_gro_enable_set,
4739                 (void *)&cmd_gro_enable_port,
4740                 (void *)&cmd_gro_enable_pid,
4741                 (void *)&cmd_gro_enable_keyword,
4742                 (void *)&cmd_gro_enable_onoff,
4743                 NULL,
4744         },
4745 };
4746
4747 /* *** DISPLAY GRO CONFIGURATION *** */
4748 struct cmd_gro_show_result {
4749         cmdline_fixed_string_t cmd_show;
4750         cmdline_fixed_string_t cmd_port;
4751         cmdline_fixed_string_t cmd_keyword;
4752         portid_t cmd_pid;
4753 };
4754
4755 static void
4756 cmd_gro_show_parsed(void *parsed_result,
4757                 __attribute__((unused)) struct cmdline *cl,
4758                 __attribute__((unused)) void *data)
4759 {
4760         struct cmd_gro_show_result *res;
4761
4762         res = parsed_result;
4763         if (!strcmp(res->cmd_keyword, "gro"))
4764                 show_gro(res->cmd_pid);
4765 }
4766
4767 cmdline_parse_token_string_t cmd_gro_show_show =
4768         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4769                         cmd_show, "show");
4770 cmdline_parse_token_string_t cmd_gro_show_port =
4771         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4772                         cmd_port, "port");
4773 cmdline_parse_token_num_t cmd_gro_show_pid =
4774         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4775                         cmd_pid, UINT16);
4776 cmdline_parse_token_string_t cmd_gro_show_keyword =
4777         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4778                         cmd_keyword, "gro");
4779
4780 cmdline_parse_inst_t cmd_gro_show = {
4781         .f = cmd_gro_show_parsed,
4782         .data = NULL,
4783         .help_str = "show port <port_id> gro",
4784         .tokens = {
4785                 (void *)&cmd_gro_show_show,
4786                 (void *)&cmd_gro_show_port,
4787                 (void *)&cmd_gro_show_pid,
4788                 (void *)&cmd_gro_show_keyword,
4789                 NULL,
4790         },
4791 };
4792
4793 /* *** SET FLUSH CYCLES FOR GRO *** */
4794 struct cmd_gro_flush_result {
4795         cmdline_fixed_string_t cmd_set;
4796         cmdline_fixed_string_t cmd_keyword;
4797         cmdline_fixed_string_t cmd_flush;
4798         uint8_t cmd_cycles;
4799 };
4800
4801 static void
4802 cmd_gro_flush_parsed(void *parsed_result,
4803                 __attribute__((unused)) struct cmdline *cl,
4804                 __attribute__((unused)) void *data)
4805 {
4806         struct cmd_gro_flush_result *res;
4807
4808         res = parsed_result;
4809         if ((!strcmp(res->cmd_keyword, "gro")) &&
4810                         (!strcmp(res->cmd_flush, "flush")))
4811                 setup_gro_flush_cycles(res->cmd_cycles);
4812 }
4813
4814 cmdline_parse_token_string_t cmd_gro_flush_set =
4815         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4816                         cmd_set, "set");
4817 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4818         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4819                         cmd_keyword, "gro");
4820 cmdline_parse_token_string_t cmd_gro_flush_flush =
4821         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4822                         cmd_flush, "flush");
4823 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4824         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4825                         cmd_cycles, UINT8);
4826
4827 cmdline_parse_inst_t cmd_gro_flush = {
4828         .f = cmd_gro_flush_parsed,
4829         .data = NULL,
4830         .help_str = "set gro flush <cycles>",
4831         .tokens = {
4832                 (void *)&cmd_gro_flush_set,
4833                 (void *)&cmd_gro_flush_keyword,
4834                 (void *)&cmd_gro_flush_flush,
4835                 (void *)&cmd_gro_flush_cycles,
4836                 NULL,
4837         },
4838 };
4839
4840 /* *** ENABLE/DISABLE GSO *** */
4841 struct cmd_gso_enable_result {
4842         cmdline_fixed_string_t cmd_set;
4843         cmdline_fixed_string_t cmd_port;
4844         cmdline_fixed_string_t cmd_keyword;
4845         cmdline_fixed_string_t cmd_mode;
4846         portid_t cmd_pid;
4847 };
4848
4849 static void
4850 cmd_gso_enable_parsed(void *parsed_result,
4851                 __attribute__((unused)) struct cmdline *cl,
4852                 __attribute__((unused)) void *data)
4853 {
4854         struct cmd_gso_enable_result *res;
4855
4856         res = parsed_result;
4857         if (!strcmp(res->cmd_keyword, "gso"))
4858                 setup_gso(res->cmd_mode, res->cmd_pid);
4859 }
4860
4861 cmdline_parse_token_string_t cmd_gso_enable_set =
4862         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4863                         cmd_set, "set");
4864 cmdline_parse_token_string_t cmd_gso_enable_port =
4865         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4866                         cmd_port, "port");
4867 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4868         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4869                         cmd_keyword, "gso");
4870 cmdline_parse_token_string_t cmd_gso_enable_mode =
4871         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4872                         cmd_mode, "on#off");
4873 cmdline_parse_token_num_t cmd_gso_enable_pid =
4874         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4875                         cmd_pid, UINT16);
4876
4877 cmdline_parse_inst_t cmd_gso_enable = {
4878         .f = cmd_gso_enable_parsed,
4879         .data = NULL,
4880         .help_str = "set port <port_id> gso on|off",
4881         .tokens = {
4882                 (void *)&cmd_gso_enable_set,
4883                 (void *)&cmd_gso_enable_port,
4884                 (void *)&cmd_gso_enable_pid,
4885                 (void *)&cmd_gso_enable_keyword,
4886                 (void *)&cmd_gso_enable_mode,
4887                 NULL,
4888         },
4889 };
4890
4891 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4892 struct cmd_gso_size_result {
4893         cmdline_fixed_string_t cmd_set;
4894         cmdline_fixed_string_t cmd_keyword;
4895         cmdline_fixed_string_t cmd_segsz;
4896         uint16_t cmd_size;
4897 };
4898
4899 static void
4900 cmd_gso_size_parsed(void *parsed_result,
4901                        __attribute__((unused)) struct cmdline *cl,
4902                        __attribute__((unused)) void *data)
4903 {
4904         struct cmd_gso_size_result *res = parsed_result;
4905
4906         if (test_done == 0) {
4907                 printf("Before setting GSO segsz, please first"
4908                                 " stop fowarding\n");
4909                 return;
4910         }
4911
4912         if (!strcmp(res->cmd_keyword, "gso") &&
4913                         !strcmp(res->cmd_segsz, "segsz")) {
4914                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4915                         printf("gso_size should be larger than %zu."
4916                                         " Please input a legal value\n",
4917                                         RTE_GSO_SEG_SIZE_MIN);
4918                 else
4919                         gso_max_segment_size = res->cmd_size;
4920         }
4921 }
4922
4923 cmdline_parse_token_string_t cmd_gso_size_set =
4924         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4925                                 cmd_set, "set");
4926 cmdline_parse_token_string_t cmd_gso_size_keyword =
4927         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4928                                 cmd_keyword, "gso");
4929 cmdline_parse_token_string_t cmd_gso_size_segsz =
4930         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4931                                 cmd_segsz, "segsz");
4932 cmdline_parse_token_num_t cmd_gso_size_size =
4933         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4934                                 cmd_size, UINT16);
4935
4936 cmdline_parse_inst_t cmd_gso_size = {
4937         .f = cmd_gso_size_parsed,
4938         .data = NULL,
4939         .help_str = "set gso segsz <length>",
4940         .tokens = {
4941                 (void *)&cmd_gso_size_set,
4942                 (void *)&cmd_gso_size_keyword,
4943                 (void *)&cmd_gso_size_segsz,
4944                 (void *)&cmd_gso_size_size,
4945                 NULL,
4946         },
4947 };
4948
4949 /* *** SHOW GSO CONFIGURATION *** */
4950 struct cmd_gso_show_result {
4951         cmdline_fixed_string_t cmd_show;
4952         cmdline_fixed_string_t cmd_port;
4953         cmdline_fixed_string_t cmd_keyword;
4954         portid_t cmd_pid;
4955 };
4956
4957 static void
4958 cmd_gso_show_parsed(void *parsed_result,
4959                        __attribute__((unused)) struct cmdline *cl,
4960                        __attribute__((unused)) void *data)
4961 {
4962         struct cmd_gso_show_result *res = parsed_result;
4963
4964         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4965                 printf("invalid port id %u\n", res->cmd_pid);
4966                 return;
4967         }
4968         if (!strcmp(res->cmd_keyword, "gso")) {
4969                 if (gso_ports[res->cmd_pid].enable) {
4970                         printf("Max GSO'd packet size: %uB\n"
4971                                         "Supported GSO types: TCP/IPv4, "
4972                                         "UDP/IPv4, VxLAN with inner "
4973                                         "TCP/IPv4 packet, GRE with inner "
4974                                         "TCP/IPv4 packet\n",
4975                                         gso_max_segment_size);
4976                 } else
4977                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4978         }
4979 }
4980
4981 cmdline_parse_token_string_t cmd_gso_show_show =
4982 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4983                 cmd_show, "show");
4984 cmdline_parse_token_string_t cmd_gso_show_port =
4985 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4986                 cmd_port, "port");
4987 cmdline_parse_token_string_t cmd_gso_show_keyword =
4988         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4989                                 cmd_keyword, "gso");
4990 cmdline_parse_token_num_t cmd_gso_show_pid =
4991         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4992                                 cmd_pid, UINT16);
4993
4994 cmdline_parse_inst_t cmd_gso_show = {
4995         .f = cmd_gso_show_parsed,
4996         .data = NULL,
4997         .help_str = "show port <port_id> gso",
4998         .tokens = {
4999                 (void *)&cmd_gso_show_show,
5000                 (void *)&cmd_gso_show_port,
5001                 (void *)&cmd_gso_show_pid,
5002                 (void *)&cmd_gso_show_keyword,
5003                 NULL,
5004         },
5005 };
5006
5007 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5008 struct cmd_set_flush_rx {
5009         cmdline_fixed_string_t set;
5010         cmdline_fixed_string_t flush_rx;
5011         cmdline_fixed_string_t mode;
5012 };
5013
5014 static void
5015 cmd_set_flush_rx_parsed(void *parsed_result,
5016                 __attribute__((unused)) struct cmdline *cl,
5017                 __attribute__((unused)) void *data)
5018 {
5019         struct cmd_set_flush_rx *res = parsed_result;
5020         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5021 }
5022
5023 cmdline_parse_token_string_t cmd_setflushrx_set =
5024         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5025                         set, "set");
5026 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5027         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5028                         flush_rx, "flush_rx");
5029 cmdline_parse_token_string_t cmd_setflushrx_mode =
5030         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5031                         mode, "on#off");
5032
5033
5034 cmdline_parse_inst_t cmd_set_flush_rx = {
5035         .f = cmd_set_flush_rx_parsed,
5036         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5037         .data = NULL,
5038         .tokens = {
5039                 (void *)&cmd_setflushrx_set,
5040                 (void *)&cmd_setflushrx_flush_rx,
5041                 (void *)&cmd_setflushrx_mode,
5042                 NULL,
5043         },
5044 };
5045
5046 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5047 struct cmd_set_link_check {
5048         cmdline_fixed_string_t set;
5049         cmdline_fixed_string_t link_check;
5050         cmdline_fixed_string_t mode;
5051 };
5052
5053 static void
5054 cmd_set_link_check_parsed(void *parsed_result,
5055                 __attribute__((unused)) struct cmdline *cl,
5056                 __attribute__((unused)) void *data)
5057 {
5058         struct cmd_set_link_check *res = parsed_result;
5059         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5060 }
5061
5062 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5063         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5064                         set, "set");
5065 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5066         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5067                         link_check, "link_check");
5068 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5069         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5070                         mode, "on#off");
5071
5072
5073 cmdline_parse_inst_t cmd_set_link_check = {
5074         .f = cmd_set_link_check_parsed,
5075         .help_str = "set link_check on|off: Enable/Disable link status check "
5076                     "when starting/stopping a port",
5077         .data = NULL,
5078         .tokens = {
5079                 (void *)&cmd_setlinkcheck_set,
5080                 (void *)&cmd_setlinkcheck_link_check,
5081                 (void *)&cmd_setlinkcheck_mode,
5082                 NULL,
5083         },
5084 };
5085
5086 /* *** SET NIC BYPASS MODE *** */
5087 struct cmd_set_bypass_mode_result {
5088         cmdline_fixed_string_t set;
5089         cmdline_fixed_string_t bypass;
5090         cmdline_fixed_string_t mode;
5091         cmdline_fixed_string_t value;
5092         portid_t port_id;
5093 };
5094
5095 static void
5096 cmd_set_bypass_mode_parsed(void *parsed_result,
5097                 __attribute__((unused)) struct cmdline *cl,
5098                 __attribute__((unused)) void *data)
5099 {
5100         struct cmd_set_bypass_mode_result *res = parsed_result;
5101         portid_t port_id = res->port_id;
5102         int32_t rc = -EINVAL;
5103
5104 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5105         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5106
5107         if (!strcmp(res->value, "bypass"))
5108                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5109         else if (!strcmp(res->value, "isolate"))
5110                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5111         else
5112                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5113
5114         /* Set the bypass mode for the relevant port. */
5115         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5116 #endif
5117         if (rc != 0)
5118                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5119 }
5120
5121 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5122         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5123                         set, "set");
5124 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5125         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5126                         bypass, "bypass");
5127 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5128         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5129                         mode, "mode");
5130 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5131         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5132                         value, "normal#bypass#isolate");
5133 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5134         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5135                                 port_id, UINT16);
5136
5137 cmdline_parse_inst_t cmd_set_bypass_mode = {
5138         .f = cmd_set_bypass_mode_parsed,
5139         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5140                     "Set the NIC bypass mode for port_id",
5141         .data = NULL,
5142         .tokens = {
5143                 (void *)&cmd_setbypass_mode_set,
5144                 (void *)&cmd_setbypass_mode_bypass,
5145                 (void *)&cmd_setbypass_mode_mode,
5146                 (void *)&cmd_setbypass_mode_value,
5147                 (void *)&cmd_setbypass_mode_port,
5148                 NULL,
5149         },
5150 };
5151
5152 /* *** SET NIC BYPASS EVENT *** */
5153 struct cmd_set_bypass_event_result {
5154         cmdline_fixed_string_t set;
5155         cmdline_fixed_string_t bypass;
5156         cmdline_fixed_string_t event;
5157         cmdline_fixed_string_t event_value;
5158         cmdline_fixed_string_t mode;
5159         cmdline_fixed_string_t mode_value;
5160         portid_t port_id;
5161 };
5162
5163 static void
5164 cmd_set_bypass_event_parsed(void *parsed_result,
5165                 __attribute__((unused)) struct cmdline *cl,
5166                 __attribute__((unused)) void *data)
5167 {
5168         int32_t rc = -EINVAL;
5169         struct cmd_set_bypass_event_result *res = parsed_result;
5170         portid_t port_id = res->port_id;
5171
5172 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5173         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5174         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5175
5176         if (!strcmp(res->event_value, "timeout"))
5177                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5178         else if (!strcmp(res->event_value, "os_on"))
5179                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5180         else if (!strcmp(res->event_value, "os_off"))
5181                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5182         else if (!strcmp(res->event_value, "power_on"))
5183                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5184         else if (!strcmp(res->event_value, "power_off"))
5185                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5186         else
5187                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5188
5189         if (!strcmp(res->mode_value, "bypass"))
5190                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5191         else if (!strcmp(res->mode_value, "isolate"))
5192                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5193         else
5194                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5195
5196         /* Set the watchdog timeout. */
5197         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5198
5199                 rc = -EINVAL;
5200                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5201                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5202                                                            bypass_timeout);
5203                 }
5204                 if (rc != 0) {
5205                         printf("Failed to set timeout value %u "
5206                         "for port %d, errto code: %d.\n",
5207                         bypass_timeout, port_id, rc);
5208                 }
5209         }
5210
5211         /* Set the bypass event to transition to bypass mode. */
5212         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5213                                               bypass_mode);
5214 #endif
5215
5216         if (rc != 0)
5217                 printf("\t Failed to set bypass event for port = %d.\n",
5218                        port_id);
5219 }
5220
5221 cmdline_parse_token_string_t cmd_setbypass_event_set =
5222         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5223                         set, "set");
5224 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5225         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5226                         bypass, "bypass");
5227 cmdline_parse_token_string_t cmd_setbypass_event_event =
5228         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5229                         event, "event");
5230 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5231         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5232                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5233 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5234         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5235                         mode, "mode");
5236 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5237         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5238                         mode_value, "normal#bypass#isolate");
5239 cmdline_parse_token_num_t cmd_setbypass_event_port =
5240         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5241                                 port_id, UINT16);
5242
5243 cmdline_parse_inst_t cmd_set_bypass_event = {
5244         .f = cmd_set_bypass_event_parsed,
5245         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5246                 "power_off mode normal|bypass|isolate <port_id>: "
5247                 "Set the NIC bypass event mode for port_id",
5248         .data = NULL,
5249         .tokens = {
5250                 (void *)&cmd_setbypass_event_set,
5251                 (void *)&cmd_setbypass_event_bypass,
5252                 (void *)&cmd_setbypass_event_event,
5253                 (void *)&cmd_setbypass_event_event_value,
5254                 (void *)&cmd_setbypass_event_mode,
5255                 (void *)&cmd_setbypass_event_mode_value,
5256                 (void *)&cmd_setbypass_event_port,
5257                 NULL,
5258         },
5259 };
5260
5261
5262 /* *** SET NIC BYPASS TIMEOUT *** */
5263 struct cmd_set_bypass_timeout_result {
5264         cmdline_fixed_string_t set;
5265         cmdline_fixed_string_t bypass;
5266         cmdline_fixed_string_t timeout;
5267         cmdline_fixed_string_t value;
5268 };
5269
5270 static void
5271 cmd_set_bypass_timeout_parsed(void *parsed_result,
5272                 __attribute__((unused)) struct cmdline *cl,
5273                 __attribute__((unused)) void *data)
5274 {
5275         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5276
5277 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5278         if (!strcmp(res->value, "1.5"))
5279                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5280         else if (!strcmp(res->value, "2"))
5281                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5282         else if (!strcmp(res->value, "3"))
5283                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5284         else if (!strcmp(res->value, "4"))
5285                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5286         else if (!strcmp(res->value, "8"))
5287                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5288         else if (!strcmp(res->value, "16"))
5289                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5290         else if (!strcmp(res->value, "32"))
5291                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5292         else
5293                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5294 #endif
5295 }
5296
5297 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5298         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5299                         set, "set");
5300 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5301         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5302                         bypass, "bypass");
5303 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5304         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5305                         timeout, "timeout");
5306 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5307         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5308                         value, "0#1.5#2#3#4#8#16#32");
5309
5310 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5311         .f = cmd_set_bypass_timeout_parsed,
5312         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5313                 "Set the NIC bypass watchdog timeout in seconds",
5314         .data = NULL,
5315         .tokens = {
5316                 (void *)&cmd_setbypass_timeout_set,
5317                 (void *)&cmd_setbypass_timeout_bypass,
5318                 (void *)&cmd_setbypass_timeout_timeout,
5319                 (void *)&cmd_setbypass_timeout_value,
5320                 NULL,
5321         },
5322 };
5323
5324 /* *** SHOW NIC BYPASS MODE *** */
5325 struct cmd_show_bypass_config_result {
5326         cmdline_fixed_string_t show;
5327         cmdline_fixed_string_t bypass;
5328         cmdline_fixed_string_t config;
5329         portid_t port_id;
5330 };
5331
5332 static void
5333 cmd_show_bypass_config_parsed(void *parsed_result,
5334                 __attribute__((unused)) struct cmdline *cl,
5335                 __attribute__((unused)) void *data)
5336 {
5337         struct cmd_show_bypass_config_result *res = parsed_result;
5338         portid_t port_id = res->port_id;
5339         int rc = -EINVAL;
5340 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5341         uint32_t event_mode;
5342         uint32_t bypass_mode;
5343         uint32_t timeout = bypass_timeout;
5344         int i;
5345
5346         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5347                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5348         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5349                 {"UNKNOWN", "normal", "bypass", "isolate"};
5350         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5351                 "NONE",
5352                 "OS/board on",
5353                 "power supply on",
5354                 "OS/board off",
5355                 "power supply off",
5356                 "timeout"};
5357         int num_events = (sizeof events) / (sizeof events[0]);
5358
5359         /* Display the bypass mode.*/
5360         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5361                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5362                 return;
5363         }
5364         else {
5365                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5366                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5367
5368                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5369         }
5370
5371         /* Display the bypass timeout.*/
5372         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5373                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5374
5375         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5376
5377         /* Display the bypass events and associated modes. */
5378         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5379
5380                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5381                         printf("\tFailed to get bypass mode for event = %s\n",
5382                                 events[i]);
5383                 } else {
5384                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5385                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5386
5387                         printf("\tbypass event: %-16s = %s\n", events[i],
5388                                 modes[event_mode]);
5389                 }
5390         }
5391 #endif
5392         if (rc != 0)
5393                 printf("\tFailed to get bypass configuration for port = %d\n",
5394                        port_id);
5395 }
5396
5397 cmdline_parse_token_string_t cmd_showbypass_config_show =
5398         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5399                         show, "show");
5400 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5401         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5402                         bypass, "bypass");
5403 cmdline_parse_token_string_t cmd_showbypass_config_config =
5404         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5405                         config, "config");
5406 cmdline_parse_token_num_t cmd_showbypass_config_port =
5407         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5408                                 port_id, UINT16);
5409
5410 cmdline_parse_inst_t cmd_show_bypass_config = {
5411         .f = cmd_show_bypass_config_parsed,
5412         .help_str = "show bypass config <port_id>: "
5413                     "Show the NIC bypass config for port_id",
5414         .data = NULL,
5415         .tokens = {
5416                 (void *)&cmd_showbypass_config_show,
5417                 (void *)&cmd_showbypass_config_bypass,
5418                 (void *)&cmd_showbypass_config_config,
5419                 (void *)&cmd_showbypass_config_port,
5420                 NULL,
5421         },
5422 };
5423
5424 #ifdef RTE_LIBRTE_PMD_BOND
5425 /* *** SET BONDING MODE *** */
5426 struct cmd_set_bonding_mode_result {
5427         cmdline_fixed_string_t set;
5428         cmdline_fixed_string_t bonding;
5429         cmdline_fixed_string_t mode;
5430         uint8_t value;
5431         portid_t port_id;
5432 };
5433
5434 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5435                 __attribute__((unused))  struct cmdline *cl,
5436                 __attribute__((unused)) void *data)
5437 {
5438         struct cmd_set_bonding_mode_result *res = parsed_result;
5439         portid_t port_id = res->port_id;
5440
5441         /* Set the bonding mode for the relevant port. */
5442         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5443                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5444 }
5445
5446 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5447 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5448                 set, "set");
5449 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5450 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5451                 bonding, "bonding");
5452 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5453 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5454                 mode, "mode");
5455 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5456 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5457                 value, UINT8);
5458 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5459 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5460                 port_id, UINT16);
5461
5462 cmdline_parse_inst_t cmd_set_bonding_mode = {
5463                 .f = cmd_set_bonding_mode_parsed,
5464                 .help_str = "set bonding mode <mode_value> <port_id>: "
5465                         "Set the bonding mode for port_id",
5466                 .data = NULL,
5467                 .tokens = {
5468                                 (void *) &cmd_setbonding_mode_set,
5469                                 (void *) &cmd_setbonding_mode_bonding,
5470                                 (void *) &cmd_setbonding_mode_mode,
5471                                 (void *) &cmd_setbonding_mode_value,
5472                                 (void *) &cmd_setbonding_mode_port,
5473                                 NULL
5474                 }
5475 };
5476
5477 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5478 struct cmd_set_bonding_lacp_dedicated_queues_result {
5479         cmdline_fixed_string_t set;
5480         cmdline_fixed_string_t bonding;
5481         cmdline_fixed_string_t lacp;
5482         cmdline_fixed_string_t dedicated_queues;
5483         portid_t port_id;
5484         cmdline_fixed_string_t mode;
5485 };
5486
5487 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5488                 __attribute__((unused))  struct cmdline *cl,
5489                 __attribute__((unused)) void *data)
5490 {
5491         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5492         portid_t port_id = res->port_id;
5493         struct rte_port *port;
5494
5495         port = &ports[port_id];
5496
5497         /** Check if the port is not started **/
5498         if (port->port_status != RTE_PORT_STOPPED) {
5499                 printf("Please stop port %d first\n", port_id);
5500                 return;
5501         }
5502
5503         if (!strcmp(res->mode, "enable")) {
5504                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5505                         printf("Dedicate queues for LACP control packets"
5506                                         " enabled\n");
5507                 else
5508                         printf("Enabling dedicate queues for LACP control "
5509                                         "packets on port %d failed\n", port_id);
5510         } else if (!strcmp(res->mode, "disable")) {
5511                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5512                         printf("Dedicated queues for LACP control packets "
5513                                         "disabled\n");
5514                 else
5515                         printf("Disabling dedicated queues for LACP control "
5516                                         "traffic on port %d failed\n", port_id);
5517         }
5518 }
5519
5520 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5521 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5522                 set, "set");
5523 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5524 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5525                 bonding, "bonding");
5526 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5527 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5528                 lacp, "lacp");
5529 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5530 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5531                 dedicated_queues, "dedicated_queues");
5532 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5533 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5534                 port_id, UINT16);
5535 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5536 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5537                 mode, "enable#disable");
5538
5539 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5540                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5541                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5542                         "enable|disable: "
5543                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5544                 .data = NULL,
5545                 .tokens = {
5546                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5547                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5548                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5549                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5550                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5551                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5552                         NULL
5553                 }
5554 };
5555
5556 /* *** SET BALANCE XMIT POLICY *** */
5557 struct cmd_set_bonding_balance_xmit_policy_result {
5558         cmdline_fixed_string_t set;
5559         cmdline_fixed_string_t bonding;
5560         cmdline_fixed_string_t balance_xmit_policy;
5561         portid_t port_id;
5562         cmdline_fixed_string_t policy;
5563 };
5564
5565 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5566                 __attribute__((unused))  struct cmdline *cl,
5567                 __attribute__((unused)) void *data)
5568 {
5569         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5570         portid_t port_id = res->port_id;
5571         uint8_t policy;
5572
5573         if (!strcmp(res->policy, "l2")) {
5574                 policy = BALANCE_XMIT_POLICY_LAYER2;
5575         } else if (!strcmp(res->policy, "l23")) {
5576                 policy = BALANCE_XMIT_POLICY_LAYER23;
5577         } else if (!strcmp(res->policy, "l34")) {
5578                 policy = BALANCE_XMIT_POLICY_LAYER34;
5579         } else {
5580                 printf("\t Invalid xmit policy selection");
5581                 return;
5582         }
5583
5584         /* Set the bonding mode for the relevant port. */
5585         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5586                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5587                                 port_id);
5588         }
5589 }
5590
5591 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5592 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5593                 set, "set");
5594 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5595 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5596                 bonding, "bonding");
5597 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5598 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5599                 balance_xmit_policy, "balance_xmit_policy");
5600 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5601 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5602                 port_id, UINT16);
5603 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5604 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5605                 policy, "l2#l23#l34");
5606
5607 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5608                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5609                 .help_str = "set bonding balance_xmit_policy <port_id> "
5610                         "l2|l23|l34: "
5611                         "Set the bonding balance_xmit_policy for port_id",
5612                 .data = NULL,
5613                 .tokens = {
5614                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5615                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5616                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5617                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5618                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5619                                 NULL
5620                 }
5621 };
5622
5623 /* *** SHOW NIC BONDING CONFIGURATION *** */
5624 struct cmd_show_bonding_config_result {
5625         cmdline_fixed_string_t show;
5626         cmdline_fixed_string_t bonding;
5627         cmdline_fixed_string_t config;
5628         portid_t port_id;
5629 };
5630
5631 static void cmd_show_bonding_config_parsed(void *parsed_result,
5632                 __attribute__((unused))  struct cmdline *cl,
5633                 __attribute__((unused)) void *data)
5634 {
5635         struct cmd_show_bonding_config_result *res = parsed_result;
5636         int bonding_mode, agg_mode;
5637         portid_t slaves[RTE_MAX_ETHPORTS];
5638         int num_slaves, num_active_slaves;
5639         int primary_id;
5640         int i;
5641         portid_t port_id = res->port_id;
5642
5643         /* Display the bonding mode.*/
5644         bonding_mode = rte_eth_bond_mode_get(port_id);
5645         if (bonding_mode < 0) {
5646                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5647                 return;
5648         } else
5649                 printf("\tBonding mode: %d\n", bonding_mode);
5650
5651         if (bonding_mode == BONDING_MODE_BALANCE) {
5652                 int balance_xmit_policy;
5653
5654                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5655                 if (balance_xmit_policy < 0) {
5656                         printf("\tFailed to get balance xmit policy for port = %d\n",
5657                                         port_id);
5658                         return;
5659                 } else {
5660                         printf("\tBalance Xmit Policy: ");
5661
5662                         switch (balance_xmit_policy) {
5663                         case BALANCE_XMIT_POLICY_LAYER2:
5664                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5665                                 break;
5666                         case BALANCE_XMIT_POLICY_LAYER23:
5667                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5668                                 break;
5669                         case BALANCE_XMIT_POLICY_LAYER34:
5670                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5671                                 break;
5672                         }
5673                         printf("\n");
5674                 }
5675         }
5676
5677         if (bonding_mode == BONDING_MODE_8023AD) {
5678                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5679                 printf("\tIEEE802.3AD Aggregator Mode: ");
5680                 switch (agg_mode) {
5681                 case AGG_BANDWIDTH:
5682                         printf("bandwidth");
5683                         break;
5684                 case AGG_STABLE:
5685                         printf("stable");
5686                         break;
5687                 case AGG_COUNT:
5688                         printf("count");
5689                         break;
5690                 }
5691                 printf("\n");
5692         }
5693
5694         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5695
5696         if (num_slaves < 0) {
5697                 printf("\tFailed to get slave list for port = %d\n", port_id);
5698                 return;
5699         }
5700         if (num_slaves > 0) {
5701                 printf("\tSlaves (%d): [", num_slaves);
5702                 for (i = 0; i < num_slaves - 1; i++)
5703                         printf("%d ", slaves[i]);
5704
5705                 printf("%d]\n", slaves[num_slaves - 1]);
5706         } else {
5707                 printf("\tSlaves: []\n");
5708
5709         }
5710
5711         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5712                         RTE_MAX_ETHPORTS);
5713
5714         if (num_active_slaves < 0) {
5715                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5716                 return;
5717         }
5718         if (num_active_slaves > 0) {
5719                 printf("\tActive Slaves (%d): [", num_active_slaves);
5720                 for (i = 0; i < num_active_slaves - 1; i++)
5721                         printf("%d ", slaves[i]);
5722
5723                 printf("%d]\n", slaves[num_active_slaves - 1]);
5724
5725         } else {
5726                 printf("\tActive Slaves: []\n");
5727
5728         }
5729
5730         primary_id = rte_eth_bond_primary_get(port_id);
5731         if (primary_id < 0) {
5732                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5733                 return;
5734         } else
5735                 printf("\tPrimary: [%d]\n", primary_id);
5736
5737 }
5738
5739 cmdline_parse_token_string_t cmd_showbonding_config_show =
5740 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5741                 show, "show");
5742 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5743 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5744                 bonding, "bonding");
5745 cmdline_parse_token_string_t cmd_showbonding_config_config =
5746 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5747                 config, "config");
5748 cmdline_parse_token_num_t cmd_showbonding_config_port =
5749 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5750                 port_id, UINT16);
5751
5752 cmdline_parse_inst_t cmd_show_bonding_config = {
5753                 .f = cmd_show_bonding_config_parsed,
5754                 .help_str = "show bonding config <port_id>: "
5755                         "Show the bonding config for port_id",
5756                 .data = NULL,
5757                 .tokens = {
5758                                 (void *)&cmd_showbonding_config_show,
5759                                 (void *)&cmd_showbonding_config_bonding,
5760                                 (void *)&cmd_showbonding_config_config,
5761                                 (void *)&cmd_showbonding_config_port,
5762                                 NULL
5763                 }
5764 };
5765
5766 /* *** SET BONDING PRIMARY *** */
5767 struct cmd_set_bonding_primary_result {
5768         cmdline_fixed_string_t set;
5769         cmdline_fixed_string_t bonding;
5770         cmdline_fixed_string_t primary;
5771         portid_t slave_id;
5772         portid_t port_id;
5773 };
5774
5775 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5776                 __attribute__((unused))  struct cmdline *cl,
5777                 __attribute__((unused)) void *data)
5778 {
5779         struct cmd_set_bonding_primary_result *res = parsed_result;
5780         portid_t master_port_id = res->port_id;
5781         portid_t slave_port_id = res->slave_id;
5782
5783         /* Set the primary slave for a bonded device. */
5784         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5785                 printf("\t Failed to set primary slave for port = %d.\n",
5786                                 master_port_id);
5787                 return;
5788         }
5789         init_port_config();
5790 }
5791
5792 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5793 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5794                 set, "set");
5795 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5796 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5797                 bonding, "bonding");
5798 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5799 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5800                 primary, "primary");
5801 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5802 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5803                 slave_id, UINT16);
5804 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5805 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5806                 port_id, UINT16);
5807
5808 cmdline_parse_inst_t cmd_set_bonding_primary = {
5809                 .f = cmd_set_bonding_primary_parsed,
5810                 .help_str = "set bonding primary <slave_id> <port_id>: "
5811                         "Set the primary slave for port_id",
5812                 .data = NULL,
5813                 .tokens = {
5814                                 (void *)&cmd_setbonding_primary_set,
5815                                 (void *)&cmd_setbonding_primary_bonding,
5816                                 (void *)&cmd_setbonding_primary_primary,
5817                                 (void *)&cmd_setbonding_primary_slave,
5818                                 (void *)&cmd_setbonding_primary_port,
5819                                 NULL
5820                 }
5821 };
5822
5823 /* *** ADD SLAVE *** */
5824 struct cmd_add_bonding_slave_result {
5825         cmdline_fixed_string_t add;
5826         cmdline_fixed_string_t bonding;
5827         cmdline_fixed_string_t slave;
5828         portid_t slave_id;
5829         portid_t port_id;
5830 };
5831
5832 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5833                 __attribute__((unused))  struct cmdline *cl,
5834                 __attribute__((unused)) void *data)
5835 {
5836         struct cmd_add_bonding_slave_result *res = parsed_result;
5837         portid_t master_port_id = res->port_id;
5838         portid_t slave_port_id = res->slave_id;
5839
5840         /* add the slave for a bonded device. */
5841         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5842                 printf("\t Failed to add slave %d to master port = %d.\n",
5843                                 slave_port_id, master_port_id);
5844                 return;
5845         }
5846         init_port_config();
5847         set_port_slave_flag(slave_port_id);
5848 }
5849
5850 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5851 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5852                 add, "add");
5853 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5854 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5855                 bonding, "bonding");
5856 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5857 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5858                 slave, "slave");
5859 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5860 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5861                 slave_id, UINT16);
5862 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5863 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5864                 port_id, UINT16);
5865
5866 cmdline_parse_inst_t cmd_add_bonding_slave = {
5867                 .f = cmd_add_bonding_slave_parsed,
5868                 .help_str = "add bonding slave <slave_id> <port_id>: "
5869                         "Add a slave device to a bonded device",
5870                 .data = NULL,
5871                 .tokens = {
5872                                 (void *)&cmd_addbonding_slave_add,
5873                                 (void *)&cmd_addbonding_slave_bonding,
5874                                 (void *)&cmd_addbonding_slave_slave,
5875                                 (void *)&cmd_addbonding_slave_slaveid,
5876                                 (void *)&cmd_addbonding_slave_port,
5877                                 NULL
5878                 }
5879 };
5880
5881 /* *** REMOVE SLAVE *** */
5882 struct cmd_remove_bonding_slave_result {
5883         cmdline_fixed_string_t remove;
5884         cmdline_fixed_string_t bonding;
5885         cmdline_fixed_string_t slave;
5886         portid_t slave_id;
5887         portid_t port_id;
5888 };
5889
5890 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5891                 __attribute__((unused))  struct cmdline *cl,
5892                 __attribute__((unused)) void *data)
5893 {
5894         struct cmd_remove_bonding_slave_result *res = parsed_result;
5895         portid_t master_port_id = res->port_id;
5896         portid_t slave_port_id = res->slave_id;
5897
5898         /* remove the slave from a bonded device. */
5899         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5900                 printf("\t Failed to remove slave %d from master port = %d.\n",
5901                                 slave_port_id, master_port_id);
5902                 return;
5903         }
5904         init_port_config();
5905         clear_port_slave_flag(slave_port_id);
5906 }
5907
5908 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5909                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5910                                 remove, "remove");
5911 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5912                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5913                                 bonding, "bonding");
5914 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5915                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5916                                 slave, "slave");
5917 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5918                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5919                                 slave_id, UINT16);
5920 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5921                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5922                                 port_id, UINT16);
5923
5924 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5925                 .f = cmd_remove_bonding_slave_parsed,
5926                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5927                         "Remove a slave device from a bonded device",
5928                 .data = NULL,
5929                 .tokens = {
5930                                 (void *)&cmd_removebonding_slave_remove,
5931                                 (void *)&cmd_removebonding_slave_bonding,
5932                                 (void *)&cmd_removebonding_slave_slave,
5933                                 (void *)&cmd_removebonding_slave_slaveid,
5934                                 (void *)&cmd_removebonding_slave_port,
5935                                 NULL
5936                 }
5937 };
5938
5939 /* *** CREATE BONDED DEVICE *** */
5940 struct cmd_create_bonded_device_result {
5941         cmdline_fixed_string_t create;
5942         cmdline_fixed_string_t bonded;
5943         cmdline_fixed_string_t device;
5944         uint8_t mode;
5945         uint8_t socket;
5946 };
5947
5948 static int bond_dev_num = 0;
5949
5950 static void cmd_create_bonded_device_parsed(void *parsed_result,
5951                 __attribute__((unused))  struct cmdline *cl,
5952                 __attribute__((unused)) void *data)
5953 {
5954         struct cmd_create_bonded_device_result *res = parsed_result;
5955         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5956         int port_id;
5957
5958         if (test_done == 0) {
5959                 printf("Please stop forwarding first\n");
5960                 return;
5961         }
5962
5963         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5964                         bond_dev_num++);
5965
5966         /* Create a new bonded device. */
5967         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5968         if (port_id < 0) {
5969                 printf("\t Failed to create bonded device.\n");
5970                 return;
5971         } else {
5972                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5973                                 port_id);
5974
5975                 /* Update number of ports */
5976                 nb_ports = rte_eth_dev_count_avail();
5977                 reconfig(port_id, res->socket);
5978                 rte_eth_promiscuous_enable(port_id);
5979         }
5980
5981 }
5982
5983 cmdline_parse_token_string_t cmd_createbonded_device_create =
5984                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5985                                 create, "create");
5986 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5987                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5988                                 bonded, "bonded");
5989 cmdline_parse_token_string_t cmd_createbonded_device_device =
5990                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5991                                 device, "device");
5992 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5993                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5994                                 mode, UINT8);
5995 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5996                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5997                                 socket, UINT8);
5998
5999 cmdline_parse_inst_t cmd_create_bonded_device = {
6000                 .f = cmd_create_bonded_device_parsed,
6001                 .help_str = "create bonded device <mode> <socket>: "
6002                         "Create a new bonded device with specific bonding mode and socket",
6003                 .data = NULL,
6004                 .tokens = {
6005                                 (void *)&cmd_createbonded_device_create,
6006                                 (void *)&cmd_createbonded_device_bonded,
6007                                 (void *)&cmd_createbonded_device_device,
6008                                 (void *)&cmd_createbonded_device_mode,
6009                                 (void *)&cmd_createbonded_device_socket,
6010                                 NULL
6011                 }
6012 };
6013
6014 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6015 struct cmd_set_bond_mac_addr_result {
6016         cmdline_fixed_string_t set;
6017         cmdline_fixed_string_t bonding;
6018         cmdline_fixed_string_t mac_addr;
6019         uint16_t port_num;
6020         struct ether_addr address;
6021 };
6022
6023 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6024                 __attribute__((unused))  struct cmdline *cl,
6025                 __attribute__((unused)) void *data)
6026 {
6027         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6028         int ret;
6029
6030         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6031                 return;
6032
6033         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6034
6035         /* check the return value and print it if is < 0 */
6036         if (ret < 0)
6037                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6038 }
6039
6040 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6041                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6042 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6043                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6044                                 "bonding");
6045 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6046                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6047                                 "mac_addr");
6048 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6049                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6050                                 port_num, UINT16);
6051 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6052                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6053
6054 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6055                 .f = cmd_set_bond_mac_addr_parsed,
6056                 .data = (void *) 0,
6057                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6058                 .tokens = {
6059                                 (void *)&cmd_set_bond_mac_addr_set,
6060                                 (void *)&cmd_set_bond_mac_addr_bonding,
6061                                 (void *)&cmd_set_bond_mac_addr_mac,
6062                                 (void *)&cmd_set_bond_mac_addr_portnum,
6063                                 (void *)&cmd_set_bond_mac_addr_addr,
6064                                 NULL
6065                 }
6066 };
6067
6068
6069 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6070 struct cmd_set_bond_mon_period_result {
6071         cmdline_fixed_string_t set;
6072         cmdline_fixed_string_t bonding;
6073         cmdline_fixed_string_t mon_period;
6074         uint16_t port_num;
6075         uint32_t period_ms;
6076 };
6077
6078 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6079                 __attribute__((unused))  struct cmdline *cl,
6080                 __attribute__((unused)) void *data)
6081 {
6082         struct cmd_set_bond_mon_period_result *res = parsed_result;
6083         int ret;
6084
6085         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6086
6087         /* check the return value and print it if is < 0 */
6088         if (ret < 0)
6089                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6090 }
6091
6092 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6093                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6094                                 set, "set");
6095 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6096                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6097                                 bonding, "bonding");
6098 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6099                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6100                                 mon_period,     "mon_period");
6101 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6102                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6103                                 port_num, UINT16);
6104 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6105                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6106                                 period_ms, UINT32);
6107
6108 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6109                 .f = cmd_set_bond_mon_period_parsed,
6110                 .data = (void *) 0,
6111                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6112                 .tokens = {
6113                                 (void *)&cmd_set_bond_mon_period_set,
6114                                 (void *)&cmd_set_bond_mon_period_bonding,
6115                                 (void *)&cmd_set_bond_mon_period_mon_period,
6116                                 (void *)&cmd_set_bond_mon_period_portnum,
6117                                 (void *)&cmd_set_bond_mon_period_period_ms,
6118                                 NULL
6119                 }
6120 };
6121
6122
6123
6124 struct cmd_set_bonding_agg_mode_policy_result {
6125         cmdline_fixed_string_t set;
6126         cmdline_fixed_string_t bonding;
6127         cmdline_fixed_string_t agg_mode;
6128         uint16_t port_num;
6129         cmdline_fixed_string_t policy;
6130 };
6131
6132
6133 static void
6134 cmd_set_bonding_agg_mode(void *parsed_result,
6135                 __attribute__((unused)) struct cmdline *cl,
6136                 __attribute__((unused)) void *data)
6137 {
6138         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6139         uint8_t policy = AGG_BANDWIDTH;
6140
6141         if (!strcmp(res->policy, "bandwidth"))
6142                 policy = AGG_BANDWIDTH;
6143         else if (!strcmp(res->policy, "stable"))
6144                 policy = AGG_STABLE;
6145         else if (!strcmp(res->policy, "count"))
6146                 policy = AGG_COUNT;
6147
6148         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6149 }
6150
6151
6152 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6153         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6154                                 set, "set");
6155 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6156         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6157                                 bonding, "bonding");
6158
6159 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6160         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6161                                 agg_mode, "agg_mode");
6162
6163 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6164         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6165                                 port_num, UINT16);
6166
6167 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6168         TOKEN_STRING_INITIALIZER(
6169                         struct cmd_set_bonding_balance_xmit_policy_result,
6170                 policy, "stable#bandwidth#count");
6171
6172 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6173         .f = cmd_set_bonding_agg_mode,
6174         .data = (void *) 0,
6175         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6176         .tokens = {
6177                         (void *)&cmd_set_bonding_agg_mode_set,
6178                         (void *)&cmd_set_bonding_agg_mode_bonding,
6179                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6180                         (void *)&cmd_set_bonding_agg_mode_portnum,
6181                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6182                         NULL
6183                 }
6184 };
6185
6186
6187 #endif /* RTE_LIBRTE_PMD_BOND */
6188
6189 /* *** SET FORWARDING MODE *** */
6190 struct cmd_set_fwd_mode_result {
6191         cmdline_fixed_string_t set;
6192         cmdline_fixed_string_t fwd;
6193         cmdline_fixed_string_t mode;
6194 };
6195
6196 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6197                                     __attribute__((unused)) struct cmdline *cl,
6198                                     __attribute__((unused)) void *data)
6199 {
6200         struct cmd_set_fwd_mode_result *res = parsed_result;
6201
6202         retry_enabled = 0;
6203         set_pkt_forwarding_mode(res->mode);
6204 }
6205
6206 cmdline_parse_token_string_t cmd_setfwd_set =
6207         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6208 cmdline_parse_token_string_t cmd_setfwd_fwd =
6209         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6210 cmdline_parse_token_string_t cmd_setfwd_mode =
6211         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6212                 "" /* defined at init */);
6213
6214 cmdline_parse_inst_t cmd_set_fwd_mode = {
6215         .f = cmd_set_fwd_mode_parsed,
6216         .data = NULL,
6217         .help_str = NULL, /* defined at init */
6218         .tokens = {
6219                 (void *)&cmd_setfwd_set,
6220                 (void *)&cmd_setfwd_fwd,
6221                 (void *)&cmd_setfwd_mode,
6222                 NULL,
6223         },
6224 };
6225
6226 static void cmd_set_fwd_mode_init(void)
6227 {
6228         char *modes, *c;
6229         static char token[128];
6230         static char help[256];
6231         cmdline_parse_token_string_t *token_struct;
6232
6233         modes = list_pkt_forwarding_modes();
6234         snprintf(help, sizeof(help), "set fwd %s: "
6235                 "Set packet forwarding mode", modes);
6236         cmd_set_fwd_mode.help_str = help;
6237
6238         /* string token separator is # */
6239         for (c = token; *modes != '\0'; modes++)
6240                 if (*modes == '|')
6241                         *c++ = '#';
6242                 else
6243                         *c++ = *modes;
6244         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6245         token_struct->string_data.str = token;
6246 }
6247
6248 /* *** SET RETRY FORWARDING MODE *** */
6249 struct cmd_set_fwd_retry_mode_result {
6250         cmdline_fixed_string_t set;
6251         cmdline_fixed_string_t fwd;
6252         cmdline_fixed_string_t mode;
6253         cmdline_fixed_string_t retry;
6254 };
6255
6256 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6257                             __attribute__((unused)) struct cmdline *cl,
6258                             __attribute__((unused)) void *data)
6259 {
6260         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6261
6262         retry_enabled = 1;
6263         set_pkt_forwarding_mode(res->mode);
6264 }
6265
6266 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6267         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6268                         set, "set");
6269 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6270         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6271                         fwd, "fwd");
6272 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6273         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6274                         mode,
6275                 "" /* defined at init */);
6276 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6277         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6278                         retry, "retry");
6279
6280 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6281         .f = cmd_set_fwd_retry_mode_parsed,
6282         .data = NULL,
6283         .help_str = NULL, /* defined at init */
6284         .tokens = {
6285                 (void *)&cmd_setfwd_retry_set,
6286                 (void *)&cmd_setfwd_retry_fwd,
6287                 (void *)&cmd_setfwd_retry_mode,
6288                 (void *)&cmd_setfwd_retry_retry,
6289                 NULL,
6290         },
6291 };
6292
6293 static void cmd_set_fwd_retry_mode_init(void)
6294 {
6295         char *modes, *c;
6296         static char token[128];
6297         static char help[256];
6298         cmdline_parse_token_string_t *token_struct;
6299
6300         modes = list_pkt_forwarding_retry_modes();
6301         snprintf(help, sizeof(help), "set fwd %s retry: "
6302                 "Set packet forwarding mode with retry", modes);
6303         cmd_set_fwd_retry_mode.help_str = help;
6304
6305         /* string token separator is # */
6306         for (c = token; *modes != '\0'; modes++)
6307                 if (*modes == '|')
6308                         *c++ = '#';
6309                 else
6310                         *c++ = *modes;
6311         token_struct = (cmdline_parse_token_string_t *)
6312                 cmd_set_fwd_retry_mode.tokens[2];
6313         token_struct->string_data.str = token;
6314 }
6315
6316 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6317 struct cmd_set_burst_tx_retry_result {
6318         cmdline_fixed_string_t set;
6319         cmdline_fixed_string_t burst;
6320         cmdline_fixed_string_t tx;
6321         cmdline_fixed_string_t delay;
6322         uint32_t time;
6323         cmdline_fixed_string_t retry;
6324         uint32_t retry_num;
6325 };
6326
6327 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6328                                         __attribute__((unused)) struct cmdline *cl,
6329                                         __attribute__((unused)) void *data)
6330 {
6331         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6332
6333         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6334                 && !strcmp(res->tx, "tx")) {
6335                 if (!strcmp(res->delay, "delay"))
6336                         burst_tx_delay_time = res->time;
6337                 if (!strcmp(res->retry, "retry"))
6338                         burst_tx_retry_num = res->retry_num;
6339         }
6340
6341 }
6342
6343 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6344         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6345 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6346         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6347                                  "burst");
6348 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6349         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6350 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6351         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6352 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6353         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6354 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6355         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6356 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6357         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6358
6359 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6360         .f = cmd_set_burst_tx_retry_parsed,
6361         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6362         .tokens = {
6363                 (void *)&cmd_set_burst_tx_retry_set,
6364                 (void *)&cmd_set_burst_tx_retry_burst,
6365                 (void *)&cmd_set_burst_tx_retry_tx,
6366                 (void *)&cmd_set_burst_tx_retry_delay,
6367                 (void *)&cmd_set_burst_tx_retry_time,
6368                 (void *)&cmd_set_burst_tx_retry_retry,
6369                 (void *)&cmd_set_burst_tx_retry_retry_num,
6370                 NULL,
6371         },
6372 };
6373
6374 /* *** SET PROMISC MODE *** */
6375 struct cmd_set_promisc_mode_result {
6376         cmdline_fixed_string_t set;
6377         cmdline_fixed_string_t promisc;
6378         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6379         uint16_t port_num;               /* valid if "allports" argument == 0 */
6380         cmdline_fixed_string_t mode;
6381 };
6382
6383 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6384                                         __attribute__((unused)) struct cmdline *cl,
6385                                         void *allports)
6386 {
6387         struct cmd_set_promisc_mode_result *res = parsed_result;
6388         int enable;
6389         portid_t i;
6390
6391         if (!strcmp(res->mode, "on"))
6392                 enable = 1;
6393         else
6394                 enable = 0;
6395
6396         /* all ports */
6397         if (allports) {
6398                 RTE_ETH_FOREACH_DEV(i) {
6399                         if (enable)
6400                                 rte_eth_promiscuous_enable(i);
6401                         else
6402                                 rte_eth_promiscuous_disable(i);
6403                 }
6404         }
6405         else {
6406                 if (enable)
6407                         rte_eth_promiscuous_enable(res->port_num);
6408                 else
6409                         rte_eth_promiscuous_disable(res->port_num);
6410         }
6411 }
6412
6413 cmdline_parse_token_string_t cmd_setpromisc_set =
6414         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6415 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6416         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6417                                  "promisc");
6418 cmdline_parse_token_string_t cmd_setpromisc_portall =
6419         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6420                                  "all");
6421 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6422         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6423                               UINT16);
6424 cmdline_parse_token_string_t cmd_setpromisc_mode =
6425         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6426                                  "on#off");
6427
6428 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6429         .f = cmd_set_promisc_mode_parsed,
6430         .data = (void *)1,
6431         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6432         .tokens = {
6433                 (void *)&cmd_setpromisc_set,
6434                 (void *)&cmd_setpromisc_promisc,
6435                 (void *)&cmd_setpromisc_portall,
6436                 (void *)&cmd_setpromisc_mode,
6437                 NULL,
6438         },
6439 };
6440
6441 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6442         .f = cmd_set_promisc_mode_parsed,
6443         .data = (void *)0,
6444         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6445         .tokens = {
6446                 (void *)&cmd_setpromisc_set,
6447                 (void *)&cmd_setpromisc_promisc,
6448                 (void *)&cmd_setpromisc_portnum,
6449                 (void *)&cmd_setpromisc_mode,
6450                 NULL,
6451         },
6452 };
6453
6454 /* *** SET ALLMULTI MODE *** */
6455 struct cmd_set_allmulti_mode_result {
6456         cmdline_fixed_string_t set;
6457         cmdline_fixed_string_t allmulti;
6458         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6459         uint16_t port_num;               /* valid if "allports" argument == 0 */
6460         cmdline_fixed_string_t mode;
6461 };
6462
6463 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6464                                         __attribute__((unused)) struct cmdline *cl,
6465                                         void *allports)
6466 {
6467         struct cmd_set_allmulti_mode_result *res = parsed_result;
6468         int enable;
6469         portid_t i;
6470
6471         if (!strcmp(res->mode, "on"))
6472                 enable = 1;
6473         else
6474                 enable = 0;
6475
6476         /* all ports */
6477         if (allports) {
6478                 RTE_ETH_FOREACH_DEV(i) {
6479                         if (enable)
6480                                 rte_eth_allmulticast_enable(i);
6481                         else
6482                                 rte_eth_allmulticast_disable(i);
6483                 }
6484         }
6485         else {
6486                 if (enable)
6487                         rte_eth_allmulticast_enable(res->port_num);
6488                 else
6489                         rte_eth_allmulticast_disable(res->port_num);
6490         }
6491 }
6492
6493 cmdline_parse_token_string_t cmd_setallmulti_set =
6494         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6495 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6496         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6497                                  "allmulti");
6498 cmdline_parse_token_string_t cmd_setallmulti_portall =
6499         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6500                                  "all");
6501 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6502         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6503                               UINT16);
6504 cmdline_parse_token_string_t cmd_setallmulti_mode =
6505         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6506                                  "on#off");
6507
6508 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6509         .f = cmd_set_allmulti_mode_parsed,
6510         .data = (void *)1,
6511         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6512         .tokens = {
6513                 (void *)&cmd_setallmulti_set,
6514                 (void *)&cmd_setallmulti_allmulti,
6515                 (void *)&cmd_setallmulti_portall,
6516                 (void *)&cmd_setallmulti_mode,
6517                 NULL,
6518         },
6519 };
6520
6521 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6522         .f = cmd_set_allmulti_mode_parsed,
6523         .data = (void *)0,
6524         .help_str = "set allmulti <port_id> on|off: "
6525                 "Set allmulti mode on port_id",
6526         .tokens = {
6527                 (void *)&cmd_setallmulti_set,
6528                 (void *)&cmd_setallmulti_allmulti,
6529                 (void *)&cmd_setallmulti_portnum,
6530                 (void *)&cmd_setallmulti_mode,
6531                 NULL,
6532         },
6533 };
6534
6535 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6536 struct cmd_link_flow_ctrl_set_result {
6537         cmdline_fixed_string_t set;
6538         cmdline_fixed_string_t flow_ctrl;
6539         cmdline_fixed_string_t rx;
6540         cmdline_fixed_string_t rx_lfc_mode;
6541         cmdline_fixed_string_t tx;
6542         cmdline_fixed_string_t tx_lfc_mode;
6543         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6544         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6545         cmdline_fixed_string_t autoneg_str;
6546         cmdline_fixed_string_t autoneg;
6547         cmdline_fixed_string_t hw_str;
6548         uint32_t high_water;
6549         cmdline_fixed_string_t lw_str;
6550         uint32_t low_water;
6551         cmdline_fixed_string_t pt_str;
6552         uint16_t pause_time;
6553         cmdline_fixed_string_t xon_str;
6554         uint16_t send_xon;
6555         portid_t port_id;
6556 };
6557
6558 cmdline_parse_token_string_t cmd_lfc_set_set =
6559         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6560                                 set, "set");
6561 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6562         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6563                                 flow_ctrl, "flow_ctrl");
6564 cmdline_parse_token_string_t cmd_lfc_set_rx =
6565         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6566                                 rx, "rx");
6567 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6568         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6569                                 rx_lfc_mode, "on#off");
6570 cmdline_parse_token_string_t cmd_lfc_set_tx =
6571         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6572                                 tx, "tx");
6573 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6574         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6575                                 tx_lfc_mode, "on#off");
6576 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6577         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6578                                 hw_str, "high_water");
6579 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6580         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6581                                 high_water, UINT32);
6582 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6583         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6584                                 lw_str, "low_water");
6585 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6586         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6587                                 low_water, UINT32);
6588 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6589         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6590                                 pt_str, "pause_time");
6591 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6592         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6593                                 pause_time, UINT16);
6594 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6595         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6596                                 xon_str, "send_xon");
6597 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6598         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6599                                 send_xon, UINT16);
6600 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6601         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6602                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6603 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6604         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6605                                 mac_ctrl_frame_fwd_mode, "on#off");
6606 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6607         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6608                                 autoneg_str, "autoneg");
6609 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6610         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6611                                 autoneg, "on#off");
6612 cmdline_parse_token_num_t cmd_lfc_set_portid =
6613         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6614                                 port_id, UINT16);
6615
6616 /* forward declaration */
6617 static void
6618 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6619                               void *data);
6620
6621 cmdline_parse_inst_t cmd_link_flow_control_set = {
6622         .f = cmd_link_flow_ctrl_set_parsed,
6623         .data = NULL,
6624         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6625                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6626                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6627         .tokens = {
6628                 (void *)&cmd_lfc_set_set,
6629                 (void *)&cmd_lfc_set_flow_ctrl,
6630                 (void *)&cmd_lfc_set_rx,
6631                 (void *)&cmd_lfc_set_rx_mode,
6632                 (void *)&cmd_lfc_set_tx,
6633                 (void *)&cmd_lfc_set_tx_mode,
6634                 (void *)&cmd_lfc_set_high_water,
6635                 (void *)&cmd_lfc_set_low_water,
6636                 (void *)&cmd_lfc_set_pause_time,
6637                 (void *)&cmd_lfc_set_send_xon,
6638                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6639                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6640                 (void *)&cmd_lfc_set_autoneg_str,
6641                 (void *)&cmd_lfc_set_autoneg,
6642                 (void *)&cmd_lfc_set_portid,
6643                 NULL,
6644         },
6645 };
6646
6647 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6648         .f = cmd_link_flow_ctrl_set_parsed,
6649         .data = (void *)&cmd_link_flow_control_set_rx,
6650         .help_str = "set flow_ctrl rx on|off <port_id>: "
6651                 "Change rx flow control parameter",
6652         .tokens = {
6653                 (void *)&cmd_lfc_set_set,
6654                 (void *)&cmd_lfc_set_flow_ctrl,
6655                 (void *)&cmd_lfc_set_rx,
6656                 (void *)&cmd_lfc_set_rx_mode,
6657                 (void *)&cmd_lfc_set_portid,
6658                 NULL,
6659         },
6660 };
6661
6662 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6663         .f = cmd_link_flow_ctrl_set_parsed,
6664         .data = (void *)&cmd_link_flow_control_set_tx,
6665         .help_str = "set flow_ctrl tx on|off <port_id>: "
6666                 "Change tx flow control parameter",
6667         .tokens = {
6668                 (void *)&cmd_lfc_set_set,
6669                 (void *)&cmd_lfc_set_flow_ctrl,
6670                 (void *)&cmd_lfc_set_tx,
6671                 (void *)&cmd_lfc_set_tx_mode,
6672                 (void *)&cmd_lfc_set_portid,
6673                 NULL,
6674         },
6675 };
6676
6677 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6678         .f = cmd_link_flow_ctrl_set_parsed,
6679         .data = (void *)&cmd_link_flow_control_set_hw,
6680         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6681                 "Change high water flow control parameter",
6682         .tokens = {
6683                 (void *)&cmd_lfc_set_set,
6684                 (void *)&cmd_lfc_set_flow_ctrl,
6685                 (void *)&cmd_lfc_set_high_water_str,
6686                 (void *)&cmd_lfc_set_high_water,
6687                 (void *)&cmd_lfc_set_portid,
6688                 NULL,
6689         },
6690 };
6691
6692 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6693         .f = cmd_link_flow_ctrl_set_parsed,
6694         .data = (void *)&cmd_link_flow_control_set_lw,
6695         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6696                 "Change low water flow control parameter",
6697         .tokens = {
6698                 (void *)&cmd_lfc_set_set,
6699                 (void *)&cmd_lfc_set_flow_ctrl,
6700                 (void *)&cmd_lfc_set_low_water_str,
6701                 (void *)&cmd_lfc_set_low_water,
6702                 (void *)&cmd_lfc_set_portid,
6703                 NULL,
6704         },
6705 };
6706
6707 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6708         .f = cmd_link_flow_ctrl_set_parsed,
6709         .data = (void *)&cmd_link_flow_control_set_pt,
6710         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6711                 "Change pause time flow control parameter",
6712         .tokens = {
6713                 (void *)&cmd_lfc_set_set,
6714                 (void *)&cmd_lfc_set_flow_ctrl,
6715                 (void *)&cmd_lfc_set_pause_time_str,
6716                 (void *)&cmd_lfc_set_pause_time,
6717                 (void *)&cmd_lfc_set_portid,
6718                 NULL,
6719         },
6720 };
6721
6722 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6723         .f = cmd_link_flow_ctrl_set_parsed,
6724         .data = (void *)&cmd_link_flow_control_set_xon,
6725         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6726                 "Change send_xon flow control parameter",
6727         .tokens = {
6728                 (void *)&cmd_lfc_set_set,
6729                 (void *)&cmd_lfc_set_flow_ctrl,
6730                 (void *)&cmd_lfc_set_send_xon_str,
6731                 (void *)&cmd_lfc_set_send_xon,
6732                 (void *)&cmd_lfc_set_portid,
6733                 NULL,
6734         },
6735 };
6736
6737 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6738         .f = cmd_link_flow_ctrl_set_parsed,
6739         .data = (void *)&cmd_link_flow_control_set_macfwd,
6740         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6741                 "Change mac ctrl fwd flow control parameter",
6742         .tokens = {
6743                 (void *)&cmd_lfc_set_set,
6744                 (void *)&cmd_lfc_set_flow_ctrl,
6745                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6746                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6747                 (void *)&cmd_lfc_set_portid,
6748                 NULL,
6749         },
6750 };
6751
6752 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6753         .f = cmd_link_flow_ctrl_set_parsed,
6754         .data = (void *)&cmd_link_flow_control_set_autoneg,
6755         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6756                 "Change autoneg flow control parameter",
6757         .tokens = {
6758                 (void *)&cmd_lfc_set_set,
6759                 (void *)&cmd_lfc_set_flow_ctrl,
6760                 (void *)&cmd_lfc_set_autoneg_str,
6761                 (void *)&cmd_lfc_set_autoneg,
6762                 (void *)&cmd_lfc_set_portid,
6763                 NULL,
6764         },
6765 };
6766
6767 static void
6768 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6769                               __attribute__((unused)) struct cmdline *cl,
6770                               void *data)
6771 {
6772         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6773         cmdline_parse_inst_t *cmd = data;
6774         struct rte_eth_fc_conf fc_conf;
6775         int rx_fc_en = 0;
6776         int tx_fc_en = 0;
6777         int ret;
6778
6779         /*
6780          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6781          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6782          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6783          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6784          */
6785         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6786                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6787         };
6788
6789         /* Partial command line, retrieve current configuration */
6790         if (cmd) {
6791                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6792                 if (ret != 0) {
6793                         printf("cannot get current flow ctrl parameters, return"
6794                                "code = %d\n", ret);
6795                         return;
6796                 }
6797
6798                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6799                     (fc_conf.mode == RTE_FC_FULL))
6800                         rx_fc_en = 1;
6801                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6802                     (fc_conf.mode == RTE_FC_FULL))
6803                         tx_fc_en = 1;
6804         }
6805
6806         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6807                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6808
6809         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6810                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6811
6812         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6813
6814         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6815                 fc_conf.high_water = res->high_water;
6816
6817         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6818                 fc_conf.low_water = res->low_water;
6819
6820         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6821                 fc_conf.pause_time = res->pause_time;
6822
6823         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6824                 fc_conf.send_xon = res->send_xon;
6825
6826         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6827                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6828                         fc_conf.mac_ctrl_frame_fwd = 1;
6829                 else
6830                         fc_conf.mac_ctrl_frame_fwd = 0;
6831         }
6832
6833         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6834                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6835
6836         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6837         if (ret != 0)
6838                 printf("bad flow contrl parameter, return code = %d \n", ret);
6839 }
6840
6841 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6842 struct cmd_priority_flow_ctrl_set_result {
6843         cmdline_fixed_string_t set;
6844         cmdline_fixed_string_t pfc_ctrl;
6845         cmdline_fixed_string_t rx;
6846         cmdline_fixed_string_t rx_pfc_mode;
6847         cmdline_fixed_string_t tx;
6848         cmdline_fixed_string_t tx_pfc_mode;
6849         uint32_t high_water;
6850         uint32_t low_water;
6851         uint16_t pause_time;
6852         uint8_t  priority;
6853         portid_t port_id;
6854 };
6855
6856 static void
6857 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6858                        __attribute__((unused)) struct cmdline *cl,
6859                        __attribute__((unused)) void *data)
6860 {
6861         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6862         struct rte_eth_pfc_conf pfc_conf;
6863         int rx_fc_enable, tx_fc_enable;
6864         int ret;
6865
6866         /*
6867          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6868          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6869          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6870          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6871          */
6872         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6873                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6874         };
6875
6876         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6877         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6878         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6879         pfc_conf.fc.high_water = res->high_water;
6880         pfc_conf.fc.low_water  = res->low_water;
6881         pfc_conf.fc.pause_time = res->pause_time;
6882         pfc_conf.priority      = res->priority;
6883
6884         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6885         if (ret != 0)
6886                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6887 }
6888
6889 cmdline_parse_token_string_t cmd_pfc_set_set =
6890         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6891                                 set, "set");
6892 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6893         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6894                                 pfc_ctrl, "pfc_ctrl");
6895 cmdline_parse_token_string_t cmd_pfc_set_rx =
6896         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6897                                 rx, "rx");
6898 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6899         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6900                                 rx_pfc_mode, "on#off");
6901 cmdline_parse_token_string_t cmd_pfc_set_tx =
6902         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6903                                 tx, "tx");
6904 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6905         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6906                                 tx_pfc_mode, "on#off");
6907 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6908         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6909                                 high_water, UINT32);
6910 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6911         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6912                                 low_water, UINT32);
6913 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6914         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6915                                 pause_time, UINT16);
6916 cmdline_parse_token_num_t cmd_pfc_set_priority =
6917         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6918                                 priority, UINT8);
6919 cmdline_parse_token_num_t cmd_pfc_set_portid =
6920         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6921                                 port_id, UINT16);
6922
6923 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6924         .f = cmd_priority_flow_ctrl_set_parsed,
6925         .data = NULL,
6926         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6927                 "<pause_time> <priority> <port_id>: "
6928                 "Configure the Ethernet priority flow control",
6929         .tokens = {
6930                 (void *)&cmd_pfc_set_set,
6931                 (void *)&cmd_pfc_set_flow_ctrl,
6932                 (void *)&cmd_pfc_set_rx,
6933                 (void *)&cmd_pfc_set_rx_mode,
6934                 (void *)&cmd_pfc_set_tx,
6935                 (void *)&cmd_pfc_set_tx_mode,
6936                 (void *)&cmd_pfc_set_high_water,
6937                 (void *)&cmd_pfc_set_low_water,
6938                 (void *)&cmd_pfc_set_pause_time,
6939                 (void *)&cmd_pfc_set_priority,
6940                 (void *)&cmd_pfc_set_portid,
6941                 NULL,
6942         },
6943 };
6944
6945 /* *** RESET CONFIGURATION *** */
6946 struct cmd_reset_result {
6947         cmdline_fixed_string_t reset;
6948         cmdline_fixed_string_t def;
6949 };
6950
6951 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6952                              struct cmdline *cl,
6953                              __attribute__((unused)) void *data)
6954 {
6955         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6956         set_def_fwd_config();
6957 }
6958
6959 cmdline_parse_token_string_t cmd_reset_set =
6960         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6961 cmdline_parse_token_string_t cmd_reset_def =
6962         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6963                                  "default");
6964
6965 cmdline_parse_inst_t cmd_reset = {
6966         .f = cmd_reset_parsed,
6967         .data = NULL,
6968         .help_str = "set default: Reset default forwarding configuration",
6969         .tokens = {
6970                 (void *)&cmd_reset_set,
6971                 (void *)&cmd_reset_def,
6972                 NULL,
6973         },
6974 };
6975
6976 /* *** START FORWARDING *** */
6977 struct cmd_start_result {
6978         cmdline_fixed_string_t start;
6979 };
6980
6981 cmdline_parse_token_string_t cmd_start_start =
6982         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6983
6984 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6985                              __attribute__((unused)) struct cmdline *cl,
6986                              __attribute__((unused)) void *data)
6987 {
6988         start_packet_forwarding(0);
6989 }
6990
6991 cmdline_parse_inst_t cmd_start = {
6992         .f = cmd_start_parsed,
6993         .data = NULL,
6994         .help_str = "start: Start packet forwarding",
6995         .tokens = {
6996                 (void *)&cmd_start_start,
6997                 NULL,
6998         },
6999 };
7000
7001 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7002 struct cmd_start_tx_first_result {
7003         cmdline_fixed_string_t start;
7004         cmdline_fixed_string_t tx_first;
7005 };
7006
7007 static void
7008 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7009                           __attribute__((unused)) struct cmdline *cl,
7010                           __attribute__((unused)) void *data)
7011 {
7012         start_packet_forwarding(1);
7013 }
7014
7015 cmdline_parse_token_string_t cmd_start_tx_first_start =
7016         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7017                                  "start");
7018 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7019         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7020                                  tx_first, "tx_first");
7021
7022 cmdline_parse_inst_t cmd_start_tx_first = {
7023         .f = cmd_start_tx_first_parsed,
7024         .data = NULL,
7025         .help_str = "start tx_first: Start packet forwarding, "
7026                 "after sending 1 burst of packets",
7027         .tokens = {
7028                 (void *)&cmd_start_tx_first_start,
7029                 (void *)&cmd_start_tx_first_tx_first,
7030                 NULL,
7031         },
7032 };
7033
7034 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7035 struct cmd_start_tx_first_n_result {
7036         cmdline_fixed_string_t start;
7037         cmdline_fixed_string_t tx_first;
7038         uint32_t tx_num;
7039 };
7040
7041 static void
7042 cmd_start_tx_first_n_parsed(void *parsed_result,
7043                           __attribute__((unused)) struct cmdline *cl,
7044                           __attribute__((unused)) void *data)
7045 {
7046         struct cmd_start_tx_first_n_result *res = parsed_result;
7047
7048         start_packet_forwarding(res->tx_num);
7049 }
7050
7051 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7052         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7053                         start, "start");
7054 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7055         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7056                         tx_first, "tx_first");
7057 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7058         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7059                         tx_num, UINT32);
7060
7061 cmdline_parse_inst_t cmd_start_tx_first_n = {
7062         .f = cmd_start_tx_first_n_parsed,
7063         .data = NULL,
7064         .help_str = "start tx_first <num>: "
7065                 "packet forwarding, after sending <num> bursts of packets",
7066         .tokens = {
7067                 (void *)&cmd_start_tx_first_n_start,
7068                 (void *)&cmd_start_tx_first_n_tx_first,
7069                 (void *)&cmd_start_tx_first_n_tx_num,
7070                 NULL,
7071         },
7072 };
7073
7074 /* *** SET LINK UP *** */
7075 struct cmd_set_link_up_result {
7076         cmdline_fixed_string_t set;
7077         cmdline_fixed_string_t link_up;
7078         cmdline_fixed_string_t port;
7079         portid_t port_id;
7080 };
7081
7082 cmdline_parse_token_string_t cmd_set_link_up_set =
7083         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7084 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7085         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7086                                 "link-up");
7087 cmdline_parse_token_string_t cmd_set_link_up_port =
7088         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7089 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7090         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7091
7092 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7093                              __attribute__((unused)) struct cmdline *cl,
7094                              __attribute__((unused)) void *data)
7095 {
7096         struct cmd_set_link_up_result *res = parsed_result;
7097         dev_set_link_up(res->port_id);
7098 }
7099
7100 cmdline_parse_inst_t cmd_set_link_up = {
7101         .f = cmd_set_link_up_parsed,
7102         .data = NULL,
7103         .help_str = "set link-up port <port id>",
7104         .tokens = {
7105                 (void *)&cmd_set_link_up_set,
7106                 (void *)&cmd_set_link_up_link_up,
7107                 (void *)&cmd_set_link_up_port,
7108                 (void *)&cmd_set_link_up_port_id,
7109                 NULL,
7110         },
7111 };
7112
7113 /* *** SET LINK DOWN *** */
7114 struct cmd_set_link_down_result {
7115         cmdline_fixed_string_t set;
7116         cmdline_fixed_string_t link_down;
7117         cmdline_fixed_string_t port;
7118         portid_t port_id;
7119 };
7120
7121 cmdline_parse_token_string_t cmd_set_link_down_set =
7122         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7123 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7124         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7125                                 "link-down");
7126 cmdline_parse_token_string_t cmd_set_link_down_port =
7127         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7128 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7129         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7130
7131 static void cmd_set_link_down_parsed(
7132                                 __attribute__((unused)) void *parsed_result,
7133                                 __attribute__((unused)) struct cmdline *cl,
7134                                 __attribute__((unused)) void *data)
7135 {
7136         struct cmd_set_link_down_result *res = parsed_result;
7137         dev_set_link_down(res->port_id);
7138 }
7139
7140 cmdline_parse_inst_t cmd_set_link_down = {
7141         .f = cmd_set_link_down_parsed,
7142         .data = NULL,
7143         .help_str = "set link-down port <port id>",
7144         .tokens = {
7145                 (void *)&cmd_set_link_down_set,
7146                 (void *)&cmd_set_link_down_link_down,
7147                 (void *)&cmd_set_link_down_port,
7148                 (void *)&cmd_set_link_down_port_id,
7149                 NULL,
7150         },
7151 };
7152
7153 /* *** SHOW CFG *** */
7154 struct cmd_showcfg_result {
7155         cmdline_fixed_string_t show;
7156         cmdline_fixed_string_t cfg;
7157         cmdline_fixed_string_t what;
7158 };
7159
7160 static void cmd_showcfg_parsed(void *parsed_result,
7161                                __attribute__((unused)) struct cmdline *cl,
7162                                __attribute__((unused)) void *data)
7163 {
7164         struct cmd_showcfg_result *res = parsed_result;
7165         if (!strcmp(res->what, "rxtx"))
7166                 rxtx_config_display();
7167         else if (!strcmp(res->what, "cores"))
7168                 fwd_lcores_config_display();
7169         else if (!strcmp(res->what, "fwd"))
7170                 pkt_fwd_config_display(&cur_fwd_config);
7171         else if (!strcmp(res->what, "txpkts"))
7172                 show_tx_pkt_segments();
7173 }
7174
7175 cmdline_parse_token_string_t cmd_showcfg_show =
7176         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7177 cmdline_parse_token_string_t cmd_showcfg_port =
7178         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7179 cmdline_parse_token_string_t cmd_showcfg_what =
7180         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7181                                  "rxtx#cores#fwd#txpkts");
7182
7183 cmdline_parse_inst_t cmd_showcfg = {
7184         .f = cmd_showcfg_parsed,
7185         .data = NULL,
7186         .help_str = "show config rxtx|cores|fwd|txpkts",
7187         .tokens = {
7188                 (void *)&cmd_showcfg_show,
7189                 (void *)&cmd_showcfg_port,
7190                 (void *)&cmd_showcfg_what,
7191                 NULL,
7192         },
7193 };
7194
7195 /* *** SHOW ALL PORT INFO *** */
7196 struct cmd_showportall_result {
7197         cmdline_fixed_string_t show;
7198         cmdline_fixed_string_t port;
7199         cmdline_fixed_string_t what;
7200         cmdline_fixed_string_t all;
7201 };
7202
7203 static void cmd_showportall_parsed(void *parsed_result,
7204                                 __attribute__((unused)) struct cmdline *cl,
7205                                 __attribute__((unused)) void *data)
7206 {
7207         portid_t i;
7208
7209         struct cmd_showportall_result *res = parsed_result;
7210         if (!strcmp(res->show, "clear")) {
7211                 if (!strcmp(res->what, "stats"))
7212                         RTE_ETH_FOREACH_DEV(i)
7213                                 nic_stats_clear(i);
7214                 else if (!strcmp(res->what, "xstats"))
7215                         RTE_ETH_FOREACH_DEV(i)
7216                                 nic_xstats_clear(i);
7217         } else if (!strcmp(res->what, "info"))
7218                 RTE_ETH_FOREACH_DEV(i)
7219                         port_infos_display(i);
7220         else if (!strcmp(res->what, "summary")) {
7221                 port_summary_header_display();
7222                 RTE_ETH_FOREACH_DEV(i)
7223                         port_summary_display(i);
7224         }
7225         else if (!strcmp(res->what, "stats"))
7226                 RTE_ETH_FOREACH_DEV(i)
7227                         nic_stats_display(i);
7228         else if (!strcmp(res->what, "xstats"))
7229                 RTE_ETH_FOREACH_DEV(i)
7230                         nic_xstats_display(i);
7231         else if (!strcmp(res->what, "fdir"))
7232                 RTE_ETH_FOREACH_DEV(i)
7233                         fdir_get_infos(i);
7234         else if (!strcmp(res->what, "stat_qmap"))
7235                 RTE_ETH_FOREACH_DEV(i)
7236                         nic_stats_mapping_display(i);
7237         else if (!strcmp(res->what, "dcb_tc"))
7238                 RTE_ETH_FOREACH_DEV(i)
7239                         port_dcb_info_display(i);
7240         else if (!strcmp(res->what, "cap"))
7241                 RTE_ETH_FOREACH_DEV(i)
7242                         port_offload_cap_display(i);
7243 }
7244
7245 cmdline_parse_token_string_t cmd_showportall_show =
7246         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7247                                  "show#clear");
7248 cmdline_parse_token_string_t cmd_showportall_port =
7249         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7250 cmdline_parse_token_string_t cmd_showportall_what =
7251         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7252                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7253 cmdline_parse_token_string_t cmd_showportall_all =
7254         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7255 cmdline_parse_inst_t cmd_showportall = {
7256         .f = cmd_showportall_parsed,
7257         .data = NULL,
7258         .help_str = "show|clear port "
7259                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7260         .tokens = {
7261                 (void *)&cmd_showportall_show,
7262                 (void *)&cmd_showportall_port,
7263                 (void *)&cmd_showportall_what,
7264                 (void *)&cmd_showportall_all,
7265                 NULL,
7266         },
7267 };
7268
7269 /* *** SHOW PORT INFO *** */
7270 struct cmd_showport_result {
7271         cmdline_fixed_string_t show;
7272         cmdline_fixed_string_t port;
7273         cmdline_fixed_string_t what;
7274         uint16_t portnum;
7275 };
7276
7277 static void cmd_showport_parsed(void *parsed_result,
7278                                 __attribute__((unused)) struct cmdline *cl,
7279                                 __attribute__((unused)) void *data)
7280 {
7281         struct cmd_showport_result *res = parsed_result;
7282         if (!strcmp(res->show, "clear")) {
7283                 if (!strcmp(res->what, "stats"))
7284                         nic_stats_clear(res->portnum);
7285                 else if (!strcmp(res->what, "xstats"))
7286                         nic_xstats_clear(res->portnum);
7287         } else if (!strcmp(res->what, "info"))
7288                 port_infos_display(res->portnum);
7289         else if (!strcmp(res->what, "summary")) {
7290                 port_summary_header_display();
7291                 port_summary_display(res->portnum);
7292         }
7293         else if (!strcmp(res->what, "stats"))
7294                 nic_stats_display(res->portnum);
7295         else if (!strcmp(res->what, "xstats"))
7296                 nic_xstats_display(res->portnum);
7297         else if (!strcmp(res->what, "fdir"))
7298                  fdir_get_infos(res->portnum);
7299         else if (!strcmp(res->what, "stat_qmap"))
7300                 nic_stats_mapping_display(res->portnum);
7301         else if (!strcmp(res->what, "dcb_tc"))
7302                 port_dcb_info_display(res->portnum);
7303         else if (!strcmp(res->what, "cap"))
7304                 port_offload_cap_display(res->portnum);
7305 }
7306
7307 cmdline_parse_token_string_t cmd_showport_show =
7308         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7309                                  "show#clear");
7310 cmdline_parse_token_string_t cmd_showport_port =
7311         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7312 cmdline_parse_token_string_t cmd_showport_what =
7313         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7314                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7315 cmdline_parse_token_num_t cmd_showport_portnum =
7316         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7317
7318 cmdline_parse_inst_t cmd_showport = {
7319         .f = cmd_showport_parsed,
7320         .data = NULL,
7321         .help_str = "show|clear port "
7322                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7323                 "<port_id>",
7324         .tokens = {
7325                 (void *)&cmd_showport_show,
7326                 (void *)&cmd_showport_port,
7327                 (void *)&cmd_showport_what,
7328                 (void *)&cmd_showport_portnum,
7329                 NULL,
7330         },
7331 };
7332
7333 /* *** SHOW QUEUE INFO *** */
7334 struct cmd_showqueue_result {
7335         cmdline_fixed_string_t show;
7336         cmdline_fixed_string_t type;
7337         cmdline_fixed_string_t what;
7338         uint16_t portnum;
7339         uint16_t queuenum;
7340 };
7341
7342 static void
7343 cmd_showqueue_parsed(void *parsed_result,
7344         __attribute__((unused)) struct cmdline *cl,
7345         __attribute__((unused)) void *data)
7346 {
7347         struct cmd_showqueue_result *res = parsed_result;
7348
7349         if (!strcmp(res->type, "rxq"))
7350                 rx_queue_infos_display(res->portnum, res->queuenum);
7351         else if (!strcmp(res->type, "txq"))
7352                 tx_queue_infos_display(res->portnum, res->queuenum);
7353 }
7354
7355 cmdline_parse_token_string_t cmd_showqueue_show =
7356         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7357 cmdline_parse_token_string_t cmd_showqueue_type =
7358         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7359 cmdline_parse_token_string_t cmd_showqueue_what =
7360         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7361 cmdline_parse_token_num_t cmd_showqueue_portnum =
7362         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7363 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7364         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7365
7366 cmdline_parse_inst_t cmd_showqueue = {
7367         .f = cmd_showqueue_parsed,
7368         .data = NULL,
7369         .help_str = "show rxq|txq info <port_id> <queue_id>",
7370         .tokens = {
7371                 (void *)&cmd_showqueue_show,
7372                 (void *)&cmd_showqueue_type,
7373                 (void *)&cmd_showqueue_what,
7374                 (void *)&cmd_showqueue_portnum,
7375                 (void *)&cmd_showqueue_queuenum,
7376                 NULL,
7377         },
7378 };
7379
7380 /* *** READ PORT REGISTER *** */
7381 struct cmd_read_reg_result {
7382         cmdline_fixed_string_t read;
7383         cmdline_fixed_string_t reg;
7384         portid_t port_id;
7385         uint32_t reg_off;
7386 };
7387
7388 static void
7389 cmd_read_reg_parsed(void *parsed_result,
7390                     __attribute__((unused)) struct cmdline *cl,
7391                     __attribute__((unused)) void *data)
7392 {
7393         struct cmd_read_reg_result *res = parsed_result;
7394         port_reg_display(res->port_id, res->reg_off);
7395 }
7396
7397 cmdline_parse_token_string_t cmd_read_reg_read =
7398         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7399 cmdline_parse_token_string_t cmd_read_reg_reg =
7400         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7401 cmdline_parse_token_num_t cmd_read_reg_port_id =
7402         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7403 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7404         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7405
7406 cmdline_parse_inst_t cmd_read_reg = {
7407         .f = cmd_read_reg_parsed,
7408         .data = NULL,
7409         .help_str = "read reg <port_id> <reg_off>",
7410         .tokens = {
7411                 (void *)&cmd_read_reg_read,
7412                 (void *)&cmd_read_reg_reg,
7413                 (void *)&cmd_read_reg_port_id,
7414                 (void *)&cmd_read_reg_reg_off,
7415                 NULL,
7416         },
7417 };
7418
7419 /* *** READ PORT REGISTER BIT FIELD *** */
7420 struct cmd_read_reg_bit_field_result {
7421         cmdline_fixed_string_t read;
7422         cmdline_fixed_string_t regfield;
7423         portid_t port_id;
7424         uint32_t reg_off;
7425         uint8_t bit1_pos;
7426         uint8_t bit2_pos;
7427 };
7428
7429 static void
7430 cmd_read_reg_bit_field_parsed(void *parsed_result,
7431                               __attribute__((unused)) struct cmdline *cl,
7432                               __attribute__((unused)) void *data)
7433 {
7434         struct cmd_read_reg_bit_field_result *res = parsed_result;
7435         port_reg_bit_field_display(res->port_id, res->reg_off,
7436                                    res->bit1_pos, res->bit2_pos);
7437 }
7438
7439 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7440         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7441                                  "read");
7442 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7443         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7444                                  regfield, "regfield");
7445 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7446         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7447                               UINT16);
7448 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7449         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7450                               UINT32);
7451 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7452         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7453                               UINT8);
7454 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7455         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7456                               UINT8);
7457
7458 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7459         .f = cmd_read_reg_bit_field_parsed,
7460         .data = NULL,
7461         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7462         "Read register bit field between bit_x and bit_y included",
7463         .tokens = {
7464                 (void *)&cmd_read_reg_bit_field_read,
7465                 (void *)&cmd_read_reg_bit_field_regfield,
7466                 (void *)&cmd_read_reg_bit_field_port_id,
7467                 (void *)&cmd_read_reg_bit_field_reg_off,
7468                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7469                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7470                 NULL,
7471         },
7472 };
7473
7474 /* *** READ PORT REGISTER BIT *** */
7475 struct cmd_read_reg_bit_result {
7476         cmdline_fixed_string_t read;
7477         cmdline_fixed_string_t regbit;
7478         portid_t port_id;
7479         uint32_t reg_off;
7480         uint8_t bit_pos;
7481 };
7482
7483 static void
7484 cmd_read_reg_bit_parsed(void *parsed_result,
7485                         __attribute__((unused)) struct cmdline *cl,
7486                         __attribute__((unused)) void *data)
7487 {
7488         struct cmd_read_reg_bit_result *res = parsed_result;
7489         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7490 }
7491
7492 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7493         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7494 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7495         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7496                                  regbit, "regbit");
7497 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7498         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7499 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7500         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7501 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7502         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7503
7504 cmdline_parse_inst_t cmd_read_reg_bit = {
7505         .f = cmd_read_reg_bit_parsed,
7506         .data = NULL,
7507         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7508         .tokens = {
7509                 (void *)&cmd_read_reg_bit_read,
7510                 (void *)&cmd_read_reg_bit_regbit,
7511                 (void *)&cmd_read_reg_bit_port_id,
7512                 (void *)&cmd_read_reg_bit_reg_off,
7513                 (void *)&cmd_read_reg_bit_bit_pos,
7514                 NULL,
7515         },
7516 };
7517
7518 /* *** WRITE PORT REGISTER *** */
7519 struct cmd_write_reg_result {
7520         cmdline_fixed_string_t write;
7521         cmdline_fixed_string_t reg;
7522         portid_t port_id;
7523         uint32_t reg_off;
7524         uint32_t value;
7525 };
7526
7527 static void
7528 cmd_write_reg_parsed(void *parsed_result,
7529                      __attribute__((unused)) struct cmdline *cl,
7530                      __attribute__((unused)) void *data)
7531 {
7532         struct cmd_write_reg_result *res = parsed_result;
7533         port_reg_set(res->port_id, res->reg_off, res->value);
7534 }
7535
7536 cmdline_parse_token_string_t cmd_write_reg_write =
7537         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7538 cmdline_parse_token_string_t cmd_write_reg_reg =
7539         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7540 cmdline_parse_token_num_t cmd_write_reg_port_id =
7541         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7542 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7543         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7544 cmdline_parse_token_num_t cmd_write_reg_value =
7545         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7546
7547 cmdline_parse_inst_t cmd_write_reg = {
7548         .f = cmd_write_reg_parsed,
7549         .data = NULL,
7550         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7551         .tokens = {
7552                 (void *)&cmd_write_reg_write,
7553                 (void *)&cmd_write_reg_reg,
7554                 (void *)&cmd_write_reg_port_id,
7555                 (void *)&cmd_write_reg_reg_off,
7556                 (void *)&cmd_write_reg_value,
7557                 NULL,
7558         },
7559 };
7560
7561 /* *** WRITE PORT REGISTER BIT FIELD *** */
7562 struct cmd_write_reg_bit_field_result {
7563         cmdline_fixed_string_t write;
7564         cmdline_fixed_string_t regfield;
7565         portid_t port_id;
7566         uint32_t reg_off;
7567         uint8_t bit1_pos;
7568         uint8_t bit2_pos;
7569         uint32_t value;
7570 };
7571
7572 static void
7573 cmd_write_reg_bit_field_parsed(void *parsed_result,
7574                                __attribute__((unused)) struct cmdline *cl,
7575                                __attribute__((unused)) void *data)
7576 {
7577         struct cmd_write_reg_bit_field_result *res = parsed_result;
7578         port_reg_bit_field_set(res->port_id, res->reg_off,
7579                           res->bit1_pos, res->bit2_pos, res->value);
7580 }
7581
7582 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7583         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7584                                  "write");
7585 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7586         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7587                                  regfield, "regfield");
7588 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7589         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7590                               UINT16);
7591 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7592         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7593                               UINT32);
7594 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7595         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7596                               UINT8);
7597 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7598         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7599                               UINT8);
7600 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7601         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7602                               UINT32);
7603
7604 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7605         .f = cmd_write_reg_bit_field_parsed,
7606         .data = NULL,
7607         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7608                 "<reg_value>: "
7609                 "Set register bit field between bit_x and bit_y included",
7610         .tokens = {
7611                 (void *)&cmd_write_reg_bit_field_write,
7612                 (void *)&cmd_write_reg_bit_field_regfield,
7613                 (void *)&cmd_write_reg_bit_field_port_id,
7614                 (void *)&cmd_write_reg_bit_field_reg_off,
7615                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7616                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7617                 (void *)&cmd_write_reg_bit_field_value,
7618                 NULL,
7619         },
7620 };
7621
7622 /* *** WRITE PORT REGISTER BIT *** */
7623 struct cmd_write_reg_bit_result {
7624         cmdline_fixed_string_t write;
7625         cmdline_fixed_string_t regbit;
7626         portid_t port_id;
7627         uint32_t reg_off;
7628         uint8_t bit_pos;
7629         uint8_t value;
7630 };
7631
7632 static void
7633 cmd_write_reg_bit_parsed(void *parsed_result,
7634                          __attribute__((unused)) struct cmdline *cl,
7635                          __attribute__((unused)) void *data)
7636 {
7637         struct cmd_write_reg_bit_result *res = parsed_result;
7638         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7639 }
7640
7641 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7642         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7643                                  "write");
7644 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7645         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7646                                  regbit, "regbit");
7647 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7648         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7649 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7650         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7651 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7652         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7653 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7654         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7655
7656 cmdline_parse_inst_t cmd_write_reg_bit = {
7657         .f = cmd_write_reg_bit_parsed,
7658         .data = NULL,
7659         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7660                 "0 <= bit_x <= 31",
7661         .tokens = {
7662                 (void *)&cmd_write_reg_bit_write,
7663                 (void *)&cmd_write_reg_bit_regbit,
7664                 (void *)&cmd_write_reg_bit_port_id,
7665                 (void *)&cmd_write_reg_bit_reg_off,
7666                 (void *)&cmd_write_reg_bit_bit_pos,
7667                 (void *)&cmd_write_reg_bit_value,
7668                 NULL,
7669         },
7670 };
7671
7672 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7673 struct cmd_read_rxd_txd_result {
7674         cmdline_fixed_string_t read;
7675         cmdline_fixed_string_t rxd_txd;
7676         portid_t port_id;
7677         uint16_t queue_id;
7678         uint16_t desc_id;
7679 };
7680
7681 static void
7682 cmd_read_rxd_txd_parsed(void *parsed_result,
7683                         __attribute__((unused)) struct cmdline *cl,
7684                         __attribute__((unused)) void *data)
7685 {
7686         struct cmd_read_rxd_txd_result *res = parsed_result;
7687
7688         if (!strcmp(res->rxd_txd, "rxd"))
7689                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7690         else if (!strcmp(res->rxd_txd, "txd"))
7691                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7692 }
7693
7694 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7695         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7696 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7697         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7698                                  "rxd#txd");
7699 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7700         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7701 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7702         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7703 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7704         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7705
7706 cmdline_parse_inst_t cmd_read_rxd_txd = {
7707         .f = cmd_read_rxd_txd_parsed,
7708         .data = NULL,
7709         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7710         .tokens = {
7711                 (void *)&cmd_read_rxd_txd_read,
7712                 (void *)&cmd_read_rxd_txd_rxd_txd,
7713                 (void *)&cmd_read_rxd_txd_port_id,
7714                 (void *)&cmd_read_rxd_txd_queue_id,
7715                 (void *)&cmd_read_rxd_txd_desc_id,
7716                 NULL,
7717         },
7718 };
7719
7720 /* *** QUIT *** */
7721 struct cmd_quit_result {
7722         cmdline_fixed_string_t quit;
7723 };
7724
7725 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7726                             struct cmdline *cl,
7727                             __attribute__((unused)) void *data)
7728 {
7729         cmdline_quit(cl);
7730 }
7731
7732 cmdline_parse_token_string_t cmd_quit_quit =
7733         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7734
7735 cmdline_parse_inst_t cmd_quit = {
7736         .f = cmd_quit_parsed,
7737         .data = NULL,
7738         .help_str = "quit: Exit application",
7739         .tokens = {
7740                 (void *)&cmd_quit_quit,
7741                 NULL,
7742         },
7743 };
7744
7745 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7746 struct cmd_mac_addr_result {
7747         cmdline_fixed_string_t mac_addr_cmd;
7748         cmdline_fixed_string_t what;
7749         uint16_t port_num;
7750         struct ether_addr address;
7751 };
7752
7753 static void cmd_mac_addr_parsed(void *parsed_result,
7754                 __attribute__((unused)) struct cmdline *cl,
7755                 __attribute__((unused)) void *data)
7756 {
7757         struct cmd_mac_addr_result *res = parsed_result;
7758         int ret;
7759
7760         if (strcmp(res->what, "add") == 0)
7761                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7762         else if (strcmp(res->what, "set") == 0)
7763                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7764                                                        &res->address);
7765         else
7766                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7767
7768         /* check the return value and print it if is < 0 */
7769         if(ret < 0)
7770                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7771
7772 }
7773
7774 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7775         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7776                                 "mac_addr");
7777 cmdline_parse_token_string_t cmd_mac_addr_what =
7778         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7779                                 "add#remove#set");
7780 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7781                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7782                                         UINT16);
7783 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7784                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7785
7786 cmdline_parse_inst_t cmd_mac_addr = {
7787         .f = cmd_mac_addr_parsed,
7788         .data = (void *)0,
7789         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7790                         "Add/Remove/Set MAC address on port_id",
7791         .tokens = {
7792                 (void *)&cmd_mac_addr_cmd,
7793                 (void *)&cmd_mac_addr_what,
7794                 (void *)&cmd_mac_addr_portnum,
7795                 (void *)&cmd_mac_addr_addr,
7796                 NULL,
7797         },
7798 };
7799
7800 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7801 struct cmd_eth_peer_result {
7802         cmdline_fixed_string_t set;
7803         cmdline_fixed_string_t eth_peer;
7804         portid_t port_id;
7805         cmdline_fixed_string_t peer_addr;
7806 };
7807
7808 static void cmd_set_eth_peer_parsed(void *parsed_result,
7809                         __attribute__((unused)) struct cmdline *cl,
7810                         __attribute__((unused)) void *data)
7811 {
7812                 struct cmd_eth_peer_result *res = parsed_result;
7813
7814                 if (test_done == 0) {
7815                         printf("Please stop forwarding first\n");
7816                         return;
7817                 }
7818                 if (!strcmp(res->eth_peer, "eth-peer")) {
7819                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7820                         fwd_config_setup();
7821                 }
7822 }
7823 cmdline_parse_token_string_t cmd_eth_peer_set =
7824         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7825 cmdline_parse_token_string_t cmd_eth_peer =
7826         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7827 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7828         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7829 cmdline_parse_token_string_t cmd_eth_peer_addr =
7830         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7831
7832 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7833         .f = cmd_set_eth_peer_parsed,
7834         .data = NULL,
7835         .help_str = "set eth-peer <port_id> <peer_mac>",
7836         .tokens = {
7837                 (void *)&cmd_eth_peer_set,
7838                 (void *)&cmd_eth_peer,
7839                 (void *)&cmd_eth_peer_port_id,
7840                 (void *)&cmd_eth_peer_addr,
7841                 NULL,
7842         },
7843 };
7844
7845 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7846 struct cmd_set_qmap_result {
7847         cmdline_fixed_string_t set;
7848         cmdline_fixed_string_t qmap;
7849         cmdline_fixed_string_t what;
7850         portid_t port_id;
7851         uint16_t queue_id;
7852         uint8_t map_value;
7853 };
7854
7855 static void
7856 cmd_set_qmap_parsed(void *parsed_result,
7857                        __attribute__((unused)) struct cmdline *cl,
7858                        __attribute__((unused)) void *data)
7859 {
7860         struct cmd_set_qmap_result *res = parsed_result;
7861         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7862
7863         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7864 }
7865
7866 cmdline_parse_token_string_t cmd_setqmap_set =
7867         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7868                                  set, "set");
7869 cmdline_parse_token_string_t cmd_setqmap_qmap =
7870         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7871                                  qmap, "stat_qmap");
7872 cmdline_parse_token_string_t cmd_setqmap_what =
7873         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7874                                  what, "tx#rx");
7875 cmdline_parse_token_num_t cmd_setqmap_portid =
7876         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7877                               port_id, UINT16);
7878 cmdline_parse_token_num_t cmd_setqmap_queueid =
7879         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7880                               queue_id, UINT16);
7881 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7882         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7883                               map_value, UINT8);
7884
7885 cmdline_parse_inst_t cmd_set_qmap = {
7886         .f = cmd_set_qmap_parsed,
7887         .data = NULL,
7888         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7889                 "Set statistics mapping value on tx|rx queue_id of port_id",
7890         .tokens = {
7891                 (void *)&cmd_setqmap_set,
7892                 (void *)&cmd_setqmap_qmap,
7893                 (void *)&cmd_setqmap_what,
7894                 (void *)&cmd_setqmap_portid,
7895                 (void *)&cmd_setqmap_queueid,
7896                 (void *)&cmd_setqmap_mapvalue,
7897                 NULL,
7898         },
7899 };
7900
7901 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7902 struct cmd_set_xstats_hide_zero_result {
7903         cmdline_fixed_string_t keyword;
7904         cmdline_fixed_string_t name;
7905         cmdline_fixed_string_t on_off;
7906 };
7907
7908 static void
7909 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7910                         __attribute__((unused)) struct cmdline *cl,
7911                         __attribute__((unused)) void *data)
7912 {
7913         struct cmd_set_xstats_hide_zero_result *res;
7914         uint16_t on_off = 0;
7915
7916         res = parsed_result;
7917         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7918         set_xstats_hide_zero(on_off);
7919 }
7920
7921 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7922         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7923                                  keyword, "set");
7924 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7925         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7926                                  name, "xstats-hide-zero");
7927 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7928         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7929                                  on_off, "on#off");
7930
7931 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7932         .f = cmd_set_xstats_hide_zero_parsed,
7933         .data = NULL,
7934         .help_str = "set xstats-hide-zero on|off",
7935         .tokens = {
7936                 (void *)&cmd_set_xstats_hide_zero_keyword,
7937                 (void *)&cmd_set_xstats_hide_zero_name,
7938                 (void *)&cmd_set_xstats_hide_zero_on_off,
7939                 NULL,
7940         },
7941 };
7942
7943 /* *** CONFIGURE UNICAST HASH TABLE *** */
7944 struct cmd_set_uc_hash_table {
7945         cmdline_fixed_string_t set;
7946         cmdline_fixed_string_t port;
7947         portid_t port_id;
7948         cmdline_fixed_string_t what;
7949         struct ether_addr address;
7950         cmdline_fixed_string_t mode;
7951 };
7952
7953 static void
7954 cmd_set_uc_hash_parsed(void *parsed_result,
7955                        __attribute__((unused)) struct cmdline *cl,
7956                        __attribute__((unused)) void *data)
7957 {
7958         int ret=0;
7959         struct cmd_set_uc_hash_table *res = parsed_result;
7960
7961         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7962
7963         if (strcmp(res->what, "uta") == 0)
7964                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7965                                                 &res->address,(uint8_t)is_on);
7966         if (ret < 0)
7967                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7968
7969 }
7970
7971 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7972         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7973                                  set, "set");
7974 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7975         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7976                                  port, "port");
7977 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7978         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7979                               port_id, UINT16);
7980 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7981         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7982                                  what, "uta");
7983 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7984         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7985                                 address);
7986 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7987         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7988                                  mode, "on#off");
7989
7990 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7991         .f = cmd_set_uc_hash_parsed,
7992         .data = NULL,
7993         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7994         .tokens = {
7995                 (void *)&cmd_set_uc_hash_set,
7996                 (void *)&cmd_set_uc_hash_port,
7997                 (void *)&cmd_set_uc_hash_portid,
7998                 (void *)&cmd_set_uc_hash_what,
7999                 (void *)&cmd_set_uc_hash_mac,
8000                 (void *)&cmd_set_uc_hash_mode,
8001                 NULL,
8002         },
8003 };
8004
8005 struct cmd_set_uc_all_hash_table {
8006         cmdline_fixed_string_t set;
8007         cmdline_fixed_string_t port;
8008         portid_t port_id;
8009         cmdline_fixed_string_t what;
8010         cmdline_fixed_string_t value;
8011         cmdline_fixed_string_t mode;
8012 };
8013
8014 static void
8015 cmd_set_uc_all_hash_parsed(void *parsed_result,
8016                        __attribute__((unused)) struct cmdline *cl,
8017                        __attribute__((unused)) void *data)
8018 {
8019         int ret=0;
8020         struct cmd_set_uc_all_hash_table *res = parsed_result;
8021
8022         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8023
8024         if ((strcmp(res->what, "uta") == 0) &&
8025                 (strcmp(res->value, "all") == 0))
8026                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8027         if (ret < 0)
8028                 printf("bad unicast hash table parameter,"
8029                         "return code = %d \n", ret);
8030 }
8031
8032 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8033         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8034                                  set, "set");
8035 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8036         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8037                                  port, "port");
8038 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8039         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8040                               port_id, UINT16);
8041 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8042         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8043                                  what, "uta");
8044 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8045         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8046                                 value,"all");
8047 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8048         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8049                                  mode, "on#off");
8050
8051 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8052         .f = cmd_set_uc_all_hash_parsed,
8053         .data = NULL,
8054         .help_str = "set port <port_id> uta all on|off",
8055         .tokens = {
8056                 (void *)&cmd_set_uc_all_hash_set,
8057                 (void *)&cmd_set_uc_all_hash_port,
8058                 (void *)&cmd_set_uc_all_hash_portid,
8059                 (void *)&cmd_set_uc_all_hash_what,
8060                 (void *)&cmd_set_uc_all_hash_value,
8061                 (void *)&cmd_set_uc_all_hash_mode,
8062                 NULL,
8063         },
8064 };
8065
8066 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8067 struct cmd_set_vf_macvlan_filter {
8068         cmdline_fixed_string_t set;
8069         cmdline_fixed_string_t port;
8070         portid_t port_id;
8071         cmdline_fixed_string_t vf;
8072         uint8_t vf_id;
8073         struct ether_addr address;
8074         cmdline_fixed_string_t filter_type;
8075         cmdline_fixed_string_t mode;
8076 };
8077
8078 static void
8079 cmd_set_vf_macvlan_parsed(void *parsed_result,
8080                        __attribute__((unused)) struct cmdline *cl,
8081                        __attribute__((unused)) void *data)
8082 {
8083         int is_on, ret = 0;
8084         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8085         struct rte_eth_mac_filter filter;
8086
8087         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8088
8089         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
8090
8091         /* set VF MAC filter */
8092         filter.is_vf = 1;
8093
8094         /* set VF ID */
8095         filter.dst_id = res->vf_id;
8096
8097         if (!strcmp(res->filter_type, "exact-mac"))
8098                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8099         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8100                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8101         else if (!strcmp(res->filter_type, "hashmac"))
8102                 filter.filter_type = RTE_MAC_HASH_MATCH;
8103         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8104                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8105
8106         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8107
8108         if (is_on)
8109                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8110                                         RTE_ETH_FILTER_MACVLAN,
8111                                         RTE_ETH_FILTER_ADD,
8112                                          &filter);
8113         else
8114                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8115                                         RTE_ETH_FILTER_MACVLAN,
8116                                         RTE_ETH_FILTER_DELETE,
8117                                         &filter);
8118
8119         if (ret < 0)
8120                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8121
8122 }
8123
8124 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8125         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8126                                  set, "set");
8127 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8128         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8129                                  port, "port");
8130 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8131         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8132                               port_id, UINT16);
8133 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8134         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8135                                  vf, "vf");
8136 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8137         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8138                                 vf_id, UINT8);
8139 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8140         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8141                                 address);
8142 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8143         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8144                                 filter_type, "exact-mac#exact-mac-vlan"
8145                                 "#hashmac#hashmac-vlan");
8146 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8147         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8148                                  mode, "on#off");
8149
8150 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8151         .f = cmd_set_vf_macvlan_parsed,
8152         .data = NULL,
8153         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8154                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8155                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8156                 "hash match rule: hash match of MAC and exact match of VLAN",
8157         .tokens = {
8158                 (void *)&cmd_set_vf_macvlan_set,
8159                 (void *)&cmd_set_vf_macvlan_port,
8160                 (void *)&cmd_set_vf_macvlan_portid,
8161                 (void *)&cmd_set_vf_macvlan_vf,
8162                 (void *)&cmd_set_vf_macvlan_vf_id,
8163                 (void *)&cmd_set_vf_macvlan_mac,
8164                 (void *)&cmd_set_vf_macvlan_filter_type,
8165                 (void *)&cmd_set_vf_macvlan_mode,
8166                 NULL,
8167         },
8168 };
8169
8170 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8171 struct cmd_set_vf_traffic {
8172         cmdline_fixed_string_t set;
8173         cmdline_fixed_string_t port;
8174         portid_t port_id;
8175         cmdline_fixed_string_t vf;
8176         uint8_t vf_id;
8177         cmdline_fixed_string_t what;
8178         cmdline_fixed_string_t mode;
8179 };
8180
8181 static void
8182 cmd_set_vf_traffic_parsed(void *parsed_result,
8183                        __attribute__((unused)) struct cmdline *cl,
8184                        __attribute__((unused)) void *data)
8185 {
8186         struct cmd_set_vf_traffic *res = parsed_result;
8187         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8188         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8189
8190         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8191 }
8192
8193 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8194         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8195                                  set, "set");
8196 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8197         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8198                                  port, "port");
8199 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8200         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8201                               port_id, UINT16);
8202 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8203         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8204                                  vf, "vf");
8205 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8206         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8207                               vf_id, UINT8);
8208 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8209         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8210                                  what, "tx#rx");
8211 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8212         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8213                                  mode, "on#off");
8214
8215 cmdline_parse_inst_t cmd_set_vf_traffic = {
8216         .f = cmd_set_vf_traffic_parsed,
8217         .data = NULL,
8218         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8219         .tokens = {
8220                 (void *)&cmd_setvf_traffic_set,
8221                 (void *)&cmd_setvf_traffic_port,
8222                 (void *)&cmd_setvf_traffic_portid,
8223                 (void *)&cmd_setvf_traffic_vf,
8224                 (void *)&cmd_setvf_traffic_vfid,
8225                 (void *)&cmd_setvf_traffic_what,
8226                 (void *)&cmd_setvf_traffic_mode,
8227                 NULL,
8228         },
8229 };
8230
8231 /* *** CONFIGURE VF RECEIVE MODE *** */
8232 struct cmd_set_vf_rxmode {
8233         cmdline_fixed_string_t set;
8234         cmdline_fixed_string_t port;
8235         portid_t port_id;
8236         cmdline_fixed_string_t vf;
8237         uint8_t vf_id;
8238         cmdline_fixed_string_t what;
8239         cmdline_fixed_string_t mode;
8240         cmdline_fixed_string_t on;
8241 };
8242
8243 static void
8244 cmd_set_vf_rxmode_parsed(void *parsed_result,
8245                        __attribute__((unused)) struct cmdline *cl,
8246                        __attribute__((unused)) void *data)
8247 {
8248         int ret = -ENOTSUP;
8249         uint16_t rx_mode = 0;
8250         struct cmd_set_vf_rxmode *res = parsed_result;
8251
8252         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8253         if (!strcmp(res->what,"rxmode")) {
8254                 if (!strcmp(res->mode, "AUPE"))
8255                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8256                 else if (!strcmp(res->mode, "ROPE"))
8257                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8258                 else if (!strcmp(res->mode, "BAM"))
8259                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8260                 else if (!strncmp(res->mode, "MPE",3))
8261                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8262         }
8263
8264         RTE_SET_USED(is_on);
8265
8266 #ifdef RTE_LIBRTE_IXGBE_PMD
8267         if (ret == -ENOTSUP)
8268                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8269                                                   rx_mode, (uint8_t)is_on);
8270 #endif
8271 #ifdef RTE_LIBRTE_BNXT_PMD
8272         if (ret == -ENOTSUP)
8273                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8274                                                  rx_mode, (uint8_t)is_on);
8275 #endif
8276         if (ret < 0)
8277                 printf("bad VF receive mode parameter, return code = %d \n",
8278                 ret);
8279 }
8280
8281 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8282         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8283                                  set, "set");
8284 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8285         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8286                                  port, "port");
8287 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8288         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8289                               port_id, UINT16);
8290 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8291         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8292                                  vf, "vf");
8293 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8294         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8295                               vf_id, UINT8);
8296 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8297         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8298                                  what, "rxmode");
8299 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8300         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8301                                  mode, "AUPE#ROPE#BAM#MPE");
8302 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8303         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8304                                  on, "on#off");
8305
8306 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8307         .f = cmd_set_vf_rxmode_parsed,
8308         .data = NULL,
8309         .help_str = "set port <port_id> vf <vf_id> rxmode "
8310                 "AUPE|ROPE|BAM|MPE on|off",
8311         .tokens = {
8312                 (void *)&cmd_set_vf_rxmode_set,
8313                 (void *)&cmd_set_vf_rxmode_port,
8314                 (void *)&cmd_set_vf_rxmode_portid,
8315                 (void *)&cmd_set_vf_rxmode_vf,
8316                 (void *)&cmd_set_vf_rxmode_vfid,
8317                 (void *)&cmd_set_vf_rxmode_what,
8318                 (void *)&cmd_set_vf_rxmode_mode,
8319                 (void *)&cmd_set_vf_rxmode_on,
8320                 NULL,
8321         },
8322 };
8323
8324 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8325 struct cmd_vf_mac_addr_result {
8326         cmdline_fixed_string_t mac_addr_cmd;
8327         cmdline_fixed_string_t what;
8328         cmdline_fixed_string_t port;
8329         uint16_t port_num;
8330         cmdline_fixed_string_t vf;
8331         uint8_t vf_num;
8332         struct ether_addr address;
8333 };
8334
8335 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8336                 __attribute__((unused)) struct cmdline *cl,
8337                 __attribute__((unused)) void *data)
8338 {
8339         struct cmd_vf_mac_addr_result *res = parsed_result;
8340         int ret = -ENOTSUP;
8341
8342         if (strcmp(res->what, "add") != 0)
8343                 return;
8344
8345 #ifdef RTE_LIBRTE_I40E_PMD
8346         if (ret == -ENOTSUP)
8347                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8348                                                    &res->address);
8349 #endif
8350 #ifdef RTE_LIBRTE_BNXT_PMD
8351         if (ret == -ENOTSUP)
8352                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8353                                                 res->vf_num);
8354 #endif
8355
8356         if(ret < 0)
8357                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8358
8359 }
8360
8361 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8362         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8363                                 mac_addr_cmd,"mac_addr");
8364 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8365         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8366                                 what,"add");
8367 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8368         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8369                                 port,"port");
8370 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8371         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8372                                 port_num, UINT16);
8373 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8374         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8375                                 vf,"vf");
8376 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8377         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8378                                 vf_num, UINT8);
8379 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8380         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8381                                 address);
8382
8383 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8384         .f = cmd_vf_mac_addr_parsed,
8385         .data = (void *)0,
8386         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8387                 "Add MAC address filtering for a VF on port_id",
8388         .tokens = {
8389                 (void *)&cmd_vf_mac_addr_cmd,
8390                 (void *)&cmd_vf_mac_addr_what,
8391                 (void *)&cmd_vf_mac_addr_port,
8392                 (void *)&cmd_vf_mac_addr_portnum,
8393                 (void *)&cmd_vf_mac_addr_vf,
8394                 (void *)&cmd_vf_mac_addr_vfnum,
8395                 (void *)&cmd_vf_mac_addr_addr,
8396                 NULL,
8397         },
8398 };
8399
8400 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8401 struct cmd_vf_rx_vlan_filter {
8402         cmdline_fixed_string_t rx_vlan;
8403         cmdline_fixed_string_t what;
8404         uint16_t vlan_id;
8405         cmdline_fixed_string_t port;
8406         portid_t port_id;
8407         cmdline_fixed_string_t vf;
8408         uint64_t vf_mask;
8409 };
8410
8411 static void
8412 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8413                           __attribute__((unused)) struct cmdline *cl,
8414                           __attribute__((unused)) void *data)
8415 {
8416         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8417         int ret = -ENOTSUP;
8418
8419         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8420
8421 #ifdef RTE_LIBRTE_IXGBE_PMD
8422         if (ret == -ENOTSUP)
8423                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8424                                 res->vlan_id, res->vf_mask, is_add);
8425 #endif
8426 #ifdef RTE_LIBRTE_I40E_PMD
8427         if (ret == -ENOTSUP)
8428                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8429                                 res->vlan_id, res->vf_mask, is_add);
8430 #endif
8431 #ifdef RTE_LIBRTE_BNXT_PMD
8432         if (ret == -ENOTSUP)
8433                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8434                                 res->vlan_id, res->vf_mask, is_add);
8435 #endif
8436
8437         switch (ret) {
8438         case 0:
8439                 break;
8440         case -EINVAL:
8441                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8442                                 res->vlan_id, res->vf_mask);
8443                 break;
8444         case -ENODEV:
8445                 printf("invalid port_id %d\n", res->port_id);
8446                 break;
8447         case -ENOTSUP:
8448                 printf("function not implemented or supported\n");
8449                 break;
8450         default:
8451                 printf("programming error: (%s)\n", strerror(-ret));
8452         }
8453 }
8454
8455 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8456         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8457                                  rx_vlan, "rx_vlan");
8458 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8459         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8460                                  what, "add#rm");
8461 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8462         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8463                               vlan_id, UINT16);
8464 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8465         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8466                                  port, "port");
8467 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8468         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8469                               port_id, UINT16);
8470 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8471         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8472                                  vf, "vf");
8473 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8474         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8475                               vf_mask, UINT64);
8476
8477 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8478         .f = cmd_vf_rx_vlan_filter_parsed,
8479         .data = NULL,
8480         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8481                 "(vf_mask = hexadecimal VF mask)",
8482         .tokens = {
8483                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8484                 (void *)&cmd_vf_rx_vlan_filter_what,
8485                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8486                 (void *)&cmd_vf_rx_vlan_filter_port,
8487                 (void *)&cmd_vf_rx_vlan_filter_portid,
8488                 (void *)&cmd_vf_rx_vlan_filter_vf,
8489                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8490                 NULL,
8491         },
8492 };
8493
8494 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8495 struct cmd_queue_rate_limit_result {
8496         cmdline_fixed_string_t set;
8497         cmdline_fixed_string_t port;
8498         uint16_t port_num;
8499         cmdline_fixed_string_t queue;
8500         uint8_t queue_num;
8501         cmdline_fixed_string_t rate;
8502         uint16_t rate_num;
8503 };
8504
8505 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8506                 __attribute__((unused)) struct cmdline *cl,
8507                 __attribute__((unused)) void *data)
8508 {
8509         struct cmd_queue_rate_limit_result *res = parsed_result;
8510         int ret = 0;
8511
8512         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8513                 && (strcmp(res->queue, "queue") == 0)
8514                 && (strcmp(res->rate, "rate") == 0))
8515                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8516                                         res->rate_num);
8517         if (ret < 0)
8518                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8519
8520 }
8521
8522 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8523         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8524                                 set, "set");
8525 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8526         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8527                                 port, "port");
8528 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8529         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8530                                 port_num, UINT16);
8531 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8532         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8533                                 queue, "queue");
8534 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8535         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8536                                 queue_num, UINT8);
8537 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8538         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8539                                 rate, "rate");
8540 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8541         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8542                                 rate_num, UINT16);
8543
8544 cmdline_parse_inst_t cmd_queue_rate_limit = {
8545         .f = cmd_queue_rate_limit_parsed,
8546         .data = (void *)0,
8547         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8548                 "Set rate limit for a queue on port_id",
8549         .tokens = {
8550                 (void *)&cmd_queue_rate_limit_set,
8551                 (void *)&cmd_queue_rate_limit_port,
8552                 (void *)&cmd_queue_rate_limit_portnum,
8553                 (void *)&cmd_queue_rate_limit_queue,
8554                 (void *)&cmd_queue_rate_limit_queuenum,
8555                 (void *)&cmd_queue_rate_limit_rate,
8556                 (void *)&cmd_queue_rate_limit_ratenum,
8557                 NULL,
8558         },
8559 };
8560
8561 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8562 struct cmd_vf_rate_limit_result {
8563         cmdline_fixed_string_t set;
8564         cmdline_fixed_string_t port;
8565         uint16_t port_num;
8566         cmdline_fixed_string_t vf;
8567         uint8_t vf_num;
8568         cmdline_fixed_string_t rate;
8569         uint16_t rate_num;
8570         cmdline_fixed_string_t q_msk;
8571         uint64_t q_msk_val;
8572 };
8573
8574 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8575                 __attribute__((unused)) struct cmdline *cl,
8576                 __attribute__((unused)) void *data)
8577 {
8578         struct cmd_vf_rate_limit_result *res = parsed_result;
8579         int ret = 0;
8580
8581         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8582                 && (strcmp(res->vf, "vf") == 0)
8583                 && (strcmp(res->rate, "rate") == 0)
8584                 && (strcmp(res->q_msk, "queue_mask") == 0))
8585                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8586                                         res->rate_num, res->q_msk_val);
8587         if (ret < 0)
8588                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8589
8590 }
8591
8592 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8593         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8594                                 set, "set");
8595 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8596         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8597                                 port, "port");
8598 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8599         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8600                                 port_num, UINT16);
8601 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8602         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8603                                 vf, "vf");
8604 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8605         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8606                                 vf_num, UINT8);
8607 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8608         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8609                                 rate, "rate");
8610 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8611         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8612                                 rate_num, UINT16);
8613 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8614         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8615                                 q_msk, "queue_mask");
8616 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8617         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8618                                 q_msk_val, UINT64);
8619
8620 cmdline_parse_inst_t cmd_vf_rate_limit = {
8621         .f = cmd_vf_rate_limit_parsed,
8622         .data = (void *)0,
8623         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8624                 "queue_mask <queue_mask_value>: "
8625                 "Set rate limit for queues of VF on port_id",
8626         .tokens = {
8627                 (void *)&cmd_vf_rate_limit_set,
8628                 (void *)&cmd_vf_rate_limit_port,
8629                 (void *)&cmd_vf_rate_limit_portnum,
8630                 (void *)&cmd_vf_rate_limit_vf,
8631                 (void *)&cmd_vf_rate_limit_vfnum,
8632                 (void *)&cmd_vf_rate_limit_rate,
8633                 (void *)&cmd_vf_rate_limit_ratenum,
8634                 (void *)&cmd_vf_rate_limit_q_msk,
8635                 (void *)&cmd_vf_rate_limit_q_msk_val,
8636                 NULL,
8637         },
8638 };
8639
8640 /* *** ADD TUNNEL FILTER OF A PORT *** */
8641 struct cmd_tunnel_filter_result {
8642         cmdline_fixed_string_t cmd;
8643         cmdline_fixed_string_t what;
8644         portid_t port_id;
8645         struct ether_addr outer_mac;
8646         struct ether_addr inner_mac;
8647         cmdline_ipaddr_t ip_value;
8648         uint16_t inner_vlan;
8649         cmdline_fixed_string_t tunnel_type;
8650         cmdline_fixed_string_t filter_type;
8651         uint32_t tenant_id;
8652         uint16_t queue_num;
8653 };
8654
8655 static void
8656 cmd_tunnel_filter_parsed(void *parsed_result,
8657                           __attribute__((unused)) struct cmdline *cl,
8658                           __attribute__((unused)) void *data)
8659 {
8660         struct cmd_tunnel_filter_result *res = parsed_result;
8661         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8662         int ret = 0;
8663
8664         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8665
8666         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8667         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8668         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8669
8670         if (res->ip_value.family == AF_INET) {
8671                 tunnel_filter_conf.ip_addr.ipv4_addr =
8672                         res->ip_value.addr.ipv4.s_addr;
8673                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8674         } else {
8675                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8676                         &(res->ip_value.addr.ipv6),
8677                         sizeof(struct in6_addr));
8678                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8679         }
8680
8681         if (!strcmp(res->filter_type, "imac-ivlan"))
8682                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8683         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8684                 tunnel_filter_conf.filter_type =
8685                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8686         else if (!strcmp(res->filter_type, "imac-tenid"))
8687                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8688         else if (!strcmp(res->filter_type, "imac"))
8689                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8690         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8691                 tunnel_filter_conf.filter_type =
8692                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8693         else if (!strcmp(res->filter_type, "oip"))
8694                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8695         else if (!strcmp(res->filter_type, "iip"))
8696                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8697         else {
8698                 printf("The filter type is not supported");
8699                 return;
8700         }
8701
8702         if (!strcmp(res->tunnel_type, "vxlan"))
8703                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8704         else if (!strcmp(res->tunnel_type, "nvgre"))
8705                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8706         else if (!strcmp(res->tunnel_type, "ipingre"))
8707                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8708         else {
8709                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8710                 return;
8711         }
8712
8713         tunnel_filter_conf.tenant_id = res->tenant_id;
8714         tunnel_filter_conf.queue_id = res->queue_num;
8715         if (!strcmp(res->what, "add"))
8716                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8717                                         RTE_ETH_FILTER_TUNNEL,
8718                                         RTE_ETH_FILTER_ADD,
8719                                         &tunnel_filter_conf);
8720         else
8721                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8722                                         RTE_ETH_FILTER_TUNNEL,
8723                                         RTE_ETH_FILTER_DELETE,
8724                                         &tunnel_filter_conf);
8725         if (ret < 0)
8726                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8727                                 strerror(-ret));
8728
8729 }
8730 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8731         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8732         cmd, "tunnel_filter");
8733 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8734         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8735         what, "add#rm");
8736 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8737         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8738         port_id, UINT16);
8739 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8740         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8741         outer_mac);
8742 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8743         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8744         inner_mac);
8745 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8746         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8747         inner_vlan, UINT16);
8748 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8749         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8750         ip_value);
8751 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8752         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8753         tunnel_type, "vxlan#nvgre#ipingre");
8754
8755 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8756         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8757         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8758                 "imac#omac-imac-tenid");
8759 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8760         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8761         tenant_id, UINT32);
8762 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8763         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8764         queue_num, UINT16);
8765
8766 cmdline_parse_inst_t cmd_tunnel_filter = {
8767         .f = cmd_tunnel_filter_parsed,
8768         .data = (void *)0,
8769         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8770                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8771                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8772                 "<queue_id>: Add/Rm tunnel filter of a port",
8773         .tokens = {
8774                 (void *)&cmd_tunnel_filter_cmd,
8775                 (void *)&cmd_tunnel_filter_what,
8776                 (void *)&cmd_tunnel_filter_port_id,
8777                 (void *)&cmd_tunnel_filter_outer_mac,
8778                 (void *)&cmd_tunnel_filter_inner_mac,
8779                 (void *)&cmd_tunnel_filter_ip_value,
8780                 (void *)&cmd_tunnel_filter_innner_vlan,
8781                 (void *)&cmd_tunnel_filter_tunnel_type,
8782                 (void *)&cmd_tunnel_filter_filter_type,
8783                 (void *)&cmd_tunnel_filter_tenant_id,
8784                 (void *)&cmd_tunnel_filter_queue_num,
8785                 NULL,
8786         },
8787 };
8788
8789 /* *** CONFIGURE TUNNEL UDP PORT *** */
8790 struct cmd_tunnel_udp_config {
8791         cmdline_fixed_string_t cmd;
8792         cmdline_fixed_string_t what;
8793         uint16_t udp_port;
8794         portid_t port_id;
8795 };
8796
8797 static void
8798 cmd_tunnel_udp_config_parsed(void *parsed_result,
8799                           __attribute__((unused)) struct cmdline *cl,
8800                           __attribute__((unused)) void *data)
8801 {
8802         struct cmd_tunnel_udp_config *res = parsed_result;
8803         struct rte_eth_udp_tunnel tunnel_udp;
8804         int ret;
8805
8806         tunnel_udp.udp_port = res->udp_port;
8807
8808         if (!strcmp(res->cmd, "rx_vxlan_port"))
8809                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8810
8811         if (!strcmp(res->what, "add"))
8812                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8813                                                       &tunnel_udp);
8814         else
8815                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8816                                                          &tunnel_udp);
8817
8818         if (ret < 0)
8819                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8820 }
8821
8822 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8823         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8824                                 cmd, "rx_vxlan_port");
8825 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8826         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8827                                 what, "add#rm");
8828 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8829         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8830                                 udp_port, UINT16);
8831 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8832         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8833                                 port_id, UINT16);
8834
8835 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8836         .f = cmd_tunnel_udp_config_parsed,
8837         .data = (void *)0,
8838         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8839                 "Add/Remove a tunneling UDP port filter",
8840         .tokens = {
8841                 (void *)&cmd_tunnel_udp_config_cmd,
8842                 (void *)&cmd_tunnel_udp_config_what,
8843                 (void *)&cmd_tunnel_udp_config_udp_port,
8844                 (void *)&cmd_tunnel_udp_config_port_id,
8845                 NULL,
8846         },
8847 };
8848
8849 struct cmd_config_tunnel_udp_port {
8850         cmdline_fixed_string_t port;
8851         cmdline_fixed_string_t config;
8852         portid_t port_id;
8853         cmdline_fixed_string_t udp_tunnel_port;
8854         cmdline_fixed_string_t action;
8855         cmdline_fixed_string_t tunnel_type;
8856         uint16_t udp_port;
8857 };
8858
8859 static void
8860 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8861                                __attribute__((unused)) struct cmdline *cl,
8862                                __attribute__((unused)) void *data)
8863 {
8864         struct cmd_config_tunnel_udp_port *res = parsed_result;
8865         struct rte_eth_udp_tunnel tunnel_udp;
8866         int ret = 0;
8867
8868         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8869                 return;
8870
8871         tunnel_udp.udp_port = res->udp_port;
8872
8873         if (!strcmp(res->tunnel_type, "vxlan")) {
8874                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8875         } else if (!strcmp(res->tunnel_type, "geneve")) {
8876                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8877         } else {
8878                 printf("Invalid tunnel type\n");
8879                 return;
8880         }
8881
8882         if (!strcmp(res->action, "add"))
8883                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8884                                                       &tunnel_udp);
8885         else
8886                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8887                                                          &tunnel_udp);
8888
8889         if (ret < 0)
8890                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8891 }
8892
8893 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8894         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8895                                  "port");
8896 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8897         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8898                                  "config");
8899 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8900         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8901                               UINT16);
8902 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8903         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8904                                  udp_tunnel_port,
8905                                  "udp_tunnel_port");
8906 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8907         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8908                                  "add#rm");
8909 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8910         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8911                                  "vxlan#geneve");
8912 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8913         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8914                               UINT16);
8915
8916 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8917         .f = cmd_cfg_tunnel_udp_port_parsed,
8918         .data = NULL,
8919         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8920         .tokens = {
8921                 (void *)&cmd_config_tunnel_udp_port_port,
8922                 (void *)&cmd_config_tunnel_udp_port_config,
8923                 (void *)&cmd_config_tunnel_udp_port_port_id,
8924                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8925                 (void *)&cmd_config_tunnel_udp_port_action,
8926                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8927                 (void *)&cmd_config_tunnel_udp_port_value,
8928                 NULL,
8929         },
8930 };
8931
8932 /* *** GLOBAL CONFIG *** */
8933 struct cmd_global_config_result {
8934         cmdline_fixed_string_t cmd;
8935         portid_t port_id;
8936         cmdline_fixed_string_t cfg_type;
8937         uint8_t len;
8938 };
8939
8940 static void
8941 cmd_global_config_parsed(void *parsed_result,
8942                          __attribute__((unused)) struct cmdline *cl,
8943                          __attribute__((unused)) void *data)
8944 {
8945         struct cmd_global_config_result *res = parsed_result;
8946         struct rte_eth_global_cfg conf;
8947         int ret;
8948
8949         memset(&conf, 0, sizeof(conf));
8950         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8951         conf.cfg.gre_key_len = res->len;
8952         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8953                                       RTE_ETH_FILTER_SET, &conf);
8954         if (ret != 0)
8955                 printf("Global config error\n");
8956 }
8957
8958 cmdline_parse_token_string_t cmd_global_config_cmd =
8959         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8960                 "global_config");
8961 cmdline_parse_token_num_t cmd_global_config_port_id =
8962         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8963                                UINT16);
8964 cmdline_parse_token_string_t cmd_global_config_type =
8965         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8966                 cfg_type, "gre-key-len");
8967 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8968         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8969                 len, UINT8);
8970
8971 cmdline_parse_inst_t cmd_global_config = {
8972         .f = cmd_global_config_parsed,
8973         .data = (void *)NULL,
8974         .help_str = "global_config <port_id> gre-key-len <key_len>",
8975         .tokens = {
8976                 (void *)&cmd_global_config_cmd,
8977                 (void *)&cmd_global_config_port_id,
8978                 (void *)&cmd_global_config_type,
8979                 (void *)&cmd_global_config_gre_key_len,
8980                 NULL,
8981         },
8982 };
8983
8984 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8985 struct cmd_set_mirror_mask_result {
8986         cmdline_fixed_string_t set;
8987         cmdline_fixed_string_t port;
8988         portid_t port_id;
8989         cmdline_fixed_string_t mirror;
8990         uint8_t rule_id;
8991         cmdline_fixed_string_t what;
8992         cmdline_fixed_string_t value;
8993         cmdline_fixed_string_t dstpool;
8994         uint8_t dstpool_id;
8995         cmdline_fixed_string_t on;
8996 };
8997
8998 cmdline_parse_token_string_t cmd_mirror_mask_set =
8999         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9000                                 set, "set");
9001 cmdline_parse_token_string_t cmd_mirror_mask_port =
9002         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9003                                 port, "port");
9004 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9005         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9006                                 port_id, UINT16);
9007 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9008         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9009                                 mirror, "mirror-rule");
9010 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9011         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9012                                 rule_id, UINT8);
9013 cmdline_parse_token_string_t cmd_mirror_mask_what =
9014         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9015                                 what, "pool-mirror-up#pool-mirror-down"
9016                                       "#vlan-mirror");
9017 cmdline_parse_token_string_t cmd_mirror_mask_value =
9018         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9019                                 value, NULL);
9020 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9021         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9022                                 dstpool, "dst-pool");
9023 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9024         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9025                                 dstpool_id, UINT8);
9026 cmdline_parse_token_string_t cmd_mirror_mask_on =
9027         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9028                                 on, "on#off");
9029
9030 static void
9031 cmd_set_mirror_mask_parsed(void *parsed_result,
9032                        __attribute__((unused)) struct cmdline *cl,
9033                        __attribute__((unused)) void *data)
9034 {
9035         int ret,nb_item,i;
9036         struct cmd_set_mirror_mask_result *res = parsed_result;
9037         struct rte_eth_mirror_conf mr_conf;
9038
9039         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9040
9041         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9042
9043         mr_conf.dst_pool = res->dstpool_id;
9044
9045         if (!strcmp(res->what, "pool-mirror-up")) {
9046                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9047                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9048         } else if (!strcmp(res->what, "pool-mirror-down")) {
9049                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9050                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9051         } else if (!strcmp(res->what, "vlan-mirror")) {
9052                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9053                 nb_item = parse_item_list(res->value, "vlan",
9054                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9055                 if (nb_item <= 0)
9056                         return;
9057
9058                 for (i = 0; i < nb_item; i++) {
9059                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
9060                                 printf("Invalid vlan_id: must be < 4096\n");
9061                                 return;
9062                         }
9063
9064                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9065                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9066                 }
9067         }
9068
9069         if (!strcmp(res->on, "on"))
9070                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9071                                                 res->rule_id, 1);
9072         else
9073                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9074                                                 res->rule_id, 0);
9075         if (ret < 0)
9076                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9077 }
9078
9079 cmdline_parse_inst_t cmd_set_mirror_mask = {
9080                 .f = cmd_set_mirror_mask_parsed,
9081                 .data = NULL,
9082                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9083                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9084                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9085                 .tokens = {
9086                         (void *)&cmd_mirror_mask_set,
9087                         (void *)&cmd_mirror_mask_port,
9088                         (void *)&cmd_mirror_mask_portid,
9089                         (void *)&cmd_mirror_mask_mirror,
9090                         (void *)&cmd_mirror_mask_ruleid,
9091                         (void *)&cmd_mirror_mask_what,
9092                         (void *)&cmd_mirror_mask_value,
9093                         (void *)&cmd_mirror_mask_dstpool,
9094                         (void *)&cmd_mirror_mask_poolid,
9095                         (void *)&cmd_mirror_mask_on,
9096                         NULL,
9097                 },
9098 };
9099
9100 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9101 struct cmd_set_mirror_link_result {
9102         cmdline_fixed_string_t set;
9103         cmdline_fixed_string_t port;
9104         portid_t port_id;
9105         cmdline_fixed_string_t mirror;
9106         uint8_t rule_id;
9107         cmdline_fixed_string_t what;
9108         cmdline_fixed_string_t dstpool;
9109         uint8_t dstpool_id;
9110         cmdline_fixed_string_t on;
9111 };
9112
9113 cmdline_parse_token_string_t cmd_mirror_link_set =
9114         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9115                                  set, "set");
9116 cmdline_parse_token_string_t cmd_mirror_link_port =
9117         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9118                                 port, "port");
9119 cmdline_parse_token_num_t cmd_mirror_link_portid =
9120         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9121                                 port_id, UINT16);
9122 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9123         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9124                                 mirror, "mirror-rule");
9125 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9126         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9127                             rule_id, UINT8);
9128 cmdline_parse_token_string_t cmd_mirror_link_what =
9129         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9130                                 what, "uplink-mirror#downlink-mirror");
9131 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9132         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9133                                 dstpool, "dst-pool");
9134 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9135         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9136                                 dstpool_id, UINT8);
9137 cmdline_parse_token_string_t cmd_mirror_link_on =
9138         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9139                                 on, "on#off");
9140
9141 static void
9142 cmd_set_mirror_link_parsed(void *parsed_result,
9143                        __attribute__((unused)) struct cmdline *cl,
9144                        __attribute__((unused)) void *data)
9145 {
9146         int ret;
9147         struct cmd_set_mirror_link_result *res = parsed_result;
9148         struct rte_eth_mirror_conf mr_conf;
9149
9150         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9151         if (!strcmp(res->what, "uplink-mirror"))
9152                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9153         else
9154                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9155
9156         mr_conf.dst_pool = res->dstpool_id;
9157
9158         if (!strcmp(res->on, "on"))
9159                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9160                                                 res->rule_id, 1);
9161         else
9162                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9163                                                 res->rule_id, 0);
9164
9165         /* check the return value and print it if is < 0 */
9166         if (ret < 0)
9167                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9168
9169 }
9170
9171 cmdline_parse_inst_t cmd_set_mirror_link = {
9172                 .f = cmd_set_mirror_link_parsed,
9173                 .data = NULL,
9174                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9175                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9176                 .tokens = {
9177                         (void *)&cmd_mirror_link_set,
9178                         (void *)&cmd_mirror_link_port,
9179                         (void *)&cmd_mirror_link_portid,
9180                         (void *)&cmd_mirror_link_mirror,
9181                         (void *)&cmd_mirror_link_ruleid,
9182                         (void *)&cmd_mirror_link_what,
9183                         (void *)&cmd_mirror_link_dstpool,
9184                         (void *)&cmd_mirror_link_poolid,
9185                         (void *)&cmd_mirror_link_on,
9186                         NULL,
9187                 },
9188 };
9189
9190 /* *** RESET VM MIRROR RULE *** */
9191 struct cmd_rm_mirror_rule_result {
9192         cmdline_fixed_string_t reset;
9193         cmdline_fixed_string_t port;
9194         portid_t port_id;
9195         cmdline_fixed_string_t mirror;
9196         uint8_t rule_id;
9197 };
9198
9199 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9200         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9201                                  reset, "reset");
9202 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9203         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9204                                 port, "port");
9205 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9206         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9207                                 port_id, UINT16);
9208 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9209         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9210                                 mirror, "mirror-rule");
9211 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9212         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9213                                 rule_id, UINT8);
9214
9215 static void
9216 cmd_reset_mirror_rule_parsed(void *parsed_result,
9217                        __attribute__((unused)) struct cmdline *cl,
9218                        __attribute__((unused)) void *data)
9219 {
9220         int ret;
9221         struct cmd_set_mirror_link_result *res = parsed_result;
9222         /* check rule_id */
9223         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9224         if(ret < 0)
9225                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9226 }
9227
9228 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9229                 .f = cmd_reset_mirror_rule_parsed,
9230                 .data = NULL,
9231                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9232                 .tokens = {
9233                         (void *)&cmd_rm_mirror_rule_reset,
9234                         (void *)&cmd_rm_mirror_rule_port,
9235                         (void *)&cmd_rm_mirror_rule_portid,
9236                         (void *)&cmd_rm_mirror_rule_mirror,
9237                         (void *)&cmd_rm_mirror_rule_ruleid,
9238                         NULL,
9239                 },
9240 };
9241
9242 /* ******************************************************************************** */
9243
9244 struct cmd_dump_result {
9245         cmdline_fixed_string_t dump;
9246 };
9247
9248 static void
9249 dump_struct_sizes(void)
9250 {
9251 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9252         DUMP_SIZE(struct rte_mbuf);
9253         DUMP_SIZE(struct rte_mempool);
9254         DUMP_SIZE(struct rte_ring);
9255 #undef DUMP_SIZE
9256 }
9257
9258 static void cmd_dump_parsed(void *parsed_result,
9259                             __attribute__((unused)) struct cmdline *cl,
9260                             __attribute__((unused)) void *data)
9261 {
9262         struct cmd_dump_result *res = parsed_result;
9263
9264         if (!strcmp(res->dump, "dump_physmem"))
9265                 rte_dump_physmem_layout(stdout);
9266         else if (!strcmp(res->dump, "dump_memzone"))
9267                 rte_memzone_dump(stdout);
9268         else if (!strcmp(res->dump, "dump_struct_sizes"))
9269                 dump_struct_sizes();
9270         else if (!strcmp(res->dump, "dump_ring"))
9271                 rte_ring_list_dump(stdout);
9272         else if (!strcmp(res->dump, "dump_mempool"))
9273                 rte_mempool_list_dump(stdout);
9274         else if (!strcmp(res->dump, "dump_devargs"))
9275                 rte_devargs_dump(stdout);
9276         else if (!strcmp(res->dump, "dump_log_types"))
9277                 rte_log_dump(stdout);
9278 }
9279
9280 cmdline_parse_token_string_t cmd_dump_dump =
9281         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9282                 "dump_physmem#"
9283                 "dump_memzone#"
9284                 "dump_struct_sizes#"
9285                 "dump_ring#"
9286                 "dump_mempool#"
9287                 "dump_devargs#"
9288                 "dump_log_types");
9289
9290 cmdline_parse_inst_t cmd_dump = {
9291         .f = cmd_dump_parsed,  /* function to call */
9292         .data = NULL,      /* 2nd arg of func */
9293         .help_str = "Dump status",
9294         .tokens = {        /* token list, NULL terminated */
9295                 (void *)&cmd_dump_dump,
9296                 NULL,
9297         },
9298 };
9299
9300 /* ******************************************************************************** */
9301
9302 struct cmd_dump_one_result {
9303         cmdline_fixed_string_t dump;
9304         cmdline_fixed_string_t name;
9305 };
9306
9307 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9308                                 __attribute__((unused)) void *data)
9309 {
9310         struct cmd_dump_one_result *res = parsed_result;
9311
9312         if (!strcmp(res->dump, "dump_ring")) {
9313                 struct rte_ring *r;
9314                 r = rte_ring_lookup(res->name);
9315                 if (r == NULL) {
9316                         cmdline_printf(cl, "Cannot find ring\n");
9317                         return;
9318                 }
9319                 rte_ring_dump(stdout, r);
9320         } else if (!strcmp(res->dump, "dump_mempool")) {
9321                 struct rte_mempool *mp;
9322                 mp = rte_mempool_lookup(res->name);
9323                 if (mp == NULL) {
9324                         cmdline_printf(cl, "Cannot find mempool\n");
9325                         return;
9326                 }
9327                 rte_mempool_dump(stdout, mp);
9328         }
9329 }
9330
9331 cmdline_parse_token_string_t cmd_dump_one_dump =
9332         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9333                                  "dump_ring#dump_mempool");
9334
9335 cmdline_parse_token_string_t cmd_dump_one_name =
9336         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9337
9338 cmdline_parse_inst_t cmd_dump_one = {
9339         .f = cmd_dump_one_parsed,  /* function to call */
9340         .data = NULL,      /* 2nd arg of func */
9341         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9342         .tokens = {        /* token list, NULL terminated */
9343                 (void *)&cmd_dump_one_dump,
9344                 (void *)&cmd_dump_one_name,
9345                 NULL,
9346         },
9347 };
9348
9349 /* *** Add/Del syn filter *** */
9350 struct cmd_syn_filter_result {
9351         cmdline_fixed_string_t filter;
9352         portid_t port_id;
9353         cmdline_fixed_string_t ops;
9354         cmdline_fixed_string_t priority;
9355         cmdline_fixed_string_t high;
9356         cmdline_fixed_string_t queue;
9357         uint16_t queue_id;
9358 };
9359
9360 static void
9361 cmd_syn_filter_parsed(void *parsed_result,
9362                         __attribute__((unused)) struct cmdline *cl,
9363                         __attribute__((unused)) void *data)
9364 {
9365         struct cmd_syn_filter_result *res = parsed_result;
9366         struct rte_eth_syn_filter syn_filter;
9367         int ret = 0;
9368
9369         ret = rte_eth_dev_filter_supported(res->port_id,
9370                                         RTE_ETH_FILTER_SYN);
9371         if (ret < 0) {
9372                 printf("syn filter is not supported on port %u.\n",
9373                                 res->port_id);
9374                 return;
9375         }
9376
9377         memset(&syn_filter, 0, sizeof(syn_filter));
9378
9379         if (!strcmp(res->ops, "add")) {
9380                 if (!strcmp(res->high, "high"))
9381                         syn_filter.hig_pri = 1;
9382                 else
9383                         syn_filter.hig_pri = 0;
9384
9385                 syn_filter.queue = res->queue_id;
9386                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9387                                                 RTE_ETH_FILTER_SYN,
9388                                                 RTE_ETH_FILTER_ADD,
9389                                                 &syn_filter);
9390         } else
9391                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9392                                                 RTE_ETH_FILTER_SYN,
9393                                                 RTE_ETH_FILTER_DELETE,
9394                                                 &syn_filter);
9395
9396         if (ret < 0)
9397                 printf("syn filter programming error: (%s)\n",
9398                                 strerror(-ret));
9399 }
9400
9401 cmdline_parse_token_string_t cmd_syn_filter_filter =
9402         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9403         filter, "syn_filter");
9404 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9405         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9406         port_id, UINT16);
9407 cmdline_parse_token_string_t cmd_syn_filter_ops =
9408         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9409         ops, "add#del");
9410 cmdline_parse_token_string_t cmd_syn_filter_priority =
9411         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9412                                 priority, "priority");
9413 cmdline_parse_token_string_t cmd_syn_filter_high =
9414         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9415                                 high, "high#low");
9416 cmdline_parse_token_string_t cmd_syn_filter_queue =
9417         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9418                                 queue, "queue");
9419 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9420         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9421                                 queue_id, UINT16);
9422
9423 cmdline_parse_inst_t cmd_syn_filter = {
9424         .f = cmd_syn_filter_parsed,
9425         .data = NULL,
9426         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9427                 "<queue_id>: Add/Delete syn filter",
9428         .tokens = {
9429                 (void *)&cmd_syn_filter_filter,
9430                 (void *)&cmd_syn_filter_port_id,
9431                 (void *)&cmd_syn_filter_ops,
9432                 (void *)&cmd_syn_filter_priority,
9433                 (void *)&cmd_syn_filter_high,
9434                 (void *)&cmd_syn_filter_queue,
9435                 (void *)&cmd_syn_filter_queue_id,
9436                 NULL,
9437         },
9438 };
9439
9440 /* *** queue region set *** */
9441 struct cmd_queue_region_result {
9442         cmdline_fixed_string_t set;
9443         cmdline_fixed_string_t port;
9444         portid_t port_id;
9445         cmdline_fixed_string_t cmd;
9446         cmdline_fixed_string_t region;
9447         uint8_t  region_id;
9448         cmdline_fixed_string_t queue_start_index;
9449         uint8_t  queue_id;
9450         cmdline_fixed_string_t queue_num;
9451         uint8_t  queue_num_value;
9452 };
9453
9454 static void
9455 cmd_queue_region_parsed(void *parsed_result,
9456                         __attribute__((unused)) struct cmdline *cl,
9457                         __attribute__((unused)) void *data)
9458 {
9459         struct cmd_queue_region_result *res = parsed_result;
9460         int ret = -ENOTSUP;
9461 #ifdef RTE_LIBRTE_I40E_PMD
9462         struct rte_pmd_i40e_queue_region_conf region_conf;
9463         enum rte_pmd_i40e_queue_region_op op_type;
9464 #endif
9465
9466         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9467                 return;
9468
9469 #ifdef RTE_LIBRTE_I40E_PMD
9470         memset(&region_conf, 0, sizeof(region_conf));
9471         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9472         region_conf.region_id = res->region_id;
9473         region_conf.queue_num = res->queue_num_value;
9474         region_conf.queue_start_index = res->queue_id;
9475
9476         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9477                                 op_type, &region_conf);
9478 #endif
9479
9480         switch (ret) {
9481         case 0:
9482                 break;
9483         case -ENOTSUP:
9484                 printf("function not implemented or supported\n");
9485                 break;
9486         default:
9487                 printf("queue region config error: (%s)\n", strerror(-ret));
9488         }
9489 }
9490
9491 cmdline_parse_token_string_t cmd_queue_region_set =
9492 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9493                 set, "set");
9494 cmdline_parse_token_string_t cmd_queue_region_port =
9495         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9496 cmdline_parse_token_num_t cmd_queue_region_port_id =
9497         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9498                                 port_id, UINT16);
9499 cmdline_parse_token_string_t cmd_queue_region_cmd =
9500         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9501                                  cmd, "queue-region");
9502 cmdline_parse_token_string_t cmd_queue_region_id =
9503         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9504                                 region, "region_id");
9505 cmdline_parse_token_num_t cmd_queue_region_index =
9506         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9507                                 region_id, UINT8);
9508 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9509         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9510                                 queue_start_index, "queue_start_index");
9511 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9512         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9513                                 queue_id, UINT8);
9514 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9515         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9516                                 queue_num, "queue_num");
9517 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9518         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9519                                 queue_num_value, UINT8);
9520
9521 cmdline_parse_inst_t cmd_queue_region = {
9522         .f = cmd_queue_region_parsed,
9523         .data = NULL,
9524         .help_str = "set port <port_id> queue-region region_id <value> "
9525                 "queue_start_index <value> queue_num <value>: Set a queue region",
9526         .tokens = {
9527                 (void *)&cmd_queue_region_set,
9528                 (void *)&cmd_queue_region_port,
9529                 (void *)&cmd_queue_region_port_id,
9530                 (void *)&cmd_queue_region_cmd,
9531                 (void *)&cmd_queue_region_id,
9532                 (void *)&cmd_queue_region_index,
9533                 (void *)&cmd_queue_region_queue_start_index,
9534                 (void *)&cmd_queue_region_queue_id,
9535                 (void *)&cmd_queue_region_queue_num,
9536                 (void *)&cmd_queue_region_queue_num_value,
9537                 NULL,
9538         },
9539 };
9540
9541 /* *** queue region and flowtype set *** */
9542 struct cmd_region_flowtype_result {
9543         cmdline_fixed_string_t set;
9544         cmdline_fixed_string_t port;
9545         portid_t port_id;
9546         cmdline_fixed_string_t cmd;
9547         cmdline_fixed_string_t region;
9548         uint8_t  region_id;
9549         cmdline_fixed_string_t flowtype;
9550         uint8_t  flowtype_id;
9551 };
9552
9553 static void
9554 cmd_region_flowtype_parsed(void *parsed_result,
9555                         __attribute__((unused)) struct cmdline *cl,
9556                         __attribute__((unused)) void *data)
9557 {
9558         struct cmd_region_flowtype_result *res = parsed_result;
9559         int ret = -ENOTSUP;
9560 #ifdef RTE_LIBRTE_I40E_PMD
9561         struct rte_pmd_i40e_queue_region_conf region_conf;
9562         enum rte_pmd_i40e_queue_region_op op_type;
9563 #endif
9564
9565         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9566                 return;
9567
9568 #ifdef RTE_LIBRTE_I40E_PMD
9569         memset(&region_conf, 0, sizeof(region_conf));
9570
9571         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9572         region_conf.region_id = res->region_id;
9573         region_conf.hw_flowtype = res->flowtype_id;
9574
9575         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9576                         op_type, &region_conf);
9577 #endif
9578
9579         switch (ret) {
9580         case 0:
9581                 break;
9582         case -ENOTSUP:
9583                 printf("function not implemented or supported\n");
9584                 break;
9585         default:
9586                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9587         }
9588 }
9589
9590 cmdline_parse_token_string_t cmd_region_flowtype_set =
9591 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9592                                 set, "set");
9593 cmdline_parse_token_string_t cmd_region_flowtype_port =
9594         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9595                                 port, "port");
9596 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9597         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9598                                 port_id, UINT16);
9599 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9600         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9601                                 cmd, "queue-region");
9602 cmdline_parse_token_string_t cmd_region_flowtype_index =
9603         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9604                                 region, "region_id");
9605 cmdline_parse_token_num_t cmd_region_flowtype_id =
9606         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9607                                 region_id, UINT8);
9608 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9609         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9610                                 flowtype, "flowtype");
9611 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9612         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9613                                 flowtype_id, UINT8);
9614 cmdline_parse_inst_t cmd_region_flowtype = {
9615         .f = cmd_region_flowtype_parsed,
9616         .data = NULL,
9617         .help_str = "set port <port_id> queue-region region_id <value> "
9618                 "flowtype <value>: Set a flowtype region index",
9619         .tokens = {
9620                 (void *)&cmd_region_flowtype_set,
9621                 (void *)&cmd_region_flowtype_port,
9622                 (void *)&cmd_region_flowtype_port_index,
9623                 (void *)&cmd_region_flowtype_cmd,
9624                 (void *)&cmd_region_flowtype_index,
9625                 (void *)&cmd_region_flowtype_id,
9626                 (void *)&cmd_region_flowtype_flow_index,
9627                 (void *)&cmd_region_flowtype_flow_id,
9628                 NULL,
9629         },
9630 };
9631
9632 /* *** User Priority (UP) to queue region (region_id) set *** */
9633 struct cmd_user_priority_region_result {
9634         cmdline_fixed_string_t set;
9635         cmdline_fixed_string_t port;
9636         portid_t port_id;
9637         cmdline_fixed_string_t cmd;
9638         cmdline_fixed_string_t user_priority;
9639         uint8_t  user_priority_id;
9640         cmdline_fixed_string_t region;
9641         uint8_t  region_id;
9642 };
9643
9644 static void
9645 cmd_user_priority_region_parsed(void *parsed_result,
9646                         __attribute__((unused)) struct cmdline *cl,
9647                         __attribute__((unused)) void *data)
9648 {
9649         struct cmd_user_priority_region_result *res = parsed_result;
9650         int ret = -ENOTSUP;
9651 #ifdef RTE_LIBRTE_I40E_PMD
9652         struct rte_pmd_i40e_queue_region_conf region_conf;
9653         enum rte_pmd_i40e_queue_region_op op_type;
9654 #endif
9655
9656         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9657                 return;
9658
9659 #ifdef RTE_LIBRTE_I40E_PMD
9660         memset(&region_conf, 0, sizeof(region_conf));
9661         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9662         region_conf.user_priority = res->user_priority_id;
9663         region_conf.region_id = res->region_id;
9664
9665         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9666                                 op_type, &region_conf);
9667 #endif
9668
9669         switch (ret) {
9670         case 0:
9671                 break;
9672         case -ENOTSUP:
9673                 printf("function not implemented or supported\n");
9674                 break;
9675         default:
9676                 printf("user_priority region config error: (%s)\n",
9677                                 strerror(-ret));
9678         }
9679 }
9680
9681 cmdline_parse_token_string_t cmd_user_priority_region_set =
9682         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9683                                 set, "set");
9684 cmdline_parse_token_string_t cmd_user_priority_region_port =
9685         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9686                                 port, "port");
9687 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9688         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9689                                 port_id, UINT16);
9690 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9691         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9692                                 cmd, "queue-region");
9693 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9694         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9695                                 user_priority, "UP");
9696 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9697         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9698                                 user_priority_id, UINT8);
9699 cmdline_parse_token_string_t cmd_user_priority_region_region =
9700         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9701                                 region, "region_id");
9702 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9703         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9704                                 region_id, UINT8);
9705
9706 cmdline_parse_inst_t cmd_user_priority_region = {
9707         .f = cmd_user_priority_region_parsed,
9708         .data = NULL,
9709         .help_str = "set port <port_id> queue-region UP <value> "
9710                 "region_id <value>: Set the mapping of User Priority (UP) "
9711                 "to queue region (region_id) ",
9712         .tokens = {
9713                 (void *)&cmd_user_priority_region_set,
9714                 (void *)&cmd_user_priority_region_port,
9715                 (void *)&cmd_user_priority_region_port_index,
9716                 (void *)&cmd_user_priority_region_cmd,
9717                 (void *)&cmd_user_priority_region_UP,
9718                 (void *)&cmd_user_priority_region_UP_id,
9719                 (void *)&cmd_user_priority_region_region,
9720                 (void *)&cmd_user_priority_region_region_id,
9721                 NULL,
9722         },
9723 };
9724
9725 /* *** flush all queue region related configuration *** */
9726 struct cmd_flush_queue_region_result {
9727         cmdline_fixed_string_t set;
9728         cmdline_fixed_string_t port;
9729         portid_t port_id;
9730         cmdline_fixed_string_t cmd;
9731         cmdline_fixed_string_t flush;
9732         cmdline_fixed_string_t what;
9733 };
9734
9735 static void
9736 cmd_flush_queue_region_parsed(void *parsed_result,
9737                         __attribute__((unused)) struct cmdline *cl,
9738                         __attribute__((unused)) void *data)
9739 {
9740         struct cmd_flush_queue_region_result *res = parsed_result;
9741         int ret = -ENOTSUP;
9742 #ifdef RTE_LIBRTE_I40E_PMD
9743         struct rte_pmd_i40e_queue_region_conf region_conf;
9744         enum rte_pmd_i40e_queue_region_op op_type;
9745 #endif
9746
9747         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9748                 return;
9749
9750 #ifdef RTE_LIBRTE_I40E_PMD
9751         memset(&region_conf, 0, sizeof(region_conf));
9752
9753         if (strcmp(res->what, "on") == 0)
9754                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9755         else
9756                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9757
9758         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9759                                 op_type, &region_conf);
9760 #endif
9761
9762         switch (ret) {
9763         case 0:
9764                 break;
9765         case -ENOTSUP:
9766                 printf("function not implemented or supported\n");
9767                 break;
9768         default:
9769                 printf("queue region config flush error: (%s)\n",
9770                                 strerror(-ret));
9771         }
9772 }
9773
9774 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9775         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9776                                 set, "set");
9777 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9778         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9779                                 port, "port");
9780 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9781         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9782                                 port_id, UINT16);
9783 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9784         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9785                                 cmd, "queue-region");
9786 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9787         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9788                                 flush, "flush");
9789 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9790         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9791                                 what, "on#off");
9792
9793 cmdline_parse_inst_t cmd_flush_queue_region = {
9794         .f = cmd_flush_queue_region_parsed,
9795         .data = NULL,
9796         .help_str = "set port <port_id> queue-region flush on|off"
9797                 ": flush all queue region related configuration",
9798         .tokens = {
9799                 (void *)&cmd_flush_queue_region_set,
9800                 (void *)&cmd_flush_queue_region_port,
9801                 (void *)&cmd_flush_queue_region_port_index,
9802                 (void *)&cmd_flush_queue_region_cmd,
9803                 (void *)&cmd_flush_queue_region_flush,
9804                 (void *)&cmd_flush_queue_region_what,
9805                 NULL,
9806         },
9807 };
9808
9809 /* *** get all queue region related configuration info *** */
9810 struct cmd_show_queue_region_info {
9811         cmdline_fixed_string_t show;
9812         cmdline_fixed_string_t port;
9813         portid_t port_id;
9814         cmdline_fixed_string_t cmd;
9815 };
9816
9817 static void
9818 cmd_show_queue_region_info_parsed(void *parsed_result,
9819                         __attribute__((unused)) struct cmdline *cl,
9820                         __attribute__((unused)) void *data)
9821 {
9822         struct cmd_show_queue_region_info *res = parsed_result;
9823         int ret = -ENOTSUP;
9824 #ifdef RTE_LIBRTE_I40E_PMD
9825         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9826         enum rte_pmd_i40e_queue_region_op op_type;
9827 #endif
9828
9829         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9830                 return;
9831
9832 #ifdef RTE_LIBRTE_I40E_PMD
9833         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9834
9835         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9836
9837         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9838                                         op_type, &rte_pmd_regions);
9839
9840         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9841 #endif
9842
9843         switch (ret) {
9844         case 0:
9845                 break;
9846         case -ENOTSUP:
9847                 printf("function not implemented or supported\n");
9848                 break;
9849         default:
9850                 printf("queue region config info show error: (%s)\n",
9851                                 strerror(-ret));
9852         }
9853 }
9854
9855 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9856 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9857                                 show, "show");
9858 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9859         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9860                                 port, "port");
9861 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9862         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9863                                 port_id, UINT16);
9864 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9865         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9866                                 cmd, "queue-region");
9867
9868 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9869         .f = cmd_show_queue_region_info_parsed,
9870         .data = NULL,
9871         .help_str = "show port <port_id> queue-region"
9872                 ": show all queue region related configuration info",
9873         .tokens = {
9874                 (void *)&cmd_show_queue_region_info_get,
9875                 (void *)&cmd_show_queue_region_info_port,
9876                 (void *)&cmd_show_queue_region_info_port_index,
9877                 (void *)&cmd_show_queue_region_info_cmd,
9878                 NULL,
9879         },
9880 };
9881
9882 /* *** ADD/REMOVE A 2tuple FILTER *** */
9883 struct cmd_2tuple_filter_result {
9884         cmdline_fixed_string_t filter;
9885         portid_t port_id;
9886         cmdline_fixed_string_t ops;
9887         cmdline_fixed_string_t dst_port;
9888         uint16_t dst_port_value;
9889         cmdline_fixed_string_t protocol;
9890         uint8_t protocol_value;
9891         cmdline_fixed_string_t mask;
9892         uint8_t  mask_value;
9893         cmdline_fixed_string_t tcp_flags;
9894         uint8_t tcp_flags_value;
9895         cmdline_fixed_string_t priority;
9896         uint8_t  priority_value;
9897         cmdline_fixed_string_t queue;
9898         uint16_t  queue_id;
9899 };
9900
9901 static void
9902 cmd_2tuple_filter_parsed(void *parsed_result,
9903                         __attribute__((unused)) struct cmdline *cl,
9904                         __attribute__((unused)) void *data)
9905 {
9906         struct rte_eth_ntuple_filter filter;
9907         struct cmd_2tuple_filter_result *res = parsed_result;
9908         int ret = 0;
9909
9910         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9911         if (ret < 0) {
9912                 printf("ntuple filter is not supported on port %u.\n",
9913                         res->port_id);
9914                 return;
9915         }
9916
9917         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9918
9919         filter.flags = RTE_2TUPLE_FLAGS;
9920         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9921         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9922         filter.proto = res->protocol_value;
9923         filter.priority = res->priority_value;
9924         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9925                 printf("nonzero tcp_flags is only meaningful"
9926                         " when protocol is TCP.\n");
9927                 return;
9928         }
9929         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9930                 printf("invalid TCP flags.\n");
9931                 return;
9932         }
9933
9934         if (res->tcp_flags_value != 0) {
9935                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9936                 filter.tcp_flags = res->tcp_flags_value;
9937         }
9938
9939         /* need convert to big endian. */
9940         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9941         filter.queue = res->queue_id;
9942
9943         if (!strcmp(res->ops, "add"))
9944                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9945                                 RTE_ETH_FILTER_NTUPLE,
9946                                 RTE_ETH_FILTER_ADD,
9947                                 &filter);
9948         else
9949                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9950                                 RTE_ETH_FILTER_NTUPLE,
9951                                 RTE_ETH_FILTER_DELETE,
9952                                 &filter);
9953         if (ret < 0)
9954                 printf("2tuple filter programming error: (%s)\n",
9955                         strerror(-ret));
9956
9957 }
9958
9959 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9960         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9961                                  filter, "2tuple_filter");
9962 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9963         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9964                                 port_id, UINT16);
9965 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9966         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9967                                  ops, "add#del");
9968 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9969         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9970                                 dst_port, "dst_port");
9971 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9972         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9973                                 dst_port_value, UINT16);
9974 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9975         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9976                                 protocol, "protocol");
9977 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9978         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9979                                 protocol_value, UINT8);
9980 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9981         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9982                                 mask, "mask");
9983 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9984         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9985                                 mask_value, INT8);
9986 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9987         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9988                                 tcp_flags, "tcp_flags");
9989 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9990         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9991                                 tcp_flags_value, UINT8);
9992 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9993         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9994                                 priority, "priority");
9995 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9996         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9997                                 priority_value, UINT8);
9998 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9999         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10000                                 queue, "queue");
10001 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10002         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10003                                 queue_id, UINT16);
10004
10005 cmdline_parse_inst_t cmd_2tuple_filter = {
10006         .f = cmd_2tuple_filter_parsed,
10007         .data = NULL,
10008         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10009                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10010                 "<queue_id>: Add a 2tuple filter",
10011         .tokens = {
10012                 (void *)&cmd_2tuple_filter_filter,
10013                 (void *)&cmd_2tuple_filter_port_id,
10014                 (void *)&cmd_2tuple_filter_ops,
10015                 (void *)&cmd_2tuple_filter_dst_port,
10016                 (void *)&cmd_2tuple_filter_dst_port_value,
10017                 (void *)&cmd_2tuple_filter_protocol,
10018                 (void *)&cmd_2tuple_filter_protocol_value,
10019                 (void *)&cmd_2tuple_filter_mask,
10020                 (void *)&cmd_2tuple_filter_mask_value,
10021                 (void *)&cmd_2tuple_filter_tcp_flags,
10022                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10023                 (void *)&cmd_2tuple_filter_priority,
10024                 (void *)&cmd_2tuple_filter_priority_value,
10025                 (void *)&cmd_2tuple_filter_queue,
10026                 (void *)&cmd_2tuple_filter_queue_id,
10027                 NULL,
10028         },
10029 };
10030
10031 /* *** ADD/REMOVE A 5tuple FILTER *** */
10032 struct cmd_5tuple_filter_result {
10033         cmdline_fixed_string_t filter;
10034         portid_t port_id;
10035         cmdline_fixed_string_t ops;
10036         cmdline_fixed_string_t dst_ip;
10037         cmdline_ipaddr_t dst_ip_value;
10038         cmdline_fixed_string_t src_ip;
10039         cmdline_ipaddr_t src_ip_value;
10040         cmdline_fixed_string_t dst_port;
10041         uint16_t dst_port_value;
10042         cmdline_fixed_string_t src_port;
10043         uint16_t src_port_value;
10044         cmdline_fixed_string_t protocol;
10045         uint8_t protocol_value;
10046         cmdline_fixed_string_t mask;
10047         uint8_t  mask_value;
10048         cmdline_fixed_string_t tcp_flags;
10049         uint8_t tcp_flags_value;
10050         cmdline_fixed_string_t priority;
10051         uint8_t  priority_value;
10052         cmdline_fixed_string_t queue;
10053         uint16_t  queue_id;
10054 };
10055
10056 static void
10057 cmd_5tuple_filter_parsed(void *parsed_result,
10058                         __attribute__((unused)) struct cmdline *cl,
10059                         __attribute__((unused)) void *data)
10060 {
10061         struct rte_eth_ntuple_filter filter;
10062         struct cmd_5tuple_filter_result *res = parsed_result;
10063         int ret = 0;
10064
10065         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10066         if (ret < 0) {
10067                 printf("ntuple filter is not supported on port %u.\n",
10068                         res->port_id);
10069                 return;
10070         }
10071
10072         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10073
10074         filter.flags = RTE_5TUPLE_FLAGS;
10075         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10076         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10077         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10078         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10079         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10080         filter.proto = res->protocol_value;
10081         filter.priority = res->priority_value;
10082         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10083                 printf("nonzero tcp_flags is only meaningful"
10084                         " when protocol is TCP.\n");
10085                 return;
10086         }
10087         if (res->tcp_flags_value > TCP_FLAG_ALL) {
10088                 printf("invalid TCP flags.\n");
10089                 return;
10090         }
10091
10092         if (res->tcp_flags_value != 0) {
10093                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10094                 filter.tcp_flags = res->tcp_flags_value;
10095         }
10096
10097         if (res->dst_ip_value.family == AF_INET)
10098                 /* no need to convert, already big endian. */
10099                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10100         else {
10101                 if (filter.dst_ip_mask == 0) {
10102                         printf("can not support ipv6 involved compare.\n");
10103                         return;
10104                 }
10105                 filter.dst_ip = 0;
10106         }
10107
10108         if (res->src_ip_value.family == AF_INET)
10109                 /* no need to convert, already big endian. */
10110                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10111         else {
10112                 if (filter.src_ip_mask == 0) {
10113                         printf("can not support ipv6 involved compare.\n");
10114                         return;
10115                 }
10116                 filter.src_ip = 0;
10117         }
10118         /* need convert to big endian. */
10119         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10120         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10121         filter.queue = res->queue_id;
10122
10123         if (!strcmp(res->ops, "add"))
10124                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10125                                 RTE_ETH_FILTER_NTUPLE,
10126                                 RTE_ETH_FILTER_ADD,
10127                                 &filter);
10128         else
10129                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10130                                 RTE_ETH_FILTER_NTUPLE,
10131                                 RTE_ETH_FILTER_DELETE,
10132                                 &filter);
10133         if (ret < 0)
10134                 printf("5tuple filter programming error: (%s)\n",
10135                         strerror(-ret));
10136 }
10137
10138 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10139         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10140                                  filter, "5tuple_filter");
10141 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10142         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10143                                 port_id, UINT16);
10144 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10145         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10146                                  ops, "add#del");
10147 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10148         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10149                                 dst_ip, "dst_ip");
10150 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10151         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10152                                 dst_ip_value);
10153 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10154         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10155                                 src_ip, "src_ip");
10156 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10157         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10158                                 src_ip_value);
10159 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10160         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10161                                 dst_port, "dst_port");
10162 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10163         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10164                                 dst_port_value, UINT16);
10165 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10166         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10167                                 src_port, "src_port");
10168 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10169         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10170                                 src_port_value, UINT16);
10171 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10172         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10173                                 protocol, "protocol");
10174 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10175         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10176                                 protocol_value, UINT8);
10177 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10178         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10179                                 mask, "mask");
10180 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10181         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10182                                 mask_value, INT8);
10183 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10184         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10185                                 tcp_flags, "tcp_flags");
10186 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10187         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10188                                 tcp_flags_value, UINT8);
10189 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10190         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10191                                 priority, "priority");
10192 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10193         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10194                                 priority_value, UINT8);
10195 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10196         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10197                                 queue, "queue");
10198 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10199         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10200                                 queue_id, UINT16);
10201
10202 cmdline_parse_inst_t cmd_5tuple_filter = {
10203         .f = cmd_5tuple_filter_parsed,
10204         .data = NULL,
10205         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10206                 "src_ip <value> dst_port <value> src_port <value> "
10207                 "protocol <value>  mask <value> tcp_flags <value> "
10208                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10209         .tokens = {
10210                 (void *)&cmd_5tuple_filter_filter,
10211                 (void *)&cmd_5tuple_filter_port_id,
10212                 (void *)&cmd_5tuple_filter_ops,
10213                 (void *)&cmd_5tuple_filter_dst_ip,
10214                 (void *)&cmd_5tuple_filter_dst_ip_value,
10215                 (void *)&cmd_5tuple_filter_src_ip,
10216                 (void *)&cmd_5tuple_filter_src_ip_value,
10217                 (void *)&cmd_5tuple_filter_dst_port,
10218                 (void *)&cmd_5tuple_filter_dst_port_value,
10219                 (void *)&cmd_5tuple_filter_src_port,
10220                 (void *)&cmd_5tuple_filter_src_port_value,
10221                 (void *)&cmd_5tuple_filter_protocol,
10222                 (void *)&cmd_5tuple_filter_protocol_value,
10223                 (void *)&cmd_5tuple_filter_mask,
10224                 (void *)&cmd_5tuple_filter_mask_value,
10225                 (void *)&cmd_5tuple_filter_tcp_flags,
10226                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10227                 (void *)&cmd_5tuple_filter_priority,
10228                 (void *)&cmd_5tuple_filter_priority_value,
10229                 (void *)&cmd_5tuple_filter_queue,
10230                 (void *)&cmd_5tuple_filter_queue_id,
10231                 NULL,
10232         },
10233 };
10234
10235 /* *** ADD/REMOVE A flex FILTER *** */
10236 struct cmd_flex_filter_result {
10237         cmdline_fixed_string_t filter;
10238         cmdline_fixed_string_t ops;
10239         portid_t port_id;
10240         cmdline_fixed_string_t len;
10241         uint8_t len_value;
10242         cmdline_fixed_string_t bytes;
10243         cmdline_fixed_string_t bytes_value;
10244         cmdline_fixed_string_t mask;
10245         cmdline_fixed_string_t mask_value;
10246         cmdline_fixed_string_t priority;
10247         uint8_t priority_value;
10248         cmdline_fixed_string_t queue;
10249         uint16_t queue_id;
10250 };
10251
10252 static int xdigit2val(unsigned char c)
10253 {
10254         int val;
10255         if (isdigit(c))
10256                 val = c - '0';
10257         else if (isupper(c))
10258                 val = c - 'A' + 10;
10259         else
10260                 val = c - 'a' + 10;
10261         return val;
10262 }
10263
10264 static void
10265 cmd_flex_filter_parsed(void *parsed_result,
10266                           __attribute__((unused)) struct cmdline *cl,
10267                           __attribute__((unused)) void *data)
10268 {
10269         int ret = 0;
10270         struct rte_eth_flex_filter filter;
10271         struct cmd_flex_filter_result *res = parsed_result;
10272         char *bytes_ptr, *mask_ptr;
10273         uint16_t len, i, j = 0;
10274         char c;
10275         int val;
10276         uint8_t byte = 0;
10277
10278         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10279                 printf("the len exceed the max length 128\n");
10280                 return;
10281         }
10282         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10283         filter.len = res->len_value;
10284         filter.priority = res->priority_value;
10285         filter.queue = res->queue_id;
10286         bytes_ptr = res->bytes_value;
10287         mask_ptr = res->mask_value;
10288
10289          /* translate bytes string to array. */
10290         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10291                 (bytes_ptr[1] == 'X')))
10292                 bytes_ptr += 2;
10293         len = strnlen(bytes_ptr, res->len_value * 2);
10294         if (len == 0 || (len % 8 != 0)) {
10295                 printf("please check len and bytes input\n");
10296                 return;
10297         }
10298         for (i = 0; i < len; i++) {
10299                 c = bytes_ptr[i];
10300                 if (isxdigit(c) == 0) {
10301                         /* invalid characters. */
10302                         printf("invalid input\n");
10303                         return;
10304                 }
10305                 val = xdigit2val(c);
10306                 if (i % 2) {
10307                         byte |= val;
10308                         filter.bytes[j] = byte;
10309                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10310                         j++;
10311                         byte = 0;
10312                 } else
10313                         byte |= val << 4;
10314         }
10315         printf("\n");
10316          /* translate mask string to uint8_t array. */
10317         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10318                 (mask_ptr[1] == 'X')))
10319                 mask_ptr += 2;
10320         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10321         if (len == 0) {
10322                 printf("invalid input\n");
10323                 return;
10324         }
10325         j = 0;
10326         byte = 0;
10327         for (i = 0; i < len; i++) {
10328                 c = mask_ptr[i];
10329                 if (isxdigit(c) == 0) {
10330                         /* invalid characters. */
10331                         printf("invalid input\n");
10332                         return;
10333                 }
10334                 val = xdigit2val(c);
10335                 if (i % 2) {
10336                         byte |= val;
10337                         filter.mask[j] = byte;
10338                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10339                         j++;
10340                         byte = 0;
10341                 } else
10342                         byte |= val << 4;
10343         }
10344         printf("\n");
10345
10346         if (!strcmp(res->ops, "add"))
10347                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10348                                 RTE_ETH_FILTER_FLEXIBLE,
10349                                 RTE_ETH_FILTER_ADD,
10350                                 &filter);
10351         else
10352                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10353                                 RTE_ETH_FILTER_FLEXIBLE,
10354                                 RTE_ETH_FILTER_DELETE,
10355                                 &filter);
10356
10357         if (ret < 0)
10358                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10359 }
10360
10361 cmdline_parse_token_string_t cmd_flex_filter_filter =
10362         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10363                                 filter, "flex_filter");
10364 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10365         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10366                                 port_id, UINT16);
10367 cmdline_parse_token_string_t cmd_flex_filter_ops =
10368         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10369                                 ops, "add#del");
10370 cmdline_parse_token_string_t cmd_flex_filter_len =
10371         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10372                                 len, "len");
10373 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10374         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10375                                 len_value, UINT8);
10376 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10377         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10378                                 bytes, "bytes");
10379 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10380         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10381                                 bytes_value, NULL);
10382 cmdline_parse_token_string_t cmd_flex_filter_mask =
10383         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10384                                 mask, "mask");
10385 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10386         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10387                                 mask_value, NULL);
10388 cmdline_parse_token_string_t cmd_flex_filter_priority =
10389         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10390                                 priority, "priority");
10391 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10392         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10393                                 priority_value, UINT8);
10394 cmdline_parse_token_string_t cmd_flex_filter_queue =
10395         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10396                                 queue, "queue");
10397 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10398         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10399                                 queue_id, UINT16);
10400 cmdline_parse_inst_t cmd_flex_filter = {
10401         .f = cmd_flex_filter_parsed,
10402         .data = NULL,
10403         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10404                 "<value> mask <value> priority <value> queue <queue_id>: "
10405                 "Add/Del a flex filter",
10406         .tokens = {
10407                 (void *)&cmd_flex_filter_filter,
10408                 (void *)&cmd_flex_filter_port_id,
10409                 (void *)&cmd_flex_filter_ops,
10410                 (void *)&cmd_flex_filter_len,
10411                 (void *)&cmd_flex_filter_len_value,
10412                 (void *)&cmd_flex_filter_bytes,
10413                 (void *)&cmd_flex_filter_bytes_value,
10414                 (void *)&cmd_flex_filter_mask,
10415                 (void *)&cmd_flex_filter_mask_value,
10416                 (void *)&cmd_flex_filter_priority,
10417                 (void *)&cmd_flex_filter_priority_value,
10418                 (void *)&cmd_flex_filter_queue,
10419                 (void *)&cmd_flex_filter_queue_id,
10420                 NULL,
10421         },
10422 };
10423
10424 /* *** Filters Control *** */
10425
10426 /* *** deal with ethertype filter *** */
10427 struct cmd_ethertype_filter_result {
10428         cmdline_fixed_string_t filter;
10429         portid_t port_id;
10430         cmdline_fixed_string_t ops;
10431         cmdline_fixed_string_t mac;
10432         struct ether_addr mac_addr;
10433         cmdline_fixed_string_t ethertype;
10434         uint16_t ethertype_value;
10435         cmdline_fixed_string_t drop;
10436         cmdline_fixed_string_t queue;
10437         uint16_t  queue_id;
10438 };
10439
10440 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10441         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10442                                  filter, "ethertype_filter");
10443 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10444         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10445                               port_id, UINT16);
10446 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10447         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10448                                  ops, "add#del");
10449 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10450         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10451                                  mac, "mac_addr#mac_ignr");
10452 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10453         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10454                                      mac_addr);
10455 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10456         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10457                                  ethertype, "ethertype");
10458 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10459         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10460                               ethertype_value, UINT16);
10461 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10462         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10463                                  drop, "drop#fwd");
10464 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10465         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10466                                  queue, "queue");
10467 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10468         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10469                               queue_id, UINT16);
10470
10471 static void
10472 cmd_ethertype_filter_parsed(void *parsed_result,
10473                           __attribute__((unused)) struct cmdline *cl,
10474                           __attribute__((unused)) void *data)
10475 {
10476         struct cmd_ethertype_filter_result *res = parsed_result;
10477         struct rte_eth_ethertype_filter filter;
10478         int ret = 0;
10479
10480         ret = rte_eth_dev_filter_supported(res->port_id,
10481                         RTE_ETH_FILTER_ETHERTYPE);
10482         if (ret < 0) {
10483                 printf("ethertype filter is not supported on port %u.\n",
10484                         res->port_id);
10485                 return;
10486         }
10487
10488         memset(&filter, 0, sizeof(filter));
10489         if (!strcmp(res->mac, "mac_addr")) {
10490                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10491                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10492                         sizeof(struct ether_addr));
10493         }
10494         if (!strcmp(res->drop, "drop"))
10495                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10496         filter.ether_type = res->ethertype_value;
10497         filter.queue = res->queue_id;
10498
10499         if (!strcmp(res->ops, "add"))
10500                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10501                                 RTE_ETH_FILTER_ETHERTYPE,
10502                                 RTE_ETH_FILTER_ADD,
10503                                 &filter);
10504         else
10505                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10506                                 RTE_ETH_FILTER_ETHERTYPE,
10507                                 RTE_ETH_FILTER_DELETE,
10508                                 &filter);
10509         if (ret < 0)
10510                 printf("ethertype filter programming error: (%s)\n",
10511                         strerror(-ret));
10512 }
10513
10514 cmdline_parse_inst_t cmd_ethertype_filter = {
10515         .f = cmd_ethertype_filter_parsed,
10516         .data = NULL,
10517         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10518                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10519                 "Add or delete an ethertype filter entry",
10520         .tokens = {
10521                 (void *)&cmd_ethertype_filter_filter,
10522                 (void *)&cmd_ethertype_filter_port_id,
10523                 (void *)&cmd_ethertype_filter_ops,
10524                 (void *)&cmd_ethertype_filter_mac,
10525                 (void *)&cmd_ethertype_filter_mac_addr,
10526                 (void *)&cmd_ethertype_filter_ethertype,
10527                 (void *)&cmd_ethertype_filter_ethertype_value,
10528                 (void *)&cmd_ethertype_filter_drop,
10529                 (void *)&cmd_ethertype_filter_queue,
10530                 (void *)&cmd_ethertype_filter_queue_id,
10531                 NULL,
10532         },
10533 };
10534
10535 /* *** deal with flow director filter *** */
10536 struct cmd_flow_director_result {
10537         cmdline_fixed_string_t flow_director_filter;
10538         portid_t port_id;
10539         cmdline_fixed_string_t mode;
10540         cmdline_fixed_string_t mode_value;
10541         cmdline_fixed_string_t ops;
10542         cmdline_fixed_string_t flow;
10543         cmdline_fixed_string_t flow_type;
10544         cmdline_fixed_string_t ether;
10545         uint16_t ether_type;
10546         cmdline_fixed_string_t src;
10547         cmdline_ipaddr_t ip_src;
10548         uint16_t port_src;
10549         cmdline_fixed_string_t dst;
10550         cmdline_ipaddr_t ip_dst;
10551         uint16_t port_dst;
10552         cmdline_fixed_string_t verify_tag;
10553         uint32_t verify_tag_value;
10554         cmdline_fixed_string_t tos;
10555         uint8_t tos_value;
10556         cmdline_fixed_string_t proto;
10557         uint8_t proto_value;
10558         cmdline_fixed_string_t ttl;
10559         uint8_t ttl_value;
10560         cmdline_fixed_string_t vlan;
10561         uint16_t vlan_value;
10562         cmdline_fixed_string_t flexbytes;
10563         cmdline_fixed_string_t flexbytes_value;
10564         cmdline_fixed_string_t pf_vf;
10565         cmdline_fixed_string_t drop;
10566         cmdline_fixed_string_t queue;
10567         uint16_t  queue_id;
10568         cmdline_fixed_string_t fd_id;
10569         uint32_t  fd_id_value;
10570         cmdline_fixed_string_t mac;
10571         struct ether_addr mac_addr;
10572         cmdline_fixed_string_t tunnel;
10573         cmdline_fixed_string_t tunnel_type;
10574         cmdline_fixed_string_t tunnel_id;
10575         uint32_t tunnel_id_value;
10576         cmdline_fixed_string_t packet;
10577         char filepath[];
10578 };
10579
10580 static inline int
10581 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10582 {
10583         char s[256];
10584         const char *p, *p0 = q_arg;
10585         char *end;
10586         unsigned long int_fld;
10587         char *str_fld[max_num];
10588         int i;
10589         unsigned size;
10590         int ret = -1;
10591
10592         p = strchr(p0, '(');
10593         if (p == NULL)
10594                 return -1;
10595         ++p;
10596         p0 = strchr(p, ')');
10597         if (p0 == NULL)
10598                 return -1;
10599
10600         size = p0 - p;
10601         if (size >= sizeof(s))
10602                 return -1;
10603
10604         snprintf(s, sizeof(s), "%.*s", size, p);
10605         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10606         if (ret < 0 || ret > max_num)
10607                 return -1;
10608         for (i = 0; i < ret; i++) {
10609                 errno = 0;
10610                 int_fld = strtoul(str_fld[i], &end, 0);
10611                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10612                         return -1;
10613                 flexbytes[i] = (uint8_t)int_fld;
10614         }
10615         return ret;
10616 }
10617
10618 static uint16_t
10619 str2flowtype(char *string)
10620 {
10621         uint8_t i = 0;
10622         static const struct {
10623                 char str[32];
10624                 uint16_t type;
10625         } flowtype_str[] = {
10626                 {"raw", RTE_ETH_FLOW_RAW},
10627                 {"ipv4", RTE_ETH_FLOW_IPV4},
10628                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10629                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10630                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10631                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10632                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10633                 {"ipv6", RTE_ETH_FLOW_IPV6},
10634                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10635                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10636                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10637                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10638                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10639                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10640         };
10641
10642         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10643                 if (!strcmp(flowtype_str[i].str, string))
10644                         return flowtype_str[i].type;
10645         }
10646
10647         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10648                 return (uint16_t)atoi(string);
10649
10650         return RTE_ETH_FLOW_UNKNOWN;
10651 }
10652
10653 static enum rte_eth_fdir_tunnel_type
10654 str2fdir_tunneltype(char *string)
10655 {
10656         uint8_t i = 0;
10657
10658         static const struct {
10659                 char str[32];
10660                 enum rte_eth_fdir_tunnel_type type;
10661         } tunneltype_str[] = {
10662                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10663                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10664         };
10665
10666         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10667                 if (!strcmp(tunneltype_str[i].str, string))
10668                         return tunneltype_str[i].type;
10669         }
10670         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10671 }
10672
10673 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10674 do { \
10675         if ((ip_addr).family == AF_INET) \
10676                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10677         else { \
10678                 printf("invalid parameter.\n"); \
10679                 return; \
10680         } \
10681 } while (0)
10682
10683 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10684 do { \
10685         if ((ip_addr).family == AF_INET6) \
10686                 rte_memcpy(&(ip), \
10687                                  &((ip_addr).addr.ipv6), \
10688                                  sizeof(struct in6_addr)); \
10689         else { \
10690                 printf("invalid parameter.\n"); \
10691                 return; \
10692         } \
10693 } while (0)
10694
10695 static void
10696 cmd_flow_director_filter_parsed(void *parsed_result,
10697                           __attribute__((unused)) struct cmdline *cl,
10698                           __attribute__((unused)) void *data)
10699 {
10700         struct cmd_flow_director_result *res = parsed_result;
10701         struct rte_eth_fdir_filter entry;
10702         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10703         char *end;
10704         unsigned long vf_id;
10705         int ret = 0;
10706
10707         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10708         if (ret < 0) {
10709                 printf("flow director is not supported on port %u.\n",
10710                         res->port_id);
10711                 return;
10712         }
10713         memset(flexbytes, 0, sizeof(flexbytes));
10714         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10715
10716         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10717                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10718                         printf("Please set mode to MAC-VLAN.\n");
10719                         return;
10720                 }
10721         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10722                 if (strcmp(res->mode_value, "Tunnel")) {
10723                         printf("Please set mode to Tunnel.\n");
10724                         return;
10725                 }
10726         } else {
10727                 if (!strcmp(res->mode_value, "raw")) {
10728 #ifdef RTE_LIBRTE_I40E_PMD
10729                         struct rte_pmd_i40e_flow_type_mapping
10730                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10731                         struct rte_pmd_i40e_pkt_template_conf conf;
10732                         uint16_t flow_type = str2flowtype(res->flow_type);
10733                         uint16_t i, port = res->port_id;
10734                         uint8_t add;
10735
10736                         memset(&conf, 0, sizeof(conf));
10737
10738                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10739                                 printf("Invalid flow type specified.\n");
10740                                 return;
10741                         }
10742                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10743                                                                  mapping);
10744                         if (ret)
10745                                 return;
10746                         if (mapping[flow_type].pctype == 0ULL) {
10747                                 printf("Invalid flow type specified.\n");
10748                                 return;
10749                         }
10750                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10751                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10752                                         conf.input.pctype = i;
10753                                         break;
10754                                 }
10755                         }
10756
10757                         conf.input.packet = open_file(res->filepath,
10758                                                 &conf.input.length);
10759                         if (!conf.input.packet)
10760                                 return;
10761                         if (!strcmp(res->drop, "drop"))
10762                                 conf.action.behavior =
10763                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10764                         else
10765                                 conf.action.behavior =
10766                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10767                         conf.action.report_status =
10768                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10769                         conf.action.rx_queue = res->queue_id;
10770                         conf.soft_id = res->fd_id_value;
10771                         add  = strcmp(res->ops, "del") ? 1 : 0;
10772                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10773                                                                         &conf,
10774                                                                         add);
10775                         if (ret < 0)
10776                                 printf("flow director config error: (%s)\n",
10777                                        strerror(-ret));
10778                         close_file(conf.input.packet);
10779 #endif
10780                         return;
10781                 } else if (strcmp(res->mode_value, "IP")) {
10782                         printf("Please set mode to IP or raw.\n");
10783                         return;
10784                 }
10785                 entry.input.flow_type = str2flowtype(res->flow_type);
10786         }
10787
10788         ret = parse_flexbytes(res->flexbytes_value,
10789                                         flexbytes,
10790                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10791         if (ret < 0) {
10792                 printf("error: Cannot parse flexbytes input.\n");
10793                 return;
10794         }
10795
10796         switch (entry.input.flow_type) {
10797         case RTE_ETH_FLOW_FRAG_IPV4:
10798         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10799                 entry.input.flow.ip4_flow.proto = res->proto_value;
10800                 /* fall-through */
10801         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10802         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10803                 IPV4_ADDR_TO_UINT(res->ip_dst,
10804                         entry.input.flow.ip4_flow.dst_ip);
10805                 IPV4_ADDR_TO_UINT(res->ip_src,
10806                         entry.input.flow.ip4_flow.src_ip);
10807                 entry.input.flow.ip4_flow.tos = res->tos_value;
10808                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10809                 /* need convert to big endian. */
10810                 entry.input.flow.udp4_flow.dst_port =
10811                                 rte_cpu_to_be_16(res->port_dst);
10812                 entry.input.flow.udp4_flow.src_port =
10813                                 rte_cpu_to_be_16(res->port_src);
10814                 break;
10815         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10816                 IPV4_ADDR_TO_UINT(res->ip_dst,
10817                         entry.input.flow.sctp4_flow.ip.dst_ip);
10818                 IPV4_ADDR_TO_UINT(res->ip_src,
10819                         entry.input.flow.sctp4_flow.ip.src_ip);
10820                 entry.input.flow.ip4_flow.tos = res->tos_value;
10821                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10822                 /* need convert to big endian. */
10823                 entry.input.flow.sctp4_flow.dst_port =
10824                                 rte_cpu_to_be_16(res->port_dst);
10825                 entry.input.flow.sctp4_flow.src_port =
10826                                 rte_cpu_to_be_16(res->port_src);
10827                 entry.input.flow.sctp4_flow.verify_tag =
10828                                 rte_cpu_to_be_32(res->verify_tag_value);
10829                 break;
10830         case RTE_ETH_FLOW_FRAG_IPV6:
10831         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10832                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10833                 /* fall-through */
10834         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10835         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10836                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10837                         entry.input.flow.ipv6_flow.dst_ip);
10838                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10839                         entry.input.flow.ipv6_flow.src_ip);
10840                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10841                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10842                 /* need convert to big endian. */
10843                 entry.input.flow.udp6_flow.dst_port =
10844                                 rte_cpu_to_be_16(res->port_dst);
10845                 entry.input.flow.udp6_flow.src_port =
10846                                 rte_cpu_to_be_16(res->port_src);
10847                 break;
10848         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10849                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10850                         entry.input.flow.sctp6_flow.ip.dst_ip);
10851                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10852                         entry.input.flow.sctp6_flow.ip.src_ip);
10853                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10854                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10855                 /* need convert to big endian. */
10856                 entry.input.flow.sctp6_flow.dst_port =
10857                                 rte_cpu_to_be_16(res->port_dst);
10858                 entry.input.flow.sctp6_flow.src_port =
10859                                 rte_cpu_to_be_16(res->port_src);
10860                 entry.input.flow.sctp6_flow.verify_tag =
10861                                 rte_cpu_to_be_32(res->verify_tag_value);
10862                 break;
10863         case RTE_ETH_FLOW_L2_PAYLOAD:
10864                 entry.input.flow.l2_flow.ether_type =
10865                         rte_cpu_to_be_16(res->ether_type);
10866                 break;
10867         default:
10868                 break;
10869         }
10870
10871         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10872                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10873                                  &res->mac_addr,
10874                                  sizeof(struct ether_addr));
10875
10876         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10877                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10878                                  &res->mac_addr,
10879                                  sizeof(struct ether_addr));
10880                 entry.input.flow.tunnel_flow.tunnel_type =
10881                         str2fdir_tunneltype(res->tunnel_type);
10882                 entry.input.flow.tunnel_flow.tunnel_id =
10883                         rte_cpu_to_be_32(res->tunnel_id_value);
10884         }
10885
10886         rte_memcpy(entry.input.flow_ext.flexbytes,
10887                    flexbytes,
10888                    RTE_ETH_FDIR_MAX_FLEXLEN);
10889
10890         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10891
10892         entry.action.flex_off = 0;  /*use 0 by default */
10893         if (!strcmp(res->drop, "drop"))
10894                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10895         else
10896                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10897
10898         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10899             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10900                 if (!strcmp(res->pf_vf, "pf"))
10901                         entry.input.flow_ext.is_vf = 0;
10902                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10903                         struct rte_eth_dev_info dev_info;
10904
10905                         memset(&dev_info, 0, sizeof(dev_info));
10906                         rte_eth_dev_info_get(res->port_id, &dev_info);
10907                         errno = 0;
10908                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10909                         if (errno != 0 || *end != '\0' ||
10910                             vf_id >= dev_info.max_vfs) {
10911                                 printf("invalid parameter %s.\n", res->pf_vf);
10912                                 return;
10913                         }
10914                         entry.input.flow_ext.is_vf = 1;
10915                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10916                 } else {
10917                         printf("invalid parameter %s.\n", res->pf_vf);
10918                         return;
10919                 }
10920         }
10921
10922         /* set to report FD ID by default */
10923         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10924         entry.action.rx_queue = res->queue_id;
10925         entry.soft_id = res->fd_id_value;
10926         if (!strcmp(res->ops, "add"))
10927                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10928                                              RTE_ETH_FILTER_ADD, &entry);
10929         else if (!strcmp(res->ops, "del"))
10930                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10931                                              RTE_ETH_FILTER_DELETE, &entry);
10932         else
10933                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10934                                              RTE_ETH_FILTER_UPDATE, &entry);
10935         if (ret < 0)
10936                 printf("flow director programming error: (%s)\n",
10937                         strerror(-ret));
10938 }
10939
10940 cmdline_parse_token_string_t cmd_flow_director_filter =
10941         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10942                                  flow_director_filter, "flow_director_filter");
10943 cmdline_parse_token_num_t cmd_flow_director_port_id =
10944         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10945                               port_id, UINT16);
10946 cmdline_parse_token_string_t cmd_flow_director_ops =
10947         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10948                                  ops, "add#del#update");
10949 cmdline_parse_token_string_t cmd_flow_director_flow =
10950         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10951                                  flow, "flow");
10952 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10953         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10954                 flow_type, NULL);
10955 cmdline_parse_token_string_t cmd_flow_director_ether =
10956         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10957                                  ether, "ether");
10958 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10959         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10960                               ether_type, UINT16);
10961 cmdline_parse_token_string_t cmd_flow_director_src =
10962         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10963                                  src, "src");
10964 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10965         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10966                                  ip_src);
10967 cmdline_parse_token_num_t cmd_flow_director_port_src =
10968         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10969                               port_src, UINT16);
10970 cmdline_parse_token_string_t cmd_flow_director_dst =
10971         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10972                                  dst, "dst");
10973 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10974         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10975                                  ip_dst);
10976 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10977         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10978                               port_dst, UINT16);
10979 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10980         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10981                                   verify_tag, "verify_tag");
10982 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10983         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10984                               verify_tag_value, UINT32);
10985 cmdline_parse_token_string_t cmd_flow_director_tos =
10986         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10987                                  tos, "tos");
10988 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10989         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10990                               tos_value, UINT8);
10991 cmdline_parse_token_string_t cmd_flow_director_proto =
10992         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10993                                  proto, "proto");
10994 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10995         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10996                               proto_value, UINT8);
10997 cmdline_parse_token_string_t cmd_flow_director_ttl =
10998         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10999                                  ttl, "ttl");
11000 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11001         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11002                               ttl_value, UINT8);
11003 cmdline_parse_token_string_t cmd_flow_director_vlan =
11004         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11005                                  vlan, "vlan");
11006 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11007         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11008                               vlan_value, UINT16);
11009 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11010         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11011                                  flexbytes, "flexbytes");
11012 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11013         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11014                               flexbytes_value, NULL);
11015 cmdline_parse_token_string_t cmd_flow_director_drop =
11016         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11017                                  drop, "drop#fwd");
11018 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11019         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11020                               pf_vf, NULL);
11021 cmdline_parse_token_string_t cmd_flow_director_queue =
11022         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11023                                  queue, "queue");
11024 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11025         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11026                               queue_id, UINT16);
11027 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11028         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11029                                  fd_id, "fd_id");
11030 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11031         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11032                               fd_id_value, UINT32);
11033
11034 cmdline_parse_token_string_t cmd_flow_director_mode =
11035         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11036                                  mode, "mode");
11037 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11038         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11039                                  mode_value, "IP");
11040 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11041         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11042                                  mode_value, "MAC-VLAN");
11043 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11044         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11045                                  mode_value, "Tunnel");
11046 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11047         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11048                                  mode_value, "raw");
11049 cmdline_parse_token_string_t cmd_flow_director_mac =
11050         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11051                                  mac, "mac");
11052 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11053         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11054                                     mac_addr);
11055 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11056         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11057                                  tunnel, "tunnel");
11058 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11059         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11060                                  tunnel_type, "NVGRE#VxLAN");
11061 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11062         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11063                                  tunnel_id, "tunnel-id");
11064 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11065         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11066                               tunnel_id_value, UINT32);
11067 cmdline_parse_token_string_t cmd_flow_director_packet =
11068         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11069                                  packet, "packet");
11070 cmdline_parse_token_string_t cmd_flow_director_filepath =
11071         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11072                                  filepath, NULL);
11073
11074 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11075         .f = cmd_flow_director_filter_parsed,
11076         .data = NULL,
11077         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11078                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11079                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11080                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11081                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11082                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11083                 "fd_id <fd_id_value>: "
11084                 "Add or delete an ip flow director entry on NIC",
11085         .tokens = {
11086                 (void *)&cmd_flow_director_filter,
11087                 (void *)&cmd_flow_director_port_id,
11088                 (void *)&cmd_flow_director_mode,
11089                 (void *)&cmd_flow_director_mode_ip,
11090                 (void *)&cmd_flow_director_ops,
11091                 (void *)&cmd_flow_director_flow,
11092                 (void *)&cmd_flow_director_flow_type,
11093                 (void *)&cmd_flow_director_src,
11094                 (void *)&cmd_flow_director_ip_src,
11095                 (void *)&cmd_flow_director_dst,
11096                 (void *)&cmd_flow_director_ip_dst,
11097                 (void *)&cmd_flow_director_tos,
11098                 (void *)&cmd_flow_director_tos_value,
11099                 (void *)&cmd_flow_director_proto,
11100                 (void *)&cmd_flow_director_proto_value,
11101                 (void *)&cmd_flow_director_ttl,
11102                 (void *)&cmd_flow_director_ttl_value,
11103                 (void *)&cmd_flow_director_vlan,
11104                 (void *)&cmd_flow_director_vlan_value,
11105                 (void *)&cmd_flow_director_flexbytes,
11106                 (void *)&cmd_flow_director_flexbytes_value,
11107                 (void *)&cmd_flow_director_drop,
11108                 (void *)&cmd_flow_director_pf_vf,
11109                 (void *)&cmd_flow_director_queue,
11110                 (void *)&cmd_flow_director_queue_id,
11111                 (void *)&cmd_flow_director_fd_id,
11112                 (void *)&cmd_flow_director_fd_id_value,
11113                 NULL,
11114         },
11115 };
11116
11117 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11118         .f = cmd_flow_director_filter_parsed,
11119         .data = NULL,
11120         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11121                 "director entry on NIC",
11122         .tokens = {
11123                 (void *)&cmd_flow_director_filter,
11124                 (void *)&cmd_flow_director_port_id,
11125                 (void *)&cmd_flow_director_mode,
11126                 (void *)&cmd_flow_director_mode_ip,
11127                 (void *)&cmd_flow_director_ops,
11128                 (void *)&cmd_flow_director_flow,
11129                 (void *)&cmd_flow_director_flow_type,
11130                 (void *)&cmd_flow_director_src,
11131                 (void *)&cmd_flow_director_ip_src,
11132                 (void *)&cmd_flow_director_port_src,
11133                 (void *)&cmd_flow_director_dst,
11134                 (void *)&cmd_flow_director_ip_dst,
11135                 (void *)&cmd_flow_director_port_dst,
11136                 (void *)&cmd_flow_director_tos,
11137                 (void *)&cmd_flow_director_tos_value,
11138                 (void *)&cmd_flow_director_ttl,
11139                 (void *)&cmd_flow_director_ttl_value,
11140                 (void *)&cmd_flow_director_vlan,
11141                 (void *)&cmd_flow_director_vlan_value,
11142                 (void *)&cmd_flow_director_flexbytes,
11143                 (void *)&cmd_flow_director_flexbytes_value,
11144                 (void *)&cmd_flow_director_drop,
11145                 (void *)&cmd_flow_director_pf_vf,
11146                 (void *)&cmd_flow_director_queue,
11147                 (void *)&cmd_flow_director_queue_id,
11148                 (void *)&cmd_flow_director_fd_id,
11149                 (void *)&cmd_flow_director_fd_id_value,
11150                 NULL,
11151         },
11152 };
11153
11154 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11155         .f = cmd_flow_director_filter_parsed,
11156         .data = NULL,
11157         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11158                 "director entry on NIC",
11159         .tokens = {
11160                 (void *)&cmd_flow_director_filter,
11161                 (void *)&cmd_flow_director_port_id,
11162                 (void *)&cmd_flow_director_mode,
11163                 (void *)&cmd_flow_director_mode_ip,
11164                 (void *)&cmd_flow_director_ops,
11165                 (void *)&cmd_flow_director_flow,
11166                 (void *)&cmd_flow_director_flow_type,
11167                 (void *)&cmd_flow_director_src,
11168                 (void *)&cmd_flow_director_ip_src,
11169                 (void *)&cmd_flow_director_port_src,
11170                 (void *)&cmd_flow_director_dst,
11171                 (void *)&cmd_flow_director_ip_dst,
11172                 (void *)&cmd_flow_director_port_dst,
11173                 (void *)&cmd_flow_director_verify_tag,
11174                 (void *)&cmd_flow_director_verify_tag_value,
11175                 (void *)&cmd_flow_director_tos,
11176                 (void *)&cmd_flow_director_tos_value,
11177                 (void *)&cmd_flow_director_ttl,
11178                 (void *)&cmd_flow_director_ttl_value,
11179                 (void *)&cmd_flow_director_vlan,
11180                 (void *)&cmd_flow_director_vlan_value,
11181                 (void *)&cmd_flow_director_flexbytes,
11182                 (void *)&cmd_flow_director_flexbytes_value,
11183                 (void *)&cmd_flow_director_drop,
11184                 (void *)&cmd_flow_director_pf_vf,
11185                 (void *)&cmd_flow_director_queue,
11186                 (void *)&cmd_flow_director_queue_id,
11187                 (void *)&cmd_flow_director_fd_id,
11188                 (void *)&cmd_flow_director_fd_id_value,
11189                 NULL,
11190         },
11191 };
11192
11193 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11194         .f = cmd_flow_director_filter_parsed,
11195         .data = NULL,
11196         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11197                 "director entry on NIC",
11198         .tokens = {
11199                 (void *)&cmd_flow_director_filter,
11200                 (void *)&cmd_flow_director_port_id,
11201                 (void *)&cmd_flow_director_mode,
11202                 (void *)&cmd_flow_director_mode_ip,
11203                 (void *)&cmd_flow_director_ops,
11204                 (void *)&cmd_flow_director_flow,
11205                 (void *)&cmd_flow_director_flow_type,
11206                 (void *)&cmd_flow_director_ether,
11207                 (void *)&cmd_flow_director_ether_type,
11208                 (void *)&cmd_flow_director_flexbytes,
11209                 (void *)&cmd_flow_director_flexbytes_value,
11210                 (void *)&cmd_flow_director_drop,
11211                 (void *)&cmd_flow_director_pf_vf,
11212                 (void *)&cmd_flow_director_queue,
11213                 (void *)&cmd_flow_director_queue_id,
11214                 (void *)&cmd_flow_director_fd_id,
11215                 (void *)&cmd_flow_director_fd_id_value,
11216                 NULL,
11217         },
11218 };
11219
11220 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11221         .f = cmd_flow_director_filter_parsed,
11222         .data = NULL,
11223         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11224                 "director entry on NIC",
11225         .tokens = {
11226                 (void *)&cmd_flow_director_filter,
11227                 (void *)&cmd_flow_director_port_id,
11228                 (void *)&cmd_flow_director_mode,
11229                 (void *)&cmd_flow_director_mode_mac_vlan,
11230                 (void *)&cmd_flow_director_ops,
11231                 (void *)&cmd_flow_director_mac,
11232                 (void *)&cmd_flow_director_mac_addr,
11233                 (void *)&cmd_flow_director_vlan,
11234                 (void *)&cmd_flow_director_vlan_value,
11235                 (void *)&cmd_flow_director_flexbytes,
11236                 (void *)&cmd_flow_director_flexbytes_value,
11237                 (void *)&cmd_flow_director_drop,
11238                 (void *)&cmd_flow_director_queue,
11239                 (void *)&cmd_flow_director_queue_id,
11240                 (void *)&cmd_flow_director_fd_id,
11241                 (void *)&cmd_flow_director_fd_id_value,
11242                 NULL,
11243         },
11244 };
11245
11246 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11247         .f = cmd_flow_director_filter_parsed,
11248         .data = NULL,
11249         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11250                 "director entry on NIC",
11251         .tokens = {
11252                 (void *)&cmd_flow_director_filter,
11253                 (void *)&cmd_flow_director_port_id,
11254                 (void *)&cmd_flow_director_mode,
11255                 (void *)&cmd_flow_director_mode_tunnel,
11256                 (void *)&cmd_flow_director_ops,
11257                 (void *)&cmd_flow_director_mac,
11258                 (void *)&cmd_flow_director_mac_addr,
11259                 (void *)&cmd_flow_director_vlan,
11260                 (void *)&cmd_flow_director_vlan_value,
11261                 (void *)&cmd_flow_director_tunnel,
11262                 (void *)&cmd_flow_director_tunnel_type,
11263                 (void *)&cmd_flow_director_tunnel_id,
11264                 (void *)&cmd_flow_director_tunnel_id_value,
11265                 (void *)&cmd_flow_director_flexbytes,
11266                 (void *)&cmd_flow_director_flexbytes_value,
11267                 (void *)&cmd_flow_director_drop,
11268                 (void *)&cmd_flow_director_queue,
11269                 (void *)&cmd_flow_director_queue_id,
11270                 (void *)&cmd_flow_director_fd_id,
11271                 (void *)&cmd_flow_director_fd_id_value,
11272                 NULL,
11273         },
11274 };
11275
11276 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11277         .f = cmd_flow_director_filter_parsed,
11278         .data = NULL,
11279         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11280                 "director entry on NIC",
11281         .tokens = {
11282                 (void *)&cmd_flow_director_filter,
11283                 (void *)&cmd_flow_director_port_id,
11284                 (void *)&cmd_flow_director_mode,
11285                 (void *)&cmd_flow_director_mode_raw,
11286                 (void *)&cmd_flow_director_ops,
11287                 (void *)&cmd_flow_director_flow,
11288                 (void *)&cmd_flow_director_flow_type,
11289                 (void *)&cmd_flow_director_drop,
11290                 (void *)&cmd_flow_director_queue,
11291                 (void *)&cmd_flow_director_queue_id,
11292                 (void *)&cmd_flow_director_fd_id,
11293                 (void *)&cmd_flow_director_fd_id_value,
11294                 (void *)&cmd_flow_director_packet,
11295                 (void *)&cmd_flow_director_filepath,
11296                 NULL,
11297         },
11298 };
11299
11300 struct cmd_flush_flow_director_result {
11301         cmdline_fixed_string_t flush_flow_director;
11302         portid_t port_id;
11303 };
11304
11305 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11306         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11307                                  flush_flow_director, "flush_flow_director");
11308 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11309         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11310                               port_id, UINT16);
11311
11312 static void
11313 cmd_flush_flow_director_parsed(void *parsed_result,
11314                           __attribute__((unused)) struct cmdline *cl,
11315                           __attribute__((unused)) void *data)
11316 {
11317         struct cmd_flow_director_result *res = parsed_result;
11318         int ret = 0;
11319
11320         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11321         if (ret < 0) {
11322                 printf("flow director is not supported on port %u.\n",
11323                         res->port_id);
11324                 return;
11325         }
11326
11327         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11328                         RTE_ETH_FILTER_FLUSH, NULL);
11329         if (ret < 0)
11330                 printf("flow director table flushing error: (%s)\n",
11331                         strerror(-ret));
11332 }
11333
11334 cmdline_parse_inst_t cmd_flush_flow_director = {
11335         .f = cmd_flush_flow_director_parsed,
11336         .data = NULL,
11337         .help_str = "flush_flow_director <port_id>: "
11338                 "Flush all flow director entries of a device on NIC",
11339         .tokens = {
11340                 (void *)&cmd_flush_flow_director_flush,
11341                 (void *)&cmd_flush_flow_director_port_id,
11342                 NULL,
11343         },
11344 };
11345
11346 /* *** deal with flow director mask *** */
11347 struct cmd_flow_director_mask_result {
11348         cmdline_fixed_string_t flow_director_mask;
11349         portid_t port_id;
11350         cmdline_fixed_string_t mode;
11351         cmdline_fixed_string_t mode_value;
11352         cmdline_fixed_string_t vlan;
11353         uint16_t vlan_mask;
11354         cmdline_fixed_string_t src_mask;
11355         cmdline_ipaddr_t ipv4_src;
11356         cmdline_ipaddr_t ipv6_src;
11357         uint16_t port_src;
11358         cmdline_fixed_string_t dst_mask;
11359         cmdline_ipaddr_t ipv4_dst;
11360         cmdline_ipaddr_t ipv6_dst;
11361         uint16_t port_dst;
11362         cmdline_fixed_string_t mac;
11363         uint8_t mac_addr_byte_mask;
11364         cmdline_fixed_string_t tunnel_id;
11365         uint32_t tunnel_id_mask;
11366         cmdline_fixed_string_t tunnel_type;
11367         uint8_t tunnel_type_mask;
11368 };
11369
11370 static void
11371 cmd_flow_director_mask_parsed(void *parsed_result,
11372                           __attribute__((unused)) struct cmdline *cl,
11373                           __attribute__((unused)) void *data)
11374 {
11375         struct cmd_flow_director_mask_result *res = parsed_result;
11376         struct rte_eth_fdir_masks *mask;
11377         struct rte_port *port;
11378
11379         port = &ports[res->port_id];
11380         /** Check if the port is not started **/
11381         if (port->port_status != RTE_PORT_STOPPED) {
11382                 printf("Please stop port %d first\n", res->port_id);
11383                 return;
11384         }
11385
11386         mask = &port->dev_conf.fdir_conf.mask;
11387
11388         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11389                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11390                         printf("Please set mode to MAC-VLAN.\n");
11391                         return;
11392                 }
11393
11394                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11395         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11396                 if (strcmp(res->mode_value, "Tunnel")) {
11397                         printf("Please set mode to Tunnel.\n");
11398                         return;
11399                 }
11400
11401                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11402                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11403                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11404                 mask->tunnel_type_mask = res->tunnel_type_mask;
11405         } else {
11406                 if (strcmp(res->mode_value, "IP")) {
11407                         printf("Please set mode to IP.\n");
11408                         return;
11409                 }
11410
11411                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11412                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11413                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11414                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11415                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11416                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11417                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11418         }
11419
11420         cmd_reconfig_device_queue(res->port_id, 1, 1);
11421 }
11422
11423 cmdline_parse_token_string_t cmd_flow_director_mask =
11424         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11425                                  flow_director_mask, "flow_director_mask");
11426 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11427         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11428                               port_id, UINT16);
11429 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11431                                  vlan, "vlan");
11432 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11433         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11434                               vlan_mask, UINT16);
11435 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11436         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11437                                  src_mask, "src_mask");
11438 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11439         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11440                                  ipv4_src);
11441 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11442         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11443                                  ipv6_src);
11444 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11445         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11446                               port_src, UINT16);
11447 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11448         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11449                                  dst_mask, "dst_mask");
11450 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11451         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11452                                  ipv4_dst);
11453 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11454         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11455                                  ipv6_dst);
11456 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11457         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11458                               port_dst, UINT16);
11459
11460 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11461         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11462                                  mode, "mode");
11463 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11464         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11465                                  mode_value, "IP");
11466 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11467         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11468                                  mode_value, "MAC-VLAN");
11469 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11470         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11471                                  mode_value, "Tunnel");
11472 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11473         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11474                                  mac, "mac");
11475 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11476         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11477                               mac_addr_byte_mask, UINT8);
11478 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11479         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11480                                  tunnel_type, "tunnel-type");
11481 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11482         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11483                               tunnel_type_mask, UINT8);
11484 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11485         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11486                                  tunnel_id, "tunnel-id");
11487 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11488         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11489                               tunnel_id_mask, UINT32);
11490
11491 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11492         .f = cmd_flow_director_mask_parsed,
11493         .data = NULL,
11494         .help_str = "flow_director_mask ... : "
11495                 "Set IP mode flow director's mask on NIC",
11496         .tokens = {
11497                 (void *)&cmd_flow_director_mask,
11498                 (void *)&cmd_flow_director_mask_port_id,
11499                 (void *)&cmd_flow_director_mask_mode,
11500                 (void *)&cmd_flow_director_mask_mode_ip,
11501                 (void *)&cmd_flow_director_mask_vlan,
11502                 (void *)&cmd_flow_director_mask_vlan_value,
11503                 (void *)&cmd_flow_director_mask_src,
11504                 (void *)&cmd_flow_director_mask_ipv4_src,
11505                 (void *)&cmd_flow_director_mask_ipv6_src,
11506                 (void *)&cmd_flow_director_mask_port_src,
11507                 (void *)&cmd_flow_director_mask_dst,
11508                 (void *)&cmd_flow_director_mask_ipv4_dst,
11509                 (void *)&cmd_flow_director_mask_ipv6_dst,
11510                 (void *)&cmd_flow_director_mask_port_dst,
11511                 NULL,
11512         },
11513 };
11514
11515 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11516         .f = cmd_flow_director_mask_parsed,
11517         .data = NULL,
11518         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11519                 "flow director's mask on NIC",
11520         .tokens = {
11521                 (void *)&cmd_flow_director_mask,
11522                 (void *)&cmd_flow_director_mask_port_id,
11523                 (void *)&cmd_flow_director_mask_mode,
11524                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11525                 (void *)&cmd_flow_director_mask_vlan,
11526                 (void *)&cmd_flow_director_mask_vlan_value,
11527                 NULL,
11528         },
11529 };
11530
11531 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11532         .f = cmd_flow_director_mask_parsed,
11533         .data = NULL,
11534         .help_str = "flow_director_mask ... : Set tunnel mode "
11535                 "flow director's mask on NIC",
11536         .tokens = {
11537                 (void *)&cmd_flow_director_mask,
11538                 (void *)&cmd_flow_director_mask_port_id,
11539                 (void *)&cmd_flow_director_mask_mode,
11540                 (void *)&cmd_flow_director_mask_mode_tunnel,
11541                 (void *)&cmd_flow_director_mask_vlan,
11542                 (void *)&cmd_flow_director_mask_vlan_value,
11543                 (void *)&cmd_flow_director_mask_mac,
11544                 (void *)&cmd_flow_director_mask_mac_value,
11545                 (void *)&cmd_flow_director_mask_tunnel_type,
11546                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11547                 (void *)&cmd_flow_director_mask_tunnel_id,
11548                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11549                 NULL,
11550         },
11551 };
11552
11553 /* *** deal with flow director mask on flexible payload *** */
11554 struct cmd_flow_director_flex_mask_result {
11555         cmdline_fixed_string_t flow_director_flexmask;
11556         portid_t port_id;
11557         cmdline_fixed_string_t flow;
11558         cmdline_fixed_string_t flow_type;
11559         cmdline_fixed_string_t mask;
11560 };
11561
11562 static void
11563 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11564                           __attribute__((unused)) struct cmdline *cl,
11565                           __attribute__((unused)) void *data)
11566 {
11567         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11568         struct rte_eth_fdir_info fdir_info;
11569         struct rte_eth_fdir_flex_mask flex_mask;
11570         struct rte_port *port;
11571         uint64_t flow_type_mask;
11572         uint16_t i;
11573         int ret;
11574
11575         port = &ports[res->port_id];
11576         /** Check if the port is not started **/
11577         if (port->port_status != RTE_PORT_STOPPED) {
11578                 printf("Please stop port %d first\n", res->port_id);
11579                 return;
11580         }
11581
11582         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11583         ret = parse_flexbytes(res->mask,
11584                         flex_mask.mask,
11585                         RTE_ETH_FDIR_MAX_FLEXLEN);
11586         if (ret < 0) {
11587                 printf("error: Cannot parse mask input.\n");
11588                 return;
11589         }
11590
11591         memset(&fdir_info, 0, sizeof(fdir_info));
11592         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11593                                 RTE_ETH_FILTER_INFO, &fdir_info);
11594         if (ret < 0) {
11595                 printf("Cannot get FDir filter info\n");
11596                 return;
11597         }
11598
11599         if (!strcmp(res->flow_type, "none")) {
11600                 /* means don't specify the flow type */
11601                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11602                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11603                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11604                                0, sizeof(struct rte_eth_fdir_flex_mask));
11605                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11606                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11607                                  &flex_mask,
11608                                  sizeof(struct rte_eth_fdir_flex_mask));
11609                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11610                 return;
11611         }
11612         flow_type_mask = fdir_info.flow_types_mask[0];
11613         if (!strcmp(res->flow_type, "all")) {
11614                 if (!flow_type_mask) {
11615                         printf("No flow type supported\n");
11616                         return;
11617                 }
11618                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11619                         if (flow_type_mask & (1ULL << i)) {
11620                                 flex_mask.flow_type = i;
11621                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11622                         }
11623                 }
11624                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11625                 return;
11626         }
11627         flex_mask.flow_type = str2flowtype(res->flow_type);
11628         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11629                 printf("Flow type %s not supported on port %d\n",
11630                                 res->flow_type, res->port_id);
11631                 return;
11632         }
11633         fdir_set_flex_mask(res->port_id, &flex_mask);
11634         cmd_reconfig_device_queue(res->port_id, 1, 1);
11635 }
11636
11637 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11638         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11639                                  flow_director_flexmask,
11640                                  "flow_director_flex_mask");
11641 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11642         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11643                               port_id, UINT16);
11644 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11645         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11646                                  flow, "flow");
11647 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11648         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11649                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11650                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11651 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11652         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11653                                  mask, NULL);
11654
11655 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11656         .f = cmd_flow_director_flex_mask_parsed,
11657         .data = NULL,
11658         .help_str = "flow_director_flex_mask ... : "
11659                 "Set flow director's flex mask on NIC",
11660         .tokens = {
11661                 (void *)&cmd_flow_director_flexmask,
11662                 (void *)&cmd_flow_director_flexmask_port_id,
11663                 (void *)&cmd_flow_director_flexmask_flow,
11664                 (void *)&cmd_flow_director_flexmask_flow_type,
11665                 (void *)&cmd_flow_director_flexmask_mask,
11666                 NULL,
11667         },
11668 };
11669
11670 /* *** deal with flow director flexible payload configuration *** */
11671 struct cmd_flow_director_flexpayload_result {
11672         cmdline_fixed_string_t flow_director_flexpayload;
11673         portid_t port_id;
11674         cmdline_fixed_string_t payload_layer;
11675         cmdline_fixed_string_t payload_cfg;
11676 };
11677
11678 static inline int
11679 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11680 {
11681         char s[256];
11682         const char *p, *p0 = q_arg;
11683         char *end;
11684         unsigned long int_fld;
11685         char *str_fld[max_num];
11686         int i;
11687         unsigned size;
11688         int ret = -1;
11689
11690         p = strchr(p0, '(');
11691         if (p == NULL)
11692                 return -1;
11693         ++p;
11694         p0 = strchr(p, ')');
11695         if (p0 == NULL)
11696                 return -1;
11697
11698         size = p0 - p;
11699         if (size >= sizeof(s))
11700                 return -1;
11701
11702         snprintf(s, sizeof(s), "%.*s", size, p);
11703         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11704         if (ret < 0 || ret > max_num)
11705                 return -1;
11706         for (i = 0; i < ret; i++) {
11707                 errno = 0;
11708                 int_fld = strtoul(str_fld[i], &end, 0);
11709                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11710                         return -1;
11711                 offsets[i] = (uint16_t)int_fld;
11712         }
11713         return ret;
11714 }
11715
11716 static void
11717 cmd_flow_director_flxpld_parsed(void *parsed_result,
11718                           __attribute__((unused)) struct cmdline *cl,
11719                           __attribute__((unused)) void *data)
11720 {
11721         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11722         struct rte_eth_flex_payload_cfg flex_cfg;
11723         struct rte_port *port;
11724         int ret = 0;
11725
11726         port = &ports[res->port_id];
11727         /** Check if the port is not started **/
11728         if (port->port_status != RTE_PORT_STOPPED) {
11729                 printf("Please stop port %d first\n", res->port_id);
11730                 return;
11731         }
11732
11733         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11734
11735         if (!strcmp(res->payload_layer, "raw"))
11736                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11737         else if (!strcmp(res->payload_layer, "l2"))
11738                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11739         else if (!strcmp(res->payload_layer, "l3"))
11740                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11741         else if (!strcmp(res->payload_layer, "l4"))
11742                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11743
11744         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11745                             RTE_ETH_FDIR_MAX_FLEXLEN);
11746         if (ret < 0) {
11747                 printf("error: Cannot parse flex payload input.\n");
11748                 return;
11749         }
11750
11751         fdir_set_flex_payload(res->port_id, &flex_cfg);
11752         cmd_reconfig_device_queue(res->port_id, 1, 1);
11753 }
11754
11755 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11756         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11757                                  flow_director_flexpayload,
11758                                  "flow_director_flex_payload");
11759 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11760         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11761                               port_id, UINT16);
11762 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11763         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11764                                  payload_layer, "raw#l2#l3#l4");
11765 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11766         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11767                                  payload_cfg, NULL);
11768
11769 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11770         .f = cmd_flow_director_flxpld_parsed,
11771         .data = NULL,
11772         .help_str = "flow_director_flexpayload ... : "
11773                 "Set flow director's flex payload on NIC",
11774         .tokens = {
11775                 (void *)&cmd_flow_director_flexpayload,
11776                 (void *)&cmd_flow_director_flexpayload_port_id,
11777                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11778                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11779                 NULL,
11780         },
11781 };
11782
11783 /* Generic flow interface command. */
11784 extern cmdline_parse_inst_t cmd_flow;
11785
11786 /* *** Classification Filters Control *** */
11787 /* *** Get symmetric hash enable per port *** */
11788 struct cmd_get_sym_hash_ena_per_port_result {
11789         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11790         portid_t port_id;
11791 };
11792
11793 static void
11794 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11795                                  __rte_unused struct cmdline *cl,
11796                                  __rte_unused void *data)
11797 {
11798         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11799         struct rte_eth_hash_filter_info info;
11800         int ret;
11801
11802         if (rte_eth_dev_filter_supported(res->port_id,
11803                                 RTE_ETH_FILTER_HASH) < 0) {
11804                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11805                                                         res->port_id);
11806                 return;
11807         }
11808
11809         memset(&info, 0, sizeof(info));
11810         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11811         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11812                                                 RTE_ETH_FILTER_GET, &info);
11813
11814         if (ret < 0) {
11815                 printf("Cannot get symmetric hash enable per port "
11816                                         "on port %u\n", res->port_id);
11817                 return;
11818         }
11819
11820         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11821                                 "enabled" : "disabled", res->port_id);
11822 }
11823
11824 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11825         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11826                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11827 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11828         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11829                 port_id, UINT16);
11830
11831 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11832         .f = cmd_get_sym_hash_per_port_parsed,
11833         .data = NULL,
11834         .help_str = "get_sym_hash_ena_per_port <port_id>",
11835         .tokens = {
11836                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11837                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11838                 NULL,
11839         },
11840 };
11841
11842 /* *** Set symmetric hash enable per port *** */
11843 struct cmd_set_sym_hash_ena_per_port_result {
11844         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11845         cmdline_fixed_string_t enable;
11846         portid_t port_id;
11847 };
11848
11849 static void
11850 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11851                                  __rte_unused struct cmdline *cl,
11852                                  __rte_unused void *data)
11853 {
11854         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11855         struct rte_eth_hash_filter_info info;
11856         int ret;
11857
11858         if (rte_eth_dev_filter_supported(res->port_id,
11859                                 RTE_ETH_FILTER_HASH) < 0) {
11860                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11861                                                         res->port_id);
11862                 return;
11863         }
11864
11865         memset(&info, 0, sizeof(info));
11866         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11867         if (!strcmp(res->enable, "enable"))
11868                 info.info.enable = 1;
11869         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11870                                         RTE_ETH_FILTER_SET, &info);
11871         if (ret < 0) {
11872                 printf("Cannot set symmetric hash enable per port on "
11873                                         "port %u\n", res->port_id);
11874                 return;
11875         }
11876         printf("Symmetric hash has been set to %s on port %u\n",
11877                                         res->enable, res->port_id);
11878 }
11879
11880 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11881         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11882                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11883 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11884         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11885                 port_id, UINT16);
11886 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11887         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11888                 enable, "enable#disable");
11889
11890 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11891         .f = cmd_set_sym_hash_per_port_parsed,
11892         .data = NULL,
11893         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11894         .tokens = {
11895                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11896                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11897                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11898                 NULL,
11899         },
11900 };
11901
11902 /* Get global config of hash function */
11903 struct cmd_get_hash_global_config_result {
11904         cmdline_fixed_string_t get_hash_global_config;
11905         portid_t port_id;
11906 };
11907
11908 static char *
11909 flowtype_to_str(uint16_t ftype)
11910 {
11911         uint16_t i;
11912         static struct {
11913                 char str[16];
11914                 uint16_t ftype;
11915         } ftype_table[] = {
11916                 {"ipv4", RTE_ETH_FLOW_IPV4},
11917                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11918                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11919                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11920                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11921                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11922                 {"ipv6", RTE_ETH_FLOW_IPV6},
11923                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11924                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11925                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11926                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11927                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11928                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11929                 {"port", RTE_ETH_FLOW_PORT},
11930                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11931                 {"geneve", RTE_ETH_FLOW_GENEVE},
11932                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11933         };
11934
11935         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11936                 if (ftype_table[i].ftype == ftype)
11937                         return ftype_table[i].str;
11938         }
11939
11940         return NULL;
11941 }
11942
11943 static void
11944 cmd_get_hash_global_config_parsed(void *parsed_result,
11945                                   __rte_unused struct cmdline *cl,
11946                                   __rte_unused void *data)
11947 {
11948         struct cmd_get_hash_global_config_result *res = parsed_result;
11949         struct rte_eth_hash_filter_info info;
11950         uint32_t idx, offset;
11951         uint16_t i;
11952         char *str;
11953         int ret;
11954
11955         if (rte_eth_dev_filter_supported(res->port_id,
11956                         RTE_ETH_FILTER_HASH) < 0) {
11957                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11958                                                         res->port_id);
11959                 return;
11960         }
11961
11962         memset(&info, 0, sizeof(info));
11963         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11964         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11965                                         RTE_ETH_FILTER_GET, &info);
11966         if (ret < 0) {
11967                 printf("Cannot get hash global configurations by port %d\n",
11968                                                         res->port_id);
11969                 return;
11970         }
11971
11972         switch (info.info.global_conf.hash_func) {
11973         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11974                 printf("Hash function is Toeplitz\n");
11975                 break;
11976         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11977                 printf("Hash function is Simple XOR\n");
11978                 break;
11979         default:
11980                 printf("Unknown hash function\n");
11981                 break;
11982         }
11983
11984         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11985                 idx = i / UINT64_BIT;
11986                 offset = i % UINT64_BIT;
11987                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11988                                                 (1ULL << offset)))
11989                         continue;
11990                 str = flowtype_to_str(i);
11991                 if (!str)
11992                         continue;
11993                 printf("Symmetric hash is %s globally for flow type %s "
11994                                                         "by port %d\n",
11995                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11996                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11997                                                         res->port_id);
11998         }
11999 }
12000
12001 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12002         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12003                 get_hash_global_config, "get_hash_global_config");
12004 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12005         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12006                 port_id, UINT16);
12007
12008 cmdline_parse_inst_t cmd_get_hash_global_config = {
12009         .f = cmd_get_hash_global_config_parsed,
12010         .data = NULL,
12011         .help_str = "get_hash_global_config <port_id>",
12012         .tokens = {
12013                 (void *)&cmd_get_hash_global_config_all,
12014                 (void *)&cmd_get_hash_global_config_port_id,
12015                 NULL,
12016         },
12017 };
12018
12019 /* Set global config of hash function */
12020 struct cmd_set_hash_global_config_result {
12021         cmdline_fixed_string_t set_hash_global_config;
12022         portid_t port_id;
12023         cmdline_fixed_string_t hash_func;
12024         cmdline_fixed_string_t flow_type;
12025         cmdline_fixed_string_t enable;
12026 };
12027
12028 static void
12029 cmd_set_hash_global_config_parsed(void *parsed_result,
12030                                   __rte_unused struct cmdline *cl,
12031                                   __rte_unused void *data)
12032 {
12033         struct cmd_set_hash_global_config_result *res = parsed_result;
12034         struct rte_eth_hash_filter_info info;
12035         uint32_t ftype, idx, offset;
12036         int ret;
12037
12038         if (rte_eth_dev_filter_supported(res->port_id,
12039                                 RTE_ETH_FILTER_HASH) < 0) {
12040                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12041                                                         res->port_id);
12042                 return;
12043         }
12044         memset(&info, 0, sizeof(info));
12045         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12046         if (!strcmp(res->hash_func, "toeplitz"))
12047                 info.info.global_conf.hash_func =
12048                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12049         else if (!strcmp(res->hash_func, "simple_xor"))
12050                 info.info.global_conf.hash_func =
12051                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12052         else if (!strcmp(res->hash_func, "default"))
12053                 info.info.global_conf.hash_func =
12054                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12055
12056         ftype = str2flowtype(res->flow_type);
12057         idx = ftype / UINT64_BIT;
12058         offset = ftype % UINT64_BIT;
12059         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12060         if (!strcmp(res->enable, "enable"))
12061                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12062                                                 (1ULL << offset);
12063         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12064                                         RTE_ETH_FILTER_SET, &info);
12065         if (ret < 0)
12066                 printf("Cannot set global hash configurations by port %d\n",
12067                                                         res->port_id);
12068         else
12069                 printf("Global hash configurations have been set "
12070                         "succcessfully by port %d\n", res->port_id);
12071 }
12072
12073 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12074         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12075                 set_hash_global_config, "set_hash_global_config");
12076 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12077         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12078                 port_id, UINT16);
12079 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12080         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12081                 hash_func, "toeplitz#simple_xor#default");
12082 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12083         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12084                 flow_type,
12085                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12086                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12087 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12088         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12089                 enable, "enable#disable");
12090
12091 cmdline_parse_inst_t cmd_set_hash_global_config = {
12092         .f = cmd_set_hash_global_config_parsed,
12093         .data = NULL,
12094         .help_str = "set_hash_global_config <port_id> "
12095                 "toeplitz|simple_xor|default "
12096                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12097                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12098                 "l2_payload enable|disable",
12099         .tokens = {
12100                 (void *)&cmd_set_hash_global_config_all,
12101                 (void *)&cmd_set_hash_global_config_port_id,
12102                 (void *)&cmd_set_hash_global_config_hash_func,
12103                 (void *)&cmd_set_hash_global_config_flow_type,
12104                 (void *)&cmd_set_hash_global_config_enable,
12105                 NULL,
12106         },
12107 };
12108
12109 /* Set hash input set */
12110 struct cmd_set_hash_input_set_result {
12111         cmdline_fixed_string_t set_hash_input_set;
12112         portid_t port_id;
12113         cmdline_fixed_string_t flow_type;
12114         cmdline_fixed_string_t inset_field;
12115         cmdline_fixed_string_t select;
12116 };
12117
12118 static enum rte_eth_input_set_field
12119 str2inset(char *string)
12120 {
12121         uint16_t i;
12122
12123         static const struct {
12124                 char str[32];
12125                 enum rte_eth_input_set_field inset;
12126         } inset_table[] = {
12127                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12128                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12129                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12130                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12131                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12132                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12133                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12134                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12135                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12136                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12137                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12138                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12139                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12140                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12141                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12142                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12143                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12144                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12145                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12146                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12147                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12148                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12149                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12150                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12151                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12152                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12153                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12154                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12155                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12156                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12157                 {"none", RTE_ETH_INPUT_SET_NONE},
12158         };
12159
12160         for (i = 0; i < RTE_DIM(inset_table); i++) {
12161                 if (!strcmp(string, inset_table[i].str))
12162                         return inset_table[i].inset;
12163         }
12164
12165         return RTE_ETH_INPUT_SET_UNKNOWN;
12166 }
12167
12168 static void
12169 cmd_set_hash_input_set_parsed(void *parsed_result,
12170                               __rte_unused struct cmdline *cl,
12171                               __rte_unused void *data)
12172 {
12173         struct cmd_set_hash_input_set_result *res = parsed_result;
12174         struct rte_eth_hash_filter_info info;
12175
12176         memset(&info, 0, sizeof(info));
12177         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12178         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12179         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12180         info.info.input_set_conf.inset_size = 1;
12181         if (!strcmp(res->select, "select"))
12182                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12183         else if (!strcmp(res->select, "add"))
12184                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12185         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12186                                 RTE_ETH_FILTER_SET, &info);
12187 }
12188
12189 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12190         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12191                 set_hash_input_set, "set_hash_input_set");
12192 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12193         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12194                 port_id, UINT16);
12195 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12196         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12197                 flow_type, NULL);
12198 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12199         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12200                 inset_field,
12201                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12202                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12203                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12204                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12205                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12206                 "fld-8th#none");
12207 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12208         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12209                 select, "select#add");
12210
12211 cmdline_parse_inst_t cmd_set_hash_input_set = {
12212         .f = cmd_set_hash_input_set_parsed,
12213         .data = NULL,
12214         .help_str = "set_hash_input_set <port_id> "
12215         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12216         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12217         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12218         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12219         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12220         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12221         "fld-7th|fld-8th|none select|add",
12222         .tokens = {
12223                 (void *)&cmd_set_hash_input_set_cmd,
12224                 (void *)&cmd_set_hash_input_set_port_id,
12225                 (void *)&cmd_set_hash_input_set_flow_type,
12226                 (void *)&cmd_set_hash_input_set_field,
12227                 (void *)&cmd_set_hash_input_set_select,
12228                 NULL,
12229         },
12230 };
12231
12232 /* Set flow director input set */
12233 struct cmd_set_fdir_input_set_result {
12234         cmdline_fixed_string_t set_fdir_input_set;
12235         portid_t port_id;
12236         cmdline_fixed_string_t flow_type;
12237         cmdline_fixed_string_t inset_field;
12238         cmdline_fixed_string_t select;
12239 };
12240
12241 static void
12242 cmd_set_fdir_input_set_parsed(void *parsed_result,
12243         __rte_unused struct cmdline *cl,
12244         __rte_unused void *data)
12245 {
12246         struct cmd_set_fdir_input_set_result *res = parsed_result;
12247         struct rte_eth_fdir_filter_info info;
12248
12249         memset(&info, 0, sizeof(info));
12250         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12251         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12252         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12253         info.info.input_set_conf.inset_size = 1;
12254         if (!strcmp(res->select, "select"))
12255                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12256         else if (!strcmp(res->select, "add"))
12257                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12258         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12259                 RTE_ETH_FILTER_SET, &info);
12260 }
12261
12262 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12263         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12264         set_fdir_input_set, "set_fdir_input_set");
12265 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12266         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12267         port_id, UINT16);
12268 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12269         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12270         flow_type,
12271         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12272         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12273 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12274         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12275         inset_field,
12276         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12277         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12278         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12279         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12280         "sctp-veri-tag#none");
12281 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12282         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12283         select, "select#add");
12284
12285 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12286         .f = cmd_set_fdir_input_set_parsed,
12287         .data = NULL,
12288         .help_str = "set_fdir_input_set <port_id> "
12289         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12290         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12291         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12292         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12293         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12294         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12295         "sctp-veri-tag|none select|add",
12296         .tokens = {
12297                 (void *)&cmd_set_fdir_input_set_cmd,
12298                 (void *)&cmd_set_fdir_input_set_port_id,
12299                 (void *)&cmd_set_fdir_input_set_flow_type,
12300                 (void *)&cmd_set_fdir_input_set_field,
12301                 (void *)&cmd_set_fdir_input_set_select,
12302                 NULL,
12303         },
12304 };
12305
12306 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12307 struct cmd_mcast_addr_result {
12308         cmdline_fixed_string_t mcast_addr_cmd;
12309         cmdline_fixed_string_t what;
12310         uint16_t port_num;
12311         struct ether_addr mc_addr;
12312 };
12313
12314 static void cmd_mcast_addr_parsed(void *parsed_result,
12315                 __attribute__((unused)) struct cmdline *cl,
12316                 __attribute__((unused)) void *data)
12317 {
12318         struct cmd_mcast_addr_result *res = parsed_result;
12319
12320         if (!is_multicast_ether_addr(&res->mc_addr)) {
12321                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12322                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12323                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12324                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12325                 return;
12326         }
12327         if (strcmp(res->what, "add") == 0)
12328                 mcast_addr_add(res->port_num, &res->mc_addr);
12329         else
12330                 mcast_addr_remove(res->port_num, &res->mc_addr);
12331 }
12332
12333 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12334         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12335                                  mcast_addr_cmd, "mcast_addr");
12336 cmdline_parse_token_string_t cmd_mcast_addr_what =
12337         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12338                                  "add#remove");
12339 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12340         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12341 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12342         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12343
12344 cmdline_parse_inst_t cmd_mcast_addr = {
12345         .f = cmd_mcast_addr_parsed,
12346         .data = (void *)0,
12347         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12348                 "Add/Remove multicast MAC address on port_id",
12349         .tokens = {
12350                 (void *)&cmd_mcast_addr_cmd,
12351                 (void *)&cmd_mcast_addr_what,
12352                 (void *)&cmd_mcast_addr_portnum,
12353                 (void *)&cmd_mcast_addr_addr,
12354                 NULL,
12355         },
12356 };
12357
12358 /* l2 tunnel config
12359  * only support E-tag now.
12360  */
12361
12362 /* Ether type config */
12363 struct cmd_config_l2_tunnel_eth_type_result {
12364         cmdline_fixed_string_t port;
12365         cmdline_fixed_string_t config;
12366         cmdline_fixed_string_t all;
12367         portid_t id;
12368         cmdline_fixed_string_t l2_tunnel;
12369         cmdline_fixed_string_t l2_tunnel_type;
12370         cmdline_fixed_string_t eth_type;
12371         uint16_t eth_type_val;
12372 };
12373
12374 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12375         TOKEN_STRING_INITIALIZER
12376                 (struct cmd_config_l2_tunnel_eth_type_result,
12377                  port, "port");
12378 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12379         TOKEN_STRING_INITIALIZER
12380                 (struct cmd_config_l2_tunnel_eth_type_result,
12381                  config, "config");
12382 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12383         TOKEN_STRING_INITIALIZER
12384                 (struct cmd_config_l2_tunnel_eth_type_result,
12385                  all, "all");
12386 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12387         TOKEN_NUM_INITIALIZER
12388                 (struct cmd_config_l2_tunnel_eth_type_result,
12389                  id, UINT16);
12390 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12391         TOKEN_STRING_INITIALIZER
12392                 (struct cmd_config_l2_tunnel_eth_type_result,
12393                  l2_tunnel, "l2-tunnel");
12394 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12395         TOKEN_STRING_INITIALIZER
12396                 (struct cmd_config_l2_tunnel_eth_type_result,
12397                  l2_tunnel_type, "E-tag");
12398 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12399         TOKEN_STRING_INITIALIZER
12400                 (struct cmd_config_l2_tunnel_eth_type_result,
12401                  eth_type, "ether-type");
12402 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12403         TOKEN_NUM_INITIALIZER
12404                 (struct cmd_config_l2_tunnel_eth_type_result,
12405                  eth_type_val, UINT16);
12406
12407 static enum rte_eth_tunnel_type
12408 str2fdir_l2_tunnel_type(char *string)
12409 {
12410         uint32_t i = 0;
12411
12412         static const struct {
12413                 char str[32];
12414                 enum rte_eth_tunnel_type type;
12415         } l2_tunnel_type_str[] = {
12416                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12417         };
12418
12419         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12420                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12421                         return l2_tunnel_type_str[i].type;
12422         }
12423         return RTE_TUNNEL_TYPE_NONE;
12424 }
12425
12426 /* ether type config for all ports */
12427 static void
12428 cmd_config_l2_tunnel_eth_type_all_parsed
12429         (void *parsed_result,
12430          __attribute__((unused)) struct cmdline *cl,
12431          __attribute__((unused)) void *data)
12432 {
12433         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12434         struct rte_eth_l2_tunnel_conf entry;
12435         portid_t pid;
12436
12437         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12438         entry.ether_type = res->eth_type_val;
12439
12440         RTE_ETH_FOREACH_DEV(pid) {
12441                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12442         }
12443 }
12444
12445 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12446         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12447         .data = NULL,
12448         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12449         .tokens = {
12450                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12451                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12452                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12453                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12454                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12455                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12456                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12457                 NULL,
12458         },
12459 };
12460
12461 /* ether type config for a specific port */
12462 static void
12463 cmd_config_l2_tunnel_eth_type_specific_parsed(
12464         void *parsed_result,
12465         __attribute__((unused)) struct cmdline *cl,
12466         __attribute__((unused)) void *data)
12467 {
12468         struct cmd_config_l2_tunnel_eth_type_result *res =
12469                  parsed_result;
12470         struct rte_eth_l2_tunnel_conf entry;
12471
12472         if (port_id_is_invalid(res->id, ENABLED_WARN))
12473                 return;
12474
12475         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12476         entry.ether_type = res->eth_type_val;
12477
12478         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12479 }
12480
12481 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12482         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12483         .data = NULL,
12484         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12485         .tokens = {
12486                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12487                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12488                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12489                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12490                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12491                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12492                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12493                 NULL,
12494         },
12495 };
12496
12497 /* Enable/disable l2 tunnel */
12498 struct cmd_config_l2_tunnel_en_dis_result {
12499         cmdline_fixed_string_t port;
12500         cmdline_fixed_string_t config;
12501         cmdline_fixed_string_t all;
12502         portid_t id;
12503         cmdline_fixed_string_t l2_tunnel;
12504         cmdline_fixed_string_t l2_tunnel_type;
12505         cmdline_fixed_string_t en_dis;
12506 };
12507
12508 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12509         TOKEN_STRING_INITIALIZER
12510                 (struct cmd_config_l2_tunnel_en_dis_result,
12511                  port, "port");
12512 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12513         TOKEN_STRING_INITIALIZER
12514                 (struct cmd_config_l2_tunnel_en_dis_result,
12515                  config, "config");
12516 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12517         TOKEN_STRING_INITIALIZER
12518                 (struct cmd_config_l2_tunnel_en_dis_result,
12519                  all, "all");
12520 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12521         TOKEN_NUM_INITIALIZER
12522                 (struct cmd_config_l2_tunnel_en_dis_result,
12523                  id, UINT16);
12524 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12525         TOKEN_STRING_INITIALIZER
12526                 (struct cmd_config_l2_tunnel_en_dis_result,
12527                  l2_tunnel, "l2-tunnel");
12528 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12529         TOKEN_STRING_INITIALIZER
12530                 (struct cmd_config_l2_tunnel_en_dis_result,
12531                  l2_tunnel_type, "E-tag");
12532 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12533         TOKEN_STRING_INITIALIZER
12534                 (struct cmd_config_l2_tunnel_en_dis_result,
12535                  en_dis, "enable#disable");
12536
12537 /* enable/disable l2 tunnel for all ports */
12538 static void
12539 cmd_config_l2_tunnel_en_dis_all_parsed(
12540         void *parsed_result,
12541         __attribute__((unused)) struct cmdline *cl,
12542         __attribute__((unused)) void *data)
12543 {
12544         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12545         struct rte_eth_l2_tunnel_conf entry;
12546         portid_t pid;
12547         uint8_t en;
12548
12549         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12550
12551         if (!strcmp("enable", res->en_dis))
12552                 en = 1;
12553         else
12554                 en = 0;
12555
12556         RTE_ETH_FOREACH_DEV(pid) {
12557                 rte_eth_dev_l2_tunnel_offload_set(pid,
12558                                                   &entry,
12559                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12560                                                   en);
12561         }
12562 }
12563
12564 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12565         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12566         .data = NULL,
12567         .help_str = "port config all l2-tunnel E-tag enable|disable",
12568         .tokens = {
12569                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12570                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12571                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12572                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12573                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12574                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12575                 NULL,
12576         },
12577 };
12578
12579 /* enable/disable l2 tunnel for a port */
12580 static void
12581 cmd_config_l2_tunnel_en_dis_specific_parsed(
12582         void *parsed_result,
12583         __attribute__((unused)) struct cmdline *cl,
12584         __attribute__((unused)) void *data)
12585 {
12586         struct cmd_config_l2_tunnel_en_dis_result *res =
12587                 parsed_result;
12588         struct rte_eth_l2_tunnel_conf entry;
12589
12590         if (port_id_is_invalid(res->id, ENABLED_WARN))
12591                 return;
12592
12593         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12594
12595         if (!strcmp("enable", res->en_dis))
12596                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12597                                                   &entry,
12598                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12599                                                   1);
12600         else
12601                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12602                                                   &entry,
12603                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12604                                                   0);
12605 }
12606
12607 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12608         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12609         .data = NULL,
12610         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12611         .tokens = {
12612                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12613                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12614                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12615                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12616                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12617                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12618                 NULL,
12619         },
12620 };
12621
12622 /* E-tag configuration */
12623
12624 /* Common result structure for all E-tag configuration */
12625 struct cmd_config_e_tag_result {
12626         cmdline_fixed_string_t e_tag;
12627         cmdline_fixed_string_t set;
12628         cmdline_fixed_string_t insertion;
12629         cmdline_fixed_string_t stripping;
12630         cmdline_fixed_string_t forwarding;
12631         cmdline_fixed_string_t filter;
12632         cmdline_fixed_string_t add;
12633         cmdline_fixed_string_t del;
12634         cmdline_fixed_string_t on;
12635         cmdline_fixed_string_t off;
12636         cmdline_fixed_string_t on_off;
12637         cmdline_fixed_string_t port_tag_id;
12638         uint32_t port_tag_id_val;
12639         cmdline_fixed_string_t e_tag_id;
12640         uint16_t e_tag_id_val;
12641         cmdline_fixed_string_t dst_pool;
12642         uint8_t dst_pool_val;
12643         cmdline_fixed_string_t port;
12644         portid_t port_id;
12645         cmdline_fixed_string_t vf;
12646         uint8_t vf_id;
12647 };
12648
12649 /* Common CLI fields for all E-tag configuration */
12650 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12651         TOKEN_STRING_INITIALIZER
12652                 (struct cmd_config_e_tag_result,
12653                  e_tag, "E-tag");
12654 cmdline_parse_token_string_t cmd_config_e_tag_set =
12655         TOKEN_STRING_INITIALIZER
12656                 (struct cmd_config_e_tag_result,
12657                  set, "set");
12658 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12659         TOKEN_STRING_INITIALIZER
12660                 (struct cmd_config_e_tag_result,
12661                  insertion, "insertion");
12662 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12663         TOKEN_STRING_INITIALIZER
12664                 (struct cmd_config_e_tag_result,
12665                  stripping, "stripping");
12666 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12667         TOKEN_STRING_INITIALIZER
12668                 (struct cmd_config_e_tag_result,
12669                  forwarding, "forwarding");
12670 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12671         TOKEN_STRING_INITIALIZER
12672                 (struct cmd_config_e_tag_result,
12673                  filter, "filter");
12674 cmdline_parse_token_string_t cmd_config_e_tag_add =
12675         TOKEN_STRING_INITIALIZER
12676                 (struct cmd_config_e_tag_result,
12677                  add, "add");
12678 cmdline_parse_token_string_t cmd_config_e_tag_del =
12679         TOKEN_STRING_INITIALIZER
12680                 (struct cmd_config_e_tag_result,
12681                  del, "del");
12682 cmdline_parse_token_string_t cmd_config_e_tag_on =
12683         TOKEN_STRING_INITIALIZER
12684                 (struct cmd_config_e_tag_result,
12685                  on, "on");
12686 cmdline_parse_token_string_t cmd_config_e_tag_off =
12687         TOKEN_STRING_INITIALIZER
12688                 (struct cmd_config_e_tag_result,
12689                  off, "off");
12690 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12691         TOKEN_STRING_INITIALIZER
12692                 (struct cmd_config_e_tag_result,
12693                  on_off, "on#off");
12694 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12695         TOKEN_STRING_INITIALIZER
12696                 (struct cmd_config_e_tag_result,
12697                  port_tag_id, "port-tag-id");
12698 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12699         TOKEN_NUM_INITIALIZER
12700                 (struct cmd_config_e_tag_result,
12701                  port_tag_id_val, UINT32);
12702 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12703         TOKEN_STRING_INITIALIZER
12704                 (struct cmd_config_e_tag_result,
12705                  e_tag_id, "e-tag-id");
12706 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12707         TOKEN_NUM_INITIALIZER
12708                 (struct cmd_config_e_tag_result,
12709                  e_tag_id_val, UINT16);
12710 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12711         TOKEN_STRING_INITIALIZER
12712                 (struct cmd_config_e_tag_result,
12713                  dst_pool, "dst-pool");
12714 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12715         TOKEN_NUM_INITIALIZER
12716                 (struct cmd_config_e_tag_result,
12717                  dst_pool_val, UINT8);
12718 cmdline_parse_token_string_t cmd_config_e_tag_port =
12719         TOKEN_STRING_INITIALIZER
12720                 (struct cmd_config_e_tag_result,
12721                  port, "port");
12722 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12723         TOKEN_NUM_INITIALIZER
12724                 (struct cmd_config_e_tag_result,
12725                  port_id, UINT16);
12726 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12727         TOKEN_STRING_INITIALIZER
12728                 (struct cmd_config_e_tag_result,
12729                  vf, "vf");
12730 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12731         TOKEN_NUM_INITIALIZER
12732                 (struct cmd_config_e_tag_result,
12733                  vf_id, UINT8);
12734
12735 /* E-tag insertion configuration */
12736 static void
12737 cmd_config_e_tag_insertion_en_parsed(
12738         void *parsed_result,
12739         __attribute__((unused)) struct cmdline *cl,
12740         __attribute__((unused)) void *data)
12741 {
12742         struct cmd_config_e_tag_result *res =
12743                 parsed_result;
12744         struct rte_eth_l2_tunnel_conf entry;
12745
12746         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12747                 return;
12748
12749         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12750         entry.tunnel_id = res->port_tag_id_val;
12751         entry.vf_id = res->vf_id;
12752         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12753                                           &entry,
12754                                           ETH_L2_TUNNEL_INSERTION_MASK,
12755                                           1);
12756 }
12757
12758 static void
12759 cmd_config_e_tag_insertion_dis_parsed(
12760         void *parsed_result,
12761         __attribute__((unused)) struct cmdline *cl,
12762         __attribute__((unused)) void *data)
12763 {
12764         struct cmd_config_e_tag_result *res =
12765                 parsed_result;
12766         struct rte_eth_l2_tunnel_conf entry;
12767
12768         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12769                 return;
12770
12771         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12772         entry.vf_id = res->vf_id;
12773
12774         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12775                                           &entry,
12776                                           ETH_L2_TUNNEL_INSERTION_MASK,
12777                                           0);
12778 }
12779
12780 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12781         .f = cmd_config_e_tag_insertion_en_parsed,
12782         .data = NULL,
12783         .help_str = "E-tag ... : E-tag insertion enable",
12784         .tokens = {
12785                 (void *)&cmd_config_e_tag_e_tag,
12786                 (void *)&cmd_config_e_tag_set,
12787                 (void *)&cmd_config_e_tag_insertion,
12788                 (void *)&cmd_config_e_tag_on,
12789                 (void *)&cmd_config_e_tag_port_tag_id,
12790                 (void *)&cmd_config_e_tag_port_tag_id_val,
12791                 (void *)&cmd_config_e_tag_port,
12792                 (void *)&cmd_config_e_tag_port_id,
12793                 (void *)&cmd_config_e_tag_vf,
12794                 (void *)&cmd_config_e_tag_vf_id,
12795                 NULL,
12796         },
12797 };
12798
12799 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12800         .f = cmd_config_e_tag_insertion_dis_parsed,
12801         .data = NULL,
12802         .help_str = "E-tag ... : E-tag insertion disable",
12803         .tokens = {
12804                 (void *)&cmd_config_e_tag_e_tag,
12805                 (void *)&cmd_config_e_tag_set,
12806                 (void *)&cmd_config_e_tag_insertion,
12807                 (void *)&cmd_config_e_tag_off,
12808                 (void *)&cmd_config_e_tag_port,
12809                 (void *)&cmd_config_e_tag_port_id,
12810                 (void *)&cmd_config_e_tag_vf,
12811                 (void *)&cmd_config_e_tag_vf_id,
12812                 NULL,
12813         },
12814 };
12815
12816 /* E-tag stripping configuration */
12817 static void
12818 cmd_config_e_tag_stripping_parsed(
12819         void *parsed_result,
12820         __attribute__((unused)) struct cmdline *cl,
12821         __attribute__((unused)) void *data)
12822 {
12823         struct cmd_config_e_tag_result *res =
12824                 parsed_result;
12825         struct rte_eth_l2_tunnel_conf entry;
12826
12827         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12828                 return;
12829
12830         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12831
12832         if (!strcmp(res->on_off, "on"))
12833                 rte_eth_dev_l2_tunnel_offload_set
12834                         (res->port_id,
12835                          &entry,
12836                          ETH_L2_TUNNEL_STRIPPING_MASK,
12837                          1);
12838         else
12839                 rte_eth_dev_l2_tunnel_offload_set
12840                         (res->port_id,
12841                          &entry,
12842                          ETH_L2_TUNNEL_STRIPPING_MASK,
12843                          0);
12844 }
12845
12846 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12847         .f = cmd_config_e_tag_stripping_parsed,
12848         .data = NULL,
12849         .help_str = "E-tag ... : E-tag stripping enable/disable",
12850         .tokens = {
12851                 (void *)&cmd_config_e_tag_e_tag,
12852                 (void *)&cmd_config_e_tag_set,
12853                 (void *)&cmd_config_e_tag_stripping,
12854                 (void *)&cmd_config_e_tag_on_off,
12855                 (void *)&cmd_config_e_tag_port,
12856                 (void *)&cmd_config_e_tag_port_id,
12857                 NULL,
12858         },
12859 };
12860
12861 /* E-tag forwarding configuration */
12862 static void
12863 cmd_config_e_tag_forwarding_parsed(
12864         void *parsed_result,
12865         __attribute__((unused)) struct cmdline *cl,
12866         __attribute__((unused)) void *data)
12867 {
12868         struct cmd_config_e_tag_result *res = parsed_result;
12869         struct rte_eth_l2_tunnel_conf entry;
12870
12871         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12872                 return;
12873
12874         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12875
12876         if (!strcmp(res->on_off, "on"))
12877                 rte_eth_dev_l2_tunnel_offload_set
12878                         (res->port_id,
12879                          &entry,
12880                          ETH_L2_TUNNEL_FORWARDING_MASK,
12881                          1);
12882         else
12883                 rte_eth_dev_l2_tunnel_offload_set
12884                         (res->port_id,
12885                          &entry,
12886                          ETH_L2_TUNNEL_FORWARDING_MASK,
12887                          0);
12888 }
12889
12890 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12891         .f = cmd_config_e_tag_forwarding_parsed,
12892         .data = NULL,
12893         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12894         .tokens = {
12895                 (void *)&cmd_config_e_tag_e_tag,
12896                 (void *)&cmd_config_e_tag_set,
12897                 (void *)&cmd_config_e_tag_forwarding,
12898                 (void *)&cmd_config_e_tag_on_off,
12899                 (void *)&cmd_config_e_tag_port,
12900                 (void *)&cmd_config_e_tag_port_id,
12901                 NULL,
12902         },
12903 };
12904
12905 /* E-tag filter configuration */
12906 static void
12907 cmd_config_e_tag_filter_add_parsed(
12908         void *parsed_result,
12909         __attribute__((unused)) struct cmdline *cl,
12910         __attribute__((unused)) void *data)
12911 {
12912         struct cmd_config_e_tag_result *res = parsed_result;
12913         struct rte_eth_l2_tunnel_conf entry;
12914         int ret = 0;
12915
12916         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12917                 return;
12918
12919         if (res->e_tag_id_val > 0x3fff) {
12920                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12921                 return;
12922         }
12923
12924         ret = rte_eth_dev_filter_supported(res->port_id,
12925                                            RTE_ETH_FILTER_L2_TUNNEL);
12926         if (ret < 0) {
12927                 printf("E-tag filter is not supported on port %u.\n",
12928                        res->port_id);
12929                 return;
12930         }
12931
12932         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12933         entry.tunnel_id = res->e_tag_id_val;
12934         entry.pool = res->dst_pool_val;
12935
12936         ret = rte_eth_dev_filter_ctrl(res->port_id,
12937                                       RTE_ETH_FILTER_L2_TUNNEL,
12938                                       RTE_ETH_FILTER_ADD,
12939                                       &entry);
12940         if (ret < 0)
12941                 printf("E-tag filter programming error: (%s)\n",
12942                        strerror(-ret));
12943 }
12944
12945 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12946         .f = cmd_config_e_tag_filter_add_parsed,
12947         .data = NULL,
12948         .help_str = "E-tag ... : E-tag filter add",
12949         .tokens = {
12950                 (void *)&cmd_config_e_tag_e_tag,
12951                 (void *)&cmd_config_e_tag_set,
12952                 (void *)&cmd_config_e_tag_filter,
12953                 (void *)&cmd_config_e_tag_add,
12954                 (void *)&cmd_config_e_tag_e_tag_id,
12955                 (void *)&cmd_config_e_tag_e_tag_id_val,
12956                 (void *)&cmd_config_e_tag_dst_pool,
12957                 (void *)&cmd_config_e_tag_dst_pool_val,
12958                 (void *)&cmd_config_e_tag_port,
12959                 (void *)&cmd_config_e_tag_port_id,
12960                 NULL,
12961         },
12962 };
12963
12964 static void
12965 cmd_config_e_tag_filter_del_parsed(
12966         void *parsed_result,
12967         __attribute__((unused)) struct cmdline *cl,
12968         __attribute__((unused)) void *data)
12969 {
12970         struct cmd_config_e_tag_result *res = parsed_result;
12971         struct rte_eth_l2_tunnel_conf entry;
12972         int ret = 0;
12973
12974         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12975                 return;
12976
12977         if (res->e_tag_id_val > 0x3fff) {
12978                 printf("e-tag-id must be less than 0x3fff.\n");
12979                 return;
12980         }
12981
12982         ret = rte_eth_dev_filter_supported(res->port_id,
12983                                            RTE_ETH_FILTER_L2_TUNNEL);
12984         if (ret < 0) {
12985                 printf("E-tag filter is not supported on port %u.\n",
12986                        res->port_id);
12987                 return;
12988         }
12989
12990         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12991         entry.tunnel_id = res->e_tag_id_val;
12992
12993         ret = rte_eth_dev_filter_ctrl(res->port_id,
12994                                       RTE_ETH_FILTER_L2_TUNNEL,
12995                                       RTE_ETH_FILTER_DELETE,
12996                                       &entry);
12997         if (ret < 0)
12998                 printf("E-tag filter programming error: (%s)\n",
12999                        strerror(-ret));
13000 }
13001
13002 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13003         .f = cmd_config_e_tag_filter_del_parsed,
13004         .data = NULL,
13005         .help_str = "E-tag ... : E-tag filter delete",
13006         .tokens = {
13007                 (void *)&cmd_config_e_tag_e_tag,
13008                 (void *)&cmd_config_e_tag_set,
13009                 (void *)&cmd_config_e_tag_filter,
13010                 (void *)&cmd_config_e_tag_del,
13011                 (void *)&cmd_config_e_tag_e_tag_id,
13012                 (void *)&cmd_config_e_tag_e_tag_id_val,
13013                 (void *)&cmd_config_e_tag_port,
13014                 (void *)&cmd_config_e_tag_port_id,
13015                 NULL,
13016         },
13017 };
13018
13019 /* vf vlan anti spoof configuration */
13020
13021 /* Common result structure for vf vlan anti spoof */
13022 struct cmd_vf_vlan_anti_spoof_result {
13023         cmdline_fixed_string_t set;
13024         cmdline_fixed_string_t vf;
13025         cmdline_fixed_string_t vlan;
13026         cmdline_fixed_string_t antispoof;
13027         portid_t port_id;
13028         uint32_t vf_id;
13029         cmdline_fixed_string_t on_off;
13030 };
13031
13032 /* Common CLI fields for vf vlan anti spoof enable disable */
13033 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13034         TOKEN_STRING_INITIALIZER
13035                 (struct cmd_vf_vlan_anti_spoof_result,
13036                  set, "set");
13037 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13038         TOKEN_STRING_INITIALIZER
13039                 (struct cmd_vf_vlan_anti_spoof_result,
13040                  vf, "vf");
13041 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13042         TOKEN_STRING_INITIALIZER
13043                 (struct cmd_vf_vlan_anti_spoof_result,
13044                  vlan, "vlan");
13045 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13046         TOKEN_STRING_INITIALIZER
13047                 (struct cmd_vf_vlan_anti_spoof_result,
13048                  antispoof, "antispoof");
13049 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13050         TOKEN_NUM_INITIALIZER
13051                 (struct cmd_vf_vlan_anti_spoof_result,
13052                  port_id, UINT16);
13053 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13054         TOKEN_NUM_INITIALIZER
13055                 (struct cmd_vf_vlan_anti_spoof_result,
13056                  vf_id, UINT32);
13057 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13058         TOKEN_STRING_INITIALIZER
13059                 (struct cmd_vf_vlan_anti_spoof_result,
13060                  on_off, "on#off");
13061
13062 static void
13063 cmd_set_vf_vlan_anti_spoof_parsed(
13064         void *parsed_result,
13065         __attribute__((unused)) struct cmdline *cl,
13066         __attribute__((unused)) void *data)
13067 {
13068         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13069         int ret = -ENOTSUP;
13070
13071         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13072
13073         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13074                 return;
13075
13076 #ifdef RTE_LIBRTE_IXGBE_PMD
13077         if (ret == -ENOTSUP)
13078                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13079                                 res->vf_id, is_on);
13080 #endif
13081 #ifdef RTE_LIBRTE_I40E_PMD
13082         if (ret == -ENOTSUP)
13083                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13084                                 res->vf_id, is_on);
13085 #endif
13086 #ifdef RTE_LIBRTE_BNXT_PMD
13087         if (ret == -ENOTSUP)
13088                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13089                                 res->vf_id, is_on);
13090 #endif
13091
13092         switch (ret) {
13093         case 0:
13094                 break;
13095         case -EINVAL:
13096                 printf("invalid vf_id %d\n", res->vf_id);
13097                 break;
13098         case -ENODEV:
13099                 printf("invalid port_id %d\n", res->port_id);
13100                 break;
13101         case -ENOTSUP:
13102                 printf("function not implemented\n");
13103                 break;
13104         default:
13105                 printf("programming error: (%s)\n", strerror(-ret));
13106         }
13107 }
13108
13109 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13110         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13111         .data = NULL,
13112         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13113         .tokens = {
13114                 (void *)&cmd_vf_vlan_anti_spoof_set,
13115                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13116                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13117                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13118                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13119                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13120                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13121                 NULL,
13122         },
13123 };
13124
13125 /* vf mac anti spoof configuration */
13126
13127 /* Common result structure for vf mac anti spoof */
13128 struct cmd_vf_mac_anti_spoof_result {
13129         cmdline_fixed_string_t set;
13130         cmdline_fixed_string_t vf;
13131         cmdline_fixed_string_t mac;
13132         cmdline_fixed_string_t antispoof;
13133         portid_t port_id;
13134         uint32_t vf_id;
13135         cmdline_fixed_string_t on_off;
13136 };
13137
13138 /* Common CLI fields for vf mac anti spoof enable disable */
13139 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13140         TOKEN_STRING_INITIALIZER
13141                 (struct cmd_vf_mac_anti_spoof_result,
13142                  set, "set");
13143 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13144         TOKEN_STRING_INITIALIZER
13145                 (struct cmd_vf_mac_anti_spoof_result,
13146                  vf, "vf");
13147 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13148         TOKEN_STRING_INITIALIZER
13149                 (struct cmd_vf_mac_anti_spoof_result,
13150                  mac, "mac");
13151 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13152         TOKEN_STRING_INITIALIZER
13153                 (struct cmd_vf_mac_anti_spoof_result,
13154                  antispoof, "antispoof");
13155 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13156         TOKEN_NUM_INITIALIZER
13157                 (struct cmd_vf_mac_anti_spoof_result,
13158                  port_id, UINT16);
13159 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13160         TOKEN_NUM_INITIALIZER
13161                 (struct cmd_vf_mac_anti_spoof_result,
13162                  vf_id, UINT32);
13163 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13164         TOKEN_STRING_INITIALIZER
13165                 (struct cmd_vf_mac_anti_spoof_result,
13166                  on_off, "on#off");
13167
13168 static void
13169 cmd_set_vf_mac_anti_spoof_parsed(
13170         void *parsed_result,
13171         __attribute__((unused)) struct cmdline *cl,
13172         __attribute__((unused)) void *data)
13173 {
13174         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13175         int ret = -ENOTSUP;
13176
13177         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13178
13179         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13180                 return;
13181
13182 #ifdef RTE_LIBRTE_IXGBE_PMD
13183         if (ret == -ENOTSUP)
13184                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13185                         res->vf_id, is_on);
13186 #endif
13187 #ifdef RTE_LIBRTE_I40E_PMD
13188         if (ret == -ENOTSUP)
13189                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13190                         res->vf_id, is_on);
13191 #endif
13192 #ifdef RTE_LIBRTE_BNXT_PMD
13193         if (ret == -ENOTSUP)
13194                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13195                         res->vf_id, is_on);
13196 #endif
13197
13198         switch (ret) {
13199         case 0:
13200                 break;
13201         case -EINVAL:
13202                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13203                 break;
13204         case -ENODEV:
13205                 printf("invalid port_id %d\n", res->port_id);
13206                 break;
13207         case -ENOTSUP:
13208                 printf("function not implemented\n");
13209                 break;
13210         default:
13211                 printf("programming error: (%s)\n", strerror(-ret));
13212         }
13213 }
13214
13215 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13216         .f = cmd_set_vf_mac_anti_spoof_parsed,
13217         .data = NULL,
13218         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13219         .tokens = {
13220                 (void *)&cmd_vf_mac_anti_spoof_set,
13221                 (void *)&cmd_vf_mac_anti_spoof_vf,
13222                 (void *)&cmd_vf_mac_anti_spoof_mac,
13223                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13224                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13225                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13226                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13227                 NULL,
13228         },
13229 };
13230
13231 /* vf vlan strip queue configuration */
13232
13233 /* Common result structure for vf mac anti spoof */
13234 struct cmd_vf_vlan_stripq_result {
13235         cmdline_fixed_string_t set;
13236         cmdline_fixed_string_t vf;
13237         cmdline_fixed_string_t vlan;
13238         cmdline_fixed_string_t stripq;
13239         portid_t port_id;
13240         uint16_t vf_id;
13241         cmdline_fixed_string_t on_off;
13242 };
13243
13244 /* Common CLI fields for vf vlan strip enable disable */
13245 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13246         TOKEN_STRING_INITIALIZER
13247                 (struct cmd_vf_vlan_stripq_result,
13248                  set, "set");
13249 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13250         TOKEN_STRING_INITIALIZER
13251                 (struct cmd_vf_vlan_stripq_result,
13252                  vf, "vf");
13253 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13254         TOKEN_STRING_INITIALIZER
13255                 (struct cmd_vf_vlan_stripq_result,
13256                  vlan, "vlan");
13257 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13258         TOKEN_STRING_INITIALIZER
13259                 (struct cmd_vf_vlan_stripq_result,
13260                  stripq, "stripq");
13261 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13262         TOKEN_NUM_INITIALIZER
13263                 (struct cmd_vf_vlan_stripq_result,
13264                  port_id, UINT16);
13265 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13266         TOKEN_NUM_INITIALIZER
13267                 (struct cmd_vf_vlan_stripq_result,
13268                  vf_id, UINT16);
13269 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13270         TOKEN_STRING_INITIALIZER
13271                 (struct cmd_vf_vlan_stripq_result,
13272                  on_off, "on#off");
13273
13274 static void
13275 cmd_set_vf_vlan_stripq_parsed(
13276         void *parsed_result,
13277         __attribute__((unused)) struct cmdline *cl,
13278         __attribute__((unused)) void *data)
13279 {
13280         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13281         int ret = -ENOTSUP;
13282
13283         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13284
13285         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13286                 return;
13287
13288 #ifdef RTE_LIBRTE_IXGBE_PMD
13289         if (ret == -ENOTSUP)
13290                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13291                         res->vf_id, is_on);
13292 #endif
13293 #ifdef RTE_LIBRTE_I40E_PMD
13294         if (ret == -ENOTSUP)
13295                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13296                         res->vf_id, is_on);
13297 #endif
13298 #ifdef RTE_LIBRTE_BNXT_PMD
13299         if (ret == -ENOTSUP)
13300                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13301                         res->vf_id, is_on);
13302 #endif
13303
13304         switch (ret) {
13305         case 0:
13306                 break;
13307         case -EINVAL:
13308                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13309                 break;
13310         case -ENODEV:
13311                 printf("invalid port_id %d\n", res->port_id);
13312                 break;
13313         case -ENOTSUP:
13314                 printf("function not implemented\n");
13315                 break;
13316         default:
13317                 printf("programming error: (%s)\n", strerror(-ret));
13318         }
13319 }
13320
13321 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13322         .f = cmd_set_vf_vlan_stripq_parsed,
13323         .data = NULL,
13324         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13325         .tokens = {
13326                 (void *)&cmd_vf_vlan_stripq_set,
13327                 (void *)&cmd_vf_vlan_stripq_vf,
13328                 (void *)&cmd_vf_vlan_stripq_vlan,
13329                 (void *)&cmd_vf_vlan_stripq_stripq,
13330                 (void *)&cmd_vf_vlan_stripq_port_id,
13331                 (void *)&cmd_vf_vlan_stripq_vf_id,
13332                 (void *)&cmd_vf_vlan_stripq_on_off,
13333                 NULL,
13334         },
13335 };
13336
13337 /* vf vlan insert configuration */
13338
13339 /* Common result structure for vf vlan insert */
13340 struct cmd_vf_vlan_insert_result {
13341         cmdline_fixed_string_t set;
13342         cmdline_fixed_string_t vf;
13343         cmdline_fixed_string_t vlan;
13344         cmdline_fixed_string_t insert;
13345         portid_t port_id;
13346         uint16_t vf_id;
13347         uint16_t vlan_id;
13348 };
13349
13350 /* Common CLI fields for vf vlan insert enable disable */
13351 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13352         TOKEN_STRING_INITIALIZER
13353                 (struct cmd_vf_vlan_insert_result,
13354                  set, "set");
13355 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13356         TOKEN_STRING_INITIALIZER
13357                 (struct cmd_vf_vlan_insert_result,
13358                  vf, "vf");
13359 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13360         TOKEN_STRING_INITIALIZER
13361                 (struct cmd_vf_vlan_insert_result,
13362                  vlan, "vlan");
13363 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13364         TOKEN_STRING_INITIALIZER
13365                 (struct cmd_vf_vlan_insert_result,
13366                  insert, "insert");
13367 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13368         TOKEN_NUM_INITIALIZER
13369                 (struct cmd_vf_vlan_insert_result,
13370                  port_id, UINT16);
13371 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13372         TOKEN_NUM_INITIALIZER
13373                 (struct cmd_vf_vlan_insert_result,
13374                  vf_id, UINT16);
13375 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13376         TOKEN_NUM_INITIALIZER
13377                 (struct cmd_vf_vlan_insert_result,
13378                  vlan_id, UINT16);
13379
13380 static void
13381 cmd_set_vf_vlan_insert_parsed(
13382         void *parsed_result,
13383         __attribute__((unused)) struct cmdline *cl,
13384         __attribute__((unused)) void *data)
13385 {
13386         struct cmd_vf_vlan_insert_result *res = parsed_result;
13387         int ret = -ENOTSUP;
13388
13389         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13390                 return;
13391
13392 #ifdef RTE_LIBRTE_IXGBE_PMD
13393         if (ret == -ENOTSUP)
13394                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13395                         res->vlan_id);
13396 #endif
13397 #ifdef RTE_LIBRTE_I40E_PMD
13398         if (ret == -ENOTSUP)
13399                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13400                         res->vlan_id);
13401 #endif
13402 #ifdef RTE_LIBRTE_BNXT_PMD
13403         if (ret == -ENOTSUP)
13404                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13405                         res->vlan_id);
13406 #endif
13407
13408         switch (ret) {
13409         case 0:
13410                 break;
13411         case -EINVAL:
13412                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13413                 break;
13414         case -ENODEV:
13415                 printf("invalid port_id %d\n", res->port_id);
13416                 break;
13417         case -ENOTSUP:
13418                 printf("function not implemented\n");
13419                 break;
13420         default:
13421                 printf("programming error: (%s)\n", strerror(-ret));
13422         }
13423 }
13424
13425 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13426         .f = cmd_set_vf_vlan_insert_parsed,
13427         .data = NULL,
13428         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13429         .tokens = {
13430                 (void *)&cmd_vf_vlan_insert_set,
13431                 (void *)&cmd_vf_vlan_insert_vf,
13432                 (void *)&cmd_vf_vlan_insert_vlan,
13433                 (void *)&cmd_vf_vlan_insert_insert,
13434                 (void *)&cmd_vf_vlan_insert_port_id,
13435                 (void *)&cmd_vf_vlan_insert_vf_id,
13436                 (void *)&cmd_vf_vlan_insert_vlan_id,
13437                 NULL,
13438         },
13439 };
13440
13441 /* tx loopback configuration */
13442
13443 /* Common result structure for tx loopback */
13444 struct cmd_tx_loopback_result {
13445         cmdline_fixed_string_t set;
13446         cmdline_fixed_string_t tx;
13447         cmdline_fixed_string_t loopback;
13448         portid_t port_id;
13449         cmdline_fixed_string_t on_off;
13450 };
13451
13452 /* Common CLI fields for tx loopback enable disable */
13453 cmdline_parse_token_string_t cmd_tx_loopback_set =
13454         TOKEN_STRING_INITIALIZER
13455                 (struct cmd_tx_loopback_result,
13456                  set, "set");
13457 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13458         TOKEN_STRING_INITIALIZER
13459                 (struct cmd_tx_loopback_result,
13460                  tx, "tx");
13461 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13462         TOKEN_STRING_INITIALIZER
13463                 (struct cmd_tx_loopback_result,
13464                  loopback, "loopback");
13465 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13466         TOKEN_NUM_INITIALIZER
13467                 (struct cmd_tx_loopback_result,
13468                  port_id, UINT16);
13469 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13470         TOKEN_STRING_INITIALIZER
13471                 (struct cmd_tx_loopback_result,
13472                  on_off, "on#off");
13473
13474 static void
13475 cmd_set_tx_loopback_parsed(
13476         void *parsed_result,
13477         __attribute__((unused)) struct cmdline *cl,
13478         __attribute__((unused)) void *data)
13479 {
13480         struct cmd_tx_loopback_result *res = parsed_result;
13481         int ret = -ENOTSUP;
13482
13483         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13484
13485         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13486                 return;
13487
13488 #ifdef RTE_LIBRTE_IXGBE_PMD
13489         if (ret == -ENOTSUP)
13490                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13491 #endif
13492 #ifdef RTE_LIBRTE_I40E_PMD
13493         if (ret == -ENOTSUP)
13494                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13495 #endif
13496 #ifdef RTE_LIBRTE_BNXT_PMD
13497         if (ret == -ENOTSUP)
13498                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13499 #endif
13500 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13501         if (ret == -ENOTSUP)
13502                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13503 #endif
13504
13505         switch (ret) {
13506         case 0:
13507                 break;
13508         case -EINVAL:
13509                 printf("invalid is_on %d\n", is_on);
13510                 break;
13511         case -ENODEV:
13512                 printf("invalid port_id %d\n", res->port_id);
13513                 break;
13514         case -ENOTSUP:
13515                 printf("function not implemented\n");
13516                 break;
13517         default:
13518                 printf("programming error: (%s)\n", strerror(-ret));
13519         }
13520 }
13521
13522 cmdline_parse_inst_t cmd_set_tx_loopback = {
13523         .f = cmd_set_tx_loopback_parsed,
13524         .data = NULL,
13525         .help_str = "set tx loopback <port_id> on|off",
13526         .tokens = {
13527                 (void *)&cmd_tx_loopback_set,
13528                 (void *)&cmd_tx_loopback_tx,
13529                 (void *)&cmd_tx_loopback_loopback,
13530                 (void *)&cmd_tx_loopback_port_id,
13531                 (void *)&cmd_tx_loopback_on_off,
13532                 NULL,
13533         },
13534 };
13535
13536 /* all queues drop enable configuration */
13537
13538 /* Common result structure for all queues drop enable */
13539 struct cmd_all_queues_drop_en_result {
13540         cmdline_fixed_string_t set;
13541         cmdline_fixed_string_t all;
13542         cmdline_fixed_string_t queues;
13543         cmdline_fixed_string_t drop;
13544         portid_t port_id;
13545         cmdline_fixed_string_t on_off;
13546 };
13547
13548 /* Common CLI fields for tx loopback enable disable */
13549 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13550         TOKEN_STRING_INITIALIZER
13551                 (struct cmd_all_queues_drop_en_result,
13552                  set, "set");
13553 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13554         TOKEN_STRING_INITIALIZER
13555                 (struct cmd_all_queues_drop_en_result,
13556                  all, "all");
13557 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13558         TOKEN_STRING_INITIALIZER
13559                 (struct cmd_all_queues_drop_en_result,
13560                  queues, "queues");
13561 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13562         TOKEN_STRING_INITIALIZER
13563                 (struct cmd_all_queues_drop_en_result,
13564                  drop, "drop");
13565 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13566         TOKEN_NUM_INITIALIZER
13567                 (struct cmd_all_queues_drop_en_result,
13568                  port_id, UINT16);
13569 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13570         TOKEN_STRING_INITIALIZER
13571                 (struct cmd_all_queues_drop_en_result,
13572                  on_off, "on#off");
13573
13574 static void
13575 cmd_set_all_queues_drop_en_parsed(
13576         void *parsed_result,
13577         __attribute__((unused)) struct cmdline *cl,
13578         __attribute__((unused)) void *data)
13579 {
13580         struct cmd_all_queues_drop_en_result *res = parsed_result;
13581         int ret = -ENOTSUP;
13582         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13583
13584         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13585                 return;
13586
13587 #ifdef RTE_LIBRTE_IXGBE_PMD
13588         if (ret == -ENOTSUP)
13589                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13590 #endif
13591 #ifdef RTE_LIBRTE_BNXT_PMD
13592         if (ret == -ENOTSUP)
13593                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13594 #endif
13595         switch (ret) {
13596         case 0:
13597                 break;
13598         case -EINVAL:
13599                 printf("invalid is_on %d\n", is_on);
13600                 break;
13601         case -ENODEV:
13602                 printf("invalid port_id %d\n", res->port_id);
13603                 break;
13604         case -ENOTSUP:
13605                 printf("function not implemented\n");
13606                 break;
13607         default:
13608                 printf("programming error: (%s)\n", strerror(-ret));
13609         }
13610 }
13611
13612 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13613         .f = cmd_set_all_queues_drop_en_parsed,
13614         .data = NULL,
13615         .help_str = "set all queues drop <port_id> on|off",
13616         .tokens = {
13617                 (void *)&cmd_all_queues_drop_en_set,
13618                 (void *)&cmd_all_queues_drop_en_all,
13619                 (void *)&cmd_all_queues_drop_en_queues,
13620                 (void *)&cmd_all_queues_drop_en_drop,
13621                 (void *)&cmd_all_queues_drop_en_port_id,
13622                 (void *)&cmd_all_queues_drop_en_on_off,
13623                 NULL,
13624         },
13625 };
13626
13627 /* vf split drop enable configuration */
13628
13629 /* Common result structure for vf split drop enable */
13630 struct cmd_vf_split_drop_en_result {
13631         cmdline_fixed_string_t set;
13632         cmdline_fixed_string_t vf;
13633         cmdline_fixed_string_t split;
13634         cmdline_fixed_string_t drop;
13635         portid_t port_id;
13636         uint16_t vf_id;
13637         cmdline_fixed_string_t on_off;
13638 };
13639
13640 /* Common CLI fields for vf split drop enable disable */
13641 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13642         TOKEN_STRING_INITIALIZER
13643                 (struct cmd_vf_split_drop_en_result,
13644                  set, "set");
13645 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13646         TOKEN_STRING_INITIALIZER
13647                 (struct cmd_vf_split_drop_en_result,
13648                  vf, "vf");
13649 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13650         TOKEN_STRING_INITIALIZER
13651                 (struct cmd_vf_split_drop_en_result,
13652                  split, "split");
13653 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13654         TOKEN_STRING_INITIALIZER
13655                 (struct cmd_vf_split_drop_en_result,
13656                  drop, "drop");
13657 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13658         TOKEN_NUM_INITIALIZER
13659                 (struct cmd_vf_split_drop_en_result,
13660                  port_id, UINT16);
13661 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13662         TOKEN_NUM_INITIALIZER
13663                 (struct cmd_vf_split_drop_en_result,
13664                  vf_id, UINT16);
13665 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13666         TOKEN_STRING_INITIALIZER
13667                 (struct cmd_vf_split_drop_en_result,
13668                  on_off, "on#off");
13669
13670 static void
13671 cmd_set_vf_split_drop_en_parsed(
13672         void *parsed_result,
13673         __attribute__((unused)) struct cmdline *cl,
13674         __attribute__((unused)) void *data)
13675 {
13676         struct cmd_vf_split_drop_en_result *res = parsed_result;
13677         int ret = -ENOTSUP;
13678         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13679
13680         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13681                 return;
13682
13683 #ifdef RTE_LIBRTE_IXGBE_PMD
13684         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13685                         is_on);
13686 #endif
13687         switch (ret) {
13688         case 0:
13689                 break;
13690         case -EINVAL:
13691                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13692                 break;
13693         case -ENODEV:
13694                 printf("invalid port_id %d\n", res->port_id);
13695                 break;
13696         case -ENOTSUP:
13697                 printf("not supported on port %d\n", res->port_id);
13698                 break;
13699         default:
13700                 printf("programming error: (%s)\n", strerror(-ret));
13701         }
13702 }
13703
13704 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13705         .f = cmd_set_vf_split_drop_en_parsed,
13706         .data = NULL,
13707         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13708         .tokens = {
13709                 (void *)&cmd_vf_split_drop_en_set,
13710                 (void *)&cmd_vf_split_drop_en_vf,
13711                 (void *)&cmd_vf_split_drop_en_split,
13712                 (void *)&cmd_vf_split_drop_en_drop,
13713                 (void *)&cmd_vf_split_drop_en_port_id,
13714                 (void *)&cmd_vf_split_drop_en_vf_id,
13715                 (void *)&cmd_vf_split_drop_en_on_off,
13716                 NULL,
13717         },
13718 };
13719
13720 /* vf mac address configuration */
13721
13722 /* Common result structure for vf mac address */
13723 struct cmd_set_vf_mac_addr_result {
13724         cmdline_fixed_string_t set;
13725         cmdline_fixed_string_t vf;
13726         cmdline_fixed_string_t mac;
13727         cmdline_fixed_string_t addr;
13728         portid_t port_id;
13729         uint16_t vf_id;
13730         struct ether_addr mac_addr;
13731
13732 };
13733
13734 /* Common CLI fields for vf split drop enable disable */
13735 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13736         TOKEN_STRING_INITIALIZER
13737                 (struct cmd_set_vf_mac_addr_result,
13738                  set, "set");
13739 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13740         TOKEN_STRING_INITIALIZER
13741                 (struct cmd_set_vf_mac_addr_result,
13742                  vf, "vf");
13743 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13744         TOKEN_STRING_INITIALIZER
13745                 (struct cmd_set_vf_mac_addr_result,
13746                  mac, "mac");
13747 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13748         TOKEN_STRING_INITIALIZER
13749                 (struct cmd_set_vf_mac_addr_result,
13750                  addr, "addr");
13751 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13752         TOKEN_NUM_INITIALIZER
13753                 (struct cmd_set_vf_mac_addr_result,
13754                  port_id, UINT16);
13755 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13756         TOKEN_NUM_INITIALIZER
13757                 (struct cmd_set_vf_mac_addr_result,
13758                  vf_id, UINT16);
13759 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13760         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13761                  mac_addr);
13762
13763 static void
13764 cmd_set_vf_mac_addr_parsed(
13765         void *parsed_result,
13766         __attribute__((unused)) struct cmdline *cl,
13767         __attribute__((unused)) void *data)
13768 {
13769         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13770         int ret = -ENOTSUP;
13771
13772         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13773                 return;
13774
13775 #ifdef RTE_LIBRTE_IXGBE_PMD
13776         if (ret == -ENOTSUP)
13777                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13778                                 &res->mac_addr);
13779 #endif
13780 #ifdef RTE_LIBRTE_I40E_PMD
13781         if (ret == -ENOTSUP)
13782                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13783                                 &res->mac_addr);
13784 #endif
13785 #ifdef RTE_LIBRTE_BNXT_PMD
13786         if (ret == -ENOTSUP)
13787                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13788                                 &res->mac_addr);
13789 #endif
13790
13791         switch (ret) {
13792         case 0:
13793                 break;
13794         case -EINVAL:
13795                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13796                 break;
13797         case -ENODEV:
13798                 printf("invalid port_id %d\n", res->port_id);
13799                 break;
13800         case -ENOTSUP:
13801                 printf("function not implemented\n");
13802                 break;
13803         default:
13804                 printf("programming error: (%s)\n", strerror(-ret));
13805         }
13806 }
13807
13808 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13809         .f = cmd_set_vf_mac_addr_parsed,
13810         .data = NULL,
13811         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13812         .tokens = {
13813                 (void *)&cmd_set_vf_mac_addr_set,
13814                 (void *)&cmd_set_vf_mac_addr_vf,
13815                 (void *)&cmd_set_vf_mac_addr_mac,
13816                 (void *)&cmd_set_vf_mac_addr_addr,
13817                 (void *)&cmd_set_vf_mac_addr_port_id,
13818                 (void *)&cmd_set_vf_mac_addr_vf_id,
13819                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13820                 NULL,
13821         },
13822 };
13823
13824 /* MACsec configuration */
13825
13826 /* Common result structure for MACsec offload enable */
13827 struct cmd_macsec_offload_on_result {
13828         cmdline_fixed_string_t set;
13829         cmdline_fixed_string_t macsec;
13830         cmdline_fixed_string_t offload;
13831         portid_t port_id;
13832         cmdline_fixed_string_t on;
13833         cmdline_fixed_string_t encrypt;
13834         cmdline_fixed_string_t en_on_off;
13835         cmdline_fixed_string_t replay_protect;
13836         cmdline_fixed_string_t rp_on_off;
13837 };
13838
13839 /* Common CLI fields for MACsec offload disable */
13840 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13841         TOKEN_STRING_INITIALIZER
13842                 (struct cmd_macsec_offload_on_result,
13843                  set, "set");
13844 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13845         TOKEN_STRING_INITIALIZER
13846                 (struct cmd_macsec_offload_on_result,
13847                  macsec, "macsec");
13848 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13849         TOKEN_STRING_INITIALIZER
13850                 (struct cmd_macsec_offload_on_result,
13851                  offload, "offload");
13852 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13853         TOKEN_NUM_INITIALIZER
13854                 (struct cmd_macsec_offload_on_result,
13855                  port_id, UINT16);
13856 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13857         TOKEN_STRING_INITIALIZER
13858                 (struct cmd_macsec_offload_on_result,
13859                  on, "on");
13860 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13861         TOKEN_STRING_INITIALIZER
13862                 (struct cmd_macsec_offload_on_result,
13863                  encrypt, "encrypt");
13864 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13865         TOKEN_STRING_INITIALIZER
13866                 (struct cmd_macsec_offload_on_result,
13867                  en_on_off, "on#off");
13868 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13869         TOKEN_STRING_INITIALIZER
13870                 (struct cmd_macsec_offload_on_result,
13871                  replay_protect, "replay-protect");
13872 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13873         TOKEN_STRING_INITIALIZER
13874                 (struct cmd_macsec_offload_on_result,
13875                  rp_on_off, "on#off");
13876
13877 static void
13878 cmd_set_macsec_offload_on_parsed(
13879         void *parsed_result,
13880         __attribute__((unused)) struct cmdline *cl,
13881         __attribute__((unused)) void *data)
13882 {
13883         struct cmd_macsec_offload_on_result *res = parsed_result;
13884         int ret = -ENOTSUP;
13885         portid_t port_id = res->port_id;
13886         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13887         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13888         struct rte_eth_dev_info dev_info;
13889
13890         if (port_id_is_invalid(port_id, ENABLED_WARN))
13891                 return;
13892         if (!port_is_stopped(port_id)) {
13893                 printf("Please stop port %d first\n", port_id);
13894                 return;
13895         }
13896
13897         rte_eth_dev_info_get(port_id, &dev_info);
13898         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13899 #ifdef RTE_LIBRTE_IXGBE_PMD
13900                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13901 #endif
13902         }
13903         RTE_SET_USED(en);
13904         RTE_SET_USED(rp);
13905
13906         switch (ret) {
13907         case 0:
13908                 ports[port_id].dev_conf.txmode.offloads |=
13909                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13910                 cmd_reconfig_device_queue(port_id, 1, 1);
13911                 break;
13912         case -ENODEV:
13913                 printf("invalid port_id %d\n", port_id);
13914                 break;
13915         case -ENOTSUP:
13916                 printf("not supported on port %d\n", port_id);
13917                 break;
13918         default:
13919                 printf("programming error: (%s)\n", strerror(-ret));
13920         }
13921 }
13922
13923 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13924         .f = cmd_set_macsec_offload_on_parsed,
13925         .data = NULL,
13926         .help_str = "set macsec offload <port_id> on "
13927                 "encrypt on|off replay-protect on|off",
13928         .tokens = {
13929                 (void *)&cmd_macsec_offload_on_set,
13930                 (void *)&cmd_macsec_offload_on_macsec,
13931                 (void *)&cmd_macsec_offload_on_offload,
13932                 (void *)&cmd_macsec_offload_on_port_id,
13933                 (void *)&cmd_macsec_offload_on_on,
13934                 (void *)&cmd_macsec_offload_on_encrypt,
13935                 (void *)&cmd_macsec_offload_on_en_on_off,
13936                 (void *)&cmd_macsec_offload_on_replay_protect,
13937                 (void *)&cmd_macsec_offload_on_rp_on_off,
13938                 NULL,
13939         },
13940 };
13941
13942 /* Common result structure for MACsec offload disable */
13943 struct cmd_macsec_offload_off_result {
13944         cmdline_fixed_string_t set;
13945         cmdline_fixed_string_t macsec;
13946         cmdline_fixed_string_t offload;
13947         portid_t port_id;
13948         cmdline_fixed_string_t off;
13949 };
13950
13951 /* Common CLI fields for MACsec offload disable */
13952 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13953         TOKEN_STRING_INITIALIZER
13954                 (struct cmd_macsec_offload_off_result,
13955                  set, "set");
13956 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13957         TOKEN_STRING_INITIALIZER
13958                 (struct cmd_macsec_offload_off_result,
13959                  macsec, "macsec");
13960 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13961         TOKEN_STRING_INITIALIZER
13962                 (struct cmd_macsec_offload_off_result,
13963                  offload, "offload");
13964 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13965         TOKEN_NUM_INITIALIZER
13966                 (struct cmd_macsec_offload_off_result,
13967                  port_id, UINT16);
13968 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13969         TOKEN_STRING_INITIALIZER
13970                 (struct cmd_macsec_offload_off_result,
13971                  off, "off");
13972
13973 static void
13974 cmd_set_macsec_offload_off_parsed(
13975         void *parsed_result,
13976         __attribute__((unused)) struct cmdline *cl,
13977         __attribute__((unused)) void *data)
13978 {
13979         struct cmd_macsec_offload_off_result *res = parsed_result;
13980         int ret = -ENOTSUP;
13981         struct rte_eth_dev_info dev_info;
13982         portid_t port_id = res->port_id;
13983
13984         if (port_id_is_invalid(port_id, ENABLED_WARN))
13985                 return;
13986         if (!port_is_stopped(port_id)) {
13987                 printf("Please stop port %d first\n", port_id);
13988                 return;
13989         }
13990
13991         rte_eth_dev_info_get(port_id, &dev_info);
13992         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13993 #ifdef RTE_LIBRTE_IXGBE_PMD
13994                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13995 #endif
13996         }
13997         switch (ret) {
13998         case 0:
13999                 ports[port_id].dev_conf.txmode.offloads &=
14000                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14001                 cmd_reconfig_device_queue(port_id, 1, 1);
14002                 break;
14003         case -ENODEV:
14004                 printf("invalid port_id %d\n", port_id);
14005                 break;
14006         case -ENOTSUP:
14007                 printf("not supported on port %d\n", port_id);
14008                 break;
14009         default:
14010                 printf("programming error: (%s)\n", strerror(-ret));
14011         }
14012 }
14013
14014 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14015         .f = cmd_set_macsec_offload_off_parsed,
14016         .data = NULL,
14017         .help_str = "set macsec offload <port_id> off",
14018         .tokens = {
14019                 (void *)&cmd_macsec_offload_off_set,
14020                 (void *)&cmd_macsec_offload_off_macsec,
14021                 (void *)&cmd_macsec_offload_off_offload,
14022                 (void *)&cmd_macsec_offload_off_port_id,
14023                 (void *)&cmd_macsec_offload_off_off,
14024                 NULL,
14025         },
14026 };
14027
14028 /* Common result structure for MACsec secure connection configure */
14029 struct cmd_macsec_sc_result {
14030         cmdline_fixed_string_t set;
14031         cmdline_fixed_string_t macsec;
14032         cmdline_fixed_string_t sc;
14033         cmdline_fixed_string_t tx_rx;
14034         portid_t port_id;
14035         struct ether_addr mac;
14036         uint16_t pi;
14037 };
14038
14039 /* Common CLI fields for MACsec secure connection configure */
14040 cmdline_parse_token_string_t cmd_macsec_sc_set =
14041         TOKEN_STRING_INITIALIZER
14042                 (struct cmd_macsec_sc_result,
14043                  set, "set");
14044 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14045         TOKEN_STRING_INITIALIZER
14046                 (struct cmd_macsec_sc_result,
14047                  macsec, "macsec");
14048 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14049         TOKEN_STRING_INITIALIZER
14050                 (struct cmd_macsec_sc_result,
14051                  sc, "sc");
14052 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14053         TOKEN_STRING_INITIALIZER
14054                 (struct cmd_macsec_sc_result,
14055                  tx_rx, "tx#rx");
14056 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14057         TOKEN_NUM_INITIALIZER
14058                 (struct cmd_macsec_sc_result,
14059                  port_id, UINT16);
14060 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14061         TOKEN_ETHERADDR_INITIALIZER
14062                 (struct cmd_macsec_sc_result,
14063                  mac);
14064 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14065         TOKEN_NUM_INITIALIZER
14066                 (struct cmd_macsec_sc_result,
14067                  pi, UINT16);
14068
14069 static void
14070 cmd_set_macsec_sc_parsed(
14071         void *parsed_result,
14072         __attribute__((unused)) struct cmdline *cl,
14073         __attribute__((unused)) void *data)
14074 {
14075         struct cmd_macsec_sc_result *res = parsed_result;
14076         int ret = -ENOTSUP;
14077         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14078
14079 #ifdef RTE_LIBRTE_IXGBE_PMD
14080         ret = is_tx ?
14081                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14082                                 res->mac.addr_bytes) :
14083                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14084                                 res->mac.addr_bytes, res->pi);
14085 #endif
14086         RTE_SET_USED(is_tx);
14087
14088         switch (ret) {
14089         case 0:
14090                 break;
14091         case -ENODEV:
14092                 printf("invalid port_id %d\n", res->port_id);
14093                 break;
14094         case -ENOTSUP:
14095                 printf("not supported on port %d\n", res->port_id);
14096                 break;
14097         default:
14098                 printf("programming error: (%s)\n", strerror(-ret));
14099         }
14100 }
14101
14102 cmdline_parse_inst_t cmd_set_macsec_sc = {
14103         .f = cmd_set_macsec_sc_parsed,
14104         .data = NULL,
14105         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14106         .tokens = {
14107                 (void *)&cmd_macsec_sc_set,
14108                 (void *)&cmd_macsec_sc_macsec,
14109                 (void *)&cmd_macsec_sc_sc,
14110                 (void *)&cmd_macsec_sc_tx_rx,
14111                 (void *)&cmd_macsec_sc_port_id,
14112                 (void *)&cmd_macsec_sc_mac,
14113                 (void *)&cmd_macsec_sc_pi,
14114                 NULL,
14115         },
14116 };
14117
14118 /* Common result structure for MACsec secure connection configure */
14119 struct cmd_macsec_sa_result {
14120         cmdline_fixed_string_t set;
14121         cmdline_fixed_string_t macsec;
14122         cmdline_fixed_string_t sa;
14123         cmdline_fixed_string_t tx_rx;
14124         portid_t port_id;
14125         uint8_t idx;
14126         uint8_t an;
14127         uint32_t pn;
14128         cmdline_fixed_string_t key;
14129 };
14130
14131 /* Common CLI fields for MACsec secure connection configure */
14132 cmdline_parse_token_string_t cmd_macsec_sa_set =
14133         TOKEN_STRING_INITIALIZER
14134                 (struct cmd_macsec_sa_result,
14135                  set, "set");
14136 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14137         TOKEN_STRING_INITIALIZER
14138                 (struct cmd_macsec_sa_result,
14139                  macsec, "macsec");
14140 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14141         TOKEN_STRING_INITIALIZER
14142                 (struct cmd_macsec_sa_result,
14143                  sa, "sa");
14144 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14145         TOKEN_STRING_INITIALIZER
14146                 (struct cmd_macsec_sa_result,
14147                  tx_rx, "tx#rx");
14148 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14149         TOKEN_NUM_INITIALIZER
14150                 (struct cmd_macsec_sa_result,
14151                  port_id, UINT16);
14152 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14153         TOKEN_NUM_INITIALIZER
14154                 (struct cmd_macsec_sa_result,
14155                  idx, UINT8);
14156 cmdline_parse_token_num_t cmd_macsec_sa_an =
14157         TOKEN_NUM_INITIALIZER
14158                 (struct cmd_macsec_sa_result,
14159                  an, UINT8);
14160 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14161         TOKEN_NUM_INITIALIZER
14162                 (struct cmd_macsec_sa_result,
14163                  pn, UINT32);
14164 cmdline_parse_token_string_t cmd_macsec_sa_key =
14165         TOKEN_STRING_INITIALIZER
14166                 (struct cmd_macsec_sa_result,
14167                  key, NULL);
14168
14169 static void
14170 cmd_set_macsec_sa_parsed(
14171         void *parsed_result,
14172         __attribute__((unused)) struct cmdline *cl,
14173         __attribute__((unused)) void *data)
14174 {
14175         struct cmd_macsec_sa_result *res = parsed_result;
14176         int ret = -ENOTSUP;
14177         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14178         uint8_t key[16] = { 0 };
14179         uint8_t xdgt0;
14180         uint8_t xdgt1;
14181         int key_len;
14182         int i;
14183
14184         key_len = strlen(res->key) / 2;
14185         if (key_len > 16)
14186                 key_len = 16;
14187
14188         for (i = 0; i < key_len; i++) {
14189                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14190                 if (xdgt0 == 0xFF)
14191                         return;
14192                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14193                 if (xdgt1 == 0xFF)
14194                         return;
14195                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14196         }
14197
14198 #ifdef RTE_LIBRTE_IXGBE_PMD
14199         ret = is_tx ?
14200                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14201                         res->idx, res->an, res->pn, key) :
14202                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14203                         res->idx, res->an, res->pn, key);
14204 #endif
14205         RTE_SET_USED(is_tx);
14206         RTE_SET_USED(key);
14207
14208         switch (ret) {
14209         case 0:
14210                 break;
14211         case -EINVAL:
14212                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14213                 break;
14214         case -ENODEV:
14215                 printf("invalid port_id %d\n", res->port_id);
14216                 break;
14217         case -ENOTSUP:
14218                 printf("not supported on port %d\n", res->port_id);
14219                 break;
14220         default:
14221                 printf("programming error: (%s)\n", strerror(-ret));
14222         }
14223 }
14224
14225 cmdline_parse_inst_t cmd_set_macsec_sa = {
14226         .f = cmd_set_macsec_sa_parsed,
14227         .data = NULL,
14228         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14229         .tokens = {
14230                 (void *)&cmd_macsec_sa_set,
14231                 (void *)&cmd_macsec_sa_macsec,
14232                 (void *)&cmd_macsec_sa_sa,
14233                 (void *)&cmd_macsec_sa_tx_rx,
14234                 (void *)&cmd_macsec_sa_port_id,
14235                 (void *)&cmd_macsec_sa_idx,
14236                 (void *)&cmd_macsec_sa_an,
14237                 (void *)&cmd_macsec_sa_pn,
14238                 (void *)&cmd_macsec_sa_key,
14239                 NULL,
14240         },
14241 };
14242
14243 /* VF unicast promiscuous mode configuration */
14244
14245 /* Common result structure for VF unicast promiscuous mode */
14246 struct cmd_vf_promisc_result {
14247         cmdline_fixed_string_t set;
14248         cmdline_fixed_string_t vf;
14249         cmdline_fixed_string_t promisc;
14250         portid_t port_id;
14251         uint32_t vf_id;
14252         cmdline_fixed_string_t on_off;
14253 };
14254
14255 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14256 cmdline_parse_token_string_t cmd_vf_promisc_set =
14257         TOKEN_STRING_INITIALIZER
14258                 (struct cmd_vf_promisc_result,
14259                  set, "set");
14260 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14261         TOKEN_STRING_INITIALIZER
14262                 (struct cmd_vf_promisc_result,
14263                  vf, "vf");
14264 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14265         TOKEN_STRING_INITIALIZER
14266                 (struct cmd_vf_promisc_result,
14267                  promisc, "promisc");
14268 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14269         TOKEN_NUM_INITIALIZER
14270                 (struct cmd_vf_promisc_result,
14271                  port_id, UINT16);
14272 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14273         TOKEN_NUM_INITIALIZER
14274                 (struct cmd_vf_promisc_result,
14275                  vf_id, UINT32);
14276 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14277         TOKEN_STRING_INITIALIZER
14278                 (struct cmd_vf_promisc_result,
14279                  on_off, "on#off");
14280
14281 static void
14282 cmd_set_vf_promisc_parsed(
14283         void *parsed_result,
14284         __attribute__((unused)) struct cmdline *cl,
14285         __attribute__((unused)) void *data)
14286 {
14287         struct cmd_vf_promisc_result *res = parsed_result;
14288         int ret = -ENOTSUP;
14289
14290         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14291
14292         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14293                 return;
14294
14295 #ifdef RTE_LIBRTE_I40E_PMD
14296         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14297                                                   res->vf_id, is_on);
14298 #endif
14299
14300         switch (ret) {
14301         case 0:
14302                 break;
14303         case -EINVAL:
14304                 printf("invalid vf_id %d\n", res->vf_id);
14305                 break;
14306         case -ENODEV:
14307                 printf("invalid port_id %d\n", res->port_id);
14308                 break;
14309         case -ENOTSUP:
14310                 printf("function not implemented\n");
14311                 break;
14312         default:
14313                 printf("programming error: (%s)\n", strerror(-ret));
14314         }
14315 }
14316
14317 cmdline_parse_inst_t cmd_set_vf_promisc = {
14318         .f = cmd_set_vf_promisc_parsed,
14319         .data = NULL,
14320         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14321                 "Set unicast promiscuous mode for a VF from the PF",
14322         .tokens = {
14323                 (void *)&cmd_vf_promisc_set,
14324                 (void *)&cmd_vf_promisc_vf,
14325                 (void *)&cmd_vf_promisc_promisc,
14326                 (void *)&cmd_vf_promisc_port_id,
14327                 (void *)&cmd_vf_promisc_vf_id,
14328                 (void *)&cmd_vf_promisc_on_off,
14329                 NULL,
14330         },
14331 };
14332
14333 /* VF multicast promiscuous mode configuration */
14334
14335 /* Common result structure for VF multicast promiscuous mode */
14336 struct cmd_vf_allmulti_result {
14337         cmdline_fixed_string_t set;
14338         cmdline_fixed_string_t vf;
14339         cmdline_fixed_string_t allmulti;
14340         portid_t port_id;
14341         uint32_t vf_id;
14342         cmdline_fixed_string_t on_off;
14343 };
14344
14345 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14346 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14347         TOKEN_STRING_INITIALIZER
14348                 (struct cmd_vf_allmulti_result,
14349                  set, "set");
14350 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14351         TOKEN_STRING_INITIALIZER
14352                 (struct cmd_vf_allmulti_result,
14353                  vf, "vf");
14354 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14355         TOKEN_STRING_INITIALIZER
14356                 (struct cmd_vf_allmulti_result,
14357                  allmulti, "allmulti");
14358 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14359         TOKEN_NUM_INITIALIZER
14360                 (struct cmd_vf_allmulti_result,
14361                  port_id, UINT16);
14362 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14363         TOKEN_NUM_INITIALIZER
14364                 (struct cmd_vf_allmulti_result,
14365                  vf_id, UINT32);
14366 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14367         TOKEN_STRING_INITIALIZER
14368                 (struct cmd_vf_allmulti_result,
14369                  on_off, "on#off");
14370
14371 static void
14372 cmd_set_vf_allmulti_parsed(
14373         void *parsed_result,
14374         __attribute__((unused)) struct cmdline *cl,
14375         __attribute__((unused)) void *data)
14376 {
14377         struct cmd_vf_allmulti_result *res = parsed_result;
14378         int ret = -ENOTSUP;
14379
14380         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14381
14382         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14383                 return;
14384
14385 #ifdef RTE_LIBRTE_I40E_PMD
14386         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14387                                                     res->vf_id, is_on);
14388 #endif
14389
14390         switch (ret) {
14391         case 0:
14392                 break;
14393         case -EINVAL:
14394                 printf("invalid vf_id %d\n", res->vf_id);
14395                 break;
14396         case -ENODEV:
14397                 printf("invalid port_id %d\n", res->port_id);
14398                 break;
14399         case -ENOTSUP:
14400                 printf("function not implemented\n");
14401                 break;
14402         default:
14403                 printf("programming error: (%s)\n", strerror(-ret));
14404         }
14405 }
14406
14407 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14408         .f = cmd_set_vf_allmulti_parsed,
14409         .data = NULL,
14410         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14411                 "Set multicast promiscuous mode for a VF from the PF",
14412         .tokens = {
14413                 (void *)&cmd_vf_allmulti_set,
14414                 (void *)&cmd_vf_allmulti_vf,
14415                 (void *)&cmd_vf_allmulti_allmulti,
14416                 (void *)&cmd_vf_allmulti_port_id,
14417                 (void *)&cmd_vf_allmulti_vf_id,
14418                 (void *)&cmd_vf_allmulti_on_off,
14419                 NULL,
14420         },
14421 };
14422
14423 /* vf broadcast mode configuration */
14424
14425 /* Common result structure for vf broadcast */
14426 struct cmd_set_vf_broadcast_result {
14427         cmdline_fixed_string_t set;
14428         cmdline_fixed_string_t vf;
14429         cmdline_fixed_string_t broadcast;
14430         portid_t port_id;
14431         uint16_t vf_id;
14432         cmdline_fixed_string_t on_off;
14433 };
14434
14435 /* Common CLI fields for vf broadcast enable disable */
14436 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14437         TOKEN_STRING_INITIALIZER
14438                 (struct cmd_set_vf_broadcast_result,
14439                  set, "set");
14440 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14441         TOKEN_STRING_INITIALIZER
14442                 (struct cmd_set_vf_broadcast_result,
14443                  vf, "vf");
14444 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14445         TOKEN_STRING_INITIALIZER
14446                 (struct cmd_set_vf_broadcast_result,
14447                  broadcast, "broadcast");
14448 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14449         TOKEN_NUM_INITIALIZER
14450                 (struct cmd_set_vf_broadcast_result,
14451                  port_id, UINT16);
14452 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14453         TOKEN_NUM_INITIALIZER
14454                 (struct cmd_set_vf_broadcast_result,
14455                  vf_id, UINT16);
14456 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14457         TOKEN_STRING_INITIALIZER
14458                 (struct cmd_set_vf_broadcast_result,
14459                  on_off, "on#off");
14460
14461 static void
14462 cmd_set_vf_broadcast_parsed(
14463         void *parsed_result,
14464         __attribute__((unused)) struct cmdline *cl,
14465         __attribute__((unused)) void *data)
14466 {
14467         struct cmd_set_vf_broadcast_result *res = parsed_result;
14468         int ret = -ENOTSUP;
14469
14470         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14471
14472         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14473                 return;
14474
14475 #ifdef RTE_LIBRTE_I40E_PMD
14476         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14477                                             res->vf_id, is_on);
14478 #endif
14479
14480         switch (ret) {
14481         case 0:
14482                 break;
14483         case -EINVAL:
14484                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14485                 break;
14486         case -ENODEV:
14487                 printf("invalid port_id %d\n", res->port_id);
14488                 break;
14489         case -ENOTSUP:
14490                 printf("function not implemented\n");
14491                 break;
14492         default:
14493                 printf("programming error: (%s)\n", strerror(-ret));
14494         }
14495 }
14496
14497 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14498         .f = cmd_set_vf_broadcast_parsed,
14499         .data = NULL,
14500         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14501         .tokens = {
14502                 (void *)&cmd_set_vf_broadcast_set,
14503                 (void *)&cmd_set_vf_broadcast_vf,
14504                 (void *)&cmd_set_vf_broadcast_broadcast,
14505                 (void *)&cmd_set_vf_broadcast_port_id,
14506                 (void *)&cmd_set_vf_broadcast_vf_id,
14507                 (void *)&cmd_set_vf_broadcast_on_off,
14508                 NULL,
14509         },
14510 };
14511
14512 /* vf vlan tag configuration */
14513
14514 /* Common result structure for vf vlan tag */
14515 struct cmd_set_vf_vlan_tag_result {
14516         cmdline_fixed_string_t set;
14517         cmdline_fixed_string_t vf;
14518         cmdline_fixed_string_t vlan;
14519         cmdline_fixed_string_t tag;
14520         portid_t port_id;
14521         uint16_t vf_id;
14522         cmdline_fixed_string_t on_off;
14523 };
14524
14525 /* Common CLI fields for vf vlan tag enable disable */
14526 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14527         TOKEN_STRING_INITIALIZER
14528                 (struct cmd_set_vf_vlan_tag_result,
14529                  set, "set");
14530 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14531         TOKEN_STRING_INITIALIZER
14532                 (struct cmd_set_vf_vlan_tag_result,
14533                  vf, "vf");
14534 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14535         TOKEN_STRING_INITIALIZER
14536                 (struct cmd_set_vf_vlan_tag_result,
14537                  vlan, "vlan");
14538 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14539         TOKEN_STRING_INITIALIZER
14540                 (struct cmd_set_vf_vlan_tag_result,
14541                  tag, "tag");
14542 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14543         TOKEN_NUM_INITIALIZER
14544                 (struct cmd_set_vf_vlan_tag_result,
14545                  port_id, UINT16);
14546 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14547         TOKEN_NUM_INITIALIZER
14548                 (struct cmd_set_vf_vlan_tag_result,
14549                  vf_id, UINT16);
14550 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14551         TOKEN_STRING_INITIALIZER
14552                 (struct cmd_set_vf_vlan_tag_result,
14553                  on_off, "on#off");
14554
14555 static void
14556 cmd_set_vf_vlan_tag_parsed(
14557         void *parsed_result,
14558         __attribute__((unused)) struct cmdline *cl,
14559         __attribute__((unused)) void *data)
14560 {
14561         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14562         int ret = -ENOTSUP;
14563
14564         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14565
14566         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14567                 return;
14568
14569 #ifdef RTE_LIBRTE_I40E_PMD
14570         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14571                                            res->vf_id, is_on);
14572 #endif
14573
14574         switch (ret) {
14575         case 0:
14576                 break;
14577         case -EINVAL:
14578                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14579                 break;
14580         case -ENODEV:
14581                 printf("invalid port_id %d\n", res->port_id);
14582                 break;
14583         case -ENOTSUP:
14584                 printf("function not implemented\n");
14585                 break;
14586         default:
14587                 printf("programming error: (%s)\n", strerror(-ret));
14588         }
14589 }
14590
14591 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14592         .f = cmd_set_vf_vlan_tag_parsed,
14593         .data = NULL,
14594         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14595         .tokens = {
14596                 (void *)&cmd_set_vf_vlan_tag_set,
14597                 (void *)&cmd_set_vf_vlan_tag_vf,
14598                 (void *)&cmd_set_vf_vlan_tag_vlan,
14599                 (void *)&cmd_set_vf_vlan_tag_tag,
14600                 (void *)&cmd_set_vf_vlan_tag_port_id,
14601                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14602                 (void *)&cmd_set_vf_vlan_tag_on_off,
14603                 NULL,
14604         },
14605 };
14606
14607 /* Common definition of VF and TC TX bandwidth configuration */
14608 struct cmd_vf_tc_bw_result {
14609         cmdline_fixed_string_t set;
14610         cmdline_fixed_string_t vf;
14611         cmdline_fixed_string_t tc;
14612         cmdline_fixed_string_t tx;
14613         cmdline_fixed_string_t min_bw;
14614         cmdline_fixed_string_t max_bw;
14615         cmdline_fixed_string_t strict_link_prio;
14616         portid_t port_id;
14617         uint16_t vf_id;
14618         uint8_t tc_no;
14619         uint32_t bw;
14620         cmdline_fixed_string_t bw_list;
14621         uint8_t tc_map;
14622 };
14623
14624 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14625         TOKEN_STRING_INITIALIZER
14626                 (struct cmd_vf_tc_bw_result,
14627                  set, "set");
14628 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14629         TOKEN_STRING_INITIALIZER
14630                 (struct cmd_vf_tc_bw_result,
14631                  vf, "vf");
14632 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14633         TOKEN_STRING_INITIALIZER
14634                 (struct cmd_vf_tc_bw_result,
14635                  tc, "tc");
14636 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14637         TOKEN_STRING_INITIALIZER
14638                 (struct cmd_vf_tc_bw_result,
14639                  tx, "tx");
14640 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14641         TOKEN_STRING_INITIALIZER
14642                 (struct cmd_vf_tc_bw_result,
14643                  strict_link_prio, "strict-link-priority");
14644 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14645         TOKEN_STRING_INITIALIZER
14646                 (struct cmd_vf_tc_bw_result,
14647                  min_bw, "min-bandwidth");
14648 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14649         TOKEN_STRING_INITIALIZER
14650                 (struct cmd_vf_tc_bw_result,
14651                  max_bw, "max-bandwidth");
14652 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14653         TOKEN_NUM_INITIALIZER
14654                 (struct cmd_vf_tc_bw_result,
14655                  port_id, UINT16);
14656 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14657         TOKEN_NUM_INITIALIZER
14658                 (struct cmd_vf_tc_bw_result,
14659                  vf_id, UINT16);
14660 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14661         TOKEN_NUM_INITIALIZER
14662                 (struct cmd_vf_tc_bw_result,
14663                  tc_no, UINT8);
14664 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14665         TOKEN_NUM_INITIALIZER
14666                 (struct cmd_vf_tc_bw_result,
14667                  bw, UINT32);
14668 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14669         TOKEN_STRING_INITIALIZER
14670                 (struct cmd_vf_tc_bw_result,
14671                  bw_list, NULL);
14672 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14673         TOKEN_NUM_INITIALIZER
14674                 (struct cmd_vf_tc_bw_result,
14675                  tc_map, UINT8);
14676
14677 /* VF max bandwidth setting */
14678 static void
14679 cmd_vf_max_bw_parsed(
14680         void *parsed_result,
14681         __attribute__((unused)) struct cmdline *cl,
14682         __attribute__((unused)) void *data)
14683 {
14684         struct cmd_vf_tc_bw_result *res = parsed_result;
14685         int ret = -ENOTSUP;
14686
14687         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14688                 return;
14689
14690 #ifdef RTE_LIBRTE_I40E_PMD
14691         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14692                                          res->vf_id, res->bw);
14693 #endif
14694
14695         switch (ret) {
14696         case 0:
14697                 break;
14698         case -EINVAL:
14699                 printf("invalid vf_id %d or bandwidth %d\n",
14700                        res->vf_id, res->bw);
14701                 break;
14702         case -ENODEV:
14703                 printf("invalid port_id %d\n", res->port_id);
14704                 break;
14705         case -ENOTSUP:
14706                 printf("function not implemented\n");
14707                 break;
14708         default:
14709                 printf("programming error: (%s)\n", strerror(-ret));
14710         }
14711 }
14712
14713 cmdline_parse_inst_t cmd_vf_max_bw = {
14714         .f = cmd_vf_max_bw_parsed,
14715         .data = NULL,
14716         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14717         .tokens = {
14718                 (void *)&cmd_vf_tc_bw_set,
14719                 (void *)&cmd_vf_tc_bw_vf,
14720                 (void *)&cmd_vf_tc_bw_tx,
14721                 (void *)&cmd_vf_tc_bw_max_bw,
14722                 (void *)&cmd_vf_tc_bw_port_id,
14723                 (void *)&cmd_vf_tc_bw_vf_id,
14724                 (void *)&cmd_vf_tc_bw_bw,
14725                 NULL,
14726         },
14727 };
14728
14729 static int
14730 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14731                            uint8_t *tc_num,
14732                            char *str)
14733 {
14734         uint32_t size;
14735         const char *p, *p0 = str;
14736         char s[256];
14737         char *end;
14738         char *str_fld[16];
14739         uint16_t i;
14740         int ret;
14741
14742         p = strchr(p0, '(');
14743         if (p == NULL) {
14744                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14745                 return -1;
14746         }
14747         p++;
14748         p0 = strchr(p, ')');
14749         if (p0 == NULL) {
14750                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14751                 return -1;
14752         }
14753         size = p0 - p;
14754         if (size >= sizeof(s)) {
14755                 printf("The string size exceeds the internal buffer size\n");
14756                 return -1;
14757         }
14758         snprintf(s, sizeof(s), "%.*s", size, p);
14759         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14760         if (ret <= 0) {
14761                 printf("Failed to get the bandwidth list. ");
14762                 return -1;
14763         }
14764         *tc_num = ret;
14765         for (i = 0; i < ret; i++)
14766                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14767
14768         return 0;
14769 }
14770
14771 /* TC min bandwidth setting */
14772 static void
14773 cmd_vf_tc_min_bw_parsed(
14774         void *parsed_result,
14775         __attribute__((unused)) struct cmdline *cl,
14776         __attribute__((unused)) void *data)
14777 {
14778         struct cmd_vf_tc_bw_result *res = parsed_result;
14779         uint8_t tc_num;
14780         uint8_t bw[16];
14781         int ret = -ENOTSUP;
14782
14783         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14784                 return;
14785
14786         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14787         if (ret)
14788                 return;
14789
14790 #ifdef RTE_LIBRTE_I40E_PMD
14791         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14792                                               tc_num, bw);
14793 #endif
14794
14795         switch (ret) {
14796         case 0:
14797                 break;
14798         case -EINVAL:
14799                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14800                 break;
14801         case -ENODEV:
14802                 printf("invalid port_id %d\n", res->port_id);
14803                 break;
14804         case -ENOTSUP:
14805                 printf("function not implemented\n");
14806                 break;
14807         default:
14808                 printf("programming error: (%s)\n", strerror(-ret));
14809         }
14810 }
14811
14812 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14813         .f = cmd_vf_tc_min_bw_parsed,
14814         .data = NULL,
14815         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14816                     " <bw1, bw2, ...>",
14817         .tokens = {
14818                 (void *)&cmd_vf_tc_bw_set,
14819                 (void *)&cmd_vf_tc_bw_vf,
14820                 (void *)&cmd_vf_tc_bw_tc,
14821                 (void *)&cmd_vf_tc_bw_tx,
14822                 (void *)&cmd_vf_tc_bw_min_bw,
14823                 (void *)&cmd_vf_tc_bw_port_id,
14824                 (void *)&cmd_vf_tc_bw_vf_id,
14825                 (void *)&cmd_vf_tc_bw_bw_list,
14826                 NULL,
14827         },
14828 };
14829
14830 static void
14831 cmd_tc_min_bw_parsed(
14832         void *parsed_result,
14833         __attribute__((unused)) struct cmdline *cl,
14834         __attribute__((unused)) void *data)
14835 {
14836         struct cmd_vf_tc_bw_result *res = parsed_result;
14837         struct rte_port *port;
14838         uint8_t tc_num;
14839         uint8_t bw[16];
14840         int ret = -ENOTSUP;
14841
14842         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14843                 return;
14844
14845         port = &ports[res->port_id];
14846         /** Check if the port is not started **/
14847         if (port->port_status != RTE_PORT_STOPPED) {
14848                 printf("Please stop port %d first\n", res->port_id);
14849                 return;
14850         }
14851
14852         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14853         if (ret)
14854                 return;
14855
14856 #ifdef RTE_LIBRTE_IXGBE_PMD
14857         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14858 #endif
14859
14860         switch (ret) {
14861         case 0:
14862                 break;
14863         case -EINVAL:
14864                 printf("invalid bandwidth\n");
14865                 break;
14866         case -ENODEV:
14867                 printf("invalid port_id %d\n", res->port_id);
14868                 break;
14869         case -ENOTSUP:
14870                 printf("function not implemented\n");
14871                 break;
14872         default:
14873                 printf("programming error: (%s)\n", strerror(-ret));
14874         }
14875 }
14876
14877 cmdline_parse_inst_t cmd_tc_min_bw = {
14878         .f = cmd_tc_min_bw_parsed,
14879         .data = NULL,
14880         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14881         .tokens = {
14882                 (void *)&cmd_vf_tc_bw_set,
14883                 (void *)&cmd_vf_tc_bw_tc,
14884                 (void *)&cmd_vf_tc_bw_tx,
14885                 (void *)&cmd_vf_tc_bw_min_bw,
14886                 (void *)&cmd_vf_tc_bw_port_id,
14887                 (void *)&cmd_vf_tc_bw_bw_list,
14888                 NULL,
14889         },
14890 };
14891
14892 /* TC max bandwidth setting */
14893 static void
14894 cmd_vf_tc_max_bw_parsed(
14895         void *parsed_result,
14896         __attribute__((unused)) struct cmdline *cl,
14897         __attribute__((unused)) void *data)
14898 {
14899         struct cmd_vf_tc_bw_result *res = parsed_result;
14900         int ret = -ENOTSUP;
14901
14902         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14903                 return;
14904
14905 #ifdef RTE_LIBRTE_I40E_PMD
14906         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14907                                             res->tc_no, res->bw);
14908 #endif
14909
14910         switch (ret) {
14911         case 0:
14912                 break;
14913         case -EINVAL:
14914                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14915                        res->vf_id, res->tc_no, res->bw);
14916                 break;
14917         case -ENODEV:
14918                 printf("invalid port_id %d\n", res->port_id);
14919                 break;
14920         case -ENOTSUP:
14921                 printf("function not implemented\n");
14922                 break;
14923         default:
14924                 printf("programming error: (%s)\n", strerror(-ret));
14925         }
14926 }
14927
14928 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14929         .f = cmd_vf_tc_max_bw_parsed,
14930         .data = NULL,
14931         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14932                     " <bandwidth>",
14933         .tokens = {
14934                 (void *)&cmd_vf_tc_bw_set,
14935                 (void *)&cmd_vf_tc_bw_vf,
14936                 (void *)&cmd_vf_tc_bw_tc,
14937                 (void *)&cmd_vf_tc_bw_tx,
14938                 (void *)&cmd_vf_tc_bw_max_bw,
14939                 (void *)&cmd_vf_tc_bw_port_id,
14940                 (void *)&cmd_vf_tc_bw_vf_id,
14941                 (void *)&cmd_vf_tc_bw_tc_no,
14942                 (void *)&cmd_vf_tc_bw_bw,
14943                 NULL,
14944         },
14945 };
14946
14947
14948 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14949
14950 /* *** Set Port default Traffic Management Hierarchy *** */
14951 struct cmd_set_port_tm_hierarchy_default_result {
14952         cmdline_fixed_string_t set;
14953         cmdline_fixed_string_t port;
14954         cmdline_fixed_string_t tm;
14955         cmdline_fixed_string_t hierarchy;
14956         cmdline_fixed_string_t def;
14957         portid_t port_id;
14958 };
14959
14960 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14961         TOKEN_STRING_INITIALIZER(
14962                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14963 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14964         TOKEN_STRING_INITIALIZER(
14965                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14966 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14967         TOKEN_STRING_INITIALIZER(
14968                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14969 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14970         TOKEN_STRING_INITIALIZER(
14971                 struct cmd_set_port_tm_hierarchy_default_result,
14972                         hierarchy, "hierarchy");
14973 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14974         TOKEN_STRING_INITIALIZER(
14975                 struct cmd_set_port_tm_hierarchy_default_result,
14976                         def, "default");
14977 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14978         TOKEN_NUM_INITIALIZER(
14979                 struct cmd_set_port_tm_hierarchy_default_result,
14980                         port_id, UINT16);
14981
14982 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14983         __attribute__((unused)) struct cmdline *cl,
14984         __attribute__((unused)) void *data)
14985 {
14986         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14987         struct rte_port *p;
14988         portid_t port_id = res->port_id;
14989
14990         if (port_id_is_invalid(port_id, ENABLED_WARN))
14991                 return;
14992
14993         p = &ports[port_id];
14994
14995         /* Forward mode: tm */
14996         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
14997                 printf("  softnicfwd mode not enabled(error)\n");
14998                 return;
14999         }
15000
15001         /* Set the default tm hierarchy */
15002         p->softport.default_tm_hierarchy_enable = 1;
15003 }
15004
15005 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15006         .f = cmd_set_port_tm_hierarchy_default_parsed,
15007         .data = NULL,
15008         .help_str = "set port tm hierarchy default <port_id>",
15009         .tokens = {
15010                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15011                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15012                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15013                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15014                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15015                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15016                 NULL,
15017         },
15018 };
15019 #endif
15020
15021 /** Set VXLAN encapsulation details */
15022 struct cmd_set_vxlan_result {
15023         cmdline_fixed_string_t set;
15024         cmdline_fixed_string_t vxlan;
15025         cmdline_fixed_string_t pos_token;
15026         cmdline_fixed_string_t ip_version;
15027         uint32_t vlan_present:1;
15028         uint32_t vni;
15029         uint16_t udp_src;
15030         uint16_t udp_dst;
15031         cmdline_ipaddr_t ip_src;
15032         cmdline_ipaddr_t ip_dst;
15033         uint16_t tci;
15034         struct ether_addr eth_src;
15035         struct ether_addr eth_dst;
15036 };
15037
15038 cmdline_parse_token_string_t cmd_set_vxlan_set =
15039         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15040 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15041         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15042 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15043         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15044                                  "vxlan-with-vlan");
15045 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15046         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15047                                  "ip-version");
15048 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15049         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15050                                  "ipv4#ipv6");
15051 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15052         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15053                                  "vni");
15054 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15055         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15056 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15057         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15058                                  "udp-src");
15059 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15060         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15061 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15062         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15063                                  "udp-dst");
15064 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15065         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15066 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15067         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15068                                  "ip-src");
15069 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15070         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15071 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15072         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15073                                  "ip-dst");
15074 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15075         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15076 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15077         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15078                                  "vlan-tci");
15079 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15080         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15081 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15082         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15083                                  "eth-src");
15084 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15085         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15086 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15087         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15088                                  "eth-dst");
15089 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15090         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15091
15092 static void cmd_set_vxlan_parsed(void *parsed_result,
15093         __attribute__((unused)) struct cmdline *cl,
15094         __attribute__((unused)) void *data)
15095 {
15096         struct cmd_set_vxlan_result *res = parsed_result;
15097         union {
15098                 uint32_t vxlan_id;
15099                 uint8_t vni[4];
15100         } id = {
15101                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15102         };
15103
15104         if (strcmp(res->vxlan, "vxlan") == 0)
15105                 vxlan_encap_conf.select_vlan = 0;
15106         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15107                 vxlan_encap_conf.select_vlan = 1;
15108         if (strcmp(res->ip_version, "ipv4") == 0)
15109                 vxlan_encap_conf.select_ipv4 = 1;
15110         else if (strcmp(res->ip_version, "ipv6") == 0)
15111                 vxlan_encap_conf.select_ipv4 = 0;
15112         else
15113                 return;
15114         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15115         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15116         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15117         if (vxlan_encap_conf.select_ipv4) {
15118                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15119                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15120         } else {
15121                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15122                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15123         }
15124         if (vxlan_encap_conf.select_vlan)
15125                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15126         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15127                    ETHER_ADDR_LEN);
15128         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15129                    ETHER_ADDR_LEN);
15130 }
15131
15132 cmdline_parse_inst_t cmd_set_vxlan = {
15133         .f = cmd_set_vxlan_parsed,
15134         .data = NULL,
15135         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15136                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15137                 " eth-src <eth-src> eth-dst <eth-dst>",
15138         .tokens = {
15139                 (void *)&cmd_set_vxlan_set,
15140                 (void *)&cmd_set_vxlan_vxlan,
15141                 (void *)&cmd_set_vxlan_ip_version,
15142                 (void *)&cmd_set_vxlan_ip_version_value,
15143                 (void *)&cmd_set_vxlan_vni,
15144                 (void *)&cmd_set_vxlan_vni_value,
15145                 (void *)&cmd_set_vxlan_udp_src,
15146                 (void *)&cmd_set_vxlan_udp_src_value,
15147                 (void *)&cmd_set_vxlan_udp_dst,
15148                 (void *)&cmd_set_vxlan_udp_dst_value,
15149                 (void *)&cmd_set_vxlan_ip_src,
15150                 (void *)&cmd_set_vxlan_ip_src_value,
15151                 (void *)&cmd_set_vxlan_ip_dst,
15152                 (void *)&cmd_set_vxlan_ip_dst_value,
15153                 (void *)&cmd_set_vxlan_eth_src,
15154                 (void *)&cmd_set_vxlan_eth_src_value,
15155                 (void *)&cmd_set_vxlan_eth_dst,
15156                 (void *)&cmd_set_vxlan_eth_dst_value,
15157                 NULL,
15158         },
15159 };
15160
15161 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15162         .f = cmd_set_vxlan_parsed,
15163         .data = NULL,
15164         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15165                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15166                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15167                 " <eth-dst>",
15168         .tokens = {
15169                 (void *)&cmd_set_vxlan_set,
15170                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15171                 (void *)&cmd_set_vxlan_ip_version,
15172                 (void *)&cmd_set_vxlan_ip_version_value,
15173                 (void *)&cmd_set_vxlan_vni,
15174                 (void *)&cmd_set_vxlan_vni_value,
15175                 (void *)&cmd_set_vxlan_udp_src,
15176                 (void *)&cmd_set_vxlan_udp_src_value,
15177                 (void *)&cmd_set_vxlan_udp_dst,
15178                 (void *)&cmd_set_vxlan_udp_dst_value,
15179                 (void *)&cmd_set_vxlan_ip_src,
15180                 (void *)&cmd_set_vxlan_ip_src_value,
15181                 (void *)&cmd_set_vxlan_ip_dst,
15182                 (void *)&cmd_set_vxlan_ip_dst_value,
15183                 (void *)&cmd_set_vxlan_vlan,
15184                 (void *)&cmd_set_vxlan_vlan_value,
15185                 (void *)&cmd_set_vxlan_eth_src,
15186                 (void *)&cmd_set_vxlan_eth_src_value,
15187                 (void *)&cmd_set_vxlan_eth_dst,
15188                 (void *)&cmd_set_vxlan_eth_dst_value,
15189                 NULL,
15190         },
15191 };
15192
15193 /** Set NVGRE encapsulation details */
15194 struct cmd_set_nvgre_result {
15195         cmdline_fixed_string_t set;
15196         cmdline_fixed_string_t nvgre;
15197         cmdline_fixed_string_t pos_token;
15198         cmdline_fixed_string_t ip_version;
15199         uint32_t tni;
15200         cmdline_ipaddr_t ip_src;
15201         cmdline_ipaddr_t ip_dst;
15202         uint16_t tci;
15203         struct ether_addr eth_src;
15204         struct ether_addr eth_dst;
15205 };
15206
15207 cmdline_parse_token_string_t cmd_set_nvgre_set =
15208         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15209 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15210         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15211 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15212         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15213                                  "nvgre-with-vlan");
15214 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15215         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15216                                  "ip-version");
15217 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15218         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15219                                  "ipv4#ipv6");
15220 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15221         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15222                                  "tni");
15223 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15224         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15225 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15226         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15227                                  "ip-src");
15228 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15229         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15230 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15231         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15232                                  "ip-dst");
15233 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15234         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15235 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15236         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15237                                  "vlan-tci");
15238 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15239         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15240 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15241         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15242                                  "eth-src");
15243 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15244         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15245 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15246         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15247                                  "eth-dst");
15248 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15249         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15250
15251 static void cmd_set_nvgre_parsed(void *parsed_result,
15252         __attribute__((unused)) struct cmdline *cl,
15253         __attribute__((unused)) void *data)
15254 {
15255         struct cmd_set_nvgre_result *res = parsed_result;
15256         union {
15257                 uint32_t nvgre_tni;
15258                 uint8_t tni[4];
15259         } id = {
15260                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15261         };
15262
15263         if (strcmp(res->nvgre, "nvgre") == 0)
15264                 nvgre_encap_conf.select_vlan = 0;
15265         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15266                 nvgre_encap_conf.select_vlan = 1;
15267         if (strcmp(res->ip_version, "ipv4") == 0)
15268                 nvgre_encap_conf.select_ipv4 = 1;
15269         else if (strcmp(res->ip_version, "ipv6") == 0)
15270                 nvgre_encap_conf.select_ipv4 = 0;
15271         else
15272                 return;
15273         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15274         if (nvgre_encap_conf.select_ipv4) {
15275                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15276                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15277         } else {
15278                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15279                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15280         }
15281         if (nvgre_encap_conf.select_vlan)
15282                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15283         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15284                    ETHER_ADDR_LEN);
15285         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15286                    ETHER_ADDR_LEN);
15287 }
15288
15289 cmdline_parse_inst_t cmd_set_nvgre = {
15290         .f = cmd_set_nvgre_parsed,
15291         .data = NULL,
15292         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15293                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15294                 " eth-dst <eth-dst>",
15295         .tokens = {
15296                 (void *)&cmd_set_nvgre_set,
15297                 (void *)&cmd_set_nvgre_nvgre,
15298                 (void *)&cmd_set_nvgre_ip_version,
15299                 (void *)&cmd_set_nvgre_ip_version_value,
15300                 (void *)&cmd_set_nvgre_tni,
15301                 (void *)&cmd_set_nvgre_tni_value,
15302                 (void *)&cmd_set_nvgre_ip_src,
15303                 (void *)&cmd_set_nvgre_ip_src_value,
15304                 (void *)&cmd_set_nvgre_ip_dst,
15305                 (void *)&cmd_set_nvgre_ip_dst_value,
15306                 (void *)&cmd_set_nvgre_eth_src,
15307                 (void *)&cmd_set_nvgre_eth_src_value,
15308                 (void *)&cmd_set_nvgre_eth_dst,
15309                 (void *)&cmd_set_nvgre_eth_dst_value,
15310                 NULL,
15311         },
15312 };
15313
15314 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15315         .f = cmd_set_nvgre_parsed,
15316         .data = NULL,
15317         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15318                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15319                 " eth-src <eth-src> eth-dst <eth-dst>",
15320         .tokens = {
15321                 (void *)&cmd_set_nvgre_set,
15322                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15323                 (void *)&cmd_set_nvgre_ip_version,
15324                 (void *)&cmd_set_nvgre_ip_version_value,
15325                 (void *)&cmd_set_nvgre_tni,
15326                 (void *)&cmd_set_nvgre_tni_value,
15327                 (void *)&cmd_set_nvgre_ip_src,
15328                 (void *)&cmd_set_nvgre_ip_src_value,
15329                 (void *)&cmd_set_nvgre_ip_dst,
15330                 (void *)&cmd_set_nvgre_ip_dst_value,
15331                 (void *)&cmd_set_nvgre_vlan,
15332                 (void *)&cmd_set_nvgre_vlan_value,
15333                 (void *)&cmd_set_nvgre_eth_src,
15334                 (void *)&cmd_set_nvgre_eth_src_value,
15335                 (void *)&cmd_set_nvgre_eth_dst,
15336                 (void *)&cmd_set_nvgre_eth_dst_value,
15337                 NULL,
15338         },
15339 };
15340
15341 /** Set L2 encapsulation details */
15342 struct cmd_set_l2_encap_result {
15343         cmdline_fixed_string_t set;
15344         cmdline_fixed_string_t l2_encap;
15345         cmdline_fixed_string_t pos_token;
15346         cmdline_fixed_string_t ip_version;
15347         uint32_t vlan_present:1;
15348         uint16_t tci;
15349         struct ether_addr eth_src;
15350         struct ether_addr eth_dst;
15351 };
15352
15353 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15354         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15355 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15356         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15357 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15358         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15359                                  "l2_encap-with-vlan");
15360 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15361         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15362                                  "ip-version");
15363 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15364         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15365                                  "ipv4#ipv6");
15366 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15367         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15368                                  "vlan-tci");
15369 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15370         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15371 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15372         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15373                                  "eth-src");
15374 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15375         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15376 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15377         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15378                                  "eth-dst");
15379 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15380         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15381
15382 static void cmd_set_l2_encap_parsed(void *parsed_result,
15383         __attribute__((unused)) struct cmdline *cl,
15384         __attribute__((unused)) void *data)
15385 {
15386         struct cmd_set_l2_encap_result *res = parsed_result;
15387
15388         if (strcmp(res->l2_encap, "l2_encap") == 0)
15389                 l2_encap_conf.select_vlan = 0;
15390         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15391                 l2_encap_conf.select_vlan = 1;
15392         if (strcmp(res->ip_version, "ipv4") == 0)
15393                 l2_encap_conf.select_ipv4 = 1;
15394         else if (strcmp(res->ip_version, "ipv6") == 0)
15395                 l2_encap_conf.select_ipv4 = 0;
15396         else
15397                 return;
15398         if (l2_encap_conf.select_vlan)
15399                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15400         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15401                    ETHER_ADDR_LEN);
15402         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15403                    ETHER_ADDR_LEN);
15404 }
15405
15406 cmdline_parse_inst_t cmd_set_l2_encap = {
15407         .f = cmd_set_l2_encap_parsed,
15408         .data = NULL,
15409         .help_str = "set l2_encap ip-version ipv4|ipv6"
15410                 " eth-src <eth-src> eth-dst <eth-dst>",
15411         .tokens = {
15412                 (void *)&cmd_set_l2_encap_set,
15413                 (void *)&cmd_set_l2_encap_l2_encap,
15414                 (void *)&cmd_set_l2_encap_ip_version,
15415                 (void *)&cmd_set_l2_encap_ip_version_value,
15416                 (void *)&cmd_set_l2_encap_eth_src,
15417                 (void *)&cmd_set_l2_encap_eth_src_value,
15418                 (void *)&cmd_set_l2_encap_eth_dst,
15419                 (void *)&cmd_set_l2_encap_eth_dst_value,
15420                 NULL,
15421         },
15422 };
15423
15424 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15425         .f = cmd_set_l2_encap_parsed,
15426         .data = NULL,
15427         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15428                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15429         .tokens = {
15430                 (void *)&cmd_set_l2_encap_set,
15431                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15432                 (void *)&cmd_set_l2_encap_ip_version,
15433                 (void *)&cmd_set_l2_encap_ip_version_value,
15434                 (void *)&cmd_set_l2_encap_vlan,
15435                 (void *)&cmd_set_l2_encap_vlan_value,
15436                 (void *)&cmd_set_l2_encap_eth_src,
15437                 (void *)&cmd_set_l2_encap_eth_src_value,
15438                 (void *)&cmd_set_l2_encap_eth_dst,
15439                 (void *)&cmd_set_l2_encap_eth_dst_value,
15440                 NULL,
15441         },
15442 };
15443
15444 /** Set L2 decapsulation details */
15445 struct cmd_set_l2_decap_result {
15446         cmdline_fixed_string_t set;
15447         cmdline_fixed_string_t l2_decap;
15448         cmdline_fixed_string_t pos_token;
15449         uint32_t vlan_present:1;
15450 };
15451
15452 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15453         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15454 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15455         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15456                                  "l2_decap");
15457 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15458         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15459                                  "l2_decap-with-vlan");
15460
15461 static void cmd_set_l2_decap_parsed(void *parsed_result,
15462         __attribute__((unused)) struct cmdline *cl,
15463         __attribute__((unused)) void *data)
15464 {
15465         struct cmd_set_l2_decap_result *res = parsed_result;
15466
15467         if (strcmp(res->l2_decap, "l2_decap") == 0)
15468                 l2_decap_conf.select_vlan = 0;
15469         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15470                 l2_decap_conf.select_vlan = 1;
15471 }
15472
15473 cmdline_parse_inst_t cmd_set_l2_decap = {
15474         .f = cmd_set_l2_decap_parsed,
15475         .data = NULL,
15476         .help_str = "set l2_decap",
15477         .tokens = {
15478                 (void *)&cmd_set_l2_decap_set,
15479                 (void *)&cmd_set_l2_decap_l2_decap,
15480                 NULL,
15481         },
15482 };
15483
15484 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15485         .f = cmd_set_l2_decap_parsed,
15486         .data = NULL,
15487         .help_str = "set l2_decap-with-vlan",
15488         .tokens = {
15489                 (void *)&cmd_set_l2_decap_set,
15490                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15491                 NULL,
15492         },
15493 };
15494
15495 /** Set MPLSoGRE encapsulation details */
15496 struct cmd_set_mplsogre_encap_result {
15497         cmdline_fixed_string_t set;
15498         cmdline_fixed_string_t mplsogre;
15499         cmdline_fixed_string_t pos_token;
15500         cmdline_fixed_string_t ip_version;
15501         uint32_t vlan_present:1;
15502         uint32_t label;
15503         cmdline_ipaddr_t ip_src;
15504         cmdline_ipaddr_t ip_dst;
15505         uint16_t tci;
15506         struct ether_addr eth_src;
15507         struct ether_addr eth_dst;
15508 };
15509
15510 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15511         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15512                                  "set");
15513 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15514         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15515                                  "mplsogre_encap");
15516 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15517         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15518                                  mplsogre, "mplsogre_encap-with-vlan");
15519 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15520         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15521                                  pos_token, "ip-version");
15522 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15523         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15524                                  ip_version, "ipv4#ipv6");
15525 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15526         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15527                                  pos_token, "label");
15528 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15529         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15530                               UINT32);
15531 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15532         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15533                                  pos_token, "ip-src");
15534 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15535         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15536 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15537         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15538                                  pos_token, "ip-dst");
15539 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15540         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15541 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15542         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15543                                  pos_token, "vlan-tci");
15544 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15545         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15546                               UINT16);
15547 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15548         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15549                                  pos_token, "eth-src");
15550 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15551         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15552                                     eth_src);
15553 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15554         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15555                                  pos_token, "eth-dst");
15556 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15557         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15558                                     eth_dst);
15559
15560 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15561         __attribute__((unused)) struct cmdline *cl,
15562         __attribute__((unused)) void *data)
15563 {
15564         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15565         union {
15566                 uint32_t mplsogre_label;
15567                 uint8_t label[3];
15568         } id = {
15569                 .mplsogre_label =
15570                         rte_cpu_to_be_32(res->label) & RTE_BE32(0x00ffffff),
15571         };
15572
15573         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15574                 mplsogre_encap_conf.select_vlan = 0;
15575         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15576                 mplsogre_encap_conf.select_vlan = 1;
15577         if (strcmp(res->ip_version, "ipv4") == 0)
15578                 mplsogre_encap_conf.select_ipv4 = 1;
15579         else if (strcmp(res->ip_version, "ipv6") == 0)
15580                 mplsogre_encap_conf.select_ipv4 = 0;
15581         else
15582                 return;
15583         rte_memcpy(mplsogre_encap_conf.label, &id.label[1], 3);
15584         if (mplsogre_encap_conf.select_ipv4) {
15585                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15586                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15587         } else {
15588                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15589                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15590         }
15591         if (mplsogre_encap_conf.select_vlan)
15592                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15593         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15594                    ETHER_ADDR_LEN);
15595         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15596                    ETHER_ADDR_LEN);
15597 }
15598
15599 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15600         .f = cmd_set_mplsogre_encap_parsed,
15601         .data = NULL,
15602         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15603                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15604                 " eth-dst <eth-dst>",
15605         .tokens = {
15606                 (void *)&cmd_set_mplsogre_encap_set,
15607                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15608                 (void *)&cmd_set_mplsogre_encap_ip_version,
15609                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15610                 (void *)&cmd_set_mplsogre_encap_label,
15611                 (void *)&cmd_set_mplsogre_encap_label_value,
15612                 (void *)&cmd_set_mplsogre_encap_ip_src,
15613                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15614                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15615                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15616                 (void *)&cmd_set_mplsogre_encap_eth_src,
15617                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15618                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15619                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15620                 NULL,
15621         },
15622 };
15623
15624 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15625         .f = cmd_set_mplsogre_encap_parsed,
15626         .data = NULL,
15627         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15628                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15629                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15630         .tokens = {
15631                 (void *)&cmd_set_mplsogre_encap_set,
15632                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15633                 (void *)&cmd_set_mplsogre_encap_ip_version,
15634                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15635                 (void *)&cmd_set_mplsogre_encap_label,
15636                 (void *)&cmd_set_mplsogre_encap_label_value,
15637                 (void *)&cmd_set_mplsogre_encap_ip_src,
15638                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15639                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15640                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15641                 (void *)&cmd_set_mplsogre_encap_vlan,
15642                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15643                 (void *)&cmd_set_mplsogre_encap_eth_src,
15644                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15645                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15646                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15647                 NULL,
15648         },
15649 };
15650
15651 /** Set MPLSoGRE decapsulation details */
15652 struct cmd_set_mplsogre_decap_result {
15653         cmdline_fixed_string_t set;
15654         cmdline_fixed_string_t mplsogre;
15655         cmdline_fixed_string_t pos_token;
15656         cmdline_fixed_string_t ip_version;
15657         uint32_t vlan_present:1;
15658 };
15659
15660 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15661         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15662                                  "set");
15663 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15664         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15665                                  "mplsogre_decap");
15666 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15667         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15668                                  mplsogre, "mplsogre_decap-with-vlan");
15669 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15670         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15671                                  pos_token, "ip-version");
15672 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15673         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15674                                  ip_version, "ipv4#ipv6");
15675
15676 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15677         __attribute__((unused)) struct cmdline *cl,
15678         __attribute__((unused)) void *data)
15679 {
15680         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15681
15682         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15683                 mplsogre_decap_conf.select_vlan = 0;
15684         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15685                 mplsogre_decap_conf.select_vlan = 1;
15686         if (strcmp(res->ip_version, "ipv4") == 0)
15687                 mplsogre_decap_conf.select_ipv4 = 1;
15688         else if (strcmp(res->ip_version, "ipv6") == 0)
15689                 mplsogre_decap_conf.select_ipv4 = 0;
15690 }
15691
15692 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15693         .f = cmd_set_mplsogre_decap_parsed,
15694         .data = NULL,
15695         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15696         .tokens = {
15697                 (void *)&cmd_set_mplsogre_decap_set,
15698                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15699                 (void *)&cmd_set_mplsogre_decap_ip_version,
15700                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15701                 NULL,
15702         },
15703 };
15704
15705 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15706         .f = cmd_set_mplsogre_decap_parsed,
15707         .data = NULL,
15708         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15709         .tokens = {
15710                 (void *)&cmd_set_mplsogre_decap_set,
15711                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15712                 (void *)&cmd_set_mplsogre_decap_ip_version,
15713                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15714                 NULL,
15715         },
15716 };
15717
15718 /** Set MPLSoUDP encapsulation details */
15719 struct cmd_set_mplsoudp_encap_result {
15720         cmdline_fixed_string_t set;
15721         cmdline_fixed_string_t mplsoudp;
15722         cmdline_fixed_string_t pos_token;
15723         cmdline_fixed_string_t ip_version;
15724         uint32_t vlan_present:1;
15725         uint32_t label;
15726         uint16_t udp_src;
15727         uint16_t udp_dst;
15728         cmdline_ipaddr_t ip_src;
15729         cmdline_ipaddr_t ip_dst;
15730         uint16_t tci;
15731         struct ether_addr eth_src;
15732         struct ether_addr eth_dst;
15733 };
15734
15735 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15736         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15737                                  "set");
15738 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15739         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15740                                  "mplsoudp_encap");
15741 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15742         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15743                                  mplsoudp, "mplsoudp_encap-with-vlan");
15744 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15745         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15746                                  pos_token, "ip-version");
15747 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15748         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15749                                  ip_version, "ipv4#ipv6");
15750 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15751         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15752                                  pos_token, "label");
15753 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15754         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15755                               UINT32);
15756 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15757         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15758                                  pos_token, "udp-src");
15759 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
15760         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
15761                               UINT16);
15762 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
15763         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15764                                  pos_token, "udp-dst");
15765 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
15766         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
15767                               UINT16);
15768 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
15769         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15770                                  pos_token, "ip-src");
15771 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
15772         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
15773 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
15774         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15775                                  pos_token, "ip-dst");
15776 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
15777         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
15778 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
15779         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15780                                  pos_token, "vlan-tci");
15781 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
15782         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
15783                               UINT16);
15784 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
15785         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15786                                  pos_token, "eth-src");
15787 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
15788         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15789                                     eth_src);
15790 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
15791         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15792                                  pos_token, "eth-dst");
15793 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
15794         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15795                                     eth_dst);
15796
15797 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
15798         __attribute__((unused)) struct cmdline *cl,
15799         __attribute__((unused)) void *data)
15800 {
15801         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
15802         union {
15803                 uint32_t mplsoudp_label;
15804                 uint8_t label[3];
15805         } id = {
15806                 .mplsoudp_label =
15807                         rte_cpu_to_be_32(res->label) & RTE_BE32(0x00ffffff),
15808         };
15809
15810         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
15811                 mplsoudp_encap_conf.select_vlan = 0;
15812         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
15813                 mplsoudp_encap_conf.select_vlan = 1;
15814         if (strcmp(res->ip_version, "ipv4") == 0)
15815                 mplsoudp_encap_conf.select_ipv4 = 1;
15816         else if (strcmp(res->ip_version, "ipv6") == 0)
15817                 mplsoudp_encap_conf.select_ipv4 = 0;
15818         else
15819                 return;
15820         rte_memcpy(mplsoudp_encap_conf.label, &id.label[1], 3);
15821         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15822         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15823         if (mplsoudp_encap_conf.select_ipv4) {
15824                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
15825                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
15826         } else {
15827                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
15828                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
15829         }
15830         if (mplsoudp_encap_conf.select_vlan)
15831                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15832         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
15833                    ETHER_ADDR_LEN);
15834         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15835                    ETHER_ADDR_LEN);
15836 }
15837
15838 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
15839         .f = cmd_set_mplsoudp_encap_parsed,
15840         .data = NULL,
15841         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
15842                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
15843                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
15844         .tokens = {
15845                 (void *)&cmd_set_mplsoudp_encap_set,
15846                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
15847                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15848                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15849                 (void *)&cmd_set_mplsoudp_encap_label,
15850                 (void *)&cmd_set_mplsoudp_encap_label_value,
15851                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15852                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15853                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15854                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15855                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15856                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15857                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15858                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15859                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15860                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15861                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15862                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15863                 NULL,
15864         },
15865 };
15866
15867 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
15868         .f = cmd_set_mplsoudp_encap_parsed,
15869         .data = NULL,
15870         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
15871                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
15872                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15873                 " eth-src <eth-src> eth-dst <eth-dst>",
15874         .tokens = {
15875                 (void *)&cmd_set_mplsoudp_encap_set,
15876                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
15877                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15878                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15879                 (void *)&cmd_set_mplsoudp_encap_label,
15880                 (void *)&cmd_set_mplsoudp_encap_label_value,
15881                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15882                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15883                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15884                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15885                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15886                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15887                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15888                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15889                 (void *)&cmd_set_mplsoudp_encap_vlan,
15890                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
15891                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15892                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15893                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15894                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15895                 NULL,
15896         },
15897 };
15898
15899 /** Set MPLSoUDP decapsulation details */
15900 struct cmd_set_mplsoudp_decap_result {
15901         cmdline_fixed_string_t set;
15902         cmdline_fixed_string_t mplsoudp;
15903         cmdline_fixed_string_t pos_token;
15904         cmdline_fixed_string_t ip_version;
15905         uint32_t vlan_present:1;
15906 };
15907
15908 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
15909         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
15910                                  "set");
15911 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
15912         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
15913                                  "mplsoudp_decap");
15914 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
15915         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15916                                  mplsoudp, "mplsoudp_decap-with-vlan");
15917 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
15918         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15919                                  pos_token, "ip-version");
15920 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
15921         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15922                                  ip_version, "ipv4#ipv6");
15923
15924 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
15925         __attribute__((unused)) struct cmdline *cl,
15926         __attribute__((unused)) void *data)
15927 {
15928         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
15929
15930         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
15931                 mplsoudp_decap_conf.select_vlan = 0;
15932         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
15933                 mplsoudp_decap_conf.select_vlan = 1;
15934         if (strcmp(res->ip_version, "ipv4") == 0)
15935                 mplsoudp_decap_conf.select_ipv4 = 1;
15936         else if (strcmp(res->ip_version, "ipv6") == 0)
15937                 mplsoudp_decap_conf.select_ipv4 = 0;
15938 }
15939
15940 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
15941         .f = cmd_set_mplsoudp_decap_parsed,
15942         .data = NULL,
15943         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
15944         .tokens = {
15945                 (void *)&cmd_set_mplsoudp_decap_set,
15946                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
15947                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15948                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15949                 NULL,
15950         },
15951 };
15952
15953 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
15954         .f = cmd_set_mplsoudp_decap_parsed,
15955         .data = NULL,
15956         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
15957         .tokens = {
15958                 (void *)&cmd_set_mplsoudp_decap_set,
15959                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
15960                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15961                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15962                 NULL,
15963         },
15964 };
15965
15966 /* Strict link priority scheduling mode setting */
15967 static void
15968 cmd_strict_link_prio_parsed(
15969         void *parsed_result,
15970         __attribute__((unused)) struct cmdline *cl,
15971         __attribute__((unused)) void *data)
15972 {
15973         struct cmd_vf_tc_bw_result *res = parsed_result;
15974         int ret = -ENOTSUP;
15975
15976         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15977                 return;
15978
15979 #ifdef RTE_LIBRTE_I40E_PMD
15980         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
15981 #endif
15982
15983         switch (ret) {
15984         case 0:
15985                 break;
15986         case -EINVAL:
15987                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
15988                 break;
15989         case -ENODEV:
15990                 printf("invalid port_id %d\n", res->port_id);
15991                 break;
15992         case -ENOTSUP:
15993                 printf("function not implemented\n");
15994                 break;
15995         default:
15996                 printf("programming error: (%s)\n", strerror(-ret));
15997         }
15998 }
15999
16000 cmdline_parse_inst_t cmd_strict_link_prio = {
16001         .f = cmd_strict_link_prio_parsed,
16002         .data = NULL,
16003         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16004         .tokens = {
16005                 (void *)&cmd_vf_tc_bw_set,
16006                 (void *)&cmd_vf_tc_bw_tx,
16007                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16008                 (void *)&cmd_vf_tc_bw_port_id,
16009                 (void *)&cmd_vf_tc_bw_tc_map,
16010                 NULL,
16011         },
16012 };
16013
16014 /* Load dynamic device personalization*/
16015 struct cmd_ddp_add_result {
16016         cmdline_fixed_string_t ddp;
16017         cmdline_fixed_string_t add;
16018         portid_t port_id;
16019         char filepath[];
16020 };
16021
16022 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16023         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16024 cmdline_parse_token_string_t cmd_ddp_add_add =
16025         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16026 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16027         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16028 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16029         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16030
16031 static void
16032 cmd_ddp_add_parsed(
16033         void *parsed_result,
16034         __attribute__((unused)) struct cmdline *cl,
16035         __attribute__((unused)) void *data)
16036 {
16037         struct cmd_ddp_add_result *res = parsed_result;
16038         uint8_t *buff;
16039         uint32_t size;
16040         char *filepath;
16041         char *file_fld[2];
16042         int file_num;
16043         int ret = -ENOTSUP;
16044
16045         if (!all_ports_stopped()) {
16046                 printf("Please stop all ports first\n");
16047                 return;
16048         }
16049
16050         filepath = strdup(res->filepath);
16051         if (filepath == NULL) {
16052                 printf("Failed to allocate memory\n");
16053                 return;
16054         }
16055         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16056
16057         buff = open_file(file_fld[0], &size);
16058         if (!buff) {
16059                 free((void *)filepath);
16060                 return;
16061         }
16062
16063 #ifdef RTE_LIBRTE_I40E_PMD
16064         if (ret == -ENOTSUP)
16065                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16066                                                buff, size,
16067                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16068 #endif
16069
16070         if (ret == -EEXIST)
16071                 printf("Profile has already existed.\n");
16072         else if (ret < 0)
16073                 printf("Failed to load profile.\n");
16074         else if (file_num == 2)
16075                 save_file(file_fld[1], buff, size);
16076
16077         close_file(buff);
16078         free((void *)filepath);
16079 }
16080
16081 cmdline_parse_inst_t cmd_ddp_add = {
16082         .f = cmd_ddp_add_parsed,
16083         .data = NULL,
16084         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16085         .tokens = {
16086                 (void *)&cmd_ddp_add_ddp,
16087                 (void *)&cmd_ddp_add_add,
16088                 (void *)&cmd_ddp_add_port_id,
16089                 (void *)&cmd_ddp_add_filepath,
16090                 NULL,
16091         },
16092 };
16093
16094 /* Delete dynamic device personalization*/
16095 struct cmd_ddp_del_result {
16096         cmdline_fixed_string_t ddp;
16097         cmdline_fixed_string_t del;
16098         portid_t port_id;
16099         char filepath[];
16100 };
16101
16102 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16103         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16104 cmdline_parse_token_string_t cmd_ddp_del_del =
16105         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16106 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16107         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16108 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16109         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16110
16111 static void
16112 cmd_ddp_del_parsed(
16113         void *parsed_result,
16114         __attribute__((unused)) struct cmdline *cl,
16115         __attribute__((unused)) void *data)
16116 {
16117         struct cmd_ddp_del_result *res = parsed_result;
16118         uint8_t *buff;
16119         uint32_t size;
16120         int ret = -ENOTSUP;
16121
16122         if (!all_ports_stopped()) {
16123                 printf("Please stop all ports first\n");
16124                 return;
16125         }
16126
16127         buff = open_file(res->filepath, &size);
16128         if (!buff)
16129                 return;
16130
16131 #ifdef RTE_LIBRTE_I40E_PMD
16132         if (ret == -ENOTSUP)
16133                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16134                                                buff, size,
16135                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16136 #endif
16137
16138         if (ret == -EACCES)
16139                 printf("Profile does not exist.\n");
16140         else if (ret < 0)
16141                 printf("Failed to delete profile.\n");
16142
16143         close_file(buff);
16144 }
16145
16146 cmdline_parse_inst_t cmd_ddp_del = {
16147         .f = cmd_ddp_del_parsed,
16148         .data = NULL,
16149         .help_str = "ddp del <port_id> <backup_profile_path>",
16150         .tokens = {
16151                 (void *)&cmd_ddp_del_ddp,
16152                 (void *)&cmd_ddp_del_del,
16153                 (void *)&cmd_ddp_del_port_id,
16154                 (void *)&cmd_ddp_del_filepath,
16155                 NULL,
16156         },
16157 };
16158
16159 /* Get dynamic device personalization profile info */
16160 struct cmd_ddp_info_result {
16161         cmdline_fixed_string_t ddp;
16162         cmdline_fixed_string_t get;
16163         cmdline_fixed_string_t info;
16164         char filepath[];
16165 };
16166
16167 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16168         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16169 cmdline_parse_token_string_t cmd_ddp_info_get =
16170         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16171 cmdline_parse_token_string_t cmd_ddp_info_info =
16172         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16173 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16174         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16175
16176 static void
16177 cmd_ddp_info_parsed(
16178         void *parsed_result,
16179         __attribute__((unused)) struct cmdline *cl,
16180         __attribute__((unused)) void *data)
16181 {
16182         struct cmd_ddp_info_result *res = parsed_result;
16183         uint8_t *pkg;
16184         uint32_t pkg_size;
16185         int ret = -ENOTSUP;
16186 #ifdef RTE_LIBRTE_I40E_PMD
16187         uint32_t i, j, n;
16188         uint8_t *buff;
16189         uint32_t buff_size = 0;
16190         struct rte_pmd_i40e_profile_info info;
16191         uint32_t dev_num = 0;
16192         struct rte_pmd_i40e_ddp_device_id *devs;
16193         uint32_t proto_num = 0;
16194         struct rte_pmd_i40e_proto_info *proto = NULL;
16195         uint32_t pctype_num = 0;
16196         struct rte_pmd_i40e_ptype_info *pctype;
16197         uint32_t ptype_num = 0;
16198         struct rte_pmd_i40e_ptype_info *ptype;
16199         uint8_t proto_id;
16200
16201 #endif
16202
16203         pkg = open_file(res->filepath, &pkg_size);
16204         if (!pkg)
16205                 return;
16206
16207 #ifdef RTE_LIBRTE_I40E_PMD
16208         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16209                                 (uint8_t *)&info, sizeof(info),
16210                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16211         if (!ret) {
16212                 printf("Global Track id:       0x%x\n", info.track_id);
16213                 printf("Global Version:        %d.%d.%d.%d\n",
16214                         info.version.major,
16215                         info.version.minor,
16216                         info.version.update,
16217                         info.version.draft);
16218                 printf("Global Package name:   %s\n\n", info.name);
16219         }
16220
16221         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16222                                 (uint8_t *)&info, sizeof(info),
16223                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16224         if (!ret) {
16225                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16226                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16227                         info.version.major,
16228                         info.version.minor,
16229                         info.version.update,
16230                         info.version.draft);
16231                 printf("i40e Profile name:     %s\n\n", info.name);
16232         }
16233
16234         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16235                                 (uint8_t *)&buff_size, sizeof(buff_size),
16236                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16237         if (!ret && buff_size) {
16238                 buff = (uint8_t *)malloc(buff_size);
16239                 if (buff) {
16240                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16241                                                 buff, buff_size,
16242                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16243                         if (!ret)
16244                                 printf("Package Notes:\n%s\n\n", buff);
16245                         free(buff);
16246                 }
16247         }
16248
16249         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16250                                 (uint8_t *)&dev_num, sizeof(dev_num),
16251                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16252         if (!ret && dev_num) {
16253                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16254                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16255                 if (devs) {
16256                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16257                                                 (uint8_t *)devs, buff_size,
16258                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16259                         if (!ret) {
16260                                 printf("List of supported devices:\n");
16261                                 for (i = 0; i < dev_num; i++) {
16262                                         printf("  %04X:%04X %04X:%04X\n",
16263                                                 devs[i].vendor_dev_id >> 16,
16264                                                 devs[i].vendor_dev_id & 0xFFFF,
16265                                                 devs[i].sub_vendor_dev_id >> 16,
16266                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16267                                 }
16268                                 printf("\n");
16269                         }
16270                         free(devs);
16271                 }
16272         }
16273
16274         /* get information about protocols and packet types */
16275         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16276                 (uint8_t *)&proto_num, sizeof(proto_num),
16277                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16278         if (ret || !proto_num)
16279                 goto no_print_return;
16280
16281         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16282         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16283         if (!proto)
16284                 goto no_print_return;
16285
16286         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16287                                         buff_size,
16288                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16289         if (!ret) {
16290                 printf("List of used protocols:\n");
16291                 for (i = 0; i < proto_num; i++)
16292                         printf("  %2u: %s\n", proto[i].proto_id,
16293                                proto[i].name);
16294                 printf("\n");
16295         }
16296         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16297                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16298                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16299         if (ret || !pctype_num)
16300                 goto no_print_pctypes;
16301
16302         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16303         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16304         if (!pctype)
16305                 goto no_print_pctypes;
16306
16307         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16308                                         buff_size,
16309                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16310         if (ret) {
16311                 free(pctype);
16312                 goto no_print_pctypes;
16313         }
16314
16315         printf("List of defined packet classification types:\n");
16316         for (i = 0; i < pctype_num; i++) {
16317                 printf("  %2u:", pctype[i].ptype_id);
16318                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16319                         proto_id = pctype[i].protocols[j];
16320                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16321                                 for (n = 0; n < proto_num; n++) {
16322                                         if (proto[n].proto_id == proto_id) {
16323                                                 printf(" %s", proto[n].name);
16324                                                 break;
16325                                         }
16326                                 }
16327                         }
16328                 }
16329                 printf("\n");
16330         }
16331         printf("\n");
16332         free(pctype);
16333
16334 no_print_pctypes:
16335
16336         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16337                                         sizeof(ptype_num),
16338                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16339         if (ret || !ptype_num)
16340                 goto no_print_return;
16341
16342         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16343         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16344         if (!ptype)
16345                 goto no_print_return;
16346
16347         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16348                                         buff_size,
16349                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16350         if (ret) {
16351                 free(ptype);
16352                 goto no_print_return;
16353         }
16354         printf("List of defined packet types:\n");
16355         for (i = 0; i < ptype_num; i++) {
16356                 printf("  %2u:", ptype[i].ptype_id);
16357                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16358                         proto_id = ptype[i].protocols[j];
16359                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16360                                 for (n = 0; n < proto_num; n++) {
16361                                         if (proto[n].proto_id == proto_id) {
16362                                                 printf(" %s", proto[n].name);
16363                                                 break;
16364                                         }
16365                                 }
16366                         }
16367                 }
16368                 printf("\n");
16369         }
16370         free(ptype);
16371         printf("\n");
16372
16373         ret = 0;
16374 no_print_return:
16375         if (proto)
16376                 free(proto);
16377 #endif
16378         if (ret == -ENOTSUP)
16379                 printf("Function not supported in PMD driver\n");
16380         close_file(pkg);
16381 }
16382
16383 cmdline_parse_inst_t cmd_ddp_get_info = {
16384         .f = cmd_ddp_info_parsed,
16385         .data = NULL,
16386         .help_str = "ddp get info <profile_path>",
16387         .tokens = {
16388                 (void *)&cmd_ddp_info_ddp,
16389                 (void *)&cmd_ddp_info_get,
16390                 (void *)&cmd_ddp_info_info,
16391                 (void *)&cmd_ddp_info_filepath,
16392                 NULL,
16393         },
16394 };
16395
16396 /* Get dynamic device personalization profile info list*/
16397 #define PROFILE_INFO_SIZE 48
16398 #define MAX_PROFILE_NUM 16
16399
16400 struct cmd_ddp_get_list_result {
16401         cmdline_fixed_string_t ddp;
16402         cmdline_fixed_string_t get;
16403         cmdline_fixed_string_t list;
16404         portid_t port_id;
16405 };
16406
16407 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16408         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16409 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16410         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16411 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16412         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16413 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16414         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16415
16416 static void
16417 cmd_ddp_get_list_parsed(
16418         __attribute__((unused)) void *parsed_result,
16419         __attribute__((unused)) struct cmdline *cl,
16420         __attribute__((unused)) void *data)
16421 {
16422 #ifdef RTE_LIBRTE_I40E_PMD
16423         struct cmd_ddp_get_list_result *res = parsed_result;
16424         struct rte_pmd_i40e_profile_list *p_list;
16425         struct rte_pmd_i40e_profile_info *p_info;
16426         uint32_t p_num;
16427         uint32_t size;
16428         uint32_t i;
16429 #endif
16430         int ret = -ENOTSUP;
16431
16432 #ifdef RTE_LIBRTE_I40E_PMD
16433         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16434         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16435         if (!p_list)
16436                 printf("%s: Failed to malloc buffer\n", __func__);
16437
16438         if (ret == -ENOTSUP)
16439                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16440                                                 (uint8_t *)p_list, size);
16441
16442         if (!ret) {
16443                 p_num = p_list->p_count;
16444                 printf("Profile number is: %d\n\n", p_num);
16445
16446                 for (i = 0; i < p_num; i++) {
16447                         p_info = &p_list->p_info[i];
16448                         printf("Profile %d:\n", i);
16449                         printf("Track id:     0x%x\n", p_info->track_id);
16450                         printf("Version:      %d.%d.%d.%d\n",
16451                                p_info->version.major,
16452                                p_info->version.minor,
16453                                p_info->version.update,
16454                                p_info->version.draft);
16455                         printf("Profile name: %s\n\n", p_info->name);
16456                 }
16457         }
16458
16459         free(p_list);
16460 #endif
16461
16462         if (ret < 0)
16463                 printf("Failed to get ddp list\n");
16464 }
16465
16466 cmdline_parse_inst_t cmd_ddp_get_list = {
16467         .f = cmd_ddp_get_list_parsed,
16468         .data = NULL,
16469         .help_str = "ddp get list <port_id>",
16470         .tokens = {
16471                 (void *)&cmd_ddp_get_list_ddp,
16472                 (void *)&cmd_ddp_get_list_get,
16473                 (void *)&cmd_ddp_get_list_list,
16474                 (void *)&cmd_ddp_get_list_port_id,
16475                 NULL,
16476         },
16477 };
16478
16479 /* Configure input set */
16480 struct cmd_cfg_input_set_result {
16481         cmdline_fixed_string_t port;
16482         cmdline_fixed_string_t cfg;
16483         portid_t port_id;
16484         cmdline_fixed_string_t pctype;
16485         uint8_t pctype_id;
16486         cmdline_fixed_string_t inset_type;
16487         cmdline_fixed_string_t opt;
16488         cmdline_fixed_string_t field;
16489         uint8_t field_idx;
16490 };
16491
16492 static void
16493 cmd_cfg_input_set_parsed(
16494         __attribute__((unused)) void *parsed_result,
16495         __attribute__((unused)) struct cmdline *cl,
16496         __attribute__((unused)) void *data)
16497 {
16498 #ifdef RTE_LIBRTE_I40E_PMD
16499         struct cmd_cfg_input_set_result *res = parsed_result;
16500         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16501         struct rte_pmd_i40e_inset inset;
16502 #endif
16503         int ret = -ENOTSUP;
16504
16505         if (!all_ports_stopped()) {
16506                 printf("Please stop all ports first\n");
16507                 return;
16508         }
16509
16510 #ifdef RTE_LIBRTE_I40E_PMD
16511         if (!strcmp(res->inset_type, "hash_inset"))
16512                 inset_type = INSET_HASH;
16513         else if (!strcmp(res->inset_type, "fdir_inset"))
16514                 inset_type = INSET_FDIR;
16515         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16516                 inset_type = INSET_FDIR_FLX;
16517         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16518                                      &inset, inset_type);
16519         if (ret) {
16520                 printf("Failed to get input set.\n");
16521                 return;
16522         }
16523
16524         if (!strcmp(res->opt, "get")) {
16525                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16526                                                    res->field_idx);
16527                 if (ret)
16528                         printf("Field index %d is enabled.\n", res->field_idx);
16529                 else
16530                         printf("Field index %d is disabled.\n", res->field_idx);
16531                 return;
16532         } else if (!strcmp(res->opt, "set"))
16533                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16534                                                    res->field_idx);
16535         else if (!strcmp(res->opt, "clear"))
16536                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16537                                                      res->field_idx);
16538         if (ret) {
16539                 printf("Failed to configure input set field.\n");
16540                 return;
16541         }
16542
16543         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16544                                      &inset, inset_type);
16545         if (ret) {
16546                 printf("Failed to set input set.\n");
16547                 return;
16548         }
16549 #endif
16550
16551         if (ret == -ENOTSUP)
16552                 printf("Function not supported\n");
16553 }
16554
16555 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16556         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16557                                  port, "port");
16558 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16559         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16560                                  cfg, "config");
16561 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16562         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16563                               port_id, UINT16);
16564 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16565         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16566                                  pctype, "pctype");
16567 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16568         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16569                               pctype_id, UINT8);
16570 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16571         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16572                                  inset_type,
16573                                  "hash_inset#fdir_inset#fdir_flx_inset");
16574 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16575         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16576                                  opt, "get#set#clear");
16577 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16578         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16579                                  field, "field");
16580 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16581         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16582                               field_idx, UINT8);
16583
16584 cmdline_parse_inst_t cmd_cfg_input_set = {
16585         .f = cmd_cfg_input_set_parsed,
16586         .data = NULL,
16587         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16588                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16589         .tokens = {
16590                 (void *)&cmd_cfg_input_set_port,
16591                 (void *)&cmd_cfg_input_set_cfg,
16592                 (void *)&cmd_cfg_input_set_port_id,
16593                 (void *)&cmd_cfg_input_set_pctype,
16594                 (void *)&cmd_cfg_input_set_pctype_id,
16595                 (void *)&cmd_cfg_input_set_inset_type,
16596                 (void *)&cmd_cfg_input_set_opt,
16597                 (void *)&cmd_cfg_input_set_field,
16598                 (void *)&cmd_cfg_input_set_field_idx,
16599                 NULL,
16600         },
16601 };
16602
16603 /* Clear input set */
16604 struct cmd_clear_input_set_result {
16605         cmdline_fixed_string_t port;
16606         cmdline_fixed_string_t cfg;
16607         portid_t port_id;
16608         cmdline_fixed_string_t pctype;
16609         uint8_t pctype_id;
16610         cmdline_fixed_string_t inset_type;
16611         cmdline_fixed_string_t clear;
16612         cmdline_fixed_string_t all;
16613 };
16614
16615 static void
16616 cmd_clear_input_set_parsed(
16617         __attribute__((unused)) void *parsed_result,
16618         __attribute__((unused)) struct cmdline *cl,
16619         __attribute__((unused)) void *data)
16620 {
16621 #ifdef RTE_LIBRTE_I40E_PMD
16622         struct cmd_clear_input_set_result *res = parsed_result;
16623         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16624         struct rte_pmd_i40e_inset inset;
16625 #endif
16626         int ret = -ENOTSUP;
16627
16628         if (!all_ports_stopped()) {
16629                 printf("Please stop all ports first\n");
16630                 return;
16631         }
16632
16633 #ifdef RTE_LIBRTE_I40E_PMD
16634         if (!strcmp(res->inset_type, "hash_inset"))
16635                 inset_type = INSET_HASH;
16636         else if (!strcmp(res->inset_type, "fdir_inset"))
16637                 inset_type = INSET_FDIR;
16638         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16639                 inset_type = INSET_FDIR_FLX;
16640
16641         memset(&inset, 0, sizeof(inset));
16642
16643         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16644                                      &inset, inset_type);
16645         if (ret) {
16646                 printf("Failed to clear input set.\n");
16647                 return;
16648         }
16649
16650 #endif
16651
16652         if (ret == -ENOTSUP)
16653                 printf("Function not supported\n");
16654 }
16655
16656 cmdline_parse_token_string_t cmd_clear_input_set_port =
16657         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16658                                  port, "port");
16659 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16660         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16661                                  cfg, "config");
16662 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16663         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16664                               port_id, UINT16);
16665 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16666         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16667                                  pctype, "pctype");
16668 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16669         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16670                               pctype_id, UINT8);
16671 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16672         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16673                                  inset_type,
16674                                  "hash_inset#fdir_inset#fdir_flx_inset");
16675 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16676         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16677                                  clear, "clear");
16678 cmdline_parse_token_string_t cmd_clear_input_set_all =
16679         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16680                                  all, "all");
16681
16682 cmdline_parse_inst_t cmd_clear_input_set = {
16683         .f = cmd_clear_input_set_parsed,
16684         .data = NULL,
16685         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16686                     "fdir_inset|fdir_flx_inset clear all",
16687         .tokens = {
16688                 (void *)&cmd_clear_input_set_port,
16689                 (void *)&cmd_clear_input_set_cfg,
16690                 (void *)&cmd_clear_input_set_port_id,
16691                 (void *)&cmd_clear_input_set_pctype,
16692                 (void *)&cmd_clear_input_set_pctype_id,
16693                 (void *)&cmd_clear_input_set_inset_type,
16694                 (void *)&cmd_clear_input_set_clear,
16695                 (void *)&cmd_clear_input_set_all,
16696                 NULL,
16697         },
16698 };
16699
16700 /* show vf stats */
16701
16702 /* Common result structure for show vf stats */
16703 struct cmd_show_vf_stats_result {
16704         cmdline_fixed_string_t show;
16705         cmdline_fixed_string_t vf;
16706         cmdline_fixed_string_t stats;
16707         portid_t port_id;
16708         uint16_t vf_id;
16709 };
16710
16711 /* Common CLI fields show vf stats*/
16712 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16713         TOKEN_STRING_INITIALIZER
16714                 (struct cmd_show_vf_stats_result,
16715                  show, "show");
16716 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16717         TOKEN_STRING_INITIALIZER
16718                 (struct cmd_show_vf_stats_result,
16719                  vf, "vf");
16720 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16721         TOKEN_STRING_INITIALIZER
16722                 (struct cmd_show_vf_stats_result,
16723                  stats, "stats");
16724 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16725         TOKEN_NUM_INITIALIZER
16726                 (struct cmd_show_vf_stats_result,
16727                  port_id, UINT16);
16728 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16729         TOKEN_NUM_INITIALIZER
16730                 (struct cmd_show_vf_stats_result,
16731                  vf_id, UINT16);
16732
16733 static void
16734 cmd_show_vf_stats_parsed(
16735         void *parsed_result,
16736         __attribute__((unused)) struct cmdline *cl,
16737         __attribute__((unused)) void *data)
16738 {
16739         struct cmd_show_vf_stats_result *res = parsed_result;
16740         struct rte_eth_stats stats;
16741         int ret = -ENOTSUP;
16742         static const char *nic_stats_border = "########################";
16743
16744         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16745                 return;
16746
16747         memset(&stats, 0, sizeof(stats));
16748
16749 #ifdef RTE_LIBRTE_I40E_PMD
16750         if (ret == -ENOTSUP)
16751                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16752                                                 res->vf_id,
16753                                                 &stats);
16754 #endif
16755 #ifdef RTE_LIBRTE_BNXT_PMD
16756         if (ret == -ENOTSUP)
16757                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16758                                                 res->vf_id,
16759                                                 &stats);
16760 #endif
16761
16762         switch (ret) {
16763         case 0:
16764                 break;
16765         case -EINVAL:
16766                 printf("invalid vf_id %d\n", res->vf_id);
16767                 break;
16768         case -ENODEV:
16769                 printf("invalid port_id %d\n", res->port_id);
16770                 break;
16771         case -ENOTSUP:
16772                 printf("function not implemented\n");
16773                 break;
16774         default:
16775                 printf("programming error: (%s)\n", strerror(-ret));
16776         }
16777
16778         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
16779                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
16780
16781         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
16782                "%-"PRIu64"\n",
16783                stats.ipackets, stats.imissed, stats.ibytes);
16784         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
16785         printf("  RX-nombuf:  %-10"PRIu64"\n",
16786                stats.rx_nombuf);
16787         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
16788                "%-"PRIu64"\n",
16789                stats.opackets, stats.oerrors, stats.obytes);
16790
16791         printf("  %s############################%s\n",
16792                                nic_stats_border, nic_stats_border);
16793 }
16794
16795 cmdline_parse_inst_t cmd_show_vf_stats = {
16796         .f = cmd_show_vf_stats_parsed,
16797         .data = NULL,
16798         .help_str = "show vf stats <port_id> <vf_id>",
16799         .tokens = {
16800                 (void *)&cmd_show_vf_stats_show,
16801                 (void *)&cmd_show_vf_stats_vf,
16802                 (void *)&cmd_show_vf_stats_stats,
16803                 (void *)&cmd_show_vf_stats_port_id,
16804                 (void *)&cmd_show_vf_stats_vf_id,
16805                 NULL,
16806         },
16807 };
16808
16809 /* clear vf stats */
16810
16811 /* Common result structure for clear vf stats */
16812 struct cmd_clear_vf_stats_result {
16813         cmdline_fixed_string_t clear;
16814         cmdline_fixed_string_t vf;
16815         cmdline_fixed_string_t stats;
16816         portid_t port_id;
16817         uint16_t vf_id;
16818 };
16819
16820 /* Common CLI fields clear vf stats*/
16821 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
16822         TOKEN_STRING_INITIALIZER
16823                 (struct cmd_clear_vf_stats_result,
16824                  clear, "clear");
16825 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
16826         TOKEN_STRING_INITIALIZER
16827                 (struct cmd_clear_vf_stats_result,
16828                  vf, "vf");
16829 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
16830         TOKEN_STRING_INITIALIZER
16831                 (struct cmd_clear_vf_stats_result,
16832                  stats, "stats");
16833 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
16834         TOKEN_NUM_INITIALIZER
16835                 (struct cmd_clear_vf_stats_result,
16836                  port_id, UINT16);
16837 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
16838         TOKEN_NUM_INITIALIZER
16839                 (struct cmd_clear_vf_stats_result,
16840                  vf_id, UINT16);
16841
16842 static void
16843 cmd_clear_vf_stats_parsed(
16844         void *parsed_result,
16845         __attribute__((unused)) struct cmdline *cl,
16846         __attribute__((unused)) void *data)
16847 {
16848         struct cmd_clear_vf_stats_result *res = parsed_result;
16849         int ret = -ENOTSUP;
16850
16851         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16852                 return;
16853
16854 #ifdef RTE_LIBRTE_I40E_PMD
16855         if (ret == -ENOTSUP)
16856                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
16857                                                   res->vf_id);
16858 #endif
16859 #ifdef RTE_LIBRTE_BNXT_PMD
16860         if (ret == -ENOTSUP)
16861                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
16862                                                   res->vf_id);
16863 #endif
16864
16865         switch (ret) {
16866         case 0:
16867                 break;
16868         case -EINVAL:
16869                 printf("invalid vf_id %d\n", res->vf_id);
16870                 break;
16871         case -ENODEV:
16872                 printf("invalid port_id %d\n", res->port_id);
16873                 break;
16874         case -ENOTSUP:
16875                 printf("function not implemented\n");
16876                 break;
16877         default:
16878                 printf("programming error: (%s)\n", strerror(-ret));
16879         }
16880 }
16881
16882 cmdline_parse_inst_t cmd_clear_vf_stats = {
16883         .f = cmd_clear_vf_stats_parsed,
16884         .data = NULL,
16885         .help_str = "clear vf stats <port_id> <vf_id>",
16886         .tokens = {
16887                 (void *)&cmd_clear_vf_stats_clear,
16888                 (void *)&cmd_clear_vf_stats_vf,
16889                 (void *)&cmd_clear_vf_stats_stats,
16890                 (void *)&cmd_clear_vf_stats_port_id,
16891                 (void *)&cmd_clear_vf_stats_vf_id,
16892                 NULL,
16893         },
16894 };
16895
16896 /* port config pctype mapping reset */
16897
16898 /* Common result structure for port config pctype mapping reset */
16899 struct cmd_pctype_mapping_reset_result {
16900         cmdline_fixed_string_t port;
16901         cmdline_fixed_string_t config;
16902         portid_t port_id;
16903         cmdline_fixed_string_t pctype;
16904         cmdline_fixed_string_t mapping;
16905         cmdline_fixed_string_t reset;
16906 };
16907
16908 /* Common CLI fields for port config pctype mapping reset*/
16909 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
16910         TOKEN_STRING_INITIALIZER
16911                 (struct cmd_pctype_mapping_reset_result,
16912                  port, "port");
16913 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
16914         TOKEN_STRING_INITIALIZER
16915                 (struct cmd_pctype_mapping_reset_result,
16916                  config, "config");
16917 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
16918         TOKEN_NUM_INITIALIZER
16919                 (struct cmd_pctype_mapping_reset_result,
16920                  port_id, UINT16);
16921 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
16922         TOKEN_STRING_INITIALIZER
16923                 (struct cmd_pctype_mapping_reset_result,
16924                  pctype, "pctype");
16925 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
16926         TOKEN_STRING_INITIALIZER
16927                 (struct cmd_pctype_mapping_reset_result,
16928                  mapping, "mapping");
16929 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
16930         TOKEN_STRING_INITIALIZER
16931                 (struct cmd_pctype_mapping_reset_result,
16932                  reset, "reset");
16933
16934 static void
16935 cmd_pctype_mapping_reset_parsed(
16936         void *parsed_result,
16937         __attribute__((unused)) struct cmdline *cl,
16938         __attribute__((unused)) void *data)
16939 {
16940         struct cmd_pctype_mapping_reset_result *res = parsed_result;
16941         int ret = -ENOTSUP;
16942
16943         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16944                 return;
16945
16946 #ifdef RTE_LIBRTE_I40E_PMD
16947         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
16948 #endif
16949
16950         switch (ret) {
16951         case 0:
16952                 break;
16953         case -ENODEV:
16954                 printf("invalid port_id %d\n", res->port_id);
16955                 break;
16956         case -ENOTSUP:
16957                 printf("function not implemented\n");
16958                 break;
16959         default:
16960                 printf("programming error: (%s)\n", strerror(-ret));
16961         }
16962 }
16963
16964 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
16965         .f = cmd_pctype_mapping_reset_parsed,
16966         .data = NULL,
16967         .help_str = "port config <port_id> pctype mapping reset",
16968         .tokens = {
16969                 (void *)&cmd_pctype_mapping_reset_port,
16970                 (void *)&cmd_pctype_mapping_reset_config,
16971                 (void *)&cmd_pctype_mapping_reset_port_id,
16972                 (void *)&cmd_pctype_mapping_reset_pctype,
16973                 (void *)&cmd_pctype_mapping_reset_mapping,
16974                 (void *)&cmd_pctype_mapping_reset_reset,
16975                 NULL,
16976         },
16977 };
16978
16979 /* show port pctype mapping */
16980
16981 /* Common result structure for show port pctype mapping */
16982 struct cmd_pctype_mapping_get_result {
16983         cmdline_fixed_string_t show;
16984         cmdline_fixed_string_t port;
16985         portid_t port_id;
16986         cmdline_fixed_string_t pctype;
16987         cmdline_fixed_string_t mapping;
16988 };
16989
16990 /* Common CLI fields for pctype mapping get */
16991 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
16992         TOKEN_STRING_INITIALIZER
16993                 (struct cmd_pctype_mapping_get_result,
16994                  show, "show");
16995 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
16996         TOKEN_STRING_INITIALIZER
16997                 (struct cmd_pctype_mapping_get_result,
16998                  port, "port");
16999 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17000         TOKEN_NUM_INITIALIZER
17001                 (struct cmd_pctype_mapping_get_result,
17002                  port_id, UINT16);
17003 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17004         TOKEN_STRING_INITIALIZER
17005                 (struct cmd_pctype_mapping_get_result,
17006                  pctype, "pctype");
17007 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17008         TOKEN_STRING_INITIALIZER
17009                 (struct cmd_pctype_mapping_get_result,
17010                  mapping, "mapping");
17011
17012 static void
17013 cmd_pctype_mapping_get_parsed(
17014         void *parsed_result,
17015         __attribute__((unused)) struct cmdline *cl,
17016         __attribute__((unused)) void *data)
17017 {
17018         struct cmd_pctype_mapping_get_result *res = parsed_result;
17019         int ret = -ENOTSUP;
17020 #ifdef RTE_LIBRTE_I40E_PMD
17021         struct rte_pmd_i40e_flow_type_mapping
17022                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17023         int i, j, first_pctype;
17024 #endif
17025
17026         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17027                 return;
17028
17029 #ifdef RTE_LIBRTE_I40E_PMD
17030         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17031 #endif
17032
17033         switch (ret) {
17034         case 0:
17035                 break;
17036         case -ENODEV:
17037                 printf("invalid port_id %d\n", res->port_id);
17038                 return;
17039         case -ENOTSUP:
17040                 printf("function not implemented\n");
17041                 return;
17042         default:
17043                 printf("programming error: (%s)\n", strerror(-ret));
17044                 return;
17045         }
17046
17047 #ifdef RTE_LIBRTE_I40E_PMD
17048         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17049                 if (mapping[i].pctype != 0ULL) {
17050                         first_pctype = 1;
17051
17052                         printf("pctype: ");
17053                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17054                                 if (mapping[i].pctype & (1ULL << j)) {
17055                                         printf(first_pctype ?
17056                                                "%02d" : ",%02d", j);
17057                                         first_pctype = 0;
17058                                 }
17059                         }
17060                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17061                 }
17062         }
17063 #endif
17064 }
17065
17066 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17067         .f = cmd_pctype_mapping_get_parsed,
17068         .data = NULL,
17069         .help_str = "show port <port_id> pctype mapping",
17070         .tokens = {
17071                 (void *)&cmd_pctype_mapping_get_show,
17072                 (void *)&cmd_pctype_mapping_get_port,
17073                 (void *)&cmd_pctype_mapping_get_port_id,
17074                 (void *)&cmd_pctype_mapping_get_pctype,
17075                 (void *)&cmd_pctype_mapping_get_mapping,
17076                 NULL,
17077         },
17078 };
17079
17080 /* port config pctype mapping update */
17081
17082 /* Common result structure for port config pctype mapping update */
17083 struct cmd_pctype_mapping_update_result {
17084         cmdline_fixed_string_t port;
17085         cmdline_fixed_string_t config;
17086         portid_t port_id;
17087         cmdline_fixed_string_t pctype;
17088         cmdline_fixed_string_t mapping;
17089         cmdline_fixed_string_t update;
17090         cmdline_fixed_string_t pctype_list;
17091         uint16_t flow_type;
17092 };
17093
17094 /* Common CLI fields for pctype mapping update*/
17095 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17096         TOKEN_STRING_INITIALIZER
17097                 (struct cmd_pctype_mapping_update_result,
17098                  port, "port");
17099 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17100         TOKEN_STRING_INITIALIZER
17101                 (struct cmd_pctype_mapping_update_result,
17102                  config, "config");
17103 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17104         TOKEN_NUM_INITIALIZER
17105                 (struct cmd_pctype_mapping_update_result,
17106                  port_id, UINT16);
17107 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17108         TOKEN_STRING_INITIALIZER
17109                 (struct cmd_pctype_mapping_update_result,
17110                  pctype, "pctype");
17111 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17112         TOKEN_STRING_INITIALIZER
17113                 (struct cmd_pctype_mapping_update_result,
17114                  mapping, "mapping");
17115 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17116         TOKEN_STRING_INITIALIZER
17117                 (struct cmd_pctype_mapping_update_result,
17118                  update, "update");
17119 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17120         TOKEN_STRING_INITIALIZER
17121                 (struct cmd_pctype_mapping_update_result,
17122                  pctype_list, NULL);
17123 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17124         TOKEN_NUM_INITIALIZER
17125                 (struct cmd_pctype_mapping_update_result,
17126                  flow_type, UINT16);
17127
17128 static void
17129 cmd_pctype_mapping_update_parsed(
17130         void *parsed_result,
17131         __attribute__((unused)) struct cmdline *cl,
17132         __attribute__((unused)) void *data)
17133 {
17134         struct cmd_pctype_mapping_update_result *res = parsed_result;
17135         int ret = -ENOTSUP;
17136 #ifdef RTE_LIBRTE_I40E_PMD
17137         struct rte_pmd_i40e_flow_type_mapping mapping;
17138         unsigned int i;
17139         unsigned int nb_item;
17140         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17141 #endif
17142
17143         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17144                 return;
17145
17146 #ifdef RTE_LIBRTE_I40E_PMD
17147         nb_item = parse_item_list(res->pctype_list, "pctypes",
17148                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17149         mapping.flow_type = res->flow_type;
17150         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17151                 mapping.pctype |= (1ULL << pctype_list[i]);
17152         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17153                                                 &mapping,
17154                                                 1,
17155                                                 0);
17156 #endif
17157
17158         switch (ret) {
17159         case 0:
17160                 break;
17161         case -EINVAL:
17162                 printf("invalid pctype or flow type\n");
17163                 break;
17164         case -ENODEV:
17165                 printf("invalid port_id %d\n", res->port_id);
17166                 break;
17167         case -ENOTSUP:
17168                 printf("function not implemented\n");
17169                 break;
17170         default:
17171                 printf("programming error: (%s)\n", strerror(-ret));
17172         }
17173 }
17174
17175 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17176         .f = cmd_pctype_mapping_update_parsed,
17177         .data = NULL,
17178         .help_str = "port config <port_id> pctype mapping update"
17179         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17180         .tokens = {
17181                 (void *)&cmd_pctype_mapping_update_port,
17182                 (void *)&cmd_pctype_mapping_update_config,
17183                 (void *)&cmd_pctype_mapping_update_port_id,
17184                 (void *)&cmd_pctype_mapping_update_pctype,
17185                 (void *)&cmd_pctype_mapping_update_mapping,
17186                 (void *)&cmd_pctype_mapping_update_update,
17187                 (void *)&cmd_pctype_mapping_update_pc_type,
17188                 (void *)&cmd_pctype_mapping_update_flow_type,
17189                 NULL,
17190         },
17191 };
17192
17193 /* ptype mapping get */
17194
17195 /* Common result structure for ptype mapping get */
17196 struct cmd_ptype_mapping_get_result {
17197         cmdline_fixed_string_t ptype;
17198         cmdline_fixed_string_t mapping;
17199         cmdline_fixed_string_t get;
17200         portid_t port_id;
17201         uint8_t valid_only;
17202 };
17203
17204 /* Common CLI fields for ptype mapping get */
17205 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17206         TOKEN_STRING_INITIALIZER
17207                 (struct cmd_ptype_mapping_get_result,
17208                  ptype, "ptype");
17209 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17210         TOKEN_STRING_INITIALIZER
17211                 (struct cmd_ptype_mapping_get_result,
17212                  mapping, "mapping");
17213 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17214         TOKEN_STRING_INITIALIZER
17215                 (struct cmd_ptype_mapping_get_result,
17216                  get, "get");
17217 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17218         TOKEN_NUM_INITIALIZER
17219                 (struct cmd_ptype_mapping_get_result,
17220                  port_id, UINT16);
17221 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17222         TOKEN_NUM_INITIALIZER
17223                 (struct cmd_ptype_mapping_get_result,
17224                  valid_only, UINT8);
17225
17226 static void
17227 cmd_ptype_mapping_get_parsed(
17228         void *parsed_result,
17229         __attribute__((unused)) struct cmdline *cl,
17230         __attribute__((unused)) void *data)
17231 {
17232         struct cmd_ptype_mapping_get_result *res = parsed_result;
17233         int ret = -ENOTSUP;
17234 #ifdef RTE_LIBRTE_I40E_PMD
17235         int max_ptype_num = 256;
17236         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17237         uint16_t count;
17238         int i;
17239 #endif
17240
17241         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17242                 return;
17243
17244 #ifdef RTE_LIBRTE_I40E_PMD
17245         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17246                                         mapping,
17247                                         max_ptype_num,
17248                                         &count,
17249                                         res->valid_only);
17250 #endif
17251
17252         switch (ret) {
17253         case 0:
17254                 break;
17255         case -ENODEV:
17256                 printf("invalid port_id %d\n", res->port_id);
17257                 break;
17258         case -ENOTSUP:
17259                 printf("function not implemented\n");
17260                 break;
17261         default:
17262                 printf("programming error: (%s)\n", strerror(-ret));
17263         }
17264
17265 #ifdef RTE_LIBRTE_I40E_PMD
17266         if (!ret) {
17267                 for (i = 0; i < count; i++)
17268                         printf("%3d\t0x%08x\n",
17269                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17270         }
17271 #endif
17272 }
17273
17274 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17275         .f = cmd_ptype_mapping_get_parsed,
17276         .data = NULL,
17277         .help_str = "ptype mapping get <port_id> <valid_only>",
17278         .tokens = {
17279                 (void *)&cmd_ptype_mapping_get_ptype,
17280                 (void *)&cmd_ptype_mapping_get_mapping,
17281                 (void *)&cmd_ptype_mapping_get_get,
17282                 (void *)&cmd_ptype_mapping_get_port_id,
17283                 (void *)&cmd_ptype_mapping_get_valid_only,
17284                 NULL,
17285         },
17286 };
17287
17288 /* ptype mapping replace */
17289
17290 /* Common result structure for ptype mapping replace */
17291 struct cmd_ptype_mapping_replace_result {
17292         cmdline_fixed_string_t ptype;
17293         cmdline_fixed_string_t mapping;
17294         cmdline_fixed_string_t replace;
17295         portid_t port_id;
17296         uint32_t target;
17297         uint8_t mask;
17298         uint32_t pkt_type;
17299 };
17300
17301 /* Common CLI fields for ptype mapping replace */
17302 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17303         TOKEN_STRING_INITIALIZER
17304                 (struct cmd_ptype_mapping_replace_result,
17305                  ptype, "ptype");
17306 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17307         TOKEN_STRING_INITIALIZER
17308                 (struct cmd_ptype_mapping_replace_result,
17309                  mapping, "mapping");
17310 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17311         TOKEN_STRING_INITIALIZER
17312                 (struct cmd_ptype_mapping_replace_result,
17313                  replace, "replace");
17314 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17315         TOKEN_NUM_INITIALIZER
17316                 (struct cmd_ptype_mapping_replace_result,
17317                  port_id, UINT16);
17318 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17319         TOKEN_NUM_INITIALIZER
17320                 (struct cmd_ptype_mapping_replace_result,
17321                  target, UINT32);
17322 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17323         TOKEN_NUM_INITIALIZER
17324                 (struct cmd_ptype_mapping_replace_result,
17325                  mask, UINT8);
17326 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17327         TOKEN_NUM_INITIALIZER
17328                 (struct cmd_ptype_mapping_replace_result,
17329                  pkt_type, UINT32);
17330
17331 static void
17332 cmd_ptype_mapping_replace_parsed(
17333         void *parsed_result,
17334         __attribute__((unused)) struct cmdline *cl,
17335         __attribute__((unused)) void *data)
17336 {
17337         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17338         int ret = -ENOTSUP;
17339
17340         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17341                 return;
17342
17343 #ifdef RTE_LIBRTE_I40E_PMD
17344         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17345                                         res->target,
17346                                         res->mask,
17347                                         res->pkt_type);
17348 #endif
17349
17350         switch (ret) {
17351         case 0:
17352                 break;
17353         case -EINVAL:
17354                 printf("invalid ptype 0x%8x or 0x%8x\n",
17355                                 res->target, res->pkt_type);
17356                 break;
17357         case -ENODEV:
17358                 printf("invalid port_id %d\n", res->port_id);
17359                 break;
17360         case -ENOTSUP:
17361                 printf("function not implemented\n");
17362                 break;
17363         default:
17364                 printf("programming error: (%s)\n", strerror(-ret));
17365         }
17366 }
17367
17368 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17369         .f = cmd_ptype_mapping_replace_parsed,
17370         .data = NULL,
17371         .help_str =
17372                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17373         .tokens = {
17374                 (void *)&cmd_ptype_mapping_replace_ptype,
17375                 (void *)&cmd_ptype_mapping_replace_mapping,
17376                 (void *)&cmd_ptype_mapping_replace_replace,
17377                 (void *)&cmd_ptype_mapping_replace_port_id,
17378                 (void *)&cmd_ptype_mapping_replace_target,
17379                 (void *)&cmd_ptype_mapping_replace_mask,
17380                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17381                 NULL,
17382         },
17383 };
17384
17385 /* ptype mapping reset */
17386
17387 /* Common result structure for ptype mapping reset */
17388 struct cmd_ptype_mapping_reset_result {
17389         cmdline_fixed_string_t ptype;
17390         cmdline_fixed_string_t mapping;
17391         cmdline_fixed_string_t reset;
17392         portid_t port_id;
17393 };
17394
17395 /* Common CLI fields for ptype mapping reset*/
17396 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17397         TOKEN_STRING_INITIALIZER
17398                 (struct cmd_ptype_mapping_reset_result,
17399                  ptype, "ptype");
17400 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17401         TOKEN_STRING_INITIALIZER
17402                 (struct cmd_ptype_mapping_reset_result,
17403                  mapping, "mapping");
17404 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17405         TOKEN_STRING_INITIALIZER
17406                 (struct cmd_ptype_mapping_reset_result,
17407                  reset, "reset");
17408 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17409         TOKEN_NUM_INITIALIZER
17410                 (struct cmd_ptype_mapping_reset_result,
17411                  port_id, UINT16);
17412
17413 static void
17414 cmd_ptype_mapping_reset_parsed(
17415         void *parsed_result,
17416         __attribute__((unused)) struct cmdline *cl,
17417         __attribute__((unused)) void *data)
17418 {
17419         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17420         int ret = -ENOTSUP;
17421
17422         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17423                 return;
17424
17425 #ifdef RTE_LIBRTE_I40E_PMD
17426         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17427 #endif
17428
17429         switch (ret) {
17430         case 0:
17431                 break;
17432         case -ENODEV:
17433                 printf("invalid port_id %d\n", res->port_id);
17434                 break;
17435         case -ENOTSUP:
17436                 printf("function not implemented\n");
17437                 break;
17438         default:
17439                 printf("programming error: (%s)\n", strerror(-ret));
17440         }
17441 }
17442
17443 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17444         .f = cmd_ptype_mapping_reset_parsed,
17445         .data = NULL,
17446         .help_str = "ptype mapping reset <port_id>",
17447         .tokens = {
17448                 (void *)&cmd_ptype_mapping_reset_ptype,
17449                 (void *)&cmd_ptype_mapping_reset_mapping,
17450                 (void *)&cmd_ptype_mapping_reset_reset,
17451                 (void *)&cmd_ptype_mapping_reset_port_id,
17452                 NULL,
17453         },
17454 };
17455
17456 /* ptype mapping update */
17457
17458 /* Common result structure for ptype mapping update */
17459 struct cmd_ptype_mapping_update_result {
17460         cmdline_fixed_string_t ptype;
17461         cmdline_fixed_string_t mapping;
17462         cmdline_fixed_string_t reset;
17463         portid_t port_id;
17464         uint8_t hw_ptype;
17465         uint32_t sw_ptype;
17466 };
17467
17468 /* Common CLI fields for ptype mapping update*/
17469 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17470         TOKEN_STRING_INITIALIZER
17471                 (struct cmd_ptype_mapping_update_result,
17472                  ptype, "ptype");
17473 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17474         TOKEN_STRING_INITIALIZER
17475                 (struct cmd_ptype_mapping_update_result,
17476                  mapping, "mapping");
17477 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17478         TOKEN_STRING_INITIALIZER
17479                 (struct cmd_ptype_mapping_update_result,
17480                  reset, "update");
17481 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17482         TOKEN_NUM_INITIALIZER
17483                 (struct cmd_ptype_mapping_update_result,
17484                  port_id, UINT16);
17485 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17486         TOKEN_NUM_INITIALIZER
17487                 (struct cmd_ptype_mapping_update_result,
17488                  hw_ptype, UINT8);
17489 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17490         TOKEN_NUM_INITIALIZER
17491                 (struct cmd_ptype_mapping_update_result,
17492                  sw_ptype, UINT32);
17493
17494 static void
17495 cmd_ptype_mapping_update_parsed(
17496         void *parsed_result,
17497         __attribute__((unused)) struct cmdline *cl,
17498         __attribute__((unused)) void *data)
17499 {
17500         struct cmd_ptype_mapping_update_result *res = parsed_result;
17501         int ret = -ENOTSUP;
17502 #ifdef RTE_LIBRTE_I40E_PMD
17503         struct rte_pmd_i40e_ptype_mapping mapping;
17504 #endif
17505         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17506                 return;
17507
17508 #ifdef RTE_LIBRTE_I40E_PMD
17509         mapping.hw_ptype = res->hw_ptype;
17510         mapping.sw_ptype = res->sw_ptype;
17511         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17512                                                 &mapping,
17513                                                 1,
17514                                                 0);
17515 #endif
17516
17517         switch (ret) {
17518         case 0:
17519                 break;
17520         case -EINVAL:
17521                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17522                 break;
17523         case -ENODEV:
17524                 printf("invalid port_id %d\n", res->port_id);
17525                 break;
17526         case -ENOTSUP:
17527                 printf("function not implemented\n");
17528                 break;
17529         default:
17530                 printf("programming error: (%s)\n", strerror(-ret));
17531         }
17532 }
17533
17534 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17535         .f = cmd_ptype_mapping_update_parsed,
17536         .data = NULL,
17537         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17538         .tokens = {
17539                 (void *)&cmd_ptype_mapping_update_ptype,
17540                 (void *)&cmd_ptype_mapping_update_mapping,
17541                 (void *)&cmd_ptype_mapping_update_update,
17542                 (void *)&cmd_ptype_mapping_update_port_id,
17543                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17544                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17545                 NULL,
17546         },
17547 };
17548
17549 /* Common result structure for file commands */
17550 struct cmd_cmdfile_result {
17551         cmdline_fixed_string_t load;
17552         cmdline_fixed_string_t filename;
17553 };
17554
17555 /* Common CLI fields for file commands */
17556 cmdline_parse_token_string_t cmd_load_cmdfile =
17557         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17558 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17559         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17560
17561 static void
17562 cmd_load_from_file_parsed(
17563         void *parsed_result,
17564         __attribute__((unused)) struct cmdline *cl,
17565         __attribute__((unused)) void *data)
17566 {
17567         struct cmd_cmdfile_result *res = parsed_result;
17568
17569         cmdline_read_from_file(res->filename);
17570 }
17571
17572 cmdline_parse_inst_t cmd_load_from_file = {
17573         .f = cmd_load_from_file_parsed,
17574         .data = NULL,
17575         .help_str = "load <filename>",
17576         .tokens = {
17577                 (void *)&cmd_load_cmdfile,
17578                 (void *)&cmd_load_cmdfile_filename,
17579                 NULL,
17580         },
17581 };
17582
17583 /* Get Rx offloads capabilities */
17584 struct cmd_rx_offload_get_capa_result {
17585         cmdline_fixed_string_t show;
17586         cmdline_fixed_string_t port;
17587         portid_t port_id;
17588         cmdline_fixed_string_t rx_offload;
17589         cmdline_fixed_string_t capabilities;
17590 };
17591
17592 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17593         TOKEN_STRING_INITIALIZER
17594                 (struct cmd_rx_offload_get_capa_result,
17595                  show, "show");
17596 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17597         TOKEN_STRING_INITIALIZER
17598                 (struct cmd_rx_offload_get_capa_result,
17599                  port, "port");
17600 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17601         TOKEN_NUM_INITIALIZER
17602                 (struct cmd_rx_offload_get_capa_result,
17603                  port_id, UINT16);
17604 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17605         TOKEN_STRING_INITIALIZER
17606                 (struct cmd_rx_offload_get_capa_result,
17607                  rx_offload, "rx_offload");
17608 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17609         TOKEN_STRING_INITIALIZER
17610                 (struct cmd_rx_offload_get_capa_result,
17611                  capabilities, "capabilities");
17612
17613 static void
17614 print_rx_offloads(uint64_t offloads)
17615 {
17616         uint64_t single_offload;
17617         int begin;
17618         int end;
17619         int bit;
17620
17621         if (offloads == 0)
17622                 return;
17623
17624         begin = __builtin_ctzll(offloads);
17625         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17626
17627         single_offload = 1 << begin;
17628         for (bit = begin; bit < end; bit++) {
17629                 if (offloads & single_offload)
17630                         printf(" %s",
17631                                rte_eth_dev_rx_offload_name(single_offload));
17632                 single_offload <<= 1;
17633         }
17634 }
17635
17636 static void
17637 cmd_rx_offload_get_capa_parsed(
17638         void *parsed_result,
17639         __attribute__((unused)) struct cmdline *cl,
17640         __attribute__((unused)) void *data)
17641 {
17642         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17643         struct rte_eth_dev_info dev_info;
17644         portid_t port_id = res->port_id;
17645         uint64_t queue_offloads;
17646         uint64_t port_offloads;
17647
17648         rte_eth_dev_info_get(port_id, &dev_info);
17649         queue_offloads = dev_info.rx_queue_offload_capa;
17650         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17651
17652         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17653         printf("  Per Queue :");
17654         print_rx_offloads(queue_offloads);
17655
17656         printf("\n");
17657         printf("  Per Port  :");
17658         print_rx_offloads(port_offloads);
17659         printf("\n\n");
17660 }
17661
17662 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17663         .f = cmd_rx_offload_get_capa_parsed,
17664         .data = NULL,
17665         .help_str = "show port <port_id> rx_offload capabilities",
17666         .tokens = {
17667                 (void *)&cmd_rx_offload_get_capa_show,
17668                 (void *)&cmd_rx_offload_get_capa_port,
17669                 (void *)&cmd_rx_offload_get_capa_port_id,
17670                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17671                 (void *)&cmd_rx_offload_get_capa_capabilities,
17672                 NULL,
17673         }
17674 };
17675
17676 /* Get Rx offloads configuration */
17677 struct cmd_rx_offload_get_configuration_result {
17678         cmdline_fixed_string_t show;
17679         cmdline_fixed_string_t port;
17680         portid_t port_id;
17681         cmdline_fixed_string_t rx_offload;
17682         cmdline_fixed_string_t configuration;
17683 };
17684
17685 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17686         TOKEN_STRING_INITIALIZER
17687                 (struct cmd_rx_offload_get_configuration_result,
17688                  show, "show");
17689 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17690         TOKEN_STRING_INITIALIZER
17691                 (struct cmd_rx_offload_get_configuration_result,
17692                  port, "port");
17693 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17694         TOKEN_NUM_INITIALIZER
17695                 (struct cmd_rx_offload_get_configuration_result,
17696                  port_id, UINT16);
17697 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17698         TOKEN_STRING_INITIALIZER
17699                 (struct cmd_rx_offload_get_configuration_result,
17700                  rx_offload, "rx_offload");
17701 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17702         TOKEN_STRING_INITIALIZER
17703                 (struct cmd_rx_offload_get_configuration_result,
17704                  configuration, "configuration");
17705
17706 static void
17707 cmd_rx_offload_get_configuration_parsed(
17708         void *parsed_result,
17709         __attribute__((unused)) struct cmdline *cl,
17710         __attribute__((unused)) void *data)
17711 {
17712         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17713         struct rte_eth_dev_info dev_info;
17714         portid_t port_id = res->port_id;
17715         struct rte_port *port = &ports[port_id];
17716         uint64_t port_offloads;
17717         uint64_t queue_offloads;
17718         uint16_t nb_rx_queues;
17719         int q;
17720
17721         printf("Rx Offloading Configuration of port %d :\n", port_id);
17722
17723         port_offloads = port->dev_conf.rxmode.offloads;
17724         printf("  Port :");
17725         print_rx_offloads(port_offloads);
17726         printf("\n");
17727
17728         rte_eth_dev_info_get(port_id, &dev_info);
17729         nb_rx_queues = dev_info.nb_rx_queues;
17730         for (q = 0; q < nb_rx_queues; q++) {
17731                 queue_offloads = port->rx_conf[q].offloads;
17732                 printf("  Queue[%2d] :", q);
17733                 print_rx_offloads(queue_offloads);
17734                 printf("\n");
17735         }
17736         printf("\n");
17737 }
17738
17739 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17740         .f = cmd_rx_offload_get_configuration_parsed,
17741         .data = NULL,
17742         .help_str = "show port <port_id> rx_offload configuration",
17743         .tokens = {
17744                 (void *)&cmd_rx_offload_get_configuration_show,
17745                 (void *)&cmd_rx_offload_get_configuration_port,
17746                 (void *)&cmd_rx_offload_get_configuration_port_id,
17747                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17748                 (void *)&cmd_rx_offload_get_configuration_configuration,
17749                 NULL,
17750         }
17751 };
17752
17753 /* Enable/Disable a per port offloading */
17754 struct cmd_config_per_port_rx_offload_result {
17755         cmdline_fixed_string_t port;
17756         cmdline_fixed_string_t config;
17757         portid_t port_id;
17758         cmdline_fixed_string_t rx_offload;
17759         cmdline_fixed_string_t offload;
17760         cmdline_fixed_string_t on_off;
17761 };
17762
17763 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
17764         TOKEN_STRING_INITIALIZER
17765                 (struct cmd_config_per_port_rx_offload_result,
17766                  port, "port");
17767 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
17768         TOKEN_STRING_INITIALIZER
17769                 (struct cmd_config_per_port_rx_offload_result,
17770                  config, "config");
17771 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
17772         TOKEN_NUM_INITIALIZER
17773                 (struct cmd_config_per_port_rx_offload_result,
17774                  port_id, UINT16);
17775 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
17776         TOKEN_STRING_INITIALIZER
17777                 (struct cmd_config_per_port_rx_offload_result,
17778                  rx_offload, "rx_offload");
17779 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
17780         TOKEN_STRING_INITIALIZER
17781                 (struct cmd_config_per_port_rx_offload_result,
17782                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17783                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17784                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17785                            "crc_strip#scatter#timestamp#security#keep_crc");
17786 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
17787         TOKEN_STRING_INITIALIZER
17788                 (struct cmd_config_per_port_rx_offload_result,
17789                  on_off, "on#off");
17790
17791 static uint64_t
17792 search_rx_offload(const char *name)
17793 {
17794         uint64_t single_offload;
17795         const char *single_name;
17796         int found = 0;
17797         unsigned int bit;
17798
17799         single_offload = 1;
17800         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17801                 single_name = rte_eth_dev_rx_offload_name(single_offload);
17802                 if (!strcasecmp(single_name, name)) {
17803                         found = 1;
17804                         break;
17805                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17806                         break;
17807                 else if (single_name == NULL)
17808                         break;
17809                 single_offload <<= 1;
17810         }
17811
17812         if (found)
17813                 return single_offload;
17814
17815         return 0;
17816 }
17817
17818 static void
17819 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
17820                                 __attribute__((unused)) struct cmdline *cl,
17821                                 __attribute__((unused)) void *data)
17822 {
17823         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
17824         portid_t port_id = res->port_id;
17825         struct rte_eth_dev_info dev_info;
17826         struct rte_port *port = &ports[port_id];
17827         uint64_t single_offload;
17828         uint16_t nb_rx_queues;
17829         int q;
17830
17831         if (port->port_status != RTE_PORT_STOPPED) {
17832                 printf("Error: Can't config offload when Port %d "
17833                        "is not stopped\n", port_id);
17834                 return;
17835         }
17836
17837         single_offload = search_rx_offload(res->offload);
17838         if (single_offload == 0) {
17839                 printf("Unknown offload name: %s\n", res->offload);
17840                 return;
17841         }
17842
17843         rte_eth_dev_info_get(port_id, &dev_info);
17844         nb_rx_queues = dev_info.nb_rx_queues;
17845         if (!strcmp(res->on_off, "on")) {
17846                 port->dev_conf.rxmode.offloads |= single_offload;
17847                 for (q = 0; q < nb_rx_queues; q++)
17848                         port->rx_conf[q].offloads |= single_offload;
17849         } else {
17850                 port->dev_conf.rxmode.offloads &= ~single_offload;
17851                 for (q = 0; q < nb_rx_queues; q++)
17852                         port->rx_conf[q].offloads &= ~single_offload;
17853         }
17854
17855         cmd_reconfig_device_queue(port_id, 1, 1);
17856 }
17857
17858 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
17859         .f = cmd_config_per_port_rx_offload_parsed,
17860         .data = NULL,
17861         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
17862                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17863                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17864                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17865                     "on|off",
17866         .tokens = {
17867                 (void *)&cmd_config_per_port_rx_offload_result_port,
17868                 (void *)&cmd_config_per_port_rx_offload_result_config,
17869                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
17870                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
17871                 (void *)&cmd_config_per_port_rx_offload_result_offload,
17872                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
17873                 NULL,
17874         }
17875 };
17876
17877 /* Enable/Disable a per queue offloading */
17878 struct cmd_config_per_queue_rx_offload_result {
17879         cmdline_fixed_string_t port;
17880         portid_t port_id;
17881         cmdline_fixed_string_t rxq;
17882         uint16_t queue_id;
17883         cmdline_fixed_string_t rx_offload;
17884         cmdline_fixed_string_t offload;
17885         cmdline_fixed_string_t on_off;
17886 };
17887
17888 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
17889         TOKEN_STRING_INITIALIZER
17890                 (struct cmd_config_per_queue_rx_offload_result,
17891                  port, "port");
17892 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
17893         TOKEN_NUM_INITIALIZER
17894                 (struct cmd_config_per_queue_rx_offload_result,
17895                  port_id, UINT16);
17896 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
17897         TOKEN_STRING_INITIALIZER
17898                 (struct cmd_config_per_queue_rx_offload_result,
17899                  rxq, "rxq");
17900 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
17901         TOKEN_NUM_INITIALIZER
17902                 (struct cmd_config_per_queue_rx_offload_result,
17903                  queue_id, UINT16);
17904 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
17905         TOKEN_STRING_INITIALIZER
17906                 (struct cmd_config_per_queue_rx_offload_result,
17907                  rx_offload, "rx_offload");
17908 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
17909         TOKEN_STRING_INITIALIZER
17910                 (struct cmd_config_per_queue_rx_offload_result,
17911                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17912                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17913                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17914                            "crc_strip#scatter#timestamp#security#keep_crc");
17915 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
17916         TOKEN_STRING_INITIALIZER
17917                 (struct cmd_config_per_queue_rx_offload_result,
17918                  on_off, "on#off");
17919
17920 static void
17921 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
17922                                 __attribute__((unused)) struct cmdline *cl,
17923                                 __attribute__((unused)) void *data)
17924 {
17925         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
17926         struct rte_eth_dev_info dev_info;
17927         portid_t port_id = res->port_id;
17928         uint16_t queue_id = res->queue_id;
17929         struct rte_port *port = &ports[port_id];
17930         uint64_t single_offload;
17931
17932         if (port->port_status != RTE_PORT_STOPPED) {
17933                 printf("Error: Can't config offload when Port %d "
17934                        "is not stopped\n", port_id);
17935                 return;
17936         }
17937
17938         rte_eth_dev_info_get(port_id, &dev_info);
17939         if (queue_id >= dev_info.nb_rx_queues) {
17940                 printf("Error: input queue_id should be 0 ... "
17941                        "%d\n", dev_info.nb_rx_queues - 1);
17942                 return;
17943         }
17944
17945         single_offload = search_rx_offload(res->offload);
17946         if (single_offload == 0) {
17947                 printf("Unknown offload name: %s\n", res->offload);
17948                 return;
17949         }
17950
17951         if (!strcmp(res->on_off, "on"))
17952                 port->rx_conf[queue_id].offloads |= single_offload;
17953         else
17954                 port->rx_conf[queue_id].offloads &= ~single_offload;
17955
17956         cmd_reconfig_device_queue(port_id, 1, 1);
17957 }
17958
17959 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
17960         .f = cmd_config_per_queue_rx_offload_parsed,
17961         .data = NULL,
17962         .help_str = "port <port_id> rxq <queue_id> rx_offload "
17963                     "vlan_strip|ipv4_cksum|"
17964                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17965                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17966                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17967                     "on|off",
17968         .tokens = {
17969                 (void *)&cmd_config_per_queue_rx_offload_result_port,
17970                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
17971                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
17972                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
17973                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
17974                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
17975                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
17976                 NULL,
17977         }
17978 };
17979
17980 /* Get Tx offloads capabilities */
17981 struct cmd_tx_offload_get_capa_result {
17982         cmdline_fixed_string_t show;
17983         cmdline_fixed_string_t port;
17984         portid_t port_id;
17985         cmdline_fixed_string_t tx_offload;
17986         cmdline_fixed_string_t capabilities;
17987 };
17988
17989 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
17990         TOKEN_STRING_INITIALIZER
17991                 (struct cmd_tx_offload_get_capa_result,
17992                  show, "show");
17993 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
17994         TOKEN_STRING_INITIALIZER
17995                 (struct cmd_tx_offload_get_capa_result,
17996                  port, "port");
17997 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
17998         TOKEN_NUM_INITIALIZER
17999                 (struct cmd_tx_offload_get_capa_result,
18000                  port_id, UINT16);
18001 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18002         TOKEN_STRING_INITIALIZER
18003                 (struct cmd_tx_offload_get_capa_result,
18004                  tx_offload, "tx_offload");
18005 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18006         TOKEN_STRING_INITIALIZER
18007                 (struct cmd_tx_offload_get_capa_result,
18008                  capabilities, "capabilities");
18009
18010 static void
18011 print_tx_offloads(uint64_t offloads)
18012 {
18013         uint64_t single_offload;
18014         int begin;
18015         int end;
18016         int bit;
18017
18018         if (offloads == 0)
18019                 return;
18020
18021         begin = __builtin_ctzll(offloads);
18022         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18023
18024         single_offload = 1 << begin;
18025         for (bit = begin; bit < end; bit++) {
18026                 if (offloads & single_offload)
18027                         printf(" %s",
18028                                rte_eth_dev_tx_offload_name(single_offload));
18029                 single_offload <<= 1;
18030         }
18031 }
18032
18033 static void
18034 cmd_tx_offload_get_capa_parsed(
18035         void *parsed_result,
18036         __attribute__((unused)) struct cmdline *cl,
18037         __attribute__((unused)) void *data)
18038 {
18039         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18040         struct rte_eth_dev_info dev_info;
18041         portid_t port_id = res->port_id;
18042         uint64_t queue_offloads;
18043         uint64_t port_offloads;
18044
18045         rte_eth_dev_info_get(port_id, &dev_info);
18046         queue_offloads = dev_info.tx_queue_offload_capa;
18047         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18048
18049         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18050         printf("  Per Queue :");
18051         print_tx_offloads(queue_offloads);
18052
18053         printf("\n");
18054         printf("  Per Port  :");
18055         print_tx_offloads(port_offloads);
18056         printf("\n\n");
18057 }
18058
18059 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18060         .f = cmd_tx_offload_get_capa_parsed,
18061         .data = NULL,
18062         .help_str = "show port <port_id> tx_offload capabilities",
18063         .tokens = {
18064                 (void *)&cmd_tx_offload_get_capa_show,
18065                 (void *)&cmd_tx_offload_get_capa_port,
18066                 (void *)&cmd_tx_offload_get_capa_port_id,
18067                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18068                 (void *)&cmd_tx_offload_get_capa_capabilities,
18069                 NULL,
18070         }
18071 };
18072
18073 /* Get Tx offloads configuration */
18074 struct cmd_tx_offload_get_configuration_result {
18075         cmdline_fixed_string_t show;
18076         cmdline_fixed_string_t port;
18077         portid_t port_id;
18078         cmdline_fixed_string_t tx_offload;
18079         cmdline_fixed_string_t configuration;
18080 };
18081
18082 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18083         TOKEN_STRING_INITIALIZER
18084                 (struct cmd_tx_offload_get_configuration_result,
18085                  show, "show");
18086 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18087         TOKEN_STRING_INITIALIZER
18088                 (struct cmd_tx_offload_get_configuration_result,
18089                  port, "port");
18090 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18091         TOKEN_NUM_INITIALIZER
18092                 (struct cmd_tx_offload_get_configuration_result,
18093                  port_id, UINT16);
18094 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18095         TOKEN_STRING_INITIALIZER
18096                 (struct cmd_tx_offload_get_configuration_result,
18097                  tx_offload, "tx_offload");
18098 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18099         TOKEN_STRING_INITIALIZER
18100                 (struct cmd_tx_offload_get_configuration_result,
18101                  configuration, "configuration");
18102
18103 static void
18104 cmd_tx_offload_get_configuration_parsed(
18105         void *parsed_result,
18106         __attribute__((unused)) struct cmdline *cl,
18107         __attribute__((unused)) void *data)
18108 {
18109         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18110         struct rte_eth_dev_info dev_info;
18111         portid_t port_id = res->port_id;
18112         struct rte_port *port = &ports[port_id];
18113         uint64_t port_offloads;
18114         uint64_t queue_offloads;
18115         uint16_t nb_tx_queues;
18116         int q;
18117
18118         printf("Tx Offloading Configuration of port %d :\n", port_id);
18119
18120         port_offloads = port->dev_conf.txmode.offloads;
18121         printf("  Port :");
18122         print_tx_offloads(port_offloads);
18123         printf("\n");
18124
18125         rte_eth_dev_info_get(port_id, &dev_info);
18126         nb_tx_queues = dev_info.nb_tx_queues;
18127         for (q = 0; q < nb_tx_queues; q++) {
18128                 queue_offloads = port->tx_conf[q].offloads;
18129                 printf("  Queue[%2d] :", q);
18130                 print_tx_offloads(queue_offloads);
18131                 printf("\n");
18132         }
18133         printf("\n");
18134 }
18135
18136 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18137         .f = cmd_tx_offload_get_configuration_parsed,
18138         .data = NULL,
18139         .help_str = "show port <port_id> tx_offload configuration",
18140         .tokens = {
18141                 (void *)&cmd_tx_offload_get_configuration_show,
18142                 (void *)&cmd_tx_offload_get_configuration_port,
18143                 (void *)&cmd_tx_offload_get_configuration_port_id,
18144                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18145                 (void *)&cmd_tx_offload_get_configuration_configuration,
18146                 NULL,
18147         }
18148 };
18149
18150 /* Enable/Disable a per port offloading */
18151 struct cmd_config_per_port_tx_offload_result {
18152         cmdline_fixed_string_t port;
18153         cmdline_fixed_string_t config;
18154         portid_t port_id;
18155         cmdline_fixed_string_t tx_offload;
18156         cmdline_fixed_string_t offload;
18157         cmdline_fixed_string_t on_off;
18158 };
18159
18160 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18161         TOKEN_STRING_INITIALIZER
18162                 (struct cmd_config_per_port_tx_offload_result,
18163                  port, "port");
18164 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18165         TOKEN_STRING_INITIALIZER
18166                 (struct cmd_config_per_port_tx_offload_result,
18167                  config, "config");
18168 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18169         TOKEN_NUM_INITIALIZER
18170                 (struct cmd_config_per_port_tx_offload_result,
18171                  port_id, UINT16);
18172 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18173         TOKEN_STRING_INITIALIZER
18174                 (struct cmd_config_per_port_tx_offload_result,
18175                  tx_offload, "tx_offload");
18176 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18177         TOKEN_STRING_INITIALIZER
18178                 (struct cmd_config_per_port_tx_offload_result,
18179                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18180                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18181                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18182                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18183                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18184                           "match_metadata");
18185 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18186         TOKEN_STRING_INITIALIZER
18187                 (struct cmd_config_per_port_tx_offload_result,
18188                  on_off, "on#off");
18189
18190 static uint64_t
18191 search_tx_offload(const char *name)
18192 {
18193         uint64_t single_offload;
18194         const char *single_name;
18195         int found = 0;
18196         unsigned int bit;
18197
18198         single_offload = 1;
18199         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18200                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18201                 if (!strcasecmp(single_name, name)) {
18202                         found = 1;
18203                         break;
18204                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18205                         break;
18206                 else if (single_name == NULL)
18207                         break;
18208                 single_offload <<= 1;
18209         }
18210
18211         if (found)
18212                 return single_offload;
18213
18214         return 0;
18215 }
18216
18217 static void
18218 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18219                                 __attribute__((unused)) struct cmdline *cl,
18220                                 __attribute__((unused)) void *data)
18221 {
18222         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18223         portid_t port_id = res->port_id;
18224         struct rte_eth_dev_info dev_info;
18225         struct rte_port *port = &ports[port_id];
18226         uint64_t single_offload;
18227         uint16_t nb_tx_queues;
18228         int q;
18229
18230         if (port->port_status != RTE_PORT_STOPPED) {
18231                 printf("Error: Can't config offload when Port %d "
18232                        "is not stopped\n", port_id);
18233                 return;
18234         }
18235
18236         single_offload = search_tx_offload(res->offload);
18237         if (single_offload == 0) {
18238                 printf("Unknown offload name: %s\n", res->offload);
18239                 return;
18240         }
18241
18242         rte_eth_dev_info_get(port_id, &dev_info);
18243         nb_tx_queues = dev_info.nb_tx_queues;
18244         if (!strcmp(res->on_off, "on")) {
18245                 port->dev_conf.txmode.offloads |= single_offload;
18246                 for (q = 0; q < nb_tx_queues; q++)
18247                         port->tx_conf[q].offloads |= single_offload;
18248         } else {
18249                 port->dev_conf.txmode.offloads &= ~single_offload;
18250                 for (q = 0; q < nb_tx_queues; q++)
18251                         port->tx_conf[q].offloads &= ~single_offload;
18252         }
18253
18254         cmd_reconfig_device_queue(port_id, 1, 1);
18255 }
18256
18257 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18258         .f = cmd_config_per_port_tx_offload_parsed,
18259         .data = NULL,
18260         .help_str = "port config <port_id> tx_offload "
18261                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18262                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18263                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18264                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18265                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18266                     "match_metadata on|off",
18267         .tokens = {
18268                 (void *)&cmd_config_per_port_tx_offload_result_port,
18269                 (void *)&cmd_config_per_port_tx_offload_result_config,
18270                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18271                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18272                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18273                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18274                 NULL,
18275         }
18276 };
18277
18278 /* Enable/Disable a per queue offloading */
18279 struct cmd_config_per_queue_tx_offload_result {
18280         cmdline_fixed_string_t port;
18281         portid_t port_id;
18282         cmdline_fixed_string_t txq;
18283         uint16_t queue_id;
18284         cmdline_fixed_string_t tx_offload;
18285         cmdline_fixed_string_t offload;
18286         cmdline_fixed_string_t on_off;
18287 };
18288
18289 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18290         TOKEN_STRING_INITIALIZER
18291                 (struct cmd_config_per_queue_tx_offload_result,
18292                  port, "port");
18293 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18294         TOKEN_NUM_INITIALIZER
18295                 (struct cmd_config_per_queue_tx_offload_result,
18296                  port_id, UINT16);
18297 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18298         TOKEN_STRING_INITIALIZER
18299                 (struct cmd_config_per_queue_tx_offload_result,
18300                  txq, "txq");
18301 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18302         TOKEN_NUM_INITIALIZER
18303                 (struct cmd_config_per_queue_tx_offload_result,
18304                  queue_id, UINT16);
18305 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18306         TOKEN_STRING_INITIALIZER
18307                 (struct cmd_config_per_queue_tx_offload_result,
18308                  tx_offload, "tx_offload");
18309 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18310         TOKEN_STRING_INITIALIZER
18311                 (struct cmd_config_per_queue_tx_offload_result,
18312                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18313                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18314                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18315                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18316                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18317 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18318         TOKEN_STRING_INITIALIZER
18319                 (struct cmd_config_per_queue_tx_offload_result,
18320                  on_off, "on#off");
18321
18322 static void
18323 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18324                                 __attribute__((unused)) struct cmdline *cl,
18325                                 __attribute__((unused)) void *data)
18326 {
18327         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18328         struct rte_eth_dev_info dev_info;
18329         portid_t port_id = res->port_id;
18330         uint16_t queue_id = res->queue_id;
18331         struct rte_port *port = &ports[port_id];
18332         uint64_t single_offload;
18333
18334         if (port->port_status != RTE_PORT_STOPPED) {
18335                 printf("Error: Can't config offload when Port %d "
18336                        "is not stopped\n", port_id);
18337                 return;
18338         }
18339
18340         rte_eth_dev_info_get(port_id, &dev_info);
18341         if (queue_id >= dev_info.nb_tx_queues) {
18342                 printf("Error: input queue_id should be 0 ... "
18343                        "%d\n", dev_info.nb_tx_queues - 1);
18344                 return;
18345         }
18346
18347         single_offload = search_tx_offload(res->offload);
18348         if (single_offload == 0) {
18349                 printf("Unknown offload name: %s\n", res->offload);
18350                 return;
18351         }
18352
18353         if (!strcmp(res->on_off, "on"))
18354                 port->tx_conf[queue_id].offloads |= single_offload;
18355         else
18356                 port->tx_conf[queue_id].offloads &= ~single_offload;
18357
18358         cmd_reconfig_device_queue(port_id, 1, 1);
18359 }
18360
18361 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18362         .f = cmd_config_per_queue_tx_offload_parsed,
18363         .data = NULL,
18364         .help_str = "port <port_id> txq <queue_id> tx_offload "
18365                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18366                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18367                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18368                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18369                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18370                     "on|off",
18371         .tokens = {
18372                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18373                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18374                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18375                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18376                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18377                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18378                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18379                 NULL,
18380         }
18381 };
18382
18383 /* *** configure tx_metadata for specific port *** */
18384 struct cmd_config_tx_metadata_specific_result {
18385         cmdline_fixed_string_t port;
18386         cmdline_fixed_string_t keyword;
18387         uint16_t port_id;
18388         cmdline_fixed_string_t item;
18389         uint32_t value;
18390 };
18391
18392 static void
18393 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18394                                 __attribute__((unused)) struct cmdline *cl,
18395                                 __attribute__((unused)) void *data)
18396 {
18397         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18398
18399         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18400                 return;
18401         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18402         /* Add/remove callback to insert valid metadata in every Tx packet. */
18403         if (ports[res->port_id].tx_metadata)
18404                 add_tx_md_callback(res->port_id);
18405         else
18406                 remove_tx_md_callback(res->port_id);
18407 }
18408
18409 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18410         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18411                         port, "port");
18412 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18413         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18414                         keyword, "config");
18415 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18416         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18417                         port_id, UINT16);
18418 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18419         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18420                         item, "tx_metadata");
18421 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18422         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18423                         value, UINT32);
18424
18425 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18426         .f = cmd_config_tx_metadata_specific_parsed,
18427         .data = NULL,
18428         .help_str = "port config <port_id> tx_metadata <value>",
18429         .tokens = {
18430                 (void *)&cmd_config_tx_metadata_specific_port,
18431                 (void *)&cmd_config_tx_metadata_specific_keyword,
18432                 (void *)&cmd_config_tx_metadata_specific_id,
18433                 (void *)&cmd_config_tx_metadata_specific_item,
18434                 (void *)&cmd_config_tx_metadata_specific_value,
18435                 NULL,
18436         },
18437 };
18438
18439 /* *** display tx_metadata per port configuration *** */
18440 struct cmd_show_tx_metadata_result {
18441         cmdline_fixed_string_t cmd_show;
18442         cmdline_fixed_string_t cmd_port;
18443         cmdline_fixed_string_t cmd_keyword;
18444         portid_t cmd_pid;
18445 };
18446
18447 static void
18448 cmd_show_tx_metadata_parsed(void *parsed_result,
18449                 __attribute__((unused)) struct cmdline *cl,
18450                 __attribute__((unused)) void *data)
18451 {
18452         struct cmd_show_tx_metadata_result *res = parsed_result;
18453
18454         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18455                 printf("invalid port id %u\n", res->cmd_pid);
18456                 return;
18457         }
18458         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18459                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18460                                 ports[res->cmd_pid].tx_metadata);
18461         }
18462 }
18463
18464 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18465         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18466                         cmd_show, "show");
18467 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18468         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18469                         cmd_port, "port");
18470 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18471         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18472                         cmd_pid, UINT16);
18473 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18474         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18475                         cmd_keyword, "tx_metadata");
18476
18477 cmdline_parse_inst_t cmd_show_tx_metadata = {
18478         .f = cmd_show_tx_metadata_parsed,
18479         .data = NULL,
18480         .help_str = "show port <port_id> tx_metadata",
18481         .tokens = {
18482                 (void *)&cmd_show_tx_metadata_show,
18483                 (void *)&cmd_show_tx_metadata_port,
18484                 (void *)&cmd_show_tx_metadata_pid,
18485                 (void *)&cmd_show_tx_metadata_keyword,
18486                 NULL,
18487         },
18488 };
18489
18490 /* ******************************************************************************** */
18491
18492 /* list of instructions */
18493 cmdline_parse_ctx_t main_ctx[] = {
18494         (cmdline_parse_inst_t *)&cmd_help_brief,
18495         (cmdline_parse_inst_t *)&cmd_help_long,
18496         (cmdline_parse_inst_t *)&cmd_quit,
18497         (cmdline_parse_inst_t *)&cmd_load_from_file,
18498         (cmdline_parse_inst_t *)&cmd_showport,
18499         (cmdline_parse_inst_t *)&cmd_showqueue,
18500         (cmdline_parse_inst_t *)&cmd_showportall,
18501         (cmdline_parse_inst_t *)&cmd_showcfg,
18502         (cmdline_parse_inst_t *)&cmd_start,
18503         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18504         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18505         (cmdline_parse_inst_t *)&cmd_set_link_up,
18506         (cmdline_parse_inst_t *)&cmd_set_link_down,
18507         (cmdline_parse_inst_t *)&cmd_reset,
18508         (cmdline_parse_inst_t *)&cmd_set_numbers,
18509         (cmdline_parse_inst_t *)&cmd_set_log,
18510         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18511         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18512         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18513         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18514         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18515         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18516         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18517         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18518         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18519         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18520         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18521         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18522         (cmdline_parse_inst_t *)&cmd_set_link_check,
18523         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18524         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18525         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18526         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18527 #ifdef RTE_LIBRTE_PMD_BOND
18528         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18529         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18530         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18531         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18532         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18533         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18534         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18535         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18536         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18537         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18538         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18539 #endif
18540         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18541         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18542         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18543         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18544         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18545         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18546         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18547         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18548         (cmdline_parse_inst_t *)&cmd_csum_set,
18549         (cmdline_parse_inst_t *)&cmd_csum_show,
18550         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18551         (cmdline_parse_inst_t *)&cmd_tso_set,
18552         (cmdline_parse_inst_t *)&cmd_tso_show,
18553         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18554         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18555         (cmdline_parse_inst_t *)&cmd_gro_enable,
18556         (cmdline_parse_inst_t *)&cmd_gro_flush,
18557         (cmdline_parse_inst_t *)&cmd_gro_show,
18558         (cmdline_parse_inst_t *)&cmd_gso_enable,
18559         (cmdline_parse_inst_t *)&cmd_gso_size,
18560         (cmdline_parse_inst_t *)&cmd_gso_show,
18561         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18562         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18563         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18564         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18565         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18566         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18567         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18568         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18569         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18570         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18571         (cmdline_parse_inst_t *)&cmd_config_dcb,
18572         (cmdline_parse_inst_t *)&cmd_read_reg,
18573         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18574         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18575         (cmdline_parse_inst_t *)&cmd_write_reg,
18576         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18577         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18578         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18579         (cmdline_parse_inst_t *)&cmd_stop,
18580         (cmdline_parse_inst_t *)&cmd_mac_addr,
18581         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18582         (cmdline_parse_inst_t *)&cmd_set_qmap,
18583         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18584         (cmdline_parse_inst_t *)&cmd_operate_port,
18585         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18586         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18587         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18588         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18589         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18590         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18591         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18592         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18593         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18594         (cmdline_parse_inst_t *)&cmd_config_mtu,
18595         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18596         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18597         (cmdline_parse_inst_t *)&cmd_config_rss,
18598         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18599         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18600         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18601         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18602         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18603         (cmdline_parse_inst_t *)&cmd_showport_reta,
18604         (cmdline_parse_inst_t *)&cmd_config_burst,
18605         (cmdline_parse_inst_t *)&cmd_config_thresh,
18606         (cmdline_parse_inst_t *)&cmd_config_threshold,
18607         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18608         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18609         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18610         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18611         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18612         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18613         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18614         (cmdline_parse_inst_t *)&cmd_global_config,
18615         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18616         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18617         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18618         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18619         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18620         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18621         (cmdline_parse_inst_t *)&cmd_dump,
18622         (cmdline_parse_inst_t *)&cmd_dump_one,
18623         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18624         (cmdline_parse_inst_t *)&cmd_syn_filter,
18625         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18626         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18627         (cmdline_parse_inst_t *)&cmd_flex_filter,
18628         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18629         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18630         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18631         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18632         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18633         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18634         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18635         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18636         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18637         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18638         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18639         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18640         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18641         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18642         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18643         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18644         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18645         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18646         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18647         (cmdline_parse_inst_t *)&cmd_flow,
18648         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18649         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18650         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18651         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18652         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18653         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18654         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18655         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18656         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18657         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18658         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18659         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18660         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18661         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18662         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18663         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18664         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18665         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18666         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18667         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18668         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18669         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18670         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18671         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18672         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18673         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18674         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18675         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18676         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18677         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18678         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18679         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18680         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18681         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18682         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18683         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18684         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18685         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18686         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18687         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18688         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18689         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18690         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18691         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18692         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18693         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18694         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18695         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18696         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18697 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
18698         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
18699 #endif
18700         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18701         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18702         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18703         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18704         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18705         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18706         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18707         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18708         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18709         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18710         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18711         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18712         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18713         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18714         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18715         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18716         (cmdline_parse_inst_t *)&cmd_ddp_add,
18717         (cmdline_parse_inst_t *)&cmd_ddp_del,
18718         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18719         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18720         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18721         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18722         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18723         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18724         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18725         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18726         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18727         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18728
18729         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18730         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18731         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18732         (cmdline_parse_inst_t *)&cmd_queue_region,
18733         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18734         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18735         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18736         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18737         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18738         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18739         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18740         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18741         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18742         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18743         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18744         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18745         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18746         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18747         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18748         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18749         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18750         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18751         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18752         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18753         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18754         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18755         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18756         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18757         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18758         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18759         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18760         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18761         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18762         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18763         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18764         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18765         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18766         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18767         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18768 #ifdef RTE_LIBRTE_BPF
18769         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18770         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18771 #endif
18772         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18773         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18774         NULL,
18775 };
18776
18777 /* read cmdline commands from file */
18778 void
18779 cmdline_read_from_file(const char *filename)
18780 {
18781         struct cmdline *cl;
18782
18783         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18784         if (cl == NULL) {
18785                 printf("Failed to create file based cmdline context: %s\n",
18786                        filename);
18787                 return;
18788         }
18789
18790         cmdline_interact(cl);
18791         cmdline_quit(cl);
18792
18793         cmdline_free(cl);
18794
18795         printf("Read CLI commands from %s\n", filename);
18796 }
18797
18798 /* prompt function, called from main on MASTER lcore */
18799 void
18800 prompt(void)
18801 {
18802         /* initialize non-constant commands */
18803         cmd_set_fwd_mode_init();
18804         cmd_set_fwd_retry_mode_init();
18805
18806         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18807         if (testpmd_cl == NULL)
18808                 return;
18809         cmdline_interact(testpmd_cl);
18810         cmdline_stdin_exit(testpmd_cl);
18811 }
18812
18813 void
18814 prompt_exit(void)
18815 {
18816         if (testpmd_cl != NULL)
18817                 cmdline_quit(testpmd_cl);
18818 }
18819
18820 static void
18821 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18822 {
18823         if (id == (portid_t)RTE_PORT_ALL) {
18824                 portid_t pid;
18825
18826                 RTE_ETH_FOREACH_DEV(pid) {
18827                         /* check if need_reconfig has been set to 1 */
18828                         if (ports[pid].need_reconfig == 0)
18829                                 ports[pid].need_reconfig = dev;
18830                         /* check if need_reconfig_queues has been set to 1 */
18831                         if (ports[pid].need_reconfig_queues == 0)
18832                                 ports[pid].need_reconfig_queues = queue;
18833                 }
18834         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18835                 /* check if need_reconfig has been set to 1 */
18836                 if (ports[id].need_reconfig == 0)
18837                         ports[id].need_reconfig = dev;
18838                 /* check if need_reconfig_queues has been set to 1 */
18839                 if (ports[id].need_reconfig_queues == 0)
18840                         ports[id].need_reconfig_queues = queue;
18841         }
18842 }