New upstream version 18.11-rc2
[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                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
732                         " (packet_length_adjust)\n"
733                         "       Add port tm node private shaper profile.\n\n"
734
735                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
736                         "       Delete port tm node private shaper profile.\n\n"
737
738                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
739                         " (shaper_profile_id)\n"
740                         "       Add/update port tm node shared shaper.\n\n"
741
742                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
743                         "       Delete port tm node shared shaper.\n\n"
744
745                         "set port tm node shaper profile (port_id) (node_id)"
746                         " (shaper_profile_id)\n"
747                         "       Set port tm node shaper profile.\n\n"
748
749                         "add port tm node wred profile (port_id) (wred_profile_id)"
750                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
751                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
752                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
753                         "       Add port tm node wred profile.\n\n"
754
755                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
756                         "       Delete port tm node wred profile.\n\n"
757
758                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
759                         " (priority) (weight) (level_id) (shaper_profile_id)"
760                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
761                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
762                         "       Add port tm nonleaf node.\n\n"
763
764                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
765                         " (priority) (weight) (level_id) (shaper_profile_id)"
766                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
767                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
768                         "       Add port tm leaf node.\n\n"
769
770                         "del port tm node (port_id) (node_id)\n"
771                         "       Delete port tm node.\n\n"
772
773                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
774                         " (priority) (weight)\n"
775                         "       Set port tm node parent.\n\n"
776
777                         "suspend port tm node (port_id) (node_id)"
778                         "       Suspend tm node.\n\n"
779
780                         "resume port tm node (port_id) (node_id)"
781                         "       Resume tm node.\n\n"
782
783                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
784                         "       Commit tm hierarchy.\n\n"
785
786                         "vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
787                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
788                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
789                         "       Configure the VXLAN encapsulation for flows.\n\n"
790
791                         "vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
792                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
793                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
794                         " eth-dst (eth-dst)\n"
795                         "       Configure the VXLAN encapsulation for flows.\n\n"
796
797                         "nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
798                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
799                         " (eth-dst)\n"
800                         "       Configure the NVGRE encapsulation for flows.\n\n"
801
802                         "nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
803                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
804                         " eth-src (eth-src) eth-dst (eth-dst)\n"
805                         "       Configure the NVGRE encapsulation for flows.\n\n"
806
807                         , list_pkt_forwarding_modes()
808                 );
809         }
810
811         if (show_all || !strcmp(res->section, "ports")) {
812
813                 cmdline_printf(
814                         cl,
815                         "\n"
816                         "Port Operations:\n"
817                         "----------------\n\n"
818
819                         "port start (port_id|all)\n"
820                         "    Start all ports or port_id.\n\n"
821
822                         "port stop (port_id|all)\n"
823                         "    Stop all ports or port_id.\n\n"
824
825                         "port close (port_id|all)\n"
826                         "    Close all ports or port_id.\n\n"
827
828                         "port attach (ident)\n"
829                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
830
831                         "port detach (port_id)\n"
832                         "    Detach physical or virtual dev by port_id\n\n"
833
834                         "port config (port_id|all)"
835                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
836                         " duplex (half|full|auto)\n"
837                         "    Set speed and duplex for all ports or port_id\n\n"
838
839                         "port config (port_id|all) loopback (mode)\n"
840                         "    Set loopback mode for all ports or port_id\n\n"
841
842                         "port config all (rxq|txq|rxd|txd) (value)\n"
843                         "    Set number for rxq/txq/rxd/txd.\n\n"
844
845                         "port config all max-pkt-len (value)\n"
846                         "    Set the max packet length.\n\n"
847
848                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
849                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
850                         " (on|off)\n"
851                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
852                         " for ports.\n\n"
853
854                         "port config all rss (all|default|ip|tcp|udp|sctp|"
855                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
856                         "    Set the RSS mode.\n\n"
857
858                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
859                         "    Set the RSS redirection table.\n\n"
860
861                         "port config (port_id) dcb vt (on|off) (traffic_class)"
862                         " pfc (on|off)\n"
863                         "    Set the DCB mode.\n\n"
864
865                         "port config all burst (value)\n"
866                         "    Set the number of packets per burst.\n\n"
867
868                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
869                         " (value)\n"
870                         "    Set the ring prefetch/host/writeback threshold"
871                         " for tx/rx queue.\n\n"
872
873                         "port config all (txfreet|txrst|rxfreet) (value)\n"
874                         "    Set free threshold for rx/tx, or set"
875                         " tx rs bit threshold.\n\n"
876                         "port config mtu X value\n"
877                         "    Set the MTU of port X to a given value\n\n"
878
879                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
880                         "    Set a rx/tx queue's ring size configuration, the new"
881                         " value will take effect after command that (re-)start the port"
882                         " or command that setup the specific queue\n\n"
883
884                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
885                         "    Start/stop a rx/tx queue of port X. Only take effect"
886                         " when port X is started\n\n"
887
888                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
889                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
890                         " take effect when port X is stopped.\n\n"
891
892                         "port (port_id) (rxq|txq) (queue_id) setup\n"
893                         "    Setup a rx/tx queue of port X.\n\n"
894
895                         "port config (port_id|all) l2-tunnel E-tag ether-type"
896                         " (value)\n"
897                         "    Set the value of E-tag ether-type.\n\n"
898
899                         "port config (port_id|all) l2-tunnel E-tag"
900                         " (enable|disable)\n"
901                         "    Enable/disable the E-tag support.\n\n"
902
903                         "port config (port_id) pctype mapping reset\n"
904                         "    Reset flow type to pctype mapping on a port\n\n"
905
906                         "port config (port_id) pctype mapping update"
907                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
908                         "    Update a flow type to pctype mapping item on a port\n\n"
909
910                         "port config (port_id) pctype (pctype_id) hash_inset|"
911                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
912                         " (field_idx)\n"
913                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
914
915                         "port config (port_id) pctype (pctype_id) hash_inset|"
916                         "fdir_inset|fdir_flx_inset clear all"
917                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
918
919                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
920                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
921                 );
922         }
923
924         if (show_all || !strcmp(res->section, "registers")) {
925
926                 cmdline_printf(
927                         cl,
928                         "\n"
929                         "Registers:\n"
930                         "----------\n\n"
931
932                         "read reg (port_id) (address)\n"
933                         "    Display value of a port register.\n\n"
934
935                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
936                         "    Display a port register bit field.\n\n"
937
938                         "read regbit (port_id) (address) (bit_x)\n"
939                         "    Display a single port register bit.\n\n"
940
941                         "write reg (port_id) (address) (value)\n"
942                         "    Set value of a port register.\n\n"
943
944                         "write regfield (port_id) (address) (bit_x) (bit_y)"
945                         " (value)\n"
946                         "    Set bit field of a port register.\n\n"
947
948                         "write regbit (port_id) (address) (bit_x) (value)\n"
949                         "    Set single bit value of a port register.\n\n"
950                 );
951         }
952         if (show_all || !strcmp(res->section, "filters")) {
953
954                 cmdline_printf(
955                         cl,
956                         "\n"
957                         "filters:\n"
958                         "--------\n\n"
959
960                         "ethertype_filter (port_id) (add|del)"
961                         " (mac_addr|mac_ignr) (mac_address) ethertype"
962                         " (ether_type) (drop|fwd) queue (queue_id)\n"
963                         "    Add/Del an ethertype filter.\n\n"
964
965                         "2tuple_filter (port_id) (add|del)"
966                         " dst_port (dst_port_value) protocol (protocol_value)"
967                         " mask (mask_value) tcp_flags (tcp_flags_value)"
968                         " priority (prio_value) queue (queue_id)\n"
969                         "    Add/Del a 2tuple filter.\n\n"
970
971                         "5tuple_filter (port_id) (add|del)"
972                         " dst_ip (dst_address) src_ip (src_address)"
973                         " dst_port (dst_port_value) src_port (src_port_value)"
974                         " protocol (protocol_value)"
975                         " mask (mask_value) tcp_flags (tcp_flags_value)"
976                         " priority (prio_value) queue (queue_id)\n"
977                         "    Add/Del a 5tuple filter.\n\n"
978
979                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
980                         "    Add/Del syn filter.\n\n"
981
982                         "flex_filter (port_id) (add|del) len (len_value)"
983                         " bytes (bytes_value) mask (mask_value)"
984                         " priority (prio_value) queue (queue_id)\n"
985                         "    Add/Del a flex filter.\n\n"
986
987                         "flow_director_filter (port_id) mode IP (add|del|update)"
988                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
989                         " src (src_ip_address) dst (dst_ip_address)"
990                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
991                         " vlan (vlan_value) flexbytes (flexbytes_value)"
992                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
993                         " fd_id (fd_id_value)\n"
994                         "    Add/Del an IP type flow director filter.\n\n"
995
996                         "flow_director_filter (port_id) mode IP (add|del|update)"
997                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
998                         " src (src_ip_address) (src_port)"
999                         " dst (dst_ip_address) (dst_port)"
1000                         " tos (tos_value) ttl (ttl_value)"
1001                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1002                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1003                         " fd_id (fd_id_value)\n"
1004                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode IP (add|del|update)"
1007                         " flow (ipv4-sctp|ipv6-sctp)"
1008                         " src (src_ip_address) (src_port)"
1009                         " dst (dst_ip_address) (dst_port)"
1010                         " tag (verification_tag) "
1011                         " tos (tos_value) ttl (ttl_value)"
1012                         " vlan (vlan_value)"
1013                         " flexbytes (flexbytes_value) (drop|fwd)"
1014                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1015                         "    Add/Del a SCTP type flow director filter.\n\n"
1016
1017                         "flow_director_filter (port_id) mode IP (add|del|update)"
1018                         " flow l2_payload ether (ethertype)"
1019                         " flexbytes (flexbytes_value) (drop|fwd)"
1020                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1021                         "    Add/Del a l2 payload type flow director filter.\n\n"
1022
1023                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1024                         " mac (mac_address) vlan (vlan_value)"
1025                         " flexbytes (flexbytes_value) (drop|fwd)"
1026                         " queue (queue_id) fd_id (fd_id_value)\n"
1027                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1028
1029                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1030                         " mac (mac_address) vlan (vlan_value)"
1031                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1032                         " flexbytes (flexbytes_value) (drop|fwd)"
1033                         " queue (queue_id) fd_id (fd_id_value)\n"
1034                         "    Add/Del a Tunnel flow director filter.\n\n"
1035
1036                         "flow_director_filter (port_id) mode raw (add|del|update)"
1037                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1038                         " fd_id (fd_id_value) packet (packet file name)\n"
1039                         "    Add/Del a raw type flow director filter.\n\n"
1040
1041                         "flush_flow_director (port_id)\n"
1042                         "    Flush all flow director entries of a device.\n\n"
1043
1044                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1045                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1046                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1047                         "    Set flow director IP mask.\n\n"
1048
1049                         "flow_director_mask (port_id) mode MAC-VLAN"
1050                         " vlan (vlan_value)\n"
1051                         "    Set flow director MAC-VLAN mask.\n\n"
1052
1053                         "flow_director_mask (port_id) mode Tunnel"
1054                         " vlan (vlan_value) mac (mac_value)"
1055                         " tunnel-type (tunnel_type_value)"
1056                         " tunnel-id (tunnel_id_value)\n"
1057                         "    Set flow director Tunnel mask.\n\n"
1058
1059                         "flow_director_flex_mask (port_id)"
1060                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1061                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1062                         " (mask)\n"
1063                         "    Configure mask of flex payload.\n\n"
1064
1065                         "flow_director_flex_payload (port_id)"
1066                         " (raw|l2|l3|l4) (config)\n"
1067                         "    Configure flex payload selection.\n\n"
1068
1069                         "get_sym_hash_ena_per_port (port_id)\n"
1070                         "    get symmetric hash enable configuration per port.\n\n"
1071
1072                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1073                         "    set symmetric hash enable configuration per port"
1074                         " to enable or disable.\n\n"
1075
1076                         "get_hash_global_config (port_id)\n"
1077                         "    Get the global configurations of hash filters.\n\n"
1078
1079                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1080                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1081                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1082                         " (enable|disable)\n"
1083                         "    Set the global configurations of hash filters.\n\n"
1084
1085                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1086                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1087                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1088                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1089                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1090                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1091                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1092                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1093                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1094                         "fld-8th|none) (select|add)\n"
1095                         "    Set the input set for hash.\n\n"
1096
1097                         "set_fdir_input_set (port_id) "
1098                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1099                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1100                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1101                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1102                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1103                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1104                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1105                         " (select|add)\n"
1106                         "    Set the input set for FDir.\n\n"
1107
1108                         "flow validate {port_id}"
1109                         " [group {group_id}] [priority {level}]"
1110                         " [ingress] [egress]"
1111                         " pattern {item} [/ {item} [...]] / end"
1112                         " actions {action} [/ {action} [...]] / end\n"
1113                         "    Check whether a flow rule can be created.\n\n"
1114
1115                         "flow create {port_id}"
1116                         " [group {group_id}] [priority {level}]"
1117                         " [ingress] [egress]"
1118                         " pattern {item} [/ {item} [...]] / end"
1119                         " actions {action} [/ {action} [...]] / end\n"
1120                         "    Create a flow rule.\n\n"
1121
1122                         "flow destroy {port_id} rule {rule_id} [...]\n"
1123                         "    Destroy specific flow rules.\n\n"
1124
1125                         "flow flush {port_id}\n"
1126                         "    Destroy all flow rules.\n\n"
1127
1128                         "flow query {port_id} {rule_id} {action}\n"
1129                         "    Query an existing flow rule.\n\n"
1130
1131                         "flow list {port_id} [group {group_id}] [...]\n"
1132                         "    List existing flow rules sorted by priority,"
1133                         " filtered by group identifiers.\n\n"
1134
1135                         "flow isolate {port_id} {boolean}\n"
1136                         "    Restrict ingress traffic to the defined"
1137                         " flow rules\n\n"
1138                 );
1139         }
1140 }
1141
1142 cmdline_parse_token_string_t cmd_help_long_help =
1143         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1144
1145 cmdline_parse_token_string_t cmd_help_long_section =
1146         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1147                         "all#control#display#config#"
1148                         "ports#registers#filters");
1149
1150 cmdline_parse_inst_t cmd_help_long = {
1151         .f = cmd_help_long_parsed,
1152         .data = NULL,
1153         .help_str = "help all|control|display|config|ports|register|filters: "
1154                 "Show help",
1155         .tokens = {
1156                 (void *)&cmd_help_long_help,
1157                 (void *)&cmd_help_long_section,
1158                 NULL,
1159         },
1160 };
1161
1162
1163 /* *** start/stop/close all ports *** */
1164 struct cmd_operate_port_result {
1165         cmdline_fixed_string_t keyword;
1166         cmdline_fixed_string_t name;
1167         cmdline_fixed_string_t value;
1168 };
1169
1170 static void cmd_operate_port_parsed(void *parsed_result,
1171                                 __attribute__((unused)) struct cmdline *cl,
1172                                 __attribute__((unused)) void *data)
1173 {
1174         struct cmd_operate_port_result *res = parsed_result;
1175
1176         if (!strcmp(res->name, "start"))
1177                 start_port(RTE_PORT_ALL);
1178         else if (!strcmp(res->name, "stop"))
1179                 stop_port(RTE_PORT_ALL);
1180         else if (!strcmp(res->name, "close"))
1181                 close_port(RTE_PORT_ALL);
1182         else if (!strcmp(res->name, "reset"))
1183                 reset_port(RTE_PORT_ALL);
1184         else
1185                 printf("Unknown parameter\n");
1186 }
1187
1188 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1189         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1190                                                                 "port");
1191 cmdline_parse_token_string_t cmd_operate_port_all_port =
1192         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1193                                                 "start#stop#close#reset");
1194 cmdline_parse_token_string_t cmd_operate_port_all_all =
1195         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1196
1197 cmdline_parse_inst_t cmd_operate_port = {
1198         .f = cmd_operate_port_parsed,
1199         .data = NULL,
1200         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1201         .tokens = {
1202                 (void *)&cmd_operate_port_all_cmd,
1203                 (void *)&cmd_operate_port_all_port,
1204                 (void *)&cmd_operate_port_all_all,
1205                 NULL,
1206         },
1207 };
1208
1209 /* *** start/stop/close specific port *** */
1210 struct cmd_operate_specific_port_result {
1211         cmdline_fixed_string_t keyword;
1212         cmdline_fixed_string_t name;
1213         uint8_t value;
1214 };
1215
1216 static void cmd_operate_specific_port_parsed(void *parsed_result,
1217                         __attribute__((unused)) struct cmdline *cl,
1218                                 __attribute__((unused)) void *data)
1219 {
1220         struct cmd_operate_specific_port_result *res = parsed_result;
1221
1222         if (!strcmp(res->name, "start"))
1223                 start_port(res->value);
1224         else if (!strcmp(res->name, "stop"))
1225                 stop_port(res->value);
1226         else if (!strcmp(res->name, "close"))
1227                 close_port(res->value);
1228         else if (!strcmp(res->name, "reset"))
1229                 reset_port(res->value);
1230         else
1231                 printf("Unknown parameter\n");
1232 }
1233
1234 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1235         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1236                                                         keyword, "port");
1237 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1238         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1239                                                 name, "start#stop#close#reset");
1240 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1241         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1242                                                         value, UINT8);
1243
1244 cmdline_parse_inst_t cmd_operate_specific_port = {
1245         .f = cmd_operate_specific_port_parsed,
1246         .data = NULL,
1247         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1248         .tokens = {
1249                 (void *)&cmd_operate_specific_port_cmd,
1250                 (void *)&cmd_operate_specific_port_port,
1251                 (void *)&cmd_operate_specific_port_id,
1252                 NULL,
1253         },
1254 };
1255
1256 /* *** enable port setup (after attach) via iterator or event *** */
1257 struct cmd_set_port_setup_on_result {
1258         cmdline_fixed_string_t set;
1259         cmdline_fixed_string_t port;
1260         cmdline_fixed_string_t setup;
1261         cmdline_fixed_string_t on;
1262         cmdline_fixed_string_t mode;
1263 };
1264
1265 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1266                                 __attribute__((unused)) struct cmdline *cl,
1267                                 __attribute__((unused)) void *data)
1268 {
1269         struct cmd_set_port_setup_on_result *res = parsed_result;
1270
1271         if (strcmp(res->mode, "event") == 0)
1272                 setup_on_probe_event = true;
1273         else if (strcmp(res->mode, "iterator") == 0)
1274                 setup_on_probe_event = false;
1275         else
1276                 printf("Unknown mode\n");
1277 }
1278
1279 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1280         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1281                         set, "set");
1282 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1283         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1284                         port, "port");
1285 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1286         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1287                         setup, "setup");
1288 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1289         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1290                         on, "on");
1291 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1292         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1293                         mode, "iterator#event");
1294
1295 cmdline_parse_inst_t cmd_set_port_setup_on = {
1296         .f = cmd_set_port_setup_on_parsed,
1297         .data = NULL,
1298         .help_str = "set port setup on iterator|event",
1299         .tokens = {
1300                 (void *)&cmd_set_port_setup_on_set,
1301                 (void *)&cmd_set_port_setup_on_port,
1302                 (void *)&cmd_set_port_setup_on_setup,
1303                 (void *)&cmd_set_port_setup_on_on,
1304                 (void *)&cmd_set_port_setup_on_mode,
1305                 NULL,
1306         },
1307 };
1308
1309 /* *** attach a specified port *** */
1310 struct cmd_operate_attach_port_result {
1311         cmdline_fixed_string_t port;
1312         cmdline_fixed_string_t keyword;
1313         cmdline_fixed_string_t identifier;
1314 };
1315
1316 static void cmd_operate_attach_port_parsed(void *parsed_result,
1317                                 __attribute__((unused)) struct cmdline *cl,
1318                                 __attribute__((unused)) void *data)
1319 {
1320         struct cmd_operate_attach_port_result *res = parsed_result;
1321
1322         if (!strcmp(res->keyword, "attach"))
1323                 attach_port(res->identifier);
1324         else
1325                 printf("Unknown parameter\n");
1326 }
1327
1328 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1329         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1330                         port, "port");
1331 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1332         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1333                         keyword, "attach");
1334 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1335         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1336                         identifier, NULL);
1337
1338 cmdline_parse_inst_t cmd_operate_attach_port = {
1339         .f = cmd_operate_attach_port_parsed,
1340         .data = NULL,
1341         .help_str = "port attach <identifier>: "
1342                 "(identifier: pci address or virtual dev name)",
1343         .tokens = {
1344                 (void *)&cmd_operate_attach_port_port,
1345                 (void *)&cmd_operate_attach_port_keyword,
1346                 (void *)&cmd_operate_attach_port_identifier,
1347                 NULL,
1348         },
1349 };
1350
1351 /* *** detach a specified port *** */
1352 struct cmd_operate_detach_port_result {
1353         cmdline_fixed_string_t port;
1354         cmdline_fixed_string_t keyword;
1355         portid_t port_id;
1356 };
1357
1358 static void cmd_operate_detach_port_parsed(void *parsed_result,
1359                                 __attribute__((unused)) struct cmdline *cl,
1360                                 __attribute__((unused)) void *data)
1361 {
1362         struct cmd_operate_detach_port_result *res = parsed_result;
1363
1364         if (!strcmp(res->keyword, "detach"))
1365                 detach_port_device(res->port_id);
1366         else
1367                 printf("Unknown parameter\n");
1368 }
1369
1370 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1371         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1372                         port, "port");
1373 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1374         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1375                         keyword, "detach");
1376 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1377         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1378                         port_id, UINT16);
1379
1380 cmdline_parse_inst_t cmd_operate_detach_port = {
1381         .f = cmd_operate_detach_port_parsed,
1382         .data = NULL,
1383         .help_str = "port detach <port_id>",
1384         .tokens = {
1385                 (void *)&cmd_operate_detach_port_port,
1386                 (void *)&cmd_operate_detach_port_keyword,
1387                 (void *)&cmd_operate_detach_port_port_id,
1388                 NULL,
1389         },
1390 };
1391
1392 /* *** configure speed for all ports *** */
1393 struct cmd_config_speed_all {
1394         cmdline_fixed_string_t port;
1395         cmdline_fixed_string_t keyword;
1396         cmdline_fixed_string_t all;
1397         cmdline_fixed_string_t item1;
1398         cmdline_fixed_string_t item2;
1399         cmdline_fixed_string_t value1;
1400         cmdline_fixed_string_t value2;
1401 };
1402
1403 static int
1404 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1405 {
1406
1407         int duplex;
1408
1409         if (!strcmp(duplexstr, "half")) {
1410                 duplex = ETH_LINK_HALF_DUPLEX;
1411         } else if (!strcmp(duplexstr, "full")) {
1412                 duplex = ETH_LINK_FULL_DUPLEX;
1413         } else if (!strcmp(duplexstr, "auto")) {
1414                 duplex = ETH_LINK_FULL_DUPLEX;
1415         } else {
1416                 printf("Unknown duplex parameter\n");
1417                 return -1;
1418         }
1419
1420         if (!strcmp(speedstr, "10")) {
1421                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1422                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1423         } else if (!strcmp(speedstr, "100")) {
1424                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1425                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1426         } else {
1427                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1428                         printf("Invalid speed/duplex parameters\n");
1429                         return -1;
1430                 }
1431                 if (!strcmp(speedstr, "1000")) {
1432                         *speed = ETH_LINK_SPEED_1G;
1433                 } else if (!strcmp(speedstr, "10000")) {
1434                         *speed = ETH_LINK_SPEED_10G;
1435                 } else if (!strcmp(speedstr, "25000")) {
1436                         *speed = ETH_LINK_SPEED_25G;
1437                 } else if (!strcmp(speedstr, "40000")) {
1438                         *speed = ETH_LINK_SPEED_40G;
1439                 } else if (!strcmp(speedstr, "50000")) {
1440                         *speed = ETH_LINK_SPEED_50G;
1441                 } else if (!strcmp(speedstr, "100000")) {
1442                         *speed = ETH_LINK_SPEED_100G;
1443                 } else if (!strcmp(speedstr, "auto")) {
1444                         *speed = ETH_LINK_SPEED_AUTONEG;
1445                 } else {
1446                         printf("Unknown speed parameter\n");
1447                         return -1;
1448                 }
1449         }
1450
1451         return 0;
1452 }
1453
1454 static void
1455 cmd_config_speed_all_parsed(void *parsed_result,
1456                         __attribute__((unused)) struct cmdline *cl,
1457                         __attribute__((unused)) void *data)
1458 {
1459         struct cmd_config_speed_all *res = parsed_result;
1460         uint32_t link_speed;
1461         portid_t pid;
1462
1463         if (!all_ports_stopped()) {
1464                 printf("Please stop all ports first\n");
1465                 return;
1466         }
1467
1468         if (parse_and_check_speed_duplex(res->value1, res->value2,
1469                         &link_speed) < 0)
1470                 return;
1471
1472         RTE_ETH_FOREACH_DEV(pid) {
1473                 ports[pid].dev_conf.link_speeds = link_speed;
1474         }
1475
1476         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1477 }
1478
1479 cmdline_parse_token_string_t cmd_config_speed_all_port =
1480         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1481 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1482         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1483                                                         "config");
1484 cmdline_parse_token_string_t cmd_config_speed_all_all =
1485         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1486 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1487         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1488 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1489         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1490                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1491 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1492         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1493 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1494         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1495                                                 "half#full#auto");
1496
1497 cmdline_parse_inst_t cmd_config_speed_all = {
1498         .f = cmd_config_speed_all_parsed,
1499         .data = NULL,
1500         .help_str = "port config all speed "
1501                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1502                                                         "half|full|auto",
1503         .tokens = {
1504                 (void *)&cmd_config_speed_all_port,
1505                 (void *)&cmd_config_speed_all_keyword,
1506                 (void *)&cmd_config_speed_all_all,
1507                 (void *)&cmd_config_speed_all_item1,
1508                 (void *)&cmd_config_speed_all_value1,
1509                 (void *)&cmd_config_speed_all_item2,
1510                 (void *)&cmd_config_speed_all_value2,
1511                 NULL,
1512         },
1513 };
1514
1515 /* *** configure speed for specific port *** */
1516 struct cmd_config_speed_specific {
1517         cmdline_fixed_string_t port;
1518         cmdline_fixed_string_t keyword;
1519         portid_t id;
1520         cmdline_fixed_string_t item1;
1521         cmdline_fixed_string_t item2;
1522         cmdline_fixed_string_t value1;
1523         cmdline_fixed_string_t value2;
1524 };
1525
1526 static void
1527 cmd_config_speed_specific_parsed(void *parsed_result,
1528                                 __attribute__((unused)) struct cmdline *cl,
1529                                 __attribute__((unused)) void *data)
1530 {
1531         struct cmd_config_speed_specific *res = parsed_result;
1532         uint32_t link_speed;
1533
1534         if (!all_ports_stopped()) {
1535                 printf("Please stop all ports first\n");
1536                 return;
1537         }
1538
1539         if (port_id_is_invalid(res->id, ENABLED_WARN))
1540                 return;
1541
1542         if (parse_and_check_speed_duplex(res->value1, res->value2,
1543                         &link_speed) < 0)
1544                 return;
1545
1546         ports[res->id].dev_conf.link_speeds = link_speed;
1547
1548         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1549 }
1550
1551
1552 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1553         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1554                                                                 "port");
1555 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1556         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1557                                                                 "config");
1558 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1559         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1560 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1561         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1562                                                                 "speed");
1563 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1565                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1566 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1568                                                                 "duplex");
1569 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1570         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1571                                                         "half#full#auto");
1572
1573 cmdline_parse_inst_t cmd_config_speed_specific = {
1574         .f = cmd_config_speed_specific_parsed,
1575         .data = NULL,
1576         .help_str = "port config <port_id> speed "
1577                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1578                                                         "half|full|auto",
1579         .tokens = {
1580                 (void *)&cmd_config_speed_specific_port,
1581                 (void *)&cmd_config_speed_specific_keyword,
1582                 (void *)&cmd_config_speed_specific_id,
1583                 (void *)&cmd_config_speed_specific_item1,
1584                 (void *)&cmd_config_speed_specific_value1,
1585                 (void *)&cmd_config_speed_specific_item2,
1586                 (void *)&cmd_config_speed_specific_value2,
1587                 NULL,
1588         },
1589 };
1590
1591 /* *** configure loopback for all ports *** */
1592 struct cmd_config_loopback_all {
1593         cmdline_fixed_string_t port;
1594         cmdline_fixed_string_t keyword;
1595         cmdline_fixed_string_t all;
1596         cmdline_fixed_string_t item;
1597         uint32_t mode;
1598 };
1599
1600 static void
1601 cmd_config_loopback_all_parsed(void *parsed_result,
1602                         __attribute__((unused)) struct cmdline *cl,
1603                         __attribute__((unused)) void *data)
1604 {
1605         struct cmd_config_loopback_all *res = parsed_result;
1606         portid_t pid;
1607
1608         if (!all_ports_stopped()) {
1609                 printf("Please stop all ports first\n");
1610                 return;
1611         }
1612
1613         RTE_ETH_FOREACH_DEV(pid) {
1614                 ports[pid].dev_conf.lpbk_mode = res->mode;
1615         }
1616
1617         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1618 }
1619
1620 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1621         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1622 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1623         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1624                                                         "config");
1625 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1626         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1627 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1628         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1629                                                         "loopback");
1630 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1631         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1632
1633 cmdline_parse_inst_t cmd_config_loopback_all = {
1634         .f = cmd_config_loopback_all_parsed,
1635         .data = NULL,
1636         .help_str = "port config all loopback <mode>",
1637         .tokens = {
1638                 (void *)&cmd_config_loopback_all_port,
1639                 (void *)&cmd_config_loopback_all_keyword,
1640                 (void *)&cmd_config_loopback_all_all,
1641                 (void *)&cmd_config_loopback_all_item,
1642                 (void *)&cmd_config_loopback_all_mode,
1643                 NULL,
1644         },
1645 };
1646
1647 /* *** configure loopback for specific port *** */
1648 struct cmd_config_loopback_specific {
1649         cmdline_fixed_string_t port;
1650         cmdline_fixed_string_t keyword;
1651         uint16_t port_id;
1652         cmdline_fixed_string_t item;
1653         uint32_t mode;
1654 };
1655
1656 static void
1657 cmd_config_loopback_specific_parsed(void *parsed_result,
1658                                 __attribute__((unused)) struct cmdline *cl,
1659                                 __attribute__((unused)) void *data)
1660 {
1661         struct cmd_config_loopback_specific *res = parsed_result;
1662
1663         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1664                 return;
1665
1666         if (!port_is_stopped(res->port_id)) {
1667                 printf("Please stop port %u first\n", res->port_id);
1668                 return;
1669         }
1670
1671         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1672
1673         cmd_reconfig_device_queue(res->port_id, 1, 1);
1674 }
1675
1676
1677 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1679                                                                 "port");
1680 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1681         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1682                                                                 "config");
1683 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1684         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1685                                                                 UINT16);
1686 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1687         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1688                                                                 "loopback");
1689 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1690         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1691                               UINT32);
1692
1693 cmdline_parse_inst_t cmd_config_loopback_specific = {
1694         .f = cmd_config_loopback_specific_parsed,
1695         .data = NULL,
1696         .help_str = "port config <port_id> loopback <mode>",
1697         .tokens = {
1698                 (void *)&cmd_config_loopback_specific_port,
1699                 (void *)&cmd_config_loopback_specific_keyword,
1700                 (void *)&cmd_config_loopback_specific_id,
1701                 (void *)&cmd_config_loopback_specific_item,
1702                 (void *)&cmd_config_loopback_specific_mode,
1703                 NULL,
1704         },
1705 };
1706
1707 /* *** configure txq/rxq, txd/rxd *** */
1708 struct cmd_config_rx_tx {
1709         cmdline_fixed_string_t port;
1710         cmdline_fixed_string_t keyword;
1711         cmdline_fixed_string_t all;
1712         cmdline_fixed_string_t name;
1713         uint16_t value;
1714 };
1715
1716 static void
1717 cmd_config_rx_tx_parsed(void *parsed_result,
1718                         __attribute__((unused)) struct cmdline *cl,
1719                         __attribute__((unused)) void *data)
1720 {
1721         struct cmd_config_rx_tx *res = parsed_result;
1722
1723         if (!all_ports_stopped()) {
1724                 printf("Please stop all ports first\n");
1725                 return;
1726         }
1727         if (!strcmp(res->name, "rxq")) {
1728                 if (!res->value && !nb_txq) {
1729                         printf("Warning: Either rx or tx queues should be non zero\n");
1730                         return;
1731                 }
1732                 if (check_nb_rxq(res->value) != 0)
1733                         return;
1734                 nb_rxq = res->value;
1735         }
1736         else if (!strcmp(res->name, "txq")) {
1737                 if (!res->value && !nb_rxq) {
1738                         printf("Warning: Either rx or tx queues should be non zero\n");
1739                         return;
1740                 }
1741                 if (check_nb_txq(res->value) != 0)
1742                         return;
1743                 nb_txq = res->value;
1744         }
1745         else if (!strcmp(res->name, "rxd")) {
1746                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1747                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1748                                         res->value, RTE_TEST_RX_DESC_MAX);
1749                         return;
1750                 }
1751                 nb_rxd = res->value;
1752         } else if (!strcmp(res->name, "txd")) {
1753                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1754                         printf("txd %d invalid - must be > 0 && <= %d\n",
1755                                         res->value, RTE_TEST_TX_DESC_MAX);
1756                         return;
1757                 }
1758                 nb_txd = res->value;
1759         } else {
1760                 printf("Unknown parameter\n");
1761                 return;
1762         }
1763
1764         fwd_config_setup();
1765
1766         init_port_config();
1767
1768         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1769 }
1770
1771 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1772         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1773 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1774         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1775 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1776         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1777 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1778         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1779                                                 "rxq#txq#rxd#txd");
1780 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1781         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1782
1783 cmdline_parse_inst_t cmd_config_rx_tx = {
1784         .f = cmd_config_rx_tx_parsed,
1785         .data = NULL,
1786         .help_str = "port config all rxq|txq|rxd|txd <value>",
1787         .tokens = {
1788                 (void *)&cmd_config_rx_tx_port,
1789                 (void *)&cmd_config_rx_tx_keyword,
1790                 (void *)&cmd_config_rx_tx_all,
1791                 (void *)&cmd_config_rx_tx_name,
1792                 (void *)&cmd_config_rx_tx_value,
1793                 NULL,
1794         },
1795 };
1796
1797 /* *** config max packet length *** */
1798 struct cmd_config_max_pkt_len_result {
1799         cmdline_fixed_string_t port;
1800         cmdline_fixed_string_t keyword;
1801         cmdline_fixed_string_t all;
1802         cmdline_fixed_string_t name;
1803         uint32_t value;
1804 };
1805
1806 static void
1807 cmd_config_max_pkt_len_parsed(void *parsed_result,
1808                                 __attribute__((unused)) struct cmdline *cl,
1809                                 __attribute__((unused)) void *data)
1810 {
1811         struct cmd_config_max_pkt_len_result *res = parsed_result;
1812         portid_t pid;
1813
1814         if (!all_ports_stopped()) {
1815                 printf("Please stop all ports first\n");
1816                 return;
1817         }
1818
1819         RTE_ETH_FOREACH_DEV(pid) {
1820                 struct rte_port *port = &ports[pid];
1821                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1822
1823                 if (!strcmp(res->name, "max-pkt-len")) {
1824                         if (res->value < ETHER_MIN_LEN) {
1825                                 printf("max-pkt-len can not be less than %d\n",
1826                                                 ETHER_MIN_LEN);
1827                                 return;
1828                         }
1829                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1830                                 return;
1831
1832                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1833                         if (res->value > ETHER_MAX_LEN)
1834                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1835                         else
1836                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1837                         port->dev_conf.rxmode.offloads = rx_offloads;
1838                 } else {
1839                         printf("Unknown parameter\n");
1840                         return;
1841                 }
1842         }
1843
1844         init_port_config();
1845
1846         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1847 }
1848
1849 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1851                                                                 "port");
1852 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1853         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1854                                                                 "config");
1855 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1856         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1857                                                                 "all");
1858 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1859         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1860                                                                 "max-pkt-len");
1861 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1862         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1863                                                                 UINT32);
1864
1865 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1866         .f = cmd_config_max_pkt_len_parsed,
1867         .data = NULL,
1868         .help_str = "port config all max-pkt-len <value>",
1869         .tokens = {
1870                 (void *)&cmd_config_max_pkt_len_port,
1871                 (void *)&cmd_config_max_pkt_len_keyword,
1872                 (void *)&cmd_config_max_pkt_len_all,
1873                 (void *)&cmd_config_max_pkt_len_name,
1874                 (void *)&cmd_config_max_pkt_len_value,
1875                 NULL,
1876         },
1877 };
1878
1879 /* *** configure port MTU *** */
1880 struct cmd_config_mtu_result {
1881         cmdline_fixed_string_t port;
1882         cmdline_fixed_string_t keyword;
1883         cmdline_fixed_string_t mtu;
1884         portid_t port_id;
1885         uint16_t value;
1886 };
1887
1888 static void
1889 cmd_config_mtu_parsed(void *parsed_result,
1890                       __attribute__((unused)) struct cmdline *cl,
1891                       __attribute__((unused)) void *data)
1892 {
1893         struct cmd_config_mtu_result *res = parsed_result;
1894
1895         if (res->value < ETHER_MIN_LEN) {
1896                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1897                 return;
1898         }
1899         port_mtu_set(res->port_id, res->value);
1900 }
1901
1902 cmdline_parse_token_string_t cmd_config_mtu_port =
1903         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1904                                  "port");
1905 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1906         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1907                                  "config");
1908 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1909         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1910                                  "mtu");
1911 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1912         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1913 cmdline_parse_token_num_t cmd_config_mtu_value =
1914         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1915
1916 cmdline_parse_inst_t cmd_config_mtu = {
1917         .f = cmd_config_mtu_parsed,
1918         .data = NULL,
1919         .help_str = "port config mtu <port_id> <value>",
1920         .tokens = {
1921                 (void *)&cmd_config_mtu_port,
1922                 (void *)&cmd_config_mtu_keyword,
1923                 (void *)&cmd_config_mtu_mtu,
1924                 (void *)&cmd_config_mtu_port_id,
1925                 (void *)&cmd_config_mtu_value,
1926                 NULL,
1927         },
1928 };
1929
1930 /* *** configure rx mode *** */
1931 struct cmd_config_rx_mode_flag {
1932         cmdline_fixed_string_t port;
1933         cmdline_fixed_string_t keyword;
1934         cmdline_fixed_string_t all;
1935         cmdline_fixed_string_t name;
1936         cmdline_fixed_string_t value;
1937 };
1938
1939 static void
1940 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1941                                 __attribute__((unused)) struct cmdline *cl,
1942                                 __attribute__((unused)) void *data)
1943 {
1944         struct cmd_config_rx_mode_flag *res = parsed_result;
1945         portid_t pid;
1946
1947         if (!all_ports_stopped()) {
1948                 printf("Please stop all ports first\n");
1949                 return;
1950         }
1951
1952         RTE_ETH_FOREACH_DEV(pid) {
1953                 struct rte_port *port;
1954                 uint64_t rx_offloads;
1955
1956                 port = &ports[pid];
1957                 rx_offloads = port->dev_conf.rxmode.offloads;
1958                 if (!strcmp(res->name, "crc-strip")) {
1959                         if (!strcmp(res->value, "on")) {
1960                                 rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
1961                         } else if (!strcmp(res->value, "off")) {
1962                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
1963                         } else {
1964                                 printf("Unknown parameter\n");
1965                                 return;
1966                         }
1967                 } else if (!strcmp(res->name, "scatter")) {
1968                         if (!strcmp(res->value, "on")) {
1969                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1970                         } else if (!strcmp(res->value, "off")) {
1971                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1972                         } else {
1973                                 printf("Unknown parameter\n");
1974                                 return;
1975                         }
1976                 } else if (!strcmp(res->name, "rx-cksum")) {
1977                         if (!strcmp(res->value, "on"))
1978                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1979                         else if (!strcmp(res->value, "off"))
1980                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1981                         else {
1982                                 printf("Unknown parameter\n");
1983                                 return;
1984                         }
1985                 } else if (!strcmp(res->name, "rx-timestamp")) {
1986                         if (!strcmp(res->value, "on"))
1987                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1988                         else if (!strcmp(res->value, "off"))
1989                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1990                         else {
1991                                 printf("Unknown parameter\n");
1992                                 return;
1993                         }
1994                 } else if (!strcmp(res->name, "hw-vlan")) {
1995                         if (!strcmp(res->value, "on")) {
1996                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1997                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1998                         } else if (!strcmp(res->value, "off")) {
1999                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
2000                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2001                         } else {
2002                                 printf("Unknown parameter\n");
2003                                 return;
2004                         }
2005                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
2006                         if (!strcmp(res->value, "on"))
2007                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2008                         else if (!strcmp(res->value, "off"))
2009                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2010                         else {
2011                                 printf("Unknown parameter\n");
2012                                 return;
2013                         }
2014                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
2015                         if (!strcmp(res->value, "on"))
2016                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2017                         else if (!strcmp(res->value, "off"))
2018                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2019                         else {
2020                                 printf("Unknown parameter\n");
2021                                 return;
2022                         }
2023                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
2024                         if (!strcmp(res->value, "on"))
2025                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2026                         else if (!strcmp(res->value, "off"))
2027                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2028                         else {
2029                                 printf("Unknown parameter\n");
2030                                 return;
2031                         }
2032                 } else if (!strcmp(res->name, "drop-en")) {
2033                         if (!strcmp(res->value, "on"))
2034                                 rx_drop_en = 1;
2035                         else if (!strcmp(res->value, "off"))
2036                                 rx_drop_en = 0;
2037                         else {
2038                                 printf("Unknown parameter\n");
2039                                 return;
2040                         }
2041                 } else {
2042                         printf("Unknown parameter\n");
2043                         return;
2044                 }
2045                 port->dev_conf.rxmode.offloads = rx_offloads;
2046         }
2047
2048         init_port_config();
2049
2050         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2051 }
2052
2053 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2054         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2055 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2056         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2057                                                                 "config");
2058 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2059         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2060 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2061         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2062                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2063                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2064 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2065         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2066                                                         "on#off");
2067
2068 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2069         .f = cmd_config_rx_mode_flag_parsed,
2070         .data = NULL,
2071         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2072                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2073         .tokens = {
2074                 (void *)&cmd_config_rx_mode_flag_port,
2075                 (void *)&cmd_config_rx_mode_flag_keyword,
2076                 (void *)&cmd_config_rx_mode_flag_all,
2077                 (void *)&cmd_config_rx_mode_flag_name,
2078                 (void *)&cmd_config_rx_mode_flag_value,
2079                 NULL,
2080         },
2081 };
2082
2083 /* *** configure rss *** */
2084 struct cmd_config_rss {
2085         cmdline_fixed_string_t port;
2086         cmdline_fixed_string_t keyword;
2087         cmdline_fixed_string_t all;
2088         cmdline_fixed_string_t name;
2089         cmdline_fixed_string_t value;
2090 };
2091
2092 static void
2093 cmd_config_rss_parsed(void *parsed_result,
2094                         __attribute__((unused)) struct cmdline *cl,
2095                         __attribute__((unused)) void *data)
2096 {
2097         struct cmd_config_rss *res = parsed_result;
2098         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2099         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2100         int use_default = 0;
2101         int all_updated = 1;
2102         int diag;
2103         uint16_t i;
2104
2105         if (!strcmp(res->value, "all"))
2106                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2107                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2108                                         ETH_RSS_L2_PAYLOAD;
2109         else if (!strcmp(res->value, "ip"))
2110                 rss_conf.rss_hf = ETH_RSS_IP;
2111         else if (!strcmp(res->value, "udp"))
2112                 rss_conf.rss_hf = ETH_RSS_UDP;
2113         else if (!strcmp(res->value, "tcp"))
2114                 rss_conf.rss_hf = ETH_RSS_TCP;
2115         else if (!strcmp(res->value, "sctp"))
2116                 rss_conf.rss_hf = ETH_RSS_SCTP;
2117         else if (!strcmp(res->value, "ether"))
2118                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2119         else if (!strcmp(res->value, "port"))
2120                 rss_conf.rss_hf = ETH_RSS_PORT;
2121         else if (!strcmp(res->value, "vxlan"))
2122                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2123         else if (!strcmp(res->value, "geneve"))
2124                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2125         else if (!strcmp(res->value, "nvgre"))
2126                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2127         else if (!strcmp(res->value, "none"))
2128                 rss_conf.rss_hf = 0;
2129         else if (!strcmp(res->value, "default"))
2130                 use_default = 1;
2131         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2132                                                 atoi(res->value) < 64)
2133                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2134         else {
2135                 printf("Unknown parameter\n");
2136                 return;
2137         }
2138         rss_conf.rss_key = NULL;
2139         /* Update global configuration for RSS types. */
2140         RTE_ETH_FOREACH_DEV(i) {
2141                 struct rte_eth_rss_conf local_rss_conf;
2142
2143                 rte_eth_dev_info_get(i, &dev_info);
2144                 if (use_default)
2145                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2146
2147                 local_rss_conf = rss_conf;
2148                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2149                         dev_info.flow_type_rss_offloads;
2150                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2151                         printf("Port %u modified RSS hash function based on hardware support,"
2152                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2153                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2154                 }
2155                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2156                 if (diag < 0) {
2157                         all_updated = 0;
2158                         printf("Configuration of RSS hash at ethernet port %d "
2159                                 "failed with error (%d): %s.\n",
2160                                 i, -diag, strerror(-diag));
2161                 }
2162         }
2163         if (all_updated && !use_default)
2164                 rss_hf = rss_conf.rss_hf;
2165 }
2166
2167 cmdline_parse_token_string_t cmd_config_rss_port =
2168         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2169 cmdline_parse_token_string_t cmd_config_rss_keyword =
2170         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2171 cmdline_parse_token_string_t cmd_config_rss_all =
2172         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2173 cmdline_parse_token_string_t cmd_config_rss_name =
2174         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2175 cmdline_parse_token_string_t cmd_config_rss_value =
2176         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2177
2178 cmdline_parse_inst_t cmd_config_rss = {
2179         .f = cmd_config_rss_parsed,
2180         .data = NULL,
2181         .help_str = "port config all rss "
2182                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2183         .tokens = {
2184                 (void *)&cmd_config_rss_port,
2185                 (void *)&cmd_config_rss_keyword,
2186                 (void *)&cmd_config_rss_all,
2187                 (void *)&cmd_config_rss_name,
2188                 (void *)&cmd_config_rss_value,
2189                 NULL,
2190         },
2191 };
2192
2193 /* *** configure rss hash key *** */
2194 struct cmd_config_rss_hash_key {
2195         cmdline_fixed_string_t port;
2196         cmdline_fixed_string_t config;
2197         portid_t port_id;
2198         cmdline_fixed_string_t rss_hash_key;
2199         cmdline_fixed_string_t rss_type;
2200         cmdline_fixed_string_t key;
2201 };
2202
2203 static uint8_t
2204 hexa_digit_to_value(char hexa_digit)
2205 {
2206         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2207                 return (uint8_t) (hexa_digit - '0');
2208         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2209                 return (uint8_t) ((hexa_digit - 'a') + 10);
2210         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2211                 return (uint8_t) ((hexa_digit - 'A') + 10);
2212         /* Invalid hexa digit */
2213         return 0xFF;
2214 }
2215
2216 static uint8_t
2217 parse_and_check_key_hexa_digit(char *key, int idx)
2218 {
2219         uint8_t hexa_v;
2220
2221         hexa_v = hexa_digit_to_value(key[idx]);
2222         if (hexa_v == 0xFF)
2223                 printf("invalid key: character %c at position %d is not a "
2224                        "valid hexa digit\n", key[idx], idx);
2225         return hexa_v;
2226 }
2227
2228 static void
2229 cmd_config_rss_hash_key_parsed(void *parsed_result,
2230                                __attribute__((unused)) struct cmdline *cl,
2231                                __attribute__((unused)) void *data)
2232 {
2233         struct cmd_config_rss_hash_key *res = parsed_result;
2234         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2235         uint8_t xdgt0;
2236         uint8_t xdgt1;
2237         int i;
2238         struct rte_eth_dev_info dev_info;
2239         uint8_t hash_key_size;
2240         uint32_t key_len;
2241
2242         memset(&dev_info, 0, sizeof(dev_info));
2243         rte_eth_dev_info_get(res->port_id, &dev_info);
2244         if (dev_info.hash_key_size > 0 &&
2245                         dev_info.hash_key_size <= sizeof(hash_key))
2246                 hash_key_size = dev_info.hash_key_size;
2247         else {
2248                 printf("dev_info did not provide a valid hash key size\n");
2249                 return;
2250         }
2251         /* Check the length of the RSS hash key */
2252         key_len = strlen(res->key);
2253         if (key_len != (hash_key_size * 2)) {
2254                 printf("key length: %d invalid - key must be a string of %d"
2255                            " hexa-decimal numbers\n",
2256                            (int) key_len, hash_key_size * 2);
2257                 return;
2258         }
2259         /* Translate RSS hash key into binary representation */
2260         for (i = 0; i < hash_key_size; i++) {
2261                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2262                 if (xdgt0 == 0xFF)
2263                         return;
2264                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2265                 if (xdgt1 == 0xFF)
2266                         return;
2267                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2268         }
2269         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2270                         hash_key_size);
2271 }
2272
2273 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2274         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2275 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2276         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2277                                  "config");
2278 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2279         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2280 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2281         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2282                                  rss_hash_key, "rss-hash-key");
2283 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2284         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2285                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2286                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2287                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2288                                  "ipv6-tcp-ex#ipv6-udp-ex");
2289 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2290         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2291
2292 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2293         .f = cmd_config_rss_hash_key_parsed,
2294         .data = NULL,
2295         .help_str = "port config <port_id> rss-hash-key "
2296                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2297                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2298                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2299                 "<string of hex digits (variable length, NIC dependent)>",
2300         .tokens = {
2301                 (void *)&cmd_config_rss_hash_key_port,
2302                 (void *)&cmd_config_rss_hash_key_config,
2303                 (void *)&cmd_config_rss_hash_key_port_id,
2304                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2305                 (void *)&cmd_config_rss_hash_key_rss_type,
2306                 (void *)&cmd_config_rss_hash_key_value,
2307                 NULL,
2308         },
2309 };
2310
2311 /* *** configure port rxq/txq ring size *** */
2312 struct cmd_config_rxtx_ring_size {
2313         cmdline_fixed_string_t port;
2314         cmdline_fixed_string_t config;
2315         portid_t portid;
2316         cmdline_fixed_string_t rxtxq;
2317         uint16_t qid;
2318         cmdline_fixed_string_t rsize;
2319         uint16_t size;
2320 };
2321
2322 static void
2323 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2324                                  __attribute__((unused)) struct cmdline *cl,
2325                                  __attribute__((unused)) void *data)
2326 {
2327         struct cmd_config_rxtx_ring_size *res = parsed_result;
2328         struct rte_port *port;
2329         uint8_t isrx;
2330
2331         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2332                 return;
2333
2334         if (res->portid == (portid_t)RTE_PORT_ALL) {
2335                 printf("Invalid port id\n");
2336                 return;
2337         }
2338
2339         port = &ports[res->portid];
2340
2341         if (!strcmp(res->rxtxq, "rxq"))
2342                 isrx = 1;
2343         else if (!strcmp(res->rxtxq, "txq"))
2344                 isrx = 0;
2345         else {
2346                 printf("Unknown parameter\n");
2347                 return;
2348         }
2349
2350         if (isrx && rx_queue_id_is_invalid(res->qid))
2351                 return;
2352         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2353                 return;
2354
2355         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2356                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2357                        rx_free_thresh);
2358                 return;
2359         }
2360
2361         if (isrx)
2362                 port->nb_rx_desc[res->qid] = res->size;
2363         else
2364                 port->nb_tx_desc[res->qid] = res->size;
2365
2366         cmd_reconfig_device_queue(res->portid, 0, 1);
2367 }
2368
2369 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2370         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2371                                  port, "port");
2372 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2373         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2374                                  config, "config");
2375 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2376         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2377                                  portid, UINT16);
2378 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2379         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2380                                  rxtxq, "rxq#txq");
2381 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2382         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2383                               qid, UINT16);
2384 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2385         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2386                                  rsize, "ring_size");
2387 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2388         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2389                               size, UINT16);
2390
2391 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2392         .f = cmd_config_rxtx_ring_size_parsed,
2393         .data = NULL,
2394         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2395         .tokens = {
2396                 (void *)&cmd_config_rxtx_ring_size_port,
2397                 (void *)&cmd_config_rxtx_ring_size_config,
2398                 (void *)&cmd_config_rxtx_ring_size_portid,
2399                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2400                 (void *)&cmd_config_rxtx_ring_size_qid,
2401                 (void *)&cmd_config_rxtx_ring_size_rsize,
2402                 (void *)&cmd_config_rxtx_ring_size_size,
2403                 NULL,
2404         },
2405 };
2406
2407 /* *** configure port rxq/txq start/stop *** */
2408 struct cmd_config_rxtx_queue {
2409         cmdline_fixed_string_t port;
2410         portid_t portid;
2411         cmdline_fixed_string_t rxtxq;
2412         uint16_t qid;
2413         cmdline_fixed_string_t opname;
2414 };
2415
2416 static void
2417 cmd_config_rxtx_queue_parsed(void *parsed_result,
2418                         __attribute__((unused)) struct cmdline *cl,
2419                         __attribute__((unused)) void *data)
2420 {
2421         struct cmd_config_rxtx_queue *res = parsed_result;
2422         uint8_t isrx;
2423         uint8_t isstart;
2424         int ret = 0;
2425
2426         if (test_done == 0) {
2427                 printf("Please stop forwarding first\n");
2428                 return;
2429         }
2430
2431         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2432                 return;
2433
2434         if (port_is_started(res->portid) != 1) {
2435                 printf("Please start port %u first\n", res->portid);
2436                 return;
2437         }
2438
2439         if (!strcmp(res->rxtxq, "rxq"))
2440                 isrx = 1;
2441         else if (!strcmp(res->rxtxq, "txq"))
2442                 isrx = 0;
2443         else {
2444                 printf("Unknown parameter\n");
2445                 return;
2446         }
2447
2448         if (isrx && rx_queue_id_is_invalid(res->qid))
2449                 return;
2450         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2451                 return;
2452
2453         if (!strcmp(res->opname, "start"))
2454                 isstart = 1;
2455         else if (!strcmp(res->opname, "stop"))
2456                 isstart = 0;
2457         else {
2458                 printf("Unknown parameter\n");
2459                 return;
2460         }
2461
2462         if (isstart && isrx)
2463                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2464         else if (!isstart && isrx)
2465                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2466         else if (isstart && !isrx)
2467                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2468         else
2469                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2470
2471         if (ret == -ENOTSUP)
2472                 printf("Function not supported in PMD driver\n");
2473 }
2474
2475 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2476         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2477 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2478         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2479 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2480         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2481 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2482         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2483 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2484         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2485                                                 "start#stop");
2486
2487 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2488         .f = cmd_config_rxtx_queue_parsed,
2489         .data = NULL,
2490         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2491         .tokens = {
2492                 (void *)&cmd_config_rxtx_queue_port,
2493                 (void *)&cmd_config_rxtx_queue_portid,
2494                 (void *)&cmd_config_rxtx_queue_rxtxq,
2495                 (void *)&cmd_config_rxtx_queue_qid,
2496                 (void *)&cmd_config_rxtx_queue_opname,
2497                 NULL,
2498         },
2499 };
2500
2501 /* *** configure port rxq/txq deferred start on/off *** */
2502 struct cmd_config_deferred_start_rxtx_queue {
2503         cmdline_fixed_string_t port;
2504         portid_t port_id;
2505         cmdline_fixed_string_t rxtxq;
2506         uint16_t qid;
2507         cmdline_fixed_string_t opname;
2508         cmdline_fixed_string_t state;
2509 };
2510
2511 static void
2512 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2513                         __attribute__((unused)) struct cmdline *cl,
2514                         __attribute__((unused)) void *data)
2515 {
2516         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2517         struct rte_port *port;
2518         uint8_t isrx;
2519         uint8_t ison;
2520         uint8_t needreconfig = 0;
2521
2522         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2523                 return;
2524
2525         if (port_is_started(res->port_id) != 0) {
2526                 printf("Please stop port %u first\n", res->port_id);
2527                 return;
2528         }
2529
2530         port = &ports[res->port_id];
2531
2532         isrx = !strcmp(res->rxtxq, "rxq");
2533
2534         if (isrx && rx_queue_id_is_invalid(res->qid))
2535                 return;
2536         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2537                 return;
2538
2539         ison = !strcmp(res->state, "on");
2540
2541         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2542                 port->rx_conf[res->qid].rx_deferred_start = ison;
2543                 needreconfig = 1;
2544         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2545                 port->tx_conf[res->qid].tx_deferred_start = ison;
2546                 needreconfig = 1;
2547         }
2548
2549         if (needreconfig)
2550                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2551 }
2552
2553 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2554         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2555                                                 port, "port");
2556 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2557         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2558                                                 port_id, UINT16);
2559 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2560         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2561                                                 rxtxq, "rxq#txq");
2562 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2563         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2564                                                 qid, UINT16);
2565 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2566         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2567                                                 opname, "deferred_start");
2568 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2569         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2570                                                 state, "on#off");
2571
2572 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2573         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2574         .data = NULL,
2575         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2576         .tokens = {
2577                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2578                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2579                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2580                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2581                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2582                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2583                 NULL,
2584         },
2585 };
2586
2587 /* *** configure port rxq/txq setup *** */
2588 struct cmd_setup_rxtx_queue {
2589         cmdline_fixed_string_t port;
2590         portid_t portid;
2591         cmdline_fixed_string_t rxtxq;
2592         uint16_t qid;
2593         cmdline_fixed_string_t setup;
2594 };
2595
2596 /* Common CLI fields for queue setup */
2597 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2598         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2599 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2600         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2601 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2602         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2603 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2604         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2605 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2606         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2607
2608 static void
2609 cmd_setup_rxtx_queue_parsed(
2610         void *parsed_result,
2611         __attribute__((unused)) struct cmdline *cl,
2612         __attribute__((unused)) void *data)
2613 {
2614         struct cmd_setup_rxtx_queue *res = parsed_result;
2615         struct rte_port *port;
2616         struct rte_mempool *mp;
2617         unsigned int socket_id;
2618         uint8_t isrx = 0;
2619         int ret;
2620
2621         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2622                 return;
2623
2624         if (res->portid == (portid_t)RTE_PORT_ALL) {
2625                 printf("Invalid port id\n");
2626                 return;
2627         }
2628
2629         if (!strcmp(res->rxtxq, "rxq"))
2630                 isrx = 1;
2631         else if (!strcmp(res->rxtxq, "txq"))
2632                 isrx = 0;
2633         else {
2634                 printf("Unknown parameter\n");
2635                 return;
2636         }
2637
2638         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2639                 printf("Invalid rx queue\n");
2640                 return;
2641         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2642                 printf("Invalid tx queue\n");
2643                 return;
2644         }
2645
2646         port = &ports[res->portid];
2647         if (isrx) {
2648                 socket_id = rxring_numa[res->portid];
2649                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2650                         socket_id = port->socket_id;
2651
2652                 mp = mbuf_pool_find(socket_id);
2653                 if (mp == NULL) {
2654                         printf("Failed to setup RX queue: "
2655                                 "No mempool allocation"
2656                                 " on the socket %d\n",
2657                                 rxring_numa[res->portid]);
2658                         return;
2659                 }
2660                 ret = rte_eth_rx_queue_setup(res->portid,
2661                                              res->qid,
2662                                              port->nb_rx_desc[res->qid],
2663                                              socket_id,
2664                                              &port->rx_conf[res->qid],
2665                                              mp);
2666                 if (ret)
2667                         printf("Failed to setup RX queue\n");
2668         } else {
2669                 socket_id = txring_numa[res->portid];
2670                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2671                         socket_id = port->socket_id;
2672
2673                 ret = rte_eth_tx_queue_setup(res->portid,
2674                                              res->qid,
2675                                              port->nb_tx_desc[res->qid],
2676                                              socket_id,
2677                                              &port->tx_conf[res->qid]);
2678                 if (ret)
2679                         printf("Failed to setup TX queue\n");
2680         }
2681 }
2682
2683 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2684         .f = cmd_setup_rxtx_queue_parsed,
2685         .data = NULL,
2686         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2687         .tokens = {
2688                 (void *)&cmd_setup_rxtx_queue_port,
2689                 (void *)&cmd_setup_rxtx_queue_portid,
2690                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2691                 (void *)&cmd_setup_rxtx_queue_qid,
2692                 (void *)&cmd_setup_rxtx_queue_setup,
2693                 NULL,
2694         },
2695 };
2696
2697
2698 /* *** Configure RSS RETA *** */
2699 struct cmd_config_rss_reta {
2700         cmdline_fixed_string_t port;
2701         cmdline_fixed_string_t keyword;
2702         portid_t port_id;
2703         cmdline_fixed_string_t name;
2704         cmdline_fixed_string_t list_name;
2705         cmdline_fixed_string_t list_of_items;
2706 };
2707
2708 static int
2709 parse_reta_config(const char *str,
2710                   struct rte_eth_rss_reta_entry64 *reta_conf,
2711                   uint16_t nb_entries)
2712 {
2713         int i;
2714         unsigned size;
2715         uint16_t hash_index, idx, shift;
2716         uint16_t nb_queue;
2717         char s[256];
2718         const char *p, *p0 = str;
2719         char *end;
2720         enum fieldnames {
2721                 FLD_HASH_INDEX = 0,
2722                 FLD_QUEUE,
2723                 _NUM_FLD
2724         };
2725         unsigned long int_fld[_NUM_FLD];
2726         char *str_fld[_NUM_FLD];
2727
2728         while ((p = strchr(p0,'(')) != NULL) {
2729                 ++p;
2730                 if((p0 = strchr(p,')')) == NULL)
2731                         return -1;
2732
2733                 size = p0 - p;
2734                 if(size >= sizeof(s))
2735                         return -1;
2736
2737                 snprintf(s, sizeof(s), "%.*s", size, p);
2738                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2739                         return -1;
2740                 for (i = 0; i < _NUM_FLD; i++) {
2741                         errno = 0;
2742                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2743                         if (errno != 0 || end == str_fld[i] ||
2744                                         int_fld[i] > 65535)
2745                                 return -1;
2746                 }
2747
2748                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2749                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2750
2751                 if (hash_index >= nb_entries) {
2752                         printf("Invalid RETA hash index=%d\n", hash_index);
2753                         return -1;
2754                 }
2755
2756                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2757                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2758                 reta_conf[idx].mask |= (1ULL << shift);
2759                 reta_conf[idx].reta[shift] = nb_queue;
2760         }
2761
2762         return 0;
2763 }
2764
2765 static void
2766 cmd_set_rss_reta_parsed(void *parsed_result,
2767                         __attribute__((unused)) struct cmdline *cl,
2768                         __attribute__((unused)) void *data)
2769 {
2770         int ret;
2771         struct rte_eth_dev_info dev_info;
2772         struct rte_eth_rss_reta_entry64 reta_conf[8];
2773         struct cmd_config_rss_reta *res = parsed_result;
2774
2775         memset(&dev_info, 0, sizeof(dev_info));
2776         rte_eth_dev_info_get(res->port_id, &dev_info);
2777         if (dev_info.reta_size == 0) {
2778                 printf("Redirection table size is 0 which is "
2779                                         "invalid for RSS\n");
2780                 return;
2781         } else
2782                 printf("The reta size of port %d is %u\n",
2783                         res->port_id, dev_info.reta_size);
2784         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2785                 printf("Currently do not support more than %u entries of "
2786                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2787                 return;
2788         }
2789
2790         memset(reta_conf, 0, sizeof(reta_conf));
2791         if (!strcmp(res->list_name, "reta")) {
2792                 if (parse_reta_config(res->list_of_items, reta_conf,
2793                                                 dev_info.reta_size)) {
2794                         printf("Invalid RSS Redirection Table "
2795                                         "config entered\n");
2796                         return;
2797                 }
2798                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2799                                 reta_conf, dev_info.reta_size);
2800                 if (ret != 0)
2801                         printf("Bad redirection table parameter, "
2802                                         "return code = %d \n", ret);
2803         }
2804 }
2805
2806 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2807         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2808 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2809         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2810 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2811         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2812 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2813         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2814 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2815         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2816 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2817         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2818                                  NULL);
2819 cmdline_parse_inst_t cmd_config_rss_reta = {
2820         .f = cmd_set_rss_reta_parsed,
2821         .data = NULL,
2822         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2823         .tokens = {
2824                 (void *)&cmd_config_rss_reta_port,
2825                 (void *)&cmd_config_rss_reta_keyword,
2826                 (void *)&cmd_config_rss_reta_port_id,
2827                 (void *)&cmd_config_rss_reta_name,
2828                 (void *)&cmd_config_rss_reta_list_name,
2829                 (void *)&cmd_config_rss_reta_list_of_items,
2830                 NULL,
2831         },
2832 };
2833
2834 /* *** SHOW PORT RETA INFO *** */
2835 struct cmd_showport_reta {
2836         cmdline_fixed_string_t show;
2837         cmdline_fixed_string_t port;
2838         portid_t port_id;
2839         cmdline_fixed_string_t rss;
2840         cmdline_fixed_string_t reta;
2841         uint16_t size;
2842         cmdline_fixed_string_t list_of_items;
2843 };
2844
2845 static int
2846 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2847                            uint16_t nb_entries,
2848                            char *str)
2849 {
2850         uint32_t size;
2851         const char *p, *p0 = str;
2852         char s[256];
2853         char *end;
2854         char *str_fld[8];
2855         uint16_t i;
2856         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2857                         RTE_RETA_GROUP_SIZE;
2858         int ret;
2859
2860         p = strchr(p0, '(');
2861         if (p == NULL)
2862                 return -1;
2863         p++;
2864         p0 = strchr(p, ')');
2865         if (p0 == NULL)
2866                 return -1;
2867         size = p0 - p;
2868         if (size >= sizeof(s)) {
2869                 printf("The string size exceeds the internal buffer size\n");
2870                 return -1;
2871         }
2872         snprintf(s, sizeof(s), "%.*s", size, p);
2873         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2874         if (ret <= 0 || ret != num) {
2875                 printf("The bits of masks do not match the number of "
2876                                         "reta entries: %u\n", num);
2877                 return -1;
2878         }
2879         for (i = 0; i < ret; i++)
2880                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2881
2882         return 0;
2883 }
2884
2885 static void
2886 cmd_showport_reta_parsed(void *parsed_result,
2887                          __attribute__((unused)) struct cmdline *cl,
2888                          __attribute__((unused)) void *data)
2889 {
2890         struct cmd_showport_reta *res = parsed_result;
2891         struct rte_eth_rss_reta_entry64 reta_conf[8];
2892         struct rte_eth_dev_info dev_info;
2893         uint16_t max_reta_size;
2894
2895         memset(&dev_info, 0, sizeof(dev_info));
2896         rte_eth_dev_info_get(res->port_id, &dev_info);
2897         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2898         if (res->size == 0 || res->size > max_reta_size) {
2899                 printf("Invalid redirection table size: %u (1-%u)\n",
2900                         res->size, max_reta_size);
2901                 return;
2902         }
2903
2904         memset(reta_conf, 0, sizeof(reta_conf));
2905         if (showport_parse_reta_config(reta_conf, res->size,
2906                                 res->list_of_items) < 0) {
2907                 printf("Invalid string: %s for reta masks\n",
2908                                         res->list_of_items);
2909                 return;
2910         }
2911         port_rss_reta_info(res->port_id, reta_conf, res->size);
2912 }
2913
2914 cmdline_parse_token_string_t cmd_showport_reta_show =
2915         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2916 cmdline_parse_token_string_t cmd_showport_reta_port =
2917         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2918 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2919         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2920 cmdline_parse_token_string_t cmd_showport_reta_rss =
2921         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2922 cmdline_parse_token_string_t cmd_showport_reta_reta =
2923         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2924 cmdline_parse_token_num_t cmd_showport_reta_size =
2925         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2926 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2927         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2928                                         list_of_items, NULL);
2929
2930 cmdline_parse_inst_t cmd_showport_reta = {
2931         .f = cmd_showport_reta_parsed,
2932         .data = NULL,
2933         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2934         .tokens = {
2935                 (void *)&cmd_showport_reta_show,
2936                 (void *)&cmd_showport_reta_port,
2937                 (void *)&cmd_showport_reta_port_id,
2938                 (void *)&cmd_showport_reta_rss,
2939                 (void *)&cmd_showport_reta_reta,
2940                 (void *)&cmd_showport_reta_size,
2941                 (void *)&cmd_showport_reta_list_of_items,
2942                 NULL,
2943         },
2944 };
2945
2946 /* *** Show RSS hash configuration *** */
2947 struct cmd_showport_rss_hash {
2948         cmdline_fixed_string_t show;
2949         cmdline_fixed_string_t port;
2950         portid_t port_id;
2951         cmdline_fixed_string_t rss_hash;
2952         cmdline_fixed_string_t rss_type;
2953         cmdline_fixed_string_t key; /* optional argument */
2954 };
2955
2956 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2957                                 __attribute__((unused)) struct cmdline *cl,
2958                                 void *show_rss_key)
2959 {
2960         struct cmd_showport_rss_hash *res = parsed_result;
2961
2962         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
2963 }
2964
2965 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2966         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2967 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2968         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2969 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2970         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2971 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2972         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2973                                  "rss-hash");
2974 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2975         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2976
2977 cmdline_parse_inst_t cmd_showport_rss_hash = {
2978         .f = cmd_showport_rss_hash_parsed,
2979         .data = NULL,
2980         .help_str = "show port <port_id> rss-hash",
2981         .tokens = {
2982                 (void *)&cmd_showport_rss_hash_show,
2983                 (void *)&cmd_showport_rss_hash_port,
2984                 (void *)&cmd_showport_rss_hash_port_id,
2985                 (void *)&cmd_showport_rss_hash_rss_hash,
2986                 NULL,
2987         },
2988 };
2989
2990 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2991         .f = cmd_showport_rss_hash_parsed,
2992         .data = (void *)1,
2993         .help_str = "show port <port_id> rss-hash key",
2994         .tokens = {
2995                 (void *)&cmd_showport_rss_hash_show,
2996                 (void *)&cmd_showport_rss_hash_port,
2997                 (void *)&cmd_showport_rss_hash_port_id,
2998                 (void *)&cmd_showport_rss_hash_rss_hash,
2999                 (void *)&cmd_showport_rss_hash_rss_key,
3000                 NULL,
3001         },
3002 };
3003
3004 /* *** Configure DCB *** */
3005 struct cmd_config_dcb {
3006         cmdline_fixed_string_t port;
3007         cmdline_fixed_string_t config;
3008         portid_t port_id;
3009         cmdline_fixed_string_t dcb;
3010         cmdline_fixed_string_t vt;
3011         cmdline_fixed_string_t vt_en;
3012         uint8_t num_tcs;
3013         cmdline_fixed_string_t pfc;
3014         cmdline_fixed_string_t pfc_en;
3015 };
3016
3017 static void
3018 cmd_config_dcb_parsed(void *parsed_result,
3019                         __attribute__((unused)) struct cmdline *cl,
3020                         __attribute__((unused)) void *data)
3021 {
3022         struct cmd_config_dcb *res = parsed_result;
3023         portid_t port_id = res->port_id;
3024         struct rte_port *port;
3025         uint8_t pfc_en;
3026         int ret;
3027
3028         port = &ports[port_id];
3029         /** Check if the port is not started **/
3030         if (port->port_status != RTE_PORT_STOPPED) {
3031                 printf("Please stop port %d first\n", port_id);
3032                 return;
3033         }
3034
3035         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3036                 printf("The invalid number of traffic class,"
3037                         " only 4 or 8 allowed.\n");
3038                 return;
3039         }
3040
3041         if (nb_fwd_lcores < res->num_tcs) {
3042                 printf("nb_cores shouldn't be less than number of TCs.\n");
3043                 return;
3044         }
3045         if (!strncmp(res->pfc_en, "on", 2))
3046                 pfc_en = 1;
3047         else
3048                 pfc_en = 0;
3049
3050         /* DCB in VT mode */
3051         if (!strncmp(res->vt_en, "on", 2))
3052                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3053                                 (enum rte_eth_nb_tcs)res->num_tcs,
3054                                 pfc_en);
3055         else
3056                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3057                                 (enum rte_eth_nb_tcs)res->num_tcs,
3058                                 pfc_en);
3059
3060
3061         if (ret != 0) {
3062                 printf("Cannot initialize network ports.\n");
3063                 return;
3064         }
3065
3066         cmd_reconfig_device_queue(port_id, 1, 1);
3067 }
3068
3069 cmdline_parse_token_string_t cmd_config_dcb_port =
3070         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3071 cmdline_parse_token_string_t cmd_config_dcb_config =
3072         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3073 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3074         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3075 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3076         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3077 cmdline_parse_token_string_t cmd_config_dcb_vt =
3078         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3079 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3080         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3081 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3082         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3083 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3084         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3085 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3086         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3087
3088 cmdline_parse_inst_t cmd_config_dcb = {
3089         .f = cmd_config_dcb_parsed,
3090         .data = NULL,
3091         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3092         .tokens = {
3093                 (void *)&cmd_config_dcb_port,
3094                 (void *)&cmd_config_dcb_config,
3095                 (void *)&cmd_config_dcb_port_id,
3096                 (void *)&cmd_config_dcb_dcb,
3097                 (void *)&cmd_config_dcb_vt,
3098                 (void *)&cmd_config_dcb_vt_en,
3099                 (void *)&cmd_config_dcb_num_tcs,
3100                 (void *)&cmd_config_dcb_pfc,
3101                 (void *)&cmd_config_dcb_pfc_en,
3102                 NULL,
3103         },
3104 };
3105
3106 /* *** configure number of packets per burst *** */
3107 struct cmd_config_burst {
3108         cmdline_fixed_string_t port;
3109         cmdline_fixed_string_t keyword;
3110         cmdline_fixed_string_t all;
3111         cmdline_fixed_string_t name;
3112         uint16_t value;
3113 };
3114
3115 static void
3116 cmd_config_burst_parsed(void *parsed_result,
3117                         __attribute__((unused)) struct cmdline *cl,
3118                         __attribute__((unused)) void *data)
3119 {
3120         struct cmd_config_burst *res = parsed_result;
3121         struct rte_eth_dev_info dev_info;
3122         uint16_t rec_nb_pkts;
3123
3124         if (!all_ports_stopped()) {
3125                 printf("Please stop all ports first\n");
3126                 return;
3127         }
3128
3129         if (!strcmp(res->name, "burst")) {
3130                 if (res->value == 0) {
3131                         /* If user gives a value of zero, query the PMD for
3132                          * its recommended Rx burst size. Testpmd uses a single
3133                          * size for all ports, so assume all ports are the same
3134                          * NIC model and use the values from Port 0.
3135                          */
3136                         rte_eth_dev_info_get(0, &dev_info);
3137                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3138
3139                         if (rec_nb_pkts == 0) {
3140                                 printf("PMD does not recommend a burst size.\n"
3141                                         "User provided value must be between"
3142                                         " 1 and %d\n", MAX_PKT_BURST);
3143                                 return;
3144                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3145                                 printf("PMD recommended burst size of %d"
3146                                         " exceeds maximum value of %d\n",
3147                                         rec_nb_pkts, MAX_PKT_BURST);
3148                                 return;
3149                         }
3150                         printf("Using PMD-provided burst value of %d\n",
3151                                 rec_nb_pkts);
3152                         nb_pkt_per_burst = rec_nb_pkts;
3153                 } else if (res->value > MAX_PKT_BURST) {
3154                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3155                         return;
3156                 } else
3157                         nb_pkt_per_burst = res->value;
3158         } else {
3159                 printf("Unknown parameter\n");
3160                 return;
3161         }
3162
3163         init_port_config();
3164
3165         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3166 }
3167
3168 cmdline_parse_token_string_t cmd_config_burst_port =
3169         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3170 cmdline_parse_token_string_t cmd_config_burst_keyword =
3171         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3172 cmdline_parse_token_string_t cmd_config_burst_all =
3173         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3174 cmdline_parse_token_string_t cmd_config_burst_name =
3175         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3176 cmdline_parse_token_num_t cmd_config_burst_value =
3177         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3178
3179 cmdline_parse_inst_t cmd_config_burst = {
3180         .f = cmd_config_burst_parsed,
3181         .data = NULL,
3182         .help_str = "port config all burst <value>",
3183         .tokens = {
3184                 (void *)&cmd_config_burst_port,
3185                 (void *)&cmd_config_burst_keyword,
3186                 (void *)&cmd_config_burst_all,
3187                 (void *)&cmd_config_burst_name,
3188                 (void *)&cmd_config_burst_value,
3189                 NULL,
3190         },
3191 };
3192
3193 /* *** configure rx/tx queues *** */
3194 struct cmd_config_thresh {
3195         cmdline_fixed_string_t port;
3196         cmdline_fixed_string_t keyword;
3197         cmdline_fixed_string_t all;
3198         cmdline_fixed_string_t name;
3199         uint8_t value;
3200 };
3201
3202 static void
3203 cmd_config_thresh_parsed(void *parsed_result,
3204                         __attribute__((unused)) struct cmdline *cl,
3205                         __attribute__((unused)) void *data)
3206 {
3207         struct cmd_config_thresh *res = parsed_result;
3208
3209         if (!all_ports_stopped()) {
3210                 printf("Please stop all ports first\n");
3211                 return;
3212         }
3213
3214         if (!strcmp(res->name, "txpt"))
3215                 tx_pthresh = res->value;
3216         else if(!strcmp(res->name, "txht"))
3217                 tx_hthresh = res->value;
3218         else if(!strcmp(res->name, "txwt"))
3219                 tx_wthresh = res->value;
3220         else if(!strcmp(res->name, "rxpt"))
3221                 rx_pthresh = res->value;
3222         else if(!strcmp(res->name, "rxht"))
3223                 rx_hthresh = res->value;
3224         else if(!strcmp(res->name, "rxwt"))
3225                 rx_wthresh = res->value;
3226         else {
3227                 printf("Unknown parameter\n");
3228                 return;
3229         }
3230
3231         init_port_config();
3232
3233         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3234 }
3235
3236 cmdline_parse_token_string_t cmd_config_thresh_port =
3237         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3238 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3239         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3240 cmdline_parse_token_string_t cmd_config_thresh_all =
3241         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3242 cmdline_parse_token_string_t cmd_config_thresh_name =
3243         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3244                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3245 cmdline_parse_token_num_t cmd_config_thresh_value =
3246         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3247
3248 cmdline_parse_inst_t cmd_config_thresh = {
3249         .f = cmd_config_thresh_parsed,
3250         .data = NULL,
3251         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3252         .tokens = {
3253                 (void *)&cmd_config_thresh_port,
3254                 (void *)&cmd_config_thresh_keyword,
3255                 (void *)&cmd_config_thresh_all,
3256                 (void *)&cmd_config_thresh_name,
3257                 (void *)&cmd_config_thresh_value,
3258                 NULL,
3259         },
3260 };
3261
3262 /* *** configure free/rs threshold *** */
3263 struct cmd_config_threshold {
3264         cmdline_fixed_string_t port;
3265         cmdline_fixed_string_t keyword;
3266         cmdline_fixed_string_t all;
3267         cmdline_fixed_string_t name;
3268         uint16_t value;
3269 };
3270
3271 static void
3272 cmd_config_threshold_parsed(void *parsed_result,
3273                         __attribute__((unused)) struct cmdline *cl,
3274                         __attribute__((unused)) void *data)
3275 {
3276         struct cmd_config_threshold *res = parsed_result;
3277
3278         if (!all_ports_stopped()) {
3279                 printf("Please stop all ports first\n");
3280                 return;
3281         }
3282
3283         if (!strcmp(res->name, "txfreet"))
3284                 tx_free_thresh = res->value;
3285         else if (!strcmp(res->name, "txrst"))
3286                 tx_rs_thresh = res->value;
3287         else if (!strcmp(res->name, "rxfreet"))
3288                 rx_free_thresh = res->value;
3289         else {
3290                 printf("Unknown parameter\n");
3291                 return;
3292         }
3293
3294         init_port_config();
3295
3296         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3297 }
3298
3299 cmdline_parse_token_string_t cmd_config_threshold_port =
3300         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3301 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3302         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3303                                                                 "config");
3304 cmdline_parse_token_string_t cmd_config_threshold_all =
3305         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3306 cmdline_parse_token_string_t cmd_config_threshold_name =
3307         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3308                                                 "txfreet#txrst#rxfreet");
3309 cmdline_parse_token_num_t cmd_config_threshold_value =
3310         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3311
3312 cmdline_parse_inst_t cmd_config_threshold = {
3313         .f = cmd_config_threshold_parsed,
3314         .data = NULL,
3315         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3316         .tokens = {
3317                 (void *)&cmd_config_threshold_port,
3318                 (void *)&cmd_config_threshold_keyword,
3319                 (void *)&cmd_config_threshold_all,
3320                 (void *)&cmd_config_threshold_name,
3321                 (void *)&cmd_config_threshold_value,
3322                 NULL,
3323         },
3324 };
3325
3326 /* *** stop *** */
3327 struct cmd_stop_result {
3328         cmdline_fixed_string_t stop;
3329 };
3330
3331 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3332                             __attribute__((unused)) struct cmdline *cl,
3333                             __attribute__((unused)) void *data)
3334 {
3335         stop_packet_forwarding();
3336 }
3337
3338 cmdline_parse_token_string_t cmd_stop_stop =
3339         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3340
3341 cmdline_parse_inst_t cmd_stop = {
3342         .f = cmd_stop_parsed,
3343         .data = NULL,
3344         .help_str = "stop: Stop packet forwarding",
3345         .tokens = {
3346                 (void *)&cmd_stop_stop,
3347                 NULL,
3348         },
3349 };
3350
3351 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3352
3353 unsigned int
3354 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3355                 unsigned int *parsed_items, int check_unique_values)
3356 {
3357         unsigned int nb_item;
3358         unsigned int value;
3359         unsigned int i;
3360         unsigned int j;
3361         int value_ok;
3362         char c;
3363
3364         /*
3365          * First parse all items in the list and store their value.
3366          */
3367         value = 0;
3368         nb_item = 0;
3369         value_ok = 0;
3370         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3371                 c = str[i];
3372                 if ((c >= '0') && (c <= '9')) {
3373                         value = (unsigned int) (value * 10 + (c - '0'));
3374                         value_ok = 1;
3375                         continue;
3376                 }
3377                 if (c != ',') {
3378                         printf("character %c is not a decimal digit\n", c);
3379                         return 0;
3380                 }
3381                 if (! value_ok) {
3382                         printf("No valid value before comma\n");
3383                         return 0;
3384                 }
3385                 if (nb_item < max_items) {
3386                         parsed_items[nb_item] = value;
3387                         value_ok = 0;
3388                         value = 0;
3389                 }
3390                 nb_item++;
3391         }
3392         if (nb_item >= max_items) {
3393                 printf("Number of %s = %u > %u (maximum items)\n",
3394                        item_name, nb_item + 1, max_items);
3395                 return 0;
3396         }
3397         parsed_items[nb_item++] = value;
3398         if (! check_unique_values)
3399                 return nb_item;
3400
3401         /*
3402          * Then, check that all values in the list are differents.
3403          * No optimization here...
3404          */
3405         for (i = 0; i < nb_item; i++) {
3406                 for (j = i + 1; j < nb_item; j++) {
3407                         if (parsed_items[j] == parsed_items[i]) {
3408                                 printf("duplicated %s %u at index %u and %u\n",
3409                                        item_name, parsed_items[i], i, j);
3410                                 return 0;
3411                         }
3412                 }
3413         }
3414         return nb_item;
3415 }
3416
3417 struct cmd_set_list_result {
3418         cmdline_fixed_string_t cmd_keyword;
3419         cmdline_fixed_string_t list_name;
3420         cmdline_fixed_string_t list_of_items;
3421 };
3422
3423 static void cmd_set_list_parsed(void *parsed_result,
3424                                 __attribute__((unused)) struct cmdline *cl,
3425                                 __attribute__((unused)) void *data)
3426 {
3427         struct cmd_set_list_result *res;
3428         union {
3429                 unsigned int lcorelist[RTE_MAX_LCORE];
3430                 unsigned int portlist[RTE_MAX_ETHPORTS];
3431         } parsed_items;
3432         unsigned int nb_item;
3433
3434         if (test_done == 0) {
3435                 printf("Please stop forwarding first\n");
3436                 return;
3437         }
3438
3439         res = parsed_result;
3440         if (!strcmp(res->list_name, "corelist")) {
3441                 nb_item = parse_item_list(res->list_of_items, "core",
3442                                           RTE_MAX_LCORE,
3443                                           parsed_items.lcorelist, 1);
3444                 if (nb_item > 0) {
3445                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3446                         fwd_config_setup();
3447                 }
3448                 return;
3449         }
3450         if (!strcmp(res->list_name, "portlist")) {
3451                 nb_item = parse_item_list(res->list_of_items, "port",
3452                                           RTE_MAX_ETHPORTS,
3453                                           parsed_items.portlist, 1);
3454                 if (nb_item > 0) {
3455                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3456                         fwd_config_setup();
3457                 }
3458         }
3459 }
3460
3461 cmdline_parse_token_string_t cmd_set_list_keyword =
3462         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3463                                  "set");
3464 cmdline_parse_token_string_t cmd_set_list_name =
3465         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3466                                  "corelist#portlist");
3467 cmdline_parse_token_string_t cmd_set_list_of_items =
3468         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3469                                  NULL);
3470
3471 cmdline_parse_inst_t cmd_set_fwd_list = {
3472         .f = cmd_set_list_parsed,
3473         .data = NULL,
3474         .help_str = "set corelist|portlist <list0[,list1]*>",
3475         .tokens = {
3476                 (void *)&cmd_set_list_keyword,
3477                 (void *)&cmd_set_list_name,
3478                 (void *)&cmd_set_list_of_items,
3479                 NULL,
3480         },
3481 };
3482
3483 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3484
3485 struct cmd_setmask_result {
3486         cmdline_fixed_string_t set;
3487         cmdline_fixed_string_t mask;
3488         uint64_t hexavalue;
3489 };
3490
3491 static void cmd_set_mask_parsed(void *parsed_result,
3492                                 __attribute__((unused)) struct cmdline *cl,
3493                                 __attribute__((unused)) void *data)
3494 {
3495         struct cmd_setmask_result *res = parsed_result;
3496
3497         if (test_done == 0) {
3498                 printf("Please stop forwarding first\n");
3499                 return;
3500         }
3501         if (!strcmp(res->mask, "coremask")) {
3502                 set_fwd_lcores_mask(res->hexavalue);
3503                 fwd_config_setup();
3504         } else if (!strcmp(res->mask, "portmask")) {
3505                 set_fwd_ports_mask(res->hexavalue);
3506                 fwd_config_setup();
3507         }
3508 }
3509
3510 cmdline_parse_token_string_t cmd_setmask_set =
3511         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3512 cmdline_parse_token_string_t cmd_setmask_mask =
3513         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3514                                  "coremask#portmask");
3515 cmdline_parse_token_num_t cmd_setmask_value =
3516         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3517
3518 cmdline_parse_inst_t cmd_set_fwd_mask = {
3519         .f = cmd_set_mask_parsed,
3520         .data = NULL,
3521         .help_str = "set coremask|portmask <hexadecimal value>",
3522         .tokens = {
3523                 (void *)&cmd_setmask_set,
3524                 (void *)&cmd_setmask_mask,
3525                 (void *)&cmd_setmask_value,
3526                 NULL,
3527         },
3528 };
3529
3530 /*
3531  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3532  */
3533 struct cmd_set_result {
3534         cmdline_fixed_string_t set;
3535         cmdline_fixed_string_t what;
3536         uint16_t value;
3537 };
3538
3539 static void cmd_set_parsed(void *parsed_result,
3540                            __attribute__((unused)) struct cmdline *cl,
3541                            __attribute__((unused)) void *data)
3542 {
3543         struct cmd_set_result *res = parsed_result;
3544         if (!strcmp(res->what, "nbport")) {
3545                 set_fwd_ports_number(res->value);
3546                 fwd_config_setup();
3547         } else if (!strcmp(res->what, "nbcore")) {
3548                 set_fwd_lcores_number(res->value);
3549                 fwd_config_setup();
3550         } else if (!strcmp(res->what, "burst"))
3551                 set_nb_pkt_per_burst(res->value);
3552         else if (!strcmp(res->what, "verbose"))
3553                 set_verbose_level(res->value);
3554 }
3555
3556 cmdline_parse_token_string_t cmd_set_set =
3557         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3558 cmdline_parse_token_string_t cmd_set_what =
3559         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3560                                  "nbport#nbcore#burst#verbose");
3561 cmdline_parse_token_num_t cmd_set_value =
3562         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3563
3564 cmdline_parse_inst_t cmd_set_numbers = {
3565         .f = cmd_set_parsed,
3566         .data = NULL,
3567         .help_str = "set nbport|nbcore|burst|verbose <value>",
3568         .tokens = {
3569                 (void *)&cmd_set_set,
3570                 (void *)&cmd_set_what,
3571                 (void *)&cmd_set_value,
3572                 NULL,
3573         },
3574 };
3575
3576 /* *** SET LOG LEVEL CONFIGURATION *** */
3577
3578 struct cmd_set_log_result {
3579         cmdline_fixed_string_t set;
3580         cmdline_fixed_string_t log;
3581         cmdline_fixed_string_t type;
3582         uint32_t level;
3583 };
3584
3585 static void
3586 cmd_set_log_parsed(void *parsed_result,
3587                    __attribute__((unused)) struct cmdline *cl,
3588                    __attribute__((unused)) void *data)
3589 {
3590         struct cmd_set_log_result *res;
3591         int ret;
3592
3593         res = parsed_result;
3594         if (!strcmp(res->type, "global"))
3595                 rte_log_set_global_level(res->level);
3596         else {
3597                 ret = rte_log_set_level_regexp(res->type, res->level);
3598                 if (ret < 0)
3599                         printf("Unable to set log level\n");
3600         }
3601 }
3602
3603 cmdline_parse_token_string_t cmd_set_log_set =
3604         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3605 cmdline_parse_token_string_t cmd_set_log_log =
3606         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3607 cmdline_parse_token_string_t cmd_set_log_type =
3608         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3609 cmdline_parse_token_num_t cmd_set_log_level =
3610         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3611
3612 cmdline_parse_inst_t cmd_set_log = {
3613         .f = cmd_set_log_parsed,
3614         .data = NULL,
3615         .help_str = "set log global|<type> <level>",
3616         .tokens = {
3617                 (void *)&cmd_set_log_set,
3618                 (void *)&cmd_set_log_log,
3619                 (void *)&cmd_set_log_type,
3620                 (void *)&cmd_set_log_level,
3621                 NULL,
3622         },
3623 };
3624
3625 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3626
3627 struct cmd_set_txpkts_result {
3628         cmdline_fixed_string_t cmd_keyword;
3629         cmdline_fixed_string_t txpkts;
3630         cmdline_fixed_string_t seg_lengths;
3631 };
3632
3633 static void
3634 cmd_set_txpkts_parsed(void *parsed_result,
3635                       __attribute__((unused)) struct cmdline *cl,
3636                       __attribute__((unused)) void *data)
3637 {
3638         struct cmd_set_txpkts_result *res;
3639         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3640         unsigned int nb_segs;
3641
3642         res = parsed_result;
3643         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3644                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3645         if (nb_segs > 0)
3646                 set_tx_pkt_segments(seg_lengths, nb_segs);
3647 }
3648
3649 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3650         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3651                                  cmd_keyword, "set");
3652 cmdline_parse_token_string_t cmd_set_txpkts_name =
3653         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3654                                  txpkts, "txpkts");
3655 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3656         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3657                                  seg_lengths, NULL);
3658
3659 cmdline_parse_inst_t cmd_set_txpkts = {
3660         .f = cmd_set_txpkts_parsed,
3661         .data = NULL,
3662         .help_str = "set txpkts <len0[,len1]*>",
3663         .tokens = {
3664                 (void *)&cmd_set_txpkts_keyword,
3665                 (void *)&cmd_set_txpkts_name,
3666                 (void *)&cmd_set_txpkts_lengths,
3667                 NULL,
3668         },
3669 };
3670
3671 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3672
3673 struct cmd_set_txsplit_result {
3674         cmdline_fixed_string_t cmd_keyword;
3675         cmdline_fixed_string_t txsplit;
3676         cmdline_fixed_string_t mode;
3677 };
3678
3679 static void
3680 cmd_set_txsplit_parsed(void *parsed_result,
3681                       __attribute__((unused)) struct cmdline *cl,
3682                       __attribute__((unused)) void *data)
3683 {
3684         struct cmd_set_txsplit_result *res;
3685
3686         res = parsed_result;
3687         set_tx_pkt_split(res->mode);
3688 }
3689
3690 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3691         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3692                                  cmd_keyword, "set");
3693 cmdline_parse_token_string_t cmd_set_txsplit_name =
3694         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3695                                  txsplit, "txsplit");
3696 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3697         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3698                                  mode, NULL);
3699
3700 cmdline_parse_inst_t cmd_set_txsplit = {
3701         .f = cmd_set_txsplit_parsed,
3702         .data = NULL,
3703         .help_str = "set txsplit on|off|rand",
3704         .tokens = {
3705                 (void *)&cmd_set_txsplit_keyword,
3706                 (void *)&cmd_set_txsplit_name,
3707                 (void *)&cmd_set_txsplit_mode,
3708                 NULL,
3709         },
3710 };
3711
3712 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3713 struct cmd_rx_vlan_filter_all_result {
3714         cmdline_fixed_string_t rx_vlan;
3715         cmdline_fixed_string_t what;
3716         cmdline_fixed_string_t all;
3717         portid_t port_id;
3718 };
3719
3720 static void
3721 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3722                               __attribute__((unused)) struct cmdline *cl,
3723                               __attribute__((unused)) void *data)
3724 {
3725         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3726
3727         if (!strcmp(res->what, "add"))
3728                 rx_vlan_all_filter_set(res->port_id, 1);
3729         else
3730                 rx_vlan_all_filter_set(res->port_id, 0);
3731 }
3732
3733 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3734         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3735                                  rx_vlan, "rx_vlan");
3736 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3737         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3738                                  what, "add#rm");
3739 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3740         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3741                                  all, "all");
3742 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3743         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3744                               port_id, UINT16);
3745
3746 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3747         .f = cmd_rx_vlan_filter_all_parsed,
3748         .data = NULL,
3749         .help_str = "rx_vlan add|rm all <port_id>: "
3750                 "Add/Remove all identifiers to/from the set of VLAN "
3751                 "identifiers filtered by a port",
3752         .tokens = {
3753                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3754                 (void *)&cmd_rx_vlan_filter_all_what,
3755                 (void *)&cmd_rx_vlan_filter_all_all,
3756                 (void *)&cmd_rx_vlan_filter_all_portid,
3757                 NULL,
3758         },
3759 };
3760
3761 /* *** VLAN OFFLOAD SET ON A PORT *** */
3762 struct cmd_vlan_offload_result {
3763         cmdline_fixed_string_t vlan;
3764         cmdline_fixed_string_t set;
3765         cmdline_fixed_string_t vlan_type;
3766         cmdline_fixed_string_t what;
3767         cmdline_fixed_string_t on;
3768         cmdline_fixed_string_t port_id;
3769 };
3770
3771 static void
3772 cmd_vlan_offload_parsed(void *parsed_result,
3773                           __attribute__((unused)) struct cmdline *cl,
3774                           __attribute__((unused)) void *data)
3775 {
3776         int on;
3777         struct cmd_vlan_offload_result *res = parsed_result;
3778         char *str;
3779         int i, len = 0;
3780         portid_t port_id = 0;
3781         unsigned int tmp;
3782
3783         str = res->port_id;
3784         len = strnlen(str, STR_TOKEN_SIZE);
3785         i = 0;
3786         /* Get port_id first */
3787         while(i < len){
3788                 if(str[i] == ',')
3789                         break;
3790
3791                 i++;
3792         }
3793         str[i]='\0';
3794         tmp = strtoul(str, NULL, 0);
3795         /* If port_id greater that what portid_t can represent, return */
3796         if(tmp >= RTE_MAX_ETHPORTS)
3797                 return;
3798         port_id = (portid_t)tmp;
3799
3800         if (!strcmp(res->on, "on"))
3801                 on = 1;
3802         else
3803                 on = 0;
3804
3805         if (!strcmp(res->what, "strip"))
3806                 rx_vlan_strip_set(port_id,  on);
3807         else if(!strcmp(res->what, "stripq")){
3808                 uint16_t queue_id = 0;
3809
3810                 /* No queue_id, return */
3811                 if(i + 1 >= len) {
3812                         printf("must specify (port,queue_id)\n");
3813                         return;
3814                 }
3815                 tmp = strtoul(str + i + 1, NULL, 0);
3816                 /* If queue_id greater that what 16-bits can represent, return */
3817                 if(tmp > 0xffff)
3818                         return;
3819
3820                 queue_id = (uint16_t)tmp;
3821                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3822         }
3823         else if (!strcmp(res->what, "filter"))
3824                 rx_vlan_filter_set(port_id, on);
3825         else
3826                 vlan_extend_set(port_id, on);
3827
3828         return;
3829 }
3830
3831 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3832         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3833                                  vlan, "vlan");
3834 cmdline_parse_token_string_t cmd_vlan_offload_set =
3835         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3836                                  set, "set");
3837 cmdline_parse_token_string_t cmd_vlan_offload_what =
3838         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3839                                  what, "strip#filter#qinq#stripq");
3840 cmdline_parse_token_string_t cmd_vlan_offload_on =
3841         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3842                               on, "on#off");
3843 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3844         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3845                               port_id, NULL);
3846
3847 cmdline_parse_inst_t cmd_vlan_offload = {
3848         .f = cmd_vlan_offload_parsed,
3849         .data = NULL,
3850         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3851                 "<port_id[,queue_id]>: "
3852                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3853         .tokens = {
3854                 (void *)&cmd_vlan_offload_vlan,
3855                 (void *)&cmd_vlan_offload_set,
3856                 (void *)&cmd_vlan_offload_what,
3857                 (void *)&cmd_vlan_offload_on,
3858                 (void *)&cmd_vlan_offload_portid,
3859                 NULL,
3860         },
3861 };
3862
3863 /* *** VLAN TPID SET ON A PORT *** */
3864 struct cmd_vlan_tpid_result {
3865         cmdline_fixed_string_t vlan;
3866         cmdline_fixed_string_t set;
3867         cmdline_fixed_string_t vlan_type;
3868         cmdline_fixed_string_t what;
3869         uint16_t tp_id;
3870         portid_t port_id;
3871 };
3872
3873 static void
3874 cmd_vlan_tpid_parsed(void *parsed_result,
3875                           __attribute__((unused)) struct cmdline *cl,
3876                           __attribute__((unused)) void *data)
3877 {
3878         struct cmd_vlan_tpid_result *res = parsed_result;
3879         enum rte_vlan_type vlan_type;
3880
3881         if (!strcmp(res->vlan_type, "inner"))
3882                 vlan_type = ETH_VLAN_TYPE_INNER;
3883         else if (!strcmp(res->vlan_type, "outer"))
3884                 vlan_type = ETH_VLAN_TYPE_OUTER;
3885         else {
3886                 printf("Unknown vlan type\n");
3887                 return;
3888         }
3889         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3890 }
3891
3892 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3893         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3894                                  vlan, "vlan");
3895 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3896         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3897                                  set, "set");
3898 cmdline_parse_token_string_t cmd_vlan_type =
3899         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3900                                  vlan_type, "inner#outer");
3901 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3902         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3903                                  what, "tpid");
3904 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3905         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3906                               tp_id, UINT16);
3907 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3908         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3909                               port_id, UINT16);
3910
3911 cmdline_parse_inst_t cmd_vlan_tpid = {
3912         .f = cmd_vlan_tpid_parsed,
3913         .data = NULL,
3914         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3915                 "Set the VLAN Ether type",
3916         .tokens = {
3917                 (void *)&cmd_vlan_tpid_vlan,
3918                 (void *)&cmd_vlan_tpid_set,
3919                 (void *)&cmd_vlan_type,
3920                 (void *)&cmd_vlan_tpid_what,
3921                 (void *)&cmd_vlan_tpid_tpid,
3922                 (void *)&cmd_vlan_tpid_portid,
3923                 NULL,
3924         },
3925 };
3926
3927 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3928 struct cmd_rx_vlan_filter_result {
3929         cmdline_fixed_string_t rx_vlan;
3930         cmdline_fixed_string_t what;
3931         uint16_t vlan_id;
3932         portid_t port_id;
3933 };
3934
3935 static void
3936 cmd_rx_vlan_filter_parsed(void *parsed_result,
3937                           __attribute__((unused)) struct cmdline *cl,
3938                           __attribute__((unused)) void *data)
3939 {
3940         struct cmd_rx_vlan_filter_result *res = parsed_result;
3941
3942         if (!strcmp(res->what, "add"))
3943                 rx_vft_set(res->port_id, res->vlan_id, 1);
3944         else
3945                 rx_vft_set(res->port_id, res->vlan_id, 0);
3946 }
3947
3948 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3949         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3950                                  rx_vlan, "rx_vlan");
3951 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3952         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3953                                  what, "add#rm");
3954 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3955         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3956                               vlan_id, UINT16);
3957 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3958         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3959                               port_id, UINT16);
3960
3961 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3962         .f = cmd_rx_vlan_filter_parsed,
3963         .data = NULL,
3964         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3965                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3966                 "identifiers filtered by a port",
3967         .tokens = {
3968                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3969                 (void *)&cmd_rx_vlan_filter_what,
3970                 (void *)&cmd_rx_vlan_filter_vlanid,
3971                 (void *)&cmd_rx_vlan_filter_portid,
3972                 NULL,
3973         },
3974 };
3975
3976 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3977 struct cmd_tx_vlan_set_result {
3978         cmdline_fixed_string_t tx_vlan;
3979         cmdline_fixed_string_t set;
3980         portid_t port_id;
3981         uint16_t vlan_id;
3982 };
3983
3984 static void
3985 cmd_tx_vlan_set_parsed(void *parsed_result,
3986                        __attribute__((unused)) struct cmdline *cl,
3987                        __attribute__((unused)) void *data)
3988 {
3989         struct cmd_tx_vlan_set_result *res = parsed_result;
3990
3991         if (!port_is_stopped(res->port_id)) {
3992                 printf("Please stop port %d first\n", res->port_id);
3993                 return;
3994         }
3995
3996         tx_vlan_set(res->port_id, res->vlan_id);
3997
3998         cmd_reconfig_device_queue(res->port_id, 1, 1);
3999 }
4000
4001 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4002         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4003                                  tx_vlan, "tx_vlan");
4004 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4005         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4006                                  set, "set");
4007 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4008         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4009                               port_id, UINT16);
4010 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4011         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4012                               vlan_id, UINT16);
4013
4014 cmdline_parse_inst_t cmd_tx_vlan_set = {
4015         .f = cmd_tx_vlan_set_parsed,
4016         .data = NULL,
4017         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4018                 "Enable hardware insertion of a single VLAN header "
4019                 "with a given TAG Identifier in packets sent on a port",
4020         .tokens = {
4021                 (void *)&cmd_tx_vlan_set_tx_vlan,
4022                 (void *)&cmd_tx_vlan_set_set,
4023                 (void *)&cmd_tx_vlan_set_portid,
4024                 (void *)&cmd_tx_vlan_set_vlanid,
4025                 NULL,
4026         },
4027 };
4028
4029 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4030 struct cmd_tx_vlan_set_qinq_result {
4031         cmdline_fixed_string_t tx_vlan;
4032         cmdline_fixed_string_t set;
4033         portid_t port_id;
4034         uint16_t vlan_id;
4035         uint16_t vlan_id_outer;
4036 };
4037
4038 static void
4039 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4040                             __attribute__((unused)) struct cmdline *cl,
4041                             __attribute__((unused)) void *data)
4042 {
4043         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4044
4045         if (!port_is_stopped(res->port_id)) {
4046                 printf("Please stop port %d first\n", res->port_id);
4047                 return;
4048         }
4049
4050         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4051
4052         cmd_reconfig_device_queue(res->port_id, 1, 1);
4053 }
4054
4055 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4056         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4057                 tx_vlan, "tx_vlan");
4058 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4059         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4060                 set, "set");
4061 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4062         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4063                 port_id, UINT16);
4064 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4065         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4066                 vlan_id, UINT16);
4067 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4068         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4069                 vlan_id_outer, UINT16);
4070
4071 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4072         .f = cmd_tx_vlan_set_qinq_parsed,
4073         .data = NULL,
4074         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4075                 "Enable hardware insertion of double VLAN header "
4076                 "with given TAG Identifiers in packets sent on a port",
4077         .tokens = {
4078                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4079                 (void *)&cmd_tx_vlan_set_qinq_set,
4080                 (void *)&cmd_tx_vlan_set_qinq_portid,
4081                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4082                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4083                 NULL,
4084         },
4085 };
4086
4087 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4088 struct cmd_tx_vlan_set_pvid_result {
4089         cmdline_fixed_string_t tx_vlan;
4090         cmdline_fixed_string_t set;
4091         cmdline_fixed_string_t pvid;
4092         portid_t port_id;
4093         uint16_t vlan_id;
4094         cmdline_fixed_string_t mode;
4095 };
4096
4097 static void
4098 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4099                             __attribute__((unused)) struct cmdline *cl,
4100                             __attribute__((unused)) void *data)
4101 {
4102         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4103
4104         if (strcmp(res->mode, "on") == 0)
4105                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4106         else
4107                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4108 }
4109
4110 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4111         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4112                                  tx_vlan, "tx_vlan");
4113 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4114         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4115                                  set, "set");
4116 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4117         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4118                                  pvid, "pvid");
4119 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4120         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4121                              port_id, UINT16);
4122 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4123         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4124                               vlan_id, UINT16);
4125 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4126         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4127                                  mode, "on#off");
4128
4129 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4130         .f = cmd_tx_vlan_set_pvid_parsed,
4131         .data = NULL,
4132         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4133         .tokens = {
4134                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4135                 (void *)&cmd_tx_vlan_set_pvid_set,
4136                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4137                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4138                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4139                 (void *)&cmd_tx_vlan_set_pvid_mode,
4140                 NULL,
4141         },
4142 };
4143
4144 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4145 struct cmd_tx_vlan_reset_result {
4146         cmdline_fixed_string_t tx_vlan;
4147         cmdline_fixed_string_t reset;
4148         portid_t port_id;
4149 };
4150
4151 static void
4152 cmd_tx_vlan_reset_parsed(void *parsed_result,
4153                          __attribute__((unused)) struct cmdline *cl,
4154                          __attribute__((unused)) void *data)
4155 {
4156         struct cmd_tx_vlan_reset_result *res = parsed_result;
4157
4158         if (!port_is_stopped(res->port_id)) {
4159                 printf("Please stop port %d first\n", res->port_id);
4160                 return;
4161         }
4162
4163         tx_vlan_reset(res->port_id);
4164
4165         cmd_reconfig_device_queue(res->port_id, 1, 1);
4166 }
4167
4168 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4169         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4170                                  tx_vlan, "tx_vlan");
4171 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4172         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4173                                  reset, "reset");
4174 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4175         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4176                               port_id, UINT16);
4177
4178 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4179         .f = cmd_tx_vlan_reset_parsed,
4180         .data = NULL,
4181         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4182                 "VLAN header in packets sent on a port",
4183         .tokens = {
4184                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4185                 (void *)&cmd_tx_vlan_reset_reset,
4186                 (void *)&cmd_tx_vlan_reset_portid,
4187                 NULL,
4188         },
4189 };
4190
4191
4192 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4193 struct cmd_csum_result {
4194         cmdline_fixed_string_t csum;
4195         cmdline_fixed_string_t mode;
4196         cmdline_fixed_string_t proto;
4197         cmdline_fixed_string_t hwsw;
4198         portid_t port_id;
4199 };
4200
4201 static void
4202 csum_show(int port_id)
4203 {
4204         struct rte_eth_dev_info dev_info;
4205         uint64_t tx_offloads;
4206
4207         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4208         printf("Parse tunnel is %s\n",
4209                 (ports[port_id].parse_tunnel) ? "on" : "off");
4210         printf("IP checksum offload is %s\n",
4211                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4212         printf("UDP checksum offload is %s\n",
4213                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4214         printf("TCP checksum offload is %s\n",
4215                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4216         printf("SCTP checksum offload is %s\n",
4217                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4218         printf("Outer-Ip checksum offload is %s\n",
4219                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4220         printf("Outer-Udp checksum offload is %s\n",
4221                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4222
4223         /* display warnings if configuration is not supported by the NIC */
4224         rte_eth_dev_info_get(port_id, &dev_info);
4225         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4226                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4227                 printf("Warning: hardware IP checksum enabled but not "
4228                         "supported by port %d\n", port_id);
4229         }
4230         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4231                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4232                 printf("Warning: hardware UDP checksum enabled but not "
4233                         "supported by port %d\n", port_id);
4234         }
4235         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4236                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4237                 printf("Warning: hardware TCP checksum enabled but not "
4238                         "supported by port %d\n", port_id);
4239         }
4240         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4241                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4242                 printf("Warning: hardware SCTP checksum enabled but not "
4243                         "supported by port %d\n", port_id);
4244         }
4245         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4246                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4247                 printf("Warning: hardware outer IP checksum enabled but not "
4248                         "supported by port %d\n", port_id);
4249         }
4250         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4251                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4252                         == 0) {
4253                 printf("Warning: hardware outer UDP checksum enabled but not "
4254                         "supported by port %d\n", port_id);
4255         }
4256 }
4257
4258 static void
4259 cmd_csum_parsed(void *parsed_result,
4260                        __attribute__((unused)) struct cmdline *cl,
4261                        __attribute__((unused)) void *data)
4262 {
4263         struct cmd_csum_result *res = parsed_result;
4264         int hw = 0;
4265         uint64_t csum_offloads = 0;
4266         struct rte_eth_dev_info dev_info;
4267
4268         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4269                 printf("invalid port %d\n", res->port_id);
4270                 return;
4271         }
4272         if (!port_is_stopped(res->port_id)) {
4273                 printf("Please stop port %d first\n", res->port_id);
4274                 return;
4275         }
4276
4277         rte_eth_dev_info_get(res->port_id, &dev_info);
4278         if (!strcmp(res->mode, "set")) {
4279
4280                 if (!strcmp(res->hwsw, "hw"))
4281                         hw = 1;
4282
4283                 if (!strcmp(res->proto, "ip")) {
4284                         if (hw == 0 || (dev_info.tx_offload_capa &
4285                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4286                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4287                         } else {
4288                                 printf("IP checksum offload is not supported "
4289                                        "by port %u\n", res->port_id);
4290                         }
4291                 } else if (!strcmp(res->proto, "udp")) {
4292                         if (hw == 0 || (dev_info.tx_offload_capa &
4293                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4294                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4295                         } else {
4296                                 printf("UDP checksum offload is not supported "
4297                                        "by port %u\n", res->port_id);
4298                         }
4299                 } else if (!strcmp(res->proto, "tcp")) {
4300                         if (hw == 0 || (dev_info.tx_offload_capa &
4301                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4302                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4303                         } else {
4304                                 printf("TCP checksum offload is not supported "
4305                                        "by port %u\n", res->port_id);
4306                         }
4307                 } else if (!strcmp(res->proto, "sctp")) {
4308                         if (hw == 0 || (dev_info.tx_offload_capa &
4309                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4310                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4311                         } else {
4312                                 printf("SCTP checksum offload is not supported "
4313                                        "by port %u\n", res->port_id);
4314                         }
4315                 } else if (!strcmp(res->proto, "outer-ip")) {
4316                         if (hw == 0 || (dev_info.tx_offload_capa &
4317                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4318                                 csum_offloads |=
4319                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4320                         } else {
4321                                 printf("Outer IP checksum offload is not "
4322                                        "supported by port %u\n", res->port_id);
4323                         }
4324                 } else if (!strcmp(res->proto, "outer-udp")) {
4325                         if (hw == 0 || (dev_info.tx_offload_capa &
4326                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4327                                 csum_offloads |=
4328                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4329                         } else {
4330                                 printf("Outer UDP checksum offload is not "
4331                                        "supported by port %u\n", res->port_id);
4332                         }
4333                 }
4334
4335                 if (hw) {
4336                         ports[res->port_id].dev_conf.txmode.offloads |=
4337                                                         csum_offloads;
4338                 } else {
4339                         ports[res->port_id].dev_conf.txmode.offloads &=
4340                                                         (~csum_offloads);
4341                 }
4342         }
4343         csum_show(res->port_id);
4344
4345         cmd_reconfig_device_queue(res->port_id, 1, 1);
4346 }
4347
4348 cmdline_parse_token_string_t cmd_csum_csum =
4349         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4350                                 csum, "csum");
4351 cmdline_parse_token_string_t cmd_csum_mode =
4352         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4353                                 mode, "set");
4354 cmdline_parse_token_string_t cmd_csum_proto =
4355         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4356                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4357 cmdline_parse_token_string_t cmd_csum_hwsw =
4358         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4359                                 hwsw, "hw#sw");
4360 cmdline_parse_token_num_t cmd_csum_portid =
4361         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4362                                 port_id, UINT16);
4363
4364 cmdline_parse_inst_t cmd_csum_set = {
4365         .f = cmd_csum_parsed,
4366         .data = NULL,
4367         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4368                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4369                 "using csum forward engine",
4370         .tokens = {
4371                 (void *)&cmd_csum_csum,
4372                 (void *)&cmd_csum_mode,
4373                 (void *)&cmd_csum_proto,
4374                 (void *)&cmd_csum_hwsw,
4375                 (void *)&cmd_csum_portid,
4376                 NULL,
4377         },
4378 };
4379
4380 cmdline_parse_token_string_t cmd_csum_mode_show =
4381         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4382                                 mode, "show");
4383
4384 cmdline_parse_inst_t cmd_csum_show = {
4385         .f = cmd_csum_parsed,
4386         .data = NULL,
4387         .help_str = "csum show <port_id>: Show checksum offload configuration",
4388         .tokens = {
4389                 (void *)&cmd_csum_csum,
4390                 (void *)&cmd_csum_mode_show,
4391                 (void *)&cmd_csum_portid,
4392                 NULL,
4393         },
4394 };
4395
4396 /* Enable/disable tunnel parsing */
4397 struct cmd_csum_tunnel_result {
4398         cmdline_fixed_string_t csum;
4399         cmdline_fixed_string_t parse;
4400         cmdline_fixed_string_t onoff;
4401         portid_t port_id;
4402 };
4403
4404 static void
4405 cmd_csum_tunnel_parsed(void *parsed_result,
4406                        __attribute__((unused)) struct cmdline *cl,
4407                        __attribute__((unused)) void *data)
4408 {
4409         struct cmd_csum_tunnel_result *res = parsed_result;
4410
4411         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4412                 return;
4413
4414         if (!strcmp(res->onoff, "on"))
4415                 ports[res->port_id].parse_tunnel = 1;
4416         else
4417                 ports[res->port_id].parse_tunnel = 0;
4418
4419         csum_show(res->port_id);
4420 }
4421
4422 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4423         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4424                                 csum, "csum");
4425 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4426         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4427                                 parse, "parse-tunnel");
4428 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4429         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4430                                 onoff, "on#off");
4431 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4432         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4433                                 port_id, UINT16);
4434
4435 cmdline_parse_inst_t cmd_csum_tunnel = {
4436         .f = cmd_csum_tunnel_parsed,
4437         .data = NULL,
4438         .help_str = "csum parse-tunnel on|off <port_id>: "
4439                 "Enable/Disable parsing of tunnels for csum engine",
4440         .tokens = {
4441                 (void *)&cmd_csum_tunnel_csum,
4442                 (void *)&cmd_csum_tunnel_parse,
4443                 (void *)&cmd_csum_tunnel_onoff,
4444                 (void *)&cmd_csum_tunnel_portid,
4445                 NULL,
4446         },
4447 };
4448
4449 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4450 struct cmd_tso_set_result {
4451         cmdline_fixed_string_t tso;
4452         cmdline_fixed_string_t mode;
4453         uint16_t tso_segsz;
4454         portid_t port_id;
4455 };
4456
4457 static void
4458 cmd_tso_set_parsed(void *parsed_result,
4459                        __attribute__((unused)) struct cmdline *cl,
4460                        __attribute__((unused)) void *data)
4461 {
4462         struct cmd_tso_set_result *res = parsed_result;
4463         struct rte_eth_dev_info dev_info;
4464
4465         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4466                 return;
4467         if (!port_is_stopped(res->port_id)) {
4468                 printf("Please stop port %d first\n", res->port_id);
4469                 return;
4470         }
4471
4472         if (!strcmp(res->mode, "set"))
4473                 ports[res->port_id].tso_segsz = res->tso_segsz;
4474
4475         rte_eth_dev_info_get(res->port_id, &dev_info);
4476         if ((ports[res->port_id].tso_segsz != 0) &&
4477                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4478                 printf("Error: TSO is not supported by port %d\n",
4479                        res->port_id);
4480                 return;
4481         }
4482
4483         if (ports[res->port_id].tso_segsz == 0) {
4484                 ports[res->port_id].dev_conf.txmode.offloads &=
4485                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4486                 printf("TSO for non-tunneled packets is disabled\n");
4487         } else {
4488                 ports[res->port_id].dev_conf.txmode.offloads |=
4489                                                 DEV_TX_OFFLOAD_TCP_TSO;
4490                 printf("TSO segment size for non-tunneled packets is %d\n",
4491                         ports[res->port_id].tso_segsz);
4492         }
4493
4494         /* display warnings if configuration is not supported by the NIC */
4495         rte_eth_dev_info_get(res->port_id, &dev_info);
4496         if ((ports[res->port_id].tso_segsz != 0) &&
4497                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4498                 printf("Warning: TSO enabled but not "
4499                         "supported by port %d\n", res->port_id);
4500         }
4501
4502         cmd_reconfig_device_queue(res->port_id, 1, 1);
4503 }
4504
4505 cmdline_parse_token_string_t cmd_tso_set_tso =
4506         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4507                                 tso, "tso");
4508 cmdline_parse_token_string_t cmd_tso_set_mode =
4509         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4510                                 mode, "set");
4511 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4512         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4513                                 tso_segsz, UINT16);
4514 cmdline_parse_token_num_t cmd_tso_set_portid =
4515         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4516                                 port_id, UINT16);
4517
4518 cmdline_parse_inst_t cmd_tso_set = {
4519         .f = cmd_tso_set_parsed,
4520         .data = NULL,
4521         .help_str = "tso set <tso_segsz> <port_id>: "
4522                 "Set TSO segment size of non-tunneled packets for csum engine "
4523                 "(0 to disable)",
4524         .tokens = {
4525                 (void *)&cmd_tso_set_tso,
4526                 (void *)&cmd_tso_set_mode,
4527                 (void *)&cmd_tso_set_tso_segsz,
4528                 (void *)&cmd_tso_set_portid,
4529                 NULL,
4530         },
4531 };
4532
4533 cmdline_parse_token_string_t cmd_tso_show_mode =
4534         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4535                                 mode, "show");
4536
4537
4538 cmdline_parse_inst_t cmd_tso_show = {
4539         .f = cmd_tso_set_parsed,
4540         .data = NULL,
4541         .help_str = "tso show <port_id>: "
4542                 "Show TSO segment size of non-tunneled packets for csum engine",
4543         .tokens = {
4544                 (void *)&cmd_tso_set_tso,
4545                 (void *)&cmd_tso_show_mode,
4546                 (void *)&cmd_tso_set_portid,
4547                 NULL,
4548         },
4549 };
4550
4551 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4552 struct cmd_tunnel_tso_set_result {
4553         cmdline_fixed_string_t tso;
4554         cmdline_fixed_string_t mode;
4555         uint16_t tso_segsz;
4556         portid_t port_id;
4557 };
4558
4559 static struct rte_eth_dev_info
4560 check_tunnel_tso_nic_support(portid_t port_id)
4561 {
4562         struct rte_eth_dev_info dev_info;
4563
4564         rte_eth_dev_info_get(port_id, &dev_info);
4565         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4566                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4567                        "not enabled for port %d\n", port_id);
4568         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4569                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4570                        "not enabled for port %d\n", port_id);
4571         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4572                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4573                        "not enabled for port %d\n", port_id);
4574         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4575                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4576                        "not enabled for port %d\n", port_id);
4577         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4578                 printf("Warning: IP TUNNEL TSO not supported therefore "
4579                        "not enabled for port %d\n", port_id);
4580         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4581                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4582                        "not enabled for port %d\n", port_id);
4583         return dev_info;
4584 }
4585
4586 static void
4587 cmd_tunnel_tso_set_parsed(void *parsed_result,
4588                           __attribute__((unused)) struct cmdline *cl,
4589                           __attribute__((unused)) void *data)
4590 {
4591         struct cmd_tunnel_tso_set_result *res = parsed_result;
4592         struct rte_eth_dev_info dev_info;
4593
4594         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4595                 return;
4596         if (!port_is_stopped(res->port_id)) {
4597                 printf("Please stop port %d first\n", res->port_id);
4598                 return;
4599         }
4600
4601         if (!strcmp(res->mode, "set"))
4602                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4603
4604         dev_info = check_tunnel_tso_nic_support(res->port_id);
4605         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4606                 ports[res->port_id].dev_conf.txmode.offloads &=
4607                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4608                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4609                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4610                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4611                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4612                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4613                 printf("TSO for tunneled packets is disabled\n");
4614         } else {
4615                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4616                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4617                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4618                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4619                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4620                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4621
4622                 ports[res->port_id].dev_conf.txmode.offloads |=
4623                         (tso_offloads & dev_info.tx_offload_capa);
4624                 printf("TSO segment size for tunneled packets is %d\n",
4625                         ports[res->port_id].tunnel_tso_segsz);
4626
4627                 /* Below conditions are needed to make it work:
4628                  * (1) tunnel TSO is supported by the NIC;
4629                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4630                  * are recognized;
4631                  * (3) for tunneled pkts with outer L3 of IPv4,
4632                  * "csum set outer-ip" must be set to hw, because after tso,
4633                  * total_len of outer IP header is changed, and the checksum
4634                  * of outer IP header calculated by sw should be wrong; that
4635                  * is not necessary for IPv6 tunneled pkts because there's no
4636                  * checksum in IP header anymore.
4637                  */
4638
4639                 if (!ports[res->port_id].parse_tunnel)
4640                         printf("Warning: csum parse_tunnel must be set "
4641                                 "so that tunneled packets are recognized\n");
4642                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4643                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4644                         printf("Warning: csum set outer-ip must be set to hw "
4645                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4646         }
4647
4648         cmd_reconfig_device_queue(res->port_id, 1, 1);
4649 }
4650
4651 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4652         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4653                                 tso, "tunnel_tso");
4654 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4655         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4656                                 mode, "set");
4657 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4658         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4659                                 tso_segsz, UINT16);
4660 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4661         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4662                                 port_id, UINT16);
4663
4664 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4665         .f = cmd_tunnel_tso_set_parsed,
4666         .data = NULL,
4667         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4668                 "Set TSO segment size of tunneled packets for csum engine "
4669                 "(0 to disable)",
4670         .tokens = {
4671                 (void *)&cmd_tunnel_tso_set_tso,
4672                 (void *)&cmd_tunnel_tso_set_mode,
4673                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4674                 (void *)&cmd_tunnel_tso_set_portid,
4675                 NULL,
4676         },
4677 };
4678
4679 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4680         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4681                                 mode, "show");
4682
4683
4684 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4685         .f = cmd_tunnel_tso_set_parsed,
4686         .data = NULL,
4687         .help_str = "tunnel_tso show <port_id> "
4688                 "Show TSO segment size of tunneled packets for csum engine",
4689         .tokens = {
4690                 (void *)&cmd_tunnel_tso_set_tso,
4691                 (void *)&cmd_tunnel_tso_show_mode,
4692                 (void *)&cmd_tunnel_tso_set_portid,
4693                 NULL,
4694         },
4695 };
4696
4697 /* *** SET GRO FOR A PORT *** */
4698 struct cmd_gro_enable_result {
4699         cmdline_fixed_string_t cmd_set;
4700         cmdline_fixed_string_t cmd_port;
4701         cmdline_fixed_string_t cmd_keyword;
4702         cmdline_fixed_string_t cmd_onoff;
4703         portid_t cmd_pid;
4704 };
4705
4706 static void
4707 cmd_gro_enable_parsed(void *parsed_result,
4708                 __attribute__((unused)) struct cmdline *cl,
4709                 __attribute__((unused)) void *data)
4710 {
4711         struct cmd_gro_enable_result *res;
4712
4713         res = parsed_result;
4714         if (!strcmp(res->cmd_keyword, "gro"))
4715                 setup_gro(res->cmd_onoff, res->cmd_pid);
4716 }
4717
4718 cmdline_parse_token_string_t cmd_gro_enable_set =
4719         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4720                         cmd_set, "set");
4721 cmdline_parse_token_string_t cmd_gro_enable_port =
4722         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4723                         cmd_keyword, "port");
4724 cmdline_parse_token_num_t cmd_gro_enable_pid =
4725         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4726                         cmd_pid, UINT16);
4727 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4728         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4729                         cmd_keyword, "gro");
4730 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4731         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4732                         cmd_onoff, "on#off");
4733
4734 cmdline_parse_inst_t cmd_gro_enable = {
4735         .f = cmd_gro_enable_parsed,
4736         .data = NULL,
4737         .help_str = "set port <port_id> gro on|off",
4738         .tokens = {
4739                 (void *)&cmd_gro_enable_set,
4740                 (void *)&cmd_gro_enable_port,
4741                 (void *)&cmd_gro_enable_pid,
4742                 (void *)&cmd_gro_enable_keyword,
4743                 (void *)&cmd_gro_enable_onoff,
4744                 NULL,
4745         },
4746 };
4747
4748 /* *** DISPLAY GRO CONFIGURATION *** */
4749 struct cmd_gro_show_result {
4750         cmdline_fixed_string_t cmd_show;
4751         cmdline_fixed_string_t cmd_port;
4752         cmdline_fixed_string_t cmd_keyword;
4753         portid_t cmd_pid;
4754 };
4755
4756 static void
4757 cmd_gro_show_parsed(void *parsed_result,
4758                 __attribute__((unused)) struct cmdline *cl,
4759                 __attribute__((unused)) void *data)
4760 {
4761         struct cmd_gro_show_result *res;
4762
4763         res = parsed_result;
4764         if (!strcmp(res->cmd_keyword, "gro"))
4765                 show_gro(res->cmd_pid);
4766 }
4767
4768 cmdline_parse_token_string_t cmd_gro_show_show =
4769         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4770                         cmd_show, "show");
4771 cmdline_parse_token_string_t cmd_gro_show_port =
4772         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4773                         cmd_port, "port");
4774 cmdline_parse_token_num_t cmd_gro_show_pid =
4775         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4776                         cmd_pid, UINT16);
4777 cmdline_parse_token_string_t cmd_gro_show_keyword =
4778         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4779                         cmd_keyword, "gro");
4780
4781 cmdline_parse_inst_t cmd_gro_show = {
4782         .f = cmd_gro_show_parsed,
4783         .data = NULL,
4784         .help_str = "show port <port_id> gro",
4785         .tokens = {
4786                 (void *)&cmd_gro_show_show,
4787                 (void *)&cmd_gro_show_port,
4788                 (void *)&cmd_gro_show_pid,
4789                 (void *)&cmd_gro_show_keyword,
4790                 NULL,
4791         },
4792 };
4793
4794 /* *** SET FLUSH CYCLES FOR GRO *** */
4795 struct cmd_gro_flush_result {
4796         cmdline_fixed_string_t cmd_set;
4797         cmdline_fixed_string_t cmd_keyword;
4798         cmdline_fixed_string_t cmd_flush;
4799         uint8_t cmd_cycles;
4800 };
4801
4802 static void
4803 cmd_gro_flush_parsed(void *parsed_result,
4804                 __attribute__((unused)) struct cmdline *cl,
4805                 __attribute__((unused)) void *data)
4806 {
4807         struct cmd_gro_flush_result *res;
4808
4809         res = parsed_result;
4810         if ((!strcmp(res->cmd_keyword, "gro")) &&
4811                         (!strcmp(res->cmd_flush, "flush")))
4812                 setup_gro_flush_cycles(res->cmd_cycles);
4813 }
4814
4815 cmdline_parse_token_string_t cmd_gro_flush_set =
4816         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4817                         cmd_set, "set");
4818 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4819         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4820                         cmd_keyword, "gro");
4821 cmdline_parse_token_string_t cmd_gro_flush_flush =
4822         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4823                         cmd_flush, "flush");
4824 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4825         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4826                         cmd_cycles, UINT8);
4827
4828 cmdline_parse_inst_t cmd_gro_flush = {
4829         .f = cmd_gro_flush_parsed,
4830         .data = NULL,
4831         .help_str = "set gro flush <cycles>",
4832         .tokens = {
4833                 (void *)&cmd_gro_flush_set,
4834                 (void *)&cmd_gro_flush_keyword,
4835                 (void *)&cmd_gro_flush_flush,
4836                 (void *)&cmd_gro_flush_cycles,
4837                 NULL,
4838         },
4839 };
4840
4841 /* *** ENABLE/DISABLE GSO *** */
4842 struct cmd_gso_enable_result {
4843         cmdline_fixed_string_t cmd_set;
4844         cmdline_fixed_string_t cmd_port;
4845         cmdline_fixed_string_t cmd_keyword;
4846         cmdline_fixed_string_t cmd_mode;
4847         portid_t cmd_pid;
4848 };
4849
4850 static void
4851 cmd_gso_enable_parsed(void *parsed_result,
4852                 __attribute__((unused)) struct cmdline *cl,
4853                 __attribute__((unused)) void *data)
4854 {
4855         struct cmd_gso_enable_result *res;
4856
4857         res = parsed_result;
4858         if (!strcmp(res->cmd_keyword, "gso"))
4859                 setup_gso(res->cmd_mode, res->cmd_pid);
4860 }
4861
4862 cmdline_parse_token_string_t cmd_gso_enable_set =
4863         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4864                         cmd_set, "set");
4865 cmdline_parse_token_string_t cmd_gso_enable_port =
4866         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4867                         cmd_port, "port");
4868 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4869         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4870                         cmd_keyword, "gso");
4871 cmdline_parse_token_string_t cmd_gso_enable_mode =
4872         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4873                         cmd_mode, "on#off");
4874 cmdline_parse_token_num_t cmd_gso_enable_pid =
4875         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4876                         cmd_pid, UINT16);
4877
4878 cmdline_parse_inst_t cmd_gso_enable = {
4879         .f = cmd_gso_enable_parsed,
4880         .data = NULL,
4881         .help_str = "set port <port_id> gso on|off",
4882         .tokens = {
4883                 (void *)&cmd_gso_enable_set,
4884                 (void *)&cmd_gso_enable_port,
4885                 (void *)&cmd_gso_enable_pid,
4886                 (void *)&cmd_gso_enable_keyword,
4887                 (void *)&cmd_gso_enable_mode,
4888                 NULL,
4889         },
4890 };
4891
4892 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4893 struct cmd_gso_size_result {
4894         cmdline_fixed_string_t cmd_set;
4895         cmdline_fixed_string_t cmd_keyword;
4896         cmdline_fixed_string_t cmd_segsz;
4897         uint16_t cmd_size;
4898 };
4899
4900 static void
4901 cmd_gso_size_parsed(void *parsed_result,
4902                        __attribute__((unused)) struct cmdline *cl,
4903                        __attribute__((unused)) void *data)
4904 {
4905         struct cmd_gso_size_result *res = parsed_result;
4906
4907         if (test_done == 0) {
4908                 printf("Before setting GSO segsz, please first"
4909                                 " stop fowarding\n");
4910                 return;
4911         }
4912
4913         if (!strcmp(res->cmd_keyword, "gso") &&
4914                         !strcmp(res->cmd_segsz, "segsz")) {
4915                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4916                         printf("gso_size should be larger than %zu."
4917                                         " Please input a legal value\n",
4918                                         RTE_GSO_SEG_SIZE_MIN);
4919                 else
4920                         gso_max_segment_size = res->cmd_size;
4921         }
4922 }
4923
4924 cmdline_parse_token_string_t cmd_gso_size_set =
4925         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4926                                 cmd_set, "set");
4927 cmdline_parse_token_string_t cmd_gso_size_keyword =
4928         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4929                                 cmd_keyword, "gso");
4930 cmdline_parse_token_string_t cmd_gso_size_segsz =
4931         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4932                                 cmd_segsz, "segsz");
4933 cmdline_parse_token_num_t cmd_gso_size_size =
4934         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4935                                 cmd_size, UINT16);
4936
4937 cmdline_parse_inst_t cmd_gso_size = {
4938         .f = cmd_gso_size_parsed,
4939         .data = NULL,
4940         .help_str = "set gso segsz <length>",
4941         .tokens = {
4942                 (void *)&cmd_gso_size_set,
4943                 (void *)&cmd_gso_size_keyword,
4944                 (void *)&cmd_gso_size_segsz,
4945                 (void *)&cmd_gso_size_size,
4946                 NULL,
4947         },
4948 };
4949
4950 /* *** SHOW GSO CONFIGURATION *** */
4951 struct cmd_gso_show_result {
4952         cmdline_fixed_string_t cmd_show;
4953         cmdline_fixed_string_t cmd_port;
4954         cmdline_fixed_string_t cmd_keyword;
4955         portid_t cmd_pid;
4956 };
4957
4958 static void
4959 cmd_gso_show_parsed(void *parsed_result,
4960                        __attribute__((unused)) struct cmdline *cl,
4961                        __attribute__((unused)) void *data)
4962 {
4963         struct cmd_gso_show_result *res = parsed_result;
4964
4965         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4966                 printf("invalid port id %u\n", res->cmd_pid);
4967                 return;
4968         }
4969         if (!strcmp(res->cmd_keyword, "gso")) {
4970                 if (gso_ports[res->cmd_pid].enable) {
4971                         printf("Max GSO'd packet size: %uB\n"
4972                                         "Supported GSO types: TCP/IPv4, "
4973                                         "UDP/IPv4, VxLAN with inner "
4974                                         "TCP/IPv4 packet, GRE with inner "
4975                                         "TCP/IPv4 packet\n",
4976                                         gso_max_segment_size);
4977                 } else
4978                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4979         }
4980 }
4981
4982 cmdline_parse_token_string_t cmd_gso_show_show =
4983 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4984                 cmd_show, "show");
4985 cmdline_parse_token_string_t cmd_gso_show_port =
4986 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4987                 cmd_port, "port");
4988 cmdline_parse_token_string_t cmd_gso_show_keyword =
4989         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4990                                 cmd_keyword, "gso");
4991 cmdline_parse_token_num_t cmd_gso_show_pid =
4992         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4993                                 cmd_pid, UINT16);
4994
4995 cmdline_parse_inst_t cmd_gso_show = {
4996         .f = cmd_gso_show_parsed,
4997         .data = NULL,
4998         .help_str = "show port <port_id> gso",
4999         .tokens = {
5000                 (void *)&cmd_gso_show_show,
5001                 (void *)&cmd_gso_show_port,
5002                 (void *)&cmd_gso_show_pid,
5003                 (void *)&cmd_gso_show_keyword,
5004                 NULL,
5005         },
5006 };
5007
5008 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5009 struct cmd_set_flush_rx {
5010         cmdline_fixed_string_t set;
5011         cmdline_fixed_string_t flush_rx;
5012         cmdline_fixed_string_t mode;
5013 };
5014
5015 static void
5016 cmd_set_flush_rx_parsed(void *parsed_result,
5017                 __attribute__((unused)) struct cmdline *cl,
5018                 __attribute__((unused)) void *data)
5019 {
5020         struct cmd_set_flush_rx *res = parsed_result;
5021         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5022 }
5023
5024 cmdline_parse_token_string_t cmd_setflushrx_set =
5025         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5026                         set, "set");
5027 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5028         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5029                         flush_rx, "flush_rx");
5030 cmdline_parse_token_string_t cmd_setflushrx_mode =
5031         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5032                         mode, "on#off");
5033
5034
5035 cmdline_parse_inst_t cmd_set_flush_rx = {
5036         .f = cmd_set_flush_rx_parsed,
5037         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5038         .data = NULL,
5039         .tokens = {
5040                 (void *)&cmd_setflushrx_set,
5041                 (void *)&cmd_setflushrx_flush_rx,
5042                 (void *)&cmd_setflushrx_mode,
5043                 NULL,
5044         },
5045 };
5046
5047 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5048 struct cmd_set_link_check {
5049         cmdline_fixed_string_t set;
5050         cmdline_fixed_string_t link_check;
5051         cmdline_fixed_string_t mode;
5052 };
5053
5054 static void
5055 cmd_set_link_check_parsed(void *parsed_result,
5056                 __attribute__((unused)) struct cmdline *cl,
5057                 __attribute__((unused)) void *data)
5058 {
5059         struct cmd_set_link_check *res = parsed_result;
5060         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5061 }
5062
5063 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5064         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5065                         set, "set");
5066 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5067         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5068                         link_check, "link_check");
5069 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5070         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5071                         mode, "on#off");
5072
5073
5074 cmdline_parse_inst_t cmd_set_link_check = {
5075         .f = cmd_set_link_check_parsed,
5076         .help_str = "set link_check on|off: Enable/Disable link status check "
5077                     "when starting/stopping a port",
5078         .data = NULL,
5079         .tokens = {
5080                 (void *)&cmd_setlinkcheck_set,
5081                 (void *)&cmd_setlinkcheck_link_check,
5082                 (void *)&cmd_setlinkcheck_mode,
5083                 NULL,
5084         },
5085 };
5086
5087 /* *** SET NIC BYPASS MODE *** */
5088 struct cmd_set_bypass_mode_result {
5089         cmdline_fixed_string_t set;
5090         cmdline_fixed_string_t bypass;
5091         cmdline_fixed_string_t mode;
5092         cmdline_fixed_string_t value;
5093         portid_t port_id;
5094 };
5095
5096 static void
5097 cmd_set_bypass_mode_parsed(void *parsed_result,
5098                 __attribute__((unused)) struct cmdline *cl,
5099                 __attribute__((unused)) void *data)
5100 {
5101         struct cmd_set_bypass_mode_result *res = parsed_result;
5102         portid_t port_id = res->port_id;
5103         int32_t rc = -EINVAL;
5104
5105 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5106         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5107
5108         if (!strcmp(res->value, "bypass"))
5109                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5110         else if (!strcmp(res->value, "isolate"))
5111                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5112         else
5113                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5114
5115         /* Set the bypass mode for the relevant port. */
5116         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5117 #endif
5118         if (rc != 0)
5119                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5120 }
5121
5122 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5123         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5124                         set, "set");
5125 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5126         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5127                         bypass, "bypass");
5128 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5129         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5130                         mode, "mode");
5131 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5132         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5133                         value, "normal#bypass#isolate");
5134 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5135         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5136                                 port_id, UINT16);
5137
5138 cmdline_parse_inst_t cmd_set_bypass_mode = {
5139         .f = cmd_set_bypass_mode_parsed,
5140         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5141                     "Set the NIC bypass mode for port_id",
5142         .data = NULL,
5143         .tokens = {
5144                 (void *)&cmd_setbypass_mode_set,
5145                 (void *)&cmd_setbypass_mode_bypass,
5146                 (void *)&cmd_setbypass_mode_mode,
5147                 (void *)&cmd_setbypass_mode_value,
5148                 (void *)&cmd_setbypass_mode_port,
5149                 NULL,
5150         },
5151 };
5152
5153 /* *** SET NIC BYPASS EVENT *** */
5154 struct cmd_set_bypass_event_result {
5155         cmdline_fixed_string_t set;
5156         cmdline_fixed_string_t bypass;
5157         cmdline_fixed_string_t event;
5158         cmdline_fixed_string_t event_value;
5159         cmdline_fixed_string_t mode;
5160         cmdline_fixed_string_t mode_value;
5161         portid_t port_id;
5162 };
5163
5164 static void
5165 cmd_set_bypass_event_parsed(void *parsed_result,
5166                 __attribute__((unused)) struct cmdline *cl,
5167                 __attribute__((unused)) void *data)
5168 {
5169         int32_t rc = -EINVAL;
5170         struct cmd_set_bypass_event_result *res = parsed_result;
5171         portid_t port_id = res->port_id;
5172
5173 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5174         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5175         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5176
5177         if (!strcmp(res->event_value, "timeout"))
5178                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5179         else if (!strcmp(res->event_value, "os_on"))
5180                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5181         else if (!strcmp(res->event_value, "os_off"))
5182                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5183         else if (!strcmp(res->event_value, "power_on"))
5184                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5185         else if (!strcmp(res->event_value, "power_off"))
5186                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5187         else
5188                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5189
5190         if (!strcmp(res->mode_value, "bypass"))
5191                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5192         else if (!strcmp(res->mode_value, "isolate"))
5193                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5194         else
5195                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5196
5197         /* Set the watchdog timeout. */
5198         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5199
5200                 rc = -EINVAL;
5201                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5202                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5203                                                            bypass_timeout);
5204                 }
5205                 if (rc != 0) {
5206                         printf("Failed to set timeout value %u "
5207                         "for port %d, errto code: %d.\n",
5208                         bypass_timeout, port_id, rc);
5209                 }
5210         }
5211
5212         /* Set the bypass event to transition to bypass mode. */
5213         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5214                                               bypass_mode);
5215 #endif
5216
5217         if (rc != 0)
5218                 printf("\t Failed to set bypass event for port = %d.\n",
5219                        port_id);
5220 }
5221
5222 cmdline_parse_token_string_t cmd_setbypass_event_set =
5223         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5224                         set, "set");
5225 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5226         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5227                         bypass, "bypass");
5228 cmdline_parse_token_string_t cmd_setbypass_event_event =
5229         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5230                         event, "event");
5231 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5232         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5233                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5234 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5235         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5236                         mode, "mode");
5237 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5238         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5239                         mode_value, "normal#bypass#isolate");
5240 cmdline_parse_token_num_t cmd_setbypass_event_port =
5241         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5242                                 port_id, UINT16);
5243
5244 cmdline_parse_inst_t cmd_set_bypass_event = {
5245         .f = cmd_set_bypass_event_parsed,
5246         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5247                 "power_off mode normal|bypass|isolate <port_id>: "
5248                 "Set the NIC bypass event mode for port_id",
5249         .data = NULL,
5250         .tokens = {
5251                 (void *)&cmd_setbypass_event_set,
5252                 (void *)&cmd_setbypass_event_bypass,
5253                 (void *)&cmd_setbypass_event_event,
5254                 (void *)&cmd_setbypass_event_event_value,
5255                 (void *)&cmd_setbypass_event_mode,
5256                 (void *)&cmd_setbypass_event_mode_value,
5257                 (void *)&cmd_setbypass_event_port,
5258                 NULL,
5259         },
5260 };
5261
5262
5263 /* *** SET NIC BYPASS TIMEOUT *** */
5264 struct cmd_set_bypass_timeout_result {
5265         cmdline_fixed_string_t set;
5266         cmdline_fixed_string_t bypass;
5267         cmdline_fixed_string_t timeout;
5268         cmdline_fixed_string_t value;
5269 };
5270
5271 static void
5272 cmd_set_bypass_timeout_parsed(void *parsed_result,
5273                 __attribute__((unused)) struct cmdline *cl,
5274                 __attribute__((unused)) void *data)
5275 {
5276         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5277
5278 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5279         if (!strcmp(res->value, "1.5"))
5280                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5281         else if (!strcmp(res->value, "2"))
5282                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5283         else if (!strcmp(res->value, "3"))
5284                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5285         else if (!strcmp(res->value, "4"))
5286                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5287         else if (!strcmp(res->value, "8"))
5288                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5289         else if (!strcmp(res->value, "16"))
5290                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5291         else if (!strcmp(res->value, "32"))
5292                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5293         else
5294                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5295 #endif
5296 }
5297
5298 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5299         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5300                         set, "set");
5301 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5302         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5303                         bypass, "bypass");
5304 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5305         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5306                         timeout, "timeout");
5307 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5308         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5309                         value, "0#1.5#2#3#4#8#16#32");
5310
5311 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5312         .f = cmd_set_bypass_timeout_parsed,
5313         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5314                 "Set the NIC bypass watchdog timeout in seconds",
5315         .data = NULL,
5316         .tokens = {
5317                 (void *)&cmd_setbypass_timeout_set,
5318                 (void *)&cmd_setbypass_timeout_bypass,
5319                 (void *)&cmd_setbypass_timeout_timeout,
5320                 (void *)&cmd_setbypass_timeout_value,
5321                 NULL,
5322         },
5323 };
5324
5325 /* *** SHOW NIC BYPASS MODE *** */
5326 struct cmd_show_bypass_config_result {
5327         cmdline_fixed_string_t show;
5328         cmdline_fixed_string_t bypass;
5329         cmdline_fixed_string_t config;
5330         portid_t port_id;
5331 };
5332
5333 static void
5334 cmd_show_bypass_config_parsed(void *parsed_result,
5335                 __attribute__((unused)) struct cmdline *cl,
5336                 __attribute__((unused)) void *data)
5337 {
5338         struct cmd_show_bypass_config_result *res = parsed_result;
5339         portid_t port_id = res->port_id;
5340         int rc = -EINVAL;
5341 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5342         uint32_t event_mode;
5343         uint32_t bypass_mode;
5344         uint32_t timeout = bypass_timeout;
5345         int i;
5346
5347         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5348                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5349         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5350                 {"UNKNOWN", "normal", "bypass", "isolate"};
5351         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5352                 "NONE",
5353                 "OS/board on",
5354                 "power supply on",
5355                 "OS/board off",
5356                 "power supply off",
5357                 "timeout"};
5358         int num_events = (sizeof events) / (sizeof events[0]);
5359
5360         /* Display the bypass mode.*/
5361         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5362                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5363                 return;
5364         }
5365         else {
5366                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5367                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5368
5369                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5370         }
5371
5372         /* Display the bypass timeout.*/
5373         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5374                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5375
5376         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5377
5378         /* Display the bypass events and associated modes. */
5379         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5380
5381                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5382                         printf("\tFailed to get bypass mode for event = %s\n",
5383                                 events[i]);
5384                 } else {
5385                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5386                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5387
5388                         printf("\tbypass event: %-16s = %s\n", events[i],
5389                                 modes[event_mode]);
5390                 }
5391         }
5392 #endif
5393         if (rc != 0)
5394                 printf("\tFailed to get bypass configuration for port = %d\n",
5395                        port_id);
5396 }
5397
5398 cmdline_parse_token_string_t cmd_showbypass_config_show =
5399         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5400                         show, "show");
5401 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5402         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5403                         bypass, "bypass");
5404 cmdline_parse_token_string_t cmd_showbypass_config_config =
5405         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5406                         config, "config");
5407 cmdline_parse_token_num_t cmd_showbypass_config_port =
5408         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5409                                 port_id, UINT16);
5410
5411 cmdline_parse_inst_t cmd_show_bypass_config = {
5412         .f = cmd_show_bypass_config_parsed,
5413         .help_str = "show bypass config <port_id>: "
5414                     "Show the NIC bypass config for port_id",
5415         .data = NULL,
5416         .tokens = {
5417                 (void *)&cmd_showbypass_config_show,
5418                 (void *)&cmd_showbypass_config_bypass,
5419                 (void *)&cmd_showbypass_config_config,
5420                 (void *)&cmd_showbypass_config_port,
5421                 NULL,
5422         },
5423 };
5424
5425 #ifdef RTE_LIBRTE_PMD_BOND
5426 /* *** SET BONDING MODE *** */
5427 struct cmd_set_bonding_mode_result {
5428         cmdline_fixed_string_t set;
5429         cmdline_fixed_string_t bonding;
5430         cmdline_fixed_string_t mode;
5431         uint8_t value;
5432         portid_t port_id;
5433 };
5434
5435 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5436                 __attribute__((unused))  struct cmdline *cl,
5437                 __attribute__((unused)) void *data)
5438 {
5439         struct cmd_set_bonding_mode_result *res = parsed_result;
5440         portid_t port_id = res->port_id;
5441
5442         /* Set the bonding mode for the relevant port. */
5443         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5444                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5445 }
5446
5447 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5448 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5449                 set, "set");
5450 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5451 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5452                 bonding, "bonding");
5453 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5454 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5455                 mode, "mode");
5456 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5457 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5458                 value, UINT8);
5459 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5460 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5461                 port_id, UINT16);
5462
5463 cmdline_parse_inst_t cmd_set_bonding_mode = {
5464                 .f = cmd_set_bonding_mode_parsed,
5465                 .help_str = "set bonding mode <mode_value> <port_id>: "
5466                         "Set the bonding mode for port_id",
5467                 .data = NULL,
5468                 .tokens = {
5469                                 (void *) &cmd_setbonding_mode_set,
5470                                 (void *) &cmd_setbonding_mode_bonding,
5471                                 (void *) &cmd_setbonding_mode_mode,
5472                                 (void *) &cmd_setbonding_mode_value,
5473                                 (void *) &cmd_setbonding_mode_port,
5474                                 NULL
5475                 }
5476 };
5477
5478 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5479 struct cmd_set_bonding_lacp_dedicated_queues_result {
5480         cmdline_fixed_string_t set;
5481         cmdline_fixed_string_t bonding;
5482         cmdline_fixed_string_t lacp;
5483         cmdline_fixed_string_t dedicated_queues;
5484         portid_t port_id;
5485         cmdline_fixed_string_t mode;
5486 };
5487
5488 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5489                 __attribute__((unused))  struct cmdline *cl,
5490                 __attribute__((unused)) void *data)
5491 {
5492         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5493         portid_t port_id = res->port_id;
5494         struct rte_port *port;
5495
5496         port = &ports[port_id];
5497
5498         /** Check if the port is not started **/
5499         if (port->port_status != RTE_PORT_STOPPED) {
5500                 printf("Please stop port %d first\n", port_id);
5501                 return;
5502         }
5503
5504         if (!strcmp(res->mode, "enable")) {
5505                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5506                         printf("Dedicate queues for LACP control packets"
5507                                         " enabled\n");
5508                 else
5509                         printf("Enabling dedicate queues for LACP control "
5510                                         "packets on port %d failed\n", port_id);
5511         } else if (!strcmp(res->mode, "disable")) {
5512                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5513                         printf("Dedicated queues for LACP control packets "
5514                                         "disabled\n");
5515                 else
5516                         printf("Disabling dedicated queues for LACP control "
5517                                         "traffic on port %d failed\n", port_id);
5518         }
5519 }
5520
5521 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5522 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5523                 set, "set");
5524 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5525 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5526                 bonding, "bonding");
5527 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5528 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5529                 lacp, "lacp");
5530 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5531 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5532                 dedicated_queues, "dedicated_queues");
5533 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5534 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5535                 port_id, UINT16);
5536 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5537 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5538                 mode, "enable#disable");
5539
5540 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5541                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5542                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5543                         "enable|disable: "
5544                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5545                 .data = NULL,
5546                 .tokens = {
5547                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5548                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5549                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5550                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5551                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5552                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5553                         NULL
5554                 }
5555 };
5556
5557 /* *** SET BALANCE XMIT POLICY *** */
5558 struct cmd_set_bonding_balance_xmit_policy_result {
5559         cmdline_fixed_string_t set;
5560         cmdline_fixed_string_t bonding;
5561         cmdline_fixed_string_t balance_xmit_policy;
5562         portid_t port_id;
5563         cmdline_fixed_string_t policy;
5564 };
5565
5566 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5567                 __attribute__((unused))  struct cmdline *cl,
5568                 __attribute__((unused)) void *data)
5569 {
5570         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5571         portid_t port_id = res->port_id;
5572         uint8_t policy;
5573
5574         if (!strcmp(res->policy, "l2")) {
5575                 policy = BALANCE_XMIT_POLICY_LAYER2;
5576         } else if (!strcmp(res->policy, "l23")) {
5577                 policy = BALANCE_XMIT_POLICY_LAYER23;
5578         } else if (!strcmp(res->policy, "l34")) {
5579                 policy = BALANCE_XMIT_POLICY_LAYER34;
5580         } else {
5581                 printf("\t Invalid xmit policy selection");
5582                 return;
5583         }
5584
5585         /* Set the bonding mode for the relevant port. */
5586         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5587                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5588                                 port_id);
5589         }
5590 }
5591
5592 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5593 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5594                 set, "set");
5595 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5596 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5597                 bonding, "bonding");
5598 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5599 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5600                 balance_xmit_policy, "balance_xmit_policy");
5601 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5602 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5603                 port_id, UINT16);
5604 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5605 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5606                 policy, "l2#l23#l34");
5607
5608 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5609                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5610                 .help_str = "set bonding balance_xmit_policy <port_id> "
5611                         "l2|l23|l34: "
5612                         "Set the bonding balance_xmit_policy for port_id",
5613                 .data = NULL,
5614                 .tokens = {
5615                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5616                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5617                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5618                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5619                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5620                                 NULL
5621                 }
5622 };
5623
5624 /* *** SHOW NIC BONDING CONFIGURATION *** */
5625 struct cmd_show_bonding_config_result {
5626         cmdline_fixed_string_t show;
5627         cmdline_fixed_string_t bonding;
5628         cmdline_fixed_string_t config;
5629         portid_t port_id;
5630 };
5631
5632 static void cmd_show_bonding_config_parsed(void *parsed_result,
5633                 __attribute__((unused))  struct cmdline *cl,
5634                 __attribute__((unused)) void *data)
5635 {
5636         struct cmd_show_bonding_config_result *res = parsed_result;
5637         int bonding_mode, agg_mode;
5638         portid_t slaves[RTE_MAX_ETHPORTS];
5639         int num_slaves, num_active_slaves;
5640         int primary_id;
5641         int i;
5642         portid_t port_id = res->port_id;
5643
5644         /* Display the bonding mode.*/
5645         bonding_mode = rte_eth_bond_mode_get(port_id);
5646         if (bonding_mode < 0) {
5647                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5648                 return;
5649         } else
5650                 printf("\tBonding mode: %d\n", bonding_mode);
5651
5652         if (bonding_mode == BONDING_MODE_BALANCE) {
5653                 int balance_xmit_policy;
5654
5655                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5656                 if (balance_xmit_policy < 0) {
5657                         printf("\tFailed to get balance xmit policy for port = %d\n",
5658                                         port_id);
5659                         return;
5660                 } else {
5661                         printf("\tBalance Xmit Policy: ");
5662
5663                         switch (balance_xmit_policy) {
5664                         case BALANCE_XMIT_POLICY_LAYER2:
5665                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5666                                 break;
5667                         case BALANCE_XMIT_POLICY_LAYER23:
5668                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5669                                 break;
5670                         case BALANCE_XMIT_POLICY_LAYER34:
5671                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5672                                 break;
5673                         }
5674                         printf("\n");
5675                 }
5676         }
5677
5678         if (bonding_mode == BONDING_MODE_8023AD) {
5679                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5680                 printf("\tIEEE802.3AD Aggregator Mode: ");
5681                 switch (agg_mode) {
5682                 case AGG_BANDWIDTH:
5683                         printf("bandwidth");
5684                         break;
5685                 case AGG_STABLE:
5686                         printf("stable");
5687                         break;
5688                 case AGG_COUNT:
5689                         printf("count");
5690                         break;
5691                 }
5692                 printf("\n");
5693         }
5694
5695         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5696
5697         if (num_slaves < 0) {
5698                 printf("\tFailed to get slave list for port = %d\n", port_id);
5699                 return;
5700         }
5701         if (num_slaves > 0) {
5702                 printf("\tSlaves (%d): [", num_slaves);
5703                 for (i = 0; i < num_slaves - 1; i++)
5704                         printf("%d ", slaves[i]);
5705
5706                 printf("%d]\n", slaves[num_slaves - 1]);
5707         } else {
5708                 printf("\tSlaves: []\n");
5709
5710         }
5711
5712         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5713                         RTE_MAX_ETHPORTS);
5714
5715         if (num_active_slaves < 0) {
5716                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5717                 return;
5718         }
5719         if (num_active_slaves > 0) {
5720                 printf("\tActive Slaves (%d): [", num_active_slaves);
5721                 for (i = 0; i < num_active_slaves - 1; i++)
5722                         printf("%d ", slaves[i]);
5723
5724                 printf("%d]\n", slaves[num_active_slaves - 1]);
5725
5726         } else {
5727                 printf("\tActive Slaves: []\n");
5728
5729         }
5730
5731         primary_id = rte_eth_bond_primary_get(port_id);
5732         if (primary_id < 0) {
5733                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5734                 return;
5735         } else
5736                 printf("\tPrimary: [%d]\n", primary_id);
5737
5738 }
5739
5740 cmdline_parse_token_string_t cmd_showbonding_config_show =
5741 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5742                 show, "show");
5743 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5744 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5745                 bonding, "bonding");
5746 cmdline_parse_token_string_t cmd_showbonding_config_config =
5747 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5748                 config, "config");
5749 cmdline_parse_token_num_t cmd_showbonding_config_port =
5750 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5751                 port_id, UINT16);
5752
5753 cmdline_parse_inst_t cmd_show_bonding_config = {
5754                 .f = cmd_show_bonding_config_parsed,
5755                 .help_str = "show bonding config <port_id>: "
5756                         "Show the bonding config for port_id",
5757                 .data = NULL,
5758                 .tokens = {
5759                                 (void *)&cmd_showbonding_config_show,
5760                                 (void *)&cmd_showbonding_config_bonding,
5761                                 (void *)&cmd_showbonding_config_config,
5762                                 (void *)&cmd_showbonding_config_port,
5763                                 NULL
5764                 }
5765 };
5766
5767 /* *** SET BONDING PRIMARY *** */
5768 struct cmd_set_bonding_primary_result {
5769         cmdline_fixed_string_t set;
5770         cmdline_fixed_string_t bonding;
5771         cmdline_fixed_string_t primary;
5772         portid_t slave_id;
5773         portid_t port_id;
5774 };
5775
5776 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5777                 __attribute__((unused))  struct cmdline *cl,
5778                 __attribute__((unused)) void *data)
5779 {
5780         struct cmd_set_bonding_primary_result *res = parsed_result;
5781         portid_t master_port_id = res->port_id;
5782         portid_t slave_port_id = res->slave_id;
5783
5784         /* Set the primary slave for a bonded device. */
5785         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5786                 printf("\t Failed to set primary slave for port = %d.\n",
5787                                 master_port_id);
5788                 return;
5789         }
5790         init_port_config();
5791 }
5792
5793 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5794 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5795                 set, "set");
5796 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5797 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5798                 bonding, "bonding");
5799 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5800 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5801                 primary, "primary");
5802 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5803 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5804                 slave_id, UINT16);
5805 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5806 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5807                 port_id, UINT16);
5808
5809 cmdline_parse_inst_t cmd_set_bonding_primary = {
5810                 .f = cmd_set_bonding_primary_parsed,
5811                 .help_str = "set bonding primary <slave_id> <port_id>: "
5812                         "Set the primary slave for port_id",
5813                 .data = NULL,
5814                 .tokens = {
5815                                 (void *)&cmd_setbonding_primary_set,
5816                                 (void *)&cmd_setbonding_primary_bonding,
5817                                 (void *)&cmd_setbonding_primary_primary,
5818                                 (void *)&cmd_setbonding_primary_slave,
5819                                 (void *)&cmd_setbonding_primary_port,
5820                                 NULL
5821                 }
5822 };
5823
5824 /* *** ADD SLAVE *** */
5825 struct cmd_add_bonding_slave_result {
5826         cmdline_fixed_string_t add;
5827         cmdline_fixed_string_t bonding;
5828         cmdline_fixed_string_t slave;
5829         portid_t slave_id;
5830         portid_t port_id;
5831 };
5832
5833 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5834                 __attribute__((unused))  struct cmdline *cl,
5835                 __attribute__((unused)) void *data)
5836 {
5837         struct cmd_add_bonding_slave_result *res = parsed_result;
5838         portid_t master_port_id = res->port_id;
5839         portid_t slave_port_id = res->slave_id;
5840
5841         /* add the slave for a bonded device. */
5842         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5843                 printf("\t Failed to add slave %d to master port = %d.\n",
5844                                 slave_port_id, master_port_id);
5845                 return;
5846         }
5847         init_port_config();
5848         set_port_slave_flag(slave_port_id);
5849 }
5850
5851 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5852 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5853                 add, "add");
5854 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5855 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5856                 bonding, "bonding");
5857 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5858 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5859                 slave, "slave");
5860 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5861 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5862                 slave_id, UINT16);
5863 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5864 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5865                 port_id, UINT16);
5866
5867 cmdline_parse_inst_t cmd_add_bonding_slave = {
5868                 .f = cmd_add_bonding_slave_parsed,
5869                 .help_str = "add bonding slave <slave_id> <port_id>: "
5870                         "Add a slave device to a bonded device",
5871                 .data = NULL,
5872                 .tokens = {
5873                                 (void *)&cmd_addbonding_slave_add,
5874                                 (void *)&cmd_addbonding_slave_bonding,
5875                                 (void *)&cmd_addbonding_slave_slave,
5876                                 (void *)&cmd_addbonding_slave_slaveid,
5877                                 (void *)&cmd_addbonding_slave_port,
5878                                 NULL
5879                 }
5880 };
5881
5882 /* *** REMOVE SLAVE *** */
5883 struct cmd_remove_bonding_slave_result {
5884         cmdline_fixed_string_t remove;
5885         cmdline_fixed_string_t bonding;
5886         cmdline_fixed_string_t slave;
5887         portid_t slave_id;
5888         portid_t port_id;
5889 };
5890
5891 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5892                 __attribute__((unused))  struct cmdline *cl,
5893                 __attribute__((unused)) void *data)
5894 {
5895         struct cmd_remove_bonding_slave_result *res = parsed_result;
5896         portid_t master_port_id = res->port_id;
5897         portid_t slave_port_id = res->slave_id;
5898
5899         /* remove the slave from a bonded device. */
5900         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5901                 printf("\t Failed to remove slave %d from master port = %d.\n",
5902                                 slave_port_id, master_port_id);
5903                 return;
5904         }
5905         init_port_config();
5906         clear_port_slave_flag(slave_port_id);
5907 }
5908
5909 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5910                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5911                                 remove, "remove");
5912 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5913                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5914                                 bonding, "bonding");
5915 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5916                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5917                                 slave, "slave");
5918 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5919                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5920                                 slave_id, UINT16);
5921 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5922                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5923                                 port_id, UINT16);
5924
5925 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5926                 .f = cmd_remove_bonding_slave_parsed,
5927                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5928                         "Remove a slave device from a bonded device",
5929                 .data = NULL,
5930                 .tokens = {
5931                                 (void *)&cmd_removebonding_slave_remove,
5932                                 (void *)&cmd_removebonding_slave_bonding,
5933                                 (void *)&cmd_removebonding_slave_slave,
5934                                 (void *)&cmd_removebonding_slave_slaveid,
5935                                 (void *)&cmd_removebonding_slave_port,
5936                                 NULL
5937                 }
5938 };
5939
5940 /* *** CREATE BONDED DEVICE *** */
5941 struct cmd_create_bonded_device_result {
5942         cmdline_fixed_string_t create;
5943         cmdline_fixed_string_t bonded;
5944         cmdline_fixed_string_t device;
5945         uint8_t mode;
5946         uint8_t socket;
5947 };
5948
5949 static int bond_dev_num = 0;
5950
5951 static void cmd_create_bonded_device_parsed(void *parsed_result,
5952                 __attribute__((unused))  struct cmdline *cl,
5953                 __attribute__((unused)) void *data)
5954 {
5955         struct cmd_create_bonded_device_result *res = parsed_result;
5956         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5957         int port_id;
5958
5959         if (test_done == 0) {
5960                 printf("Please stop forwarding first\n");
5961                 return;
5962         }
5963
5964         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5965                         bond_dev_num++);
5966
5967         /* Create a new bonded device. */
5968         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5969         if (port_id < 0) {
5970                 printf("\t Failed to create bonded device.\n");
5971                 return;
5972         } else {
5973                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5974                                 port_id);
5975
5976                 /* Update number of ports */
5977                 nb_ports = rte_eth_dev_count_avail();
5978                 reconfig(port_id, res->socket);
5979                 rte_eth_promiscuous_enable(port_id);
5980                 ports[port_id].need_setup = 0;
5981                 ports[port_id].port_status = RTE_PORT_STOPPED;
5982         }
5983
5984 }
5985
5986 cmdline_parse_token_string_t cmd_createbonded_device_create =
5987                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5988                                 create, "create");
5989 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5990                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5991                                 bonded, "bonded");
5992 cmdline_parse_token_string_t cmd_createbonded_device_device =
5993                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5994                                 device, "device");
5995 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5996                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5997                                 mode, UINT8);
5998 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5999                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6000                                 socket, UINT8);
6001
6002 cmdline_parse_inst_t cmd_create_bonded_device = {
6003                 .f = cmd_create_bonded_device_parsed,
6004                 .help_str = "create bonded device <mode> <socket>: "
6005                         "Create a new bonded device with specific bonding mode and socket",
6006                 .data = NULL,
6007                 .tokens = {
6008                                 (void *)&cmd_createbonded_device_create,
6009                                 (void *)&cmd_createbonded_device_bonded,
6010                                 (void *)&cmd_createbonded_device_device,
6011                                 (void *)&cmd_createbonded_device_mode,
6012                                 (void *)&cmd_createbonded_device_socket,
6013                                 NULL
6014                 }
6015 };
6016
6017 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6018 struct cmd_set_bond_mac_addr_result {
6019         cmdline_fixed_string_t set;
6020         cmdline_fixed_string_t bonding;
6021         cmdline_fixed_string_t mac_addr;
6022         uint16_t port_num;
6023         struct ether_addr address;
6024 };
6025
6026 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6027                 __attribute__((unused))  struct cmdline *cl,
6028                 __attribute__((unused)) void *data)
6029 {
6030         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6031         int ret;
6032
6033         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6034                 return;
6035
6036         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6037
6038         /* check the return value and print it if is < 0 */
6039         if (ret < 0)
6040                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6041 }
6042
6043 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6044                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6045 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6046                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6047                                 "bonding");
6048 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6049                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6050                                 "mac_addr");
6051 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6052                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6053                                 port_num, UINT16);
6054 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6055                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6056
6057 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6058                 .f = cmd_set_bond_mac_addr_parsed,
6059                 .data = (void *) 0,
6060                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6061                 .tokens = {
6062                                 (void *)&cmd_set_bond_mac_addr_set,
6063                                 (void *)&cmd_set_bond_mac_addr_bonding,
6064                                 (void *)&cmd_set_bond_mac_addr_mac,
6065                                 (void *)&cmd_set_bond_mac_addr_portnum,
6066                                 (void *)&cmd_set_bond_mac_addr_addr,
6067                                 NULL
6068                 }
6069 };
6070
6071
6072 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6073 struct cmd_set_bond_mon_period_result {
6074         cmdline_fixed_string_t set;
6075         cmdline_fixed_string_t bonding;
6076         cmdline_fixed_string_t mon_period;
6077         uint16_t port_num;
6078         uint32_t period_ms;
6079 };
6080
6081 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6082                 __attribute__((unused))  struct cmdline *cl,
6083                 __attribute__((unused)) void *data)
6084 {
6085         struct cmd_set_bond_mon_period_result *res = parsed_result;
6086         int ret;
6087
6088         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6089
6090         /* check the return value and print it if is < 0 */
6091         if (ret < 0)
6092                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6093 }
6094
6095 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6096                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6097                                 set, "set");
6098 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6099                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6100                                 bonding, "bonding");
6101 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6102                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6103                                 mon_period,     "mon_period");
6104 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6105                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6106                                 port_num, UINT16);
6107 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6108                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6109                                 period_ms, UINT32);
6110
6111 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6112                 .f = cmd_set_bond_mon_period_parsed,
6113                 .data = (void *) 0,
6114                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6115                 .tokens = {
6116                                 (void *)&cmd_set_bond_mon_period_set,
6117                                 (void *)&cmd_set_bond_mon_period_bonding,
6118                                 (void *)&cmd_set_bond_mon_period_mon_period,
6119                                 (void *)&cmd_set_bond_mon_period_portnum,
6120                                 (void *)&cmd_set_bond_mon_period_period_ms,
6121                                 NULL
6122                 }
6123 };
6124
6125
6126
6127 struct cmd_set_bonding_agg_mode_policy_result {
6128         cmdline_fixed_string_t set;
6129         cmdline_fixed_string_t bonding;
6130         cmdline_fixed_string_t agg_mode;
6131         uint16_t port_num;
6132         cmdline_fixed_string_t policy;
6133 };
6134
6135
6136 static void
6137 cmd_set_bonding_agg_mode(void *parsed_result,
6138                 __attribute__((unused)) struct cmdline *cl,
6139                 __attribute__((unused)) void *data)
6140 {
6141         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6142         uint8_t policy = AGG_BANDWIDTH;
6143
6144         if (!strcmp(res->policy, "bandwidth"))
6145                 policy = AGG_BANDWIDTH;
6146         else if (!strcmp(res->policy, "stable"))
6147                 policy = AGG_STABLE;
6148         else if (!strcmp(res->policy, "count"))
6149                 policy = AGG_COUNT;
6150
6151         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6152 }
6153
6154
6155 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6156         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6157                                 set, "set");
6158 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6159         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6160                                 bonding, "bonding");
6161
6162 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6163         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6164                                 agg_mode, "agg_mode");
6165
6166 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6167         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6168                                 port_num, UINT16);
6169
6170 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6171         TOKEN_STRING_INITIALIZER(
6172                         struct cmd_set_bonding_balance_xmit_policy_result,
6173                 policy, "stable#bandwidth#count");
6174
6175 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6176         .f = cmd_set_bonding_agg_mode,
6177         .data = (void *) 0,
6178         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6179         .tokens = {
6180                         (void *)&cmd_set_bonding_agg_mode_set,
6181                         (void *)&cmd_set_bonding_agg_mode_bonding,
6182                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6183                         (void *)&cmd_set_bonding_agg_mode_portnum,
6184                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6185                         NULL
6186                 }
6187 };
6188
6189
6190 #endif /* RTE_LIBRTE_PMD_BOND */
6191
6192 /* *** SET FORWARDING MODE *** */
6193 struct cmd_set_fwd_mode_result {
6194         cmdline_fixed_string_t set;
6195         cmdline_fixed_string_t fwd;
6196         cmdline_fixed_string_t mode;
6197 };
6198
6199 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6200                                     __attribute__((unused)) struct cmdline *cl,
6201                                     __attribute__((unused)) void *data)
6202 {
6203         struct cmd_set_fwd_mode_result *res = parsed_result;
6204
6205         retry_enabled = 0;
6206         set_pkt_forwarding_mode(res->mode);
6207 }
6208
6209 cmdline_parse_token_string_t cmd_setfwd_set =
6210         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6211 cmdline_parse_token_string_t cmd_setfwd_fwd =
6212         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6213 cmdline_parse_token_string_t cmd_setfwd_mode =
6214         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6215                 "" /* defined at init */);
6216
6217 cmdline_parse_inst_t cmd_set_fwd_mode = {
6218         .f = cmd_set_fwd_mode_parsed,
6219         .data = NULL,
6220         .help_str = NULL, /* defined at init */
6221         .tokens = {
6222                 (void *)&cmd_setfwd_set,
6223                 (void *)&cmd_setfwd_fwd,
6224                 (void *)&cmd_setfwd_mode,
6225                 NULL,
6226         },
6227 };
6228
6229 static void cmd_set_fwd_mode_init(void)
6230 {
6231         char *modes, *c;
6232         static char token[128];
6233         static char help[256];
6234         cmdline_parse_token_string_t *token_struct;
6235
6236         modes = list_pkt_forwarding_modes();
6237         snprintf(help, sizeof(help), "set fwd %s: "
6238                 "Set packet forwarding mode", modes);
6239         cmd_set_fwd_mode.help_str = help;
6240
6241         /* string token separator is # */
6242         for (c = token; *modes != '\0'; modes++)
6243                 if (*modes == '|')
6244                         *c++ = '#';
6245                 else
6246                         *c++ = *modes;
6247         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6248         token_struct->string_data.str = token;
6249 }
6250
6251 /* *** SET RETRY FORWARDING MODE *** */
6252 struct cmd_set_fwd_retry_mode_result {
6253         cmdline_fixed_string_t set;
6254         cmdline_fixed_string_t fwd;
6255         cmdline_fixed_string_t mode;
6256         cmdline_fixed_string_t retry;
6257 };
6258
6259 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6260                             __attribute__((unused)) struct cmdline *cl,
6261                             __attribute__((unused)) void *data)
6262 {
6263         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6264
6265         retry_enabled = 1;
6266         set_pkt_forwarding_mode(res->mode);
6267 }
6268
6269 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6270         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6271                         set, "set");
6272 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6273         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6274                         fwd, "fwd");
6275 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6276         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6277                         mode,
6278                 "" /* defined at init */);
6279 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6280         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6281                         retry, "retry");
6282
6283 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6284         .f = cmd_set_fwd_retry_mode_parsed,
6285         .data = NULL,
6286         .help_str = NULL, /* defined at init */
6287         .tokens = {
6288                 (void *)&cmd_setfwd_retry_set,
6289                 (void *)&cmd_setfwd_retry_fwd,
6290                 (void *)&cmd_setfwd_retry_mode,
6291                 (void *)&cmd_setfwd_retry_retry,
6292                 NULL,
6293         },
6294 };
6295
6296 static void cmd_set_fwd_retry_mode_init(void)
6297 {
6298         char *modes, *c;
6299         static char token[128];
6300         static char help[256];
6301         cmdline_parse_token_string_t *token_struct;
6302
6303         modes = list_pkt_forwarding_retry_modes();
6304         snprintf(help, sizeof(help), "set fwd %s retry: "
6305                 "Set packet forwarding mode with retry", modes);
6306         cmd_set_fwd_retry_mode.help_str = help;
6307
6308         /* string token separator is # */
6309         for (c = token; *modes != '\0'; modes++)
6310                 if (*modes == '|')
6311                         *c++ = '#';
6312                 else
6313                         *c++ = *modes;
6314         token_struct = (cmdline_parse_token_string_t *)
6315                 cmd_set_fwd_retry_mode.tokens[2];
6316         token_struct->string_data.str = token;
6317 }
6318
6319 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6320 struct cmd_set_burst_tx_retry_result {
6321         cmdline_fixed_string_t set;
6322         cmdline_fixed_string_t burst;
6323         cmdline_fixed_string_t tx;
6324         cmdline_fixed_string_t delay;
6325         uint32_t time;
6326         cmdline_fixed_string_t retry;
6327         uint32_t retry_num;
6328 };
6329
6330 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6331                                         __attribute__((unused)) struct cmdline *cl,
6332                                         __attribute__((unused)) void *data)
6333 {
6334         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6335
6336         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6337                 && !strcmp(res->tx, "tx")) {
6338                 if (!strcmp(res->delay, "delay"))
6339                         burst_tx_delay_time = res->time;
6340                 if (!strcmp(res->retry, "retry"))
6341                         burst_tx_retry_num = res->retry_num;
6342         }
6343
6344 }
6345
6346 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6347         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6348 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6349         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6350                                  "burst");
6351 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6352         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6353 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6354         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6355 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6356         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6357 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6358         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6359 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6360         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6361
6362 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6363         .f = cmd_set_burst_tx_retry_parsed,
6364         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6365         .tokens = {
6366                 (void *)&cmd_set_burst_tx_retry_set,
6367                 (void *)&cmd_set_burst_tx_retry_burst,
6368                 (void *)&cmd_set_burst_tx_retry_tx,
6369                 (void *)&cmd_set_burst_tx_retry_delay,
6370                 (void *)&cmd_set_burst_tx_retry_time,
6371                 (void *)&cmd_set_burst_tx_retry_retry,
6372                 (void *)&cmd_set_burst_tx_retry_retry_num,
6373                 NULL,
6374         },
6375 };
6376
6377 /* *** SET PROMISC MODE *** */
6378 struct cmd_set_promisc_mode_result {
6379         cmdline_fixed_string_t set;
6380         cmdline_fixed_string_t promisc;
6381         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6382         uint16_t port_num;               /* valid if "allports" argument == 0 */
6383         cmdline_fixed_string_t mode;
6384 };
6385
6386 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6387                                         __attribute__((unused)) struct cmdline *cl,
6388                                         void *allports)
6389 {
6390         struct cmd_set_promisc_mode_result *res = parsed_result;
6391         int enable;
6392         portid_t i;
6393
6394         if (!strcmp(res->mode, "on"))
6395                 enable = 1;
6396         else
6397                 enable = 0;
6398
6399         /* all ports */
6400         if (allports) {
6401                 RTE_ETH_FOREACH_DEV(i) {
6402                         if (enable)
6403                                 rte_eth_promiscuous_enable(i);
6404                         else
6405                                 rte_eth_promiscuous_disable(i);
6406                 }
6407         }
6408         else {
6409                 if (enable)
6410                         rte_eth_promiscuous_enable(res->port_num);
6411                 else
6412                         rte_eth_promiscuous_disable(res->port_num);
6413         }
6414 }
6415
6416 cmdline_parse_token_string_t cmd_setpromisc_set =
6417         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6418 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6419         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6420                                  "promisc");
6421 cmdline_parse_token_string_t cmd_setpromisc_portall =
6422         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6423                                  "all");
6424 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6425         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6426                               UINT16);
6427 cmdline_parse_token_string_t cmd_setpromisc_mode =
6428         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6429                                  "on#off");
6430
6431 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6432         .f = cmd_set_promisc_mode_parsed,
6433         .data = (void *)1,
6434         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6435         .tokens = {
6436                 (void *)&cmd_setpromisc_set,
6437                 (void *)&cmd_setpromisc_promisc,
6438                 (void *)&cmd_setpromisc_portall,
6439                 (void *)&cmd_setpromisc_mode,
6440                 NULL,
6441         },
6442 };
6443
6444 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6445         .f = cmd_set_promisc_mode_parsed,
6446         .data = (void *)0,
6447         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6448         .tokens = {
6449                 (void *)&cmd_setpromisc_set,
6450                 (void *)&cmd_setpromisc_promisc,
6451                 (void *)&cmd_setpromisc_portnum,
6452                 (void *)&cmd_setpromisc_mode,
6453                 NULL,
6454         },
6455 };
6456
6457 /* *** SET ALLMULTI MODE *** */
6458 struct cmd_set_allmulti_mode_result {
6459         cmdline_fixed_string_t set;
6460         cmdline_fixed_string_t allmulti;
6461         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6462         uint16_t port_num;               /* valid if "allports" argument == 0 */
6463         cmdline_fixed_string_t mode;
6464 };
6465
6466 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6467                                         __attribute__((unused)) struct cmdline *cl,
6468                                         void *allports)
6469 {
6470         struct cmd_set_allmulti_mode_result *res = parsed_result;
6471         int enable;
6472         portid_t i;
6473
6474         if (!strcmp(res->mode, "on"))
6475                 enable = 1;
6476         else
6477                 enable = 0;
6478
6479         /* all ports */
6480         if (allports) {
6481                 RTE_ETH_FOREACH_DEV(i) {
6482                         if (enable)
6483                                 rte_eth_allmulticast_enable(i);
6484                         else
6485                                 rte_eth_allmulticast_disable(i);
6486                 }
6487         }
6488         else {
6489                 if (enable)
6490                         rte_eth_allmulticast_enable(res->port_num);
6491                 else
6492                         rte_eth_allmulticast_disable(res->port_num);
6493         }
6494 }
6495
6496 cmdline_parse_token_string_t cmd_setallmulti_set =
6497         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6498 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6499         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6500                                  "allmulti");
6501 cmdline_parse_token_string_t cmd_setallmulti_portall =
6502         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6503                                  "all");
6504 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6505         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6506                               UINT16);
6507 cmdline_parse_token_string_t cmd_setallmulti_mode =
6508         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6509                                  "on#off");
6510
6511 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6512         .f = cmd_set_allmulti_mode_parsed,
6513         .data = (void *)1,
6514         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6515         .tokens = {
6516                 (void *)&cmd_setallmulti_set,
6517                 (void *)&cmd_setallmulti_allmulti,
6518                 (void *)&cmd_setallmulti_portall,
6519                 (void *)&cmd_setallmulti_mode,
6520                 NULL,
6521         },
6522 };
6523
6524 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6525         .f = cmd_set_allmulti_mode_parsed,
6526         .data = (void *)0,
6527         .help_str = "set allmulti <port_id> on|off: "
6528                 "Set allmulti mode on port_id",
6529         .tokens = {
6530                 (void *)&cmd_setallmulti_set,
6531                 (void *)&cmd_setallmulti_allmulti,
6532                 (void *)&cmd_setallmulti_portnum,
6533                 (void *)&cmd_setallmulti_mode,
6534                 NULL,
6535         },
6536 };
6537
6538 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6539 struct cmd_link_flow_ctrl_set_result {
6540         cmdline_fixed_string_t set;
6541         cmdline_fixed_string_t flow_ctrl;
6542         cmdline_fixed_string_t rx;
6543         cmdline_fixed_string_t rx_lfc_mode;
6544         cmdline_fixed_string_t tx;
6545         cmdline_fixed_string_t tx_lfc_mode;
6546         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6547         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6548         cmdline_fixed_string_t autoneg_str;
6549         cmdline_fixed_string_t autoneg;
6550         cmdline_fixed_string_t hw_str;
6551         uint32_t high_water;
6552         cmdline_fixed_string_t lw_str;
6553         uint32_t low_water;
6554         cmdline_fixed_string_t pt_str;
6555         uint16_t pause_time;
6556         cmdline_fixed_string_t xon_str;
6557         uint16_t send_xon;
6558         portid_t port_id;
6559 };
6560
6561 cmdline_parse_token_string_t cmd_lfc_set_set =
6562         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6563                                 set, "set");
6564 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6565         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6566                                 flow_ctrl, "flow_ctrl");
6567 cmdline_parse_token_string_t cmd_lfc_set_rx =
6568         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6569                                 rx, "rx");
6570 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6571         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6572                                 rx_lfc_mode, "on#off");
6573 cmdline_parse_token_string_t cmd_lfc_set_tx =
6574         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6575                                 tx, "tx");
6576 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6577         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6578                                 tx_lfc_mode, "on#off");
6579 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6580         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6581                                 hw_str, "high_water");
6582 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6583         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6584                                 high_water, UINT32);
6585 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6586         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6587                                 lw_str, "low_water");
6588 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6589         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6590                                 low_water, UINT32);
6591 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6592         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6593                                 pt_str, "pause_time");
6594 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6595         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6596                                 pause_time, UINT16);
6597 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6598         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6599                                 xon_str, "send_xon");
6600 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6601         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6602                                 send_xon, UINT16);
6603 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6604         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6605                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6606 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6607         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6608                                 mac_ctrl_frame_fwd_mode, "on#off");
6609 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6610         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6611                                 autoneg_str, "autoneg");
6612 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6613         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6614                                 autoneg, "on#off");
6615 cmdline_parse_token_num_t cmd_lfc_set_portid =
6616         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6617                                 port_id, UINT16);
6618
6619 /* forward declaration */
6620 static void
6621 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6622                               void *data);
6623
6624 cmdline_parse_inst_t cmd_link_flow_control_set = {
6625         .f = cmd_link_flow_ctrl_set_parsed,
6626         .data = NULL,
6627         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6628                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6629                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6630         .tokens = {
6631                 (void *)&cmd_lfc_set_set,
6632                 (void *)&cmd_lfc_set_flow_ctrl,
6633                 (void *)&cmd_lfc_set_rx,
6634                 (void *)&cmd_lfc_set_rx_mode,
6635                 (void *)&cmd_lfc_set_tx,
6636                 (void *)&cmd_lfc_set_tx_mode,
6637                 (void *)&cmd_lfc_set_high_water,
6638                 (void *)&cmd_lfc_set_low_water,
6639                 (void *)&cmd_lfc_set_pause_time,
6640                 (void *)&cmd_lfc_set_send_xon,
6641                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6642                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6643                 (void *)&cmd_lfc_set_autoneg_str,
6644                 (void *)&cmd_lfc_set_autoneg,
6645                 (void *)&cmd_lfc_set_portid,
6646                 NULL,
6647         },
6648 };
6649
6650 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6651         .f = cmd_link_flow_ctrl_set_parsed,
6652         .data = (void *)&cmd_link_flow_control_set_rx,
6653         .help_str = "set flow_ctrl rx on|off <port_id>: "
6654                 "Change rx flow control parameter",
6655         .tokens = {
6656                 (void *)&cmd_lfc_set_set,
6657                 (void *)&cmd_lfc_set_flow_ctrl,
6658                 (void *)&cmd_lfc_set_rx,
6659                 (void *)&cmd_lfc_set_rx_mode,
6660                 (void *)&cmd_lfc_set_portid,
6661                 NULL,
6662         },
6663 };
6664
6665 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6666         .f = cmd_link_flow_ctrl_set_parsed,
6667         .data = (void *)&cmd_link_flow_control_set_tx,
6668         .help_str = "set flow_ctrl tx on|off <port_id>: "
6669                 "Change tx flow control parameter",
6670         .tokens = {
6671                 (void *)&cmd_lfc_set_set,
6672                 (void *)&cmd_lfc_set_flow_ctrl,
6673                 (void *)&cmd_lfc_set_tx,
6674                 (void *)&cmd_lfc_set_tx_mode,
6675                 (void *)&cmd_lfc_set_portid,
6676                 NULL,
6677         },
6678 };
6679
6680 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6681         .f = cmd_link_flow_ctrl_set_parsed,
6682         .data = (void *)&cmd_link_flow_control_set_hw,
6683         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6684                 "Change high water flow control parameter",
6685         .tokens = {
6686                 (void *)&cmd_lfc_set_set,
6687                 (void *)&cmd_lfc_set_flow_ctrl,
6688                 (void *)&cmd_lfc_set_high_water_str,
6689                 (void *)&cmd_lfc_set_high_water,
6690                 (void *)&cmd_lfc_set_portid,
6691                 NULL,
6692         },
6693 };
6694
6695 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6696         .f = cmd_link_flow_ctrl_set_parsed,
6697         .data = (void *)&cmd_link_flow_control_set_lw,
6698         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6699                 "Change low water flow control parameter",
6700         .tokens = {
6701                 (void *)&cmd_lfc_set_set,
6702                 (void *)&cmd_lfc_set_flow_ctrl,
6703                 (void *)&cmd_lfc_set_low_water_str,
6704                 (void *)&cmd_lfc_set_low_water,
6705                 (void *)&cmd_lfc_set_portid,
6706                 NULL,
6707         },
6708 };
6709
6710 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6711         .f = cmd_link_flow_ctrl_set_parsed,
6712         .data = (void *)&cmd_link_flow_control_set_pt,
6713         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6714                 "Change pause time flow control parameter",
6715         .tokens = {
6716                 (void *)&cmd_lfc_set_set,
6717                 (void *)&cmd_lfc_set_flow_ctrl,
6718                 (void *)&cmd_lfc_set_pause_time_str,
6719                 (void *)&cmd_lfc_set_pause_time,
6720                 (void *)&cmd_lfc_set_portid,
6721                 NULL,
6722         },
6723 };
6724
6725 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6726         .f = cmd_link_flow_ctrl_set_parsed,
6727         .data = (void *)&cmd_link_flow_control_set_xon,
6728         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6729                 "Change send_xon flow control parameter",
6730         .tokens = {
6731                 (void *)&cmd_lfc_set_set,
6732                 (void *)&cmd_lfc_set_flow_ctrl,
6733                 (void *)&cmd_lfc_set_send_xon_str,
6734                 (void *)&cmd_lfc_set_send_xon,
6735                 (void *)&cmd_lfc_set_portid,
6736                 NULL,
6737         },
6738 };
6739
6740 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6741         .f = cmd_link_flow_ctrl_set_parsed,
6742         .data = (void *)&cmd_link_flow_control_set_macfwd,
6743         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6744                 "Change mac ctrl fwd flow control parameter",
6745         .tokens = {
6746                 (void *)&cmd_lfc_set_set,
6747                 (void *)&cmd_lfc_set_flow_ctrl,
6748                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6749                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6750                 (void *)&cmd_lfc_set_portid,
6751                 NULL,
6752         },
6753 };
6754
6755 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6756         .f = cmd_link_flow_ctrl_set_parsed,
6757         .data = (void *)&cmd_link_flow_control_set_autoneg,
6758         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6759                 "Change autoneg flow control parameter",
6760         .tokens = {
6761                 (void *)&cmd_lfc_set_set,
6762                 (void *)&cmd_lfc_set_flow_ctrl,
6763                 (void *)&cmd_lfc_set_autoneg_str,
6764                 (void *)&cmd_lfc_set_autoneg,
6765                 (void *)&cmd_lfc_set_portid,
6766                 NULL,
6767         },
6768 };
6769
6770 static void
6771 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6772                               __attribute__((unused)) struct cmdline *cl,
6773                               void *data)
6774 {
6775         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6776         cmdline_parse_inst_t *cmd = data;
6777         struct rte_eth_fc_conf fc_conf;
6778         int rx_fc_en = 0;
6779         int tx_fc_en = 0;
6780         int ret;
6781
6782         /*
6783          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6784          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6785          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6786          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6787          */
6788         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6789                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6790         };
6791
6792         /* Partial command line, retrieve current configuration */
6793         if (cmd) {
6794                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6795                 if (ret != 0) {
6796                         printf("cannot get current flow ctrl parameters, return"
6797                                "code = %d\n", ret);
6798                         return;
6799                 }
6800
6801                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6802                     (fc_conf.mode == RTE_FC_FULL))
6803                         rx_fc_en = 1;
6804                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6805                     (fc_conf.mode == RTE_FC_FULL))
6806                         tx_fc_en = 1;
6807         }
6808
6809         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6810                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6811
6812         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6813                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6814
6815         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6816
6817         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6818                 fc_conf.high_water = res->high_water;
6819
6820         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6821                 fc_conf.low_water = res->low_water;
6822
6823         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6824                 fc_conf.pause_time = res->pause_time;
6825
6826         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6827                 fc_conf.send_xon = res->send_xon;
6828
6829         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6830                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6831                         fc_conf.mac_ctrl_frame_fwd = 1;
6832                 else
6833                         fc_conf.mac_ctrl_frame_fwd = 0;
6834         }
6835
6836         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6837                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6838
6839         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6840         if (ret != 0)
6841                 printf("bad flow contrl parameter, return code = %d \n", ret);
6842 }
6843
6844 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6845 struct cmd_priority_flow_ctrl_set_result {
6846         cmdline_fixed_string_t set;
6847         cmdline_fixed_string_t pfc_ctrl;
6848         cmdline_fixed_string_t rx;
6849         cmdline_fixed_string_t rx_pfc_mode;
6850         cmdline_fixed_string_t tx;
6851         cmdline_fixed_string_t tx_pfc_mode;
6852         uint32_t high_water;
6853         uint32_t low_water;
6854         uint16_t pause_time;
6855         uint8_t  priority;
6856         portid_t port_id;
6857 };
6858
6859 static void
6860 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6861                        __attribute__((unused)) struct cmdline *cl,
6862                        __attribute__((unused)) void *data)
6863 {
6864         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6865         struct rte_eth_pfc_conf pfc_conf;
6866         int rx_fc_enable, tx_fc_enable;
6867         int ret;
6868
6869         /*
6870          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6871          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6872          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6873          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6874          */
6875         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6876                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6877         };
6878
6879         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6880         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6881         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6882         pfc_conf.fc.high_water = res->high_water;
6883         pfc_conf.fc.low_water  = res->low_water;
6884         pfc_conf.fc.pause_time = res->pause_time;
6885         pfc_conf.priority      = res->priority;
6886
6887         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6888         if (ret != 0)
6889                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6890 }
6891
6892 cmdline_parse_token_string_t cmd_pfc_set_set =
6893         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6894                                 set, "set");
6895 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6896         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6897                                 pfc_ctrl, "pfc_ctrl");
6898 cmdline_parse_token_string_t cmd_pfc_set_rx =
6899         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6900                                 rx, "rx");
6901 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6902         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6903                                 rx_pfc_mode, "on#off");
6904 cmdline_parse_token_string_t cmd_pfc_set_tx =
6905         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6906                                 tx, "tx");
6907 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6908         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6909                                 tx_pfc_mode, "on#off");
6910 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6911         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6912                                 high_water, UINT32);
6913 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6914         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6915                                 low_water, UINT32);
6916 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6917         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6918                                 pause_time, UINT16);
6919 cmdline_parse_token_num_t cmd_pfc_set_priority =
6920         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6921                                 priority, UINT8);
6922 cmdline_parse_token_num_t cmd_pfc_set_portid =
6923         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6924                                 port_id, UINT16);
6925
6926 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6927         .f = cmd_priority_flow_ctrl_set_parsed,
6928         .data = NULL,
6929         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6930                 "<pause_time> <priority> <port_id>: "
6931                 "Configure the Ethernet priority flow control",
6932         .tokens = {
6933                 (void *)&cmd_pfc_set_set,
6934                 (void *)&cmd_pfc_set_flow_ctrl,
6935                 (void *)&cmd_pfc_set_rx,
6936                 (void *)&cmd_pfc_set_rx_mode,
6937                 (void *)&cmd_pfc_set_tx,
6938                 (void *)&cmd_pfc_set_tx_mode,
6939                 (void *)&cmd_pfc_set_high_water,
6940                 (void *)&cmd_pfc_set_low_water,
6941                 (void *)&cmd_pfc_set_pause_time,
6942                 (void *)&cmd_pfc_set_priority,
6943                 (void *)&cmd_pfc_set_portid,
6944                 NULL,
6945         },
6946 };
6947
6948 /* *** RESET CONFIGURATION *** */
6949 struct cmd_reset_result {
6950         cmdline_fixed_string_t reset;
6951         cmdline_fixed_string_t def;
6952 };
6953
6954 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6955                              struct cmdline *cl,
6956                              __attribute__((unused)) void *data)
6957 {
6958         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6959         set_def_fwd_config();
6960 }
6961
6962 cmdline_parse_token_string_t cmd_reset_set =
6963         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6964 cmdline_parse_token_string_t cmd_reset_def =
6965         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6966                                  "default");
6967
6968 cmdline_parse_inst_t cmd_reset = {
6969         .f = cmd_reset_parsed,
6970         .data = NULL,
6971         .help_str = "set default: Reset default forwarding configuration",
6972         .tokens = {
6973                 (void *)&cmd_reset_set,
6974                 (void *)&cmd_reset_def,
6975                 NULL,
6976         },
6977 };
6978
6979 /* *** START FORWARDING *** */
6980 struct cmd_start_result {
6981         cmdline_fixed_string_t start;
6982 };
6983
6984 cmdline_parse_token_string_t cmd_start_start =
6985         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6986
6987 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6988                              __attribute__((unused)) struct cmdline *cl,
6989                              __attribute__((unused)) void *data)
6990 {
6991         start_packet_forwarding(0);
6992 }
6993
6994 cmdline_parse_inst_t cmd_start = {
6995         .f = cmd_start_parsed,
6996         .data = NULL,
6997         .help_str = "start: Start packet forwarding",
6998         .tokens = {
6999                 (void *)&cmd_start_start,
7000                 NULL,
7001         },
7002 };
7003
7004 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7005 struct cmd_start_tx_first_result {
7006         cmdline_fixed_string_t start;
7007         cmdline_fixed_string_t tx_first;
7008 };
7009
7010 static void
7011 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7012                           __attribute__((unused)) struct cmdline *cl,
7013                           __attribute__((unused)) void *data)
7014 {
7015         start_packet_forwarding(1);
7016 }
7017
7018 cmdline_parse_token_string_t cmd_start_tx_first_start =
7019         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7020                                  "start");
7021 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7022         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7023                                  tx_first, "tx_first");
7024
7025 cmdline_parse_inst_t cmd_start_tx_first = {
7026         .f = cmd_start_tx_first_parsed,
7027         .data = NULL,
7028         .help_str = "start tx_first: Start packet forwarding, "
7029                 "after sending 1 burst of packets",
7030         .tokens = {
7031                 (void *)&cmd_start_tx_first_start,
7032                 (void *)&cmd_start_tx_first_tx_first,
7033                 NULL,
7034         },
7035 };
7036
7037 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7038 struct cmd_start_tx_first_n_result {
7039         cmdline_fixed_string_t start;
7040         cmdline_fixed_string_t tx_first;
7041         uint32_t tx_num;
7042 };
7043
7044 static void
7045 cmd_start_tx_first_n_parsed(void *parsed_result,
7046                           __attribute__((unused)) struct cmdline *cl,
7047                           __attribute__((unused)) void *data)
7048 {
7049         struct cmd_start_tx_first_n_result *res = parsed_result;
7050
7051         start_packet_forwarding(res->tx_num);
7052 }
7053
7054 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7055         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7056                         start, "start");
7057 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7058         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7059                         tx_first, "tx_first");
7060 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7061         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7062                         tx_num, UINT32);
7063
7064 cmdline_parse_inst_t cmd_start_tx_first_n = {
7065         .f = cmd_start_tx_first_n_parsed,
7066         .data = NULL,
7067         .help_str = "start tx_first <num>: "
7068                 "packet forwarding, after sending <num> bursts of packets",
7069         .tokens = {
7070                 (void *)&cmd_start_tx_first_n_start,
7071                 (void *)&cmd_start_tx_first_n_tx_first,
7072                 (void *)&cmd_start_tx_first_n_tx_num,
7073                 NULL,
7074         },
7075 };
7076
7077 /* *** SET LINK UP *** */
7078 struct cmd_set_link_up_result {
7079         cmdline_fixed_string_t set;
7080         cmdline_fixed_string_t link_up;
7081         cmdline_fixed_string_t port;
7082         portid_t port_id;
7083 };
7084
7085 cmdline_parse_token_string_t cmd_set_link_up_set =
7086         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7087 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7088         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7089                                 "link-up");
7090 cmdline_parse_token_string_t cmd_set_link_up_port =
7091         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7092 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7093         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7094
7095 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7096                              __attribute__((unused)) struct cmdline *cl,
7097                              __attribute__((unused)) void *data)
7098 {
7099         struct cmd_set_link_up_result *res = parsed_result;
7100         dev_set_link_up(res->port_id);
7101 }
7102
7103 cmdline_parse_inst_t cmd_set_link_up = {
7104         .f = cmd_set_link_up_parsed,
7105         .data = NULL,
7106         .help_str = "set link-up port <port id>",
7107         .tokens = {
7108                 (void *)&cmd_set_link_up_set,
7109                 (void *)&cmd_set_link_up_link_up,
7110                 (void *)&cmd_set_link_up_port,
7111                 (void *)&cmd_set_link_up_port_id,
7112                 NULL,
7113         },
7114 };
7115
7116 /* *** SET LINK DOWN *** */
7117 struct cmd_set_link_down_result {
7118         cmdline_fixed_string_t set;
7119         cmdline_fixed_string_t link_down;
7120         cmdline_fixed_string_t port;
7121         portid_t port_id;
7122 };
7123
7124 cmdline_parse_token_string_t cmd_set_link_down_set =
7125         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7126 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7127         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7128                                 "link-down");
7129 cmdline_parse_token_string_t cmd_set_link_down_port =
7130         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7131 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7132         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7133
7134 static void cmd_set_link_down_parsed(
7135                                 __attribute__((unused)) void *parsed_result,
7136                                 __attribute__((unused)) struct cmdline *cl,
7137                                 __attribute__((unused)) void *data)
7138 {
7139         struct cmd_set_link_down_result *res = parsed_result;
7140         dev_set_link_down(res->port_id);
7141 }
7142
7143 cmdline_parse_inst_t cmd_set_link_down = {
7144         .f = cmd_set_link_down_parsed,
7145         .data = NULL,
7146         .help_str = "set link-down port <port id>",
7147         .tokens = {
7148                 (void *)&cmd_set_link_down_set,
7149                 (void *)&cmd_set_link_down_link_down,
7150                 (void *)&cmd_set_link_down_port,
7151                 (void *)&cmd_set_link_down_port_id,
7152                 NULL,
7153         },
7154 };
7155
7156 /* *** SHOW CFG *** */
7157 struct cmd_showcfg_result {
7158         cmdline_fixed_string_t show;
7159         cmdline_fixed_string_t cfg;
7160         cmdline_fixed_string_t what;
7161 };
7162
7163 static void cmd_showcfg_parsed(void *parsed_result,
7164                                __attribute__((unused)) struct cmdline *cl,
7165                                __attribute__((unused)) void *data)
7166 {
7167         struct cmd_showcfg_result *res = parsed_result;
7168         if (!strcmp(res->what, "rxtx"))
7169                 rxtx_config_display();
7170         else if (!strcmp(res->what, "cores"))
7171                 fwd_lcores_config_display();
7172         else if (!strcmp(res->what, "fwd"))
7173                 pkt_fwd_config_display(&cur_fwd_config);
7174         else if (!strcmp(res->what, "txpkts"))
7175                 show_tx_pkt_segments();
7176 }
7177
7178 cmdline_parse_token_string_t cmd_showcfg_show =
7179         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7180 cmdline_parse_token_string_t cmd_showcfg_port =
7181         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7182 cmdline_parse_token_string_t cmd_showcfg_what =
7183         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7184                                  "rxtx#cores#fwd#txpkts");
7185
7186 cmdline_parse_inst_t cmd_showcfg = {
7187         .f = cmd_showcfg_parsed,
7188         .data = NULL,
7189         .help_str = "show config rxtx|cores|fwd|txpkts",
7190         .tokens = {
7191                 (void *)&cmd_showcfg_show,
7192                 (void *)&cmd_showcfg_port,
7193                 (void *)&cmd_showcfg_what,
7194                 NULL,
7195         },
7196 };
7197
7198 /* *** SHOW ALL PORT INFO *** */
7199 struct cmd_showportall_result {
7200         cmdline_fixed_string_t show;
7201         cmdline_fixed_string_t port;
7202         cmdline_fixed_string_t what;
7203         cmdline_fixed_string_t all;
7204 };
7205
7206 static void cmd_showportall_parsed(void *parsed_result,
7207                                 __attribute__((unused)) struct cmdline *cl,
7208                                 __attribute__((unused)) void *data)
7209 {
7210         portid_t i;
7211
7212         struct cmd_showportall_result *res = parsed_result;
7213         if (!strcmp(res->show, "clear")) {
7214                 if (!strcmp(res->what, "stats"))
7215                         RTE_ETH_FOREACH_DEV(i)
7216                                 nic_stats_clear(i);
7217                 else if (!strcmp(res->what, "xstats"))
7218                         RTE_ETH_FOREACH_DEV(i)
7219                                 nic_xstats_clear(i);
7220         } else if (!strcmp(res->what, "info"))
7221                 RTE_ETH_FOREACH_DEV(i)
7222                         port_infos_display(i);
7223         else if (!strcmp(res->what, "summary")) {
7224                 port_summary_header_display();
7225                 RTE_ETH_FOREACH_DEV(i)
7226                         port_summary_display(i);
7227         }
7228         else if (!strcmp(res->what, "stats"))
7229                 RTE_ETH_FOREACH_DEV(i)
7230                         nic_stats_display(i);
7231         else if (!strcmp(res->what, "xstats"))
7232                 RTE_ETH_FOREACH_DEV(i)
7233                         nic_xstats_display(i);
7234         else if (!strcmp(res->what, "fdir"))
7235                 RTE_ETH_FOREACH_DEV(i)
7236                         fdir_get_infos(i);
7237         else if (!strcmp(res->what, "stat_qmap"))
7238                 RTE_ETH_FOREACH_DEV(i)
7239                         nic_stats_mapping_display(i);
7240         else if (!strcmp(res->what, "dcb_tc"))
7241                 RTE_ETH_FOREACH_DEV(i)
7242                         port_dcb_info_display(i);
7243         else if (!strcmp(res->what, "cap"))
7244                 RTE_ETH_FOREACH_DEV(i)
7245                         port_offload_cap_display(i);
7246 }
7247
7248 cmdline_parse_token_string_t cmd_showportall_show =
7249         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7250                                  "show#clear");
7251 cmdline_parse_token_string_t cmd_showportall_port =
7252         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7253 cmdline_parse_token_string_t cmd_showportall_what =
7254         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7255                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7256 cmdline_parse_token_string_t cmd_showportall_all =
7257         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7258 cmdline_parse_inst_t cmd_showportall = {
7259         .f = cmd_showportall_parsed,
7260         .data = NULL,
7261         .help_str = "show|clear port "
7262                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7263         .tokens = {
7264                 (void *)&cmd_showportall_show,
7265                 (void *)&cmd_showportall_port,
7266                 (void *)&cmd_showportall_what,
7267                 (void *)&cmd_showportall_all,
7268                 NULL,
7269         },
7270 };
7271
7272 /* *** SHOW PORT INFO *** */
7273 struct cmd_showport_result {
7274         cmdline_fixed_string_t show;
7275         cmdline_fixed_string_t port;
7276         cmdline_fixed_string_t what;
7277         uint16_t portnum;
7278 };
7279
7280 static void cmd_showport_parsed(void *parsed_result,
7281                                 __attribute__((unused)) struct cmdline *cl,
7282                                 __attribute__((unused)) void *data)
7283 {
7284         struct cmd_showport_result *res = parsed_result;
7285         if (!strcmp(res->show, "clear")) {
7286                 if (!strcmp(res->what, "stats"))
7287                         nic_stats_clear(res->portnum);
7288                 else if (!strcmp(res->what, "xstats"))
7289                         nic_xstats_clear(res->portnum);
7290         } else if (!strcmp(res->what, "info"))
7291                 port_infos_display(res->portnum);
7292         else if (!strcmp(res->what, "summary")) {
7293                 port_summary_header_display();
7294                 port_summary_display(res->portnum);
7295         }
7296         else if (!strcmp(res->what, "stats"))
7297                 nic_stats_display(res->portnum);
7298         else if (!strcmp(res->what, "xstats"))
7299                 nic_xstats_display(res->portnum);
7300         else if (!strcmp(res->what, "fdir"))
7301                  fdir_get_infos(res->portnum);
7302         else if (!strcmp(res->what, "stat_qmap"))
7303                 nic_stats_mapping_display(res->portnum);
7304         else if (!strcmp(res->what, "dcb_tc"))
7305                 port_dcb_info_display(res->portnum);
7306         else if (!strcmp(res->what, "cap"))
7307                 port_offload_cap_display(res->portnum);
7308 }
7309
7310 cmdline_parse_token_string_t cmd_showport_show =
7311         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7312                                  "show#clear");
7313 cmdline_parse_token_string_t cmd_showport_port =
7314         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7315 cmdline_parse_token_string_t cmd_showport_what =
7316         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7317                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7318 cmdline_parse_token_num_t cmd_showport_portnum =
7319         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7320
7321 cmdline_parse_inst_t cmd_showport = {
7322         .f = cmd_showport_parsed,
7323         .data = NULL,
7324         .help_str = "show|clear port "
7325                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7326                 "<port_id>",
7327         .tokens = {
7328                 (void *)&cmd_showport_show,
7329                 (void *)&cmd_showport_port,
7330                 (void *)&cmd_showport_what,
7331                 (void *)&cmd_showport_portnum,
7332                 NULL,
7333         },
7334 };
7335
7336 /* *** SHOW QUEUE INFO *** */
7337 struct cmd_showqueue_result {
7338         cmdline_fixed_string_t show;
7339         cmdline_fixed_string_t type;
7340         cmdline_fixed_string_t what;
7341         uint16_t portnum;
7342         uint16_t queuenum;
7343 };
7344
7345 static void
7346 cmd_showqueue_parsed(void *parsed_result,
7347         __attribute__((unused)) struct cmdline *cl,
7348         __attribute__((unused)) void *data)
7349 {
7350         struct cmd_showqueue_result *res = parsed_result;
7351
7352         if (!strcmp(res->type, "rxq"))
7353                 rx_queue_infos_display(res->portnum, res->queuenum);
7354         else if (!strcmp(res->type, "txq"))
7355                 tx_queue_infos_display(res->portnum, res->queuenum);
7356 }
7357
7358 cmdline_parse_token_string_t cmd_showqueue_show =
7359         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7360 cmdline_parse_token_string_t cmd_showqueue_type =
7361         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7362 cmdline_parse_token_string_t cmd_showqueue_what =
7363         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7364 cmdline_parse_token_num_t cmd_showqueue_portnum =
7365         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7366 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7367         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7368
7369 cmdline_parse_inst_t cmd_showqueue = {
7370         .f = cmd_showqueue_parsed,
7371         .data = NULL,
7372         .help_str = "show rxq|txq info <port_id> <queue_id>",
7373         .tokens = {
7374                 (void *)&cmd_showqueue_show,
7375                 (void *)&cmd_showqueue_type,
7376                 (void *)&cmd_showqueue_what,
7377                 (void *)&cmd_showqueue_portnum,
7378                 (void *)&cmd_showqueue_queuenum,
7379                 NULL,
7380         },
7381 };
7382
7383 /* *** READ PORT REGISTER *** */
7384 struct cmd_read_reg_result {
7385         cmdline_fixed_string_t read;
7386         cmdline_fixed_string_t reg;
7387         portid_t port_id;
7388         uint32_t reg_off;
7389 };
7390
7391 static void
7392 cmd_read_reg_parsed(void *parsed_result,
7393                     __attribute__((unused)) struct cmdline *cl,
7394                     __attribute__((unused)) void *data)
7395 {
7396         struct cmd_read_reg_result *res = parsed_result;
7397         port_reg_display(res->port_id, res->reg_off);
7398 }
7399
7400 cmdline_parse_token_string_t cmd_read_reg_read =
7401         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7402 cmdline_parse_token_string_t cmd_read_reg_reg =
7403         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7404 cmdline_parse_token_num_t cmd_read_reg_port_id =
7405         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7406 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7407         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7408
7409 cmdline_parse_inst_t cmd_read_reg = {
7410         .f = cmd_read_reg_parsed,
7411         .data = NULL,
7412         .help_str = "read reg <port_id> <reg_off>",
7413         .tokens = {
7414                 (void *)&cmd_read_reg_read,
7415                 (void *)&cmd_read_reg_reg,
7416                 (void *)&cmd_read_reg_port_id,
7417                 (void *)&cmd_read_reg_reg_off,
7418                 NULL,
7419         },
7420 };
7421
7422 /* *** READ PORT REGISTER BIT FIELD *** */
7423 struct cmd_read_reg_bit_field_result {
7424         cmdline_fixed_string_t read;
7425         cmdline_fixed_string_t regfield;
7426         portid_t port_id;
7427         uint32_t reg_off;
7428         uint8_t bit1_pos;
7429         uint8_t bit2_pos;
7430 };
7431
7432 static void
7433 cmd_read_reg_bit_field_parsed(void *parsed_result,
7434                               __attribute__((unused)) struct cmdline *cl,
7435                               __attribute__((unused)) void *data)
7436 {
7437         struct cmd_read_reg_bit_field_result *res = parsed_result;
7438         port_reg_bit_field_display(res->port_id, res->reg_off,
7439                                    res->bit1_pos, res->bit2_pos);
7440 }
7441
7442 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7443         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7444                                  "read");
7445 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7446         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7447                                  regfield, "regfield");
7448 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7449         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7450                               UINT16);
7451 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7452         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7453                               UINT32);
7454 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7455         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7456                               UINT8);
7457 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7458         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7459                               UINT8);
7460
7461 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7462         .f = cmd_read_reg_bit_field_parsed,
7463         .data = NULL,
7464         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7465         "Read register bit field between bit_x and bit_y included",
7466         .tokens = {
7467                 (void *)&cmd_read_reg_bit_field_read,
7468                 (void *)&cmd_read_reg_bit_field_regfield,
7469                 (void *)&cmd_read_reg_bit_field_port_id,
7470                 (void *)&cmd_read_reg_bit_field_reg_off,
7471                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7472                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7473                 NULL,
7474         },
7475 };
7476
7477 /* *** READ PORT REGISTER BIT *** */
7478 struct cmd_read_reg_bit_result {
7479         cmdline_fixed_string_t read;
7480         cmdline_fixed_string_t regbit;
7481         portid_t port_id;
7482         uint32_t reg_off;
7483         uint8_t bit_pos;
7484 };
7485
7486 static void
7487 cmd_read_reg_bit_parsed(void *parsed_result,
7488                         __attribute__((unused)) struct cmdline *cl,
7489                         __attribute__((unused)) void *data)
7490 {
7491         struct cmd_read_reg_bit_result *res = parsed_result;
7492         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7493 }
7494
7495 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7496         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7497 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7498         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7499                                  regbit, "regbit");
7500 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7501         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7502 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7503         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7504 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7505         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7506
7507 cmdline_parse_inst_t cmd_read_reg_bit = {
7508         .f = cmd_read_reg_bit_parsed,
7509         .data = NULL,
7510         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7511         .tokens = {
7512                 (void *)&cmd_read_reg_bit_read,
7513                 (void *)&cmd_read_reg_bit_regbit,
7514                 (void *)&cmd_read_reg_bit_port_id,
7515                 (void *)&cmd_read_reg_bit_reg_off,
7516                 (void *)&cmd_read_reg_bit_bit_pos,
7517                 NULL,
7518         },
7519 };
7520
7521 /* *** WRITE PORT REGISTER *** */
7522 struct cmd_write_reg_result {
7523         cmdline_fixed_string_t write;
7524         cmdline_fixed_string_t reg;
7525         portid_t port_id;
7526         uint32_t reg_off;
7527         uint32_t value;
7528 };
7529
7530 static void
7531 cmd_write_reg_parsed(void *parsed_result,
7532                      __attribute__((unused)) struct cmdline *cl,
7533                      __attribute__((unused)) void *data)
7534 {
7535         struct cmd_write_reg_result *res = parsed_result;
7536         port_reg_set(res->port_id, res->reg_off, res->value);
7537 }
7538
7539 cmdline_parse_token_string_t cmd_write_reg_write =
7540         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7541 cmdline_parse_token_string_t cmd_write_reg_reg =
7542         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7543 cmdline_parse_token_num_t cmd_write_reg_port_id =
7544         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7545 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7546         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7547 cmdline_parse_token_num_t cmd_write_reg_value =
7548         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7549
7550 cmdline_parse_inst_t cmd_write_reg = {
7551         .f = cmd_write_reg_parsed,
7552         .data = NULL,
7553         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7554         .tokens = {
7555                 (void *)&cmd_write_reg_write,
7556                 (void *)&cmd_write_reg_reg,
7557                 (void *)&cmd_write_reg_port_id,
7558                 (void *)&cmd_write_reg_reg_off,
7559                 (void *)&cmd_write_reg_value,
7560                 NULL,
7561         },
7562 };
7563
7564 /* *** WRITE PORT REGISTER BIT FIELD *** */
7565 struct cmd_write_reg_bit_field_result {
7566         cmdline_fixed_string_t write;
7567         cmdline_fixed_string_t regfield;
7568         portid_t port_id;
7569         uint32_t reg_off;
7570         uint8_t bit1_pos;
7571         uint8_t bit2_pos;
7572         uint32_t value;
7573 };
7574
7575 static void
7576 cmd_write_reg_bit_field_parsed(void *parsed_result,
7577                                __attribute__((unused)) struct cmdline *cl,
7578                                __attribute__((unused)) void *data)
7579 {
7580         struct cmd_write_reg_bit_field_result *res = parsed_result;
7581         port_reg_bit_field_set(res->port_id, res->reg_off,
7582                           res->bit1_pos, res->bit2_pos, res->value);
7583 }
7584
7585 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7586         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7587                                  "write");
7588 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7589         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7590                                  regfield, "regfield");
7591 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7592         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7593                               UINT16);
7594 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7595         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7596                               UINT32);
7597 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7598         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7599                               UINT8);
7600 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7601         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7602                               UINT8);
7603 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7604         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7605                               UINT32);
7606
7607 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7608         .f = cmd_write_reg_bit_field_parsed,
7609         .data = NULL,
7610         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7611                 "<reg_value>: "
7612                 "Set register bit field between bit_x and bit_y included",
7613         .tokens = {
7614                 (void *)&cmd_write_reg_bit_field_write,
7615                 (void *)&cmd_write_reg_bit_field_regfield,
7616                 (void *)&cmd_write_reg_bit_field_port_id,
7617                 (void *)&cmd_write_reg_bit_field_reg_off,
7618                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7619                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7620                 (void *)&cmd_write_reg_bit_field_value,
7621                 NULL,
7622         },
7623 };
7624
7625 /* *** WRITE PORT REGISTER BIT *** */
7626 struct cmd_write_reg_bit_result {
7627         cmdline_fixed_string_t write;
7628         cmdline_fixed_string_t regbit;
7629         portid_t port_id;
7630         uint32_t reg_off;
7631         uint8_t bit_pos;
7632         uint8_t value;
7633 };
7634
7635 static void
7636 cmd_write_reg_bit_parsed(void *parsed_result,
7637                          __attribute__((unused)) struct cmdline *cl,
7638                          __attribute__((unused)) void *data)
7639 {
7640         struct cmd_write_reg_bit_result *res = parsed_result;
7641         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7642 }
7643
7644 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7645         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7646                                  "write");
7647 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7648         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7649                                  regbit, "regbit");
7650 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7651         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7652 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7653         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7654 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7655         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7656 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7657         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7658
7659 cmdline_parse_inst_t cmd_write_reg_bit = {
7660         .f = cmd_write_reg_bit_parsed,
7661         .data = NULL,
7662         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7663                 "0 <= bit_x <= 31",
7664         .tokens = {
7665                 (void *)&cmd_write_reg_bit_write,
7666                 (void *)&cmd_write_reg_bit_regbit,
7667                 (void *)&cmd_write_reg_bit_port_id,
7668                 (void *)&cmd_write_reg_bit_reg_off,
7669                 (void *)&cmd_write_reg_bit_bit_pos,
7670                 (void *)&cmd_write_reg_bit_value,
7671                 NULL,
7672         },
7673 };
7674
7675 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7676 struct cmd_read_rxd_txd_result {
7677         cmdline_fixed_string_t read;
7678         cmdline_fixed_string_t rxd_txd;
7679         portid_t port_id;
7680         uint16_t queue_id;
7681         uint16_t desc_id;
7682 };
7683
7684 static void
7685 cmd_read_rxd_txd_parsed(void *parsed_result,
7686                         __attribute__((unused)) struct cmdline *cl,
7687                         __attribute__((unused)) void *data)
7688 {
7689         struct cmd_read_rxd_txd_result *res = parsed_result;
7690
7691         if (!strcmp(res->rxd_txd, "rxd"))
7692                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7693         else if (!strcmp(res->rxd_txd, "txd"))
7694                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7695 }
7696
7697 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7698         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7699 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7700         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7701                                  "rxd#txd");
7702 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7703         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7704 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7705         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7706 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7707         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7708
7709 cmdline_parse_inst_t cmd_read_rxd_txd = {
7710         .f = cmd_read_rxd_txd_parsed,
7711         .data = NULL,
7712         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7713         .tokens = {
7714                 (void *)&cmd_read_rxd_txd_read,
7715                 (void *)&cmd_read_rxd_txd_rxd_txd,
7716                 (void *)&cmd_read_rxd_txd_port_id,
7717                 (void *)&cmd_read_rxd_txd_queue_id,
7718                 (void *)&cmd_read_rxd_txd_desc_id,
7719                 NULL,
7720         },
7721 };
7722
7723 /* *** QUIT *** */
7724 struct cmd_quit_result {
7725         cmdline_fixed_string_t quit;
7726 };
7727
7728 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7729                             struct cmdline *cl,
7730                             __attribute__((unused)) void *data)
7731 {
7732         cmdline_quit(cl);
7733 }
7734
7735 cmdline_parse_token_string_t cmd_quit_quit =
7736         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7737
7738 cmdline_parse_inst_t cmd_quit = {
7739         .f = cmd_quit_parsed,
7740         .data = NULL,
7741         .help_str = "quit: Exit application",
7742         .tokens = {
7743                 (void *)&cmd_quit_quit,
7744                 NULL,
7745         },
7746 };
7747
7748 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7749 struct cmd_mac_addr_result {
7750         cmdline_fixed_string_t mac_addr_cmd;
7751         cmdline_fixed_string_t what;
7752         uint16_t port_num;
7753         struct ether_addr address;
7754 };
7755
7756 static void cmd_mac_addr_parsed(void *parsed_result,
7757                 __attribute__((unused)) struct cmdline *cl,
7758                 __attribute__((unused)) void *data)
7759 {
7760         struct cmd_mac_addr_result *res = parsed_result;
7761         int ret;
7762
7763         if (strcmp(res->what, "add") == 0)
7764                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7765         else if (strcmp(res->what, "set") == 0)
7766                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7767                                                        &res->address);
7768         else
7769                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7770
7771         /* check the return value and print it if is < 0 */
7772         if(ret < 0)
7773                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7774
7775 }
7776
7777 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7778         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7779                                 "mac_addr");
7780 cmdline_parse_token_string_t cmd_mac_addr_what =
7781         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7782                                 "add#remove#set");
7783 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7784                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7785                                         UINT16);
7786 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7787                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7788
7789 cmdline_parse_inst_t cmd_mac_addr = {
7790         .f = cmd_mac_addr_parsed,
7791         .data = (void *)0,
7792         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7793                         "Add/Remove/Set MAC address on port_id",
7794         .tokens = {
7795                 (void *)&cmd_mac_addr_cmd,
7796                 (void *)&cmd_mac_addr_what,
7797                 (void *)&cmd_mac_addr_portnum,
7798                 (void *)&cmd_mac_addr_addr,
7799                 NULL,
7800         },
7801 };
7802
7803 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7804 struct cmd_eth_peer_result {
7805         cmdline_fixed_string_t set;
7806         cmdline_fixed_string_t eth_peer;
7807         portid_t port_id;
7808         cmdline_fixed_string_t peer_addr;
7809 };
7810
7811 static void cmd_set_eth_peer_parsed(void *parsed_result,
7812                         __attribute__((unused)) struct cmdline *cl,
7813                         __attribute__((unused)) void *data)
7814 {
7815                 struct cmd_eth_peer_result *res = parsed_result;
7816
7817                 if (test_done == 0) {
7818                         printf("Please stop forwarding first\n");
7819                         return;
7820                 }
7821                 if (!strcmp(res->eth_peer, "eth-peer")) {
7822                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7823                         fwd_config_setup();
7824                 }
7825 }
7826 cmdline_parse_token_string_t cmd_eth_peer_set =
7827         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7828 cmdline_parse_token_string_t cmd_eth_peer =
7829         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7830 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7831         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7832 cmdline_parse_token_string_t cmd_eth_peer_addr =
7833         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7834
7835 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7836         .f = cmd_set_eth_peer_parsed,
7837         .data = NULL,
7838         .help_str = "set eth-peer <port_id> <peer_mac>",
7839         .tokens = {
7840                 (void *)&cmd_eth_peer_set,
7841                 (void *)&cmd_eth_peer,
7842                 (void *)&cmd_eth_peer_port_id,
7843                 (void *)&cmd_eth_peer_addr,
7844                 NULL,
7845         },
7846 };
7847
7848 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7849 struct cmd_set_qmap_result {
7850         cmdline_fixed_string_t set;
7851         cmdline_fixed_string_t qmap;
7852         cmdline_fixed_string_t what;
7853         portid_t port_id;
7854         uint16_t queue_id;
7855         uint8_t map_value;
7856 };
7857
7858 static void
7859 cmd_set_qmap_parsed(void *parsed_result,
7860                        __attribute__((unused)) struct cmdline *cl,
7861                        __attribute__((unused)) void *data)
7862 {
7863         struct cmd_set_qmap_result *res = parsed_result;
7864         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7865
7866         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7867 }
7868
7869 cmdline_parse_token_string_t cmd_setqmap_set =
7870         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7871                                  set, "set");
7872 cmdline_parse_token_string_t cmd_setqmap_qmap =
7873         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7874                                  qmap, "stat_qmap");
7875 cmdline_parse_token_string_t cmd_setqmap_what =
7876         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7877                                  what, "tx#rx");
7878 cmdline_parse_token_num_t cmd_setqmap_portid =
7879         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7880                               port_id, UINT16);
7881 cmdline_parse_token_num_t cmd_setqmap_queueid =
7882         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7883                               queue_id, UINT16);
7884 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7885         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7886                               map_value, UINT8);
7887
7888 cmdline_parse_inst_t cmd_set_qmap = {
7889         .f = cmd_set_qmap_parsed,
7890         .data = NULL,
7891         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7892                 "Set statistics mapping value on tx|rx queue_id of port_id",
7893         .tokens = {
7894                 (void *)&cmd_setqmap_set,
7895                 (void *)&cmd_setqmap_qmap,
7896                 (void *)&cmd_setqmap_what,
7897                 (void *)&cmd_setqmap_portid,
7898                 (void *)&cmd_setqmap_queueid,
7899                 (void *)&cmd_setqmap_mapvalue,
7900                 NULL,
7901         },
7902 };
7903
7904 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7905 struct cmd_set_xstats_hide_zero_result {
7906         cmdline_fixed_string_t keyword;
7907         cmdline_fixed_string_t name;
7908         cmdline_fixed_string_t on_off;
7909 };
7910
7911 static void
7912 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7913                         __attribute__((unused)) struct cmdline *cl,
7914                         __attribute__((unused)) void *data)
7915 {
7916         struct cmd_set_xstats_hide_zero_result *res;
7917         uint16_t on_off = 0;
7918
7919         res = parsed_result;
7920         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7921         set_xstats_hide_zero(on_off);
7922 }
7923
7924 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7925         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7926                                  keyword, "set");
7927 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7928         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7929                                  name, "xstats-hide-zero");
7930 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7931         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7932                                  on_off, "on#off");
7933
7934 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7935         .f = cmd_set_xstats_hide_zero_parsed,
7936         .data = NULL,
7937         .help_str = "set xstats-hide-zero on|off",
7938         .tokens = {
7939                 (void *)&cmd_set_xstats_hide_zero_keyword,
7940                 (void *)&cmd_set_xstats_hide_zero_name,
7941                 (void *)&cmd_set_xstats_hide_zero_on_off,
7942                 NULL,
7943         },
7944 };
7945
7946 /* *** CONFIGURE UNICAST HASH TABLE *** */
7947 struct cmd_set_uc_hash_table {
7948         cmdline_fixed_string_t set;
7949         cmdline_fixed_string_t port;
7950         portid_t port_id;
7951         cmdline_fixed_string_t what;
7952         struct ether_addr address;
7953         cmdline_fixed_string_t mode;
7954 };
7955
7956 static void
7957 cmd_set_uc_hash_parsed(void *parsed_result,
7958                        __attribute__((unused)) struct cmdline *cl,
7959                        __attribute__((unused)) void *data)
7960 {
7961         int ret=0;
7962         struct cmd_set_uc_hash_table *res = parsed_result;
7963
7964         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7965
7966         if (strcmp(res->what, "uta") == 0)
7967                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7968                                                 &res->address,(uint8_t)is_on);
7969         if (ret < 0)
7970                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7971
7972 }
7973
7974 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7975         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7976                                  set, "set");
7977 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7978         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7979                                  port, "port");
7980 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7981         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7982                               port_id, UINT16);
7983 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7984         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7985                                  what, "uta");
7986 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7987         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7988                                 address);
7989 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7990         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7991                                  mode, "on#off");
7992
7993 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7994         .f = cmd_set_uc_hash_parsed,
7995         .data = NULL,
7996         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7997         .tokens = {
7998                 (void *)&cmd_set_uc_hash_set,
7999                 (void *)&cmd_set_uc_hash_port,
8000                 (void *)&cmd_set_uc_hash_portid,
8001                 (void *)&cmd_set_uc_hash_what,
8002                 (void *)&cmd_set_uc_hash_mac,
8003                 (void *)&cmd_set_uc_hash_mode,
8004                 NULL,
8005         },
8006 };
8007
8008 struct cmd_set_uc_all_hash_table {
8009         cmdline_fixed_string_t set;
8010         cmdline_fixed_string_t port;
8011         portid_t port_id;
8012         cmdline_fixed_string_t what;
8013         cmdline_fixed_string_t value;
8014         cmdline_fixed_string_t mode;
8015 };
8016
8017 static void
8018 cmd_set_uc_all_hash_parsed(void *parsed_result,
8019                        __attribute__((unused)) struct cmdline *cl,
8020                        __attribute__((unused)) void *data)
8021 {
8022         int ret=0;
8023         struct cmd_set_uc_all_hash_table *res = parsed_result;
8024
8025         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8026
8027         if ((strcmp(res->what, "uta") == 0) &&
8028                 (strcmp(res->value, "all") == 0))
8029                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8030         if (ret < 0)
8031                 printf("bad unicast hash table parameter,"
8032                         "return code = %d \n", ret);
8033 }
8034
8035 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8036         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8037                                  set, "set");
8038 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8039         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8040                                  port, "port");
8041 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8042         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8043                               port_id, UINT16);
8044 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8045         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8046                                  what, "uta");
8047 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8048         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8049                                 value,"all");
8050 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8051         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8052                                  mode, "on#off");
8053
8054 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8055         .f = cmd_set_uc_all_hash_parsed,
8056         .data = NULL,
8057         .help_str = "set port <port_id> uta all on|off",
8058         .tokens = {
8059                 (void *)&cmd_set_uc_all_hash_set,
8060                 (void *)&cmd_set_uc_all_hash_port,
8061                 (void *)&cmd_set_uc_all_hash_portid,
8062                 (void *)&cmd_set_uc_all_hash_what,
8063                 (void *)&cmd_set_uc_all_hash_value,
8064                 (void *)&cmd_set_uc_all_hash_mode,
8065                 NULL,
8066         },
8067 };
8068
8069 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8070 struct cmd_set_vf_macvlan_filter {
8071         cmdline_fixed_string_t set;
8072         cmdline_fixed_string_t port;
8073         portid_t port_id;
8074         cmdline_fixed_string_t vf;
8075         uint8_t vf_id;
8076         struct ether_addr address;
8077         cmdline_fixed_string_t filter_type;
8078         cmdline_fixed_string_t mode;
8079 };
8080
8081 static void
8082 cmd_set_vf_macvlan_parsed(void *parsed_result,
8083                        __attribute__((unused)) struct cmdline *cl,
8084                        __attribute__((unused)) void *data)
8085 {
8086         int is_on, ret = 0;
8087         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8088         struct rte_eth_mac_filter filter;
8089
8090         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8091
8092         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
8093
8094         /* set VF MAC filter */
8095         filter.is_vf = 1;
8096
8097         /* set VF ID */
8098         filter.dst_id = res->vf_id;
8099
8100         if (!strcmp(res->filter_type, "exact-mac"))
8101                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8102         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8103                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8104         else if (!strcmp(res->filter_type, "hashmac"))
8105                 filter.filter_type = RTE_MAC_HASH_MATCH;
8106         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8107                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8108
8109         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8110
8111         if (is_on)
8112                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8113                                         RTE_ETH_FILTER_MACVLAN,
8114                                         RTE_ETH_FILTER_ADD,
8115                                          &filter);
8116         else
8117                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8118                                         RTE_ETH_FILTER_MACVLAN,
8119                                         RTE_ETH_FILTER_DELETE,
8120                                         &filter);
8121
8122         if (ret < 0)
8123                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8124
8125 }
8126
8127 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8128         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8129                                  set, "set");
8130 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8131         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8132                                  port, "port");
8133 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8134         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8135                               port_id, UINT16);
8136 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8137         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8138                                  vf, "vf");
8139 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8140         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8141                                 vf_id, UINT8);
8142 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8143         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8144                                 address);
8145 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8146         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8147                                 filter_type, "exact-mac#exact-mac-vlan"
8148                                 "#hashmac#hashmac-vlan");
8149 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8150         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8151                                  mode, "on#off");
8152
8153 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8154         .f = cmd_set_vf_macvlan_parsed,
8155         .data = NULL,
8156         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8157                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8158                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8159                 "hash match rule: hash match of MAC and exact match of VLAN",
8160         .tokens = {
8161                 (void *)&cmd_set_vf_macvlan_set,
8162                 (void *)&cmd_set_vf_macvlan_port,
8163                 (void *)&cmd_set_vf_macvlan_portid,
8164                 (void *)&cmd_set_vf_macvlan_vf,
8165                 (void *)&cmd_set_vf_macvlan_vf_id,
8166                 (void *)&cmd_set_vf_macvlan_mac,
8167                 (void *)&cmd_set_vf_macvlan_filter_type,
8168                 (void *)&cmd_set_vf_macvlan_mode,
8169                 NULL,
8170         },
8171 };
8172
8173 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8174 struct cmd_set_vf_traffic {
8175         cmdline_fixed_string_t set;
8176         cmdline_fixed_string_t port;
8177         portid_t port_id;
8178         cmdline_fixed_string_t vf;
8179         uint8_t vf_id;
8180         cmdline_fixed_string_t what;
8181         cmdline_fixed_string_t mode;
8182 };
8183
8184 static void
8185 cmd_set_vf_traffic_parsed(void *parsed_result,
8186                        __attribute__((unused)) struct cmdline *cl,
8187                        __attribute__((unused)) void *data)
8188 {
8189         struct cmd_set_vf_traffic *res = parsed_result;
8190         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8191         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8192
8193         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8194 }
8195
8196 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8197         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8198                                  set, "set");
8199 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8200         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8201                                  port, "port");
8202 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8203         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8204                               port_id, UINT16);
8205 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8206         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8207                                  vf, "vf");
8208 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8209         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8210                               vf_id, UINT8);
8211 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8212         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8213                                  what, "tx#rx");
8214 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8215         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8216                                  mode, "on#off");
8217
8218 cmdline_parse_inst_t cmd_set_vf_traffic = {
8219         .f = cmd_set_vf_traffic_parsed,
8220         .data = NULL,
8221         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8222         .tokens = {
8223                 (void *)&cmd_setvf_traffic_set,
8224                 (void *)&cmd_setvf_traffic_port,
8225                 (void *)&cmd_setvf_traffic_portid,
8226                 (void *)&cmd_setvf_traffic_vf,
8227                 (void *)&cmd_setvf_traffic_vfid,
8228                 (void *)&cmd_setvf_traffic_what,
8229                 (void *)&cmd_setvf_traffic_mode,
8230                 NULL,
8231         },
8232 };
8233
8234 /* *** CONFIGURE VF RECEIVE MODE *** */
8235 struct cmd_set_vf_rxmode {
8236         cmdline_fixed_string_t set;
8237         cmdline_fixed_string_t port;
8238         portid_t port_id;
8239         cmdline_fixed_string_t vf;
8240         uint8_t vf_id;
8241         cmdline_fixed_string_t what;
8242         cmdline_fixed_string_t mode;
8243         cmdline_fixed_string_t on;
8244 };
8245
8246 static void
8247 cmd_set_vf_rxmode_parsed(void *parsed_result,
8248                        __attribute__((unused)) struct cmdline *cl,
8249                        __attribute__((unused)) void *data)
8250 {
8251         int ret = -ENOTSUP;
8252         uint16_t rx_mode = 0;
8253         struct cmd_set_vf_rxmode *res = parsed_result;
8254
8255         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8256         if (!strcmp(res->what,"rxmode")) {
8257                 if (!strcmp(res->mode, "AUPE"))
8258                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8259                 else if (!strcmp(res->mode, "ROPE"))
8260                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8261                 else if (!strcmp(res->mode, "BAM"))
8262                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8263                 else if (!strncmp(res->mode, "MPE",3))
8264                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8265         }
8266
8267         RTE_SET_USED(is_on);
8268
8269 #ifdef RTE_LIBRTE_IXGBE_PMD
8270         if (ret == -ENOTSUP)
8271                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8272                                                   rx_mode, (uint8_t)is_on);
8273 #endif
8274 #ifdef RTE_LIBRTE_BNXT_PMD
8275         if (ret == -ENOTSUP)
8276                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8277                                                  rx_mode, (uint8_t)is_on);
8278 #endif
8279         if (ret < 0)
8280                 printf("bad VF receive mode parameter, return code = %d \n",
8281                 ret);
8282 }
8283
8284 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8285         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8286                                  set, "set");
8287 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8288         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8289                                  port, "port");
8290 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8291         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8292                               port_id, UINT16);
8293 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8294         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8295                                  vf, "vf");
8296 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8297         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8298                               vf_id, UINT8);
8299 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8300         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8301                                  what, "rxmode");
8302 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8303         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8304                                  mode, "AUPE#ROPE#BAM#MPE");
8305 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8306         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8307                                  on, "on#off");
8308
8309 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8310         .f = cmd_set_vf_rxmode_parsed,
8311         .data = NULL,
8312         .help_str = "set port <port_id> vf <vf_id> rxmode "
8313                 "AUPE|ROPE|BAM|MPE on|off",
8314         .tokens = {
8315                 (void *)&cmd_set_vf_rxmode_set,
8316                 (void *)&cmd_set_vf_rxmode_port,
8317                 (void *)&cmd_set_vf_rxmode_portid,
8318                 (void *)&cmd_set_vf_rxmode_vf,
8319                 (void *)&cmd_set_vf_rxmode_vfid,
8320                 (void *)&cmd_set_vf_rxmode_what,
8321                 (void *)&cmd_set_vf_rxmode_mode,
8322                 (void *)&cmd_set_vf_rxmode_on,
8323                 NULL,
8324         },
8325 };
8326
8327 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8328 struct cmd_vf_mac_addr_result {
8329         cmdline_fixed_string_t mac_addr_cmd;
8330         cmdline_fixed_string_t what;
8331         cmdline_fixed_string_t port;
8332         uint16_t port_num;
8333         cmdline_fixed_string_t vf;
8334         uint8_t vf_num;
8335         struct ether_addr address;
8336 };
8337
8338 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8339                 __attribute__((unused)) struct cmdline *cl,
8340                 __attribute__((unused)) void *data)
8341 {
8342         struct cmd_vf_mac_addr_result *res = parsed_result;
8343         int ret = -ENOTSUP;
8344
8345         if (strcmp(res->what, "add") != 0)
8346                 return;
8347
8348 #ifdef RTE_LIBRTE_I40E_PMD
8349         if (ret == -ENOTSUP)
8350                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8351                                                    &res->address);
8352 #endif
8353 #ifdef RTE_LIBRTE_BNXT_PMD
8354         if (ret == -ENOTSUP)
8355                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8356                                                 res->vf_num);
8357 #endif
8358
8359         if(ret < 0)
8360                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8361
8362 }
8363
8364 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8365         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8366                                 mac_addr_cmd,"mac_addr");
8367 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8368         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8369                                 what,"add");
8370 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8371         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8372                                 port,"port");
8373 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8374         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8375                                 port_num, UINT16);
8376 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8377         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8378                                 vf,"vf");
8379 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8380         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8381                                 vf_num, UINT8);
8382 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8383         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8384                                 address);
8385
8386 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8387         .f = cmd_vf_mac_addr_parsed,
8388         .data = (void *)0,
8389         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8390                 "Add MAC address filtering for a VF on port_id",
8391         .tokens = {
8392                 (void *)&cmd_vf_mac_addr_cmd,
8393                 (void *)&cmd_vf_mac_addr_what,
8394                 (void *)&cmd_vf_mac_addr_port,
8395                 (void *)&cmd_vf_mac_addr_portnum,
8396                 (void *)&cmd_vf_mac_addr_vf,
8397                 (void *)&cmd_vf_mac_addr_vfnum,
8398                 (void *)&cmd_vf_mac_addr_addr,
8399                 NULL,
8400         },
8401 };
8402
8403 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8404 struct cmd_vf_rx_vlan_filter {
8405         cmdline_fixed_string_t rx_vlan;
8406         cmdline_fixed_string_t what;
8407         uint16_t vlan_id;
8408         cmdline_fixed_string_t port;
8409         portid_t port_id;
8410         cmdline_fixed_string_t vf;
8411         uint64_t vf_mask;
8412 };
8413
8414 static void
8415 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8416                           __attribute__((unused)) struct cmdline *cl,
8417                           __attribute__((unused)) void *data)
8418 {
8419         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8420         int ret = -ENOTSUP;
8421
8422         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8423
8424 #ifdef RTE_LIBRTE_IXGBE_PMD
8425         if (ret == -ENOTSUP)
8426                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8427                                 res->vlan_id, res->vf_mask, is_add);
8428 #endif
8429 #ifdef RTE_LIBRTE_I40E_PMD
8430         if (ret == -ENOTSUP)
8431                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8432                                 res->vlan_id, res->vf_mask, is_add);
8433 #endif
8434 #ifdef RTE_LIBRTE_BNXT_PMD
8435         if (ret == -ENOTSUP)
8436                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8437                                 res->vlan_id, res->vf_mask, is_add);
8438 #endif
8439
8440         switch (ret) {
8441         case 0:
8442                 break;
8443         case -EINVAL:
8444                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8445                                 res->vlan_id, res->vf_mask);
8446                 break;
8447         case -ENODEV:
8448                 printf("invalid port_id %d\n", res->port_id);
8449                 break;
8450         case -ENOTSUP:
8451                 printf("function not implemented or supported\n");
8452                 break;
8453         default:
8454                 printf("programming error: (%s)\n", strerror(-ret));
8455         }
8456 }
8457
8458 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8459         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8460                                  rx_vlan, "rx_vlan");
8461 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8462         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8463                                  what, "add#rm");
8464 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8465         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8466                               vlan_id, UINT16);
8467 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8468         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8469                                  port, "port");
8470 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8471         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8472                               port_id, UINT16);
8473 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8474         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8475                                  vf, "vf");
8476 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8477         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8478                               vf_mask, UINT64);
8479
8480 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8481         .f = cmd_vf_rx_vlan_filter_parsed,
8482         .data = NULL,
8483         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8484                 "(vf_mask = hexadecimal VF mask)",
8485         .tokens = {
8486                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8487                 (void *)&cmd_vf_rx_vlan_filter_what,
8488                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8489                 (void *)&cmd_vf_rx_vlan_filter_port,
8490                 (void *)&cmd_vf_rx_vlan_filter_portid,
8491                 (void *)&cmd_vf_rx_vlan_filter_vf,
8492                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8493                 NULL,
8494         },
8495 };
8496
8497 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8498 struct cmd_queue_rate_limit_result {
8499         cmdline_fixed_string_t set;
8500         cmdline_fixed_string_t port;
8501         uint16_t port_num;
8502         cmdline_fixed_string_t queue;
8503         uint8_t queue_num;
8504         cmdline_fixed_string_t rate;
8505         uint16_t rate_num;
8506 };
8507
8508 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8509                 __attribute__((unused)) struct cmdline *cl,
8510                 __attribute__((unused)) void *data)
8511 {
8512         struct cmd_queue_rate_limit_result *res = parsed_result;
8513         int ret = 0;
8514
8515         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8516                 && (strcmp(res->queue, "queue") == 0)
8517                 && (strcmp(res->rate, "rate") == 0))
8518                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8519                                         res->rate_num);
8520         if (ret < 0)
8521                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8522
8523 }
8524
8525 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8526         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8527                                 set, "set");
8528 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8529         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8530                                 port, "port");
8531 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8532         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8533                                 port_num, UINT16);
8534 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8535         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8536                                 queue, "queue");
8537 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8538         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8539                                 queue_num, UINT8);
8540 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8541         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8542                                 rate, "rate");
8543 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8544         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8545                                 rate_num, UINT16);
8546
8547 cmdline_parse_inst_t cmd_queue_rate_limit = {
8548         .f = cmd_queue_rate_limit_parsed,
8549         .data = (void *)0,
8550         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8551                 "Set rate limit for a queue on port_id",
8552         .tokens = {
8553                 (void *)&cmd_queue_rate_limit_set,
8554                 (void *)&cmd_queue_rate_limit_port,
8555                 (void *)&cmd_queue_rate_limit_portnum,
8556                 (void *)&cmd_queue_rate_limit_queue,
8557                 (void *)&cmd_queue_rate_limit_queuenum,
8558                 (void *)&cmd_queue_rate_limit_rate,
8559                 (void *)&cmd_queue_rate_limit_ratenum,
8560                 NULL,
8561         },
8562 };
8563
8564 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8565 struct cmd_vf_rate_limit_result {
8566         cmdline_fixed_string_t set;
8567         cmdline_fixed_string_t port;
8568         uint16_t port_num;
8569         cmdline_fixed_string_t vf;
8570         uint8_t vf_num;
8571         cmdline_fixed_string_t rate;
8572         uint16_t rate_num;
8573         cmdline_fixed_string_t q_msk;
8574         uint64_t q_msk_val;
8575 };
8576
8577 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8578                 __attribute__((unused)) struct cmdline *cl,
8579                 __attribute__((unused)) void *data)
8580 {
8581         struct cmd_vf_rate_limit_result *res = parsed_result;
8582         int ret = 0;
8583
8584         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8585                 && (strcmp(res->vf, "vf") == 0)
8586                 && (strcmp(res->rate, "rate") == 0)
8587                 && (strcmp(res->q_msk, "queue_mask") == 0))
8588                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8589                                         res->rate_num, res->q_msk_val);
8590         if (ret < 0)
8591                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8592
8593 }
8594
8595 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8596         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8597                                 set, "set");
8598 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8599         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8600                                 port, "port");
8601 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8602         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8603                                 port_num, UINT16);
8604 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8605         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8606                                 vf, "vf");
8607 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8608         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8609                                 vf_num, UINT8);
8610 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8611         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8612                                 rate, "rate");
8613 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8614         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8615                                 rate_num, UINT16);
8616 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8617         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8618                                 q_msk, "queue_mask");
8619 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8620         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8621                                 q_msk_val, UINT64);
8622
8623 cmdline_parse_inst_t cmd_vf_rate_limit = {
8624         .f = cmd_vf_rate_limit_parsed,
8625         .data = (void *)0,
8626         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8627                 "queue_mask <queue_mask_value>: "
8628                 "Set rate limit for queues of VF on port_id",
8629         .tokens = {
8630                 (void *)&cmd_vf_rate_limit_set,
8631                 (void *)&cmd_vf_rate_limit_port,
8632                 (void *)&cmd_vf_rate_limit_portnum,
8633                 (void *)&cmd_vf_rate_limit_vf,
8634                 (void *)&cmd_vf_rate_limit_vfnum,
8635                 (void *)&cmd_vf_rate_limit_rate,
8636                 (void *)&cmd_vf_rate_limit_ratenum,
8637                 (void *)&cmd_vf_rate_limit_q_msk,
8638                 (void *)&cmd_vf_rate_limit_q_msk_val,
8639                 NULL,
8640         },
8641 };
8642
8643 /* *** ADD TUNNEL FILTER OF A PORT *** */
8644 struct cmd_tunnel_filter_result {
8645         cmdline_fixed_string_t cmd;
8646         cmdline_fixed_string_t what;
8647         portid_t port_id;
8648         struct ether_addr outer_mac;
8649         struct ether_addr inner_mac;
8650         cmdline_ipaddr_t ip_value;
8651         uint16_t inner_vlan;
8652         cmdline_fixed_string_t tunnel_type;
8653         cmdline_fixed_string_t filter_type;
8654         uint32_t tenant_id;
8655         uint16_t queue_num;
8656 };
8657
8658 static void
8659 cmd_tunnel_filter_parsed(void *parsed_result,
8660                           __attribute__((unused)) struct cmdline *cl,
8661                           __attribute__((unused)) void *data)
8662 {
8663         struct cmd_tunnel_filter_result *res = parsed_result;
8664         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8665         int ret = 0;
8666
8667         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8668
8669         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8670         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8671         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8672
8673         if (res->ip_value.family == AF_INET) {
8674                 tunnel_filter_conf.ip_addr.ipv4_addr =
8675                         res->ip_value.addr.ipv4.s_addr;
8676                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8677         } else {
8678                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8679                         &(res->ip_value.addr.ipv6),
8680                         sizeof(struct in6_addr));
8681                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8682         }
8683
8684         if (!strcmp(res->filter_type, "imac-ivlan"))
8685                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8686         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8687                 tunnel_filter_conf.filter_type =
8688                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8689         else if (!strcmp(res->filter_type, "imac-tenid"))
8690                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8691         else if (!strcmp(res->filter_type, "imac"))
8692                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8693         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8694                 tunnel_filter_conf.filter_type =
8695                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8696         else if (!strcmp(res->filter_type, "oip"))
8697                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8698         else if (!strcmp(res->filter_type, "iip"))
8699                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8700         else {
8701                 printf("The filter type is not supported");
8702                 return;
8703         }
8704
8705         if (!strcmp(res->tunnel_type, "vxlan"))
8706                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8707         else if (!strcmp(res->tunnel_type, "nvgre"))
8708                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8709         else if (!strcmp(res->tunnel_type, "ipingre"))
8710                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8711         else {
8712                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8713                 return;
8714         }
8715
8716         tunnel_filter_conf.tenant_id = res->tenant_id;
8717         tunnel_filter_conf.queue_id = res->queue_num;
8718         if (!strcmp(res->what, "add"))
8719                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8720                                         RTE_ETH_FILTER_TUNNEL,
8721                                         RTE_ETH_FILTER_ADD,
8722                                         &tunnel_filter_conf);
8723         else
8724                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8725                                         RTE_ETH_FILTER_TUNNEL,
8726                                         RTE_ETH_FILTER_DELETE,
8727                                         &tunnel_filter_conf);
8728         if (ret < 0)
8729                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8730                                 strerror(-ret));
8731
8732 }
8733 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8734         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8735         cmd, "tunnel_filter");
8736 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8737         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8738         what, "add#rm");
8739 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8740         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8741         port_id, UINT16);
8742 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8743         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8744         outer_mac);
8745 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8746         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8747         inner_mac);
8748 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8749         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8750         inner_vlan, UINT16);
8751 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8752         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8753         ip_value);
8754 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8755         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8756         tunnel_type, "vxlan#nvgre#ipingre");
8757
8758 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8759         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8760         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8761                 "imac#omac-imac-tenid");
8762 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8763         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8764         tenant_id, UINT32);
8765 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8766         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8767         queue_num, UINT16);
8768
8769 cmdline_parse_inst_t cmd_tunnel_filter = {
8770         .f = cmd_tunnel_filter_parsed,
8771         .data = (void *)0,
8772         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8773                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8774                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8775                 "<queue_id>: Add/Rm tunnel filter of a port",
8776         .tokens = {
8777                 (void *)&cmd_tunnel_filter_cmd,
8778                 (void *)&cmd_tunnel_filter_what,
8779                 (void *)&cmd_tunnel_filter_port_id,
8780                 (void *)&cmd_tunnel_filter_outer_mac,
8781                 (void *)&cmd_tunnel_filter_inner_mac,
8782                 (void *)&cmd_tunnel_filter_ip_value,
8783                 (void *)&cmd_tunnel_filter_innner_vlan,
8784                 (void *)&cmd_tunnel_filter_tunnel_type,
8785                 (void *)&cmd_tunnel_filter_filter_type,
8786                 (void *)&cmd_tunnel_filter_tenant_id,
8787                 (void *)&cmd_tunnel_filter_queue_num,
8788                 NULL,
8789         },
8790 };
8791
8792 /* *** CONFIGURE TUNNEL UDP PORT *** */
8793 struct cmd_tunnel_udp_config {
8794         cmdline_fixed_string_t cmd;
8795         cmdline_fixed_string_t what;
8796         uint16_t udp_port;
8797         portid_t port_id;
8798 };
8799
8800 static void
8801 cmd_tunnel_udp_config_parsed(void *parsed_result,
8802                           __attribute__((unused)) struct cmdline *cl,
8803                           __attribute__((unused)) void *data)
8804 {
8805         struct cmd_tunnel_udp_config *res = parsed_result;
8806         struct rte_eth_udp_tunnel tunnel_udp;
8807         int ret;
8808
8809         tunnel_udp.udp_port = res->udp_port;
8810
8811         if (!strcmp(res->cmd, "rx_vxlan_port"))
8812                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8813
8814         if (!strcmp(res->what, "add"))
8815                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8816                                                       &tunnel_udp);
8817         else
8818                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8819                                                          &tunnel_udp);
8820
8821         if (ret < 0)
8822                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8823 }
8824
8825 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8826         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8827                                 cmd, "rx_vxlan_port");
8828 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8829         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8830                                 what, "add#rm");
8831 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8832         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8833                                 udp_port, UINT16);
8834 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8835         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8836                                 port_id, UINT16);
8837
8838 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8839         .f = cmd_tunnel_udp_config_parsed,
8840         .data = (void *)0,
8841         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8842                 "Add/Remove a tunneling UDP port filter",
8843         .tokens = {
8844                 (void *)&cmd_tunnel_udp_config_cmd,
8845                 (void *)&cmd_tunnel_udp_config_what,
8846                 (void *)&cmd_tunnel_udp_config_udp_port,
8847                 (void *)&cmd_tunnel_udp_config_port_id,
8848                 NULL,
8849         },
8850 };
8851
8852 struct cmd_config_tunnel_udp_port {
8853         cmdline_fixed_string_t port;
8854         cmdline_fixed_string_t config;
8855         portid_t port_id;
8856         cmdline_fixed_string_t udp_tunnel_port;
8857         cmdline_fixed_string_t action;
8858         cmdline_fixed_string_t tunnel_type;
8859         uint16_t udp_port;
8860 };
8861
8862 static void
8863 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8864                                __attribute__((unused)) struct cmdline *cl,
8865                                __attribute__((unused)) void *data)
8866 {
8867         struct cmd_config_tunnel_udp_port *res = parsed_result;
8868         struct rte_eth_udp_tunnel tunnel_udp;
8869         int ret = 0;
8870
8871         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8872                 return;
8873
8874         tunnel_udp.udp_port = res->udp_port;
8875
8876         if (!strcmp(res->tunnel_type, "vxlan")) {
8877                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8878         } else if (!strcmp(res->tunnel_type, "geneve")) {
8879                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8880         } else {
8881                 printf("Invalid tunnel type\n");
8882                 return;
8883         }
8884
8885         if (!strcmp(res->action, "add"))
8886                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8887                                                       &tunnel_udp);
8888         else
8889                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8890                                                          &tunnel_udp);
8891
8892         if (ret < 0)
8893                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8894 }
8895
8896 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8897         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8898                                  "port");
8899 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8900         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8901                                  "config");
8902 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8903         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8904                               UINT16);
8905 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8906         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8907                                  udp_tunnel_port,
8908                                  "udp_tunnel_port");
8909 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8910         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8911                                  "add#rm");
8912 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8913         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8914                                  "vxlan#geneve");
8915 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8916         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8917                               UINT16);
8918
8919 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8920         .f = cmd_cfg_tunnel_udp_port_parsed,
8921         .data = NULL,
8922         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8923         .tokens = {
8924                 (void *)&cmd_config_tunnel_udp_port_port,
8925                 (void *)&cmd_config_tunnel_udp_port_config,
8926                 (void *)&cmd_config_tunnel_udp_port_port_id,
8927                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8928                 (void *)&cmd_config_tunnel_udp_port_action,
8929                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8930                 (void *)&cmd_config_tunnel_udp_port_value,
8931                 NULL,
8932         },
8933 };
8934
8935 /* *** GLOBAL CONFIG *** */
8936 struct cmd_global_config_result {
8937         cmdline_fixed_string_t cmd;
8938         portid_t port_id;
8939         cmdline_fixed_string_t cfg_type;
8940         uint8_t len;
8941 };
8942
8943 static void
8944 cmd_global_config_parsed(void *parsed_result,
8945                          __attribute__((unused)) struct cmdline *cl,
8946                          __attribute__((unused)) void *data)
8947 {
8948         struct cmd_global_config_result *res = parsed_result;
8949         struct rte_eth_global_cfg conf;
8950         int ret;
8951
8952         memset(&conf, 0, sizeof(conf));
8953         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8954         conf.cfg.gre_key_len = res->len;
8955         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8956                                       RTE_ETH_FILTER_SET, &conf);
8957         if (ret != 0)
8958                 printf("Global config error\n");
8959 }
8960
8961 cmdline_parse_token_string_t cmd_global_config_cmd =
8962         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8963                 "global_config");
8964 cmdline_parse_token_num_t cmd_global_config_port_id =
8965         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8966                                UINT16);
8967 cmdline_parse_token_string_t cmd_global_config_type =
8968         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8969                 cfg_type, "gre-key-len");
8970 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8971         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8972                 len, UINT8);
8973
8974 cmdline_parse_inst_t cmd_global_config = {
8975         .f = cmd_global_config_parsed,
8976         .data = (void *)NULL,
8977         .help_str = "global_config <port_id> gre-key-len <key_len>",
8978         .tokens = {
8979                 (void *)&cmd_global_config_cmd,
8980                 (void *)&cmd_global_config_port_id,
8981                 (void *)&cmd_global_config_type,
8982                 (void *)&cmd_global_config_gre_key_len,
8983                 NULL,
8984         },
8985 };
8986
8987 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8988 struct cmd_set_mirror_mask_result {
8989         cmdline_fixed_string_t set;
8990         cmdline_fixed_string_t port;
8991         portid_t port_id;
8992         cmdline_fixed_string_t mirror;
8993         uint8_t rule_id;
8994         cmdline_fixed_string_t what;
8995         cmdline_fixed_string_t value;
8996         cmdline_fixed_string_t dstpool;
8997         uint8_t dstpool_id;
8998         cmdline_fixed_string_t on;
8999 };
9000
9001 cmdline_parse_token_string_t cmd_mirror_mask_set =
9002         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9003                                 set, "set");
9004 cmdline_parse_token_string_t cmd_mirror_mask_port =
9005         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9006                                 port, "port");
9007 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9008         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9009                                 port_id, UINT16);
9010 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9011         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9012                                 mirror, "mirror-rule");
9013 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9014         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9015                                 rule_id, UINT8);
9016 cmdline_parse_token_string_t cmd_mirror_mask_what =
9017         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9018                                 what, "pool-mirror-up#pool-mirror-down"
9019                                       "#vlan-mirror");
9020 cmdline_parse_token_string_t cmd_mirror_mask_value =
9021         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9022                                 value, NULL);
9023 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9024         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9025                                 dstpool, "dst-pool");
9026 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9027         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9028                                 dstpool_id, UINT8);
9029 cmdline_parse_token_string_t cmd_mirror_mask_on =
9030         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9031                                 on, "on#off");
9032
9033 static void
9034 cmd_set_mirror_mask_parsed(void *parsed_result,
9035                        __attribute__((unused)) struct cmdline *cl,
9036                        __attribute__((unused)) void *data)
9037 {
9038         int ret,nb_item,i;
9039         struct cmd_set_mirror_mask_result *res = parsed_result;
9040         struct rte_eth_mirror_conf mr_conf;
9041
9042         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9043
9044         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9045
9046         mr_conf.dst_pool = res->dstpool_id;
9047
9048         if (!strcmp(res->what, "pool-mirror-up")) {
9049                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9050                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9051         } else if (!strcmp(res->what, "pool-mirror-down")) {
9052                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9053                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9054         } else if (!strcmp(res->what, "vlan-mirror")) {
9055                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9056                 nb_item = parse_item_list(res->value, "vlan",
9057                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9058                 if (nb_item <= 0)
9059                         return;
9060
9061                 for (i = 0; i < nb_item; i++) {
9062                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
9063                                 printf("Invalid vlan_id: must be < 4096\n");
9064                                 return;
9065                         }
9066
9067                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9068                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9069                 }
9070         }
9071
9072         if (!strcmp(res->on, "on"))
9073                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9074                                                 res->rule_id, 1);
9075         else
9076                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9077                                                 res->rule_id, 0);
9078         if (ret < 0)
9079                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9080 }
9081
9082 cmdline_parse_inst_t cmd_set_mirror_mask = {
9083                 .f = cmd_set_mirror_mask_parsed,
9084                 .data = NULL,
9085                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9086                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9087                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9088                 .tokens = {
9089                         (void *)&cmd_mirror_mask_set,
9090                         (void *)&cmd_mirror_mask_port,
9091                         (void *)&cmd_mirror_mask_portid,
9092                         (void *)&cmd_mirror_mask_mirror,
9093                         (void *)&cmd_mirror_mask_ruleid,
9094                         (void *)&cmd_mirror_mask_what,
9095                         (void *)&cmd_mirror_mask_value,
9096                         (void *)&cmd_mirror_mask_dstpool,
9097                         (void *)&cmd_mirror_mask_poolid,
9098                         (void *)&cmd_mirror_mask_on,
9099                         NULL,
9100                 },
9101 };
9102
9103 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9104 struct cmd_set_mirror_link_result {
9105         cmdline_fixed_string_t set;
9106         cmdline_fixed_string_t port;
9107         portid_t port_id;
9108         cmdline_fixed_string_t mirror;
9109         uint8_t rule_id;
9110         cmdline_fixed_string_t what;
9111         cmdline_fixed_string_t dstpool;
9112         uint8_t dstpool_id;
9113         cmdline_fixed_string_t on;
9114 };
9115
9116 cmdline_parse_token_string_t cmd_mirror_link_set =
9117         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9118                                  set, "set");
9119 cmdline_parse_token_string_t cmd_mirror_link_port =
9120         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9121                                 port, "port");
9122 cmdline_parse_token_num_t cmd_mirror_link_portid =
9123         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9124                                 port_id, UINT16);
9125 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9126         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9127                                 mirror, "mirror-rule");
9128 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9129         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9130                             rule_id, UINT8);
9131 cmdline_parse_token_string_t cmd_mirror_link_what =
9132         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9133                                 what, "uplink-mirror#downlink-mirror");
9134 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9135         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9136                                 dstpool, "dst-pool");
9137 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9138         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9139                                 dstpool_id, UINT8);
9140 cmdline_parse_token_string_t cmd_mirror_link_on =
9141         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9142                                 on, "on#off");
9143
9144 static void
9145 cmd_set_mirror_link_parsed(void *parsed_result,
9146                        __attribute__((unused)) struct cmdline *cl,
9147                        __attribute__((unused)) void *data)
9148 {
9149         int ret;
9150         struct cmd_set_mirror_link_result *res = parsed_result;
9151         struct rte_eth_mirror_conf mr_conf;
9152
9153         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9154         if (!strcmp(res->what, "uplink-mirror"))
9155                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9156         else
9157                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9158
9159         mr_conf.dst_pool = res->dstpool_id;
9160
9161         if (!strcmp(res->on, "on"))
9162                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9163                                                 res->rule_id, 1);
9164         else
9165                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9166                                                 res->rule_id, 0);
9167
9168         /* check the return value and print it if is < 0 */
9169         if (ret < 0)
9170                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9171
9172 }
9173
9174 cmdline_parse_inst_t cmd_set_mirror_link = {
9175                 .f = cmd_set_mirror_link_parsed,
9176                 .data = NULL,
9177                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9178                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9179                 .tokens = {
9180                         (void *)&cmd_mirror_link_set,
9181                         (void *)&cmd_mirror_link_port,
9182                         (void *)&cmd_mirror_link_portid,
9183                         (void *)&cmd_mirror_link_mirror,
9184                         (void *)&cmd_mirror_link_ruleid,
9185                         (void *)&cmd_mirror_link_what,
9186                         (void *)&cmd_mirror_link_dstpool,
9187                         (void *)&cmd_mirror_link_poolid,
9188                         (void *)&cmd_mirror_link_on,
9189                         NULL,
9190                 },
9191 };
9192
9193 /* *** RESET VM MIRROR RULE *** */
9194 struct cmd_rm_mirror_rule_result {
9195         cmdline_fixed_string_t reset;
9196         cmdline_fixed_string_t port;
9197         portid_t port_id;
9198         cmdline_fixed_string_t mirror;
9199         uint8_t rule_id;
9200 };
9201
9202 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9203         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9204                                  reset, "reset");
9205 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9206         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9207                                 port, "port");
9208 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9209         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9210                                 port_id, UINT16);
9211 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9212         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9213                                 mirror, "mirror-rule");
9214 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9215         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9216                                 rule_id, UINT8);
9217
9218 static void
9219 cmd_reset_mirror_rule_parsed(void *parsed_result,
9220                        __attribute__((unused)) struct cmdline *cl,
9221                        __attribute__((unused)) void *data)
9222 {
9223         int ret;
9224         struct cmd_set_mirror_link_result *res = parsed_result;
9225         /* check rule_id */
9226         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9227         if(ret < 0)
9228                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9229 }
9230
9231 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9232                 .f = cmd_reset_mirror_rule_parsed,
9233                 .data = NULL,
9234                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9235                 .tokens = {
9236                         (void *)&cmd_rm_mirror_rule_reset,
9237                         (void *)&cmd_rm_mirror_rule_port,
9238                         (void *)&cmd_rm_mirror_rule_portid,
9239                         (void *)&cmd_rm_mirror_rule_mirror,
9240                         (void *)&cmd_rm_mirror_rule_ruleid,
9241                         NULL,
9242                 },
9243 };
9244
9245 /* ******************************************************************************** */
9246
9247 struct cmd_dump_result {
9248         cmdline_fixed_string_t dump;
9249 };
9250
9251 static void
9252 dump_struct_sizes(void)
9253 {
9254 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9255         DUMP_SIZE(struct rte_mbuf);
9256         DUMP_SIZE(struct rte_mempool);
9257         DUMP_SIZE(struct rte_ring);
9258 #undef DUMP_SIZE
9259 }
9260
9261 static void cmd_dump_parsed(void *parsed_result,
9262                             __attribute__((unused)) struct cmdline *cl,
9263                             __attribute__((unused)) void *data)
9264 {
9265         struct cmd_dump_result *res = parsed_result;
9266
9267         if (!strcmp(res->dump, "dump_physmem"))
9268                 rte_dump_physmem_layout(stdout);
9269         else if (!strcmp(res->dump, "dump_memzone"))
9270                 rte_memzone_dump(stdout);
9271         else if (!strcmp(res->dump, "dump_struct_sizes"))
9272                 dump_struct_sizes();
9273         else if (!strcmp(res->dump, "dump_ring"))
9274                 rte_ring_list_dump(stdout);
9275         else if (!strcmp(res->dump, "dump_mempool"))
9276                 rte_mempool_list_dump(stdout);
9277         else if (!strcmp(res->dump, "dump_devargs"))
9278                 rte_devargs_dump(stdout);
9279         else if (!strcmp(res->dump, "dump_log_types"))
9280                 rte_log_dump(stdout);
9281 }
9282
9283 cmdline_parse_token_string_t cmd_dump_dump =
9284         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9285                 "dump_physmem#"
9286                 "dump_memzone#"
9287                 "dump_struct_sizes#"
9288                 "dump_ring#"
9289                 "dump_mempool#"
9290                 "dump_devargs#"
9291                 "dump_log_types");
9292
9293 cmdline_parse_inst_t cmd_dump = {
9294         .f = cmd_dump_parsed,  /* function to call */
9295         .data = NULL,      /* 2nd arg of func */
9296         .help_str = "Dump status",
9297         .tokens = {        /* token list, NULL terminated */
9298                 (void *)&cmd_dump_dump,
9299                 NULL,
9300         },
9301 };
9302
9303 /* ******************************************************************************** */
9304
9305 struct cmd_dump_one_result {
9306         cmdline_fixed_string_t dump;
9307         cmdline_fixed_string_t name;
9308 };
9309
9310 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9311                                 __attribute__((unused)) void *data)
9312 {
9313         struct cmd_dump_one_result *res = parsed_result;
9314
9315         if (!strcmp(res->dump, "dump_ring")) {
9316                 struct rte_ring *r;
9317                 r = rte_ring_lookup(res->name);
9318                 if (r == NULL) {
9319                         cmdline_printf(cl, "Cannot find ring\n");
9320                         return;
9321                 }
9322                 rte_ring_dump(stdout, r);
9323         } else if (!strcmp(res->dump, "dump_mempool")) {
9324                 struct rte_mempool *mp;
9325                 mp = rte_mempool_lookup(res->name);
9326                 if (mp == NULL) {
9327                         cmdline_printf(cl, "Cannot find mempool\n");
9328                         return;
9329                 }
9330                 rte_mempool_dump(stdout, mp);
9331         }
9332 }
9333
9334 cmdline_parse_token_string_t cmd_dump_one_dump =
9335         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9336                                  "dump_ring#dump_mempool");
9337
9338 cmdline_parse_token_string_t cmd_dump_one_name =
9339         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9340
9341 cmdline_parse_inst_t cmd_dump_one = {
9342         .f = cmd_dump_one_parsed,  /* function to call */
9343         .data = NULL,      /* 2nd arg of func */
9344         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9345         .tokens = {        /* token list, NULL terminated */
9346                 (void *)&cmd_dump_one_dump,
9347                 (void *)&cmd_dump_one_name,
9348                 NULL,
9349         },
9350 };
9351
9352 /* *** Add/Del syn filter *** */
9353 struct cmd_syn_filter_result {
9354         cmdline_fixed_string_t filter;
9355         portid_t port_id;
9356         cmdline_fixed_string_t ops;
9357         cmdline_fixed_string_t priority;
9358         cmdline_fixed_string_t high;
9359         cmdline_fixed_string_t queue;
9360         uint16_t queue_id;
9361 };
9362
9363 static void
9364 cmd_syn_filter_parsed(void *parsed_result,
9365                         __attribute__((unused)) struct cmdline *cl,
9366                         __attribute__((unused)) void *data)
9367 {
9368         struct cmd_syn_filter_result *res = parsed_result;
9369         struct rte_eth_syn_filter syn_filter;
9370         int ret = 0;
9371
9372         ret = rte_eth_dev_filter_supported(res->port_id,
9373                                         RTE_ETH_FILTER_SYN);
9374         if (ret < 0) {
9375                 printf("syn filter is not supported on port %u.\n",
9376                                 res->port_id);
9377                 return;
9378         }
9379
9380         memset(&syn_filter, 0, sizeof(syn_filter));
9381
9382         if (!strcmp(res->ops, "add")) {
9383                 if (!strcmp(res->high, "high"))
9384                         syn_filter.hig_pri = 1;
9385                 else
9386                         syn_filter.hig_pri = 0;
9387
9388                 syn_filter.queue = res->queue_id;
9389                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9390                                                 RTE_ETH_FILTER_SYN,
9391                                                 RTE_ETH_FILTER_ADD,
9392                                                 &syn_filter);
9393         } else
9394                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9395                                                 RTE_ETH_FILTER_SYN,
9396                                                 RTE_ETH_FILTER_DELETE,
9397                                                 &syn_filter);
9398
9399         if (ret < 0)
9400                 printf("syn filter programming error: (%s)\n",
9401                                 strerror(-ret));
9402 }
9403
9404 cmdline_parse_token_string_t cmd_syn_filter_filter =
9405         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9406         filter, "syn_filter");
9407 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9408         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9409         port_id, UINT16);
9410 cmdline_parse_token_string_t cmd_syn_filter_ops =
9411         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9412         ops, "add#del");
9413 cmdline_parse_token_string_t cmd_syn_filter_priority =
9414         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9415                                 priority, "priority");
9416 cmdline_parse_token_string_t cmd_syn_filter_high =
9417         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9418                                 high, "high#low");
9419 cmdline_parse_token_string_t cmd_syn_filter_queue =
9420         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9421                                 queue, "queue");
9422 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9423         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9424                                 queue_id, UINT16);
9425
9426 cmdline_parse_inst_t cmd_syn_filter = {
9427         .f = cmd_syn_filter_parsed,
9428         .data = NULL,
9429         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9430                 "<queue_id>: Add/Delete syn filter",
9431         .tokens = {
9432                 (void *)&cmd_syn_filter_filter,
9433                 (void *)&cmd_syn_filter_port_id,
9434                 (void *)&cmd_syn_filter_ops,
9435                 (void *)&cmd_syn_filter_priority,
9436                 (void *)&cmd_syn_filter_high,
9437                 (void *)&cmd_syn_filter_queue,
9438                 (void *)&cmd_syn_filter_queue_id,
9439                 NULL,
9440         },
9441 };
9442
9443 /* *** queue region set *** */
9444 struct cmd_queue_region_result {
9445         cmdline_fixed_string_t set;
9446         cmdline_fixed_string_t port;
9447         portid_t port_id;
9448         cmdline_fixed_string_t cmd;
9449         cmdline_fixed_string_t region;
9450         uint8_t  region_id;
9451         cmdline_fixed_string_t queue_start_index;
9452         uint8_t  queue_id;
9453         cmdline_fixed_string_t queue_num;
9454         uint8_t  queue_num_value;
9455 };
9456
9457 static void
9458 cmd_queue_region_parsed(void *parsed_result,
9459                         __attribute__((unused)) struct cmdline *cl,
9460                         __attribute__((unused)) void *data)
9461 {
9462         struct cmd_queue_region_result *res = parsed_result;
9463         int ret = -ENOTSUP;
9464 #ifdef RTE_LIBRTE_I40E_PMD
9465         struct rte_pmd_i40e_queue_region_conf region_conf;
9466         enum rte_pmd_i40e_queue_region_op op_type;
9467 #endif
9468
9469         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9470                 return;
9471
9472 #ifdef RTE_LIBRTE_I40E_PMD
9473         memset(&region_conf, 0, sizeof(region_conf));
9474         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9475         region_conf.region_id = res->region_id;
9476         region_conf.queue_num = res->queue_num_value;
9477         region_conf.queue_start_index = res->queue_id;
9478
9479         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9480                                 op_type, &region_conf);
9481 #endif
9482
9483         switch (ret) {
9484         case 0:
9485                 break;
9486         case -ENOTSUP:
9487                 printf("function not implemented or supported\n");
9488                 break;
9489         default:
9490                 printf("queue region config error: (%s)\n", strerror(-ret));
9491         }
9492 }
9493
9494 cmdline_parse_token_string_t cmd_queue_region_set =
9495 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9496                 set, "set");
9497 cmdline_parse_token_string_t cmd_queue_region_port =
9498         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9499 cmdline_parse_token_num_t cmd_queue_region_port_id =
9500         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9501                                 port_id, UINT16);
9502 cmdline_parse_token_string_t cmd_queue_region_cmd =
9503         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9504                                  cmd, "queue-region");
9505 cmdline_parse_token_string_t cmd_queue_region_id =
9506         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9507                                 region, "region_id");
9508 cmdline_parse_token_num_t cmd_queue_region_index =
9509         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9510                                 region_id, UINT8);
9511 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9512         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9513                                 queue_start_index, "queue_start_index");
9514 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9515         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9516                                 queue_id, UINT8);
9517 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9518         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9519                                 queue_num, "queue_num");
9520 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9521         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9522                                 queue_num_value, UINT8);
9523
9524 cmdline_parse_inst_t cmd_queue_region = {
9525         .f = cmd_queue_region_parsed,
9526         .data = NULL,
9527         .help_str = "set port <port_id> queue-region region_id <value> "
9528                 "queue_start_index <value> queue_num <value>: Set a queue region",
9529         .tokens = {
9530                 (void *)&cmd_queue_region_set,
9531                 (void *)&cmd_queue_region_port,
9532                 (void *)&cmd_queue_region_port_id,
9533                 (void *)&cmd_queue_region_cmd,
9534                 (void *)&cmd_queue_region_id,
9535                 (void *)&cmd_queue_region_index,
9536                 (void *)&cmd_queue_region_queue_start_index,
9537                 (void *)&cmd_queue_region_queue_id,
9538                 (void *)&cmd_queue_region_queue_num,
9539                 (void *)&cmd_queue_region_queue_num_value,
9540                 NULL,
9541         },
9542 };
9543
9544 /* *** queue region and flowtype set *** */
9545 struct cmd_region_flowtype_result {
9546         cmdline_fixed_string_t set;
9547         cmdline_fixed_string_t port;
9548         portid_t port_id;
9549         cmdline_fixed_string_t cmd;
9550         cmdline_fixed_string_t region;
9551         uint8_t  region_id;
9552         cmdline_fixed_string_t flowtype;
9553         uint8_t  flowtype_id;
9554 };
9555
9556 static void
9557 cmd_region_flowtype_parsed(void *parsed_result,
9558                         __attribute__((unused)) struct cmdline *cl,
9559                         __attribute__((unused)) void *data)
9560 {
9561         struct cmd_region_flowtype_result *res = parsed_result;
9562         int ret = -ENOTSUP;
9563 #ifdef RTE_LIBRTE_I40E_PMD
9564         struct rte_pmd_i40e_queue_region_conf region_conf;
9565         enum rte_pmd_i40e_queue_region_op op_type;
9566 #endif
9567
9568         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9569                 return;
9570
9571 #ifdef RTE_LIBRTE_I40E_PMD
9572         memset(&region_conf, 0, sizeof(region_conf));
9573
9574         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9575         region_conf.region_id = res->region_id;
9576         region_conf.hw_flowtype = res->flowtype_id;
9577
9578         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9579                         op_type, &region_conf);
9580 #endif
9581
9582         switch (ret) {
9583         case 0:
9584                 break;
9585         case -ENOTSUP:
9586                 printf("function not implemented or supported\n");
9587                 break;
9588         default:
9589                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9590         }
9591 }
9592
9593 cmdline_parse_token_string_t cmd_region_flowtype_set =
9594 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9595                                 set, "set");
9596 cmdline_parse_token_string_t cmd_region_flowtype_port =
9597         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9598                                 port, "port");
9599 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9600         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9601                                 port_id, UINT16);
9602 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9603         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9604                                 cmd, "queue-region");
9605 cmdline_parse_token_string_t cmd_region_flowtype_index =
9606         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9607                                 region, "region_id");
9608 cmdline_parse_token_num_t cmd_region_flowtype_id =
9609         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9610                                 region_id, UINT8);
9611 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9612         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9613                                 flowtype, "flowtype");
9614 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9615         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9616                                 flowtype_id, UINT8);
9617 cmdline_parse_inst_t cmd_region_flowtype = {
9618         .f = cmd_region_flowtype_parsed,
9619         .data = NULL,
9620         .help_str = "set port <port_id> queue-region region_id <value> "
9621                 "flowtype <value>: Set a flowtype region index",
9622         .tokens = {
9623                 (void *)&cmd_region_flowtype_set,
9624                 (void *)&cmd_region_flowtype_port,
9625                 (void *)&cmd_region_flowtype_port_index,
9626                 (void *)&cmd_region_flowtype_cmd,
9627                 (void *)&cmd_region_flowtype_index,
9628                 (void *)&cmd_region_flowtype_id,
9629                 (void *)&cmd_region_flowtype_flow_index,
9630                 (void *)&cmd_region_flowtype_flow_id,
9631                 NULL,
9632         },
9633 };
9634
9635 /* *** User Priority (UP) to queue region (region_id) set *** */
9636 struct cmd_user_priority_region_result {
9637         cmdline_fixed_string_t set;
9638         cmdline_fixed_string_t port;
9639         portid_t port_id;
9640         cmdline_fixed_string_t cmd;
9641         cmdline_fixed_string_t user_priority;
9642         uint8_t  user_priority_id;
9643         cmdline_fixed_string_t region;
9644         uint8_t  region_id;
9645 };
9646
9647 static void
9648 cmd_user_priority_region_parsed(void *parsed_result,
9649                         __attribute__((unused)) struct cmdline *cl,
9650                         __attribute__((unused)) void *data)
9651 {
9652         struct cmd_user_priority_region_result *res = parsed_result;
9653         int ret = -ENOTSUP;
9654 #ifdef RTE_LIBRTE_I40E_PMD
9655         struct rte_pmd_i40e_queue_region_conf region_conf;
9656         enum rte_pmd_i40e_queue_region_op op_type;
9657 #endif
9658
9659         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9660                 return;
9661
9662 #ifdef RTE_LIBRTE_I40E_PMD
9663         memset(&region_conf, 0, sizeof(region_conf));
9664         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9665         region_conf.user_priority = res->user_priority_id;
9666         region_conf.region_id = res->region_id;
9667
9668         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9669                                 op_type, &region_conf);
9670 #endif
9671
9672         switch (ret) {
9673         case 0:
9674                 break;
9675         case -ENOTSUP:
9676                 printf("function not implemented or supported\n");
9677                 break;
9678         default:
9679                 printf("user_priority region config error: (%s)\n",
9680                                 strerror(-ret));
9681         }
9682 }
9683
9684 cmdline_parse_token_string_t cmd_user_priority_region_set =
9685         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9686                                 set, "set");
9687 cmdline_parse_token_string_t cmd_user_priority_region_port =
9688         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9689                                 port, "port");
9690 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9691         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9692                                 port_id, UINT16);
9693 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9694         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9695                                 cmd, "queue-region");
9696 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9697         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9698                                 user_priority, "UP");
9699 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9700         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9701                                 user_priority_id, UINT8);
9702 cmdline_parse_token_string_t cmd_user_priority_region_region =
9703         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9704                                 region, "region_id");
9705 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9706         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9707                                 region_id, UINT8);
9708
9709 cmdline_parse_inst_t cmd_user_priority_region = {
9710         .f = cmd_user_priority_region_parsed,
9711         .data = NULL,
9712         .help_str = "set port <port_id> queue-region UP <value> "
9713                 "region_id <value>: Set the mapping of User Priority (UP) "
9714                 "to queue region (region_id) ",
9715         .tokens = {
9716                 (void *)&cmd_user_priority_region_set,
9717                 (void *)&cmd_user_priority_region_port,
9718                 (void *)&cmd_user_priority_region_port_index,
9719                 (void *)&cmd_user_priority_region_cmd,
9720                 (void *)&cmd_user_priority_region_UP,
9721                 (void *)&cmd_user_priority_region_UP_id,
9722                 (void *)&cmd_user_priority_region_region,
9723                 (void *)&cmd_user_priority_region_region_id,
9724                 NULL,
9725         },
9726 };
9727
9728 /* *** flush all queue region related configuration *** */
9729 struct cmd_flush_queue_region_result {
9730         cmdline_fixed_string_t set;
9731         cmdline_fixed_string_t port;
9732         portid_t port_id;
9733         cmdline_fixed_string_t cmd;
9734         cmdline_fixed_string_t flush;
9735         cmdline_fixed_string_t what;
9736 };
9737
9738 static void
9739 cmd_flush_queue_region_parsed(void *parsed_result,
9740                         __attribute__((unused)) struct cmdline *cl,
9741                         __attribute__((unused)) void *data)
9742 {
9743         struct cmd_flush_queue_region_result *res = parsed_result;
9744         int ret = -ENOTSUP;
9745 #ifdef RTE_LIBRTE_I40E_PMD
9746         struct rte_pmd_i40e_queue_region_conf region_conf;
9747         enum rte_pmd_i40e_queue_region_op op_type;
9748 #endif
9749
9750         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9751                 return;
9752
9753 #ifdef RTE_LIBRTE_I40E_PMD
9754         memset(&region_conf, 0, sizeof(region_conf));
9755
9756         if (strcmp(res->what, "on") == 0)
9757                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9758         else
9759                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9760
9761         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9762                                 op_type, &region_conf);
9763 #endif
9764
9765         switch (ret) {
9766         case 0:
9767                 break;
9768         case -ENOTSUP:
9769                 printf("function not implemented or supported\n");
9770                 break;
9771         default:
9772                 printf("queue region config flush error: (%s)\n",
9773                                 strerror(-ret));
9774         }
9775 }
9776
9777 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9778         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9779                                 set, "set");
9780 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9781         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9782                                 port, "port");
9783 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9784         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9785                                 port_id, UINT16);
9786 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9787         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9788                                 cmd, "queue-region");
9789 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9790         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9791                                 flush, "flush");
9792 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9793         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9794                                 what, "on#off");
9795
9796 cmdline_parse_inst_t cmd_flush_queue_region = {
9797         .f = cmd_flush_queue_region_parsed,
9798         .data = NULL,
9799         .help_str = "set port <port_id> queue-region flush on|off"
9800                 ": flush all queue region related configuration",
9801         .tokens = {
9802                 (void *)&cmd_flush_queue_region_set,
9803                 (void *)&cmd_flush_queue_region_port,
9804                 (void *)&cmd_flush_queue_region_port_index,
9805                 (void *)&cmd_flush_queue_region_cmd,
9806                 (void *)&cmd_flush_queue_region_flush,
9807                 (void *)&cmd_flush_queue_region_what,
9808                 NULL,
9809         },
9810 };
9811
9812 /* *** get all queue region related configuration info *** */
9813 struct cmd_show_queue_region_info {
9814         cmdline_fixed_string_t show;
9815         cmdline_fixed_string_t port;
9816         portid_t port_id;
9817         cmdline_fixed_string_t cmd;
9818 };
9819
9820 static void
9821 cmd_show_queue_region_info_parsed(void *parsed_result,
9822                         __attribute__((unused)) struct cmdline *cl,
9823                         __attribute__((unused)) void *data)
9824 {
9825         struct cmd_show_queue_region_info *res = parsed_result;
9826         int ret = -ENOTSUP;
9827 #ifdef RTE_LIBRTE_I40E_PMD
9828         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9829         enum rte_pmd_i40e_queue_region_op op_type;
9830 #endif
9831
9832         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9833                 return;
9834
9835 #ifdef RTE_LIBRTE_I40E_PMD
9836         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9837
9838         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9839
9840         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9841                                         op_type, &rte_pmd_regions);
9842
9843         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9844 #endif
9845
9846         switch (ret) {
9847         case 0:
9848                 break;
9849         case -ENOTSUP:
9850                 printf("function not implemented or supported\n");
9851                 break;
9852         default:
9853                 printf("queue region config info show error: (%s)\n",
9854                                 strerror(-ret));
9855         }
9856 }
9857
9858 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9859 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9860                                 show, "show");
9861 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9862         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9863                                 port, "port");
9864 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9865         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9866                                 port_id, UINT16);
9867 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9868         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9869                                 cmd, "queue-region");
9870
9871 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9872         .f = cmd_show_queue_region_info_parsed,
9873         .data = NULL,
9874         .help_str = "show port <port_id> queue-region"
9875                 ": show all queue region related configuration info",
9876         .tokens = {
9877                 (void *)&cmd_show_queue_region_info_get,
9878                 (void *)&cmd_show_queue_region_info_port,
9879                 (void *)&cmd_show_queue_region_info_port_index,
9880                 (void *)&cmd_show_queue_region_info_cmd,
9881                 NULL,
9882         },
9883 };
9884
9885 /* *** ADD/REMOVE A 2tuple FILTER *** */
9886 struct cmd_2tuple_filter_result {
9887         cmdline_fixed_string_t filter;
9888         portid_t port_id;
9889         cmdline_fixed_string_t ops;
9890         cmdline_fixed_string_t dst_port;
9891         uint16_t dst_port_value;
9892         cmdline_fixed_string_t protocol;
9893         uint8_t protocol_value;
9894         cmdline_fixed_string_t mask;
9895         uint8_t  mask_value;
9896         cmdline_fixed_string_t tcp_flags;
9897         uint8_t tcp_flags_value;
9898         cmdline_fixed_string_t priority;
9899         uint8_t  priority_value;
9900         cmdline_fixed_string_t queue;
9901         uint16_t  queue_id;
9902 };
9903
9904 static void
9905 cmd_2tuple_filter_parsed(void *parsed_result,
9906                         __attribute__((unused)) struct cmdline *cl,
9907                         __attribute__((unused)) void *data)
9908 {
9909         struct rte_eth_ntuple_filter filter;
9910         struct cmd_2tuple_filter_result *res = parsed_result;
9911         int ret = 0;
9912
9913         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9914         if (ret < 0) {
9915                 printf("ntuple filter is not supported on port %u.\n",
9916                         res->port_id);
9917                 return;
9918         }
9919
9920         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9921
9922         filter.flags = RTE_2TUPLE_FLAGS;
9923         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9924         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9925         filter.proto = res->protocol_value;
9926         filter.priority = res->priority_value;
9927         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9928                 printf("nonzero tcp_flags is only meaningful"
9929                         " when protocol is TCP.\n");
9930                 return;
9931         }
9932         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9933                 printf("invalid TCP flags.\n");
9934                 return;
9935         }
9936
9937         if (res->tcp_flags_value != 0) {
9938                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9939                 filter.tcp_flags = res->tcp_flags_value;
9940         }
9941
9942         /* need convert to big endian. */
9943         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9944         filter.queue = res->queue_id;
9945
9946         if (!strcmp(res->ops, "add"))
9947                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9948                                 RTE_ETH_FILTER_NTUPLE,
9949                                 RTE_ETH_FILTER_ADD,
9950                                 &filter);
9951         else
9952                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9953                                 RTE_ETH_FILTER_NTUPLE,
9954                                 RTE_ETH_FILTER_DELETE,
9955                                 &filter);
9956         if (ret < 0)
9957                 printf("2tuple filter programming error: (%s)\n",
9958                         strerror(-ret));
9959
9960 }
9961
9962 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9963         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9964                                  filter, "2tuple_filter");
9965 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9966         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9967                                 port_id, UINT16);
9968 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9969         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9970                                  ops, "add#del");
9971 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9972         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9973                                 dst_port, "dst_port");
9974 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9975         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9976                                 dst_port_value, UINT16);
9977 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9978         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9979                                 protocol, "protocol");
9980 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9981         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9982                                 protocol_value, UINT8);
9983 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9984         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9985                                 mask, "mask");
9986 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9987         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9988                                 mask_value, INT8);
9989 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9990         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9991                                 tcp_flags, "tcp_flags");
9992 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9993         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9994                                 tcp_flags_value, UINT8);
9995 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9996         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9997                                 priority, "priority");
9998 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9999         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10000                                 priority_value, UINT8);
10001 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10002         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10003                                 queue, "queue");
10004 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10005         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10006                                 queue_id, UINT16);
10007
10008 cmdline_parse_inst_t cmd_2tuple_filter = {
10009         .f = cmd_2tuple_filter_parsed,
10010         .data = NULL,
10011         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10012                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10013                 "<queue_id>: Add a 2tuple filter",
10014         .tokens = {
10015                 (void *)&cmd_2tuple_filter_filter,
10016                 (void *)&cmd_2tuple_filter_port_id,
10017                 (void *)&cmd_2tuple_filter_ops,
10018                 (void *)&cmd_2tuple_filter_dst_port,
10019                 (void *)&cmd_2tuple_filter_dst_port_value,
10020                 (void *)&cmd_2tuple_filter_protocol,
10021                 (void *)&cmd_2tuple_filter_protocol_value,
10022                 (void *)&cmd_2tuple_filter_mask,
10023                 (void *)&cmd_2tuple_filter_mask_value,
10024                 (void *)&cmd_2tuple_filter_tcp_flags,
10025                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10026                 (void *)&cmd_2tuple_filter_priority,
10027                 (void *)&cmd_2tuple_filter_priority_value,
10028                 (void *)&cmd_2tuple_filter_queue,
10029                 (void *)&cmd_2tuple_filter_queue_id,
10030                 NULL,
10031         },
10032 };
10033
10034 /* *** ADD/REMOVE A 5tuple FILTER *** */
10035 struct cmd_5tuple_filter_result {
10036         cmdline_fixed_string_t filter;
10037         portid_t port_id;
10038         cmdline_fixed_string_t ops;
10039         cmdline_fixed_string_t dst_ip;
10040         cmdline_ipaddr_t dst_ip_value;
10041         cmdline_fixed_string_t src_ip;
10042         cmdline_ipaddr_t src_ip_value;
10043         cmdline_fixed_string_t dst_port;
10044         uint16_t dst_port_value;
10045         cmdline_fixed_string_t src_port;
10046         uint16_t src_port_value;
10047         cmdline_fixed_string_t protocol;
10048         uint8_t protocol_value;
10049         cmdline_fixed_string_t mask;
10050         uint8_t  mask_value;
10051         cmdline_fixed_string_t tcp_flags;
10052         uint8_t tcp_flags_value;
10053         cmdline_fixed_string_t priority;
10054         uint8_t  priority_value;
10055         cmdline_fixed_string_t queue;
10056         uint16_t  queue_id;
10057 };
10058
10059 static void
10060 cmd_5tuple_filter_parsed(void *parsed_result,
10061                         __attribute__((unused)) struct cmdline *cl,
10062                         __attribute__((unused)) void *data)
10063 {
10064         struct rte_eth_ntuple_filter filter;
10065         struct cmd_5tuple_filter_result *res = parsed_result;
10066         int ret = 0;
10067
10068         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10069         if (ret < 0) {
10070                 printf("ntuple filter is not supported on port %u.\n",
10071                         res->port_id);
10072                 return;
10073         }
10074
10075         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10076
10077         filter.flags = RTE_5TUPLE_FLAGS;
10078         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10079         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10080         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10081         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10082         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10083         filter.proto = res->protocol_value;
10084         filter.priority = res->priority_value;
10085         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10086                 printf("nonzero tcp_flags is only meaningful"
10087                         " when protocol is TCP.\n");
10088                 return;
10089         }
10090         if (res->tcp_flags_value > TCP_FLAG_ALL) {
10091                 printf("invalid TCP flags.\n");
10092                 return;
10093         }
10094
10095         if (res->tcp_flags_value != 0) {
10096                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10097                 filter.tcp_flags = res->tcp_flags_value;
10098         }
10099
10100         if (res->dst_ip_value.family == AF_INET)
10101                 /* no need to convert, already big endian. */
10102                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10103         else {
10104                 if (filter.dst_ip_mask == 0) {
10105                         printf("can not support ipv6 involved compare.\n");
10106                         return;
10107                 }
10108                 filter.dst_ip = 0;
10109         }
10110
10111         if (res->src_ip_value.family == AF_INET)
10112                 /* no need to convert, already big endian. */
10113                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10114         else {
10115                 if (filter.src_ip_mask == 0) {
10116                         printf("can not support ipv6 involved compare.\n");
10117                         return;
10118                 }
10119                 filter.src_ip = 0;
10120         }
10121         /* need convert to big endian. */
10122         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10123         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10124         filter.queue = res->queue_id;
10125
10126         if (!strcmp(res->ops, "add"))
10127                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10128                                 RTE_ETH_FILTER_NTUPLE,
10129                                 RTE_ETH_FILTER_ADD,
10130                                 &filter);
10131         else
10132                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10133                                 RTE_ETH_FILTER_NTUPLE,
10134                                 RTE_ETH_FILTER_DELETE,
10135                                 &filter);
10136         if (ret < 0)
10137                 printf("5tuple filter programming error: (%s)\n",
10138                         strerror(-ret));
10139 }
10140
10141 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10142         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10143                                  filter, "5tuple_filter");
10144 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10145         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10146                                 port_id, UINT16);
10147 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10148         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10149                                  ops, "add#del");
10150 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10151         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10152                                 dst_ip, "dst_ip");
10153 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10154         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10155                                 dst_ip_value);
10156 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10157         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10158                                 src_ip, "src_ip");
10159 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10160         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10161                                 src_ip_value);
10162 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10163         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10164                                 dst_port, "dst_port");
10165 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10166         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10167                                 dst_port_value, UINT16);
10168 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10169         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10170                                 src_port, "src_port");
10171 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10172         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10173                                 src_port_value, UINT16);
10174 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10175         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10176                                 protocol, "protocol");
10177 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10178         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10179                                 protocol_value, UINT8);
10180 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10181         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10182                                 mask, "mask");
10183 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10184         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10185                                 mask_value, INT8);
10186 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10187         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10188                                 tcp_flags, "tcp_flags");
10189 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10190         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10191                                 tcp_flags_value, UINT8);
10192 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10193         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10194                                 priority, "priority");
10195 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10196         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10197                                 priority_value, UINT8);
10198 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10199         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10200                                 queue, "queue");
10201 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10202         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10203                                 queue_id, UINT16);
10204
10205 cmdline_parse_inst_t cmd_5tuple_filter = {
10206         .f = cmd_5tuple_filter_parsed,
10207         .data = NULL,
10208         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10209                 "src_ip <value> dst_port <value> src_port <value> "
10210                 "protocol <value>  mask <value> tcp_flags <value> "
10211                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10212         .tokens = {
10213                 (void *)&cmd_5tuple_filter_filter,
10214                 (void *)&cmd_5tuple_filter_port_id,
10215                 (void *)&cmd_5tuple_filter_ops,
10216                 (void *)&cmd_5tuple_filter_dst_ip,
10217                 (void *)&cmd_5tuple_filter_dst_ip_value,
10218                 (void *)&cmd_5tuple_filter_src_ip,
10219                 (void *)&cmd_5tuple_filter_src_ip_value,
10220                 (void *)&cmd_5tuple_filter_dst_port,
10221                 (void *)&cmd_5tuple_filter_dst_port_value,
10222                 (void *)&cmd_5tuple_filter_src_port,
10223                 (void *)&cmd_5tuple_filter_src_port_value,
10224                 (void *)&cmd_5tuple_filter_protocol,
10225                 (void *)&cmd_5tuple_filter_protocol_value,
10226                 (void *)&cmd_5tuple_filter_mask,
10227                 (void *)&cmd_5tuple_filter_mask_value,
10228                 (void *)&cmd_5tuple_filter_tcp_flags,
10229                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10230                 (void *)&cmd_5tuple_filter_priority,
10231                 (void *)&cmd_5tuple_filter_priority_value,
10232                 (void *)&cmd_5tuple_filter_queue,
10233                 (void *)&cmd_5tuple_filter_queue_id,
10234                 NULL,
10235         },
10236 };
10237
10238 /* *** ADD/REMOVE A flex FILTER *** */
10239 struct cmd_flex_filter_result {
10240         cmdline_fixed_string_t filter;
10241         cmdline_fixed_string_t ops;
10242         portid_t port_id;
10243         cmdline_fixed_string_t len;
10244         uint8_t len_value;
10245         cmdline_fixed_string_t bytes;
10246         cmdline_fixed_string_t bytes_value;
10247         cmdline_fixed_string_t mask;
10248         cmdline_fixed_string_t mask_value;
10249         cmdline_fixed_string_t priority;
10250         uint8_t priority_value;
10251         cmdline_fixed_string_t queue;
10252         uint16_t queue_id;
10253 };
10254
10255 static int xdigit2val(unsigned char c)
10256 {
10257         int val;
10258         if (isdigit(c))
10259                 val = c - '0';
10260         else if (isupper(c))
10261                 val = c - 'A' + 10;
10262         else
10263                 val = c - 'a' + 10;
10264         return val;
10265 }
10266
10267 static void
10268 cmd_flex_filter_parsed(void *parsed_result,
10269                           __attribute__((unused)) struct cmdline *cl,
10270                           __attribute__((unused)) void *data)
10271 {
10272         int ret = 0;
10273         struct rte_eth_flex_filter filter;
10274         struct cmd_flex_filter_result *res = parsed_result;
10275         char *bytes_ptr, *mask_ptr;
10276         uint16_t len, i, j = 0;
10277         char c;
10278         int val;
10279         uint8_t byte = 0;
10280
10281         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10282                 printf("the len exceed the max length 128\n");
10283                 return;
10284         }
10285         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10286         filter.len = res->len_value;
10287         filter.priority = res->priority_value;
10288         filter.queue = res->queue_id;
10289         bytes_ptr = res->bytes_value;
10290         mask_ptr = res->mask_value;
10291
10292          /* translate bytes string to array. */
10293         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10294                 (bytes_ptr[1] == 'X')))
10295                 bytes_ptr += 2;
10296         len = strnlen(bytes_ptr, res->len_value * 2);
10297         if (len == 0 || (len % 8 != 0)) {
10298                 printf("please check len and bytes input\n");
10299                 return;
10300         }
10301         for (i = 0; i < len; i++) {
10302                 c = bytes_ptr[i];
10303                 if (isxdigit(c) == 0) {
10304                         /* invalid characters. */
10305                         printf("invalid input\n");
10306                         return;
10307                 }
10308                 val = xdigit2val(c);
10309                 if (i % 2) {
10310                         byte |= val;
10311                         filter.bytes[j] = byte;
10312                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10313                         j++;
10314                         byte = 0;
10315                 } else
10316                         byte |= val << 4;
10317         }
10318         printf("\n");
10319          /* translate mask string to uint8_t array. */
10320         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10321                 (mask_ptr[1] == 'X')))
10322                 mask_ptr += 2;
10323         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10324         if (len == 0) {
10325                 printf("invalid input\n");
10326                 return;
10327         }
10328         j = 0;
10329         byte = 0;
10330         for (i = 0; i < len; i++) {
10331                 c = mask_ptr[i];
10332                 if (isxdigit(c) == 0) {
10333                         /* invalid characters. */
10334                         printf("invalid input\n");
10335                         return;
10336                 }
10337                 val = xdigit2val(c);
10338                 if (i % 2) {
10339                         byte |= val;
10340                         filter.mask[j] = byte;
10341                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10342                         j++;
10343                         byte = 0;
10344                 } else
10345                         byte |= val << 4;
10346         }
10347         printf("\n");
10348
10349         if (!strcmp(res->ops, "add"))
10350                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10351                                 RTE_ETH_FILTER_FLEXIBLE,
10352                                 RTE_ETH_FILTER_ADD,
10353                                 &filter);
10354         else
10355                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10356                                 RTE_ETH_FILTER_FLEXIBLE,
10357                                 RTE_ETH_FILTER_DELETE,
10358                                 &filter);
10359
10360         if (ret < 0)
10361                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10362 }
10363
10364 cmdline_parse_token_string_t cmd_flex_filter_filter =
10365         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10366                                 filter, "flex_filter");
10367 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10368         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10369                                 port_id, UINT16);
10370 cmdline_parse_token_string_t cmd_flex_filter_ops =
10371         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10372                                 ops, "add#del");
10373 cmdline_parse_token_string_t cmd_flex_filter_len =
10374         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10375                                 len, "len");
10376 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10377         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10378                                 len_value, UINT8);
10379 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10380         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10381                                 bytes, "bytes");
10382 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10383         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10384                                 bytes_value, NULL);
10385 cmdline_parse_token_string_t cmd_flex_filter_mask =
10386         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10387                                 mask, "mask");
10388 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10389         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10390                                 mask_value, NULL);
10391 cmdline_parse_token_string_t cmd_flex_filter_priority =
10392         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10393                                 priority, "priority");
10394 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10395         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10396                                 priority_value, UINT8);
10397 cmdline_parse_token_string_t cmd_flex_filter_queue =
10398         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10399                                 queue, "queue");
10400 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10401         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10402                                 queue_id, UINT16);
10403 cmdline_parse_inst_t cmd_flex_filter = {
10404         .f = cmd_flex_filter_parsed,
10405         .data = NULL,
10406         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10407                 "<value> mask <value> priority <value> queue <queue_id>: "
10408                 "Add/Del a flex filter",
10409         .tokens = {
10410                 (void *)&cmd_flex_filter_filter,
10411                 (void *)&cmd_flex_filter_port_id,
10412                 (void *)&cmd_flex_filter_ops,
10413                 (void *)&cmd_flex_filter_len,
10414                 (void *)&cmd_flex_filter_len_value,
10415                 (void *)&cmd_flex_filter_bytes,
10416                 (void *)&cmd_flex_filter_bytes_value,
10417                 (void *)&cmd_flex_filter_mask,
10418                 (void *)&cmd_flex_filter_mask_value,
10419                 (void *)&cmd_flex_filter_priority,
10420                 (void *)&cmd_flex_filter_priority_value,
10421                 (void *)&cmd_flex_filter_queue,
10422                 (void *)&cmd_flex_filter_queue_id,
10423                 NULL,
10424         },
10425 };
10426
10427 /* *** Filters Control *** */
10428
10429 /* *** deal with ethertype filter *** */
10430 struct cmd_ethertype_filter_result {
10431         cmdline_fixed_string_t filter;
10432         portid_t port_id;
10433         cmdline_fixed_string_t ops;
10434         cmdline_fixed_string_t mac;
10435         struct ether_addr mac_addr;
10436         cmdline_fixed_string_t ethertype;
10437         uint16_t ethertype_value;
10438         cmdline_fixed_string_t drop;
10439         cmdline_fixed_string_t queue;
10440         uint16_t  queue_id;
10441 };
10442
10443 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10444         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10445                                  filter, "ethertype_filter");
10446 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10447         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10448                               port_id, UINT16);
10449 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10450         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10451                                  ops, "add#del");
10452 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10453         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10454                                  mac, "mac_addr#mac_ignr");
10455 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10456         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10457                                      mac_addr);
10458 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10459         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10460                                  ethertype, "ethertype");
10461 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10462         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10463                               ethertype_value, UINT16);
10464 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10465         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10466                                  drop, "drop#fwd");
10467 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10468         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10469                                  queue, "queue");
10470 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10471         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10472                               queue_id, UINT16);
10473
10474 static void
10475 cmd_ethertype_filter_parsed(void *parsed_result,
10476                           __attribute__((unused)) struct cmdline *cl,
10477                           __attribute__((unused)) void *data)
10478 {
10479         struct cmd_ethertype_filter_result *res = parsed_result;
10480         struct rte_eth_ethertype_filter filter;
10481         int ret = 0;
10482
10483         ret = rte_eth_dev_filter_supported(res->port_id,
10484                         RTE_ETH_FILTER_ETHERTYPE);
10485         if (ret < 0) {
10486                 printf("ethertype filter is not supported on port %u.\n",
10487                         res->port_id);
10488                 return;
10489         }
10490
10491         memset(&filter, 0, sizeof(filter));
10492         if (!strcmp(res->mac, "mac_addr")) {
10493                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10494                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10495                         sizeof(struct ether_addr));
10496         }
10497         if (!strcmp(res->drop, "drop"))
10498                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10499         filter.ether_type = res->ethertype_value;
10500         filter.queue = res->queue_id;
10501
10502         if (!strcmp(res->ops, "add"))
10503                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10504                                 RTE_ETH_FILTER_ETHERTYPE,
10505                                 RTE_ETH_FILTER_ADD,
10506                                 &filter);
10507         else
10508                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10509                                 RTE_ETH_FILTER_ETHERTYPE,
10510                                 RTE_ETH_FILTER_DELETE,
10511                                 &filter);
10512         if (ret < 0)
10513                 printf("ethertype filter programming error: (%s)\n",
10514                         strerror(-ret));
10515 }
10516
10517 cmdline_parse_inst_t cmd_ethertype_filter = {
10518         .f = cmd_ethertype_filter_parsed,
10519         .data = NULL,
10520         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10521                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10522                 "Add or delete an ethertype filter entry",
10523         .tokens = {
10524                 (void *)&cmd_ethertype_filter_filter,
10525                 (void *)&cmd_ethertype_filter_port_id,
10526                 (void *)&cmd_ethertype_filter_ops,
10527                 (void *)&cmd_ethertype_filter_mac,
10528                 (void *)&cmd_ethertype_filter_mac_addr,
10529                 (void *)&cmd_ethertype_filter_ethertype,
10530                 (void *)&cmd_ethertype_filter_ethertype_value,
10531                 (void *)&cmd_ethertype_filter_drop,
10532                 (void *)&cmd_ethertype_filter_queue,
10533                 (void *)&cmd_ethertype_filter_queue_id,
10534                 NULL,
10535         },
10536 };
10537
10538 /* *** deal with flow director filter *** */
10539 struct cmd_flow_director_result {
10540         cmdline_fixed_string_t flow_director_filter;
10541         portid_t port_id;
10542         cmdline_fixed_string_t mode;
10543         cmdline_fixed_string_t mode_value;
10544         cmdline_fixed_string_t ops;
10545         cmdline_fixed_string_t flow;
10546         cmdline_fixed_string_t flow_type;
10547         cmdline_fixed_string_t ether;
10548         uint16_t ether_type;
10549         cmdline_fixed_string_t src;
10550         cmdline_ipaddr_t ip_src;
10551         uint16_t port_src;
10552         cmdline_fixed_string_t dst;
10553         cmdline_ipaddr_t ip_dst;
10554         uint16_t port_dst;
10555         cmdline_fixed_string_t verify_tag;
10556         uint32_t verify_tag_value;
10557         cmdline_fixed_string_t tos;
10558         uint8_t tos_value;
10559         cmdline_fixed_string_t proto;
10560         uint8_t proto_value;
10561         cmdline_fixed_string_t ttl;
10562         uint8_t ttl_value;
10563         cmdline_fixed_string_t vlan;
10564         uint16_t vlan_value;
10565         cmdline_fixed_string_t flexbytes;
10566         cmdline_fixed_string_t flexbytes_value;
10567         cmdline_fixed_string_t pf_vf;
10568         cmdline_fixed_string_t drop;
10569         cmdline_fixed_string_t queue;
10570         uint16_t  queue_id;
10571         cmdline_fixed_string_t fd_id;
10572         uint32_t  fd_id_value;
10573         cmdline_fixed_string_t mac;
10574         struct ether_addr mac_addr;
10575         cmdline_fixed_string_t tunnel;
10576         cmdline_fixed_string_t tunnel_type;
10577         cmdline_fixed_string_t tunnel_id;
10578         uint32_t tunnel_id_value;
10579         cmdline_fixed_string_t packet;
10580         char filepath[];
10581 };
10582
10583 static inline int
10584 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10585 {
10586         char s[256];
10587         const char *p, *p0 = q_arg;
10588         char *end;
10589         unsigned long int_fld;
10590         char *str_fld[max_num];
10591         int i;
10592         unsigned size;
10593         int ret = -1;
10594
10595         p = strchr(p0, '(');
10596         if (p == NULL)
10597                 return -1;
10598         ++p;
10599         p0 = strchr(p, ')');
10600         if (p0 == NULL)
10601                 return -1;
10602
10603         size = p0 - p;
10604         if (size >= sizeof(s))
10605                 return -1;
10606
10607         snprintf(s, sizeof(s), "%.*s", size, p);
10608         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10609         if (ret < 0 || ret > max_num)
10610                 return -1;
10611         for (i = 0; i < ret; i++) {
10612                 errno = 0;
10613                 int_fld = strtoul(str_fld[i], &end, 0);
10614                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10615                         return -1;
10616                 flexbytes[i] = (uint8_t)int_fld;
10617         }
10618         return ret;
10619 }
10620
10621 static uint16_t
10622 str2flowtype(char *string)
10623 {
10624         uint8_t i = 0;
10625         static const struct {
10626                 char str[32];
10627                 uint16_t type;
10628         } flowtype_str[] = {
10629                 {"raw", RTE_ETH_FLOW_RAW},
10630                 {"ipv4", RTE_ETH_FLOW_IPV4},
10631                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10632                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10633                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10634                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10635                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10636                 {"ipv6", RTE_ETH_FLOW_IPV6},
10637                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10638                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10639                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10640                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10641                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10642                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10643         };
10644
10645         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10646                 if (!strcmp(flowtype_str[i].str, string))
10647                         return flowtype_str[i].type;
10648         }
10649
10650         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10651                 return (uint16_t)atoi(string);
10652
10653         return RTE_ETH_FLOW_UNKNOWN;
10654 }
10655
10656 static enum rte_eth_fdir_tunnel_type
10657 str2fdir_tunneltype(char *string)
10658 {
10659         uint8_t i = 0;
10660
10661         static const struct {
10662                 char str[32];
10663                 enum rte_eth_fdir_tunnel_type type;
10664         } tunneltype_str[] = {
10665                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10666                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10667         };
10668
10669         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10670                 if (!strcmp(tunneltype_str[i].str, string))
10671                         return tunneltype_str[i].type;
10672         }
10673         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10674 }
10675
10676 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10677 do { \
10678         if ((ip_addr).family == AF_INET) \
10679                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10680         else { \
10681                 printf("invalid parameter.\n"); \
10682                 return; \
10683         } \
10684 } while (0)
10685
10686 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10687 do { \
10688         if ((ip_addr).family == AF_INET6) \
10689                 rte_memcpy(&(ip), \
10690                                  &((ip_addr).addr.ipv6), \
10691                                  sizeof(struct in6_addr)); \
10692         else { \
10693                 printf("invalid parameter.\n"); \
10694                 return; \
10695         } \
10696 } while (0)
10697
10698 static void
10699 cmd_flow_director_filter_parsed(void *parsed_result,
10700                           __attribute__((unused)) struct cmdline *cl,
10701                           __attribute__((unused)) void *data)
10702 {
10703         struct cmd_flow_director_result *res = parsed_result;
10704         struct rte_eth_fdir_filter entry;
10705         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10706         char *end;
10707         unsigned long vf_id;
10708         int ret = 0;
10709
10710         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10711         if (ret < 0) {
10712                 printf("flow director is not supported on port %u.\n",
10713                         res->port_id);
10714                 return;
10715         }
10716         memset(flexbytes, 0, sizeof(flexbytes));
10717         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10718
10719         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10720                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10721                         printf("Please set mode to MAC-VLAN.\n");
10722                         return;
10723                 }
10724         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10725                 if (strcmp(res->mode_value, "Tunnel")) {
10726                         printf("Please set mode to Tunnel.\n");
10727                         return;
10728                 }
10729         } else {
10730                 if (!strcmp(res->mode_value, "raw")) {
10731 #ifdef RTE_LIBRTE_I40E_PMD
10732                         struct rte_pmd_i40e_flow_type_mapping
10733                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10734                         struct rte_pmd_i40e_pkt_template_conf conf;
10735                         uint16_t flow_type = str2flowtype(res->flow_type);
10736                         uint16_t i, port = res->port_id;
10737                         uint8_t add;
10738
10739                         memset(&conf, 0, sizeof(conf));
10740
10741                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10742                                 printf("Invalid flow type specified.\n");
10743                                 return;
10744                         }
10745                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10746                                                                  mapping);
10747                         if (ret)
10748                                 return;
10749                         if (mapping[flow_type].pctype == 0ULL) {
10750                                 printf("Invalid flow type specified.\n");
10751                                 return;
10752                         }
10753                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10754                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10755                                         conf.input.pctype = i;
10756                                         break;
10757                                 }
10758                         }
10759
10760                         conf.input.packet = open_file(res->filepath,
10761                                                 &conf.input.length);
10762                         if (!conf.input.packet)
10763                                 return;
10764                         if (!strcmp(res->drop, "drop"))
10765                                 conf.action.behavior =
10766                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10767                         else
10768                                 conf.action.behavior =
10769                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10770                         conf.action.report_status =
10771                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10772                         conf.action.rx_queue = res->queue_id;
10773                         conf.soft_id = res->fd_id_value;
10774                         add  = strcmp(res->ops, "del") ? 1 : 0;
10775                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10776                                                                         &conf,
10777                                                                         add);
10778                         if (ret < 0)
10779                                 printf("flow director config error: (%s)\n",
10780                                        strerror(-ret));
10781                         close_file(conf.input.packet);
10782 #endif
10783                         return;
10784                 } else if (strcmp(res->mode_value, "IP")) {
10785                         printf("Please set mode to IP or raw.\n");
10786                         return;
10787                 }
10788                 entry.input.flow_type = str2flowtype(res->flow_type);
10789         }
10790
10791         ret = parse_flexbytes(res->flexbytes_value,
10792                                         flexbytes,
10793                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10794         if (ret < 0) {
10795                 printf("error: Cannot parse flexbytes input.\n");
10796                 return;
10797         }
10798
10799         switch (entry.input.flow_type) {
10800         case RTE_ETH_FLOW_FRAG_IPV4:
10801         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10802                 entry.input.flow.ip4_flow.proto = res->proto_value;
10803                 /* fall-through */
10804         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10805         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10806                 IPV4_ADDR_TO_UINT(res->ip_dst,
10807                         entry.input.flow.ip4_flow.dst_ip);
10808                 IPV4_ADDR_TO_UINT(res->ip_src,
10809                         entry.input.flow.ip4_flow.src_ip);
10810                 entry.input.flow.ip4_flow.tos = res->tos_value;
10811                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10812                 /* need convert to big endian. */
10813                 entry.input.flow.udp4_flow.dst_port =
10814                                 rte_cpu_to_be_16(res->port_dst);
10815                 entry.input.flow.udp4_flow.src_port =
10816                                 rte_cpu_to_be_16(res->port_src);
10817                 break;
10818         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10819                 IPV4_ADDR_TO_UINT(res->ip_dst,
10820                         entry.input.flow.sctp4_flow.ip.dst_ip);
10821                 IPV4_ADDR_TO_UINT(res->ip_src,
10822                         entry.input.flow.sctp4_flow.ip.src_ip);
10823                 entry.input.flow.ip4_flow.tos = res->tos_value;
10824                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10825                 /* need convert to big endian. */
10826                 entry.input.flow.sctp4_flow.dst_port =
10827                                 rte_cpu_to_be_16(res->port_dst);
10828                 entry.input.flow.sctp4_flow.src_port =
10829                                 rte_cpu_to_be_16(res->port_src);
10830                 entry.input.flow.sctp4_flow.verify_tag =
10831                                 rte_cpu_to_be_32(res->verify_tag_value);
10832                 break;
10833         case RTE_ETH_FLOW_FRAG_IPV6:
10834         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10835                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10836                 /* fall-through */
10837         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10838         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10839                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10840                         entry.input.flow.ipv6_flow.dst_ip);
10841                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10842                         entry.input.flow.ipv6_flow.src_ip);
10843                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10844                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10845                 /* need convert to big endian. */
10846                 entry.input.flow.udp6_flow.dst_port =
10847                                 rte_cpu_to_be_16(res->port_dst);
10848                 entry.input.flow.udp6_flow.src_port =
10849                                 rte_cpu_to_be_16(res->port_src);
10850                 break;
10851         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10852                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10853                         entry.input.flow.sctp6_flow.ip.dst_ip);
10854                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10855                         entry.input.flow.sctp6_flow.ip.src_ip);
10856                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10857                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10858                 /* need convert to big endian. */
10859                 entry.input.flow.sctp6_flow.dst_port =
10860                                 rte_cpu_to_be_16(res->port_dst);
10861                 entry.input.flow.sctp6_flow.src_port =
10862                                 rte_cpu_to_be_16(res->port_src);
10863                 entry.input.flow.sctp6_flow.verify_tag =
10864                                 rte_cpu_to_be_32(res->verify_tag_value);
10865                 break;
10866         case RTE_ETH_FLOW_L2_PAYLOAD:
10867                 entry.input.flow.l2_flow.ether_type =
10868                         rte_cpu_to_be_16(res->ether_type);
10869                 break;
10870         default:
10871                 break;
10872         }
10873
10874         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10875                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10876                                  &res->mac_addr,
10877                                  sizeof(struct ether_addr));
10878
10879         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10880                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10881                                  &res->mac_addr,
10882                                  sizeof(struct ether_addr));
10883                 entry.input.flow.tunnel_flow.tunnel_type =
10884                         str2fdir_tunneltype(res->tunnel_type);
10885                 entry.input.flow.tunnel_flow.tunnel_id =
10886                         rte_cpu_to_be_32(res->tunnel_id_value);
10887         }
10888
10889         rte_memcpy(entry.input.flow_ext.flexbytes,
10890                    flexbytes,
10891                    RTE_ETH_FDIR_MAX_FLEXLEN);
10892
10893         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10894
10895         entry.action.flex_off = 0;  /*use 0 by default */
10896         if (!strcmp(res->drop, "drop"))
10897                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10898         else
10899                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10900
10901         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10902             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10903                 if (!strcmp(res->pf_vf, "pf"))
10904                         entry.input.flow_ext.is_vf = 0;
10905                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10906                         struct rte_eth_dev_info dev_info;
10907
10908                         memset(&dev_info, 0, sizeof(dev_info));
10909                         rte_eth_dev_info_get(res->port_id, &dev_info);
10910                         errno = 0;
10911                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10912                         if (errno != 0 || *end != '\0' ||
10913                             vf_id >= dev_info.max_vfs) {
10914                                 printf("invalid parameter %s.\n", res->pf_vf);
10915                                 return;
10916                         }
10917                         entry.input.flow_ext.is_vf = 1;
10918                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10919                 } else {
10920                         printf("invalid parameter %s.\n", res->pf_vf);
10921                         return;
10922                 }
10923         }
10924
10925         /* set to report FD ID by default */
10926         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10927         entry.action.rx_queue = res->queue_id;
10928         entry.soft_id = res->fd_id_value;
10929         if (!strcmp(res->ops, "add"))
10930                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10931                                              RTE_ETH_FILTER_ADD, &entry);
10932         else if (!strcmp(res->ops, "del"))
10933                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10934                                              RTE_ETH_FILTER_DELETE, &entry);
10935         else
10936                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10937                                              RTE_ETH_FILTER_UPDATE, &entry);
10938         if (ret < 0)
10939                 printf("flow director programming error: (%s)\n",
10940                         strerror(-ret));
10941 }
10942
10943 cmdline_parse_token_string_t cmd_flow_director_filter =
10944         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10945                                  flow_director_filter, "flow_director_filter");
10946 cmdline_parse_token_num_t cmd_flow_director_port_id =
10947         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10948                               port_id, UINT16);
10949 cmdline_parse_token_string_t cmd_flow_director_ops =
10950         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10951                                  ops, "add#del#update");
10952 cmdline_parse_token_string_t cmd_flow_director_flow =
10953         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10954                                  flow, "flow");
10955 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10956         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10957                 flow_type, NULL);
10958 cmdline_parse_token_string_t cmd_flow_director_ether =
10959         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10960                                  ether, "ether");
10961 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10962         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10963                               ether_type, UINT16);
10964 cmdline_parse_token_string_t cmd_flow_director_src =
10965         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10966                                  src, "src");
10967 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10968         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10969                                  ip_src);
10970 cmdline_parse_token_num_t cmd_flow_director_port_src =
10971         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10972                               port_src, UINT16);
10973 cmdline_parse_token_string_t cmd_flow_director_dst =
10974         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10975                                  dst, "dst");
10976 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10977         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10978                                  ip_dst);
10979 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10980         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10981                               port_dst, UINT16);
10982 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10983         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10984                                   verify_tag, "verify_tag");
10985 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10986         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10987                               verify_tag_value, UINT32);
10988 cmdline_parse_token_string_t cmd_flow_director_tos =
10989         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10990                                  tos, "tos");
10991 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10992         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10993                               tos_value, UINT8);
10994 cmdline_parse_token_string_t cmd_flow_director_proto =
10995         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10996                                  proto, "proto");
10997 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10998         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10999                               proto_value, UINT8);
11000 cmdline_parse_token_string_t cmd_flow_director_ttl =
11001         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11002                                  ttl, "ttl");
11003 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11004         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11005                               ttl_value, UINT8);
11006 cmdline_parse_token_string_t cmd_flow_director_vlan =
11007         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11008                                  vlan, "vlan");
11009 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11010         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11011                               vlan_value, UINT16);
11012 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11013         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11014                                  flexbytes, "flexbytes");
11015 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11016         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11017                               flexbytes_value, NULL);
11018 cmdline_parse_token_string_t cmd_flow_director_drop =
11019         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11020                                  drop, "drop#fwd");
11021 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11022         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11023                               pf_vf, NULL);
11024 cmdline_parse_token_string_t cmd_flow_director_queue =
11025         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11026                                  queue, "queue");
11027 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11028         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11029                               queue_id, UINT16);
11030 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11031         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11032                                  fd_id, "fd_id");
11033 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11034         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11035                               fd_id_value, UINT32);
11036
11037 cmdline_parse_token_string_t cmd_flow_director_mode =
11038         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11039                                  mode, "mode");
11040 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11041         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11042                                  mode_value, "IP");
11043 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11044         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11045                                  mode_value, "MAC-VLAN");
11046 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11047         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11048                                  mode_value, "Tunnel");
11049 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11050         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11051                                  mode_value, "raw");
11052 cmdline_parse_token_string_t cmd_flow_director_mac =
11053         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11054                                  mac, "mac");
11055 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11056         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11057                                     mac_addr);
11058 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11059         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11060                                  tunnel, "tunnel");
11061 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11062         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11063                                  tunnel_type, "NVGRE#VxLAN");
11064 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11065         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11066                                  tunnel_id, "tunnel-id");
11067 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11068         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11069                               tunnel_id_value, UINT32);
11070 cmdline_parse_token_string_t cmd_flow_director_packet =
11071         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11072                                  packet, "packet");
11073 cmdline_parse_token_string_t cmd_flow_director_filepath =
11074         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11075                                  filepath, NULL);
11076
11077 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11078         .f = cmd_flow_director_filter_parsed,
11079         .data = NULL,
11080         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11081                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11082                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11083                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11084                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11085                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11086                 "fd_id <fd_id_value>: "
11087                 "Add or delete an ip flow director entry on NIC",
11088         .tokens = {
11089                 (void *)&cmd_flow_director_filter,
11090                 (void *)&cmd_flow_director_port_id,
11091                 (void *)&cmd_flow_director_mode,
11092                 (void *)&cmd_flow_director_mode_ip,
11093                 (void *)&cmd_flow_director_ops,
11094                 (void *)&cmd_flow_director_flow,
11095                 (void *)&cmd_flow_director_flow_type,
11096                 (void *)&cmd_flow_director_src,
11097                 (void *)&cmd_flow_director_ip_src,
11098                 (void *)&cmd_flow_director_dst,
11099                 (void *)&cmd_flow_director_ip_dst,
11100                 (void *)&cmd_flow_director_tos,
11101                 (void *)&cmd_flow_director_tos_value,
11102                 (void *)&cmd_flow_director_proto,
11103                 (void *)&cmd_flow_director_proto_value,
11104                 (void *)&cmd_flow_director_ttl,
11105                 (void *)&cmd_flow_director_ttl_value,
11106                 (void *)&cmd_flow_director_vlan,
11107                 (void *)&cmd_flow_director_vlan_value,
11108                 (void *)&cmd_flow_director_flexbytes,
11109                 (void *)&cmd_flow_director_flexbytes_value,
11110                 (void *)&cmd_flow_director_drop,
11111                 (void *)&cmd_flow_director_pf_vf,
11112                 (void *)&cmd_flow_director_queue,
11113                 (void *)&cmd_flow_director_queue_id,
11114                 (void *)&cmd_flow_director_fd_id,
11115                 (void *)&cmd_flow_director_fd_id_value,
11116                 NULL,
11117         },
11118 };
11119
11120 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11121         .f = cmd_flow_director_filter_parsed,
11122         .data = NULL,
11123         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11124                 "director entry on NIC",
11125         .tokens = {
11126                 (void *)&cmd_flow_director_filter,
11127                 (void *)&cmd_flow_director_port_id,
11128                 (void *)&cmd_flow_director_mode,
11129                 (void *)&cmd_flow_director_mode_ip,
11130                 (void *)&cmd_flow_director_ops,
11131                 (void *)&cmd_flow_director_flow,
11132                 (void *)&cmd_flow_director_flow_type,
11133                 (void *)&cmd_flow_director_src,
11134                 (void *)&cmd_flow_director_ip_src,
11135                 (void *)&cmd_flow_director_port_src,
11136                 (void *)&cmd_flow_director_dst,
11137                 (void *)&cmd_flow_director_ip_dst,
11138                 (void *)&cmd_flow_director_port_dst,
11139                 (void *)&cmd_flow_director_tos,
11140                 (void *)&cmd_flow_director_tos_value,
11141                 (void *)&cmd_flow_director_ttl,
11142                 (void *)&cmd_flow_director_ttl_value,
11143                 (void *)&cmd_flow_director_vlan,
11144                 (void *)&cmd_flow_director_vlan_value,
11145                 (void *)&cmd_flow_director_flexbytes,
11146                 (void *)&cmd_flow_director_flexbytes_value,
11147                 (void *)&cmd_flow_director_drop,
11148                 (void *)&cmd_flow_director_pf_vf,
11149                 (void *)&cmd_flow_director_queue,
11150                 (void *)&cmd_flow_director_queue_id,
11151                 (void *)&cmd_flow_director_fd_id,
11152                 (void *)&cmd_flow_director_fd_id_value,
11153                 NULL,
11154         },
11155 };
11156
11157 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11158         .f = cmd_flow_director_filter_parsed,
11159         .data = NULL,
11160         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11161                 "director entry on NIC",
11162         .tokens = {
11163                 (void *)&cmd_flow_director_filter,
11164                 (void *)&cmd_flow_director_port_id,
11165                 (void *)&cmd_flow_director_mode,
11166                 (void *)&cmd_flow_director_mode_ip,
11167                 (void *)&cmd_flow_director_ops,
11168                 (void *)&cmd_flow_director_flow,
11169                 (void *)&cmd_flow_director_flow_type,
11170                 (void *)&cmd_flow_director_src,
11171                 (void *)&cmd_flow_director_ip_src,
11172                 (void *)&cmd_flow_director_port_src,
11173                 (void *)&cmd_flow_director_dst,
11174                 (void *)&cmd_flow_director_ip_dst,
11175                 (void *)&cmd_flow_director_port_dst,
11176                 (void *)&cmd_flow_director_verify_tag,
11177                 (void *)&cmd_flow_director_verify_tag_value,
11178                 (void *)&cmd_flow_director_tos,
11179                 (void *)&cmd_flow_director_tos_value,
11180                 (void *)&cmd_flow_director_ttl,
11181                 (void *)&cmd_flow_director_ttl_value,
11182                 (void *)&cmd_flow_director_vlan,
11183                 (void *)&cmd_flow_director_vlan_value,
11184                 (void *)&cmd_flow_director_flexbytes,
11185                 (void *)&cmd_flow_director_flexbytes_value,
11186                 (void *)&cmd_flow_director_drop,
11187                 (void *)&cmd_flow_director_pf_vf,
11188                 (void *)&cmd_flow_director_queue,
11189                 (void *)&cmd_flow_director_queue_id,
11190                 (void *)&cmd_flow_director_fd_id,
11191                 (void *)&cmd_flow_director_fd_id_value,
11192                 NULL,
11193         },
11194 };
11195
11196 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11197         .f = cmd_flow_director_filter_parsed,
11198         .data = NULL,
11199         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11200                 "director entry on NIC",
11201         .tokens = {
11202                 (void *)&cmd_flow_director_filter,
11203                 (void *)&cmd_flow_director_port_id,
11204                 (void *)&cmd_flow_director_mode,
11205                 (void *)&cmd_flow_director_mode_ip,
11206                 (void *)&cmd_flow_director_ops,
11207                 (void *)&cmd_flow_director_flow,
11208                 (void *)&cmd_flow_director_flow_type,
11209                 (void *)&cmd_flow_director_ether,
11210                 (void *)&cmd_flow_director_ether_type,
11211                 (void *)&cmd_flow_director_flexbytes,
11212                 (void *)&cmd_flow_director_flexbytes_value,
11213                 (void *)&cmd_flow_director_drop,
11214                 (void *)&cmd_flow_director_pf_vf,
11215                 (void *)&cmd_flow_director_queue,
11216                 (void *)&cmd_flow_director_queue_id,
11217                 (void *)&cmd_flow_director_fd_id,
11218                 (void *)&cmd_flow_director_fd_id_value,
11219                 NULL,
11220         },
11221 };
11222
11223 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11224         .f = cmd_flow_director_filter_parsed,
11225         .data = NULL,
11226         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11227                 "director entry on NIC",
11228         .tokens = {
11229                 (void *)&cmd_flow_director_filter,
11230                 (void *)&cmd_flow_director_port_id,
11231                 (void *)&cmd_flow_director_mode,
11232                 (void *)&cmd_flow_director_mode_mac_vlan,
11233                 (void *)&cmd_flow_director_ops,
11234                 (void *)&cmd_flow_director_mac,
11235                 (void *)&cmd_flow_director_mac_addr,
11236                 (void *)&cmd_flow_director_vlan,
11237                 (void *)&cmd_flow_director_vlan_value,
11238                 (void *)&cmd_flow_director_flexbytes,
11239                 (void *)&cmd_flow_director_flexbytes_value,
11240                 (void *)&cmd_flow_director_drop,
11241                 (void *)&cmd_flow_director_queue,
11242                 (void *)&cmd_flow_director_queue_id,
11243                 (void *)&cmd_flow_director_fd_id,
11244                 (void *)&cmd_flow_director_fd_id_value,
11245                 NULL,
11246         },
11247 };
11248
11249 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11250         .f = cmd_flow_director_filter_parsed,
11251         .data = NULL,
11252         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11253                 "director entry on NIC",
11254         .tokens = {
11255                 (void *)&cmd_flow_director_filter,
11256                 (void *)&cmd_flow_director_port_id,
11257                 (void *)&cmd_flow_director_mode,
11258                 (void *)&cmd_flow_director_mode_tunnel,
11259                 (void *)&cmd_flow_director_ops,
11260                 (void *)&cmd_flow_director_mac,
11261                 (void *)&cmd_flow_director_mac_addr,
11262                 (void *)&cmd_flow_director_vlan,
11263                 (void *)&cmd_flow_director_vlan_value,
11264                 (void *)&cmd_flow_director_tunnel,
11265                 (void *)&cmd_flow_director_tunnel_type,
11266                 (void *)&cmd_flow_director_tunnel_id,
11267                 (void *)&cmd_flow_director_tunnel_id_value,
11268                 (void *)&cmd_flow_director_flexbytes,
11269                 (void *)&cmd_flow_director_flexbytes_value,
11270                 (void *)&cmd_flow_director_drop,
11271                 (void *)&cmd_flow_director_queue,
11272                 (void *)&cmd_flow_director_queue_id,
11273                 (void *)&cmd_flow_director_fd_id,
11274                 (void *)&cmd_flow_director_fd_id_value,
11275                 NULL,
11276         },
11277 };
11278
11279 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11280         .f = cmd_flow_director_filter_parsed,
11281         .data = NULL,
11282         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11283                 "director entry on NIC",
11284         .tokens = {
11285                 (void *)&cmd_flow_director_filter,
11286                 (void *)&cmd_flow_director_port_id,
11287                 (void *)&cmd_flow_director_mode,
11288                 (void *)&cmd_flow_director_mode_raw,
11289                 (void *)&cmd_flow_director_ops,
11290                 (void *)&cmd_flow_director_flow,
11291                 (void *)&cmd_flow_director_flow_type,
11292                 (void *)&cmd_flow_director_drop,
11293                 (void *)&cmd_flow_director_queue,
11294                 (void *)&cmd_flow_director_queue_id,
11295                 (void *)&cmd_flow_director_fd_id,
11296                 (void *)&cmd_flow_director_fd_id_value,
11297                 (void *)&cmd_flow_director_packet,
11298                 (void *)&cmd_flow_director_filepath,
11299                 NULL,
11300         },
11301 };
11302
11303 struct cmd_flush_flow_director_result {
11304         cmdline_fixed_string_t flush_flow_director;
11305         portid_t port_id;
11306 };
11307
11308 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11309         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11310                                  flush_flow_director, "flush_flow_director");
11311 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11312         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11313                               port_id, UINT16);
11314
11315 static void
11316 cmd_flush_flow_director_parsed(void *parsed_result,
11317                           __attribute__((unused)) struct cmdline *cl,
11318                           __attribute__((unused)) void *data)
11319 {
11320         struct cmd_flow_director_result *res = parsed_result;
11321         int ret = 0;
11322
11323         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11324         if (ret < 0) {
11325                 printf("flow director is not supported on port %u.\n",
11326                         res->port_id);
11327                 return;
11328         }
11329
11330         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11331                         RTE_ETH_FILTER_FLUSH, NULL);
11332         if (ret < 0)
11333                 printf("flow director table flushing error: (%s)\n",
11334                         strerror(-ret));
11335 }
11336
11337 cmdline_parse_inst_t cmd_flush_flow_director = {
11338         .f = cmd_flush_flow_director_parsed,
11339         .data = NULL,
11340         .help_str = "flush_flow_director <port_id>: "
11341                 "Flush all flow director entries of a device on NIC",
11342         .tokens = {
11343                 (void *)&cmd_flush_flow_director_flush,
11344                 (void *)&cmd_flush_flow_director_port_id,
11345                 NULL,
11346         },
11347 };
11348
11349 /* *** deal with flow director mask *** */
11350 struct cmd_flow_director_mask_result {
11351         cmdline_fixed_string_t flow_director_mask;
11352         portid_t port_id;
11353         cmdline_fixed_string_t mode;
11354         cmdline_fixed_string_t mode_value;
11355         cmdline_fixed_string_t vlan;
11356         uint16_t vlan_mask;
11357         cmdline_fixed_string_t src_mask;
11358         cmdline_ipaddr_t ipv4_src;
11359         cmdline_ipaddr_t ipv6_src;
11360         uint16_t port_src;
11361         cmdline_fixed_string_t dst_mask;
11362         cmdline_ipaddr_t ipv4_dst;
11363         cmdline_ipaddr_t ipv6_dst;
11364         uint16_t port_dst;
11365         cmdline_fixed_string_t mac;
11366         uint8_t mac_addr_byte_mask;
11367         cmdline_fixed_string_t tunnel_id;
11368         uint32_t tunnel_id_mask;
11369         cmdline_fixed_string_t tunnel_type;
11370         uint8_t tunnel_type_mask;
11371 };
11372
11373 static void
11374 cmd_flow_director_mask_parsed(void *parsed_result,
11375                           __attribute__((unused)) struct cmdline *cl,
11376                           __attribute__((unused)) void *data)
11377 {
11378         struct cmd_flow_director_mask_result *res = parsed_result;
11379         struct rte_eth_fdir_masks *mask;
11380         struct rte_port *port;
11381
11382         port = &ports[res->port_id];
11383         /** Check if the port is not started **/
11384         if (port->port_status != RTE_PORT_STOPPED) {
11385                 printf("Please stop port %d first\n", res->port_id);
11386                 return;
11387         }
11388
11389         mask = &port->dev_conf.fdir_conf.mask;
11390
11391         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11392                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11393                         printf("Please set mode to MAC-VLAN.\n");
11394                         return;
11395                 }
11396
11397                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11398         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11399                 if (strcmp(res->mode_value, "Tunnel")) {
11400                         printf("Please set mode to Tunnel.\n");
11401                         return;
11402                 }
11403
11404                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11405                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11406                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11407                 mask->tunnel_type_mask = res->tunnel_type_mask;
11408         } else {
11409                 if (strcmp(res->mode_value, "IP")) {
11410                         printf("Please set mode to IP.\n");
11411                         return;
11412                 }
11413
11414                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11415                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11416                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11417                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11418                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11419                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11420                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11421         }
11422
11423         cmd_reconfig_device_queue(res->port_id, 1, 1);
11424 }
11425
11426 cmdline_parse_token_string_t cmd_flow_director_mask =
11427         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11428                                  flow_director_mask, "flow_director_mask");
11429 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11430         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11431                               port_id, UINT16);
11432 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11433         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11434                                  vlan, "vlan");
11435 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11436         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11437                               vlan_mask, UINT16);
11438 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11439         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11440                                  src_mask, "src_mask");
11441 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11442         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11443                                  ipv4_src);
11444 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11445         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11446                                  ipv6_src);
11447 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11448         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11449                               port_src, UINT16);
11450 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11451         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11452                                  dst_mask, "dst_mask");
11453 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11454         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11455                                  ipv4_dst);
11456 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11457         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11458                                  ipv6_dst);
11459 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11460         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11461                               port_dst, UINT16);
11462
11463 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11464         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11465                                  mode, "mode");
11466 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11467         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11468                                  mode_value, "IP");
11469 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11470         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11471                                  mode_value, "MAC-VLAN");
11472 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11473         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11474                                  mode_value, "Tunnel");
11475 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11476         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11477                                  mac, "mac");
11478 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11479         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11480                               mac_addr_byte_mask, UINT8);
11481 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11482         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11483                                  tunnel_type, "tunnel-type");
11484 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11485         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11486                               tunnel_type_mask, UINT8);
11487 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11488         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11489                                  tunnel_id, "tunnel-id");
11490 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11491         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11492                               tunnel_id_mask, UINT32);
11493
11494 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11495         .f = cmd_flow_director_mask_parsed,
11496         .data = NULL,
11497         .help_str = "flow_director_mask ... : "
11498                 "Set IP mode flow director's mask on NIC",
11499         .tokens = {
11500                 (void *)&cmd_flow_director_mask,
11501                 (void *)&cmd_flow_director_mask_port_id,
11502                 (void *)&cmd_flow_director_mask_mode,
11503                 (void *)&cmd_flow_director_mask_mode_ip,
11504                 (void *)&cmd_flow_director_mask_vlan,
11505                 (void *)&cmd_flow_director_mask_vlan_value,
11506                 (void *)&cmd_flow_director_mask_src,
11507                 (void *)&cmd_flow_director_mask_ipv4_src,
11508                 (void *)&cmd_flow_director_mask_ipv6_src,
11509                 (void *)&cmd_flow_director_mask_port_src,
11510                 (void *)&cmd_flow_director_mask_dst,
11511                 (void *)&cmd_flow_director_mask_ipv4_dst,
11512                 (void *)&cmd_flow_director_mask_ipv6_dst,
11513                 (void *)&cmd_flow_director_mask_port_dst,
11514                 NULL,
11515         },
11516 };
11517
11518 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11519         .f = cmd_flow_director_mask_parsed,
11520         .data = NULL,
11521         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11522                 "flow director's mask on NIC",
11523         .tokens = {
11524                 (void *)&cmd_flow_director_mask,
11525                 (void *)&cmd_flow_director_mask_port_id,
11526                 (void *)&cmd_flow_director_mask_mode,
11527                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11528                 (void *)&cmd_flow_director_mask_vlan,
11529                 (void *)&cmd_flow_director_mask_vlan_value,
11530                 NULL,
11531         },
11532 };
11533
11534 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11535         .f = cmd_flow_director_mask_parsed,
11536         .data = NULL,
11537         .help_str = "flow_director_mask ... : Set tunnel mode "
11538                 "flow director's mask on NIC",
11539         .tokens = {
11540                 (void *)&cmd_flow_director_mask,
11541                 (void *)&cmd_flow_director_mask_port_id,
11542                 (void *)&cmd_flow_director_mask_mode,
11543                 (void *)&cmd_flow_director_mask_mode_tunnel,
11544                 (void *)&cmd_flow_director_mask_vlan,
11545                 (void *)&cmd_flow_director_mask_vlan_value,
11546                 (void *)&cmd_flow_director_mask_mac,
11547                 (void *)&cmd_flow_director_mask_mac_value,
11548                 (void *)&cmd_flow_director_mask_tunnel_type,
11549                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11550                 (void *)&cmd_flow_director_mask_tunnel_id,
11551                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11552                 NULL,
11553         },
11554 };
11555
11556 /* *** deal with flow director mask on flexible payload *** */
11557 struct cmd_flow_director_flex_mask_result {
11558         cmdline_fixed_string_t flow_director_flexmask;
11559         portid_t port_id;
11560         cmdline_fixed_string_t flow;
11561         cmdline_fixed_string_t flow_type;
11562         cmdline_fixed_string_t mask;
11563 };
11564
11565 static void
11566 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11567                           __attribute__((unused)) struct cmdline *cl,
11568                           __attribute__((unused)) void *data)
11569 {
11570         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11571         struct rte_eth_fdir_info fdir_info;
11572         struct rte_eth_fdir_flex_mask flex_mask;
11573         struct rte_port *port;
11574         uint64_t flow_type_mask;
11575         uint16_t i;
11576         int ret;
11577
11578         port = &ports[res->port_id];
11579         /** Check if the port is not started **/
11580         if (port->port_status != RTE_PORT_STOPPED) {
11581                 printf("Please stop port %d first\n", res->port_id);
11582                 return;
11583         }
11584
11585         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11586         ret = parse_flexbytes(res->mask,
11587                         flex_mask.mask,
11588                         RTE_ETH_FDIR_MAX_FLEXLEN);
11589         if (ret < 0) {
11590                 printf("error: Cannot parse mask input.\n");
11591                 return;
11592         }
11593
11594         memset(&fdir_info, 0, sizeof(fdir_info));
11595         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11596                                 RTE_ETH_FILTER_INFO, &fdir_info);
11597         if (ret < 0) {
11598                 printf("Cannot get FDir filter info\n");
11599                 return;
11600         }
11601
11602         if (!strcmp(res->flow_type, "none")) {
11603                 /* means don't specify the flow type */
11604                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11605                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11606                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11607                                0, sizeof(struct rte_eth_fdir_flex_mask));
11608                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11609                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11610                                  &flex_mask,
11611                                  sizeof(struct rte_eth_fdir_flex_mask));
11612                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11613                 return;
11614         }
11615         flow_type_mask = fdir_info.flow_types_mask[0];
11616         if (!strcmp(res->flow_type, "all")) {
11617                 if (!flow_type_mask) {
11618                         printf("No flow type supported\n");
11619                         return;
11620                 }
11621                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11622                         if (flow_type_mask & (1ULL << i)) {
11623                                 flex_mask.flow_type = i;
11624                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11625                         }
11626                 }
11627                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11628                 return;
11629         }
11630         flex_mask.flow_type = str2flowtype(res->flow_type);
11631         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11632                 printf("Flow type %s not supported on port %d\n",
11633                                 res->flow_type, res->port_id);
11634                 return;
11635         }
11636         fdir_set_flex_mask(res->port_id, &flex_mask);
11637         cmd_reconfig_device_queue(res->port_id, 1, 1);
11638 }
11639
11640 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11641         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11642                                  flow_director_flexmask,
11643                                  "flow_director_flex_mask");
11644 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11645         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11646                               port_id, UINT16);
11647 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11648         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11649                                  flow, "flow");
11650 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11651         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11652                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11653                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11654 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11655         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11656                                  mask, NULL);
11657
11658 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11659         .f = cmd_flow_director_flex_mask_parsed,
11660         .data = NULL,
11661         .help_str = "flow_director_flex_mask ... : "
11662                 "Set flow director's flex mask on NIC",
11663         .tokens = {
11664                 (void *)&cmd_flow_director_flexmask,
11665                 (void *)&cmd_flow_director_flexmask_port_id,
11666                 (void *)&cmd_flow_director_flexmask_flow,
11667                 (void *)&cmd_flow_director_flexmask_flow_type,
11668                 (void *)&cmd_flow_director_flexmask_mask,
11669                 NULL,
11670         },
11671 };
11672
11673 /* *** deal with flow director flexible payload configuration *** */
11674 struct cmd_flow_director_flexpayload_result {
11675         cmdline_fixed_string_t flow_director_flexpayload;
11676         portid_t port_id;
11677         cmdline_fixed_string_t payload_layer;
11678         cmdline_fixed_string_t payload_cfg;
11679 };
11680
11681 static inline int
11682 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11683 {
11684         char s[256];
11685         const char *p, *p0 = q_arg;
11686         char *end;
11687         unsigned long int_fld;
11688         char *str_fld[max_num];
11689         int i;
11690         unsigned size;
11691         int ret = -1;
11692
11693         p = strchr(p0, '(');
11694         if (p == NULL)
11695                 return -1;
11696         ++p;
11697         p0 = strchr(p, ')');
11698         if (p0 == NULL)
11699                 return -1;
11700
11701         size = p0 - p;
11702         if (size >= sizeof(s))
11703                 return -1;
11704
11705         snprintf(s, sizeof(s), "%.*s", size, p);
11706         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11707         if (ret < 0 || ret > max_num)
11708                 return -1;
11709         for (i = 0; i < ret; i++) {
11710                 errno = 0;
11711                 int_fld = strtoul(str_fld[i], &end, 0);
11712                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11713                         return -1;
11714                 offsets[i] = (uint16_t)int_fld;
11715         }
11716         return ret;
11717 }
11718
11719 static void
11720 cmd_flow_director_flxpld_parsed(void *parsed_result,
11721                           __attribute__((unused)) struct cmdline *cl,
11722                           __attribute__((unused)) void *data)
11723 {
11724         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11725         struct rte_eth_flex_payload_cfg flex_cfg;
11726         struct rte_port *port;
11727         int ret = 0;
11728
11729         port = &ports[res->port_id];
11730         /** Check if the port is not started **/
11731         if (port->port_status != RTE_PORT_STOPPED) {
11732                 printf("Please stop port %d first\n", res->port_id);
11733                 return;
11734         }
11735
11736         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11737
11738         if (!strcmp(res->payload_layer, "raw"))
11739                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11740         else if (!strcmp(res->payload_layer, "l2"))
11741                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11742         else if (!strcmp(res->payload_layer, "l3"))
11743                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11744         else if (!strcmp(res->payload_layer, "l4"))
11745                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11746
11747         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11748                             RTE_ETH_FDIR_MAX_FLEXLEN);
11749         if (ret < 0) {
11750                 printf("error: Cannot parse flex payload input.\n");
11751                 return;
11752         }
11753
11754         fdir_set_flex_payload(res->port_id, &flex_cfg);
11755         cmd_reconfig_device_queue(res->port_id, 1, 1);
11756 }
11757
11758 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11759         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11760                                  flow_director_flexpayload,
11761                                  "flow_director_flex_payload");
11762 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11763         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11764                               port_id, UINT16);
11765 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11766         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11767                                  payload_layer, "raw#l2#l3#l4");
11768 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11769         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11770                                  payload_cfg, NULL);
11771
11772 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11773         .f = cmd_flow_director_flxpld_parsed,
11774         .data = NULL,
11775         .help_str = "flow_director_flexpayload ... : "
11776                 "Set flow director's flex payload on NIC",
11777         .tokens = {
11778                 (void *)&cmd_flow_director_flexpayload,
11779                 (void *)&cmd_flow_director_flexpayload_port_id,
11780                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11781                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11782                 NULL,
11783         },
11784 };
11785
11786 /* Generic flow interface command. */
11787 extern cmdline_parse_inst_t cmd_flow;
11788
11789 /* *** Classification Filters Control *** */
11790 /* *** Get symmetric hash enable per port *** */
11791 struct cmd_get_sym_hash_ena_per_port_result {
11792         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11793         portid_t port_id;
11794 };
11795
11796 static void
11797 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11798                                  __rte_unused struct cmdline *cl,
11799                                  __rte_unused void *data)
11800 {
11801         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11802         struct rte_eth_hash_filter_info info;
11803         int ret;
11804
11805         if (rte_eth_dev_filter_supported(res->port_id,
11806                                 RTE_ETH_FILTER_HASH) < 0) {
11807                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11808                                                         res->port_id);
11809                 return;
11810         }
11811
11812         memset(&info, 0, sizeof(info));
11813         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11814         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11815                                                 RTE_ETH_FILTER_GET, &info);
11816
11817         if (ret < 0) {
11818                 printf("Cannot get symmetric hash enable per port "
11819                                         "on port %u\n", res->port_id);
11820                 return;
11821         }
11822
11823         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11824                                 "enabled" : "disabled", res->port_id);
11825 }
11826
11827 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11828         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11829                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11830 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11831         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11832                 port_id, UINT16);
11833
11834 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11835         .f = cmd_get_sym_hash_per_port_parsed,
11836         .data = NULL,
11837         .help_str = "get_sym_hash_ena_per_port <port_id>",
11838         .tokens = {
11839                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11840                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11841                 NULL,
11842         },
11843 };
11844
11845 /* *** Set symmetric hash enable per port *** */
11846 struct cmd_set_sym_hash_ena_per_port_result {
11847         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11848         cmdline_fixed_string_t enable;
11849         portid_t port_id;
11850 };
11851
11852 static void
11853 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11854                                  __rte_unused struct cmdline *cl,
11855                                  __rte_unused void *data)
11856 {
11857         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11858         struct rte_eth_hash_filter_info info;
11859         int ret;
11860
11861         if (rte_eth_dev_filter_supported(res->port_id,
11862                                 RTE_ETH_FILTER_HASH) < 0) {
11863                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11864                                                         res->port_id);
11865                 return;
11866         }
11867
11868         memset(&info, 0, sizeof(info));
11869         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11870         if (!strcmp(res->enable, "enable"))
11871                 info.info.enable = 1;
11872         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11873                                         RTE_ETH_FILTER_SET, &info);
11874         if (ret < 0) {
11875                 printf("Cannot set symmetric hash enable per port on "
11876                                         "port %u\n", res->port_id);
11877                 return;
11878         }
11879         printf("Symmetric hash has been set to %s on port %u\n",
11880                                         res->enable, res->port_id);
11881 }
11882
11883 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11884         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11885                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11886 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11887         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11888                 port_id, UINT16);
11889 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11890         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11891                 enable, "enable#disable");
11892
11893 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11894         .f = cmd_set_sym_hash_per_port_parsed,
11895         .data = NULL,
11896         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11897         .tokens = {
11898                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11899                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11900                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11901                 NULL,
11902         },
11903 };
11904
11905 /* Get global config of hash function */
11906 struct cmd_get_hash_global_config_result {
11907         cmdline_fixed_string_t get_hash_global_config;
11908         portid_t port_id;
11909 };
11910
11911 static char *
11912 flowtype_to_str(uint16_t ftype)
11913 {
11914         uint16_t i;
11915         static struct {
11916                 char str[16];
11917                 uint16_t ftype;
11918         } ftype_table[] = {
11919                 {"ipv4", RTE_ETH_FLOW_IPV4},
11920                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11921                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11922                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11923                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11924                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11925                 {"ipv6", RTE_ETH_FLOW_IPV6},
11926                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11927                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11928                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11929                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11930                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11931                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11932                 {"port", RTE_ETH_FLOW_PORT},
11933                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11934                 {"geneve", RTE_ETH_FLOW_GENEVE},
11935                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11936         };
11937
11938         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11939                 if (ftype_table[i].ftype == ftype)
11940                         return ftype_table[i].str;
11941         }
11942
11943         return NULL;
11944 }
11945
11946 static void
11947 cmd_get_hash_global_config_parsed(void *parsed_result,
11948                                   __rte_unused struct cmdline *cl,
11949                                   __rte_unused void *data)
11950 {
11951         struct cmd_get_hash_global_config_result *res = parsed_result;
11952         struct rte_eth_hash_filter_info info;
11953         uint32_t idx, offset;
11954         uint16_t i;
11955         char *str;
11956         int ret;
11957
11958         if (rte_eth_dev_filter_supported(res->port_id,
11959                         RTE_ETH_FILTER_HASH) < 0) {
11960                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11961                                                         res->port_id);
11962                 return;
11963         }
11964
11965         memset(&info, 0, sizeof(info));
11966         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11967         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11968                                         RTE_ETH_FILTER_GET, &info);
11969         if (ret < 0) {
11970                 printf("Cannot get hash global configurations by port %d\n",
11971                                                         res->port_id);
11972                 return;
11973         }
11974
11975         switch (info.info.global_conf.hash_func) {
11976         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11977                 printf("Hash function is Toeplitz\n");
11978                 break;
11979         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11980                 printf("Hash function is Simple XOR\n");
11981                 break;
11982         default:
11983                 printf("Unknown hash function\n");
11984                 break;
11985         }
11986
11987         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11988                 idx = i / UINT64_BIT;
11989                 offset = i % UINT64_BIT;
11990                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11991                                                 (1ULL << offset)))
11992                         continue;
11993                 str = flowtype_to_str(i);
11994                 if (!str)
11995                         continue;
11996                 printf("Symmetric hash is %s globally for flow type %s "
11997                                                         "by port %d\n",
11998                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11999                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12000                                                         res->port_id);
12001         }
12002 }
12003
12004 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12005         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12006                 get_hash_global_config, "get_hash_global_config");
12007 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12008         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12009                 port_id, UINT16);
12010
12011 cmdline_parse_inst_t cmd_get_hash_global_config = {
12012         .f = cmd_get_hash_global_config_parsed,
12013         .data = NULL,
12014         .help_str = "get_hash_global_config <port_id>",
12015         .tokens = {
12016                 (void *)&cmd_get_hash_global_config_all,
12017                 (void *)&cmd_get_hash_global_config_port_id,
12018                 NULL,
12019         },
12020 };
12021
12022 /* Set global config of hash function */
12023 struct cmd_set_hash_global_config_result {
12024         cmdline_fixed_string_t set_hash_global_config;
12025         portid_t port_id;
12026         cmdline_fixed_string_t hash_func;
12027         cmdline_fixed_string_t flow_type;
12028         cmdline_fixed_string_t enable;
12029 };
12030
12031 static void
12032 cmd_set_hash_global_config_parsed(void *parsed_result,
12033                                   __rte_unused struct cmdline *cl,
12034                                   __rte_unused void *data)
12035 {
12036         struct cmd_set_hash_global_config_result *res = parsed_result;
12037         struct rte_eth_hash_filter_info info;
12038         uint32_t ftype, idx, offset;
12039         int ret;
12040
12041         if (rte_eth_dev_filter_supported(res->port_id,
12042                                 RTE_ETH_FILTER_HASH) < 0) {
12043                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12044                                                         res->port_id);
12045                 return;
12046         }
12047         memset(&info, 0, sizeof(info));
12048         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12049         if (!strcmp(res->hash_func, "toeplitz"))
12050                 info.info.global_conf.hash_func =
12051                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12052         else if (!strcmp(res->hash_func, "simple_xor"))
12053                 info.info.global_conf.hash_func =
12054                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12055         else if (!strcmp(res->hash_func, "default"))
12056                 info.info.global_conf.hash_func =
12057                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12058
12059         ftype = str2flowtype(res->flow_type);
12060         idx = ftype / UINT64_BIT;
12061         offset = ftype % UINT64_BIT;
12062         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12063         if (!strcmp(res->enable, "enable"))
12064                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12065                                                 (1ULL << offset);
12066         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12067                                         RTE_ETH_FILTER_SET, &info);
12068         if (ret < 0)
12069                 printf("Cannot set global hash configurations by port %d\n",
12070                                                         res->port_id);
12071         else
12072                 printf("Global hash configurations have been set "
12073                         "succcessfully by port %d\n", res->port_id);
12074 }
12075
12076 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12077         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12078                 set_hash_global_config, "set_hash_global_config");
12079 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12080         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12081                 port_id, UINT16);
12082 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12083         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12084                 hash_func, "toeplitz#simple_xor#default");
12085 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12086         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12087                 flow_type,
12088                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12089                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12090 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12091         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12092                 enable, "enable#disable");
12093
12094 cmdline_parse_inst_t cmd_set_hash_global_config = {
12095         .f = cmd_set_hash_global_config_parsed,
12096         .data = NULL,
12097         .help_str = "set_hash_global_config <port_id> "
12098                 "toeplitz|simple_xor|default "
12099                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12100                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12101                 "l2_payload enable|disable",
12102         .tokens = {
12103                 (void *)&cmd_set_hash_global_config_all,
12104                 (void *)&cmd_set_hash_global_config_port_id,
12105                 (void *)&cmd_set_hash_global_config_hash_func,
12106                 (void *)&cmd_set_hash_global_config_flow_type,
12107                 (void *)&cmd_set_hash_global_config_enable,
12108                 NULL,
12109         },
12110 };
12111
12112 /* Set hash input set */
12113 struct cmd_set_hash_input_set_result {
12114         cmdline_fixed_string_t set_hash_input_set;
12115         portid_t port_id;
12116         cmdline_fixed_string_t flow_type;
12117         cmdline_fixed_string_t inset_field;
12118         cmdline_fixed_string_t select;
12119 };
12120
12121 static enum rte_eth_input_set_field
12122 str2inset(char *string)
12123 {
12124         uint16_t i;
12125
12126         static const struct {
12127                 char str[32];
12128                 enum rte_eth_input_set_field inset;
12129         } inset_table[] = {
12130                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12131                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12132                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12133                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12134                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12135                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12136                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12137                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12138                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12139                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12140                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12141                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12142                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12143                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12144                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12145                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12146                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12147                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12148                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12149                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12150                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12151                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12152                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12153                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12154                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12155                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12156                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12157                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12158                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12159                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12160                 {"none", RTE_ETH_INPUT_SET_NONE},
12161         };
12162
12163         for (i = 0; i < RTE_DIM(inset_table); i++) {
12164                 if (!strcmp(string, inset_table[i].str))
12165                         return inset_table[i].inset;
12166         }
12167
12168         return RTE_ETH_INPUT_SET_UNKNOWN;
12169 }
12170
12171 static void
12172 cmd_set_hash_input_set_parsed(void *parsed_result,
12173                               __rte_unused struct cmdline *cl,
12174                               __rte_unused void *data)
12175 {
12176         struct cmd_set_hash_input_set_result *res = parsed_result;
12177         struct rte_eth_hash_filter_info info;
12178
12179         memset(&info, 0, sizeof(info));
12180         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12181         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12182         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12183         info.info.input_set_conf.inset_size = 1;
12184         if (!strcmp(res->select, "select"))
12185                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12186         else if (!strcmp(res->select, "add"))
12187                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12188         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12189                                 RTE_ETH_FILTER_SET, &info);
12190 }
12191
12192 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12193         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12194                 set_hash_input_set, "set_hash_input_set");
12195 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12196         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12197                 port_id, UINT16);
12198 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12199         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12200                 flow_type, NULL);
12201 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12202         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12203                 inset_field,
12204                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12205                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12206                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12207                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12208                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12209                 "fld-8th#none");
12210 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12211         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12212                 select, "select#add");
12213
12214 cmdline_parse_inst_t cmd_set_hash_input_set = {
12215         .f = cmd_set_hash_input_set_parsed,
12216         .data = NULL,
12217         .help_str = "set_hash_input_set <port_id> "
12218         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12219         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12220         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12221         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12222         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12223         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12224         "fld-7th|fld-8th|none select|add",
12225         .tokens = {
12226                 (void *)&cmd_set_hash_input_set_cmd,
12227                 (void *)&cmd_set_hash_input_set_port_id,
12228                 (void *)&cmd_set_hash_input_set_flow_type,
12229                 (void *)&cmd_set_hash_input_set_field,
12230                 (void *)&cmd_set_hash_input_set_select,
12231                 NULL,
12232         },
12233 };
12234
12235 /* Set flow director input set */
12236 struct cmd_set_fdir_input_set_result {
12237         cmdline_fixed_string_t set_fdir_input_set;
12238         portid_t port_id;
12239         cmdline_fixed_string_t flow_type;
12240         cmdline_fixed_string_t inset_field;
12241         cmdline_fixed_string_t select;
12242 };
12243
12244 static void
12245 cmd_set_fdir_input_set_parsed(void *parsed_result,
12246         __rte_unused struct cmdline *cl,
12247         __rte_unused void *data)
12248 {
12249         struct cmd_set_fdir_input_set_result *res = parsed_result;
12250         struct rte_eth_fdir_filter_info info;
12251
12252         memset(&info, 0, sizeof(info));
12253         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12254         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12255         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12256         info.info.input_set_conf.inset_size = 1;
12257         if (!strcmp(res->select, "select"))
12258                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12259         else if (!strcmp(res->select, "add"))
12260                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12261         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12262                 RTE_ETH_FILTER_SET, &info);
12263 }
12264
12265 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12266         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12267         set_fdir_input_set, "set_fdir_input_set");
12268 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12269         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12270         port_id, UINT16);
12271 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12272         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12273         flow_type,
12274         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12275         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12276 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12277         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12278         inset_field,
12279         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12280         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12281         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12282         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12283         "sctp-veri-tag#none");
12284 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12285         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12286         select, "select#add");
12287
12288 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12289         .f = cmd_set_fdir_input_set_parsed,
12290         .data = NULL,
12291         .help_str = "set_fdir_input_set <port_id> "
12292         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12293         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12294         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12295         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12296         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12297         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12298         "sctp-veri-tag|none select|add",
12299         .tokens = {
12300                 (void *)&cmd_set_fdir_input_set_cmd,
12301                 (void *)&cmd_set_fdir_input_set_port_id,
12302                 (void *)&cmd_set_fdir_input_set_flow_type,
12303                 (void *)&cmd_set_fdir_input_set_field,
12304                 (void *)&cmd_set_fdir_input_set_select,
12305                 NULL,
12306         },
12307 };
12308
12309 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12310 struct cmd_mcast_addr_result {
12311         cmdline_fixed_string_t mcast_addr_cmd;
12312         cmdline_fixed_string_t what;
12313         uint16_t port_num;
12314         struct ether_addr mc_addr;
12315 };
12316
12317 static void cmd_mcast_addr_parsed(void *parsed_result,
12318                 __attribute__((unused)) struct cmdline *cl,
12319                 __attribute__((unused)) void *data)
12320 {
12321         struct cmd_mcast_addr_result *res = parsed_result;
12322
12323         if (!is_multicast_ether_addr(&res->mc_addr)) {
12324                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12325                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12326                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12327                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12328                 return;
12329         }
12330         if (strcmp(res->what, "add") == 0)
12331                 mcast_addr_add(res->port_num, &res->mc_addr);
12332         else
12333                 mcast_addr_remove(res->port_num, &res->mc_addr);
12334 }
12335
12336 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12337         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12338                                  mcast_addr_cmd, "mcast_addr");
12339 cmdline_parse_token_string_t cmd_mcast_addr_what =
12340         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12341                                  "add#remove");
12342 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12343         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12344 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12345         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12346
12347 cmdline_parse_inst_t cmd_mcast_addr = {
12348         .f = cmd_mcast_addr_parsed,
12349         .data = (void *)0,
12350         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12351                 "Add/Remove multicast MAC address on port_id",
12352         .tokens = {
12353                 (void *)&cmd_mcast_addr_cmd,
12354                 (void *)&cmd_mcast_addr_what,
12355                 (void *)&cmd_mcast_addr_portnum,
12356                 (void *)&cmd_mcast_addr_addr,
12357                 NULL,
12358         },
12359 };
12360
12361 /* l2 tunnel config
12362  * only support E-tag now.
12363  */
12364
12365 /* Ether type config */
12366 struct cmd_config_l2_tunnel_eth_type_result {
12367         cmdline_fixed_string_t port;
12368         cmdline_fixed_string_t config;
12369         cmdline_fixed_string_t all;
12370         portid_t id;
12371         cmdline_fixed_string_t l2_tunnel;
12372         cmdline_fixed_string_t l2_tunnel_type;
12373         cmdline_fixed_string_t eth_type;
12374         uint16_t eth_type_val;
12375 };
12376
12377 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12378         TOKEN_STRING_INITIALIZER
12379                 (struct cmd_config_l2_tunnel_eth_type_result,
12380                  port, "port");
12381 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12382         TOKEN_STRING_INITIALIZER
12383                 (struct cmd_config_l2_tunnel_eth_type_result,
12384                  config, "config");
12385 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12386         TOKEN_STRING_INITIALIZER
12387                 (struct cmd_config_l2_tunnel_eth_type_result,
12388                  all, "all");
12389 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12390         TOKEN_NUM_INITIALIZER
12391                 (struct cmd_config_l2_tunnel_eth_type_result,
12392                  id, UINT16);
12393 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12394         TOKEN_STRING_INITIALIZER
12395                 (struct cmd_config_l2_tunnel_eth_type_result,
12396                  l2_tunnel, "l2-tunnel");
12397 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12398         TOKEN_STRING_INITIALIZER
12399                 (struct cmd_config_l2_tunnel_eth_type_result,
12400                  l2_tunnel_type, "E-tag");
12401 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12402         TOKEN_STRING_INITIALIZER
12403                 (struct cmd_config_l2_tunnel_eth_type_result,
12404                  eth_type, "ether-type");
12405 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12406         TOKEN_NUM_INITIALIZER
12407                 (struct cmd_config_l2_tunnel_eth_type_result,
12408                  eth_type_val, UINT16);
12409
12410 static enum rte_eth_tunnel_type
12411 str2fdir_l2_tunnel_type(char *string)
12412 {
12413         uint32_t i = 0;
12414
12415         static const struct {
12416                 char str[32];
12417                 enum rte_eth_tunnel_type type;
12418         } l2_tunnel_type_str[] = {
12419                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12420         };
12421
12422         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12423                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12424                         return l2_tunnel_type_str[i].type;
12425         }
12426         return RTE_TUNNEL_TYPE_NONE;
12427 }
12428
12429 /* ether type config for all ports */
12430 static void
12431 cmd_config_l2_tunnel_eth_type_all_parsed
12432         (void *parsed_result,
12433          __attribute__((unused)) struct cmdline *cl,
12434          __attribute__((unused)) void *data)
12435 {
12436         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12437         struct rte_eth_l2_tunnel_conf entry;
12438         portid_t pid;
12439
12440         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12441         entry.ether_type = res->eth_type_val;
12442
12443         RTE_ETH_FOREACH_DEV(pid) {
12444                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12445         }
12446 }
12447
12448 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12449         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12450         .data = NULL,
12451         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12452         .tokens = {
12453                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12454                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12455                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12456                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12457                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12458                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12459                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12460                 NULL,
12461         },
12462 };
12463
12464 /* ether type config for a specific port */
12465 static void
12466 cmd_config_l2_tunnel_eth_type_specific_parsed(
12467         void *parsed_result,
12468         __attribute__((unused)) struct cmdline *cl,
12469         __attribute__((unused)) void *data)
12470 {
12471         struct cmd_config_l2_tunnel_eth_type_result *res =
12472                  parsed_result;
12473         struct rte_eth_l2_tunnel_conf entry;
12474
12475         if (port_id_is_invalid(res->id, ENABLED_WARN))
12476                 return;
12477
12478         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12479         entry.ether_type = res->eth_type_val;
12480
12481         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12482 }
12483
12484 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12485         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12486         .data = NULL,
12487         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12488         .tokens = {
12489                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12490                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12491                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12492                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12493                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12494                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12495                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12496                 NULL,
12497         },
12498 };
12499
12500 /* Enable/disable l2 tunnel */
12501 struct cmd_config_l2_tunnel_en_dis_result {
12502         cmdline_fixed_string_t port;
12503         cmdline_fixed_string_t config;
12504         cmdline_fixed_string_t all;
12505         portid_t id;
12506         cmdline_fixed_string_t l2_tunnel;
12507         cmdline_fixed_string_t l2_tunnel_type;
12508         cmdline_fixed_string_t en_dis;
12509 };
12510
12511 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12512         TOKEN_STRING_INITIALIZER
12513                 (struct cmd_config_l2_tunnel_en_dis_result,
12514                  port, "port");
12515 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12516         TOKEN_STRING_INITIALIZER
12517                 (struct cmd_config_l2_tunnel_en_dis_result,
12518                  config, "config");
12519 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12520         TOKEN_STRING_INITIALIZER
12521                 (struct cmd_config_l2_tunnel_en_dis_result,
12522                  all, "all");
12523 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12524         TOKEN_NUM_INITIALIZER
12525                 (struct cmd_config_l2_tunnel_en_dis_result,
12526                  id, UINT16);
12527 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12528         TOKEN_STRING_INITIALIZER
12529                 (struct cmd_config_l2_tunnel_en_dis_result,
12530                  l2_tunnel, "l2-tunnel");
12531 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12532         TOKEN_STRING_INITIALIZER
12533                 (struct cmd_config_l2_tunnel_en_dis_result,
12534                  l2_tunnel_type, "E-tag");
12535 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12536         TOKEN_STRING_INITIALIZER
12537                 (struct cmd_config_l2_tunnel_en_dis_result,
12538                  en_dis, "enable#disable");
12539
12540 /* enable/disable l2 tunnel for all ports */
12541 static void
12542 cmd_config_l2_tunnel_en_dis_all_parsed(
12543         void *parsed_result,
12544         __attribute__((unused)) struct cmdline *cl,
12545         __attribute__((unused)) void *data)
12546 {
12547         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12548         struct rte_eth_l2_tunnel_conf entry;
12549         portid_t pid;
12550         uint8_t en;
12551
12552         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12553
12554         if (!strcmp("enable", res->en_dis))
12555                 en = 1;
12556         else
12557                 en = 0;
12558
12559         RTE_ETH_FOREACH_DEV(pid) {
12560                 rte_eth_dev_l2_tunnel_offload_set(pid,
12561                                                   &entry,
12562                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12563                                                   en);
12564         }
12565 }
12566
12567 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12568         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12569         .data = NULL,
12570         .help_str = "port config all l2-tunnel E-tag enable|disable",
12571         .tokens = {
12572                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12573                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12574                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12575                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12576                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12577                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12578                 NULL,
12579         },
12580 };
12581
12582 /* enable/disable l2 tunnel for a port */
12583 static void
12584 cmd_config_l2_tunnel_en_dis_specific_parsed(
12585         void *parsed_result,
12586         __attribute__((unused)) struct cmdline *cl,
12587         __attribute__((unused)) void *data)
12588 {
12589         struct cmd_config_l2_tunnel_en_dis_result *res =
12590                 parsed_result;
12591         struct rte_eth_l2_tunnel_conf entry;
12592
12593         if (port_id_is_invalid(res->id, ENABLED_WARN))
12594                 return;
12595
12596         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12597
12598         if (!strcmp("enable", res->en_dis))
12599                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12600                                                   &entry,
12601                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12602                                                   1);
12603         else
12604                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12605                                                   &entry,
12606                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12607                                                   0);
12608 }
12609
12610 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12611         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12612         .data = NULL,
12613         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12614         .tokens = {
12615                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12616                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12617                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12618                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12619                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12620                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12621                 NULL,
12622         },
12623 };
12624
12625 /* E-tag configuration */
12626
12627 /* Common result structure for all E-tag configuration */
12628 struct cmd_config_e_tag_result {
12629         cmdline_fixed_string_t e_tag;
12630         cmdline_fixed_string_t set;
12631         cmdline_fixed_string_t insertion;
12632         cmdline_fixed_string_t stripping;
12633         cmdline_fixed_string_t forwarding;
12634         cmdline_fixed_string_t filter;
12635         cmdline_fixed_string_t add;
12636         cmdline_fixed_string_t del;
12637         cmdline_fixed_string_t on;
12638         cmdline_fixed_string_t off;
12639         cmdline_fixed_string_t on_off;
12640         cmdline_fixed_string_t port_tag_id;
12641         uint32_t port_tag_id_val;
12642         cmdline_fixed_string_t e_tag_id;
12643         uint16_t e_tag_id_val;
12644         cmdline_fixed_string_t dst_pool;
12645         uint8_t dst_pool_val;
12646         cmdline_fixed_string_t port;
12647         portid_t port_id;
12648         cmdline_fixed_string_t vf;
12649         uint8_t vf_id;
12650 };
12651
12652 /* Common CLI fields for all E-tag configuration */
12653 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12654         TOKEN_STRING_INITIALIZER
12655                 (struct cmd_config_e_tag_result,
12656                  e_tag, "E-tag");
12657 cmdline_parse_token_string_t cmd_config_e_tag_set =
12658         TOKEN_STRING_INITIALIZER
12659                 (struct cmd_config_e_tag_result,
12660                  set, "set");
12661 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12662         TOKEN_STRING_INITIALIZER
12663                 (struct cmd_config_e_tag_result,
12664                  insertion, "insertion");
12665 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12666         TOKEN_STRING_INITIALIZER
12667                 (struct cmd_config_e_tag_result,
12668                  stripping, "stripping");
12669 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12670         TOKEN_STRING_INITIALIZER
12671                 (struct cmd_config_e_tag_result,
12672                  forwarding, "forwarding");
12673 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12674         TOKEN_STRING_INITIALIZER
12675                 (struct cmd_config_e_tag_result,
12676                  filter, "filter");
12677 cmdline_parse_token_string_t cmd_config_e_tag_add =
12678         TOKEN_STRING_INITIALIZER
12679                 (struct cmd_config_e_tag_result,
12680                  add, "add");
12681 cmdline_parse_token_string_t cmd_config_e_tag_del =
12682         TOKEN_STRING_INITIALIZER
12683                 (struct cmd_config_e_tag_result,
12684                  del, "del");
12685 cmdline_parse_token_string_t cmd_config_e_tag_on =
12686         TOKEN_STRING_INITIALIZER
12687                 (struct cmd_config_e_tag_result,
12688                  on, "on");
12689 cmdline_parse_token_string_t cmd_config_e_tag_off =
12690         TOKEN_STRING_INITIALIZER
12691                 (struct cmd_config_e_tag_result,
12692                  off, "off");
12693 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12694         TOKEN_STRING_INITIALIZER
12695                 (struct cmd_config_e_tag_result,
12696                  on_off, "on#off");
12697 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12698         TOKEN_STRING_INITIALIZER
12699                 (struct cmd_config_e_tag_result,
12700                  port_tag_id, "port-tag-id");
12701 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12702         TOKEN_NUM_INITIALIZER
12703                 (struct cmd_config_e_tag_result,
12704                  port_tag_id_val, UINT32);
12705 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12706         TOKEN_STRING_INITIALIZER
12707                 (struct cmd_config_e_tag_result,
12708                  e_tag_id, "e-tag-id");
12709 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12710         TOKEN_NUM_INITIALIZER
12711                 (struct cmd_config_e_tag_result,
12712                  e_tag_id_val, UINT16);
12713 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12714         TOKEN_STRING_INITIALIZER
12715                 (struct cmd_config_e_tag_result,
12716                  dst_pool, "dst-pool");
12717 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12718         TOKEN_NUM_INITIALIZER
12719                 (struct cmd_config_e_tag_result,
12720                  dst_pool_val, UINT8);
12721 cmdline_parse_token_string_t cmd_config_e_tag_port =
12722         TOKEN_STRING_INITIALIZER
12723                 (struct cmd_config_e_tag_result,
12724                  port, "port");
12725 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12726         TOKEN_NUM_INITIALIZER
12727                 (struct cmd_config_e_tag_result,
12728                  port_id, UINT16);
12729 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12730         TOKEN_STRING_INITIALIZER
12731                 (struct cmd_config_e_tag_result,
12732                  vf, "vf");
12733 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12734         TOKEN_NUM_INITIALIZER
12735                 (struct cmd_config_e_tag_result,
12736                  vf_id, UINT8);
12737
12738 /* E-tag insertion configuration */
12739 static void
12740 cmd_config_e_tag_insertion_en_parsed(
12741         void *parsed_result,
12742         __attribute__((unused)) struct cmdline *cl,
12743         __attribute__((unused)) void *data)
12744 {
12745         struct cmd_config_e_tag_result *res =
12746                 parsed_result;
12747         struct rte_eth_l2_tunnel_conf entry;
12748
12749         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12750                 return;
12751
12752         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12753         entry.tunnel_id = res->port_tag_id_val;
12754         entry.vf_id = res->vf_id;
12755         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12756                                           &entry,
12757                                           ETH_L2_TUNNEL_INSERTION_MASK,
12758                                           1);
12759 }
12760
12761 static void
12762 cmd_config_e_tag_insertion_dis_parsed(
12763         void *parsed_result,
12764         __attribute__((unused)) struct cmdline *cl,
12765         __attribute__((unused)) void *data)
12766 {
12767         struct cmd_config_e_tag_result *res =
12768                 parsed_result;
12769         struct rte_eth_l2_tunnel_conf entry;
12770
12771         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12772                 return;
12773
12774         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12775         entry.vf_id = res->vf_id;
12776
12777         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12778                                           &entry,
12779                                           ETH_L2_TUNNEL_INSERTION_MASK,
12780                                           0);
12781 }
12782
12783 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12784         .f = cmd_config_e_tag_insertion_en_parsed,
12785         .data = NULL,
12786         .help_str = "E-tag ... : E-tag insertion enable",
12787         .tokens = {
12788                 (void *)&cmd_config_e_tag_e_tag,
12789                 (void *)&cmd_config_e_tag_set,
12790                 (void *)&cmd_config_e_tag_insertion,
12791                 (void *)&cmd_config_e_tag_on,
12792                 (void *)&cmd_config_e_tag_port_tag_id,
12793                 (void *)&cmd_config_e_tag_port_tag_id_val,
12794                 (void *)&cmd_config_e_tag_port,
12795                 (void *)&cmd_config_e_tag_port_id,
12796                 (void *)&cmd_config_e_tag_vf,
12797                 (void *)&cmd_config_e_tag_vf_id,
12798                 NULL,
12799         },
12800 };
12801
12802 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12803         .f = cmd_config_e_tag_insertion_dis_parsed,
12804         .data = NULL,
12805         .help_str = "E-tag ... : E-tag insertion disable",
12806         .tokens = {
12807                 (void *)&cmd_config_e_tag_e_tag,
12808                 (void *)&cmd_config_e_tag_set,
12809                 (void *)&cmd_config_e_tag_insertion,
12810                 (void *)&cmd_config_e_tag_off,
12811                 (void *)&cmd_config_e_tag_port,
12812                 (void *)&cmd_config_e_tag_port_id,
12813                 (void *)&cmd_config_e_tag_vf,
12814                 (void *)&cmd_config_e_tag_vf_id,
12815                 NULL,
12816         },
12817 };
12818
12819 /* E-tag stripping configuration */
12820 static void
12821 cmd_config_e_tag_stripping_parsed(
12822         void *parsed_result,
12823         __attribute__((unused)) struct cmdline *cl,
12824         __attribute__((unused)) void *data)
12825 {
12826         struct cmd_config_e_tag_result *res =
12827                 parsed_result;
12828         struct rte_eth_l2_tunnel_conf entry;
12829
12830         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12831                 return;
12832
12833         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12834
12835         if (!strcmp(res->on_off, "on"))
12836                 rte_eth_dev_l2_tunnel_offload_set
12837                         (res->port_id,
12838                          &entry,
12839                          ETH_L2_TUNNEL_STRIPPING_MASK,
12840                          1);
12841         else
12842                 rte_eth_dev_l2_tunnel_offload_set
12843                         (res->port_id,
12844                          &entry,
12845                          ETH_L2_TUNNEL_STRIPPING_MASK,
12846                          0);
12847 }
12848
12849 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12850         .f = cmd_config_e_tag_stripping_parsed,
12851         .data = NULL,
12852         .help_str = "E-tag ... : E-tag stripping enable/disable",
12853         .tokens = {
12854                 (void *)&cmd_config_e_tag_e_tag,
12855                 (void *)&cmd_config_e_tag_set,
12856                 (void *)&cmd_config_e_tag_stripping,
12857                 (void *)&cmd_config_e_tag_on_off,
12858                 (void *)&cmd_config_e_tag_port,
12859                 (void *)&cmd_config_e_tag_port_id,
12860                 NULL,
12861         },
12862 };
12863
12864 /* E-tag forwarding configuration */
12865 static void
12866 cmd_config_e_tag_forwarding_parsed(
12867         void *parsed_result,
12868         __attribute__((unused)) struct cmdline *cl,
12869         __attribute__((unused)) void *data)
12870 {
12871         struct cmd_config_e_tag_result *res = parsed_result;
12872         struct rte_eth_l2_tunnel_conf entry;
12873
12874         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12875                 return;
12876
12877         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12878
12879         if (!strcmp(res->on_off, "on"))
12880                 rte_eth_dev_l2_tunnel_offload_set
12881                         (res->port_id,
12882                          &entry,
12883                          ETH_L2_TUNNEL_FORWARDING_MASK,
12884                          1);
12885         else
12886                 rte_eth_dev_l2_tunnel_offload_set
12887                         (res->port_id,
12888                          &entry,
12889                          ETH_L2_TUNNEL_FORWARDING_MASK,
12890                          0);
12891 }
12892
12893 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12894         .f = cmd_config_e_tag_forwarding_parsed,
12895         .data = NULL,
12896         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12897         .tokens = {
12898                 (void *)&cmd_config_e_tag_e_tag,
12899                 (void *)&cmd_config_e_tag_set,
12900                 (void *)&cmd_config_e_tag_forwarding,
12901                 (void *)&cmd_config_e_tag_on_off,
12902                 (void *)&cmd_config_e_tag_port,
12903                 (void *)&cmd_config_e_tag_port_id,
12904                 NULL,
12905         },
12906 };
12907
12908 /* E-tag filter configuration */
12909 static void
12910 cmd_config_e_tag_filter_add_parsed(
12911         void *parsed_result,
12912         __attribute__((unused)) struct cmdline *cl,
12913         __attribute__((unused)) void *data)
12914 {
12915         struct cmd_config_e_tag_result *res = parsed_result;
12916         struct rte_eth_l2_tunnel_conf entry;
12917         int ret = 0;
12918
12919         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12920                 return;
12921
12922         if (res->e_tag_id_val > 0x3fff) {
12923                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12924                 return;
12925         }
12926
12927         ret = rte_eth_dev_filter_supported(res->port_id,
12928                                            RTE_ETH_FILTER_L2_TUNNEL);
12929         if (ret < 0) {
12930                 printf("E-tag filter is not supported on port %u.\n",
12931                        res->port_id);
12932                 return;
12933         }
12934
12935         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12936         entry.tunnel_id = res->e_tag_id_val;
12937         entry.pool = res->dst_pool_val;
12938
12939         ret = rte_eth_dev_filter_ctrl(res->port_id,
12940                                       RTE_ETH_FILTER_L2_TUNNEL,
12941                                       RTE_ETH_FILTER_ADD,
12942                                       &entry);
12943         if (ret < 0)
12944                 printf("E-tag filter programming error: (%s)\n",
12945                        strerror(-ret));
12946 }
12947
12948 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12949         .f = cmd_config_e_tag_filter_add_parsed,
12950         .data = NULL,
12951         .help_str = "E-tag ... : E-tag filter add",
12952         .tokens = {
12953                 (void *)&cmd_config_e_tag_e_tag,
12954                 (void *)&cmd_config_e_tag_set,
12955                 (void *)&cmd_config_e_tag_filter,
12956                 (void *)&cmd_config_e_tag_add,
12957                 (void *)&cmd_config_e_tag_e_tag_id,
12958                 (void *)&cmd_config_e_tag_e_tag_id_val,
12959                 (void *)&cmd_config_e_tag_dst_pool,
12960                 (void *)&cmd_config_e_tag_dst_pool_val,
12961                 (void *)&cmd_config_e_tag_port,
12962                 (void *)&cmd_config_e_tag_port_id,
12963                 NULL,
12964         },
12965 };
12966
12967 static void
12968 cmd_config_e_tag_filter_del_parsed(
12969         void *parsed_result,
12970         __attribute__((unused)) struct cmdline *cl,
12971         __attribute__((unused)) void *data)
12972 {
12973         struct cmd_config_e_tag_result *res = parsed_result;
12974         struct rte_eth_l2_tunnel_conf entry;
12975         int ret = 0;
12976
12977         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12978                 return;
12979
12980         if (res->e_tag_id_val > 0x3fff) {
12981                 printf("e-tag-id must be less than 0x3fff.\n");
12982                 return;
12983         }
12984
12985         ret = rte_eth_dev_filter_supported(res->port_id,
12986                                            RTE_ETH_FILTER_L2_TUNNEL);
12987         if (ret < 0) {
12988                 printf("E-tag filter is not supported on port %u.\n",
12989                        res->port_id);
12990                 return;
12991         }
12992
12993         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12994         entry.tunnel_id = res->e_tag_id_val;
12995
12996         ret = rte_eth_dev_filter_ctrl(res->port_id,
12997                                       RTE_ETH_FILTER_L2_TUNNEL,
12998                                       RTE_ETH_FILTER_DELETE,
12999                                       &entry);
13000         if (ret < 0)
13001                 printf("E-tag filter programming error: (%s)\n",
13002                        strerror(-ret));
13003 }
13004
13005 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13006         .f = cmd_config_e_tag_filter_del_parsed,
13007         .data = NULL,
13008         .help_str = "E-tag ... : E-tag filter delete",
13009         .tokens = {
13010                 (void *)&cmd_config_e_tag_e_tag,
13011                 (void *)&cmd_config_e_tag_set,
13012                 (void *)&cmd_config_e_tag_filter,
13013                 (void *)&cmd_config_e_tag_del,
13014                 (void *)&cmd_config_e_tag_e_tag_id,
13015                 (void *)&cmd_config_e_tag_e_tag_id_val,
13016                 (void *)&cmd_config_e_tag_port,
13017                 (void *)&cmd_config_e_tag_port_id,
13018                 NULL,
13019         },
13020 };
13021
13022 /* vf vlan anti spoof configuration */
13023
13024 /* Common result structure for vf vlan anti spoof */
13025 struct cmd_vf_vlan_anti_spoof_result {
13026         cmdline_fixed_string_t set;
13027         cmdline_fixed_string_t vf;
13028         cmdline_fixed_string_t vlan;
13029         cmdline_fixed_string_t antispoof;
13030         portid_t port_id;
13031         uint32_t vf_id;
13032         cmdline_fixed_string_t on_off;
13033 };
13034
13035 /* Common CLI fields for vf vlan anti spoof enable disable */
13036 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13037         TOKEN_STRING_INITIALIZER
13038                 (struct cmd_vf_vlan_anti_spoof_result,
13039                  set, "set");
13040 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13041         TOKEN_STRING_INITIALIZER
13042                 (struct cmd_vf_vlan_anti_spoof_result,
13043                  vf, "vf");
13044 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13045         TOKEN_STRING_INITIALIZER
13046                 (struct cmd_vf_vlan_anti_spoof_result,
13047                  vlan, "vlan");
13048 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13049         TOKEN_STRING_INITIALIZER
13050                 (struct cmd_vf_vlan_anti_spoof_result,
13051                  antispoof, "antispoof");
13052 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13053         TOKEN_NUM_INITIALIZER
13054                 (struct cmd_vf_vlan_anti_spoof_result,
13055                  port_id, UINT16);
13056 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13057         TOKEN_NUM_INITIALIZER
13058                 (struct cmd_vf_vlan_anti_spoof_result,
13059                  vf_id, UINT32);
13060 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13061         TOKEN_STRING_INITIALIZER
13062                 (struct cmd_vf_vlan_anti_spoof_result,
13063                  on_off, "on#off");
13064
13065 static void
13066 cmd_set_vf_vlan_anti_spoof_parsed(
13067         void *parsed_result,
13068         __attribute__((unused)) struct cmdline *cl,
13069         __attribute__((unused)) void *data)
13070 {
13071         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13072         int ret = -ENOTSUP;
13073
13074         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13075
13076         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13077                 return;
13078
13079 #ifdef RTE_LIBRTE_IXGBE_PMD
13080         if (ret == -ENOTSUP)
13081                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13082                                 res->vf_id, is_on);
13083 #endif
13084 #ifdef RTE_LIBRTE_I40E_PMD
13085         if (ret == -ENOTSUP)
13086                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13087                                 res->vf_id, is_on);
13088 #endif
13089 #ifdef RTE_LIBRTE_BNXT_PMD
13090         if (ret == -ENOTSUP)
13091                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13092                                 res->vf_id, is_on);
13093 #endif
13094
13095         switch (ret) {
13096         case 0:
13097                 break;
13098         case -EINVAL:
13099                 printf("invalid vf_id %d\n", res->vf_id);
13100                 break;
13101         case -ENODEV:
13102                 printf("invalid port_id %d\n", res->port_id);
13103                 break;
13104         case -ENOTSUP:
13105                 printf("function not implemented\n");
13106                 break;
13107         default:
13108                 printf("programming error: (%s)\n", strerror(-ret));
13109         }
13110 }
13111
13112 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13113         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13114         .data = NULL,
13115         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13116         .tokens = {
13117                 (void *)&cmd_vf_vlan_anti_spoof_set,
13118                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13119                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13120                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13121                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13122                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13123                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13124                 NULL,
13125         },
13126 };
13127
13128 /* vf mac anti spoof configuration */
13129
13130 /* Common result structure for vf mac anti spoof */
13131 struct cmd_vf_mac_anti_spoof_result {
13132         cmdline_fixed_string_t set;
13133         cmdline_fixed_string_t vf;
13134         cmdline_fixed_string_t mac;
13135         cmdline_fixed_string_t antispoof;
13136         portid_t port_id;
13137         uint32_t vf_id;
13138         cmdline_fixed_string_t on_off;
13139 };
13140
13141 /* Common CLI fields for vf mac anti spoof enable disable */
13142 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13143         TOKEN_STRING_INITIALIZER
13144                 (struct cmd_vf_mac_anti_spoof_result,
13145                  set, "set");
13146 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13147         TOKEN_STRING_INITIALIZER
13148                 (struct cmd_vf_mac_anti_spoof_result,
13149                  vf, "vf");
13150 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13151         TOKEN_STRING_INITIALIZER
13152                 (struct cmd_vf_mac_anti_spoof_result,
13153                  mac, "mac");
13154 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13155         TOKEN_STRING_INITIALIZER
13156                 (struct cmd_vf_mac_anti_spoof_result,
13157                  antispoof, "antispoof");
13158 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13159         TOKEN_NUM_INITIALIZER
13160                 (struct cmd_vf_mac_anti_spoof_result,
13161                  port_id, UINT16);
13162 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13163         TOKEN_NUM_INITIALIZER
13164                 (struct cmd_vf_mac_anti_spoof_result,
13165                  vf_id, UINT32);
13166 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13167         TOKEN_STRING_INITIALIZER
13168                 (struct cmd_vf_mac_anti_spoof_result,
13169                  on_off, "on#off");
13170
13171 static void
13172 cmd_set_vf_mac_anti_spoof_parsed(
13173         void *parsed_result,
13174         __attribute__((unused)) struct cmdline *cl,
13175         __attribute__((unused)) void *data)
13176 {
13177         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13178         int ret = -ENOTSUP;
13179
13180         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13181
13182         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13183                 return;
13184
13185 #ifdef RTE_LIBRTE_IXGBE_PMD
13186         if (ret == -ENOTSUP)
13187                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13188                         res->vf_id, is_on);
13189 #endif
13190 #ifdef RTE_LIBRTE_I40E_PMD
13191         if (ret == -ENOTSUP)
13192                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13193                         res->vf_id, is_on);
13194 #endif
13195 #ifdef RTE_LIBRTE_BNXT_PMD
13196         if (ret == -ENOTSUP)
13197                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13198                         res->vf_id, is_on);
13199 #endif
13200
13201         switch (ret) {
13202         case 0:
13203                 break;
13204         case -EINVAL:
13205                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13206                 break;
13207         case -ENODEV:
13208                 printf("invalid port_id %d\n", res->port_id);
13209                 break;
13210         case -ENOTSUP:
13211                 printf("function not implemented\n");
13212                 break;
13213         default:
13214                 printf("programming error: (%s)\n", strerror(-ret));
13215         }
13216 }
13217
13218 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13219         .f = cmd_set_vf_mac_anti_spoof_parsed,
13220         .data = NULL,
13221         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13222         .tokens = {
13223                 (void *)&cmd_vf_mac_anti_spoof_set,
13224                 (void *)&cmd_vf_mac_anti_spoof_vf,
13225                 (void *)&cmd_vf_mac_anti_spoof_mac,
13226                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13227                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13228                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13229                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13230                 NULL,
13231         },
13232 };
13233
13234 /* vf vlan strip queue configuration */
13235
13236 /* Common result structure for vf mac anti spoof */
13237 struct cmd_vf_vlan_stripq_result {
13238         cmdline_fixed_string_t set;
13239         cmdline_fixed_string_t vf;
13240         cmdline_fixed_string_t vlan;
13241         cmdline_fixed_string_t stripq;
13242         portid_t port_id;
13243         uint16_t vf_id;
13244         cmdline_fixed_string_t on_off;
13245 };
13246
13247 /* Common CLI fields for vf vlan strip enable disable */
13248 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13249         TOKEN_STRING_INITIALIZER
13250                 (struct cmd_vf_vlan_stripq_result,
13251                  set, "set");
13252 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13253         TOKEN_STRING_INITIALIZER
13254                 (struct cmd_vf_vlan_stripq_result,
13255                  vf, "vf");
13256 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13257         TOKEN_STRING_INITIALIZER
13258                 (struct cmd_vf_vlan_stripq_result,
13259                  vlan, "vlan");
13260 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13261         TOKEN_STRING_INITIALIZER
13262                 (struct cmd_vf_vlan_stripq_result,
13263                  stripq, "stripq");
13264 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13265         TOKEN_NUM_INITIALIZER
13266                 (struct cmd_vf_vlan_stripq_result,
13267                  port_id, UINT16);
13268 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13269         TOKEN_NUM_INITIALIZER
13270                 (struct cmd_vf_vlan_stripq_result,
13271                  vf_id, UINT16);
13272 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13273         TOKEN_STRING_INITIALIZER
13274                 (struct cmd_vf_vlan_stripq_result,
13275                  on_off, "on#off");
13276
13277 static void
13278 cmd_set_vf_vlan_stripq_parsed(
13279         void *parsed_result,
13280         __attribute__((unused)) struct cmdline *cl,
13281         __attribute__((unused)) void *data)
13282 {
13283         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13284         int ret = -ENOTSUP;
13285
13286         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13287
13288         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13289                 return;
13290
13291 #ifdef RTE_LIBRTE_IXGBE_PMD
13292         if (ret == -ENOTSUP)
13293                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13294                         res->vf_id, is_on);
13295 #endif
13296 #ifdef RTE_LIBRTE_I40E_PMD
13297         if (ret == -ENOTSUP)
13298                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13299                         res->vf_id, is_on);
13300 #endif
13301 #ifdef RTE_LIBRTE_BNXT_PMD
13302         if (ret == -ENOTSUP)
13303                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13304                         res->vf_id, is_on);
13305 #endif
13306
13307         switch (ret) {
13308         case 0:
13309                 break;
13310         case -EINVAL:
13311                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13312                 break;
13313         case -ENODEV:
13314                 printf("invalid port_id %d\n", res->port_id);
13315                 break;
13316         case -ENOTSUP:
13317                 printf("function not implemented\n");
13318                 break;
13319         default:
13320                 printf("programming error: (%s)\n", strerror(-ret));
13321         }
13322 }
13323
13324 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13325         .f = cmd_set_vf_vlan_stripq_parsed,
13326         .data = NULL,
13327         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13328         .tokens = {
13329                 (void *)&cmd_vf_vlan_stripq_set,
13330                 (void *)&cmd_vf_vlan_stripq_vf,
13331                 (void *)&cmd_vf_vlan_stripq_vlan,
13332                 (void *)&cmd_vf_vlan_stripq_stripq,
13333                 (void *)&cmd_vf_vlan_stripq_port_id,
13334                 (void *)&cmd_vf_vlan_stripq_vf_id,
13335                 (void *)&cmd_vf_vlan_stripq_on_off,
13336                 NULL,
13337         },
13338 };
13339
13340 /* vf vlan insert configuration */
13341
13342 /* Common result structure for vf vlan insert */
13343 struct cmd_vf_vlan_insert_result {
13344         cmdline_fixed_string_t set;
13345         cmdline_fixed_string_t vf;
13346         cmdline_fixed_string_t vlan;
13347         cmdline_fixed_string_t insert;
13348         portid_t port_id;
13349         uint16_t vf_id;
13350         uint16_t vlan_id;
13351 };
13352
13353 /* Common CLI fields for vf vlan insert enable disable */
13354 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13355         TOKEN_STRING_INITIALIZER
13356                 (struct cmd_vf_vlan_insert_result,
13357                  set, "set");
13358 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13359         TOKEN_STRING_INITIALIZER
13360                 (struct cmd_vf_vlan_insert_result,
13361                  vf, "vf");
13362 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13363         TOKEN_STRING_INITIALIZER
13364                 (struct cmd_vf_vlan_insert_result,
13365                  vlan, "vlan");
13366 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13367         TOKEN_STRING_INITIALIZER
13368                 (struct cmd_vf_vlan_insert_result,
13369                  insert, "insert");
13370 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13371         TOKEN_NUM_INITIALIZER
13372                 (struct cmd_vf_vlan_insert_result,
13373                  port_id, UINT16);
13374 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13375         TOKEN_NUM_INITIALIZER
13376                 (struct cmd_vf_vlan_insert_result,
13377                  vf_id, UINT16);
13378 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13379         TOKEN_NUM_INITIALIZER
13380                 (struct cmd_vf_vlan_insert_result,
13381                  vlan_id, UINT16);
13382
13383 static void
13384 cmd_set_vf_vlan_insert_parsed(
13385         void *parsed_result,
13386         __attribute__((unused)) struct cmdline *cl,
13387         __attribute__((unused)) void *data)
13388 {
13389         struct cmd_vf_vlan_insert_result *res = parsed_result;
13390         int ret = -ENOTSUP;
13391
13392         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13393                 return;
13394
13395 #ifdef RTE_LIBRTE_IXGBE_PMD
13396         if (ret == -ENOTSUP)
13397                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13398                         res->vlan_id);
13399 #endif
13400 #ifdef RTE_LIBRTE_I40E_PMD
13401         if (ret == -ENOTSUP)
13402                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13403                         res->vlan_id);
13404 #endif
13405 #ifdef RTE_LIBRTE_BNXT_PMD
13406         if (ret == -ENOTSUP)
13407                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13408                         res->vlan_id);
13409 #endif
13410
13411         switch (ret) {
13412         case 0:
13413                 break;
13414         case -EINVAL:
13415                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13416                 break;
13417         case -ENODEV:
13418                 printf("invalid port_id %d\n", res->port_id);
13419                 break;
13420         case -ENOTSUP:
13421                 printf("function not implemented\n");
13422                 break;
13423         default:
13424                 printf("programming error: (%s)\n", strerror(-ret));
13425         }
13426 }
13427
13428 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13429         .f = cmd_set_vf_vlan_insert_parsed,
13430         .data = NULL,
13431         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13432         .tokens = {
13433                 (void *)&cmd_vf_vlan_insert_set,
13434                 (void *)&cmd_vf_vlan_insert_vf,
13435                 (void *)&cmd_vf_vlan_insert_vlan,
13436                 (void *)&cmd_vf_vlan_insert_insert,
13437                 (void *)&cmd_vf_vlan_insert_port_id,
13438                 (void *)&cmd_vf_vlan_insert_vf_id,
13439                 (void *)&cmd_vf_vlan_insert_vlan_id,
13440                 NULL,
13441         },
13442 };
13443
13444 /* tx loopback configuration */
13445
13446 /* Common result structure for tx loopback */
13447 struct cmd_tx_loopback_result {
13448         cmdline_fixed_string_t set;
13449         cmdline_fixed_string_t tx;
13450         cmdline_fixed_string_t loopback;
13451         portid_t port_id;
13452         cmdline_fixed_string_t on_off;
13453 };
13454
13455 /* Common CLI fields for tx loopback enable disable */
13456 cmdline_parse_token_string_t cmd_tx_loopback_set =
13457         TOKEN_STRING_INITIALIZER
13458                 (struct cmd_tx_loopback_result,
13459                  set, "set");
13460 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13461         TOKEN_STRING_INITIALIZER
13462                 (struct cmd_tx_loopback_result,
13463                  tx, "tx");
13464 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13465         TOKEN_STRING_INITIALIZER
13466                 (struct cmd_tx_loopback_result,
13467                  loopback, "loopback");
13468 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13469         TOKEN_NUM_INITIALIZER
13470                 (struct cmd_tx_loopback_result,
13471                  port_id, UINT16);
13472 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13473         TOKEN_STRING_INITIALIZER
13474                 (struct cmd_tx_loopback_result,
13475                  on_off, "on#off");
13476
13477 static void
13478 cmd_set_tx_loopback_parsed(
13479         void *parsed_result,
13480         __attribute__((unused)) struct cmdline *cl,
13481         __attribute__((unused)) void *data)
13482 {
13483         struct cmd_tx_loopback_result *res = parsed_result;
13484         int ret = -ENOTSUP;
13485
13486         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13487
13488         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13489                 return;
13490
13491 #ifdef RTE_LIBRTE_IXGBE_PMD
13492         if (ret == -ENOTSUP)
13493                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13494 #endif
13495 #ifdef RTE_LIBRTE_I40E_PMD
13496         if (ret == -ENOTSUP)
13497                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13498 #endif
13499 #ifdef RTE_LIBRTE_BNXT_PMD
13500         if (ret == -ENOTSUP)
13501                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13502 #endif
13503 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13504         if (ret == -ENOTSUP)
13505                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13506 #endif
13507
13508         switch (ret) {
13509         case 0:
13510                 break;
13511         case -EINVAL:
13512                 printf("invalid is_on %d\n", is_on);
13513                 break;
13514         case -ENODEV:
13515                 printf("invalid port_id %d\n", res->port_id);
13516                 break;
13517         case -ENOTSUP:
13518                 printf("function not implemented\n");
13519                 break;
13520         default:
13521                 printf("programming error: (%s)\n", strerror(-ret));
13522         }
13523 }
13524
13525 cmdline_parse_inst_t cmd_set_tx_loopback = {
13526         .f = cmd_set_tx_loopback_parsed,
13527         .data = NULL,
13528         .help_str = "set tx loopback <port_id> on|off",
13529         .tokens = {
13530                 (void *)&cmd_tx_loopback_set,
13531                 (void *)&cmd_tx_loopback_tx,
13532                 (void *)&cmd_tx_loopback_loopback,
13533                 (void *)&cmd_tx_loopback_port_id,
13534                 (void *)&cmd_tx_loopback_on_off,
13535                 NULL,
13536         },
13537 };
13538
13539 /* all queues drop enable configuration */
13540
13541 /* Common result structure for all queues drop enable */
13542 struct cmd_all_queues_drop_en_result {
13543         cmdline_fixed_string_t set;
13544         cmdline_fixed_string_t all;
13545         cmdline_fixed_string_t queues;
13546         cmdline_fixed_string_t drop;
13547         portid_t port_id;
13548         cmdline_fixed_string_t on_off;
13549 };
13550
13551 /* Common CLI fields for tx loopback enable disable */
13552 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13553         TOKEN_STRING_INITIALIZER
13554                 (struct cmd_all_queues_drop_en_result,
13555                  set, "set");
13556 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13557         TOKEN_STRING_INITIALIZER
13558                 (struct cmd_all_queues_drop_en_result,
13559                  all, "all");
13560 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13561         TOKEN_STRING_INITIALIZER
13562                 (struct cmd_all_queues_drop_en_result,
13563                  queues, "queues");
13564 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13565         TOKEN_STRING_INITIALIZER
13566                 (struct cmd_all_queues_drop_en_result,
13567                  drop, "drop");
13568 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13569         TOKEN_NUM_INITIALIZER
13570                 (struct cmd_all_queues_drop_en_result,
13571                  port_id, UINT16);
13572 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13573         TOKEN_STRING_INITIALIZER
13574                 (struct cmd_all_queues_drop_en_result,
13575                  on_off, "on#off");
13576
13577 static void
13578 cmd_set_all_queues_drop_en_parsed(
13579         void *parsed_result,
13580         __attribute__((unused)) struct cmdline *cl,
13581         __attribute__((unused)) void *data)
13582 {
13583         struct cmd_all_queues_drop_en_result *res = parsed_result;
13584         int ret = -ENOTSUP;
13585         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13586
13587         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13588                 return;
13589
13590 #ifdef RTE_LIBRTE_IXGBE_PMD
13591         if (ret == -ENOTSUP)
13592                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13593 #endif
13594 #ifdef RTE_LIBRTE_BNXT_PMD
13595         if (ret == -ENOTSUP)
13596                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13597 #endif
13598         switch (ret) {
13599         case 0:
13600                 break;
13601         case -EINVAL:
13602                 printf("invalid is_on %d\n", is_on);
13603                 break;
13604         case -ENODEV:
13605                 printf("invalid port_id %d\n", res->port_id);
13606                 break;
13607         case -ENOTSUP:
13608                 printf("function not implemented\n");
13609                 break;
13610         default:
13611                 printf("programming error: (%s)\n", strerror(-ret));
13612         }
13613 }
13614
13615 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13616         .f = cmd_set_all_queues_drop_en_parsed,
13617         .data = NULL,
13618         .help_str = "set all queues drop <port_id> on|off",
13619         .tokens = {
13620                 (void *)&cmd_all_queues_drop_en_set,
13621                 (void *)&cmd_all_queues_drop_en_all,
13622                 (void *)&cmd_all_queues_drop_en_queues,
13623                 (void *)&cmd_all_queues_drop_en_drop,
13624                 (void *)&cmd_all_queues_drop_en_port_id,
13625                 (void *)&cmd_all_queues_drop_en_on_off,
13626                 NULL,
13627         },
13628 };
13629
13630 /* vf split drop enable configuration */
13631
13632 /* Common result structure for vf split drop enable */
13633 struct cmd_vf_split_drop_en_result {
13634         cmdline_fixed_string_t set;
13635         cmdline_fixed_string_t vf;
13636         cmdline_fixed_string_t split;
13637         cmdline_fixed_string_t drop;
13638         portid_t port_id;
13639         uint16_t vf_id;
13640         cmdline_fixed_string_t on_off;
13641 };
13642
13643 /* Common CLI fields for vf split drop enable disable */
13644 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13645         TOKEN_STRING_INITIALIZER
13646                 (struct cmd_vf_split_drop_en_result,
13647                  set, "set");
13648 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13649         TOKEN_STRING_INITIALIZER
13650                 (struct cmd_vf_split_drop_en_result,
13651                  vf, "vf");
13652 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13653         TOKEN_STRING_INITIALIZER
13654                 (struct cmd_vf_split_drop_en_result,
13655                  split, "split");
13656 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13657         TOKEN_STRING_INITIALIZER
13658                 (struct cmd_vf_split_drop_en_result,
13659                  drop, "drop");
13660 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13661         TOKEN_NUM_INITIALIZER
13662                 (struct cmd_vf_split_drop_en_result,
13663                  port_id, UINT16);
13664 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13665         TOKEN_NUM_INITIALIZER
13666                 (struct cmd_vf_split_drop_en_result,
13667                  vf_id, UINT16);
13668 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13669         TOKEN_STRING_INITIALIZER
13670                 (struct cmd_vf_split_drop_en_result,
13671                  on_off, "on#off");
13672
13673 static void
13674 cmd_set_vf_split_drop_en_parsed(
13675         void *parsed_result,
13676         __attribute__((unused)) struct cmdline *cl,
13677         __attribute__((unused)) void *data)
13678 {
13679         struct cmd_vf_split_drop_en_result *res = parsed_result;
13680         int ret = -ENOTSUP;
13681         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13682
13683         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13684                 return;
13685
13686 #ifdef RTE_LIBRTE_IXGBE_PMD
13687         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13688                         is_on);
13689 #endif
13690         switch (ret) {
13691         case 0:
13692                 break;
13693         case -EINVAL:
13694                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13695                 break;
13696         case -ENODEV:
13697                 printf("invalid port_id %d\n", res->port_id);
13698                 break;
13699         case -ENOTSUP:
13700                 printf("not supported on port %d\n", res->port_id);
13701                 break;
13702         default:
13703                 printf("programming error: (%s)\n", strerror(-ret));
13704         }
13705 }
13706
13707 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13708         .f = cmd_set_vf_split_drop_en_parsed,
13709         .data = NULL,
13710         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13711         .tokens = {
13712                 (void *)&cmd_vf_split_drop_en_set,
13713                 (void *)&cmd_vf_split_drop_en_vf,
13714                 (void *)&cmd_vf_split_drop_en_split,
13715                 (void *)&cmd_vf_split_drop_en_drop,
13716                 (void *)&cmd_vf_split_drop_en_port_id,
13717                 (void *)&cmd_vf_split_drop_en_vf_id,
13718                 (void *)&cmd_vf_split_drop_en_on_off,
13719                 NULL,
13720         },
13721 };
13722
13723 /* vf mac address configuration */
13724
13725 /* Common result structure for vf mac address */
13726 struct cmd_set_vf_mac_addr_result {
13727         cmdline_fixed_string_t set;
13728         cmdline_fixed_string_t vf;
13729         cmdline_fixed_string_t mac;
13730         cmdline_fixed_string_t addr;
13731         portid_t port_id;
13732         uint16_t vf_id;
13733         struct ether_addr mac_addr;
13734
13735 };
13736
13737 /* Common CLI fields for vf split drop enable disable */
13738 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13739         TOKEN_STRING_INITIALIZER
13740                 (struct cmd_set_vf_mac_addr_result,
13741                  set, "set");
13742 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13743         TOKEN_STRING_INITIALIZER
13744                 (struct cmd_set_vf_mac_addr_result,
13745                  vf, "vf");
13746 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13747         TOKEN_STRING_INITIALIZER
13748                 (struct cmd_set_vf_mac_addr_result,
13749                  mac, "mac");
13750 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13751         TOKEN_STRING_INITIALIZER
13752                 (struct cmd_set_vf_mac_addr_result,
13753                  addr, "addr");
13754 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13755         TOKEN_NUM_INITIALIZER
13756                 (struct cmd_set_vf_mac_addr_result,
13757                  port_id, UINT16);
13758 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13759         TOKEN_NUM_INITIALIZER
13760                 (struct cmd_set_vf_mac_addr_result,
13761                  vf_id, UINT16);
13762 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13763         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13764                  mac_addr);
13765
13766 static void
13767 cmd_set_vf_mac_addr_parsed(
13768         void *parsed_result,
13769         __attribute__((unused)) struct cmdline *cl,
13770         __attribute__((unused)) void *data)
13771 {
13772         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13773         int ret = -ENOTSUP;
13774
13775         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13776                 return;
13777
13778 #ifdef RTE_LIBRTE_IXGBE_PMD
13779         if (ret == -ENOTSUP)
13780                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13781                                 &res->mac_addr);
13782 #endif
13783 #ifdef RTE_LIBRTE_I40E_PMD
13784         if (ret == -ENOTSUP)
13785                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13786                                 &res->mac_addr);
13787 #endif
13788 #ifdef RTE_LIBRTE_BNXT_PMD
13789         if (ret == -ENOTSUP)
13790                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13791                                 &res->mac_addr);
13792 #endif
13793
13794         switch (ret) {
13795         case 0:
13796                 break;
13797         case -EINVAL:
13798                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13799                 break;
13800         case -ENODEV:
13801                 printf("invalid port_id %d\n", res->port_id);
13802                 break;
13803         case -ENOTSUP:
13804                 printf("function not implemented\n");
13805                 break;
13806         default:
13807                 printf("programming error: (%s)\n", strerror(-ret));
13808         }
13809 }
13810
13811 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13812         .f = cmd_set_vf_mac_addr_parsed,
13813         .data = NULL,
13814         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13815         .tokens = {
13816                 (void *)&cmd_set_vf_mac_addr_set,
13817                 (void *)&cmd_set_vf_mac_addr_vf,
13818                 (void *)&cmd_set_vf_mac_addr_mac,
13819                 (void *)&cmd_set_vf_mac_addr_addr,
13820                 (void *)&cmd_set_vf_mac_addr_port_id,
13821                 (void *)&cmd_set_vf_mac_addr_vf_id,
13822                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13823                 NULL,
13824         },
13825 };
13826
13827 /* MACsec configuration */
13828
13829 /* Common result structure for MACsec offload enable */
13830 struct cmd_macsec_offload_on_result {
13831         cmdline_fixed_string_t set;
13832         cmdline_fixed_string_t macsec;
13833         cmdline_fixed_string_t offload;
13834         portid_t port_id;
13835         cmdline_fixed_string_t on;
13836         cmdline_fixed_string_t encrypt;
13837         cmdline_fixed_string_t en_on_off;
13838         cmdline_fixed_string_t replay_protect;
13839         cmdline_fixed_string_t rp_on_off;
13840 };
13841
13842 /* Common CLI fields for MACsec offload disable */
13843 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13844         TOKEN_STRING_INITIALIZER
13845                 (struct cmd_macsec_offload_on_result,
13846                  set, "set");
13847 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13848         TOKEN_STRING_INITIALIZER
13849                 (struct cmd_macsec_offload_on_result,
13850                  macsec, "macsec");
13851 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13852         TOKEN_STRING_INITIALIZER
13853                 (struct cmd_macsec_offload_on_result,
13854                  offload, "offload");
13855 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13856         TOKEN_NUM_INITIALIZER
13857                 (struct cmd_macsec_offload_on_result,
13858                  port_id, UINT16);
13859 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13860         TOKEN_STRING_INITIALIZER
13861                 (struct cmd_macsec_offload_on_result,
13862                  on, "on");
13863 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13864         TOKEN_STRING_INITIALIZER
13865                 (struct cmd_macsec_offload_on_result,
13866                  encrypt, "encrypt");
13867 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13868         TOKEN_STRING_INITIALIZER
13869                 (struct cmd_macsec_offload_on_result,
13870                  en_on_off, "on#off");
13871 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13872         TOKEN_STRING_INITIALIZER
13873                 (struct cmd_macsec_offload_on_result,
13874                  replay_protect, "replay-protect");
13875 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13876         TOKEN_STRING_INITIALIZER
13877                 (struct cmd_macsec_offload_on_result,
13878                  rp_on_off, "on#off");
13879
13880 static void
13881 cmd_set_macsec_offload_on_parsed(
13882         void *parsed_result,
13883         __attribute__((unused)) struct cmdline *cl,
13884         __attribute__((unused)) void *data)
13885 {
13886         struct cmd_macsec_offload_on_result *res = parsed_result;
13887         int ret = -ENOTSUP;
13888         portid_t port_id = res->port_id;
13889         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13890         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13891         struct rte_eth_dev_info dev_info;
13892
13893         if (port_id_is_invalid(port_id, ENABLED_WARN))
13894                 return;
13895         if (!port_is_stopped(port_id)) {
13896                 printf("Please stop port %d first\n", port_id);
13897                 return;
13898         }
13899
13900         rte_eth_dev_info_get(port_id, &dev_info);
13901         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13902 #ifdef RTE_LIBRTE_IXGBE_PMD
13903                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13904 #endif
13905         }
13906         RTE_SET_USED(en);
13907         RTE_SET_USED(rp);
13908
13909         switch (ret) {
13910         case 0:
13911                 ports[port_id].dev_conf.txmode.offloads |=
13912                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13913                 cmd_reconfig_device_queue(port_id, 1, 1);
13914                 break;
13915         case -ENODEV:
13916                 printf("invalid port_id %d\n", port_id);
13917                 break;
13918         case -ENOTSUP:
13919                 printf("not supported on port %d\n", port_id);
13920                 break;
13921         default:
13922                 printf("programming error: (%s)\n", strerror(-ret));
13923         }
13924 }
13925
13926 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13927         .f = cmd_set_macsec_offload_on_parsed,
13928         .data = NULL,
13929         .help_str = "set macsec offload <port_id> on "
13930                 "encrypt on|off replay-protect on|off",
13931         .tokens = {
13932                 (void *)&cmd_macsec_offload_on_set,
13933                 (void *)&cmd_macsec_offload_on_macsec,
13934                 (void *)&cmd_macsec_offload_on_offload,
13935                 (void *)&cmd_macsec_offload_on_port_id,
13936                 (void *)&cmd_macsec_offload_on_on,
13937                 (void *)&cmd_macsec_offload_on_encrypt,
13938                 (void *)&cmd_macsec_offload_on_en_on_off,
13939                 (void *)&cmd_macsec_offload_on_replay_protect,
13940                 (void *)&cmd_macsec_offload_on_rp_on_off,
13941                 NULL,
13942         },
13943 };
13944
13945 /* Common result structure for MACsec offload disable */
13946 struct cmd_macsec_offload_off_result {
13947         cmdline_fixed_string_t set;
13948         cmdline_fixed_string_t macsec;
13949         cmdline_fixed_string_t offload;
13950         portid_t port_id;
13951         cmdline_fixed_string_t off;
13952 };
13953
13954 /* Common CLI fields for MACsec offload disable */
13955 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13956         TOKEN_STRING_INITIALIZER
13957                 (struct cmd_macsec_offload_off_result,
13958                  set, "set");
13959 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13960         TOKEN_STRING_INITIALIZER
13961                 (struct cmd_macsec_offload_off_result,
13962                  macsec, "macsec");
13963 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13964         TOKEN_STRING_INITIALIZER
13965                 (struct cmd_macsec_offload_off_result,
13966                  offload, "offload");
13967 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13968         TOKEN_NUM_INITIALIZER
13969                 (struct cmd_macsec_offload_off_result,
13970                  port_id, UINT16);
13971 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13972         TOKEN_STRING_INITIALIZER
13973                 (struct cmd_macsec_offload_off_result,
13974                  off, "off");
13975
13976 static void
13977 cmd_set_macsec_offload_off_parsed(
13978         void *parsed_result,
13979         __attribute__((unused)) struct cmdline *cl,
13980         __attribute__((unused)) void *data)
13981 {
13982         struct cmd_macsec_offload_off_result *res = parsed_result;
13983         int ret = -ENOTSUP;
13984         struct rte_eth_dev_info dev_info;
13985         portid_t port_id = res->port_id;
13986
13987         if (port_id_is_invalid(port_id, ENABLED_WARN))
13988                 return;
13989         if (!port_is_stopped(port_id)) {
13990                 printf("Please stop port %d first\n", port_id);
13991                 return;
13992         }
13993
13994         rte_eth_dev_info_get(port_id, &dev_info);
13995         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13996 #ifdef RTE_LIBRTE_IXGBE_PMD
13997                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13998 #endif
13999         }
14000         switch (ret) {
14001         case 0:
14002                 ports[port_id].dev_conf.txmode.offloads &=
14003                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14004                 cmd_reconfig_device_queue(port_id, 1, 1);
14005                 break;
14006         case -ENODEV:
14007                 printf("invalid port_id %d\n", port_id);
14008                 break;
14009         case -ENOTSUP:
14010                 printf("not supported on port %d\n", port_id);
14011                 break;
14012         default:
14013                 printf("programming error: (%s)\n", strerror(-ret));
14014         }
14015 }
14016
14017 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14018         .f = cmd_set_macsec_offload_off_parsed,
14019         .data = NULL,
14020         .help_str = "set macsec offload <port_id> off",
14021         .tokens = {
14022                 (void *)&cmd_macsec_offload_off_set,
14023                 (void *)&cmd_macsec_offload_off_macsec,
14024                 (void *)&cmd_macsec_offload_off_offload,
14025                 (void *)&cmd_macsec_offload_off_port_id,
14026                 (void *)&cmd_macsec_offload_off_off,
14027                 NULL,
14028         },
14029 };
14030
14031 /* Common result structure for MACsec secure connection configure */
14032 struct cmd_macsec_sc_result {
14033         cmdline_fixed_string_t set;
14034         cmdline_fixed_string_t macsec;
14035         cmdline_fixed_string_t sc;
14036         cmdline_fixed_string_t tx_rx;
14037         portid_t port_id;
14038         struct ether_addr mac;
14039         uint16_t pi;
14040 };
14041
14042 /* Common CLI fields for MACsec secure connection configure */
14043 cmdline_parse_token_string_t cmd_macsec_sc_set =
14044         TOKEN_STRING_INITIALIZER
14045                 (struct cmd_macsec_sc_result,
14046                  set, "set");
14047 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14048         TOKEN_STRING_INITIALIZER
14049                 (struct cmd_macsec_sc_result,
14050                  macsec, "macsec");
14051 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14052         TOKEN_STRING_INITIALIZER
14053                 (struct cmd_macsec_sc_result,
14054                  sc, "sc");
14055 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14056         TOKEN_STRING_INITIALIZER
14057                 (struct cmd_macsec_sc_result,
14058                  tx_rx, "tx#rx");
14059 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14060         TOKEN_NUM_INITIALIZER
14061                 (struct cmd_macsec_sc_result,
14062                  port_id, UINT16);
14063 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14064         TOKEN_ETHERADDR_INITIALIZER
14065                 (struct cmd_macsec_sc_result,
14066                  mac);
14067 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14068         TOKEN_NUM_INITIALIZER
14069                 (struct cmd_macsec_sc_result,
14070                  pi, UINT16);
14071
14072 static void
14073 cmd_set_macsec_sc_parsed(
14074         void *parsed_result,
14075         __attribute__((unused)) struct cmdline *cl,
14076         __attribute__((unused)) void *data)
14077 {
14078         struct cmd_macsec_sc_result *res = parsed_result;
14079         int ret = -ENOTSUP;
14080         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14081
14082 #ifdef RTE_LIBRTE_IXGBE_PMD
14083         ret = is_tx ?
14084                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14085                                 res->mac.addr_bytes) :
14086                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14087                                 res->mac.addr_bytes, res->pi);
14088 #endif
14089         RTE_SET_USED(is_tx);
14090
14091         switch (ret) {
14092         case 0:
14093                 break;
14094         case -ENODEV:
14095                 printf("invalid port_id %d\n", res->port_id);
14096                 break;
14097         case -ENOTSUP:
14098                 printf("not supported on port %d\n", res->port_id);
14099                 break;
14100         default:
14101                 printf("programming error: (%s)\n", strerror(-ret));
14102         }
14103 }
14104
14105 cmdline_parse_inst_t cmd_set_macsec_sc = {
14106         .f = cmd_set_macsec_sc_parsed,
14107         .data = NULL,
14108         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14109         .tokens = {
14110                 (void *)&cmd_macsec_sc_set,
14111                 (void *)&cmd_macsec_sc_macsec,
14112                 (void *)&cmd_macsec_sc_sc,
14113                 (void *)&cmd_macsec_sc_tx_rx,
14114                 (void *)&cmd_macsec_sc_port_id,
14115                 (void *)&cmd_macsec_sc_mac,
14116                 (void *)&cmd_macsec_sc_pi,
14117                 NULL,
14118         },
14119 };
14120
14121 /* Common result structure for MACsec secure connection configure */
14122 struct cmd_macsec_sa_result {
14123         cmdline_fixed_string_t set;
14124         cmdline_fixed_string_t macsec;
14125         cmdline_fixed_string_t sa;
14126         cmdline_fixed_string_t tx_rx;
14127         portid_t port_id;
14128         uint8_t idx;
14129         uint8_t an;
14130         uint32_t pn;
14131         cmdline_fixed_string_t key;
14132 };
14133
14134 /* Common CLI fields for MACsec secure connection configure */
14135 cmdline_parse_token_string_t cmd_macsec_sa_set =
14136         TOKEN_STRING_INITIALIZER
14137                 (struct cmd_macsec_sa_result,
14138                  set, "set");
14139 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14140         TOKEN_STRING_INITIALIZER
14141                 (struct cmd_macsec_sa_result,
14142                  macsec, "macsec");
14143 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14144         TOKEN_STRING_INITIALIZER
14145                 (struct cmd_macsec_sa_result,
14146                  sa, "sa");
14147 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14148         TOKEN_STRING_INITIALIZER
14149                 (struct cmd_macsec_sa_result,
14150                  tx_rx, "tx#rx");
14151 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14152         TOKEN_NUM_INITIALIZER
14153                 (struct cmd_macsec_sa_result,
14154                  port_id, UINT16);
14155 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14156         TOKEN_NUM_INITIALIZER
14157                 (struct cmd_macsec_sa_result,
14158                  idx, UINT8);
14159 cmdline_parse_token_num_t cmd_macsec_sa_an =
14160         TOKEN_NUM_INITIALIZER
14161                 (struct cmd_macsec_sa_result,
14162                  an, UINT8);
14163 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14164         TOKEN_NUM_INITIALIZER
14165                 (struct cmd_macsec_sa_result,
14166                  pn, UINT32);
14167 cmdline_parse_token_string_t cmd_macsec_sa_key =
14168         TOKEN_STRING_INITIALIZER
14169                 (struct cmd_macsec_sa_result,
14170                  key, NULL);
14171
14172 static void
14173 cmd_set_macsec_sa_parsed(
14174         void *parsed_result,
14175         __attribute__((unused)) struct cmdline *cl,
14176         __attribute__((unused)) void *data)
14177 {
14178         struct cmd_macsec_sa_result *res = parsed_result;
14179         int ret = -ENOTSUP;
14180         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14181         uint8_t key[16] = { 0 };
14182         uint8_t xdgt0;
14183         uint8_t xdgt1;
14184         int key_len;
14185         int i;
14186
14187         key_len = strlen(res->key) / 2;
14188         if (key_len > 16)
14189                 key_len = 16;
14190
14191         for (i = 0; i < key_len; i++) {
14192                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14193                 if (xdgt0 == 0xFF)
14194                         return;
14195                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14196                 if (xdgt1 == 0xFF)
14197                         return;
14198                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14199         }
14200
14201 #ifdef RTE_LIBRTE_IXGBE_PMD
14202         ret = is_tx ?
14203                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14204                         res->idx, res->an, res->pn, key) :
14205                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14206                         res->idx, res->an, res->pn, key);
14207 #endif
14208         RTE_SET_USED(is_tx);
14209         RTE_SET_USED(key);
14210
14211         switch (ret) {
14212         case 0:
14213                 break;
14214         case -EINVAL:
14215                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14216                 break;
14217         case -ENODEV:
14218                 printf("invalid port_id %d\n", res->port_id);
14219                 break;
14220         case -ENOTSUP:
14221                 printf("not supported on port %d\n", res->port_id);
14222                 break;
14223         default:
14224                 printf("programming error: (%s)\n", strerror(-ret));
14225         }
14226 }
14227
14228 cmdline_parse_inst_t cmd_set_macsec_sa = {
14229         .f = cmd_set_macsec_sa_parsed,
14230         .data = NULL,
14231         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14232         .tokens = {
14233                 (void *)&cmd_macsec_sa_set,
14234                 (void *)&cmd_macsec_sa_macsec,
14235                 (void *)&cmd_macsec_sa_sa,
14236                 (void *)&cmd_macsec_sa_tx_rx,
14237                 (void *)&cmd_macsec_sa_port_id,
14238                 (void *)&cmd_macsec_sa_idx,
14239                 (void *)&cmd_macsec_sa_an,
14240                 (void *)&cmd_macsec_sa_pn,
14241                 (void *)&cmd_macsec_sa_key,
14242                 NULL,
14243         },
14244 };
14245
14246 /* VF unicast promiscuous mode configuration */
14247
14248 /* Common result structure for VF unicast promiscuous mode */
14249 struct cmd_vf_promisc_result {
14250         cmdline_fixed_string_t set;
14251         cmdline_fixed_string_t vf;
14252         cmdline_fixed_string_t promisc;
14253         portid_t port_id;
14254         uint32_t vf_id;
14255         cmdline_fixed_string_t on_off;
14256 };
14257
14258 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14259 cmdline_parse_token_string_t cmd_vf_promisc_set =
14260         TOKEN_STRING_INITIALIZER
14261                 (struct cmd_vf_promisc_result,
14262                  set, "set");
14263 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14264         TOKEN_STRING_INITIALIZER
14265                 (struct cmd_vf_promisc_result,
14266                  vf, "vf");
14267 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14268         TOKEN_STRING_INITIALIZER
14269                 (struct cmd_vf_promisc_result,
14270                  promisc, "promisc");
14271 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14272         TOKEN_NUM_INITIALIZER
14273                 (struct cmd_vf_promisc_result,
14274                  port_id, UINT16);
14275 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14276         TOKEN_NUM_INITIALIZER
14277                 (struct cmd_vf_promisc_result,
14278                  vf_id, UINT32);
14279 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14280         TOKEN_STRING_INITIALIZER
14281                 (struct cmd_vf_promisc_result,
14282                  on_off, "on#off");
14283
14284 static void
14285 cmd_set_vf_promisc_parsed(
14286         void *parsed_result,
14287         __attribute__((unused)) struct cmdline *cl,
14288         __attribute__((unused)) void *data)
14289 {
14290         struct cmd_vf_promisc_result *res = parsed_result;
14291         int ret = -ENOTSUP;
14292
14293         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14294
14295         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14296                 return;
14297
14298 #ifdef RTE_LIBRTE_I40E_PMD
14299         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14300                                                   res->vf_id, is_on);
14301 #endif
14302
14303         switch (ret) {
14304         case 0:
14305                 break;
14306         case -EINVAL:
14307                 printf("invalid vf_id %d\n", res->vf_id);
14308                 break;
14309         case -ENODEV:
14310                 printf("invalid port_id %d\n", res->port_id);
14311                 break;
14312         case -ENOTSUP:
14313                 printf("function not implemented\n");
14314                 break;
14315         default:
14316                 printf("programming error: (%s)\n", strerror(-ret));
14317         }
14318 }
14319
14320 cmdline_parse_inst_t cmd_set_vf_promisc = {
14321         .f = cmd_set_vf_promisc_parsed,
14322         .data = NULL,
14323         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14324                 "Set unicast promiscuous mode for a VF from the PF",
14325         .tokens = {
14326                 (void *)&cmd_vf_promisc_set,
14327                 (void *)&cmd_vf_promisc_vf,
14328                 (void *)&cmd_vf_promisc_promisc,
14329                 (void *)&cmd_vf_promisc_port_id,
14330                 (void *)&cmd_vf_promisc_vf_id,
14331                 (void *)&cmd_vf_promisc_on_off,
14332                 NULL,
14333         },
14334 };
14335
14336 /* VF multicast promiscuous mode configuration */
14337
14338 /* Common result structure for VF multicast promiscuous mode */
14339 struct cmd_vf_allmulti_result {
14340         cmdline_fixed_string_t set;
14341         cmdline_fixed_string_t vf;
14342         cmdline_fixed_string_t allmulti;
14343         portid_t port_id;
14344         uint32_t vf_id;
14345         cmdline_fixed_string_t on_off;
14346 };
14347
14348 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14349 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14350         TOKEN_STRING_INITIALIZER
14351                 (struct cmd_vf_allmulti_result,
14352                  set, "set");
14353 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14354         TOKEN_STRING_INITIALIZER
14355                 (struct cmd_vf_allmulti_result,
14356                  vf, "vf");
14357 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14358         TOKEN_STRING_INITIALIZER
14359                 (struct cmd_vf_allmulti_result,
14360                  allmulti, "allmulti");
14361 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14362         TOKEN_NUM_INITIALIZER
14363                 (struct cmd_vf_allmulti_result,
14364                  port_id, UINT16);
14365 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14366         TOKEN_NUM_INITIALIZER
14367                 (struct cmd_vf_allmulti_result,
14368                  vf_id, UINT32);
14369 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14370         TOKEN_STRING_INITIALIZER
14371                 (struct cmd_vf_allmulti_result,
14372                  on_off, "on#off");
14373
14374 static void
14375 cmd_set_vf_allmulti_parsed(
14376         void *parsed_result,
14377         __attribute__((unused)) struct cmdline *cl,
14378         __attribute__((unused)) void *data)
14379 {
14380         struct cmd_vf_allmulti_result *res = parsed_result;
14381         int ret = -ENOTSUP;
14382
14383         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14384
14385         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14386                 return;
14387
14388 #ifdef RTE_LIBRTE_I40E_PMD
14389         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14390                                                     res->vf_id, is_on);
14391 #endif
14392
14393         switch (ret) {
14394         case 0:
14395                 break;
14396         case -EINVAL:
14397                 printf("invalid vf_id %d\n", res->vf_id);
14398                 break;
14399         case -ENODEV:
14400                 printf("invalid port_id %d\n", res->port_id);
14401                 break;
14402         case -ENOTSUP:
14403                 printf("function not implemented\n");
14404                 break;
14405         default:
14406                 printf("programming error: (%s)\n", strerror(-ret));
14407         }
14408 }
14409
14410 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14411         .f = cmd_set_vf_allmulti_parsed,
14412         .data = NULL,
14413         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14414                 "Set multicast promiscuous mode for a VF from the PF",
14415         .tokens = {
14416                 (void *)&cmd_vf_allmulti_set,
14417                 (void *)&cmd_vf_allmulti_vf,
14418                 (void *)&cmd_vf_allmulti_allmulti,
14419                 (void *)&cmd_vf_allmulti_port_id,
14420                 (void *)&cmd_vf_allmulti_vf_id,
14421                 (void *)&cmd_vf_allmulti_on_off,
14422                 NULL,
14423         },
14424 };
14425
14426 /* vf broadcast mode configuration */
14427
14428 /* Common result structure for vf broadcast */
14429 struct cmd_set_vf_broadcast_result {
14430         cmdline_fixed_string_t set;
14431         cmdline_fixed_string_t vf;
14432         cmdline_fixed_string_t broadcast;
14433         portid_t port_id;
14434         uint16_t vf_id;
14435         cmdline_fixed_string_t on_off;
14436 };
14437
14438 /* Common CLI fields for vf broadcast enable disable */
14439 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14440         TOKEN_STRING_INITIALIZER
14441                 (struct cmd_set_vf_broadcast_result,
14442                  set, "set");
14443 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14444         TOKEN_STRING_INITIALIZER
14445                 (struct cmd_set_vf_broadcast_result,
14446                  vf, "vf");
14447 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14448         TOKEN_STRING_INITIALIZER
14449                 (struct cmd_set_vf_broadcast_result,
14450                  broadcast, "broadcast");
14451 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14452         TOKEN_NUM_INITIALIZER
14453                 (struct cmd_set_vf_broadcast_result,
14454                  port_id, UINT16);
14455 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14456         TOKEN_NUM_INITIALIZER
14457                 (struct cmd_set_vf_broadcast_result,
14458                  vf_id, UINT16);
14459 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14460         TOKEN_STRING_INITIALIZER
14461                 (struct cmd_set_vf_broadcast_result,
14462                  on_off, "on#off");
14463
14464 static void
14465 cmd_set_vf_broadcast_parsed(
14466         void *parsed_result,
14467         __attribute__((unused)) struct cmdline *cl,
14468         __attribute__((unused)) void *data)
14469 {
14470         struct cmd_set_vf_broadcast_result *res = parsed_result;
14471         int ret = -ENOTSUP;
14472
14473         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14474
14475         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14476                 return;
14477
14478 #ifdef RTE_LIBRTE_I40E_PMD
14479         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14480                                             res->vf_id, is_on);
14481 #endif
14482
14483         switch (ret) {
14484         case 0:
14485                 break;
14486         case -EINVAL:
14487                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14488                 break;
14489         case -ENODEV:
14490                 printf("invalid port_id %d\n", res->port_id);
14491                 break;
14492         case -ENOTSUP:
14493                 printf("function not implemented\n");
14494                 break;
14495         default:
14496                 printf("programming error: (%s)\n", strerror(-ret));
14497         }
14498 }
14499
14500 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14501         .f = cmd_set_vf_broadcast_parsed,
14502         .data = NULL,
14503         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14504         .tokens = {
14505                 (void *)&cmd_set_vf_broadcast_set,
14506                 (void *)&cmd_set_vf_broadcast_vf,
14507                 (void *)&cmd_set_vf_broadcast_broadcast,
14508                 (void *)&cmd_set_vf_broadcast_port_id,
14509                 (void *)&cmd_set_vf_broadcast_vf_id,
14510                 (void *)&cmd_set_vf_broadcast_on_off,
14511                 NULL,
14512         },
14513 };
14514
14515 /* vf vlan tag configuration */
14516
14517 /* Common result structure for vf vlan tag */
14518 struct cmd_set_vf_vlan_tag_result {
14519         cmdline_fixed_string_t set;
14520         cmdline_fixed_string_t vf;
14521         cmdline_fixed_string_t vlan;
14522         cmdline_fixed_string_t tag;
14523         portid_t port_id;
14524         uint16_t vf_id;
14525         cmdline_fixed_string_t on_off;
14526 };
14527
14528 /* Common CLI fields for vf vlan tag enable disable */
14529 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14530         TOKEN_STRING_INITIALIZER
14531                 (struct cmd_set_vf_vlan_tag_result,
14532                  set, "set");
14533 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14534         TOKEN_STRING_INITIALIZER
14535                 (struct cmd_set_vf_vlan_tag_result,
14536                  vf, "vf");
14537 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14538         TOKEN_STRING_INITIALIZER
14539                 (struct cmd_set_vf_vlan_tag_result,
14540                  vlan, "vlan");
14541 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14542         TOKEN_STRING_INITIALIZER
14543                 (struct cmd_set_vf_vlan_tag_result,
14544                  tag, "tag");
14545 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14546         TOKEN_NUM_INITIALIZER
14547                 (struct cmd_set_vf_vlan_tag_result,
14548                  port_id, UINT16);
14549 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14550         TOKEN_NUM_INITIALIZER
14551                 (struct cmd_set_vf_vlan_tag_result,
14552                  vf_id, UINT16);
14553 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14554         TOKEN_STRING_INITIALIZER
14555                 (struct cmd_set_vf_vlan_tag_result,
14556                  on_off, "on#off");
14557
14558 static void
14559 cmd_set_vf_vlan_tag_parsed(
14560         void *parsed_result,
14561         __attribute__((unused)) struct cmdline *cl,
14562         __attribute__((unused)) void *data)
14563 {
14564         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14565         int ret = -ENOTSUP;
14566
14567         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14568
14569         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14570                 return;
14571
14572 #ifdef RTE_LIBRTE_I40E_PMD
14573         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14574                                            res->vf_id, is_on);
14575 #endif
14576
14577         switch (ret) {
14578         case 0:
14579                 break;
14580         case -EINVAL:
14581                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14582                 break;
14583         case -ENODEV:
14584                 printf("invalid port_id %d\n", res->port_id);
14585                 break;
14586         case -ENOTSUP:
14587                 printf("function not implemented\n");
14588                 break;
14589         default:
14590                 printf("programming error: (%s)\n", strerror(-ret));
14591         }
14592 }
14593
14594 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14595         .f = cmd_set_vf_vlan_tag_parsed,
14596         .data = NULL,
14597         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14598         .tokens = {
14599                 (void *)&cmd_set_vf_vlan_tag_set,
14600                 (void *)&cmd_set_vf_vlan_tag_vf,
14601                 (void *)&cmd_set_vf_vlan_tag_vlan,
14602                 (void *)&cmd_set_vf_vlan_tag_tag,
14603                 (void *)&cmd_set_vf_vlan_tag_port_id,
14604                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14605                 (void *)&cmd_set_vf_vlan_tag_on_off,
14606                 NULL,
14607         },
14608 };
14609
14610 /* Common definition of VF and TC TX bandwidth configuration */
14611 struct cmd_vf_tc_bw_result {
14612         cmdline_fixed_string_t set;
14613         cmdline_fixed_string_t vf;
14614         cmdline_fixed_string_t tc;
14615         cmdline_fixed_string_t tx;
14616         cmdline_fixed_string_t min_bw;
14617         cmdline_fixed_string_t max_bw;
14618         cmdline_fixed_string_t strict_link_prio;
14619         portid_t port_id;
14620         uint16_t vf_id;
14621         uint8_t tc_no;
14622         uint32_t bw;
14623         cmdline_fixed_string_t bw_list;
14624         uint8_t tc_map;
14625 };
14626
14627 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14628         TOKEN_STRING_INITIALIZER
14629                 (struct cmd_vf_tc_bw_result,
14630                  set, "set");
14631 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14632         TOKEN_STRING_INITIALIZER
14633                 (struct cmd_vf_tc_bw_result,
14634                  vf, "vf");
14635 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14636         TOKEN_STRING_INITIALIZER
14637                 (struct cmd_vf_tc_bw_result,
14638                  tc, "tc");
14639 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14640         TOKEN_STRING_INITIALIZER
14641                 (struct cmd_vf_tc_bw_result,
14642                  tx, "tx");
14643 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14644         TOKEN_STRING_INITIALIZER
14645                 (struct cmd_vf_tc_bw_result,
14646                  strict_link_prio, "strict-link-priority");
14647 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14648         TOKEN_STRING_INITIALIZER
14649                 (struct cmd_vf_tc_bw_result,
14650                  min_bw, "min-bandwidth");
14651 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14652         TOKEN_STRING_INITIALIZER
14653                 (struct cmd_vf_tc_bw_result,
14654                  max_bw, "max-bandwidth");
14655 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14656         TOKEN_NUM_INITIALIZER
14657                 (struct cmd_vf_tc_bw_result,
14658                  port_id, UINT16);
14659 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14660         TOKEN_NUM_INITIALIZER
14661                 (struct cmd_vf_tc_bw_result,
14662                  vf_id, UINT16);
14663 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14664         TOKEN_NUM_INITIALIZER
14665                 (struct cmd_vf_tc_bw_result,
14666                  tc_no, UINT8);
14667 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14668         TOKEN_NUM_INITIALIZER
14669                 (struct cmd_vf_tc_bw_result,
14670                  bw, UINT32);
14671 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14672         TOKEN_STRING_INITIALIZER
14673                 (struct cmd_vf_tc_bw_result,
14674                  bw_list, NULL);
14675 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14676         TOKEN_NUM_INITIALIZER
14677                 (struct cmd_vf_tc_bw_result,
14678                  tc_map, UINT8);
14679
14680 /* VF max bandwidth setting */
14681 static void
14682 cmd_vf_max_bw_parsed(
14683         void *parsed_result,
14684         __attribute__((unused)) struct cmdline *cl,
14685         __attribute__((unused)) void *data)
14686 {
14687         struct cmd_vf_tc_bw_result *res = parsed_result;
14688         int ret = -ENOTSUP;
14689
14690         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14691                 return;
14692
14693 #ifdef RTE_LIBRTE_I40E_PMD
14694         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14695                                          res->vf_id, res->bw);
14696 #endif
14697
14698         switch (ret) {
14699         case 0:
14700                 break;
14701         case -EINVAL:
14702                 printf("invalid vf_id %d or bandwidth %d\n",
14703                        res->vf_id, res->bw);
14704                 break;
14705         case -ENODEV:
14706                 printf("invalid port_id %d\n", res->port_id);
14707                 break;
14708         case -ENOTSUP:
14709                 printf("function not implemented\n");
14710                 break;
14711         default:
14712                 printf("programming error: (%s)\n", strerror(-ret));
14713         }
14714 }
14715
14716 cmdline_parse_inst_t cmd_vf_max_bw = {
14717         .f = cmd_vf_max_bw_parsed,
14718         .data = NULL,
14719         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14720         .tokens = {
14721                 (void *)&cmd_vf_tc_bw_set,
14722                 (void *)&cmd_vf_tc_bw_vf,
14723                 (void *)&cmd_vf_tc_bw_tx,
14724                 (void *)&cmd_vf_tc_bw_max_bw,
14725                 (void *)&cmd_vf_tc_bw_port_id,
14726                 (void *)&cmd_vf_tc_bw_vf_id,
14727                 (void *)&cmd_vf_tc_bw_bw,
14728                 NULL,
14729         },
14730 };
14731
14732 static int
14733 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14734                            uint8_t *tc_num,
14735                            char *str)
14736 {
14737         uint32_t size;
14738         const char *p, *p0 = str;
14739         char s[256];
14740         char *end;
14741         char *str_fld[16];
14742         uint16_t i;
14743         int ret;
14744
14745         p = strchr(p0, '(');
14746         if (p == NULL) {
14747                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14748                 return -1;
14749         }
14750         p++;
14751         p0 = strchr(p, ')');
14752         if (p0 == NULL) {
14753                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14754                 return -1;
14755         }
14756         size = p0 - p;
14757         if (size >= sizeof(s)) {
14758                 printf("The string size exceeds the internal buffer size\n");
14759                 return -1;
14760         }
14761         snprintf(s, sizeof(s), "%.*s", size, p);
14762         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14763         if (ret <= 0) {
14764                 printf("Failed to get the bandwidth list. ");
14765                 return -1;
14766         }
14767         *tc_num = ret;
14768         for (i = 0; i < ret; i++)
14769                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14770
14771         return 0;
14772 }
14773
14774 /* TC min bandwidth setting */
14775 static void
14776 cmd_vf_tc_min_bw_parsed(
14777         void *parsed_result,
14778         __attribute__((unused)) struct cmdline *cl,
14779         __attribute__((unused)) void *data)
14780 {
14781         struct cmd_vf_tc_bw_result *res = parsed_result;
14782         uint8_t tc_num;
14783         uint8_t bw[16];
14784         int ret = -ENOTSUP;
14785
14786         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14787                 return;
14788
14789         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14790         if (ret)
14791                 return;
14792
14793 #ifdef RTE_LIBRTE_I40E_PMD
14794         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14795                                               tc_num, bw);
14796 #endif
14797
14798         switch (ret) {
14799         case 0:
14800                 break;
14801         case -EINVAL:
14802                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14803                 break;
14804         case -ENODEV:
14805                 printf("invalid port_id %d\n", res->port_id);
14806                 break;
14807         case -ENOTSUP:
14808                 printf("function not implemented\n");
14809                 break;
14810         default:
14811                 printf("programming error: (%s)\n", strerror(-ret));
14812         }
14813 }
14814
14815 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14816         .f = cmd_vf_tc_min_bw_parsed,
14817         .data = NULL,
14818         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14819                     " <bw1, bw2, ...>",
14820         .tokens = {
14821                 (void *)&cmd_vf_tc_bw_set,
14822                 (void *)&cmd_vf_tc_bw_vf,
14823                 (void *)&cmd_vf_tc_bw_tc,
14824                 (void *)&cmd_vf_tc_bw_tx,
14825                 (void *)&cmd_vf_tc_bw_min_bw,
14826                 (void *)&cmd_vf_tc_bw_port_id,
14827                 (void *)&cmd_vf_tc_bw_vf_id,
14828                 (void *)&cmd_vf_tc_bw_bw_list,
14829                 NULL,
14830         },
14831 };
14832
14833 static void
14834 cmd_tc_min_bw_parsed(
14835         void *parsed_result,
14836         __attribute__((unused)) struct cmdline *cl,
14837         __attribute__((unused)) void *data)
14838 {
14839         struct cmd_vf_tc_bw_result *res = parsed_result;
14840         struct rte_port *port;
14841         uint8_t tc_num;
14842         uint8_t bw[16];
14843         int ret = -ENOTSUP;
14844
14845         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14846                 return;
14847
14848         port = &ports[res->port_id];
14849         /** Check if the port is not started **/
14850         if (port->port_status != RTE_PORT_STOPPED) {
14851                 printf("Please stop port %d first\n", res->port_id);
14852                 return;
14853         }
14854
14855         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14856         if (ret)
14857                 return;
14858
14859 #ifdef RTE_LIBRTE_IXGBE_PMD
14860         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14861 #endif
14862
14863         switch (ret) {
14864         case 0:
14865                 break;
14866         case -EINVAL:
14867                 printf("invalid bandwidth\n");
14868                 break;
14869         case -ENODEV:
14870                 printf("invalid port_id %d\n", res->port_id);
14871                 break;
14872         case -ENOTSUP:
14873                 printf("function not implemented\n");
14874                 break;
14875         default:
14876                 printf("programming error: (%s)\n", strerror(-ret));
14877         }
14878 }
14879
14880 cmdline_parse_inst_t cmd_tc_min_bw = {
14881         .f = cmd_tc_min_bw_parsed,
14882         .data = NULL,
14883         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14884         .tokens = {
14885                 (void *)&cmd_vf_tc_bw_set,
14886                 (void *)&cmd_vf_tc_bw_tc,
14887                 (void *)&cmd_vf_tc_bw_tx,
14888                 (void *)&cmd_vf_tc_bw_min_bw,
14889                 (void *)&cmd_vf_tc_bw_port_id,
14890                 (void *)&cmd_vf_tc_bw_bw_list,
14891                 NULL,
14892         },
14893 };
14894
14895 /* TC max bandwidth setting */
14896 static void
14897 cmd_vf_tc_max_bw_parsed(
14898         void *parsed_result,
14899         __attribute__((unused)) struct cmdline *cl,
14900         __attribute__((unused)) void *data)
14901 {
14902         struct cmd_vf_tc_bw_result *res = parsed_result;
14903         int ret = -ENOTSUP;
14904
14905         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14906                 return;
14907
14908 #ifdef RTE_LIBRTE_I40E_PMD
14909         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14910                                             res->tc_no, res->bw);
14911 #endif
14912
14913         switch (ret) {
14914         case 0:
14915                 break;
14916         case -EINVAL:
14917                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14918                        res->vf_id, res->tc_no, res->bw);
14919                 break;
14920         case -ENODEV:
14921                 printf("invalid port_id %d\n", res->port_id);
14922                 break;
14923         case -ENOTSUP:
14924                 printf("function not implemented\n");
14925                 break;
14926         default:
14927                 printf("programming error: (%s)\n", strerror(-ret));
14928         }
14929 }
14930
14931 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14932         .f = cmd_vf_tc_max_bw_parsed,
14933         .data = NULL,
14934         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14935                     " <bandwidth>",
14936         .tokens = {
14937                 (void *)&cmd_vf_tc_bw_set,
14938                 (void *)&cmd_vf_tc_bw_vf,
14939                 (void *)&cmd_vf_tc_bw_tc,
14940                 (void *)&cmd_vf_tc_bw_tx,
14941                 (void *)&cmd_vf_tc_bw_max_bw,
14942                 (void *)&cmd_vf_tc_bw_port_id,
14943                 (void *)&cmd_vf_tc_bw_vf_id,
14944                 (void *)&cmd_vf_tc_bw_tc_no,
14945                 (void *)&cmd_vf_tc_bw_bw,
14946                 NULL,
14947         },
14948 };
14949
14950
14951 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14952
14953 /* *** Set Port default Traffic Management Hierarchy *** */
14954 struct cmd_set_port_tm_hierarchy_default_result {
14955         cmdline_fixed_string_t set;
14956         cmdline_fixed_string_t port;
14957         cmdline_fixed_string_t tm;
14958         cmdline_fixed_string_t hierarchy;
14959         cmdline_fixed_string_t def;
14960         portid_t port_id;
14961 };
14962
14963 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14964         TOKEN_STRING_INITIALIZER(
14965                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14966 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14967         TOKEN_STRING_INITIALIZER(
14968                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14969 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14970         TOKEN_STRING_INITIALIZER(
14971                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14972 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14973         TOKEN_STRING_INITIALIZER(
14974                 struct cmd_set_port_tm_hierarchy_default_result,
14975                         hierarchy, "hierarchy");
14976 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14977         TOKEN_STRING_INITIALIZER(
14978                 struct cmd_set_port_tm_hierarchy_default_result,
14979                         def, "default");
14980 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14981         TOKEN_NUM_INITIALIZER(
14982                 struct cmd_set_port_tm_hierarchy_default_result,
14983                         port_id, UINT16);
14984
14985 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14986         __attribute__((unused)) struct cmdline *cl,
14987         __attribute__((unused)) void *data)
14988 {
14989         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14990         struct rte_port *p;
14991         portid_t port_id = res->port_id;
14992
14993         if (port_id_is_invalid(port_id, ENABLED_WARN))
14994                 return;
14995
14996         p = &ports[port_id];
14997
14998         /* Forward mode: tm */
14999         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15000                 printf("  softnicfwd mode not enabled(error)\n");
15001                 return;
15002         }
15003
15004         /* Set the default tm hierarchy */
15005         p->softport.default_tm_hierarchy_enable = 1;
15006 }
15007
15008 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15009         .f = cmd_set_port_tm_hierarchy_default_parsed,
15010         .data = NULL,
15011         .help_str = "set port tm hierarchy default <port_id>",
15012         .tokens = {
15013                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15014                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15015                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15016                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15017                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15018                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15019                 NULL,
15020         },
15021 };
15022 #endif
15023
15024 /** Set VXLAN encapsulation details */
15025 struct cmd_set_vxlan_result {
15026         cmdline_fixed_string_t set;
15027         cmdline_fixed_string_t vxlan;
15028         cmdline_fixed_string_t pos_token;
15029         cmdline_fixed_string_t ip_version;
15030         uint32_t vlan_present:1;
15031         uint32_t vni;
15032         uint16_t udp_src;
15033         uint16_t udp_dst;
15034         cmdline_ipaddr_t ip_src;
15035         cmdline_ipaddr_t ip_dst;
15036         uint16_t tci;
15037         struct ether_addr eth_src;
15038         struct ether_addr eth_dst;
15039 };
15040
15041 cmdline_parse_token_string_t cmd_set_vxlan_set =
15042         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15043 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15044         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15045 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15046         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15047                                  "vxlan-with-vlan");
15048 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15049         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15050                                  "ip-version");
15051 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15052         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15053                                  "ipv4#ipv6");
15054 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15055         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15056                                  "vni");
15057 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15058         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15059 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15060         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15061                                  "udp-src");
15062 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15063         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15064 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15065         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15066                                  "udp-dst");
15067 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15068         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15069 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15070         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15071                                  "ip-src");
15072 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15073         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15074 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15075         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15076                                  "ip-dst");
15077 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15078         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15079 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15080         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15081                                  "vlan-tci");
15082 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15083         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15084 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15085         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15086                                  "eth-src");
15087 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15088         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15089 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15090         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15091                                  "eth-dst");
15092 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15093         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15094
15095 static void cmd_set_vxlan_parsed(void *parsed_result,
15096         __attribute__((unused)) struct cmdline *cl,
15097         __attribute__((unused)) void *data)
15098 {
15099         struct cmd_set_vxlan_result *res = parsed_result;
15100         union {
15101                 uint32_t vxlan_id;
15102                 uint8_t vni[4];
15103         } id = {
15104                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15105         };
15106
15107         if (strcmp(res->vxlan, "vxlan") == 0)
15108                 vxlan_encap_conf.select_vlan = 0;
15109         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15110                 vxlan_encap_conf.select_vlan = 1;
15111         if (strcmp(res->ip_version, "ipv4") == 0)
15112                 vxlan_encap_conf.select_ipv4 = 1;
15113         else if (strcmp(res->ip_version, "ipv6") == 0)
15114                 vxlan_encap_conf.select_ipv4 = 0;
15115         else
15116                 return;
15117         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15118         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15119         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15120         if (vxlan_encap_conf.select_ipv4) {
15121                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15122                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15123         } else {
15124                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15125                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15126         }
15127         if (vxlan_encap_conf.select_vlan)
15128                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15129         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15130                    ETHER_ADDR_LEN);
15131         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15132                    ETHER_ADDR_LEN);
15133 }
15134
15135 cmdline_parse_inst_t cmd_set_vxlan = {
15136         .f = cmd_set_vxlan_parsed,
15137         .data = NULL,
15138         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15139                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15140                 " eth-src <eth-src> eth-dst <eth-dst>",
15141         .tokens = {
15142                 (void *)&cmd_set_vxlan_set,
15143                 (void *)&cmd_set_vxlan_vxlan,
15144                 (void *)&cmd_set_vxlan_ip_version,
15145                 (void *)&cmd_set_vxlan_ip_version_value,
15146                 (void *)&cmd_set_vxlan_vni,
15147                 (void *)&cmd_set_vxlan_vni_value,
15148                 (void *)&cmd_set_vxlan_udp_src,
15149                 (void *)&cmd_set_vxlan_udp_src_value,
15150                 (void *)&cmd_set_vxlan_udp_dst,
15151                 (void *)&cmd_set_vxlan_udp_dst_value,
15152                 (void *)&cmd_set_vxlan_ip_src,
15153                 (void *)&cmd_set_vxlan_ip_src_value,
15154                 (void *)&cmd_set_vxlan_ip_dst,
15155                 (void *)&cmd_set_vxlan_ip_dst_value,
15156                 (void *)&cmd_set_vxlan_eth_src,
15157                 (void *)&cmd_set_vxlan_eth_src_value,
15158                 (void *)&cmd_set_vxlan_eth_dst,
15159                 (void *)&cmd_set_vxlan_eth_dst_value,
15160                 NULL,
15161         },
15162 };
15163
15164 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15165         .f = cmd_set_vxlan_parsed,
15166         .data = NULL,
15167         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15168                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15169                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15170                 " <eth-dst>",
15171         .tokens = {
15172                 (void *)&cmd_set_vxlan_set,
15173                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15174                 (void *)&cmd_set_vxlan_ip_version,
15175                 (void *)&cmd_set_vxlan_ip_version_value,
15176                 (void *)&cmd_set_vxlan_vni,
15177                 (void *)&cmd_set_vxlan_vni_value,
15178                 (void *)&cmd_set_vxlan_udp_src,
15179                 (void *)&cmd_set_vxlan_udp_src_value,
15180                 (void *)&cmd_set_vxlan_udp_dst,
15181                 (void *)&cmd_set_vxlan_udp_dst_value,
15182                 (void *)&cmd_set_vxlan_ip_src,
15183                 (void *)&cmd_set_vxlan_ip_src_value,
15184                 (void *)&cmd_set_vxlan_ip_dst,
15185                 (void *)&cmd_set_vxlan_ip_dst_value,
15186                 (void *)&cmd_set_vxlan_vlan,
15187                 (void *)&cmd_set_vxlan_vlan_value,
15188                 (void *)&cmd_set_vxlan_eth_src,
15189                 (void *)&cmd_set_vxlan_eth_src_value,
15190                 (void *)&cmd_set_vxlan_eth_dst,
15191                 (void *)&cmd_set_vxlan_eth_dst_value,
15192                 NULL,
15193         },
15194 };
15195
15196 /** Set NVGRE encapsulation details */
15197 struct cmd_set_nvgre_result {
15198         cmdline_fixed_string_t set;
15199         cmdline_fixed_string_t nvgre;
15200         cmdline_fixed_string_t pos_token;
15201         cmdline_fixed_string_t ip_version;
15202         uint32_t tni;
15203         cmdline_ipaddr_t ip_src;
15204         cmdline_ipaddr_t ip_dst;
15205         uint16_t tci;
15206         struct ether_addr eth_src;
15207         struct ether_addr eth_dst;
15208 };
15209
15210 cmdline_parse_token_string_t cmd_set_nvgre_set =
15211         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15212 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15213         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15214 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15215         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15216                                  "nvgre-with-vlan");
15217 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15218         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15219                                  "ip-version");
15220 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15221         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15222                                  "ipv4#ipv6");
15223 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15224         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15225                                  "tni");
15226 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15227         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15228 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15229         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15230                                  "ip-src");
15231 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15232         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15233 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15234         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15235                                  "ip-dst");
15236 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15237         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15238 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15239         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15240                                  "vlan-tci");
15241 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15242         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15243 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15244         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15245                                  "eth-src");
15246 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15247         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15248 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15249         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15250                                  "eth-dst");
15251 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15252         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15253
15254 static void cmd_set_nvgre_parsed(void *parsed_result,
15255         __attribute__((unused)) struct cmdline *cl,
15256         __attribute__((unused)) void *data)
15257 {
15258         struct cmd_set_nvgre_result *res = parsed_result;
15259         union {
15260                 uint32_t nvgre_tni;
15261                 uint8_t tni[4];
15262         } id = {
15263                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15264         };
15265
15266         if (strcmp(res->nvgre, "nvgre") == 0)
15267                 nvgre_encap_conf.select_vlan = 0;
15268         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15269                 nvgre_encap_conf.select_vlan = 1;
15270         if (strcmp(res->ip_version, "ipv4") == 0)
15271                 nvgre_encap_conf.select_ipv4 = 1;
15272         else if (strcmp(res->ip_version, "ipv6") == 0)
15273                 nvgre_encap_conf.select_ipv4 = 0;
15274         else
15275                 return;
15276         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15277         if (nvgre_encap_conf.select_ipv4) {
15278                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15279                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15280         } else {
15281                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15282                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15283         }
15284         if (nvgre_encap_conf.select_vlan)
15285                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15286         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15287                    ETHER_ADDR_LEN);
15288         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15289                    ETHER_ADDR_LEN);
15290 }
15291
15292 cmdline_parse_inst_t cmd_set_nvgre = {
15293         .f = cmd_set_nvgre_parsed,
15294         .data = NULL,
15295         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15296                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15297                 " eth-dst <eth-dst>",
15298         .tokens = {
15299                 (void *)&cmd_set_nvgre_set,
15300                 (void *)&cmd_set_nvgre_nvgre,
15301                 (void *)&cmd_set_nvgre_ip_version,
15302                 (void *)&cmd_set_nvgre_ip_version_value,
15303                 (void *)&cmd_set_nvgre_tni,
15304                 (void *)&cmd_set_nvgre_tni_value,
15305                 (void *)&cmd_set_nvgre_ip_src,
15306                 (void *)&cmd_set_nvgre_ip_src_value,
15307                 (void *)&cmd_set_nvgre_ip_dst,
15308                 (void *)&cmd_set_nvgre_ip_dst_value,
15309                 (void *)&cmd_set_nvgre_eth_src,
15310                 (void *)&cmd_set_nvgre_eth_src_value,
15311                 (void *)&cmd_set_nvgre_eth_dst,
15312                 (void *)&cmd_set_nvgre_eth_dst_value,
15313                 NULL,
15314         },
15315 };
15316
15317 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15318         .f = cmd_set_nvgre_parsed,
15319         .data = NULL,
15320         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15321                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15322                 " eth-src <eth-src> eth-dst <eth-dst>",
15323         .tokens = {
15324                 (void *)&cmd_set_nvgre_set,
15325                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15326                 (void *)&cmd_set_nvgre_ip_version,
15327                 (void *)&cmd_set_nvgre_ip_version_value,
15328                 (void *)&cmd_set_nvgre_tni,
15329                 (void *)&cmd_set_nvgre_tni_value,
15330                 (void *)&cmd_set_nvgre_ip_src,
15331                 (void *)&cmd_set_nvgre_ip_src_value,
15332                 (void *)&cmd_set_nvgre_ip_dst,
15333                 (void *)&cmd_set_nvgre_ip_dst_value,
15334                 (void *)&cmd_set_nvgre_vlan,
15335                 (void *)&cmd_set_nvgre_vlan_value,
15336                 (void *)&cmd_set_nvgre_eth_src,
15337                 (void *)&cmd_set_nvgre_eth_src_value,
15338                 (void *)&cmd_set_nvgre_eth_dst,
15339                 (void *)&cmd_set_nvgre_eth_dst_value,
15340                 NULL,
15341         },
15342 };
15343
15344 /** Set L2 encapsulation details */
15345 struct cmd_set_l2_encap_result {
15346         cmdline_fixed_string_t set;
15347         cmdline_fixed_string_t l2_encap;
15348         cmdline_fixed_string_t pos_token;
15349         cmdline_fixed_string_t ip_version;
15350         uint32_t vlan_present:1;
15351         uint16_t tci;
15352         struct ether_addr eth_src;
15353         struct ether_addr eth_dst;
15354 };
15355
15356 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15357         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15358 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15359         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15360 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15361         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15362                                  "l2_encap-with-vlan");
15363 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15364         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15365                                  "ip-version");
15366 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15367         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15368                                  "ipv4#ipv6");
15369 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15370         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15371                                  "vlan-tci");
15372 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15373         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15374 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15375         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15376                                  "eth-src");
15377 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15378         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15379 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15380         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15381                                  "eth-dst");
15382 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15383         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15384
15385 static void cmd_set_l2_encap_parsed(void *parsed_result,
15386         __attribute__((unused)) struct cmdline *cl,
15387         __attribute__((unused)) void *data)
15388 {
15389         struct cmd_set_l2_encap_result *res = parsed_result;
15390
15391         if (strcmp(res->l2_encap, "l2_encap") == 0)
15392                 l2_encap_conf.select_vlan = 0;
15393         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15394                 l2_encap_conf.select_vlan = 1;
15395         if (strcmp(res->ip_version, "ipv4") == 0)
15396                 l2_encap_conf.select_ipv4 = 1;
15397         else if (strcmp(res->ip_version, "ipv6") == 0)
15398                 l2_encap_conf.select_ipv4 = 0;
15399         else
15400                 return;
15401         if (l2_encap_conf.select_vlan)
15402                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15403         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15404                    ETHER_ADDR_LEN);
15405         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15406                    ETHER_ADDR_LEN);
15407 }
15408
15409 cmdline_parse_inst_t cmd_set_l2_encap = {
15410         .f = cmd_set_l2_encap_parsed,
15411         .data = NULL,
15412         .help_str = "set l2_encap ip-version ipv4|ipv6"
15413                 " eth-src <eth-src> eth-dst <eth-dst>",
15414         .tokens = {
15415                 (void *)&cmd_set_l2_encap_set,
15416                 (void *)&cmd_set_l2_encap_l2_encap,
15417                 (void *)&cmd_set_l2_encap_ip_version,
15418                 (void *)&cmd_set_l2_encap_ip_version_value,
15419                 (void *)&cmd_set_l2_encap_eth_src,
15420                 (void *)&cmd_set_l2_encap_eth_src_value,
15421                 (void *)&cmd_set_l2_encap_eth_dst,
15422                 (void *)&cmd_set_l2_encap_eth_dst_value,
15423                 NULL,
15424         },
15425 };
15426
15427 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15428         .f = cmd_set_l2_encap_parsed,
15429         .data = NULL,
15430         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15431                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15432         .tokens = {
15433                 (void *)&cmd_set_l2_encap_set,
15434                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15435                 (void *)&cmd_set_l2_encap_ip_version,
15436                 (void *)&cmd_set_l2_encap_ip_version_value,
15437                 (void *)&cmd_set_l2_encap_vlan,
15438                 (void *)&cmd_set_l2_encap_vlan_value,
15439                 (void *)&cmd_set_l2_encap_eth_src,
15440                 (void *)&cmd_set_l2_encap_eth_src_value,
15441                 (void *)&cmd_set_l2_encap_eth_dst,
15442                 (void *)&cmd_set_l2_encap_eth_dst_value,
15443                 NULL,
15444         },
15445 };
15446
15447 /** Set L2 decapsulation details */
15448 struct cmd_set_l2_decap_result {
15449         cmdline_fixed_string_t set;
15450         cmdline_fixed_string_t l2_decap;
15451         cmdline_fixed_string_t pos_token;
15452         uint32_t vlan_present:1;
15453 };
15454
15455 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15456         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15457 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15458         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15459                                  "l2_decap");
15460 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15461         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15462                                  "l2_decap-with-vlan");
15463
15464 static void cmd_set_l2_decap_parsed(void *parsed_result,
15465         __attribute__((unused)) struct cmdline *cl,
15466         __attribute__((unused)) void *data)
15467 {
15468         struct cmd_set_l2_decap_result *res = parsed_result;
15469
15470         if (strcmp(res->l2_decap, "l2_decap") == 0)
15471                 l2_decap_conf.select_vlan = 0;
15472         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15473                 l2_decap_conf.select_vlan = 1;
15474 }
15475
15476 cmdline_parse_inst_t cmd_set_l2_decap = {
15477         .f = cmd_set_l2_decap_parsed,
15478         .data = NULL,
15479         .help_str = "set l2_decap",
15480         .tokens = {
15481                 (void *)&cmd_set_l2_decap_set,
15482                 (void *)&cmd_set_l2_decap_l2_decap,
15483                 NULL,
15484         },
15485 };
15486
15487 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15488         .f = cmd_set_l2_decap_parsed,
15489         .data = NULL,
15490         .help_str = "set l2_decap-with-vlan",
15491         .tokens = {
15492                 (void *)&cmd_set_l2_decap_set,
15493                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15494                 NULL,
15495         },
15496 };
15497
15498 /** Set MPLSoGRE encapsulation details */
15499 struct cmd_set_mplsogre_encap_result {
15500         cmdline_fixed_string_t set;
15501         cmdline_fixed_string_t mplsogre;
15502         cmdline_fixed_string_t pos_token;
15503         cmdline_fixed_string_t ip_version;
15504         uint32_t vlan_present:1;
15505         uint32_t label;
15506         cmdline_ipaddr_t ip_src;
15507         cmdline_ipaddr_t ip_dst;
15508         uint16_t tci;
15509         struct ether_addr eth_src;
15510         struct ether_addr eth_dst;
15511 };
15512
15513 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15514         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15515                                  "set");
15516 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15517         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15518                                  "mplsogre_encap");
15519 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15520         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15521                                  mplsogre, "mplsogre_encap-with-vlan");
15522 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15523         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15524                                  pos_token, "ip-version");
15525 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15526         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15527                                  ip_version, "ipv4#ipv6");
15528 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15529         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15530                                  pos_token, "label");
15531 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15532         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15533                               UINT32);
15534 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15535         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15536                                  pos_token, "ip-src");
15537 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15538         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15539 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15540         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15541                                  pos_token, "ip-dst");
15542 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15543         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15544 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15545         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15546                                  pos_token, "vlan-tci");
15547 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15548         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15549                               UINT16);
15550 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15551         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15552                                  pos_token, "eth-src");
15553 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15554         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15555                                     eth_src);
15556 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15557         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15558                                  pos_token, "eth-dst");
15559 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15560         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15561                                     eth_dst);
15562
15563 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15564         __attribute__((unused)) struct cmdline *cl,
15565         __attribute__((unused)) void *data)
15566 {
15567         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15568         union {
15569                 uint32_t mplsogre_label;
15570                 uint8_t label[3];
15571         } id = {
15572                 .mplsogre_label =
15573                         rte_cpu_to_be_32(res->label) & RTE_BE32(0x00ffffff),
15574         };
15575
15576         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15577                 mplsogre_encap_conf.select_vlan = 0;
15578         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15579                 mplsogre_encap_conf.select_vlan = 1;
15580         if (strcmp(res->ip_version, "ipv4") == 0)
15581                 mplsogre_encap_conf.select_ipv4 = 1;
15582         else if (strcmp(res->ip_version, "ipv6") == 0)
15583                 mplsogre_encap_conf.select_ipv4 = 0;
15584         else
15585                 return;
15586         rte_memcpy(mplsogre_encap_conf.label, &id.label[1], 3);
15587         if (mplsogre_encap_conf.select_ipv4) {
15588                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15589                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15590         } else {
15591                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15592                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15593         }
15594         if (mplsogre_encap_conf.select_vlan)
15595                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15596         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15597                    ETHER_ADDR_LEN);
15598         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15599                    ETHER_ADDR_LEN);
15600 }
15601
15602 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15603         .f = cmd_set_mplsogre_encap_parsed,
15604         .data = NULL,
15605         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15606                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15607                 " eth-dst <eth-dst>",
15608         .tokens = {
15609                 (void *)&cmd_set_mplsogre_encap_set,
15610                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15611                 (void *)&cmd_set_mplsogre_encap_ip_version,
15612                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15613                 (void *)&cmd_set_mplsogre_encap_label,
15614                 (void *)&cmd_set_mplsogre_encap_label_value,
15615                 (void *)&cmd_set_mplsogre_encap_ip_src,
15616                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15617                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15618                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15619                 (void *)&cmd_set_mplsogre_encap_eth_src,
15620                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15621                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15622                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15623                 NULL,
15624         },
15625 };
15626
15627 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15628         .f = cmd_set_mplsogre_encap_parsed,
15629         .data = NULL,
15630         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15631                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15632                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15633         .tokens = {
15634                 (void *)&cmd_set_mplsogre_encap_set,
15635                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15636                 (void *)&cmd_set_mplsogre_encap_ip_version,
15637                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15638                 (void *)&cmd_set_mplsogre_encap_label,
15639                 (void *)&cmd_set_mplsogre_encap_label_value,
15640                 (void *)&cmd_set_mplsogre_encap_ip_src,
15641                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15642                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15643                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15644                 (void *)&cmd_set_mplsogre_encap_vlan,
15645                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15646                 (void *)&cmd_set_mplsogre_encap_eth_src,
15647                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15648                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15649                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15650                 NULL,
15651         },
15652 };
15653
15654 /** Set MPLSoGRE decapsulation details */
15655 struct cmd_set_mplsogre_decap_result {
15656         cmdline_fixed_string_t set;
15657         cmdline_fixed_string_t mplsogre;
15658         cmdline_fixed_string_t pos_token;
15659         cmdline_fixed_string_t ip_version;
15660         uint32_t vlan_present:1;
15661 };
15662
15663 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15664         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15665                                  "set");
15666 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15667         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15668                                  "mplsogre_decap");
15669 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15670         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15671                                  mplsogre, "mplsogre_decap-with-vlan");
15672 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15673         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15674                                  pos_token, "ip-version");
15675 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15676         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15677                                  ip_version, "ipv4#ipv6");
15678
15679 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15680         __attribute__((unused)) struct cmdline *cl,
15681         __attribute__((unused)) void *data)
15682 {
15683         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15684
15685         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15686                 mplsogre_decap_conf.select_vlan = 0;
15687         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15688                 mplsogre_decap_conf.select_vlan = 1;
15689         if (strcmp(res->ip_version, "ipv4") == 0)
15690                 mplsogre_decap_conf.select_ipv4 = 1;
15691         else if (strcmp(res->ip_version, "ipv6") == 0)
15692                 mplsogre_decap_conf.select_ipv4 = 0;
15693 }
15694
15695 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15696         .f = cmd_set_mplsogre_decap_parsed,
15697         .data = NULL,
15698         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15699         .tokens = {
15700                 (void *)&cmd_set_mplsogre_decap_set,
15701                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15702                 (void *)&cmd_set_mplsogre_decap_ip_version,
15703                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15704                 NULL,
15705         },
15706 };
15707
15708 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15709         .f = cmd_set_mplsogre_decap_parsed,
15710         .data = NULL,
15711         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15712         .tokens = {
15713                 (void *)&cmd_set_mplsogre_decap_set,
15714                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15715                 (void *)&cmd_set_mplsogre_decap_ip_version,
15716                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15717                 NULL,
15718         },
15719 };
15720
15721 /** Set MPLSoUDP encapsulation details */
15722 struct cmd_set_mplsoudp_encap_result {
15723         cmdline_fixed_string_t set;
15724         cmdline_fixed_string_t mplsoudp;
15725         cmdline_fixed_string_t pos_token;
15726         cmdline_fixed_string_t ip_version;
15727         uint32_t vlan_present:1;
15728         uint32_t label;
15729         uint16_t udp_src;
15730         uint16_t udp_dst;
15731         cmdline_ipaddr_t ip_src;
15732         cmdline_ipaddr_t ip_dst;
15733         uint16_t tci;
15734         struct ether_addr eth_src;
15735         struct ether_addr eth_dst;
15736 };
15737
15738 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15739         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15740                                  "set");
15741 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15742         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15743                                  "mplsoudp_encap");
15744 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15745         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15746                                  mplsoudp, "mplsoudp_encap-with-vlan");
15747 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15748         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15749                                  pos_token, "ip-version");
15750 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15751         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15752                                  ip_version, "ipv4#ipv6");
15753 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15754         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15755                                  pos_token, "label");
15756 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15757         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15758                               UINT32);
15759 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15760         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15761                                  pos_token, "udp-src");
15762 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
15763         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
15764                               UINT16);
15765 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
15766         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15767                                  pos_token, "udp-dst");
15768 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
15769         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
15770                               UINT16);
15771 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
15772         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15773                                  pos_token, "ip-src");
15774 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
15775         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
15776 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
15777         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15778                                  pos_token, "ip-dst");
15779 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
15780         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
15781 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
15782         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15783                                  pos_token, "vlan-tci");
15784 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
15785         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
15786                               UINT16);
15787 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
15788         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15789                                  pos_token, "eth-src");
15790 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
15791         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15792                                     eth_src);
15793 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
15794         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15795                                  pos_token, "eth-dst");
15796 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
15797         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15798                                     eth_dst);
15799
15800 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
15801         __attribute__((unused)) struct cmdline *cl,
15802         __attribute__((unused)) void *data)
15803 {
15804         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
15805         union {
15806                 uint32_t mplsoudp_label;
15807                 uint8_t label[3];
15808         } id = {
15809                 .mplsoudp_label =
15810                         rte_cpu_to_be_32(res->label) & RTE_BE32(0x00ffffff),
15811         };
15812
15813         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
15814                 mplsoudp_encap_conf.select_vlan = 0;
15815         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
15816                 mplsoudp_encap_conf.select_vlan = 1;
15817         if (strcmp(res->ip_version, "ipv4") == 0)
15818                 mplsoudp_encap_conf.select_ipv4 = 1;
15819         else if (strcmp(res->ip_version, "ipv6") == 0)
15820                 mplsoudp_encap_conf.select_ipv4 = 0;
15821         else
15822                 return;
15823         rte_memcpy(mplsoudp_encap_conf.label, &id.label[1], 3);
15824         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15825         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15826         if (mplsoudp_encap_conf.select_ipv4) {
15827                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
15828                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
15829         } else {
15830                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
15831                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
15832         }
15833         if (mplsoudp_encap_conf.select_vlan)
15834                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15835         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
15836                    ETHER_ADDR_LEN);
15837         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15838                    ETHER_ADDR_LEN);
15839 }
15840
15841 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
15842         .f = cmd_set_mplsoudp_encap_parsed,
15843         .data = NULL,
15844         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
15845                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
15846                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
15847         .tokens = {
15848                 (void *)&cmd_set_mplsoudp_encap_set,
15849                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
15850                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15851                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15852                 (void *)&cmd_set_mplsoudp_encap_label,
15853                 (void *)&cmd_set_mplsoudp_encap_label_value,
15854                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15855                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15856                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15857                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15858                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15859                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15860                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15861                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15862                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15863                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15864                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15865                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15866                 NULL,
15867         },
15868 };
15869
15870 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
15871         .f = cmd_set_mplsoudp_encap_parsed,
15872         .data = NULL,
15873         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
15874                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
15875                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15876                 " eth-src <eth-src> eth-dst <eth-dst>",
15877         .tokens = {
15878                 (void *)&cmd_set_mplsoudp_encap_set,
15879                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
15880                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15881                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15882                 (void *)&cmd_set_mplsoudp_encap_label,
15883                 (void *)&cmd_set_mplsoudp_encap_label_value,
15884                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15885                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15886                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15887                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15888                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15889                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15890                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15891                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15892                 (void *)&cmd_set_mplsoudp_encap_vlan,
15893                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
15894                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15895                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15896                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15897                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15898                 NULL,
15899         },
15900 };
15901
15902 /** Set MPLSoUDP decapsulation details */
15903 struct cmd_set_mplsoudp_decap_result {
15904         cmdline_fixed_string_t set;
15905         cmdline_fixed_string_t mplsoudp;
15906         cmdline_fixed_string_t pos_token;
15907         cmdline_fixed_string_t ip_version;
15908         uint32_t vlan_present:1;
15909 };
15910
15911 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
15912         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
15913                                  "set");
15914 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
15915         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
15916                                  "mplsoudp_decap");
15917 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
15918         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15919                                  mplsoudp, "mplsoudp_decap-with-vlan");
15920 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
15921         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15922                                  pos_token, "ip-version");
15923 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
15924         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15925                                  ip_version, "ipv4#ipv6");
15926
15927 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
15928         __attribute__((unused)) struct cmdline *cl,
15929         __attribute__((unused)) void *data)
15930 {
15931         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
15932
15933         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
15934                 mplsoudp_decap_conf.select_vlan = 0;
15935         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
15936                 mplsoudp_decap_conf.select_vlan = 1;
15937         if (strcmp(res->ip_version, "ipv4") == 0)
15938                 mplsoudp_decap_conf.select_ipv4 = 1;
15939         else if (strcmp(res->ip_version, "ipv6") == 0)
15940                 mplsoudp_decap_conf.select_ipv4 = 0;
15941 }
15942
15943 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
15944         .f = cmd_set_mplsoudp_decap_parsed,
15945         .data = NULL,
15946         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
15947         .tokens = {
15948                 (void *)&cmd_set_mplsoudp_decap_set,
15949                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
15950                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15951                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15952                 NULL,
15953         },
15954 };
15955
15956 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
15957         .f = cmd_set_mplsoudp_decap_parsed,
15958         .data = NULL,
15959         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
15960         .tokens = {
15961                 (void *)&cmd_set_mplsoudp_decap_set,
15962                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
15963                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15964                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15965                 NULL,
15966         },
15967 };
15968
15969 /* Strict link priority scheduling mode setting */
15970 static void
15971 cmd_strict_link_prio_parsed(
15972         void *parsed_result,
15973         __attribute__((unused)) struct cmdline *cl,
15974         __attribute__((unused)) void *data)
15975 {
15976         struct cmd_vf_tc_bw_result *res = parsed_result;
15977         int ret = -ENOTSUP;
15978
15979         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15980                 return;
15981
15982 #ifdef RTE_LIBRTE_I40E_PMD
15983         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
15984 #endif
15985
15986         switch (ret) {
15987         case 0:
15988                 break;
15989         case -EINVAL:
15990                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
15991                 break;
15992         case -ENODEV:
15993                 printf("invalid port_id %d\n", res->port_id);
15994                 break;
15995         case -ENOTSUP:
15996                 printf("function not implemented\n");
15997                 break;
15998         default:
15999                 printf("programming error: (%s)\n", strerror(-ret));
16000         }
16001 }
16002
16003 cmdline_parse_inst_t cmd_strict_link_prio = {
16004         .f = cmd_strict_link_prio_parsed,
16005         .data = NULL,
16006         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16007         .tokens = {
16008                 (void *)&cmd_vf_tc_bw_set,
16009                 (void *)&cmd_vf_tc_bw_tx,
16010                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16011                 (void *)&cmd_vf_tc_bw_port_id,
16012                 (void *)&cmd_vf_tc_bw_tc_map,
16013                 NULL,
16014         },
16015 };
16016
16017 /* Load dynamic device personalization*/
16018 struct cmd_ddp_add_result {
16019         cmdline_fixed_string_t ddp;
16020         cmdline_fixed_string_t add;
16021         portid_t port_id;
16022         char filepath[];
16023 };
16024
16025 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16026         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16027 cmdline_parse_token_string_t cmd_ddp_add_add =
16028         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16029 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16030         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16031 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16032         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16033
16034 static void
16035 cmd_ddp_add_parsed(
16036         void *parsed_result,
16037         __attribute__((unused)) struct cmdline *cl,
16038         __attribute__((unused)) void *data)
16039 {
16040         struct cmd_ddp_add_result *res = parsed_result;
16041         uint8_t *buff;
16042         uint32_t size;
16043         char *filepath;
16044         char *file_fld[2];
16045         int file_num;
16046         int ret = -ENOTSUP;
16047
16048         if (!all_ports_stopped()) {
16049                 printf("Please stop all ports first\n");
16050                 return;
16051         }
16052
16053         filepath = strdup(res->filepath);
16054         if (filepath == NULL) {
16055                 printf("Failed to allocate memory\n");
16056                 return;
16057         }
16058         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16059
16060         buff = open_file(file_fld[0], &size);
16061         if (!buff) {
16062                 free((void *)filepath);
16063                 return;
16064         }
16065
16066 #ifdef RTE_LIBRTE_I40E_PMD
16067         if (ret == -ENOTSUP)
16068                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16069                                                buff, size,
16070                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16071 #endif
16072
16073         if (ret == -EEXIST)
16074                 printf("Profile has already existed.\n");
16075         else if (ret < 0)
16076                 printf("Failed to load profile.\n");
16077         else if (file_num == 2)
16078                 save_file(file_fld[1], buff, size);
16079
16080         close_file(buff);
16081         free((void *)filepath);
16082 }
16083
16084 cmdline_parse_inst_t cmd_ddp_add = {
16085         .f = cmd_ddp_add_parsed,
16086         .data = NULL,
16087         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16088         .tokens = {
16089                 (void *)&cmd_ddp_add_ddp,
16090                 (void *)&cmd_ddp_add_add,
16091                 (void *)&cmd_ddp_add_port_id,
16092                 (void *)&cmd_ddp_add_filepath,
16093                 NULL,
16094         },
16095 };
16096
16097 /* Delete dynamic device personalization*/
16098 struct cmd_ddp_del_result {
16099         cmdline_fixed_string_t ddp;
16100         cmdline_fixed_string_t del;
16101         portid_t port_id;
16102         char filepath[];
16103 };
16104
16105 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16106         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16107 cmdline_parse_token_string_t cmd_ddp_del_del =
16108         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16109 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16110         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16111 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16112         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16113
16114 static void
16115 cmd_ddp_del_parsed(
16116         void *parsed_result,
16117         __attribute__((unused)) struct cmdline *cl,
16118         __attribute__((unused)) void *data)
16119 {
16120         struct cmd_ddp_del_result *res = parsed_result;
16121         uint8_t *buff;
16122         uint32_t size;
16123         int ret = -ENOTSUP;
16124
16125         if (!all_ports_stopped()) {
16126                 printf("Please stop all ports first\n");
16127                 return;
16128         }
16129
16130         buff = open_file(res->filepath, &size);
16131         if (!buff)
16132                 return;
16133
16134 #ifdef RTE_LIBRTE_I40E_PMD
16135         if (ret == -ENOTSUP)
16136                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16137                                                buff, size,
16138                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16139 #endif
16140
16141         if (ret == -EACCES)
16142                 printf("Profile does not exist.\n");
16143         else if (ret < 0)
16144                 printf("Failed to delete profile.\n");
16145
16146         close_file(buff);
16147 }
16148
16149 cmdline_parse_inst_t cmd_ddp_del = {
16150         .f = cmd_ddp_del_parsed,
16151         .data = NULL,
16152         .help_str = "ddp del <port_id> <backup_profile_path>",
16153         .tokens = {
16154                 (void *)&cmd_ddp_del_ddp,
16155                 (void *)&cmd_ddp_del_del,
16156                 (void *)&cmd_ddp_del_port_id,
16157                 (void *)&cmd_ddp_del_filepath,
16158                 NULL,
16159         },
16160 };
16161
16162 /* Get dynamic device personalization profile info */
16163 struct cmd_ddp_info_result {
16164         cmdline_fixed_string_t ddp;
16165         cmdline_fixed_string_t get;
16166         cmdline_fixed_string_t info;
16167         char filepath[];
16168 };
16169
16170 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16171         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16172 cmdline_parse_token_string_t cmd_ddp_info_get =
16173         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16174 cmdline_parse_token_string_t cmd_ddp_info_info =
16175         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16176 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16177         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16178
16179 static void
16180 cmd_ddp_info_parsed(
16181         void *parsed_result,
16182         __attribute__((unused)) struct cmdline *cl,
16183         __attribute__((unused)) void *data)
16184 {
16185         struct cmd_ddp_info_result *res = parsed_result;
16186         uint8_t *pkg;
16187         uint32_t pkg_size;
16188         int ret = -ENOTSUP;
16189 #ifdef RTE_LIBRTE_I40E_PMD
16190         uint32_t i, j, n;
16191         uint8_t *buff;
16192         uint32_t buff_size = 0;
16193         struct rte_pmd_i40e_profile_info info;
16194         uint32_t dev_num = 0;
16195         struct rte_pmd_i40e_ddp_device_id *devs;
16196         uint32_t proto_num = 0;
16197         struct rte_pmd_i40e_proto_info *proto = NULL;
16198         uint32_t pctype_num = 0;
16199         struct rte_pmd_i40e_ptype_info *pctype;
16200         uint32_t ptype_num = 0;
16201         struct rte_pmd_i40e_ptype_info *ptype;
16202         uint8_t proto_id;
16203
16204 #endif
16205
16206         pkg = open_file(res->filepath, &pkg_size);
16207         if (!pkg)
16208                 return;
16209
16210 #ifdef RTE_LIBRTE_I40E_PMD
16211         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16212                                 (uint8_t *)&info, sizeof(info),
16213                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16214         if (!ret) {
16215                 printf("Global Track id:       0x%x\n", info.track_id);
16216                 printf("Global Version:        %d.%d.%d.%d\n",
16217                         info.version.major,
16218                         info.version.minor,
16219                         info.version.update,
16220                         info.version.draft);
16221                 printf("Global Package name:   %s\n\n", info.name);
16222         }
16223
16224         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16225                                 (uint8_t *)&info, sizeof(info),
16226                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16227         if (!ret) {
16228                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16229                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16230                         info.version.major,
16231                         info.version.minor,
16232                         info.version.update,
16233                         info.version.draft);
16234                 printf("i40e Profile name:     %s\n\n", info.name);
16235         }
16236
16237         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16238                                 (uint8_t *)&buff_size, sizeof(buff_size),
16239                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16240         if (!ret && buff_size) {
16241                 buff = (uint8_t *)malloc(buff_size);
16242                 if (buff) {
16243                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16244                                                 buff, buff_size,
16245                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16246                         if (!ret)
16247                                 printf("Package Notes:\n%s\n\n", buff);
16248                         free(buff);
16249                 }
16250         }
16251
16252         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16253                                 (uint8_t *)&dev_num, sizeof(dev_num),
16254                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16255         if (!ret && dev_num) {
16256                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16257                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16258                 if (devs) {
16259                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16260                                                 (uint8_t *)devs, buff_size,
16261                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16262                         if (!ret) {
16263                                 printf("List of supported devices:\n");
16264                                 for (i = 0; i < dev_num; i++) {
16265                                         printf("  %04X:%04X %04X:%04X\n",
16266                                                 devs[i].vendor_dev_id >> 16,
16267                                                 devs[i].vendor_dev_id & 0xFFFF,
16268                                                 devs[i].sub_vendor_dev_id >> 16,
16269                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16270                                 }
16271                                 printf("\n");
16272                         }
16273                         free(devs);
16274                 }
16275         }
16276
16277         /* get information about protocols and packet types */
16278         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16279                 (uint8_t *)&proto_num, sizeof(proto_num),
16280                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16281         if (ret || !proto_num)
16282                 goto no_print_return;
16283
16284         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16285         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16286         if (!proto)
16287                 goto no_print_return;
16288
16289         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16290                                         buff_size,
16291                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16292         if (!ret) {
16293                 printf("List of used protocols:\n");
16294                 for (i = 0; i < proto_num; i++)
16295                         printf("  %2u: %s\n", proto[i].proto_id,
16296                                proto[i].name);
16297                 printf("\n");
16298         }
16299         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16300                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16301                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16302         if (ret || !pctype_num)
16303                 goto no_print_pctypes;
16304
16305         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16306         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16307         if (!pctype)
16308                 goto no_print_pctypes;
16309
16310         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16311                                         buff_size,
16312                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16313         if (ret) {
16314                 free(pctype);
16315                 goto no_print_pctypes;
16316         }
16317
16318         printf("List of defined packet classification types:\n");
16319         for (i = 0; i < pctype_num; i++) {
16320                 printf("  %2u:", pctype[i].ptype_id);
16321                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16322                         proto_id = pctype[i].protocols[j];
16323                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16324                                 for (n = 0; n < proto_num; n++) {
16325                                         if (proto[n].proto_id == proto_id) {
16326                                                 printf(" %s", proto[n].name);
16327                                                 break;
16328                                         }
16329                                 }
16330                         }
16331                 }
16332                 printf("\n");
16333         }
16334         printf("\n");
16335         free(pctype);
16336
16337 no_print_pctypes:
16338
16339         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16340                                         sizeof(ptype_num),
16341                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16342         if (ret || !ptype_num)
16343                 goto no_print_return;
16344
16345         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16346         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16347         if (!ptype)
16348                 goto no_print_return;
16349
16350         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16351                                         buff_size,
16352                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16353         if (ret) {
16354                 free(ptype);
16355                 goto no_print_return;
16356         }
16357         printf("List of defined packet types:\n");
16358         for (i = 0; i < ptype_num; i++) {
16359                 printf("  %2u:", ptype[i].ptype_id);
16360                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16361                         proto_id = ptype[i].protocols[j];
16362                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16363                                 for (n = 0; n < proto_num; n++) {
16364                                         if (proto[n].proto_id == proto_id) {
16365                                                 printf(" %s", proto[n].name);
16366                                                 break;
16367                                         }
16368                                 }
16369                         }
16370                 }
16371                 printf("\n");
16372         }
16373         free(ptype);
16374         printf("\n");
16375
16376         ret = 0;
16377 no_print_return:
16378         if (proto)
16379                 free(proto);
16380 #endif
16381         if (ret == -ENOTSUP)
16382                 printf("Function not supported in PMD driver\n");
16383         close_file(pkg);
16384 }
16385
16386 cmdline_parse_inst_t cmd_ddp_get_info = {
16387         .f = cmd_ddp_info_parsed,
16388         .data = NULL,
16389         .help_str = "ddp get info <profile_path>",
16390         .tokens = {
16391                 (void *)&cmd_ddp_info_ddp,
16392                 (void *)&cmd_ddp_info_get,
16393                 (void *)&cmd_ddp_info_info,
16394                 (void *)&cmd_ddp_info_filepath,
16395                 NULL,
16396         },
16397 };
16398
16399 /* Get dynamic device personalization profile info list*/
16400 #define PROFILE_INFO_SIZE 48
16401 #define MAX_PROFILE_NUM 16
16402
16403 struct cmd_ddp_get_list_result {
16404         cmdline_fixed_string_t ddp;
16405         cmdline_fixed_string_t get;
16406         cmdline_fixed_string_t list;
16407         portid_t port_id;
16408 };
16409
16410 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16411         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16412 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16413         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16414 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16415         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16416 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16417         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16418
16419 static void
16420 cmd_ddp_get_list_parsed(
16421         __attribute__((unused)) void *parsed_result,
16422         __attribute__((unused)) struct cmdline *cl,
16423         __attribute__((unused)) void *data)
16424 {
16425 #ifdef RTE_LIBRTE_I40E_PMD
16426         struct cmd_ddp_get_list_result *res = parsed_result;
16427         struct rte_pmd_i40e_profile_list *p_list;
16428         struct rte_pmd_i40e_profile_info *p_info;
16429         uint32_t p_num;
16430         uint32_t size;
16431         uint32_t i;
16432 #endif
16433         int ret = -ENOTSUP;
16434
16435 #ifdef RTE_LIBRTE_I40E_PMD
16436         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16437         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16438         if (!p_list)
16439                 printf("%s: Failed to malloc buffer\n", __func__);
16440
16441         if (ret == -ENOTSUP)
16442                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16443                                                 (uint8_t *)p_list, size);
16444
16445         if (!ret) {
16446                 p_num = p_list->p_count;
16447                 printf("Profile number is: %d\n\n", p_num);
16448
16449                 for (i = 0; i < p_num; i++) {
16450                         p_info = &p_list->p_info[i];
16451                         printf("Profile %d:\n", i);
16452                         printf("Track id:     0x%x\n", p_info->track_id);
16453                         printf("Version:      %d.%d.%d.%d\n",
16454                                p_info->version.major,
16455                                p_info->version.minor,
16456                                p_info->version.update,
16457                                p_info->version.draft);
16458                         printf("Profile name: %s\n\n", p_info->name);
16459                 }
16460         }
16461
16462         free(p_list);
16463 #endif
16464
16465         if (ret < 0)
16466                 printf("Failed to get ddp list\n");
16467 }
16468
16469 cmdline_parse_inst_t cmd_ddp_get_list = {
16470         .f = cmd_ddp_get_list_parsed,
16471         .data = NULL,
16472         .help_str = "ddp get list <port_id>",
16473         .tokens = {
16474                 (void *)&cmd_ddp_get_list_ddp,
16475                 (void *)&cmd_ddp_get_list_get,
16476                 (void *)&cmd_ddp_get_list_list,
16477                 (void *)&cmd_ddp_get_list_port_id,
16478                 NULL,
16479         },
16480 };
16481
16482 /* Configure input set */
16483 struct cmd_cfg_input_set_result {
16484         cmdline_fixed_string_t port;
16485         cmdline_fixed_string_t cfg;
16486         portid_t port_id;
16487         cmdline_fixed_string_t pctype;
16488         uint8_t pctype_id;
16489         cmdline_fixed_string_t inset_type;
16490         cmdline_fixed_string_t opt;
16491         cmdline_fixed_string_t field;
16492         uint8_t field_idx;
16493 };
16494
16495 static void
16496 cmd_cfg_input_set_parsed(
16497         __attribute__((unused)) void *parsed_result,
16498         __attribute__((unused)) struct cmdline *cl,
16499         __attribute__((unused)) void *data)
16500 {
16501 #ifdef RTE_LIBRTE_I40E_PMD
16502         struct cmd_cfg_input_set_result *res = parsed_result;
16503         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16504         struct rte_pmd_i40e_inset inset;
16505 #endif
16506         int ret = -ENOTSUP;
16507
16508         if (!all_ports_stopped()) {
16509                 printf("Please stop all ports first\n");
16510                 return;
16511         }
16512
16513 #ifdef RTE_LIBRTE_I40E_PMD
16514         if (!strcmp(res->inset_type, "hash_inset"))
16515                 inset_type = INSET_HASH;
16516         else if (!strcmp(res->inset_type, "fdir_inset"))
16517                 inset_type = INSET_FDIR;
16518         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16519                 inset_type = INSET_FDIR_FLX;
16520         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16521                                      &inset, inset_type);
16522         if (ret) {
16523                 printf("Failed to get input set.\n");
16524                 return;
16525         }
16526
16527         if (!strcmp(res->opt, "get")) {
16528                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16529                                                    res->field_idx);
16530                 if (ret)
16531                         printf("Field index %d is enabled.\n", res->field_idx);
16532                 else
16533                         printf("Field index %d is disabled.\n", res->field_idx);
16534                 return;
16535         } else if (!strcmp(res->opt, "set"))
16536                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16537                                                    res->field_idx);
16538         else if (!strcmp(res->opt, "clear"))
16539                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16540                                                      res->field_idx);
16541         if (ret) {
16542                 printf("Failed to configure input set field.\n");
16543                 return;
16544         }
16545
16546         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16547                                      &inset, inset_type);
16548         if (ret) {
16549                 printf("Failed to set input set.\n");
16550                 return;
16551         }
16552 #endif
16553
16554         if (ret == -ENOTSUP)
16555                 printf("Function not supported\n");
16556 }
16557
16558 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16559         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16560                                  port, "port");
16561 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16562         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16563                                  cfg, "config");
16564 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16565         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16566                               port_id, UINT16);
16567 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16568         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16569                                  pctype, "pctype");
16570 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16571         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16572                               pctype_id, UINT8);
16573 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16574         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16575                                  inset_type,
16576                                  "hash_inset#fdir_inset#fdir_flx_inset");
16577 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16578         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16579                                  opt, "get#set#clear");
16580 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16581         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16582                                  field, "field");
16583 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16584         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16585                               field_idx, UINT8);
16586
16587 cmdline_parse_inst_t cmd_cfg_input_set = {
16588         .f = cmd_cfg_input_set_parsed,
16589         .data = NULL,
16590         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16591                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16592         .tokens = {
16593                 (void *)&cmd_cfg_input_set_port,
16594                 (void *)&cmd_cfg_input_set_cfg,
16595                 (void *)&cmd_cfg_input_set_port_id,
16596                 (void *)&cmd_cfg_input_set_pctype,
16597                 (void *)&cmd_cfg_input_set_pctype_id,
16598                 (void *)&cmd_cfg_input_set_inset_type,
16599                 (void *)&cmd_cfg_input_set_opt,
16600                 (void *)&cmd_cfg_input_set_field,
16601                 (void *)&cmd_cfg_input_set_field_idx,
16602                 NULL,
16603         },
16604 };
16605
16606 /* Clear input set */
16607 struct cmd_clear_input_set_result {
16608         cmdline_fixed_string_t port;
16609         cmdline_fixed_string_t cfg;
16610         portid_t port_id;
16611         cmdline_fixed_string_t pctype;
16612         uint8_t pctype_id;
16613         cmdline_fixed_string_t inset_type;
16614         cmdline_fixed_string_t clear;
16615         cmdline_fixed_string_t all;
16616 };
16617
16618 static void
16619 cmd_clear_input_set_parsed(
16620         __attribute__((unused)) void *parsed_result,
16621         __attribute__((unused)) struct cmdline *cl,
16622         __attribute__((unused)) void *data)
16623 {
16624 #ifdef RTE_LIBRTE_I40E_PMD
16625         struct cmd_clear_input_set_result *res = parsed_result;
16626         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16627         struct rte_pmd_i40e_inset inset;
16628 #endif
16629         int ret = -ENOTSUP;
16630
16631         if (!all_ports_stopped()) {
16632                 printf("Please stop all ports first\n");
16633                 return;
16634         }
16635
16636 #ifdef RTE_LIBRTE_I40E_PMD
16637         if (!strcmp(res->inset_type, "hash_inset"))
16638                 inset_type = INSET_HASH;
16639         else if (!strcmp(res->inset_type, "fdir_inset"))
16640                 inset_type = INSET_FDIR;
16641         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16642                 inset_type = INSET_FDIR_FLX;
16643
16644         memset(&inset, 0, sizeof(inset));
16645
16646         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16647                                      &inset, inset_type);
16648         if (ret) {
16649                 printf("Failed to clear input set.\n");
16650                 return;
16651         }
16652
16653 #endif
16654
16655         if (ret == -ENOTSUP)
16656                 printf("Function not supported\n");
16657 }
16658
16659 cmdline_parse_token_string_t cmd_clear_input_set_port =
16660         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16661                                  port, "port");
16662 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16663         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16664                                  cfg, "config");
16665 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16666         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16667                               port_id, UINT16);
16668 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16669         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16670                                  pctype, "pctype");
16671 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16672         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16673                               pctype_id, UINT8);
16674 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16675         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16676                                  inset_type,
16677                                  "hash_inset#fdir_inset#fdir_flx_inset");
16678 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16679         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16680                                  clear, "clear");
16681 cmdline_parse_token_string_t cmd_clear_input_set_all =
16682         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16683                                  all, "all");
16684
16685 cmdline_parse_inst_t cmd_clear_input_set = {
16686         .f = cmd_clear_input_set_parsed,
16687         .data = NULL,
16688         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16689                     "fdir_inset|fdir_flx_inset clear all",
16690         .tokens = {
16691                 (void *)&cmd_clear_input_set_port,
16692                 (void *)&cmd_clear_input_set_cfg,
16693                 (void *)&cmd_clear_input_set_port_id,
16694                 (void *)&cmd_clear_input_set_pctype,
16695                 (void *)&cmd_clear_input_set_pctype_id,
16696                 (void *)&cmd_clear_input_set_inset_type,
16697                 (void *)&cmd_clear_input_set_clear,
16698                 (void *)&cmd_clear_input_set_all,
16699                 NULL,
16700         },
16701 };
16702
16703 /* show vf stats */
16704
16705 /* Common result structure for show vf stats */
16706 struct cmd_show_vf_stats_result {
16707         cmdline_fixed_string_t show;
16708         cmdline_fixed_string_t vf;
16709         cmdline_fixed_string_t stats;
16710         portid_t port_id;
16711         uint16_t vf_id;
16712 };
16713
16714 /* Common CLI fields show vf stats*/
16715 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16716         TOKEN_STRING_INITIALIZER
16717                 (struct cmd_show_vf_stats_result,
16718                  show, "show");
16719 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16720         TOKEN_STRING_INITIALIZER
16721                 (struct cmd_show_vf_stats_result,
16722                  vf, "vf");
16723 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16724         TOKEN_STRING_INITIALIZER
16725                 (struct cmd_show_vf_stats_result,
16726                  stats, "stats");
16727 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16728         TOKEN_NUM_INITIALIZER
16729                 (struct cmd_show_vf_stats_result,
16730                  port_id, UINT16);
16731 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16732         TOKEN_NUM_INITIALIZER
16733                 (struct cmd_show_vf_stats_result,
16734                  vf_id, UINT16);
16735
16736 static void
16737 cmd_show_vf_stats_parsed(
16738         void *parsed_result,
16739         __attribute__((unused)) struct cmdline *cl,
16740         __attribute__((unused)) void *data)
16741 {
16742         struct cmd_show_vf_stats_result *res = parsed_result;
16743         struct rte_eth_stats stats;
16744         int ret = -ENOTSUP;
16745         static const char *nic_stats_border = "########################";
16746
16747         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16748                 return;
16749
16750         memset(&stats, 0, sizeof(stats));
16751
16752 #ifdef RTE_LIBRTE_I40E_PMD
16753         if (ret == -ENOTSUP)
16754                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16755                                                 res->vf_id,
16756                                                 &stats);
16757 #endif
16758 #ifdef RTE_LIBRTE_BNXT_PMD
16759         if (ret == -ENOTSUP)
16760                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16761                                                 res->vf_id,
16762                                                 &stats);
16763 #endif
16764
16765         switch (ret) {
16766         case 0:
16767                 break;
16768         case -EINVAL:
16769                 printf("invalid vf_id %d\n", res->vf_id);
16770                 break;
16771         case -ENODEV:
16772                 printf("invalid port_id %d\n", res->port_id);
16773                 break;
16774         case -ENOTSUP:
16775                 printf("function not implemented\n");
16776                 break;
16777         default:
16778                 printf("programming error: (%s)\n", strerror(-ret));
16779         }
16780
16781         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
16782                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
16783
16784         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
16785                "%-"PRIu64"\n",
16786                stats.ipackets, stats.imissed, stats.ibytes);
16787         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
16788         printf("  RX-nombuf:  %-10"PRIu64"\n",
16789                stats.rx_nombuf);
16790         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
16791                "%-"PRIu64"\n",
16792                stats.opackets, stats.oerrors, stats.obytes);
16793
16794         printf("  %s############################%s\n",
16795                                nic_stats_border, nic_stats_border);
16796 }
16797
16798 cmdline_parse_inst_t cmd_show_vf_stats = {
16799         .f = cmd_show_vf_stats_parsed,
16800         .data = NULL,
16801         .help_str = "show vf stats <port_id> <vf_id>",
16802         .tokens = {
16803                 (void *)&cmd_show_vf_stats_show,
16804                 (void *)&cmd_show_vf_stats_vf,
16805                 (void *)&cmd_show_vf_stats_stats,
16806                 (void *)&cmd_show_vf_stats_port_id,
16807                 (void *)&cmd_show_vf_stats_vf_id,
16808                 NULL,
16809         },
16810 };
16811
16812 /* clear vf stats */
16813
16814 /* Common result structure for clear vf stats */
16815 struct cmd_clear_vf_stats_result {
16816         cmdline_fixed_string_t clear;
16817         cmdline_fixed_string_t vf;
16818         cmdline_fixed_string_t stats;
16819         portid_t port_id;
16820         uint16_t vf_id;
16821 };
16822
16823 /* Common CLI fields clear vf stats*/
16824 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
16825         TOKEN_STRING_INITIALIZER
16826                 (struct cmd_clear_vf_stats_result,
16827                  clear, "clear");
16828 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
16829         TOKEN_STRING_INITIALIZER
16830                 (struct cmd_clear_vf_stats_result,
16831                  vf, "vf");
16832 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
16833         TOKEN_STRING_INITIALIZER
16834                 (struct cmd_clear_vf_stats_result,
16835                  stats, "stats");
16836 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
16837         TOKEN_NUM_INITIALIZER
16838                 (struct cmd_clear_vf_stats_result,
16839                  port_id, UINT16);
16840 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
16841         TOKEN_NUM_INITIALIZER
16842                 (struct cmd_clear_vf_stats_result,
16843                  vf_id, UINT16);
16844
16845 static void
16846 cmd_clear_vf_stats_parsed(
16847         void *parsed_result,
16848         __attribute__((unused)) struct cmdline *cl,
16849         __attribute__((unused)) void *data)
16850 {
16851         struct cmd_clear_vf_stats_result *res = parsed_result;
16852         int ret = -ENOTSUP;
16853
16854         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16855                 return;
16856
16857 #ifdef RTE_LIBRTE_I40E_PMD
16858         if (ret == -ENOTSUP)
16859                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
16860                                                   res->vf_id);
16861 #endif
16862 #ifdef RTE_LIBRTE_BNXT_PMD
16863         if (ret == -ENOTSUP)
16864                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
16865                                                   res->vf_id);
16866 #endif
16867
16868         switch (ret) {
16869         case 0:
16870                 break;
16871         case -EINVAL:
16872                 printf("invalid vf_id %d\n", res->vf_id);
16873                 break;
16874         case -ENODEV:
16875                 printf("invalid port_id %d\n", res->port_id);
16876                 break;
16877         case -ENOTSUP:
16878                 printf("function not implemented\n");
16879                 break;
16880         default:
16881                 printf("programming error: (%s)\n", strerror(-ret));
16882         }
16883 }
16884
16885 cmdline_parse_inst_t cmd_clear_vf_stats = {
16886         .f = cmd_clear_vf_stats_parsed,
16887         .data = NULL,
16888         .help_str = "clear vf stats <port_id> <vf_id>",
16889         .tokens = {
16890                 (void *)&cmd_clear_vf_stats_clear,
16891                 (void *)&cmd_clear_vf_stats_vf,
16892                 (void *)&cmd_clear_vf_stats_stats,
16893                 (void *)&cmd_clear_vf_stats_port_id,
16894                 (void *)&cmd_clear_vf_stats_vf_id,
16895                 NULL,
16896         },
16897 };
16898
16899 /* port config pctype mapping reset */
16900
16901 /* Common result structure for port config pctype mapping reset */
16902 struct cmd_pctype_mapping_reset_result {
16903         cmdline_fixed_string_t port;
16904         cmdline_fixed_string_t config;
16905         portid_t port_id;
16906         cmdline_fixed_string_t pctype;
16907         cmdline_fixed_string_t mapping;
16908         cmdline_fixed_string_t reset;
16909 };
16910
16911 /* Common CLI fields for port config pctype mapping reset*/
16912 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
16913         TOKEN_STRING_INITIALIZER
16914                 (struct cmd_pctype_mapping_reset_result,
16915                  port, "port");
16916 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
16917         TOKEN_STRING_INITIALIZER
16918                 (struct cmd_pctype_mapping_reset_result,
16919                  config, "config");
16920 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
16921         TOKEN_NUM_INITIALIZER
16922                 (struct cmd_pctype_mapping_reset_result,
16923                  port_id, UINT16);
16924 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
16925         TOKEN_STRING_INITIALIZER
16926                 (struct cmd_pctype_mapping_reset_result,
16927                  pctype, "pctype");
16928 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
16929         TOKEN_STRING_INITIALIZER
16930                 (struct cmd_pctype_mapping_reset_result,
16931                  mapping, "mapping");
16932 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
16933         TOKEN_STRING_INITIALIZER
16934                 (struct cmd_pctype_mapping_reset_result,
16935                  reset, "reset");
16936
16937 static void
16938 cmd_pctype_mapping_reset_parsed(
16939         void *parsed_result,
16940         __attribute__((unused)) struct cmdline *cl,
16941         __attribute__((unused)) void *data)
16942 {
16943         struct cmd_pctype_mapping_reset_result *res = parsed_result;
16944         int ret = -ENOTSUP;
16945
16946         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16947                 return;
16948
16949 #ifdef RTE_LIBRTE_I40E_PMD
16950         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
16951 #endif
16952
16953         switch (ret) {
16954         case 0:
16955                 break;
16956         case -ENODEV:
16957                 printf("invalid port_id %d\n", res->port_id);
16958                 break;
16959         case -ENOTSUP:
16960                 printf("function not implemented\n");
16961                 break;
16962         default:
16963                 printf("programming error: (%s)\n", strerror(-ret));
16964         }
16965 }
16966
16967 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
16968         .f = cmd_pctype_mapping_reset_parsed,
16969         .data = NULL,
16970         .help_str = "port config <port_id> pctype mapping reset",
16971         .tokens = {
16972                 (void *)&cmd_pctype_mapping_reset_port,
16973                 (void *)&cmd_pctype_mapping_reset_config,
16974                 (void *)&cmd_pctype_mapping_reset_port_id,
16975                 (void *)&cmd_pctype_mapping_reset_pctype,
16976                 (void *)&cmd_pctype_mapping_reset_mapping,
16977                 (void *)&cmd_pctype_mapping_reset_reset,
16978                 NULL,
16979         },
16980 };
16981
16982 /* show port pctype mapping */
16983
16984 /* Common result structure for show port pctype mapping */
16985 struct cmd_pctype_mapping_get_result {
16986         cmdline_fixed_string_t show;
16987         cmdline_fixed_string_t port;
16988         portid_t port_id;
16989         cmdline_fixed_string_t pctype;
16990         cmdline_fixed_string_t mapping;
16991 };
16992
16993 /* Common CLI fields for pctype mapping get */
16994 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
16995         TOKEN_STRING_INITIALIZER
16996                 (struct cmd_pctype_mapping_get_result,
16997                  show, "show");
16998 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
16999         TOKEN_STRING_INITIALIZER
17000                 (struct cmd_pctype_mapping_get_result,
17001                  port, "port");
17002 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17003         TOKEN_NUM_INITIALIZER
17004                 (struct cmd_pctype_mapping_get_result,
17005                  port_id, UINT16);
17006 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17007         TOKEN_STRING_INITIALIZER
17008                 (struct cmd_pctype_mapping_get_result,
17009                  pctype, "pctype");
17010 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17011         TOKEN_STRING_INITIALIZER
17012                 (struct cmd_pctype_mapping_get_result,
17013                  mapping, "mapping");
17014
17015 static void
17016 cmd_pctype_mapping_get_parsed(
17017         void *parsed_result,
17018         __attribute__((unused)) struct cmdline *cl,
17019         __attribute__((unused)) void *data)
17020 {
17021         struct cmd_pctype_mapping_get_result *res = parsed_result;
17022         int ret = -ENOTSUP;
17023 #ifdef RTE_LIBRTE_I40E_PMD
17024         struct rte_pmd_i40e_flow_type_mapping
17025                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17026         int i, j, first_pctype;
17027 #endif
17028
17029         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17030                 return;
17031
17032 #ifdef RTE_LIBRTE_I40E_PMD
17033         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17034 #endif
17035
17036         switch (ret) {
17037         case 0:
17038                 break;
17039         case -ENODEV:
17040                 printf("invalid port_id %d\n", res->port_id);
17041                 return;
17042         case -ENOTSUP:
17043                 printf("function not implemented\n");
17044                 return;
17045         default:
17046                 printf("programming error: (%s)\n", strerror(-ret));
17047                 return;
17048         }
17049
17050 #ifdef RTE_LIBRTE_I40E_PMD
17051         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17052                 if (mapping[i].pctype != 0ULL) {
17053                         first_pctype = 1;
17054
17055                         printf("pctype: ");
17056                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17057                                 if (mapping[i].pctype & (1ULL << j)) {
17058                                         printf(first_pctype ?
17059                                                "%02d" : ",%02d", j);
17060                                         first_pctype = 0;
17061                                 }
17062                         }
17063                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17064                 }
17065         }
17066 #endif
17067 }
17068
17069 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17070         .f = cmd_pctype_mapping_get_parsed,
17071         .data = NULL,
17072         .help_str = "show port <port_id> pctype mapping",
17073         .tokens = {
17074                 (void *)&cmd_pctype_mapping_get_show,
17075                 (void *)&cmd_pctype_mapping_get_port,
17076                 (void *)&cmd_pctype_mapping_get_port_id,
17077                 (void *)&cmd_pctype_mapping_get_pctype,
17078                 (void *)&cmd_pctype_mapping_get_mapping,
17079                 NULL,
17080         },
17081 };
17082
17083 /* port config pctype mapping update */
17084
17085 /* Common result structure for port config pctype mapping update */
17086 struct cmd_pctype_mapping_update_result {
17087         cmdline_fixed_string_t port;
17088         cmdline_fixed_string_t config;
17089         portid_t port_id;
17090         cmdline_fixed_string_t pctype;
17091         cmdline_fixed_string_t mapping;
17092         cmdline_fixed_string_t update;
17093         cmdline_fixed_string_t pctype_list;
17094         uint16_t flow_type;
17095 };
17096
17097 /* Common CLI fields for pctype mapping update*/
17098 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17099         TOKEN_STRING_INITIALIZER
17100                 (struct cmd_pctype_mapping_update_result,
17101                  port, "port");
17102 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17103         TOKEN_STRING_INITIALIZER
17104                 (struct cmd_pctype_mapping_update_result,
17105                  config, "config");
17106 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17107         TOKEN_NUM_INITIALIZER
17108                 (struct cmd_pctype_mapping_update_result,
17109                  port_id, UINT16);
17110 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17111         TOKEN_STRING_INITIALIZER
17112                 (struct cmd_pctype_mapping_update_result,
17113                  pctype, "pctype");
17114 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17115         TOKEN_STRING_INITIALIZER
17116                 (struct cmd_pctype_mapping_update_result,
17117                  mapping, "mapping");
17118 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17119         TOKEN_STRING_INITIALIZER
17120                 (struct cmd_pctype_mapping_update_result,
17121                  update, "update");
17122 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17123         TOKEN_STRING_INITIALIZER
17124                 (struct cmd_pctype_mapping_update_result,
17125                  pctype_list, NULL);
17126 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17127         TOKEN_NUM_INITIALIZER
17128                 (struct cmd_pctype_mapping_update_result,
17129                  flow_type, UINT16);
17130
17131 static void
17132 cmd_pctype_mapping_update_parsed(
17133         void *parsed_result,
17134         __attribute__((unused)) struct cmdline *cl,
17135         __attribute__((unused)) void *data)
17136 {
17137         struct cmd_pctype_mapping_update_result *res = parsed_result;
17138         int ret = -ENOTSUP;
17139 #ifdef RTE_LIBRTE_I40E_PMD
17140         struct rte_pmd_i40e_flow_type_mapping mapping;
17141         unsigned int i;
17142         unsigned int nb_item;
17143         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17144 #endif
17145
17146         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17147                 return;
17148
17149 #ifdef RTE_LIBRTE_I40E_PMD
17150         nb_item = parse_item_list(res->pctype_list, "pctypes",
17151                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17152         mapping.flow_type = res->flow_type;
17153         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17154                 mapping.pctype |= (1ULL << pctype_list[i]);
17155         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17156                                                 &mapping,
17157                                                 1,
17158                                                 0);
17159 #endif
17160
17161         switch (ret) {
17162         case 0:
17163                 break;
17164         case -EINVAL:
17165                 printf("invalid pctype or flow type\n");
17166                 break;
17167         case -ENODEV:
17168                 printf("invalid port_id %d\n", res->port_id);
17169                 break;
17170         case -ENOTSUP:
17171                 printf("function not implemented\n");
17172                 break;
17173         default:
17174                 printf("programming error: (%s)\n", strerror(-ret));
17175         }
17176 }
17177
17178 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17179         .f = cmd_pctype_mapping_update_parsed,
17180         .data = NULL,
17181         .help_str = "port config <port_id> pctype mapping update"
17182         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17183         .tokens = {
17184                 (void *)&cmd_pctype_mapping_update_port,
17185                 (void *)&cmd_pctype_mapping_update_config,
17186                 (void *)&cmd_pctype_mapping_update_port_id,
17187                 (void *)&cmd_pctype_mapping_update_pctype,
17188                 (void *)&cmd_pctype_mapping_update_mapping,
17189                 (void *)&cmd_pctype_mapping_update_update,
17190                 (void *)&cmd_pctype_mapping_update_pc_type,
17191                 (void *)&cmd_pctype_mapping_update_flow_type,
17192                 NULL,
17193         },
17194 };
17195
17196 /* ptype mapping get */
17197
17198 /* Common result structure for ptype mapping get */
17199 struct cmd_ptype_mapping_get_result {
17200         cmdline_fixed_string_t ptype;
17201         cmdline_fixed_string_t mapping;
17202         cmdline_fixed_string_t get;
17203         portid_t port_id;
17204         uint8_t valid_only;
17205 };
17206
17207 /* Common CLI fields for ptype mapping get */
17208 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17209         TOKEN_STRING_INITIALIZER
17210                 (struct cmd_ptype_mapping_get_result,
17211                  ptype, "ptype");
17212 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17213         TOKEN_STRING_INITIALIZER
17214                 (struct cmd_ptype_mapping_get_result,
17215                  mapping, "mapping");
17216 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17217         TOKEN_STRING_INITIALIZER
17218                 (struct cmd_ptype_mapping_get_result,
17219                  get, "get");
17220 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17221         TOKEN_NUM_INITIALIZER
17222                 (struct cmd_ptype_mapping_get_result,
17223                  port_id, UINT16);
17224 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17225         TOKEN_NUM_INITIALIZER
17226                 (struct cmd_ptype_mapping_get_result,
17227                  valid_only, UINT8);
17228
17229 static void
17230 cmd_ptype_mapping_get_parsed(
17231         void *parsed_result,
17232         __attribute__((unused)) struct cmdline *cl,
17233         __attribute__((unused)) void *data)
17234 {
17235         struct cmd_ptype_mapping_get_result *res = parsed_result;
17236         int ret = -ENOTSUP;
17237 #ifdef RTE_LIBRTE_I40E_PMD
17238         int max_ptype_num = 256;
17239         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17240         uint16_t count;
17241         int i;
17242 #endif
17243
17244         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17245                 return;
17246
17247 #ifdef RTE_LIBRTE_I40E_PMD
17248         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17249                                         mapping,
17250                                         max_ptype_num,
17251                                         &count,
17252                                         res->valid_only);
17253 #endif
17254
17255         switch (ret) {
17256         case 0:
17257                 break;
17258         case -ENODEV:
17259                 printf("invalid port_id %d\n", res->port_id);
17260                 break;
17261         case -ENOTSUP:
17262                 printf("function not implemented\n");
17263                 break;
17264         default:
17265                 printf("programming error: (%s)\n", strerror(-ret));
17266         }
17267
17268 #ifdef RTE_LIBRTE_I40E_PMD
17269         if (!ret) {
17270                 for (i = 0; i < count; i++)
17271                         printf("%3d\t0x%08x\n",
17272                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17273         }
17274 #endif
17275 }
17276
17277 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17278         .f = cmd_ptype_mapping_get_parsed,
17279         .data = NULL,
17280         .help_str = "ptype mapping get <port_id> <valid_only>",
17281         .tokens = {
17282                 (void *)&cmd_ptype_mapping_get_ptype,
17283                 (void *)&cmd_ptype_mapping_get_mapping,
17284                 (void *)&cmd_ptype_mapping_get_get,
17285                 (void *)&cmd_ptype_mapping_get_port_id,
17286                 (void *)&cmd_ptype_mapping_get_valid_only,
17287                 NULL,
17288         },
17289 };
17290
17291 /* ptype mapping replace */
17292
17293 /* Common result structure for ptype mapping replace */
17294 struct cmd_ptype_mapping_replace_result {
17295         cmdline_fixed_string_t ptype;
17296         cmdline_fixed_string_t mapping;
17297         cmdline_fixed_string_t replace;
17298         portid_t port_id;
17299         uint32_t target;
17300         uint8_t mask;
17301         uint32_t pkt_type;
17302 };
17303
17304 /* Common CLI fields for ptype mapping replace */
17305 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17306         TOKEN_STRING_INITIALIZER
17307                 (struct cmd_ptype_mapping_replace_result,
17308                  ptype, "ptype");
17309 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17310         TOKEN_STRING_INITIALIZER
17311                 (struct cmd_ptype_mapping_replace_result,
17312                  mapping, "mapping");
17313 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17314         TOKEN_STRING_INITIALIZER
17315                 (struct cmd_ptype_mapping_replace_result,
17316                  replace, "replace");
17317 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17318         TOKEN_NUM_INITIALIZER
17319                 (struct cmd_ptype_mapping_replace_result,
17320                  port_id, UINT16);
17321 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17322         TOKEN_NUM_INITIALIZER
17323                 (struct cmd_ptype_mapping_replace_result,
17324                  target, UINT32);
17325 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17326         TOKEN_NUM_INITIALIZER
17327                 (struct cmd_ptype_mapping_replace_result,
17328                  mask, UINT8);
17329 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17330         TOKEN_NUM_INITIALIZER
17331                 (struct cmd_ptype_mapping_replace_result,
17332                  pkt_type, UINT32);
17333
17334 static void
17335 cmd_ptype_mapping_replace_parsed(
17336         void *parsed_result,
17337         __attribute__((unused)) struct cmdline *cl,
17338         __attribute__((unused)) void *data)
17339 {
17340         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17341         int ret = -ENOTSUP;
17342
17343         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17344                 return;
17345
17346 #ifdef RTE_LIBRTE_I40E_PMD
17347         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17348                                         res->target,
17349                                         res->mask,
17350                                         res->pkt_type);
17351 #endif
17352
17353         switch (ret) {
17354         case 0:
17355                 break;
17356         case -EINVAL:
17357                 printf("invalid ptype 0x%8x or 0x%8x\n",
17358                                 res->target, res->pkt_type);
17359                 break;
17360         case -ENODEV:
17361                 printf("invalid port_id %d\n", res->port_id);
17362                 break;
17363         case -ENOTSUP:
17364                 printf("function not implemented\n");
17365                 break;
17366         default:
17367                 printf("programming error: (%s)\n", strerror(-ret));
17368         }
17369 }
17370
17371 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17372         .f = cmd_ptype_mapping_replace_parsed,
17373         .data = NULL,
17374         .help_str =
17375                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17376         .tokens = {
17377                 (void *)&cmd_ptype_mapping_replace_ptype,
17378                 (void *)&cmd_ptype_mapping_replace_mapping,
17379                 (void *)&cmd_ptype_mapping_replace_replace,
17380                 (void *)&cmd_ptype_mapping_replace_port_id,
17381                 (void *)&cmd_ptype_mapping_replace_target,
17382                 (void *)&cmd_ptype_mapping_replace_mask,
17383                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17384                 NULL,
17385         },
17386 };
17387
17388 /* ptype mapping reset */
17389
17390 /* Common result structure for ptype mapping reset */
17391 struct cmd_ptype_mapping_reset_result {
17392         cmdline_fixed_string_t ptype;
17393         cmdline_fixed_string_t mapping;
17394         cmdline_fixed_string_t reset;
17395         portid_t port_id;
17396 };
17397
17398 /* Common CLI fields for ptype mapping reset*/
17399 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17400         TOKEN_STRING_INITIALIZER
17401                 (struct cmd_ptype_mapping_reset_result,
17402                  ptype, "ptype");
17403 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17404         TOKEN_STRING_INITIALIZER
17405                 (struct cmd_ptype_mapping_reset_result,
17406                  mapping, "mapping");
17407 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17408         TOKEN_STRING_INITIALIZER
17409                 (struct cmd_ptype_mapping_reset_result,
17410                  reset, "reset");
17411 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17412         TOKEN_NUM_INITIALIZER
17413                 (struct cmd_ptype_mapping_reset_result,
17414                  port_id, UINT16);
17415
17416 static void
17417 cmd_ptype_mapping_reset_parsed(
17418         void *parsed_result,
17419         __attribute__((unused)) struct cmdline *cl,
17420         __attribute__((unused)) void *data)
17421 {
17422         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17423         int ret = -ENOTSUP;
17424
17425         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17426                 return;
17427
17428 #ifdef RTE_LIBRTE_I40E_PMD
17429         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17430 #endif
17431
17432         switch (ret) {
17433         case 0:
17434                 break;
17435         case -ENODEV:
17436                 printf("invalid port_id %d\n", res->port_id);
17437                 break;
17438         case -ENOTSUP:
17439                 printf("function not implemented\n");
17440                 break;
17441         default:
17442                 printf("programming error: (%s)\n", strerror(-ret));
17443         }
17444 }
17445
17446 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17447         .f = cmd_ptype_mapping_reset_parsed,
17448         .data = NULL,
17449         .help_str = "ptype mapping reset <port_id>",
17450         .tokens = {
17451                 (void *)&cmd_ptype_mapping_reset_ptype,
17452                 (void *)&cmd_ptype_mapping_reset_mapping,
17453                 (void *)&cmd_ptype_mapping_reset_reset,
17454                 (void *)&cmd_ptype_mapping_reset_port_id,
17455                 NULL,
17456         },
17457 };
17458
17459 /* ptype mapping update */
17460
17461 /* Common result structure for ptype mapping update */
17462 struct cmd_ptype_mapping_update_result {
17463         cmdline_fixed_string_t ptype;
17464         cmdline_fixed_string_t mapping;
17465         cmdline_fixed_string_t reset;
17466         portid_t port_id;
17467         uint8_t hw_ptype;
17468         uint32_t sw_ptype;
17469 };
17470
17471 /* Common CLI fields for ptype mapping update*/
17472 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17473         TOKEN_STRING_INITIALIZER
17474                 (struct cmd_ptype_mapping_update_result,
17475                  ptype, "ptype");
17476 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17477         TOKEN_STRING_INITIALIZER
17478                 (struct cmd_ptype_mapping_update_result,
17479                  mapping, "mapping");
17480 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17481         TOKEN_STRING_INITIALIZER
17482                 (struct cmd_ptype_mapping_update_result,
17483                  reset, "update");
17484 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17485         TOKEN_NUM_INITIALIZER
17486                 (struct cmd_ptype_mapping_update_result,
17487                  port_id, UINT16);
17488 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17489         TOKEN_NUM_INITIALIZER
17490                 (struct cmd_ptype_mapping_update_result,
17491                  hw_ptype, UINT8);
17492 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17493         TOKEN_NUM_INITIALIZER
17494                 (struct cmd_ptype_mapping_update_result,
17495                  sw_ptype, UINT32);
17496
17497 static void
17498 cmd_ptype_mapping_update_parsed(
17499         void *parsed_result,
17500         __attribute__((unused)) struct cmdline *cl,
17501         __attribute__((unused)) void *data)
17502 {
17503         struct cmd_ptype_mapping_update_result *res = parsed_result;
17504         int ret = -ENOTSUP;
17505 #ifdef RTE_LIBRTE_I40E_PMD
17506         struct rte_pmd_i40e_ptype_mapping mapping;
17507 #endif
17508         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17509                 return;
17510
17511 #ifdef RTE_LIBRTE_I40E_PMD
17512         mapping.hw_ptype = res->hw_ptype;
17513         mapping.sw_ptype = res->sw_ptype;
17514         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17515                                                 &mapping,
17516                                                 1,
17517                                                 0);
17518 #endif
17519
17520         switch (ret) {
17521         case 0:
17522                 break;
17523         case -EINVAL:
17524                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17525                 break;
17526         case -ENODEV:
17527                 printf("invalid port_id %d\n", res->port_id);
17528                 break;
17529         case -ENOTSUP:
17530                 printf("function not implemented\n");
17531                 break;
17532         default:
17533                 printf("programming error: (%s)\n", strerror(-ret));
17534         }
17535 }
17536
17537 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17538         .f = cmd_ptype_mapping_update_parsed,
17539         .data = NULL,
17540         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17541         .tokens = {
17542                 (void *)&cmd_ptype_mapping_update_ptype,
17543                 (void *)&cmd_ptype_mapping_update_mapping,
17544                 (void *)&cmd_ptype_mapping_update_update,
17545                 (void *)&cmd_ptype_mapping_update_port_id,
17546                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17547                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17548                 NULL,
17549         },
17550 };
17551
17552 /* Common result structure for file commands */
17553 struct cmd_cmdfile_result {
17554         cmdline_fixed_string_t load;
17555         cmdline_fixed_string_t filename;
17556 };
17557
17558 /* Common CLI fields for file commands */
17559 cmdline_parse_token_string_t cmd_load_cmdfile =
17560         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17561 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17562         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17563
17564 static void
17565 cmd_load_from_file_parsed(
17566         void *parsed_result,
17567         __attribute__((unused)) struct cmdline *cl,
17568         __attribute__((unused)) void *data)
17569 {
17570         struct cmd_cmdfile_result *res = parsed_result;
17571
17572         cmdline_read_from_file(res->filename);
17573 }
17574
17575 cmdline_parse_inst_t cmd_load_from_file = {
17576         .f = cmd_load_from_file_parsed,
17577         .data = NULL,
17578         .help_str = "load <filename>",
17579         .tokens = {
17580                 (void *)&cmd_load_cmdfile,
17581                 (void *)&cmd_load_cmdfile_filename,
17582                 NULL,
17583         },
17584 };
17585
17586 /* Get Rx offloads capabilities */
17587 struct cmd_rx_offload_get_capa_result {
17588         cmdline_fixed_string_t show;
17589         cmdline_fixed_string_t port;
17590         portid_t port_id;
17591         cmdline_fixed_string_t rx_offload;
17592         cmdline_fixed_string_t capabilities;
17593 };
17594
17595 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17596         TOKEN_STRING_INITIALIZER
17597                 (struct cmd_rx_offload_get_capa_result,
17598                  show, "show");
17599 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17600         TOKEN_STRING_INITIALIZER
17601                 (struct cmd_rx_offload_get_capa_result,
17602                  port, "port");
17603 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17604         TOKEN_NUM_INITIALIZER
17605                 (struct cmd_rx_offload_get_capa_result,
17606                  port_id, UINT16);
17607 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17608         TOKEN_STRING_INITIALIZER
17609                 (struct cmd_rx_offload_get_capa_result,
17610                  rx_offload, "rx_offload");
17611 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17612         TOKEN_STRING_INITIALIZER
17613                 (struct cmd_rx_offload_get_capa_result,
17614                  capabilities, "capabilities");
17615
17616 static void
17617 print_rx_offloads(uint64_t offloads)
17618 {
17619         uint64_t single_offload;
17620         int begin;
17621         int end;
17622         int bit;
17623
17624         if (offloads == 0)
17625                 return;
17626
17627         begin = __builtin_ctzll(offloads);
17628         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17629
17630         single_offload = 1 << begin;
17631         for (bit = begin; bit < end; bit++) {
17632                 if (offloads & single_offload)
17633                         printf(" %s",
17634                                rte_eth_dev_rx_offload_name(single_offload));
17635                 single_offload <<= 1;
17636         }
17637 }
17638
17639 static void
17640 cmd_rx_offload_get_capa_parsed(
17641         void *parsed_result,
17642         __attribute__((unused)) struct cmdline *cl,
17643         __attribute__((unused)) void *data)
17644 {
17645         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17646         struct rte_eth_dev_info dev_info;
17647         portid_t port_id = res->port_id;
17648         uint64_t queue_offloads;
17649         uint64_t port_offloads;
17650
17651         rte_eth_dev_info_get(port_id, &dev_info);
17652         queue_offloads = dev_info.rx_queue_offload_capa;
17653         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17654
17655         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17656         printf("  Per Queue :");
17657         print_rx_offloads(queue_offloads);
17658
17659         printf("\n");
17660         printf("  Per Port  :");
17661         print_rx_offloads(port_offloads);
17662         printf("\n\n");
17663 }
17664
17665 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17666         .f = cmd_rx_offload_get_capa_parsed,
17667         .data = NULL,
17668         .help_str = "show port <port_id> rx_offload capabilities",
17669         .tokens = {
17670                 (void *)&cmd_rx_offload_get_capa_show,
17671                 (void *)&cmd_rx_offload_get_capa_port,
17672                 (void *)&cmd_rx_offload_get_capa_port_id,
17673                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17674                 (void *)&cmd_rx_offload_get_capa_capabilities,
17675                 NULL,
17676         }
17677 };
17678
17679 /* Get Rx offloads configuration */
17680 struct cmd_rx_offload_get_configuration_result {
17681         cmdline_fixed_string_t show;
17682         cmdline_fixed_string_t port;
17683         portid_t port_id;
17684         cmdline_fixed_string_t rx_offload;
17685         cmdline_fixed_string_t configuration;
17686 };
17687
17688 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17689         TOKEN_STRING_INITIALIZER
17690                 (struct cmd_rx_offload_get_configuration_result,
17691                  show, "show");
17692 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17693         TOKEN_STRING_INITIALIZER
17694                 (struct cmd_rx_offload_get_configuration_result,
17695                  port, "port");
17696 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17697         TOKEN_NUM_INITIALIZER
17698                 (struct cmd_rx_offload_get_configuration_result,
17699                  port_id, UINT16);
17700 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17701         TOKEN_STRING_INITIALIZER
17702                 (struct cmd_rx_offload_get_configuration_result,
17703                  rx_offload, "rx_offload");
17704 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17705         TOKEN_STRING_INITIALIZER
17706                 (struct cmd_rx_offload_get_configuration_result,
17707                  configuration, "configuration");
17708
17709 static void
17710 cmd_rx_offload_get_configuration_parsed(
17711         void *parsed_result,
17712         __attribute__((unused)) struct cmdline *cl,
17713         __attribute__((unused)) void *data)
17714 {
17715         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17716         struct rte_eth_dev_info dev_info;
17717         portid_t port_id = res->port_id;
17718         struct rte_port *port = &ports[port_id];
17719         uint64_t port_offloads;
17720         uint64_t queue_offloads;
17721         uint16_t nb_rx_queues;
17722         int q;
17723
17724         printf("Rx Offloading Configuration of port %d :\n", port_id);
17725
17726         port_offloads = port->dev_conf.rxmode.offloads;
17727         printf("  Port :");
17728         print_rx_offloads(port_offloads);
17729         printf("\n");
17730
17731         rte_eth_dev_info_get(port_id, &dev_info);
17732         nb_rx_queues = dev_info.nb_rx_queues;
17733         for (q = 0; q < nb_rx_queues; q++) {
17734                 queue_offloads = port->rx_conf[q].offloads;
17735                 printf("  Queue[%2d] :", q);
17736                 print_rx_offloads(queue_offloads);
17737                 printf("\n");
17738         }
17739         printf("\n");
17740 }
17741
17742 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17743         .f = cmd_rx_offload_get_configuration_parsed,
17744         .data = NULL,
17745         .help_str = "show port <port_id> rx_offload configuration",
17746         .tokens = {
17747                 (void *)&cmd_rx_offload_get_configuration_show,
17748                 (void *)&cmd_rx_offload_get_configuration_port,
17749                 (void *)&cmd_rx_offload_get_configuration_port_id,
17750                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17751                 (void *)&cmd_rx_offload_get_configuration_configuration,
17752                 NULL,
17753         }
17754 };
17755
17756 /* Enable/Disable a per port offloading */
17757 struct cmd_config_per_port_rx_offload_result {
17758         cmdline_fixed_string_t port;
17759         cmdline_fixed_string_t config;
17760         portid_t port_id;
17761         cmdline_fixed_string_t rx_offload;
17762         cmdline_fixed_string_t offload;
17763         cmdline_fixed_string_t on_off;
17764 };
17765
17766 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
17767         TOKEN_STRING_INITIALIZER
17768                 (struct cmd_config_per_port_rx_offload_result,
17769                  port, "port");
17770 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
17771         TOKEN_STRING_INITIALIZER
17772                 (struct cmd_config_per_port_rx_offload_result,
17773                  config, "config");
17774 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
17775         TOKEN_NUM_INITIALIZER
17776                 (struct cmd_config_per_port_rx_offload_result,
17777                  port_id, UINT16);
17778 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
17779         TOKEN_STRING_INITIALIZER
17780                 (struct cmd_config_per_port_rx_offload_result,
17781                  rx_offload, "rx_offload");
17782 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
17783         TOKEN_STRING_INITIALIZER
17784                 (struct cmd_config_per_port_rx_offload_result,
17785                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17786                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17787                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17788                            "crc_strip#scatter#timestamp#security#keep_crc");
17789 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
17790         TOKEN_STRING_INITIALIZER
17791                 (struct cmd_config_per_port_rx_offload_result,
17792                  on_off, "on#off");
17793
17794 static uint64_t
17795 search_rx_offload(const char *name)
17796 {
17797         uint64_t single_offload;
17798         const char *single_name;
17799         int found = 0;
17800         unsigned int bit;
17801
17802         single_offload = 1;
17803         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17804                 single_name = rte_eth_dev_rx_offload_name(single_offload);
17805                 if (!strcasecmp(single_name, name)) {
17806                         found = 1;
17807                         break;
17808                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17809                         break;
17810                 else if (single_name == NULL)
17811                         break;
17812                 single_offload <<= 1;
17813         }
17814
17815         if (found)
17816                 return single_offload;
17817
17818         return 0;
17819 }
17820
17821 static void
17822 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
17823                                 __attribute__((unused)) struct cmdline *cl,
17824                                 __attribute__((unused)) void *data)
17825 {
17826         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
17827         portid_t port_id = res->port_id;
17828         struct rte_eth_dev_info dev_info;
17829         struct rte_port *port = &ports[port_id];
17830         uint64_t single_offload;
17831         uint16_t nb_rx_queues;
17832         int q;
17833
17834         if (port->port_status != RTE_PORT_STOPPED) {
17835                 printf("Error: Can't config offload when Port %d "
17836                        "is not stopped\n", port_id);
17837                 return;
17838         }
17839
17840         single_offload = search_rx_offload(res->offload);
17841         if (single_offload == 0) {
17842                 printf("Unknown offload name: %s\n", res->offload);
17843                 return;
17844         }
17845
17846         rte_eth_dev_info_get(port_id, &dev_info);
17847         nb_rx_queues = dev_info.nb_rx_queues;
17848         if (!strcmp(res->on_off, "on")) {
17849                 port->dev_conf.rxmode.offloads |= single_offload;
17850                 for (q = 0; q < nb_rx_queues; q++)
17851                         port->rx_conf[q].offloads |= single_offload;
17852         } else {
17853                 port->dev_conf.rxmode.offloads &= ~single_offload;
17854                 for (q = 0; q < nb_rx_queues; q++)
17855                         port->rx_conf[q].offloads &= ~single_offload;
17856         }
17857
17858         cmd_reconfig_device_queue(port_id, 1, 1);
17859 }
17860
17861 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
17862         .f = cmd_config_per_port_rx_offload_parsed,
17863         .data = NULL,
17864         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
17865                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17866                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17867                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17868                     "on|off",
17869         .tokens = {
17870                 (void *)&cmd_config_per_port_rx_offload_result_port,
17871                 (void *)&cmd_config_per_port_rx_offload_result_config,
17872                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
17873                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
17874                 (void *)&cmd_config_per_port_rx_offload_result_offload,
17875                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
17876                 NULL,
17877         }
17878 };
17879
17880 /* Enable/Disable a per queue offloading */
17881 struct cmd_config_per_queue_rx_offload_result {
17882         cmdline_fixed_string_t port;
17883         portid_t port_id;
17884         cmdline_fixed_string_t rxq;
17885         uint16_t queue_id;
17886         cmdline_fixed_string_t rx_offload;
17887         cmdline_fixed_string_t offload;
17888         cmdline_fixed_string_t on_off;
17889 };
17890
17891 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
17892         TOKEN_STRING_INITIALIZER
17893                 (struct cmd_config_per_queue_rx_offload_result,
17894                  port, "port");
17895 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
17896         TOKEN_NUM_INITIALIZER
17897                 (struct cmd_config_per_queue_rx_offload_result,
17898                  port_id, UINT16);
17899 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
17900         TOKEN_STRING_INITIALIZER
17901                 (struct cmd_config_per_queue_rx_offload_result,
17902                  rxq, "rxq");
17903 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
17904         TOKEN_NUM_INITIALIZER
17905                 (struct cmd_config_per_queue_rx_offload_result,
17906                  queue_id, UINT16);
17907 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
17908         TOKEN_STRING_INITIALIZER
17909                 (struct cmd_config_per_queue_rx_offload_result,
17910                  rx_offload, "rx_offload");
17911 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
17912         TOKEN_STRING_INITIALIZER
17913                 (struct cmd_config_per_queue_rx_offload_result,
17914                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17915                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17916                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17917                            "crc_strip#scatter#timestamp#security#keep_crc");
17918 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
17919         TOKEN_STRING_INITIALIZER
17920                 (struct cmd_config_per_queue_rx_offload_result,
17921                  on_off, "on#off");
17922
17923 static void
17924 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
17925                                 __attribute__((unused)) struct cmdline *cl,
17926                                 __attribute__((unused)) void *data)
17927 {
17928         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
17929         struct rte_eth_dev_info dev_info;
17930         portid_t port_id = res->port_id;
17931         uint16_t queue_id = res->queue_id;
17932         struct rte_port *port = &ports[port_id];
17933         uint64_t single_offload;
17934
17935         if (port->port_status != RTE_PORT_STOPPED) {
17936                 printf("Error: Can't config offload when Port %d "
17937                        "is not stopped\n", port_id);
17938                 return;
17939         }
17940
17941         rte_eth_dev_info_get(port_id, &dev_info);
17942         if (queue_id >= dev_info.nb_rx_queues) {
17943                 printf("Error: input queue_id should be 0 ... "
17944                        "%d\n", dev_info.nb_rx_queues - 1);
17945                 return;
17946         }
17947
17948         single_offload = search_rx_offload(res->offload);
17949         if (single_offload == 0) {
17950                 printf("Unknown offload name: %s\n", res->offload);
17951                 return;
17952         }
17953
17954         if (!strcmp(res->on_off, "on"))
17955                 port->rx_conf[queue_id].offloads |= single_offload;
17956         else
17957                 port->rx_conf[queue_id].offloads &= ~single_offload;
17958
17959         cmd_reconfig_device_queue(port_id, 1, 1);
17960 }
17961
17962 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
17963         .f = cmd_config_per_queue_rx_offload_parsed,
17964         .data = NULL,
17965         .help_str = "port <port_id> rxq <queue_id> rx_offload "
17966                     "vlan_strip|ipv4_cksum|"
17967                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17968                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17969                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17970                     "on|off",
17971         .tokens = {
17972                 (void *)&cmd_config_per_queue_rx_offload_result_port,
17973                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
17974                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
17975                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
17976                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
17977                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
17978                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
17979                 NULL,
17980         }
17981 };
17982
17983 /* Get Tx offloads capabilities */
17984 struct cmd_tx_offload_get_capa_result {
17985         cmdline_fixed_string_t show;
17986         cmdline_fixed_string_t port;
17987         portid_t port_id;
17988         cmdline_fixed_string_t tx_offload;
17989         cmdline_fixed_string_t capabilities;
17990 };
17991
17992 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
17993         TOKEN_STRING_INITIALIZER
17994                 (struct cmd_tx_offload_get_capa_result,
17995                  show, "show");
17996 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
17997         TOKEN_STRING_INITIALIZER
17998                 (struct cmd_tx_offload_get_capa_result,
17999                  port, "port");
18000 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18001         TOKEN_NUM_INITIALIZER
18002                 (struct cmd_tx_offload_get_capa_result,
18003                  port_id, UINT16);
18004 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18005         TOKEN_STRING_INITIALIZER
18006                 (struct cmd_tx_offload_get_capa_result,
18007                  tx_offload, "tx_offload");
18008 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18009         TOKEN_STRING_INITIALIZER
18010                 (struct cmd_tx_offload_get_capa_result,
18011                  capabilities, "capabilities");
18012
18013 static void
18014 print_tx_offloads(uint64_t offloads)
18015 {
18016         uint64_t single_offload;
18017         int begin;
18018         int end;
18019         int bit;
18020
18021         if (offloads == 0)
18022                 return;
18023
18024         begin = __builtin_ctzll(offloads);
18025         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18026
18027         single_offload = 1 << begin;
18028         for (bit = begin; bit < end; bit++) {
18029                 if (offloads & single_offload)
18030                         printf(" %s",
18031                                rte_eth_dev_tx_offload_name(single_offload));
18032                 single_offload <<= 1;
18033         }
18034 }
18035
18036 static void
18037 cmd_tx_offload_get_capa_parsed(
18038         void *parsed_result,
18039         __attribute__((unused)) struct cmdline *cl,
18040         __attribute__((unused)) void *data)
18041 {
18042         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18043         struct rte_eth_dev_info dev_info;
18044         portid_t port_id = res->port_id;
18045         uint64_t queue_offloads;
18046         uint64_t port_offloads;
18047
18048         rte_eth_dev_info_get(port_id, &dev_info);
18049         queue_offloads = dev_info.tx_queue_offload_capa;
18050         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18051
18052         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18053         printf("  Per Queue :");
18054         print_tx_offloads(queue_offloads);
18055
18056         printf("\n");
18057         printf("  Per Port  :");
18058         print_tx_offloads(port_offloads);
18059         printf("\n\n");
18060 }
18061
18062 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18063         .f = cmd_tx_offload_get_capa_parsed,
18064         .data = NULL,
18065         .help_str = "show port <port_id> tx_offload capabilities",
18066         .tokens = {
18067                 (void *)&cmd_tx_offload_get_capa_show,
18068                 (void *)&cmd_tx_offload_get_capa_port,
18069                 (void *)&cmd_tx_offload_get_capa_port_id,
18070                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18071                 (void *)&cmd_tx_offload_get_capa_capabilities,
18072                 NULL,
18073         }
18074 };
18075
18076 /* Get Tx offloads configuration */
18077 struct cmd_tx_offload_get_configuration_result {
18078         cmdline_fixed_string_t show;
18079         cmdline_fixed_string_t port;
18080         portid_t port_id;
18081         cmdline_fixed_string_t tx_offload;
18082         cmdline_fixed_string_t configuration;
18083 };
18084
18085 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18086         TOKEN_STRING_INITIALIZER
18087                 (struct cmd_tx_offload_get_configuration_result,
18088                  show, "show");
18089 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18090         TOKEN_STRING_INITIALIZER
18091                 (struct cmd_tx_offload_get_configuration_result,
18092                  port, "port");
18093 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18094         TOKEN_NUM_INITIALIZER
18095                 (struct cmd_tx_offload_get_configuration_result,
18096                  port_id, UINT16);
18097 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18098         TOKEN_STRING_INITIALIZER
18099                 (struct cmd_tx_offload_get_configuration_result,
18100                  tx_offload, "tx_offload");
18101 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18102         TOKEN_STRING_INITIALIZER
18103                 (struct cmd_tx_offload_get_configuration_result,
18104                  configuration, "configuration");
18105
18106 static void
18107 cmd_tx_offload_get_configuration_parsed(
18108         void *parsed_result,
18109         __attribute__((unused)) struct cmdline *cl,
18110         __attribute__((unused)) void *data)
18111 {
18112         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18113         struct rte_eth_dev_info dev_info;
18114         portid_t port_id = res->port_id;
18115         struct rte_port *port = &ports[port_id];
18116         uint64_t port_offloads;
18117         uint64_t queue_offloads;
18118         uint16_t nb_tx_queues;
18119         int q;
18120
18121         printf("Tx Offloading Configuration of port %d :\n", port_id);
18122
18123         port_offloads = port->dev_conf.txmode.offloads;
18124         printf("  Port :");
18125         print_tx_offloads(port_offloads);
18126         printf("\n");
18127
18128         rte_eth_dev_info_get(port_id, &dev_info);
18129         nb_tx_queues = dev_info.nb_tx_queues;
18130         for (q = 0; q < nb_tx_queues; q++) {
18131                 queue_offloads = port->tx_conf[q].offloads;
18132                 printf("  Queue[%2d] :", q);
18133                 print_tx_offloads(queue_offloads);
18134                 printf("\n");
18135         }
18136         printf("\n");
18137 }
18138
18139 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18140         .f = cmd_tx_offload_get_configuration_parsed,
18141         .data = NULL,
18142         .help_str = "show port <port_id> tx_offload configuration",
18143         .tokens = {
18144                 (void *)&cmd_tx_offload_get_configuration_show,
18145                 (void *)&cmd_tx_offload_get_configuration_port,
18146                 (void *)&cmd_tx_offload_get_configuration_port_id,
18147                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18148                 (void *)&cmd_tx_offload_get_configuration_configuration,
18149                 NULL,
18150         }
18151 };
18152
18153 /* Enable/Disable a per port offloading */
18154 struct cmd_config_per_port_tx_offload_result {
18155         cmdline_fixed_string_t port;
18156         cmdline_fixed_string_t config;
18157         portid_t port_id;
18158         cmdline_fixed_string_t tx_offload;
18159         cmdline_fixed_string_t offload;
18160         cmdline_fixed_string_t on_off;
18161 };
18162
18163 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18164         TOKEN_STRING_INITIALIZER
18165                 (struct cmd_config_per_port_tx_offload_result,
18166                  port, "port");
18167 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18168         TOKEN_STRING_INITIALIZER
18169                 (struct cmd_config_per_port_tx_offload_result,
18170                  config, "config");
18171 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18172         TOKEN_NUM_INITIALIZER
18173                 (struct cmd_config_per_port_tx_offload_result,
18174                  port_id, UINT16);
18175 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18176         TOKEN_STRING_INITIALIZER
18177                 (struct cmd_config_per_port_tx_offload_result,
18178                  tx_offload, "tx_offload");
18179 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18180         TOKEN_STRING_INITIALIZER
18181                 (struct cmd_config_per_port_tx_offload_result,
18182                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18183                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18184                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18185                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18186                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18187                           "match_metadata");
18188 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18189         TOKEN_STRING_INITIALIZER
18190                 (struct cmd_config_per_port_tx_offload_result,
18191                  on_off, "on#off");
18192
18193 static uint64_t
18194 search_tx_offload(const char *name)
18195 {
18196         uint64_t single_offload;
18197         const char *single_name;
18198         int found = 0;
18199         unsigned int bit;
18200
18201         single_offload = 1;
18202         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18203                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18204                 if (!strcasecmp(single_name, name)) {
18205                         found = 1;
18206                         break;
18207                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18208                         break;
18209                 else if (single_name == NULL)
18210                         break;
18211                 single_offload <<= 1;
18212         }
18213
18214         if (found)
18215                 return single_offload;
18216
18217         return 0;
18218 }
18219
18220 static void
18221 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18222                                 __attribute__((unused)) struct cmdline *cl,
18223                                 __attribute__((unused)) void *data)
18224 {
18225         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18226         portid_t port_id = res->port_id;
18227         struct rte_eth_dev_info dev_info;
18228         struct rte_port *port = &ports[port_id];
18229         uint64_t single_offload;
18230         uint16_t nb_tx_queues;
18231         int q;
18232
18233         if (port->port_status != RTE_PORT_STOPPED) {
18234                 printf("Error: Can't config offload when Port %d "
18235                        "is not stopped\n", port_id);
18236                 return;
18237         }
18238
18239         single_offload = search_tx_offload(res->offload);
18240         if (single_offload == 0) {
18241                 printf("Unknown offload name: %s\n", res->offload);
18242                 return;
18243         }
18244
18245         rte_eth_dev_info_get(port_id, &dev_info);
18246         nb_tx_queues = dev_info.nb_tx_queues;
18247         if (!strcmp(res->on_off, "on")) {
18248                 port->dev_conf.txmode.offloads |= single_offload;
18249                 for (q = 0; q < nb_tx_queues; q++)
18250                         port->tx_conf[q].offloads |= single_offload;
18251         } else {
18252                 port->dev_conf.txmode.offloads &= ~single_offload;
18253                 for (q = 0; q < nb_tx_queues; q++)
18254                         port->tx_conf[q].offloads &= ~single_offload;
18255         }
18256
18257         cmd_reconfig_device_queue(port_id, 1, 1);
18258 }
18259
18260 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18261         .f = cmd_config_per_port_tx_offload_parsed,
18262         .data = NULL,
18263         .help_str = "port config <port_id> tx_offload "
18264                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18265                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18266                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18267                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18268                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18269                     "match_metadata on|off",
18270         .tokens = {
18271                 (void *)&cmd_config_per_port_tx_offload_result_port,
18272                 (void *)&cmd_config_per_port_tx_offload_result_config,
18273                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18274                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18275                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18276                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18277                 NULL,
18278         }
18279 };
18280
18281 /* Enable/Disable a per queue offloading */
18282 struct cmd_config_per_queue_tx_offload_result {
18283         cmdline_fixed_string_t port;
18284         portid_t port_id;
18285         cmdline_fixed_string_t txq;
18286         uint16_t queue_id;
18287         cmdline_fixed_string_t tx_offload;
18288         cmdline_fixed_string_t offload;
18289         cmdline_fixed_string_t on_off;
18290 };
18291
18292 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18293         TOKEN_STRING_INITIALIZER
18294                 (struct cmd_config_per_queue_tx_offload_result,
18295                  port, "port");
18296 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18297         TOKEN_NUM_INITIALIZER
18298                 (struct cmd_config_per_queue_tx_offload_result,
18299                  port_id, UINT16);
18300 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18301         TOKEN_STRING_INITIALIZER
18302                 (struct cmd_config_per_queue_tx_offload_result,
18303                  txq, "txq");
18304 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18305         TOKEN_NUM_INITIALIZER
18306                 (struct cmd_config_per_queue_tx_offload_result,
18307                  queue_id, UINT16);
18308 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18309         TOKEN_STRING_INITIALIZER
18310                 (struct cmd_config_per_queue_tx_offload_result,
18311                  tx_offload, "tx_offload");
18312 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18313         TOKEN_STRING_INITIALIZER
18314                 (struct cmd_config_per_queue_tx_offload_result,
18315                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18316                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18317                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18318                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18319                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18320 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18321         TOKEN_STRING_INITIALIZER
18322                 (struct cmd_config_per_queue_tx_offload_result,
18323                  on_off, "on#off");
18324
18325 static void
18326 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18327                                 __attribute__((unused)) struct cmdline *cl,
18328                                 __attribute__((unused)) void *data)
18329 {
18330         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18331         struct rte_eth_dev_info dev_info;
18332         portid_t port_id = res->port_id;
18333         uint16_t queue_id = res->queue_id;
18334         struct rte_port *port = &ports[port_id];
18335         uint64_t single_offload;
18336
18337         if (port->port_status != RTE_PORT_STOPPED) {
18338                 printf("Error: Can't config offload when Port %d "
18339                        "is not stopped\n", port_id);
18340                 return;
18341         }
18342
18343         rte_eth_dev_info_get(port_id, &dev_info);
18344         if (queue_id >= dev_info.nb_tx_queues) {
18345                 printf("Error: input queue_id should be 0 ... "
18346                        "%d\n", dev_info.nb_tx_queues - 1);
18347                 return;
18348         }
18349
18350         single_offload = search_tx_offload(res->offload);
18351         if (single_offload == 0) {
18352                 printf("Unknown offload name: %s\n", res->offload);
18353                 return;
18354         }
18355
18356         if (!strcmp(res->on_off, "on"))
18357                 port->tx_conf[queue_id].offloads |= single_offload;
18358         else
18359                 port->tx_conf[queue_id].offloads &= ~single_offload;
18360
18361         cmd_reconfig_device_queue(port_id, 1, 1);
18362 }
18363
18364 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18365         .f = cmd_config_per_queue_tx_offload_parsed,
18366         .data = NULL,
18367         .help_str = "port <port_id> txq <queue_id> tx_offload "
18368                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18369                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18370                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18371                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18372                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18373                     "on|off",
18374         .tokens = {
18375                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18376                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18377                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18378                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18379                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18380                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18381                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18382                 NULL,
18383         }
18384 };
18385
18386 /* *** configure tx_metadata for specific port *** */
18387 struct cmd_config_tx_metadata_specific_result {
18388         cmdline_fixed_string_t port;
18389         cmdline_fixed_string_t keyword;
18390         uint16_t port_id;
18391         cmdline_fixed_string_t item;
18392         uint32_t value;
18393 };
18394
18395 static void
18396 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18397                                 __attribute__((unused)) struct cmdline *cl,
18398                                 __attribute__((unused)) void *data)
18399 {
18400         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18401
18402         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18403                 return;
18404         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18405         /* Add/remove callback to insert valid metadata in every Tx packet. */
18406         if (ports[res->port_id].tx_metadata)
18407                 add_tx_md_callback(res->port_id);
18408         else
18409                 remove_tx_md_callback(res->port_id);
18410 }
18411
18412 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18413         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18414                         port, "port");
18415 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18416         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18417                         keyword, "config");
18418 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18419         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18420                         port_id, UINT16);
18421 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18422         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18423                         item, "tx_metadata");
18424 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18425         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18426                         value, UINT32);
18427
18428 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18429         .f = cmd_config_tx_metadata_specific_parsed,
18430         .data = NULL,
18431         .help_str = "port config <port_id> tx_metadata <value>",
18432         .tokens = {
18433                 (void *)&cmd_config_tx_metadata_specific_port,
18434                 (void *)&cmd_config_tx_metadata_specific_keyword,
18435                 (void *)&cmd_config_tx_metadata_specific_id,
18436                 (void *)&cmd_config_tx_metadata_specific_item,
18437                 (void *)&cmd_config_tx_metadata_specific_value,
18438                 NULL,
18439         },
18440 };
18441
18442 /* *** display tx_metadata per port configuration *** */
18443 struct cmd_show_tx_metadata_result {
18444         cmdline_fixed_string_t cmd_show;
18445         cmdline_fixed_string_t cmd_port;
18446         cmdline_fixed_string_t cmd_keyword;
18447         portid_t cmd_pid;
18448 };
18449
18450 static void
18451 cmd_show_tx_metadata_parsed(void *parsed_result,
18452                 __attribute__((unused)) struct cmdline *cl,
18453                 __attribute__((unused)) void *data)
18454 {
18455         struct cmd_show_tx_metadata_result *res = parsed_result;
18456
18457         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18458                 printf("invalid port id %u\n", res->cmd_pid);
18459                 return;
18460         }
18461         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18462                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18463                                 ports[res->cmd_pid].tx_metadata);
18464         }
18465 }
18466
18467 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18468         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18469                         cmd_show, "show");
18470 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18471         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18472                         cmd_port, "port");
18473 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18474         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18475                         cmd_pid, UINT16);
18476 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18477         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18478                         cmd_keyword, "tx_metadata");
18479
18480 cmdline_parse_inst_t cmd_show_tx_metadata = {
18481         .f = cmd_show_tx_metadata_parsed,
18482         .data = NULL,
18483         .help_str = "show port <port_id> tx_metadata",
18484         .tokens = {
18485                 (void *)&cmd_show_tx_metadata_show,
18486                 (void *)&cmd_show_tx_metadata_port,
18487                 (void *)&cmd_show_tx_metadata_pid,
18488                 (void *)&cmd_show_tx_metadata_keyword,
18489                 NULL,
18490         },
18491 };
18492
18493 /* ******************************************************************************** */
18494
18495 /* list of instructions */
18496 cmdline_parse_ctx_t main_ctx[] = {
18497         (cmdline_parse_inst_t *)&cmd_help_brief,
18498         (cmdline_parse_inst_t *)&cmd_help_long,
18499         (cmdline_parse_inst_t *)&cmd_quit,
18500         (cmdline_parse_inst_t *)&cmd_load_from_file,
18501         (cmdline_parse_inst_t *)&cmd_showport,
18502         (cmdline_parse_inst_t *)&cmd_showqueue,
18503         (cmdline_parse_inst_t *)&cmd_showportall,
18504         (cmdline_parse_inst_t *)&cmd_showcfg,
18505         (cmdline_parse_inst_t *)&cmd_start,
18506         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18507         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18508         (cmdline_parse_inst_t *)&cmd_set_link_up,
18509         (cmdline_parse_inst_t *)&cmd_set_link_down,
18510         (cmdline_parse_inst_t *)&cmd_reset,
18511         (cmdline_parse_inst_t *)&cmd_set_numbers,
18512         (cmdline_parse_inst_t *)&cmd_set_log,
18513         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18514         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18515         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18516         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18517         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18518         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18519         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18520         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18521         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18522         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18523         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18524         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18525         (cmdline_parse_inst_t *)&cmd_set_link_check,
18526         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18527         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18528         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18529         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18530 #ifdef RTE_LIBRTE_PMD_BOND
18531         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18532         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18533         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18534         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18535         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18536         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18537         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18538         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18539         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18540         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18541         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18542 #endif
18543         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18544         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18545         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18546         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18547         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18548         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18549         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18550         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18551         (cmdline_parse_inst_t *)&cmd_csum_set,
18552         (cmdline_parse_inst_t *)&cmd_csum_show,
18553         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18554         (cmdline_parse_inst_t *)&cmd_tso_set,
18555         (cmdline_parse_inst_t *)&cmd_tso_show,
18556         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18557         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18558         (cmdline_parse_inst_t *)&cmd_gro_enable,
18559         (cmdline_parse_inst_t *)&cmd_gro_flush,
18560         (cmdline_parse_inst_t *)&cmd_gro_show,
18561         (cmdline_parse_inst_t *)&cmd_gso_enable,
18562         (cmdline_parse_inst_t *)&cmd_gso_size,
18563         (cmdline_parse_inst_t *)&cmd_gso_show,
18564         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18565         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18566         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18567         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18568         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18569         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18570         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18571         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18572         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18573         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18574         (cmdline_parse_inst_t *)&cmd_config_dcb,
18575         (cmdline_parse_inst_t *)&cmd_read_reg,
18576         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18577         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18578         (cmdline_parse_inst_t *)&cmd_write_reg,
18579         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18580         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18581         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18582         (cmdline_parse_inst_t *)&cmd_stop,
18583         (cmdline_parse_inst_t *)&cmd_mac_addr,
18584         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18585         (cmdline_parse_inst_t *)&cmd_set_qmap,
18586         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18587         (cmdline_parse_inst_t *)&cmd_operate_port,
18588         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18589         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18590         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18591         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18592         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18593         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18594         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18595         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18596         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18597         (cmdline_parse_inst_t *)&cmd_config_mtu,
18598         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18599         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18600         (cmdline_parse_inst_t *)&cmd_config_rss,
18601         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18602         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18603         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18604         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18605         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18606         (cmdline_parse_inst_t *)&cmd_showport_reta,
18607         (cmdline_parse_inst_t *)&cmd_config_burst,
18608         (cmdline_parse_inst_t *)&cmd_config_thresh,
18609         (cmdline_parse_inst_t *)&cmd_config_threshold,
18610         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18611         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18612         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18613         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18614         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18615         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18616         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18617         (cmdline_parse_inst_t *)&cmd_global_config,
18618         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18619         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18620         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18621         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18622         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18623         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18624         (cmdline_parse_inst_t *)&cmd_dump,
18625         (cmdline_parse_inst_t *)&cmd_dump_one,
18626         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18627         (cmdline_parse_inst_t *)&cmd_syn_filter,
18628         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18629         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18630         (cmdline_parse_inst_t *)&cmd_flex_filter,
18631         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18632         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18633         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18634         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18635         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18636         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18637         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18638         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18639         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18640         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18641         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18642         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18643         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18644         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18645         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18646         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18647         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18648         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18649         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18650         (cmdline_parse_inst_t *)&cmd_flow,
18651         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18652         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18653         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18654         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18655         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18656         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18657         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18658         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18659         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18660         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18661         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18662         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18663         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18664         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18665         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18666         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18667         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18668         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18669         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18670         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18671         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18672         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18673         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18674         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18675         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18676         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18677         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18678         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18679         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18680         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18681         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18682         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18683         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18684         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18685         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18686         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18687         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18688         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18689         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18690         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18691         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18692         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18693         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18694         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18695         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18696         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18697         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18698         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18699         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18700 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
18701         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
18702 #endif
18703         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18704         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18705         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18706         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18707         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18708         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18709         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18710         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18711         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18712         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18713         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18714         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18715         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18716         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18717         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18718         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18719         (cmdline_parse_inst_t *)&cmd_ddp_add,
18720         (cmdline_parse_inst_t *)&cmd_ddp_del,
18721         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18722         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18723         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18724         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18725         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18726         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18727         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18728         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18729         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18730         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18731
18732         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18733         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18734         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18735         (cmdline_parse_inst_t *)&cmd_queue_region,
18736         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18737         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18738         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18739         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18740         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18741         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18742         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18743         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18744         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18745         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18746         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18747         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18748         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18749         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18750         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18751         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18752         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18753         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18754         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18755         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18756         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18757         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18758         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18759         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18760         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18761         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18762         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18763         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18764         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18765         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18766         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18767         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18768         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18769         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18770         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18771 #ifdef RTE_LIBRTE_BPF
18772         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18773         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18774 #endif
18775         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18776         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18777         NULL,
18778 };
18779
18780 /* read cmdline commands from file */
18781 void
18782 cmdline_read_from_file(const char *filename)
18783 {
18784         struct cmdline *cl;
18785
18786         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18787         if (cl == NULL) {
18788                 printf("Failed to create file based cmdline context: %s\n",
18789                        filename);
18790                 return;
18791         }
18792
18793         cmdline_interact(cl);
18794         cmdline_quit(cl);
18795
18796         cmdline_free(cl);
18797
18798         printf("Read CLI commands from %s\n", filename);
18799 }
18800
18801 /* prompt function, called from main on MASTER lcore */
18802 void
18803 prompt(void)
18804 {
18805         /* initialize non-constant commands */
18806         cmd_set_fwd_mode_init();
18807         cmd_set_fwd_retry_mode_init();
18808
18809         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18810         if (testpmd_cl == NULL)
18811                 return;
18812         cmdline_interact(testpmd_cl);
18813         cmdline_stdin_exit(testpmd_cl);
18814 }
18815
18816 void
18817 prompt_exit(void)
18818 {
18819         if (testpmd_cl != NULL)
18820                 cmdline_quit(testpmd_cl);
18821 }
18822
18823 static void
18824 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18825 {
18826         if (id == (portid_t)RTE_PORT_ALL) {
18827                 portid_t pid;
18828
18829                 RTE_ETH_FOREACH_DEV(pid) {
18830                         /* check if need_reconfig has been set to 1 */
18831                         if (ports[pid].need_reconfig == 0)
18832                                 ports[pid].need_reconfig = dev;
18833                         /* check if need_reconfig_queues has been set to 1 */
18834                         if (ports[pid].need_reconfig_queues == 0)
18835                                 ports[pid].need_reconfig_queues = queue;
18836                 }
18837         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18838                 /* check if need_reconfig has been set to 1 */
18839                 if (ports[id].need_reconfig == 0)
18840                         ports[id].need_reconfig = dev;
18841                 /* check if need_reconfig_queues has been set to 1 */
18842                 if (ports[id].need_reconfig_queues == 0)
18843                         ports[id].need_reconfig_queues = queue;
18844         }
18845 }