app/testpmd: fix crash on port reset
[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_flow.h>
48 #include <rte_gro.h>
49
50 #include <cmdline_rdline.h>
51 #include <cmdline_parse.h>
52 #include <cmdline_parse_num.h>
53 #include <cmdline_parse_string.h>
54 #include <cmdline_parse_ipaddr.h>
55 #include <cmdline_parse_etheraddr.h>
56 #include <cmdline_socket.h>
57 #include <cmdline.h>
58 #ifdef RTE_LIBRTE_PMD_BOND
59 #include <rte_eth_bond.h>
60 #include <rte_eth_bond_8023ad.h>
61 #endif
62 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
63 #include <rte_pmd_dpaa.h>
64 #endif
65 #ifdef RTE_LIBRTE_IXGBE_PMD
66 #include <rte_pmd_ixgbe.h>
67 #endif
68 #ifdef RTE_LIBRTE_I40E_PMD
69 #include <rte_pmd_i40e.h>
70 #endif
71 #ifdef RTE_LIBRTE_BNXT_PMD
72 #include <rte_pmd_bnxt.h>
73 #endif
74 #include "testpmd.h"
75 #include "cmdline_mtr.h"
76 #include "cmdline_tm.h"
77 #include "bpf_cmd.h"
78
79 static struct cmdline *testpmd_cl;
80
81 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
82
83 /* *** Help command with introduction. *** */
84 struct cmd_help_brief_result {
85         cmdline_fixed_string_t help;
86 };
87
88 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
89                                   struct cmdline *cl,
90                                   __attribute__((unused)) void *data)
91 {
92         cmdline_printf(
93                 cl,
94                 "\n"
95                 "Help is available for the following sections:\n\n"
96                 "    help control                    : Start and stop forwarding.\n"
97                 "    help display                    : Displaying port, stats and config "
98                 "information.\n"
99                 "    help config                     : Configuration information.\n"
100                 "    help ports                      : Configuring ports.\n"
101                 "    help registers                  : Reading and setting port registers.\n"
102                 "    help filters                    : Filters configuration help.\n"
103                 "    help traffic_management         : Traffic Management commmands.\n"
104                 "    help devices                    : Device related cmds.\n"
105                 "    help all                        : All of the above sections.\n\n"
106         );
107
108 }
109
110 cmdline_parse_token_string_t cmd_help_brief_help =
111         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
112
113 cmdline_parse_inst_t cmd_help_brief = {
114         .f = cmd_help_brief_parsed,
115         .data = NULL,
116         .help_str = "help: Show help",
117         .tokens = {
118                 (void *)&cmd_help_brief_help,
119                 NULL,
120         },
121 };
122
123 /* *** Help command with help sections. *** */
124 struct cmd_help_long_result {
125         cmdline_fixed_string_t help;
126         cmdline_fixed_string_t section;
127 };
128
129 static void cmd_help_long_parsed(void *parsed_result,
130                                  struct cmdline *cl,
131                                  __attribute__((unused)) void *data)
132 {
133         int show_all = 0;
134         struct cmd_help_long_result *res = parsed_result;
135
136         if (!strcmp(res->section, "all"))
137                 show_all = 1;
138
139         if (show_all || !strcmp(res->section, "control")) {
140
141                 cmdline_printf(
142                         cl,
143                         "\n"
144                         "Control forwarding:\n"
145                         "-------------------\n\n"
146
147                         "start\n"
148                         "    Start packet forwarding with current configuration.\n\n"
149
150                         "start tx_first\n"
151                         "    Start packet forwarding with current config"
152                         " after sending one burst of packets.\n\n"
153
154                         "stop\n"
155                         "    Stop packet forwarding, and display accumulated"
156                         " statistics.\n\n"
157
158                         "quit\n"
159                         "    Quit to prompt.\n\n"
160                 );
161         }
162
163         if (show_all || !strcmp(res->section, "display")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Display:\n"
169                         "--------\n\n"
170
171                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
172                         "    Display information for port_id, or all.\n\n"
173
174                         "show port X rss reta (size) (mask0,mask1,...)\n"
175                         "    Display the rss redirection table entry indicated"
176                         " by masks on port X. size is used to indicate the"
177                         " hardware supported reta size\n\n"
178
179                         "show port (port_id) rss-hash [key]\n"
180                         "    Display the RSS hash functions and RSS hash key of port\n\n"
181
182                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
183                         "    Clear information for port_id, or all.\n\n"
184
185                         "show (rxq|txq) info (port_id) (queue_id)\n"
186                         "    Display information for configured RX/TX queue.\n\n"
187
188                         "show config (rxtx|cores|fwd|txpkts)\n"
189                         "    Display the given configuration.\n\n"
190
191                         "read rxd (port_id) (queue_id) (rxd_id)\n"
192                         "    Display an RX descriptor of a port RX queue.\n\n"
193
194                         "read txd (port_id) (queue_id) (txd_id)\n"
195                         "    Display a TX descriptor of a port TX queue.\n\n"
196
197                         "ddp get list (port_id)\n"
198                         "    Get ddp profile info list\n\n"
199
200                         "ddp get info (profile_path)\n"
201                         "    Get ddp profile information.\n\n"
202
203                         "show vf stats (port_id) (vf_id)\n"
204                         "    Display a VF's statistics.\n\n"
205
206                         "clear vf stats (port_id) (vf_id)\n"
207                         "    Reset a VF's statistics.\n\n"
208
209                         "show port (port_id) pctype mapping\n"
210                         "    Get flow ptype to pctype mapping on a port\n\n"
211
212                         "show port meter stats (port_id) (meter_id) (clear)\n"
213                         "    Get meter stats on a port\n\n"
214
215                         "show fwd stats all\n"
216                         "    Display statistics for all fwd engines.\n\n"
217
218                         "clear fwd stats all\n"
219                         "    Clear statistics for all fwd engines.\n\n"
220
221                         "show port (port_id) rx_offload capabilities\n"
222                         "    List all per queue and per port Rx offloading"
223                         " capabilities of a port\n\n"
224
225                         "show port (port_id) rx_offload configuration\n"
226                         "    List port level and all queue level"
227                         " Rx offloading configuration\n\n"
228
229                         "show port (port_id) tx_offload capabilities\n"
230                         "    List all per queue and per port"
231                         " Tx offloading capabilities of a port\n\n"
232
233                         "show port (port_id) tx_offload configuration\n"
234                         "    List port level and all queue level"
235                         " Tx offloading configuration\n\n"
236
237                         "show port (port_id) tx_metadata\n"
238                         "    Show Tx metadata value set"
239                         " for a specific port\n\n"
240
241                         "show device info (<identifier>|all)"
242                         "       Show general information about devices probed.\n\n"
243                 );
244         }
245
246         if (show_all || !strcmp(res->section, "config")) {
247                 cmdline_printf(
248                         cl,
249                         "\n"
250                         "Configuration:\n"
251                         "--------------\n"
252                         "Configuration changes only become active when"
253                         " forwarding is started/restarted.\n\n"
254
255                         "set default\n"
256                         "    Reset forwarding to the default configuration.\n\n"
257
258                         "set verbose (level)\n"
259                         "    Set the debug verbosity level X.\n\n"
260
261                         "set log global|(type) (level)\n"
262                         "    Set the log level.\n\n"
263
264                         "set nbport (num)\n"
265                         "    Set number of ports.\n\n"
266
267                         "set nbcore (num)\n"
268                         "    Set number of cores.\n\n"
269
270                         "set coremask (mask)\n"
271                         "    Set the forwarding cores hexadecimal mask.\n\n"
272
273                         "set portmask (mask)\n"
274                         "    Set the forwarding ports hexadecimal mask.\n\n"
275
276                         "set burst (num)\n"
277                         "    Set number of packets per burst.\n\n"
278
279                         "set burst tx delay (microseconds) retry (num)\n"
280                         "    Set the transmit delay time and number of retries,"
281                         " effective when retry is enabled.\n\n"
282
283                         "set txpkts (x[,y]*)\n"
284                         "    Set the length of each segment of TXONLY"
285                         " and optionally CSUM packets.\n\n"
286
287                         "set txsplit (off|on|rand)\n"
288                         "    Set the split policy for the TX packets."
289                         " Right now only applicable for CSUM and TXONLY"
290                         " modes\n\n"
291
292                         "set corelist (x[,y]*)\n"
293                         "    Set the list of forwarding cores.\n\n"
294
295                         "set portlist (x[,y]*)\n"
296                         "    Set the list of forwarding ports.\n\n"
297
298                         "set port setup on (iterator|event)\n"
299                         "    Select how attached port is retrieved for setup.\n\n"
300
301                         "set tx loopback (port_id) (on|off)\n"
302                         "    Enable or disable tx loopback.\n\n"
303
304                         "set all queues drop (port_id) (on|off)\n"
305                         "    Set drop enable bit for all queues.\n\n"
306
307                         "set vf split drop (port_id) (vf_id) (on|off)\n"
308                         "    Set split drop enable bit for a VF from the PF.\n\n"
309
310                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
311                         "    Set MAC antispoof for a VF from the PF.\n\n"
312
313                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
314                         "    Enable MACsec offload.\n\n"
315
316                         "set macsec offload (port_id) off\n"
317                         "    Disable MACsec offload.\n\n"
318
319                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
320                         "    Configure MACsec secure connection (SC).\n\n"
321
322                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
323                         "    Configure MACsec secure association (SA).\n\n"
324
325                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
326                         "    Set VF broadcast for a VF from the PF.\n\n"
327
328                         "vlan set strip (on|off) (port_id)\n"
329                         "    Set the VLAN strip on a port.\n\n"
330
331                         "vlan set stripq (on|off) (port_id,queue_id)\n"
332                         "    Set the VLAN strip for a queue on a port.\n\n"
333
334                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
335                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
336
337                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
338                         "    Set VLAN insert for a VF from the PF.\n\n"
339
340                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
341                         "    Set VLAN antispoof for a VF from the PF.\n\n"
342
343                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
344                         "    Set VLAN tag for a VF from the PF.\n\n"
345
346                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
347                         "    Set a VF's max bandwidth(Mbps).\n\n"
348
349                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
350                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
351
352                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
353                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
354
355                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
356                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
357
358                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
359                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
360
361                         "vlan set filter (on|off) (port_id)\n"
362                         "    Set the VLAN filter on a port.\n\n"
363
364                         "vlan set qinq (on|off) (port_id)\n"
365                         "    Set the VLAN QinQ (extended queue in queue)"
366                         " on a port.\n\n"
367
368                         "vlan set (inner|outer) tpid (value) (port_id)\n"
369                         "    Set the VLAN TPID for Packet Filtering on"
370                         " a port\n\n"
371
372                         "rx_vlan add (vlan_id|all) (port_id)\n"
373                         "    Add a vlan_id, or all identifiers, to the set"
374                         " of VLAN identifiers filtered by port_id.\n\n"
375
376                         "rx_vlan rm (vlan_id|all) (port_id)\n"
377                         "    Remove a vlan_id, or all identifiers, from the set"
378                         " of VLAN identifiers filtered by port_id.\n\n"
379
380                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
381                         "    Add a vlan_id, to the set of VLAN identifiers"
382                         "filtered for VF(s) from port_id.\n\n"
383
384                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
385                         "    Remove a vlan_id, to the set of VLAN identifiers"
386                         "filtered for VF(s) from port_id.\n\n"
387
388                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
389                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
390                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
391                         "   add a tunnel filter of a port.\n\n"
392
393                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
394                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
395                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
396                         "   remove a tunnel filter of a port.\n\n"
397
398                         "rx_vxlan_port add (udp_port) (port_id)\n"
399                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
400
401                         "rx_vxlan_port rm (udp_port) (port_id)\n"
402                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
403
404                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
405                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
406                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
407
408                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
409                         "    Set port based TX VLAN insertion.\n\n"
410
411                         "tx_vlan reset (port_id)\n"
412                         "    Disable hardware insertion of a VLAN header in"
413                         " packets sent on a port.\n\n"
414
415                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
416                         "    Select hardware or software calculation of the"
417                         " checksum when transmitting a packet using the"
418                         " csum forward engine.\n"
419                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
420                         "    outer-ip concerns the outer IP layer in"
421                         "    outer-udp concerns the outer UDP layer in"
422                         " case the packet is recognized as a tunnel packet by"
423                         " the forward engine (vxlan, gre and ipip are supported)\n"
424                         "    Please check the NIC datasheet for HW limits.\n\n"
425
426                         "csum parse-tunnel (on|off) (tx_port_id)\n"
427                         "    If disabled, treat tunnel packets as non-tunneled"
428                         " packets (treat inner headers as payload). The port\n"
429                         "    argument is the port used for TX in csum forward"
430                         " engine.\n\n"
431
432                         "csum show (port_id)\n"
433                         "    Display tx checksum offload configuration\n\n"
434
435                         "tso set (segsize) (portid)\n"
436                         "    Enable TCP Segmentation Offload in csum forward"
437                         " engine.\n"
438                         "    Please check the NIC datasheet for HW limits.\n\n"
439
440                         "tso show (portid)"
441                         "    Display the status of TCP Segmentation Offload.\n\n"
442
443                         "set port (port_id) gro on|off\n"
444                         "    Enable or disable Generic Receive Offload in"
445                         " csum forwarding engine.\n\n"
446
447                         "show port (port_id) gro\n"
448                         "    Display GRO configuration.\n\n"
449
450                         "set gro flush (cycles)\n"
451                         "    Set the cycle to flush GROed packets from"
452                         " reassembly tables.\n\n"
453
454                         "set port (port_id) gso (on|off)"
455                         "    Enable or disable Generic Segmentation Offload in"
456                         " csum forwarding engine.\n\n"
457
458                         "set gso segsz (length)\n"
459                         "    Set max packet length for output GSO segments,"
460                         " including packet header and payload.\n\n"
461
462                         "show port (port_id) gso\n"
463                         "    Show GSO configuration.\n\n"
464
465                         "set fwd (%s)\n"
466                         "    Set packet forwarding mode.\n\n"
467
468                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
469                         "    Add a MAC address on port_id.\n\n"
470
471                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
472                         "    Remove a MAC address from port_id.\n\n"
473
474                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Set the default MAC address for port_id.\n\n"
476
477                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
478                         "    Add a MAC address for a VF on the port.\n\n"
479
480                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the MAC address for a VF from the PF.\n\n"
482
483                         "set eth-peer (port_id) (peer_addr)\n"
484                         "    set the peer address for certain port.\n\n"
485
486                         "set port (port_id) uta (mac_address|all) (on|off)\n"
487                         "    Add/Remove a or all unicast hash filter(s)"
488                         "from port X.\n\n"
489
490                         "set promisc (port_id|all) (on|off)\n"
491                         "    Set the promiscuous mode on port_id, or all.\n\n"
492
493                         "set allmulti (port_id|all) (on|off)\n"
494                         "    Set the allmulti mode on port_id, or all.\n\n"
495
496                         "set vf promisc (port_id) (vf_id) (on|off)\n"
497                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
498
499                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
500                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
503                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
504                         " (on|off) autoneg (on|off) (port_id)\n"
505                         "set flow_ctrl rx (on|off) (portid)\n"
506                         "set flow_ctrl tx (on|off) (portid)\n"
507                         "set flow_ctrl high_water (high_water) (portid)\n"
508                         "set flow_ctrl low_water (low_water) (portid)\n"
509                         "set flow_ctrl pause_time (pause_time) (portid)\n"
510                         "set flow_ctrl send_xon (send_xon) (portid)\n"
511                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
512                         "set flow_ctrl autoneg (on|off) (port_id)\n"
513                         "    Set the link flow control parameter on a port.\n\n"
514
515                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
516                         " (low_water) (pause_time) (priority) (port_id)\n"
517                         "    Set the priority flow control parameter on a"
518                         " port.\n\n"
519
520                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
521                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
522                         " queue on port.\n"
523                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
524                         " on port 0 to mapping 5.\n\n"
525
526                         "set xstats-hide-zero on|off\n"
527                         "    Set the option to hide the zero values"
528                         " for xstats display.\n"
529
530                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
531                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
532
533                         "set port (port_id) vf (vf_id) (mac_addr)"
534                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
535                         "   Add/Remove unicast or multicast MAC addr filter"
536                         " for a VF.\n\n"
537
538                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
539                         "|MPE) (on|off)\n"
540                         "    AUPE:accepts untagged VLAN;"
541                         "ROPE:accept unicast hash\n\n"
542                         "    BAM:accepts broadcast packets;"
543                         "MPE:accepts all multicast packets\n\n"
544                         "    Enable/Disable a VF receive mode of a port\n\n"
545
546                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
547                         "    Set rate limit for a queue of a port\n\n"
548
549                         "set port (port_id) vf (vf_id) rate (rate_num) "
550                         "queue_mask (queue_mask_value)\n"
551                         "    Set rate limit for queues in VF of a port\n\n"
552
553                         "set port (port_id) mirror-rule (rule_id)"
554                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
555                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
556                         "   Set pool or vlan type mirror rule on a port.\n"
557                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
558                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
559                         " to pool 0.\n\n"
560
561                         "set port (port_id) mirror-rule (rule_id)"
562                         " (uplink-mirror|downlink-mirror) dst-pool"
563                         " (pool_id) (on|off)\n"
564                         "   Set uplink or downlink type mirror rule on a port.\n"
565                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
566                         " 0 on' enable mirror income traffic to pool 0.\n\n"
567
568                         "reset port (port_id) mirror-rule (rule_id)\n"
569                         "   Reset a mirror rule.\n\n"
570
571                         "set flush_rx (on|off)\n"
572                         "   Flush (default) or don't flush RX streams before"
573                         " forwarding. Mainly used with PCAP drivers.\n\n"
574
575                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
576                         "   Set the bypass mode for the lowest port on bypass enabled"
577                         " NIC.\n\n"
578
579                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
580                         "mode (normal|bypass|isolate) (port_id)\n"
581                         "   Set the event required to initiate specified bypass mode for"
582                         " the lowest port on a bypass enabled NIC where:\n"
583                         "       timeout   = enable bypass after watchdog timeout.\n"
584                         "       os_on     = enable bypass when OS/board is powered on.\n"
585                         "       os_off    = enable bypass when OS/board is powered off.\n"
586                         "       power_on  = enable bypass when power supply is turned on.\n"
587                         "       power_off = enable bypass when power supply is turned off."
588                         "\n\n"
589
590                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
591                         "   Set the bypass watchdog timeout to 'n' seconds"
592                         " where 0 = instant.\n\n"
593
594                         "show bypass config (port_id)\n"
595                         "   Show the bypass configuration for a bypass enabled NIC"
596                         " using the lowest port on the NIC.\n\n"
597
598 #ifdef RTE_LIBRTE_PMD_BOND
599                         "create bonded device (mode) (socket)\n"
600                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
601
602                         "add bonding slave (slave_id) (port_id)\n"
603                         "       Add a slave device to a bonded device.\n\n"
604
605                         "remove bonding slave (slave_id) (port_id)\n"
606                         "       Remove a slave device from a bonded device.\n\n"
607
608                         "set bonding mode (value) (port_id)\n"
609                         "       Set the bonding mode on a bonded device.\n\n"
610
611                         "set bonding primary (slave_id) (port_id)\n"
612                         "       Set the primary slave for a bonded device.\n\n"
613
614                         "show bonding config (port_id)\n"
615                         "       Show the bonding config for port_id.\n\n"
616
617                         "set bonding mac_addr (port_id) (address)\n"
618                         "       Set the MAC address of a bonded device.\n\n"
619
620                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
621                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
622
623                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
624                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
625
626                         "set bonding mon_period (port_id) (value)\n"
627                         "       Set the bonding link status monitoring polling period in ms.\n\n"
628
629                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
630                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
631
632 #endif
633                         "set link-up port (port_id)\n"
634                         "       Set link up for a port.\n\n"
635
636                         "set link-down port (port_id)\n"
637                         "       Set link down for a port.\n\n"
638
639                         "E-tag set insertion on port-tag-id (value)"
640                         " port (port_id) vf (vf_id)\n"
641                         "    Enable E-tag insertion for a VF on a port\n\n"
642
643                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
644                         "    Disable E-tag insertion for a VF on a port\n\n"
645
646                         "E-tag set stripping (on|off) port (port_id)\n"
647                         "    Enable/disable E-tag stripping on a port\n\n"
648
649                         "E-tag set forwarding (on|off) port (port_id)\n"
650                         "    Enable/disable E-tag based forwarding"
651                         " on a port\n\n"
652
653                         "E-tag set filter add e-tag-id (value) dst-pool"
654                         " (pool_id) port (port_id)\n"
655                         "    Add an E-tag forwarding filter on a port\n\n"
656
657                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
658                         "    Delete an E-tag forwarding filter on a port\n\n"
659
660                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
661                         "    Load a profile package on a port\n\n"
662
663                         "ddp del (port_id) (backup_profile_path)\n"
664                         "    Delete a profile package from a port\n\n"
665
666                         "ptype mapping get (port_id) (valid_only)\n"
667                         "    Get ptype mapping on a port\n\n"
668
669                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
670                         "    Replace target with the pkt_type in ptype mapping\n\n"
671
672                         "ptype mapping reset (port_id)\n"
673                         "    Reset ptype mapping on a port\n\n"
674
675                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
676                         "    Update a ptype mapping item on a port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "queue_start_index (value) queue_num (value)\n"
680                         "    Set a queue region on a port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "flowtype (value)\n"
684                         "    Set a flowtype region index on a port\n\n"
685
686                         "set port (port_id) queue-region UP (value) region_id (value)\n"
687                         "    Set the mapping of User Priority to "
688                         "queue region on a port\n\n"
689
690                         "set port (port_id) queue-region flush (on|off)\n"
691                         "    flush all queue region related configuration\n\n"
692
693                         "show port meter cap (port_id)\n"
694                         "    Show port meter capability information\n\n"
695
696                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
697                         "    meter profile add - srtcm rfc 2697\n\n"
698
699                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
700                         "    meter profile add - trtcm rfc 2698\n\n"
701
702                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
703                         "    meter profile add - trtcm rfc 4115\n\n"
704
705                         "del port meter profile (port_id) (profile_id)\n"
706                         "    meter profile delete\n\n"
707
708                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
709                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
710                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
711                         "(dscp_tbl_entry63)]\n"
712                         "    meter create\n\n"
713
714                         "enable port meter (port_id) (mtr_id)\n"
715                         "    meter enable\n\n"
716
717                         "disable port meter (port_id) (mtr_id)\n"
718                         "    meter disable\n\n"
719
720                         "del port meter (port_id) (mtr_id)\n"
721                         "    meter delete\n\n"
722
723                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
724                         "    meter update meter profile\n\n"
725
726                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
727                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
728                         "    update meter dscp table entries\n\n"
729
730                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
731                         "(action0) [(action1) (action2)]\n"
732                         "    meter update policer action\n\n"
733
734                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
735                         "    meter update stats\n\n"
736
737                         "show port (port_id) queue-region\n"
738                         "    show all queue region related configuration info\n\n"
739
740                         , list_pkt_forwarding_modes()
741                 );
742         }
743
744         if (show_all || !strcmp(res->section, "ports")) {
745
746                 cmdline_printf(
747                         cl,
748                         "\n"
749                         "Port Operations:\n"
750                         "----------------\n\n"
751
752                         "port start (port_id|all)\n"
753                         "    Start all ports or port_id.\n\n"
754
755                         "port stop (port_id|all)\n"
756                         "    Stop all ports or port_id.\n\n"
757
758                         "port close (port_id|all)\n"
759                         "    Close all ports or port_id.\n\n"
760
761                         "port reset (port_id|all)\n"
762                         "    Reset all ports or port_id.\n\n"
763
764                         "port attach (ident)\n"
765                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
766
767                         "port detach (port_id)\n"
768                         "    Detach physical or virtual dev by port_id\n\n"
769
770                         "port config (port_id|all)"
771                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
772                         " duplex (half|full|auto)\n"
773                         "    Set speed and duplex for all ports or port_id\n\n"
774
775                         "port config (port_id|all) loopback (mode)\n"
776                         "    Set loopback mode for all ports or port_id\n\n"
777
778                         "port config all (rxq|txq|rxd|txd) (value)\n"
779                         "    Set number for rxq/txq/rxd/txd.\n\n"
780
781                         "port config all max-pkt-len (value)\n"
782                         "    Set the max packet length.\n\n"
783
784                         "port config all drop-en (on|off)\n"
785                         "    Enable or disable packet drop on all RX queues of all ports when no "
786                         "receive buffers available.\n\n"
787
788                         "port config all rss (all|default|ip|tcp|udp|sctp|"
789                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
790                         "    Set the RSS mode.\n\n"
791
792                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
793                         "    Set the RSS redirection table.\n\n"
794
795                         "port config (port_id) dcb vt (on|off) (traffic_class)"
796                         " pfc (on|off)\n"
797                         "    Set the DCB mode.\n\n"
798
799                         "port config all burst (value)\n"
800                         "    Set the number of packets per burst.\n\n"
801
802                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
803                         " (value)\n"
804                         "    Set the ring prefetch/host/writeback threshold"
805                         " for tx/rx queue.\n\n"
806
807                         "port config all (txfreet|txrst|rxfreet) (value)\n"
808                         "    Set free threshold for rx/tx, or set"
809                         " tx rs bit threshold.\n\n"
810                         "port config mtu X value\n"
811                         "    Set the MTU of port X to a given value\n\n"
812
813                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
814                         "    Set a rx/tx queue's ring size configuration, the new"
815                         " value will take effect after command that (re-)start the port"
816                         " or command that setup the specific queue\n\n"
817
818                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
819                         "    Start/stop a rx/tx queue of port X. Only take effect"
820                         " when port X is started\n\n"
821
822                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
823                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
824                         " take effect when port X is stopped.\n\n"
825
826                         "port (port_id) (rxq|txq) (queue_id) setup\n"
827                         "    Setup a rx/tx queue of port X.\n\n"
828
829                         "port config (port_id|all) l2-tunnel E-tag ether-type"
830                         " (value)\n"
831                         "    Set the value of E-tag ether-type.\n\n"
832
833                         "port config (port_id|all) l2-tunnel E-tag"
834                         " (enable|disable)\n"
835                         "    Enable/disable the E-tag support.\n\n"
836
837                         "port config (port_id) pctype mapping reset\n"
838                         "    Reset flow type to pctype mapping on a port\n\n"
839
840                         "port config (port_id) pctype mapping update"
841                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
842                         "    Update a flow type to pctype mapping item on a port\n\n"
843
844                         "port config (port_id) pctype (pctype_id) hash_inset|"
845                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
846                         " (field_idx)\n"
847                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
848
849                         "port config (port_id) pctype (pctype_id) hash_inset|"
850                         "fdir_inset|fdir_flx_inset clear all"
851                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
852
853                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
854                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
855
856                         "port config <port_id> rx_offload vlan_strip|"
857                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
858                         "outer_ipv4_cksum|macsec_strip|header_split|"
859                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
860                         "scatter|timestamp|security|keep_crc on|off\n"
861                         "     Enable or disable a per port Rx offloading"
862                         " on all Rx queues of a port\n\n"
863
864                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
865                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
866                         "outer_ipv4_cksum|macsec_strip|header_split|"
867                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
868                         "scatter|timestamp|security|keep_crc on|off\n"
869                         "    Enable or disable a per queue Rx offloading"
870                         " only on a specific Rx queue\n\n"
871
872                         "port config (port_id) tx_offload vlan_insert|"
873                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
874                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
875                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
876                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
877                         "security|match_metadata on|off\n"
878                         "    Enable or disable a per port Tx offloading"
879                         " on all Tx queues of a port\n\n"
880
881                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
882                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
883                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
884                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
885                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
886                         " on|off\n"
887                         "    Enable or disable a per queue Tx offloading"
888                         " only on a specific Tx queue\n\n"
889
890                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
891                         "    Load an eBPF program as a callback"
892                         " for particular RX/TX queue\n\n"
893
894                         "bpf-unload rx|tx (port) (queue)\n"
895                         "    Unload previously loaded eBPF program"
896                         " for particular RX/TX queue\n\n"
897
898                         "port config (port_id) tx_metadata (value)\n"
899                         "    Set Tx metadata value per port. Testpmd will add this value"
900                         " to any Tx packet sent from this port\n\n"
901                 );
902         }
903
904         if (show_all || !strcmp(res->section, "registers")) {
905
906                 cmdline_printf(
907                         cl,
908                         "\n"
909                         "Registers:\n"
910                         "----------\n\n"
911
912                         "read reg (port_id) (address)\n"
913                         "    Display value of a port register.\n\n"
914
915                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
916                         "    Display a port register bit field.\n\n"
917
918                         "read regbit (port_id) (address) (bit_x)\n"
919                         "    Display a single port register bit.\n\n"
920
921                         "write reg (port_id) (address) (value)\n"
922                         "    Set value of a port register.\n\n"
923
924                         "write regfield (port_id) (address) (bit_x) (bit_y)"
925                         " (value)\n"
926                         "    Set bit field of a port register.\n\n"
927
928                         "write regbit (port_id) (address) (bit_x) (value)\n"
929                         "    Set single bit value of a port register.\n\n"
930                 );
931         }
932         if (show_all || !strcmp(res->section, "filters")) {
933
934                 cmdline_printf(
935                         cl,
936                         "\n"
937                         "filters:\n"
938                         "--------\n\n"
939
940                         "ethertype_filter (port_id) (add|del)"
941                         " (mac_addr|mac_ignr) (mac_address) ethertype"
942                         " (ether_type) (drop|fwd) queue (queue_id)\n"
943                         "    Add/Del an ethertype filter.\n\n"
944
945                         "2tuple_filter (port_id) (add|del)"
946                         " dst_port (dst_port_value) protocol (protocol_value)"
947                         " mask (mask_value) tcp_flags (tcp_flags_value)"
948                         " priority (prio_value) queue (queue_id)\n"
949                         "    Add/Del a 2tuple filter.\n\n"
950
951                         "5tuple_filter (port_id) (add|del)"
952                         " dst_ip (dst_address) src_ip (src_address)"
953                         " dst_port (dst_port_value) src_port (src_port_value)"
954                         " protocol (protocol_value)"
955                         " mask (mask_value) tcp_flags (tcp_flags_value)"
956                         " priority (prio_value) queue (queue_id)\n"
957                         "    Add/Del a 5tuple filter.\n\n"
958
959                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
960                         "    Add/Del syn filter.\n\n"
961
962                         "flex_filter (port_id) (add|del) len (len_value)"
963                         " bytes (bytes_value) mask (mask_value)"
964                         " priority (prio_value) queue (queue_id)\n"
965                         "    Add/Del a flex filter.\n\n"
966
967                         "flow_director_filter (port_id) mode IP (add|del|update)"
968                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
969                         " src (src_ip_address) dst (dst_ip_address)"
970                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
971                         " vlan (vlan_value) flexbytes (flexbytes_value)"
972                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
973                         " fd_id (fd_id_value)\n"
974                         "    Add/Del an IP type flow director filter.\n\n"
975
976                         "flow_director_filter (port_id) mode IP (add|del|update)"
977                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
978                         " src (src_ip_address) (src_port)"
979                         " dst (dst_ip_address) (dst_port)"
980                         " tos (tos_value) ttl (ttl_value)"
981                         " vlan (vlan_value) flexbytes (flexbytes_value)"
982                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
983                         " fd_id (fd_id_value)\n"
984                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
985
986                         "flow_director_filter (port_id) mode IP (add|del|update)"
987                         " flow (ipv4-sctp|ipv6-sctp)"
988                         " src (src_ip_address) (src_port)"
989                         " dst (dst_ip_address) (dst_port)"
990                         " tag (verification_tag) "
991                         " tos (tos_value) ttl (ttl_value)"
992                         " vlan (vlan_value)"
993                         " flexbytes (flexbytes_value) (drop|fwd)"
994                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
995                         "    Add/Del a SCTP type flow director filter.\n\n"
996
997                         "flow_director_filter (port_id) mode IP (add|del|update)"
998                         " flow l2_payload ether (ethertype)"
999                         " flexbytes (flexbytes_value) (drop|fwd)"
1000                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1001                         "    Add/Del a l2 payload type flow director filter.\n\n"
1002
1003                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1004                         " mac (mac_address) vlan (vlan_value)"
1005                         " flexbytes (flexbytes_value) (drop|fwd)"
1006                         " queue (queue_id) fd_id (fd_id_value)\n"
1007                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1008
1009                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1010                         " mac (mac_address) vlan (vlan_value)"
1011                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1012                         " flexbytes (flexbytes_value) (drop|fwd)"
1013                         " queue (queue_id) fd_id (fd_id_value)\n"
1014                         "    Add/Del a Tunnel flow director filter.\n\n"
1015
1016                         "flow_director_filter (port_id) mode raw (add|del|update)"
1017                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1018                         " fd_id (fd_id_value) packet (packet file name)\n"
1019                         "    Add/Del a raw type flow director filter.\n\n"
1020
1021                         "flush_flow_director (port_id)\n"
1022                         "    Flush all flow director entries of a device.\n\n"
1023
1024                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1025                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1026                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1027                         "    Set flow director IP mask.\n\n"
1028
1029                         "flow_director_mask (port_id) mode MAC-VLAN"
1030                         " vlan (vlan_value)\n"
1031                         "    Set flow director MAC-VLAN mask.\n\n"
1032
1033                         "flow_director_mask (port_id) mode Tunnel"
1034                         " vlan (vlan_value) mac (mac_value)"
1035                         " tunnel-type (tunnel_type_value)"
1036                         " tunnel-id (tunnel_id_value)\n"
1037                         "    Set flow director Tunnel mask.\n\n"
1038
1039                         "flow_director_flex_mask (port_id)"
1040                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1041                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1042                         " (mask)\n"
1043                         "    Configure mask of flex payload.\n\n"
1044
1045                         "flow_director_flex_payload (port_id)"
1046                         " (raw|l2|l3|l4) (config)\n"
1047                         "    Configure flex payload selection.\n\n"
1048
1049                         "get_sym_hash_ena_per_port (port_id)\n"
1050                         "    get symmetric hash enable configuration per port.\n\n"
1051
1052                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1053                         "    set symmetric hash enable configuration per port"
1054                         " to enable or disable.\n\n"
1055
1056                         "get_hash_global_config (port_id)\n"
1057                         "    Get the global configurations of hash filters.\n\n"
1058
1059                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1060                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1061                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1062                         " (enable|disable)\n"
1063                         "    Set the global configurations of hash filters.\n\n"
1064
1065                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1066                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1067                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1068                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1069                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1070                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1071                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1072                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1073                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1074                         "fld-8th|none) (select|add)\n"
1075                         "    Set the input set for hash.\n\n"
1076
1077                         "set_fdir_input_set (port_id) "
1078                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1079                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1080                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1081                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1082                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1083                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1084                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1085                         " (select|add)\n"
1086                         "    Set the input set for FDir.\n\n"
1087
1088                         "flow validate {port_id}"
1089                         " [group {group_id}] [priority {level}]"
1090                         " [ingress] [egress]"
1091                         " pattern {item} [/ {item} [...]] / end"
1092                         " actions {action} [/ {action} [...]] / end\n"
1093                         "    Check whether a flow rule can be created.\n\n"
1094
1095                         "flow create {port_id}"
1096                         " [group {group_id}] [priority {level}]"
1097                         " [ingress] [egress]"
1098                         " pattern {item} [/ {item} [...]] / end"
1099                         " actions {action} [/ {action} [...]] / end\n"
1100                         "    Create a flow rule.\n\n"
1101
1102                         "flow destroy {port_id} rule {rule_id} [...]\n"
1103                         "    Destroy specific flow rules.\n\n"
1104
1105                         "flow flush {port_id}\n"
1106                         "    Destroy all flow rules.\n\n"
1107
1108                         "flow query {port_id} {rule_id} {action}\n"
1109                         "    Query an existing flow rule.\n\n"
1110
1111                         "flow list {port_id} [group {group_id}] [...]\n"
1112                         "    List existing flow rules sorted by priority,"
1113                         " filtered by group identifiers.\n\n"
1114
1115                         "flow isolate {port_id} {boolean}\n"
1116                         "    Restrict ingress traffic to the defined"
1117                         " flow rules\n\n"
1118
1119                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1120                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1121                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1122                         "       Configure the VXLAN encapsulation for flows.\n\n"
1123
1124                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1125                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1126                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1127                         " eth-dst (eth-dst)\n"
1128                         "       Configure the VXLAN encapsulation for flows.\n\n"
1129
1130                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1131                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1132                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1133                         " eth-dst (eth-dst)\n"
1134                         "       Configure the VXLAN encapsulation for flows.\n\n"
1135
1136                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1137                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1138                         " (eth-dst)\n"
1139                         "       Configure the NVGRE encapsulation for flows.\n\n"
1140
1141                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1142                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1143                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1144                         "       Configure the NVGRE encapsulation for flows.\n\n"
1145
1146                         "set raw_encap {flow items}\n"
1147                         "       Configure the encapsulation with raw data.\n\n"
1148
1149                         "set raw_decap {flow items}\n"
1150                         "       Configure the decapsulation with raw data.\n\n"
1151
1152                 );
1153         }
1154
1155         if (show_all || !strcmp(res->section, "traffic_management")) {
1156                 cmdline_printf(
1157                         cl,
1158                         "\n"
1159                         "Traffic Management:\n"
1160                         "--------------\n"
1161                         "show port tm cap (port_id)\n"
1162                         "       Display the port TM capability.\n\n"
1163
1164                         "show port tm level cap (port_id) (level_id)\n"
1165                         "       Display the port TM hierarchical level capability.\n\n"
1166
1167                         "show port tm node cap (port_id) (node_id)\n"
1168                         "       Display the port TM node capability.\n\n"
1169
1170                         "show port tm node type (port_id) (node_id)\n"
1171                         "       Display the port TM node type.\n\n"
1172
1173                         "show port tm node stats (port_id) (node_id) (clear)\n"
1174                         "       Display the port TM node stats.\n\n"
1175
1176 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1177                         "set port tm hierarchy default (port_id)\n"
1178                         "       Set default traffic Management hierarchy on a port\n\n"
1179 #endif
1180
1181                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1182                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1183                         " (packet_length_adjust)\n"
1184                         "       Add port tm node private shaper profile.\n\n"
1185
1186                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1187                         "       Delete port tm node private shaper profile.\n\n"
1188
1189                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1190                         " (shaper_profile_id)\n"
1191                         "       Add/update port tm node shared shaper.\n\n"
1192
1193                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1194                         "       Delete port tm node shared shaper.\n\n"
1195
1196                         "set port tm node shaper profile (port_id) (node_id)"
1197                         " (shaper_profile_id)\n"
1198                         "       Set port tm node shaper profile.\n\n"
1199
1200                         "add port tm node wred profile (port_id) (wred_profile_id)"
1201                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1202                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1203                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1204                         "       Add port tm node wred profile.\n\n"
1205
1206                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1207                         "       Delete port tm node wred profile.\n\n"
1208
1209                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1210                         " (priority) (weight) (level_id) (shaper_profile_id)"
1211                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1212                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1213                         "       Add port tm nonleaf node.\n\n"
1214
1215                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1216                         " (priority) (weight) (level_id) (shaper_profile_id)"
1217                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1218                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1219                         "       Add port tm leaf node.\n\n"
1220
1221                         "del port tm node (port_id) (node_id)\n"
1222                         "       Delete port tm node.\n\n"
1223
1224                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1225                         " (priority) (weight)\n"
1226                         "       Set port tm node parent.\n\n"
1227
1228                         "suspend port tm node (port_id) (node_id)"
1229                         "       Suspend tm node.\n\n"
1230
1231                         "resume port tm node (port_id) (node_id)"
1232                         "       Resume tm node.\n\n"
1233
1234                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1235                         "       Commit tm hierarchy.\n\n"
1236
1237                         "set port tm mark ip_ecn (port) (green) (yellow)"
1238                         " (red)\n"
1239                         "    Enables/Disables the traffic management marking"
1240                         " for IP ECN (Explicit Congestion Notification)"
1241                         " packets on a given port\n\n"
1242
1243                         "set port tm mark ip_dscp (port) (green) (yellow)"
1244                         " (red)\n"
1245                         "    Enables/Disables the traffic management marking"
1246                         " on the port for IP dscp packets\n\n"
1247
1248                         "set port tm mark vlan_dei (port) (green) (yellow)"
1249                         " (red)\n"
1250                         "    Enables/Disables the traffic management marking"
1251                         " on the port for VLAN packets with DEI enabled\n\n"
1252                 );
1253         }
1254
1255         if (show_all || !strcmp(res->section, "devices")) {
1256                 cmdline_printf(
1257                         cl,
1258                         "\n"
1259                         "Device Operations:\n"
1260                         "--------------\n"
1261                         "device detach (identifier)\n"
1262                         "       Detach device by identifier.\n\n"
1263                 );
1264         }
1265
1266 }
1267
1268 cmdline_parse_token_string_t cmd_help_long_help =
1269         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1270
1271 cmdline_parse_token_string_t cmd_help_long_section =
1272         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1273                         "all#control#display#config#"
1274                         "ports#registers#filters#traffic_management#devices");
1275
1276 cmdline_parse_inst_t cmd_help_long = {
1277         .f = cmd_help_long_parsed,
1278         .data = NULL,
1279         .help_str = "help all|control|display|config|ports|register|"
1280                 "filters|traffic_management|devices: "
1281                 "Show help",
1282         .tokens = {
1283                 (void *)&cmd_help_long_help,
1284                 (void *)&cmd_help_long_section,
1285                 NULL,
1286         },
1287 };
1288
1289
1290 /* *** start/stop/close all ports *** */
1291 struct cmd_operate_port_result {
1292         cmdline_fixed_string_t keyword;
1293         cmdline_fixed_string_t name;
1294         cmdline_fixed_string_t value;
1295 };
1296
1297 static void cmd_operate_port_parsed(void *parsed_result,
1298                                 __attribute__((unused)) struct cmdline *cl,
1299                                 __attribute__((unused)) void *data)
1300 {
1301         struct cmd_operate_port_result *res = parsed_result;
1302
1303         if (!strcmp(res->name, "start"))
1304                 start_port(RTE_PORT_ALL);
1305         else if (!strcmp(res->name, "stop"))
1306                 stop_port(RTE_PORT_ALL);
1307         else if (!strcmp(res->name, "close"))
1308                 close_port(RTE_PORT_ALL);
1309         else if (!strcmp(res->name, "reset"))
1310                 reset_port(RTE_PORT_ALL);
1311         else
1312                 printf("Unknown parameter\n");
1313 }
1314
1315 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1316         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1317                                                                 "port");
1318 cmdline_parse_token_string_t cmd_operate_port_all_port =
1319         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1320                                                 "start#stop#close#reset");
1321 cmdline_parse_token_string_t cmd_operate_port_all_all =
1322         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1323
1324 cmdline_parse_inst_t cmd_operate_port = {
1325         .f = cmd_operate_port_parsed,
1326         .data = NULL,
1327         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1328         .tokens = {
1329                 (void *)&cmd_operate_port_all_cmd,
1330                 (void *)&cmd_operate_port_all_port,
1331                 (void *)&cmd_operate_port_all_all,
1332                 NULL,
1333         },
1334 };
1335
1336 /* *** start/stop/close specific port *** */
1337 struct cmd_operate_specific_port_result {
1338         cmdline_fixed_string_t keyword;
1339         cmdline_fixed_string_t name;
1340         uint8_t value;
1341 };
1342
1343 static void cmd_operate_specific_port_parsed(void *parsed_result,
1344                         __attribute__((unused)) struct cmdline *cl,
1345                                 __attribute__((unused)) void *data)
1346 {
1347         struct cmd_operate_specific_port_result *res = parsed_result;
1348
1349         if (!strcmp(res->name, "start"))
1350                 start_port(res->value);
1351         else if (!strcmp(res->name, "stop"))
1352                 stop_port(res->value);
1353         else if (!strcmp(res->name, "close"))
1354                 close_port(res->value);
1355         else if (!strcmp(res->name, "reset"))
1356                 reset_port(res->value);
1357         else
1358                 printf("Unknown parameter\n");
1359 }
1360
1361 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1362         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1363                                                         keyword, "port");
1364 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1365         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1366                                                 name, "start#stop#close#reset");
1367 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1368         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1369                                                         value, UINT8);
1370
1371 cmdline_parse_inst_t cmd_operate_specific_port = {
1372         .f = cmd_operate_specific_port_parsed,
1373         .data = NULL,
1374         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1375         .tokens = {
1376                 (void *)&cmd_operate_specific_port_cmd,
1377                 (void *)&cmd_operate_specific_port_port,
1378                 (void *)&cmd_operate_specific_port_id,
1379                 NULL,
1380         },
1381 };
1382
1383 /* *** enable port setup (after attach) via iterator or event *** */
1384 struct cmd_set_port_setup_on_result {
1385         cmdline_fixed_string_t set;
1386         cmdline_fixed_string_t port;
1387         cmdline_fixed_string_t setup;
1388         cmdline_fixed_string_t on;
1389         cmdline_fixed_string_t mode;
1390 };
1391
1392 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1393                                 __attribute__((unused)) struct cmdline *cl,
1394                                 __attribute__((unused)) void *data)
1395 {
1396         struct cmd_set_port_setup_on_result *res = parsed_result;
1397
1398         if (strcmp(res->mode, "event") == 0)
1399                 setup_on_probe_event = true;
1400         else if (strcmp(res->mode, "iterator") == 0)
1401                 setup_on_probe_event = false;
1402         else
1403                 printf("Unknown mode\n");
1404 }
1405
1406 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1407         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1408                         set, "set");
1409 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1410         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1411                         port, "port");
1412 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1413         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1414                         setup, "setup");
1415 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1416         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1417                         on, "on");
1418 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1419         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1420                         mode, "iterator#event");
1421
1422 cmdline_parse_inst_t cmd_set_port_setup_on = {
1423         .f = cmd_set_port_setup_on_parsed,
1424         .data = NULL,
1425         .help_str = "set port setup on iterator|event",
1426         .tokens = {
1427                 (void *)&cmd_set_port_setup_on_set,
1428                 (void *)&cmd_set_port_setup_on_port,
1429                 (void *)&cmd_set_port_setup_on_setup,
1430                 (void *)&cmd_set_port_setup_on_on,
1431                 (void *)&cmd_set_port_setup_on_mode,
1432                 NULL,
1433         },
1434 };
1435
1436 /* *** attach a specified port *** */
1437 struct cmd_operate_attach_port_result {
1438         cmdline_fixed_string_t port;
1439         cmdline_fixed_string_t keyword;
1440         cmdline_fixed_string_t identifier;
1441 };
1442
1443 static void cmd_operate_attach_port_parsed(void *parsed_result,
1444                                 __attribute__((unused)) struct cmdline *cl,
1445                                 __attribute__((unused)) void *data)
1446 {
1447         struct cmd_operate_attach_port_result *res = parsed_result;
1448
1449         if (!strcmp(res->keyword, "attach"))
1450                 attach_port(res->identifier);
1451         else
1452                 printf("Unknown parameter\n");
1453 }
1454
1455 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1456         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1457                         port, "port");
1458 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1459         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1460                         keyword, "attach");
1461 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1462         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1463                         identifier, NULL);
1464
1465 cmdline_parse_inst_t cmd_operate_attach_port = {
1466         .f = cmd_operate_attach_port_parsed,
1467         .data = NULL,
1468         .help_str = "port attach <identifier>: "
1469                 "(identifier: pci address or virtual dev name)",
1470         .tokens = {
1471                 (void *)&cmd_operate_attach_port_port,
1472                 (void *)&cmd_operate_attach_port_keyword,
1473                 (void *)&cmd_operate_attach_port_identifier,
1474                 NULL,
1475         },
1476 };
1477
1478 /* *** detach a specified port *** */
1479 struct cmd_operate_detach_port_result {
1480         cmdline_fixed_string_t port;
1481         cmdline_fixed_string_t keyword;
1482         portid_t port_id;
1483 };
1484
1485 static void cmd_operate_detach_port_parsed(void *parsed_result,
1486                                 __attribute__((unused)) struct cmdline *cl,
1487                                 __attribute__((unused)) void *data)
1488 {
1489         struct cmd_operate_detach_port_result *res = parsed_result;
1490
1491         if (!strcmp(res->keyword, "detach"))
1492                 detach_port_device(res->port_id);
1493         else
1494                 printf("Unknown parameter\n");
1495 }
1496
1497 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1498         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1499                         port, "port");
1500 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1501         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1502                         keyword, "detach");
1503 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1504         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1505                         port_id, UINT16);
1506
1507 cmdline_parse_inst_t cmd_operate_detach_port = {
1508         .f = cmd_operate_detach_port_parsed,
1509         .data = NULL,
1510         .help_str = "port detach <port_id>",
1511         .tokens = {
1512                 (void *)&cmd_operate_detach_port_port,
1513                 (void *)&cmd_operate_detach_port_keyword,
1514                 (void *)&cmd_operate_detach_port_port_id,
1515                 NULL,
1516         },
1517 };
1518
1519 /* *** detach device by identifier *** */
1520 struct cmd_operate_detach_device_result {
1521         cmdline_fixed_string_t device;
1522         cmdline_fixed_string_t keyword;
1523         cmdline_fixed_string_t identifier;
1524 };
1525
1526 static void cmd_operate_detach_device_parsed(void *parsed_result,
1527                                 __attribute__((unused)) struct cmdline *cl,
1528                                 __attribute__((unused)) void *data)
1529 {
1530         struct cmd_operate_detach_device_result *res = parsed_result;
1531
1532         if (!strcmp(res->keyword, "detach"))
1533                 detach_device(res->identifier);
1534         else
1535                 printf("Unknown parameter\n");
1536 }
1537
1538 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1539         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1540                         device, "device");
1541 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1542         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1543                         keyword, "detach");
1544 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1545         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1546                         identifier, NULL);
1547
1548 cmdline_parse_inst_t cmd_operate_detach_device = {
1549         .f = cmd_operate_detach_device_parsed,
1550         .data = NULL,
1551         .help_str = "device detach <identifier>:"
1552                 "(identifier: pci address or virtual dev name)",
1553         .tokens = {
1554                 (void *)&cmd_operate_detach_device_device,
1555                 (void *)&cmd_operate_detach_device_keyword,
1556                 (void *)&cmd_operate_detach_device_identifier,
1557                 NULL,
1558         },
1559 };
1560 /* *** configure speed for all ports *** */
1561 struct cmd_config_speed_all {
1562         cmdline_fixed_string_t port;
1563         cmdline_fixed_string_t keyword;
1564         cmdline_fixed_string_t all;
1565         cmdline_fixed_string_t item1;
1566         cmdline_fixed_string_t item2;
1567         cmdline_fixed_string_t value1;
1568         cmdline_fixed_string_t value2;
1569 };
1570
1571 static int
1572 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1573 {
1574
1575         int duplex;
1576
1577         if (!strcmp(duplexstr, "half")) {
1578                 duplex = ETH_LINK_HALF_DUPLEX;
1579         } else if (!strcmp(duplexstr, "full")) {
1580                 duplex = ETH_LINK_FULL_DUPLEX;
1581         } else if (!strcmp(duplexstr, "auto")) {
1582                 duplex = ETH_LINK_FULL_DUPLEX;
1583         } else {
1584                 printf("Unknown duplex parameter\n");
1585                 return -1;
1586         }
1587
1588         if (!strcmp(speedstr, "10")) {
1589                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1590                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1591         } else if (!strcmp(speedstr, "100")) {
1592                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1593                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1594         } else {
1595                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1596                         printf("Invalid speed/duplex parameters\n");
1597                         return -1;
1598                 }
1599                 if (!strcmp(speedstr, "1000")) {
1600                         *speed = ETH_LINK_SPEED_1G;
1601                 } else if (!strcmp(speedstr, "10000")) {
1602                         *speed = ETH_LINK_SPEED_10G;
1603                 } else if (!strcmp(speedstr, "25000")) {
1604                         *speed = ETH_LINK_SPEED_25G;
1605                 } else if (!strcmp(speedstr, "40000")) {
1606                         *speed = ETH_LINK_SPEED_40G;
1607                 } else if (!strcmp(speedstr, "50000")) {
1608                         *speed = ETH_LINK_SPEED_50G;
1609                 } else if (!strcmp(speedstr, "100000")) {
1610                         *speed = ETH_LINK_SPEED_100G;
1611                 } else if (!strcmp(speedstr, "auto")) {
1612                         *speed = ETH_LINK_SPEED_AUTONEG;
1613                 } else {
1614                         printf("Unknown speed parameter\n");
1615                         return -1;
1616                 }
1617         }
1618
1619         return 0;
1620 }
1621
1622 static void
1623 cmd_config_speed_all_parsed(void *parsed_result,
1624                         __attribute__((unused)) struct cmdline *cl,
1625                         __attribute__((unused)) void *data)
1626 {
1627         struct cmd_config_speed_all *res = parsed_result;
1628         uint32_t link_speed;
1629         portid_t pid;
1630
1631         if (!all_ports_stopped()) {
1632                 printf("Please stop all ports first\n");
1633                 return;
1634         }
1635
1636         if (parse_and_check_speed_duplex(res->value1, res->value2,
1637                         &link_speed) < 0)
1638                 return;
1639
1640         RTE_ETH_FOREACH_DEV(pid) {
1641                 ports[pid].dev_conf.link_speeds = link_speed;
1642         }
1643
1644         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1645 }
1646
1647 cmdline_parse_token_string_t cmd_config_speed_all_port =
1648         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1649 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1650         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1651                                                         "config");
1652 cmdline_parse_token_string_t cmd_config_speed_all_all =
1653         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1654 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1655         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1656 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1657         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1658                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1659 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1660         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1661 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1662         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1663                                                 "half#full#auto");
1664
1665 cmdline_parse_inst_t cmd_config_speed_all = {
1666         .f = cmd_config_speed_all_parsed,
1667         .data = NULL,
1668         .help_str = "port config all speed "
1669                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1670                                                         "half|full|auto",
1671         .tokens = {
1672                 (void *)&cmd_config_speed_all_port,
1673                 (void *)&cmd_config_speed_all_keyword,
1674                 (void *)&cmd_config_speed_all_all,
1675                 (void *)&cmd_config_speed_all_item1,
1676                 (void *)&cmd_config_speed_all_value1,
1677                 (void *)&cmd_config_speed_all_item2,
1678                 (void *)&cmd_config_speed_all_value2,
1679                 NULL,
1680         },
1681 };
1682
1683 /* *** configure speed for specific port *** */
1684 struct cmd_config_speed_specific {
1685         cmdline_fixed_string_t port;
1686         cmdline_fixed_string_t keyword;
1687         portid_t id;
1688         cmdline_fixed_string_t item1;
1689         cmdline_fixed_string_t item2;
1690         cmdline_fixed_string_t value1;
1691         cmdline_fixed_string_t value2;
1692 };
1693
1694 static void
1695 cmd_config_speed_specific_parsed(void *parsed_result,
1696                                 __attribute__((unused)) struct cmdline *cl,
1697                                 __attribute__((unused)) void *data)
1698 {
1699         struct cmd_config_speed_specific *res = parsed_result;
1700         uint32_t link_speed;
1701
1702         if (!all_ports_stopped()) {
1703                 printf("Please stop all ports first\n");
1704                 return;
1705         }
1706
1707         if (port_id_is_invalid(res->id, ENABLED_WARN))
1708                 return;
1709
1710         if (parse_and_check_speed_duplex(res->value1, res->value2,
1711                         &link_speed) < 0)
1712                 return;
1713
1714         ports[res->id].dev_conf.link_speeds = link_speed;
1715
1716         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1717 }
1718
1719
1720 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1722                                                                 "port");
1723 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1724         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1725                                                                 "config");
1726 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1727         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1728 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1729         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1730                                                                 "speed");
1731 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1733                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1734 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1735         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1736                                                                 "duplex");
1737 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1738         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1739                                                         "half#full#auto");
1740
1741 cmdline_parse_inst_t cmd_config_speed_specific = {
1742         .f = cmd_config_speed_specific_parsed,
1743         .data = NULL,
1744         .help_str = "port config <port_id> speed "
1745                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1746                                                         "half|full|auto",
1747         .tokens = {
1748                 (void *)&cmd_config_speed_specific_port,
1749                 (void *)&cmd_config_speed_specific_keyword,
1750                 (void *)&cmd_config_speed_specific_id,
1751                 (void *)&cmd_config_speed_specific_item1,
1752                 (void *)&cmd_config_speed_specific_value1,
1753                 (void *)&cmd_config_speed_specific_item2,
1754                 (void *)&cmd_config_speed_specific_value2,
1755                 NULL,
1756         },
1757 };
1758
1759 /* *** configure loopback for all ports *** */
1760 struct cmd_config_loopback_all {
1761         cmdline_fixed_string_t port;
1762         cmdline_fixed_string_t keyword;
1763         cmdline_fixed_string_t all;
1764         cmdline_fixed_string_t item;
1765         uint32_t mode;
1766 };
1767
1768 static void
1769 cmd_config_loopback_all_parsed(void *parsed_result,
1770                         __attribute__((unused)) struct cmdline *cl,
1771                         __attribute__((unused)) void *data)
1772 {
1773         struct cmd_config_loopback_all *res = parsed_result;
1774         portid_t pid;
1775
1776         if (!all_ports_stopped()) {
1777                 printf("Please stop all ports first\n");
1778                 return;
1779         }
1780
1781         RTE_ETH_FOREACH_DEV(pid) {
1782                 ports[pid].dev_conf.lpbk_mode = res->mode;
1783         }
1784
1785         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1786 }
1787
1788 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1789         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1790 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1792                                                         "config");
1793 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1794         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1795 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1796         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1797                                                         "loopback");
1798 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1799         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1800
1801 cmdline_parse_inst_t cmd_config_loopback_all = {
1802         .f = cmd_config_loopback_all_parsed,
1803         .data = NULL,
1804         .help_str = "port config all loopback <mode>",
1805         .tokens = {
1806                 (void *)&cmd_config_loopback_all_port,
1807                 (void *)&cmd_config_loopback_all_keyword,
1808                 (void *)&cmd_config_loopback_all_all,
1809                 (void *)&cmd_config_loopback_all_item,
1810                 (void *)&cmd_config_loopback_all_mode,
1811                 NULL,
1812         },
1813 };
1814
1815 /* *** configure loopback for specific port *** */
1816 struct cmd_config_loopback_specific {
1817         cmdline_fixed_string_t port;
1818         cmdline_fixed_string_t keyword;
1819         uint16_t port_id;
1820         cmdline_fixed_string_t item;
1821         uint32_t mode;
1822 };
1823
1824 static void
1825 cmd_config_loopback_specific_parsed(void *parsed_result,
1826                                 __attribute__((unused)) struct cmdline *cl,
1827                                 __attribute__((unused)) void *data)
1828 {
1829         struct cmd_config_loopback_specific *res = parsed_result;
1830
1831         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1832                 return;
1833
1834         if (!port_is_stopped(res->port_id)) {
1835                 printf("Please stop port %u first\n", res->port_id);
1836                 return;
1837         }
1838
1839         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1840
1841         cmd_reconfig_device_queue(res->port_id, 1, 1);
1842 }
1843
1844
1845 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1847                                                                 "port");
1848 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1850                                                                 "config");
1851 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1852         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1853                                                                 UINT16);
1854 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1855         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1856                                                                 "loopback");
1857 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1858         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1859                               UINT32);
1860
1861 cmdline_parse_inst_t cmd_config_loopback_specific = {
1862         .f = cmd_config_loopback_specific_parsed,
1863         .data = NULL,
1864         .help_str = "port config <port_id> loopback <mode>",
1865         .tokens = {
1866                 (void *)&cmd_config_loopback_specific_port,
1867                 (void *)&cmd_config_loopback_specific_keyword,
1868                 (void *)&cmd_config_loopback_specific_id,
1869                 (void *)&cmd_config_loopback_specific_item,
1870                 (void *)&cmd_config_loopback_specific_mode,
1871                 NULL,
1872         },
1873 };
1874
1875 /* *** configure txq/rxq, txd/rxd *** */
1876 struct cmd_config_rx_tx {
1877         cmdline_fixed_string_t port;
1878         cmdline_fixed_string_t keyword;
1879         cmdline_fixed_string_t all;
1880         cmdline_fixed_string_t name;
1881         uint16_t value;
1882 };
1883
1884 static void
1885 cmd_config_rx_tx_parsed(void *parsed_result,
1886                         __attribute__((unused)) struct cmdline *cl,
1887                         __attribute__((unused)) void *data)
1888 {
1889         struct cmd_config_rx_tx *res = parsed_result;
1890
1891         if (!all_ports_stopped()) {
1892                 printf("Please stop all ports first\n");
1893                 return;
1894         }
1895         if (!strcmp(res->name, "rxq")) {
1896                 if (!res->value && !nb_txq) {
1897                         printf("Warning: Either rx or tx queues should be non zero\n");
1898                         return;
1899                 }
1900                 if (check_nb_rxq(res->value) != 0)
1901                         return;
1902                 nb_rxq = res->value;
1903         }
1904         else if (!strcmp(res->name, "txq")) {
1905                 if (!res->value && !nb_rxq) {
1906                         printf("Warning: Either rx or tx queues should be non zero\n");
1907                         return;
1908                 }
1909                 if (check_nb_txq(res->value) != 0)
1910                         return;
1911                 nb_txq = res->value;
1912         }
1913         else if (!strcmp(res->name, "rxd")) {
1914                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1915                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1916                                         res->value, RTE_TEST_RX_DESC_MAX);
1917                         return;
1918                 }
1919                 nb_rxd = res->value;
1920         } else if (!strcmp(res->name, "txd")) {
1921                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1922                         printf("txd %d invalid - must be > 0 && <= %d\n",
1923                                         res->value, RTE_TEST_TX_DESC_MAX);
1924                         return;
1925                 }
1926                 nb_txd = res->value;
1927         } else {
1928                 printf("Unknown parameter\n");
1929                 return;
1930         }
1931
1932         fwd_config_setup();
1933
1934         init_port_config();
1935
1936         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1937 }
1938
1939 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1940         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1941 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1942         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1943 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1944         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1945 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1946         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1947                                                 "rxq#txq#rxd#txd");
1948 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1949         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1950
1951 cmdline_parse_inst_t cmd_config_rx_tx = {
1952         .f = cmd_config_rx_tx_parsed,
1953         .data = NULL,
1954         .help_str = "port config all rxq|txq|rxd|txd <value>",
1955         .tokens = {
1956                 (void *)&cmd_config_rx_tx_port,
1957                 (void *)&cmd_config_rx_tx_keyword,
1958                 (void *)&cmd_config_rx_tx_all,
1959                 (void *)&cmd_config_rx_tx_name,
1960                 (void *)&cmd_config_rx_tx_value,
1961                 NULL,
1962         },
1963 };
1964
1965 /* *** config max packet length *** */
1966 struct cmd_config_max_pkt_len_result {
1967         cmdline_fixed_string_t port;
1968         cmdline_fixed_string_t keyword;
1969         cmdline_fixed_string_t all;
1970         cmdline_fixed_string_t name;
1971         uint32_t value;
1972 };
1973
1974 static void
1975 cmd_config_max_pkt_len_parsed(void *parsed_result,
1976                                 __attribute__((unused)) struct cmdline *cl,
1977                                 __attribute__((unused)) void *data)
1978 {
1979         struct cmd_config_max_pkt_len_result *res = parsed_result;
1980         portid_t pid;
1981
1982         if (!all_ports_stopped()) {
1983                 printf("Please stop all ports first\n");
1984                 return;
1985         }
1986
1987         RTE_ETH_FOREACH_DEV(pid) {
1988                 struct rte_port *port = &ports[pid];
1989                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1990
1991                 if (!strcmp(res->name, "max-pkt-len")) {
1992                         if (res->value < RTE_ETHER_MIN_LEN) {
1993                                 printf("max-pkt-len can not be less than %d\n",
1994                                                 RTE_ETHER_MIN_LEN);
1995                                 return;
1996                         }
1997                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1998                                 return;
1999
2000                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2001                         if (res->value > RTE_ETHER_MAX_LEN)
2002                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2003                         else
2004                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2005                         port->dev_conf.rxmode.offloads = rx_offloads;
2006                 } else {
2007                         printf("Unknown parameter\n");
2008                         return;
2009                 }
2010         }
2011
2012         init_port_config();
2013
2014         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2015 }
2016
2017 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2018         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2019                                                                 "port");
2020 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2021         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2022                                                                 "config");
2023 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2024         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2025                                                                 "all");
2026 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2027         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2028                                                                 "max-pkt-len");
2029 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2030         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2031                                                                 UINT32);
2032
2033 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2034         .f = cmd_config_max_pkt_len_parsed,
2035         .data = NULL,
2036         .help_str = "port config all max-pkt-len <value>",
2037         .tokens = {
2038                 (void *)&cmd_config_max_pkt_len_port,
2039                 (void *)&cmd_config_max_pkt_len_keyword,
2040                 (void *)&cmd_config_max_pkt_len_all,
2041                 (void *)&cmd_config_max_pkt_len_name,
2042                 (void *)&cmd_config_max_pkt_len_value,
2043                 NULL,
2044         },
2045 };
2046
2047 /* *** configure port MTU *** */
2048 struct cmd_config_mtu_result {
2049         cmdline_fixed_string_t port;
2050         cmdline_fixed_string_t keyword;
2051         cmdline_fixed_string_t mtu;
2052         portid_t port_id;
2053         uint16_t value;
2054 };
2055
2056 static void
2057 cmd_config_mtu_parsed(void *parsed_result,
2058                       __attribute__((unused)) struct cmdline *cl,
2059                       __attribute__((unused)) void *data)
2060 {
2061         struct cmd_config_mtu_result *res = parsed_result;
2062
2063         if (res->value < RTE_ETHER_MIN_LEN) {
2064                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2065                 return;
2066         }
2067         port_mtu_set(res->port_id, res->value);
2068 }
2069
2070 cmdline_parse_token_string_t cmd_config_mtu_port =
2071         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2072                                  "port");
2073 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2074         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2075                                  "config");
2076 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2077         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2078                                  "mtu");
2079 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2080         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2081 cmdline_parse_token_num_t cmd_config_mtu_value =
2082         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2083
2084 cmdline_parse_inst_t cmd_config_mtu = {
2085         .f = cmd_config_mtu_parsed,
2086         .data = NULL,
2087         .help_str = "port config mtu <port_id> <value>",
2088         .tokens = {
2089                 (void *)&cmd_config_mtu_port,
2090                 (void *)&cmd_config_mtu_keyword,
2091                 (void *)&cmd_config_mtu_mtu,
2092                 (void *)&cmd_config_mtu_port_id,
2093                 (void *)&cmd_config_mtu_value,
2094                 NULL,
2095         },
2096 };
2097
2098 /* *** configure rx mode *** */
2099 struct cmd_config_rx_mode_flag {
2100         cmdline_fixed_string_t port;
2101         cmdline_fixed_string_t keyword;
2102         cmdline_fixed_string_t all;
2103         cmdline_fixed_string_t name;
2104         cmdline_fixed_string_t value;
2105 };
2106
2107 static void
2108 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2109                                 __attribute__((unused)) struct cmdline *cl,
2110                                 __attribute__((unused)) void *data)
2111 {
2112         struct cmd_config_rx_mode_flag *res = parsed_result;
2113
2114         if (!all_ports_stopped()) {
2115                 printf("Please stop all ports first\n");
2116                 return;
2117         }
2118
2119         if (!strcmp(res->name, "drop-en")) {
2120                 if (!strcmp(res->value, "on"))
2121                         rx_drop_en = 1;
2122                 else if (!strcmp(res->value, "off"))
2123                         rx_drop_en = 0;
2124                 else {
2125                         printf("Unknown parameter\n");
2126                         return;
2127                 }
2128         } else {
2129                 printf("Unknown parameter\n");
2130                 return;
2131         }
2132
2133         init_port_config();
2134
2135         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2136 }
2137
2138 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2139         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2140 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2141         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2142                                                                 "config");
2143 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2144         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2145 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2146         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2147                                         "drop-en");
2148 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2149         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2150                                                         "on#off");
2151
2152 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2153         .f = cmd_config_rx_mode_flag_parsed,
2154         .data = NULL,
2155         .help_str = "port config all drop-en on|off",
2156         .tokens = {
2157                 (void *)&cmd_config_rx_mode_flag_port,
2158                 (void *)&cmd_config_rx_mode_flag_keyword,
2159                 (void *)&cmd_config_rx_mode_flag_all,
2160                 (void *)&cmd_config_rx_mode_flag_name,
2161                 (void *)&cmd_config_rx_mode_flag_value,
2162                 NULL,
2163         },
2164 };
2165
2166 /* *** configure rss *** */
2167 struct cmd_config_rss {
2168         cmdline_fixed_string_t port;
2169         cmdline_fixed_string_t keyword;
2170         cmdline_fixed_string_t all;
2171         cmdline_fixed_string_t name;
2172         cmdline_fixed_string_t value;
2173 };
2174
2175 static void
2176 cmd_config_rss_parsed(void *parsed_result,
2177                         __attribute__((unused)) struct cmdline *cl,
2178                         __attribute__((unused)) void *data)
2179 {
2180         struct cmd_config_rss *res = parsed_result;
2181         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2182         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2183         int use_default = 0;
2184         int all_updated = 1;
2185         int diag;
2186         uint16_t i;
2187         int ret;
2188
2189         if (!strcmp(res->value, "all"))
2190                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2191                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2192                                         ETH_RSS_L2_PAYLOAD;
2193         else if (!strcmp(res->value, "ip"))
2194                 rss_conf.rss_hf = ETH_RSS_IP;
2195         else if (!strcmp(res->value, "udp"))
2196                 rss_conf.rss_hf = ETH_RSS_UDP;
2197         else if (!strcmp(res->value, "tcp"))
2198                 rss_conf.rss_hf = ETH_RSS_TCP;
2199         else if (!strcmp(res->value, "sctp"))
2200                 rss_conf.rss_hf = ETH_RSS_SCTP;
2201         else if (!strcmp(res->value, "ether"))
2202                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2203         else if (!strcmp(res->value, "port"))
2204                 rss_conf.rss_hf = ETH_RSS_PORT;
2205         else if (!strcmp(res->value, "vxlan"))
2206                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2207         else if (!strcmp(res->value, "geneve"))
2208                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2209         else if (!strcmp(res->value, "nvgre"))
2210                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2211         else if (!strcmp(res->value, "none"))
2212                 rss_conf.rss_hf = 0;
2213         else if (!strcmp(res->value, "default"))
2214                 use_default = 1;
2215         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2216                                                 atoi(res->value) < 64)
2217                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2218         else {
2219                 printf("Unknown parameter\n");
2220                 return;
2221         }
2222         rss_conf.rss_key = NULL;
2223         /* Update global configuration for RSS types. */
2224         RTE_ETH_FOREACH_DEV(i) {
2225                 struct rte_eth_rss_conf local_rss_conf;
2226
2227                 ret = eth_dev_info_get_print_err(i, &dev_info);
2228                 if (ret != 0)
2229                         return;
2230
2231                 if (use_default)
2232                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2233
2234                 local_rss_conf = rss_conf;
2235                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2236                         dev_info.flow_type_rss_offloads;
2237                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2238                         printf("Port %u modified RSS hash function based on hardware support,"
2239                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2240                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2241                 }
2242                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2243                 if (diag < 0) {
2244                         all_updated = 0;
2245                         printf("Configuration of RSS hash at ethernet port %d "
2246                                 "failed with error (%d): %s.\n",
2247                                 i, -diag, strerror(-diag));
2248                 }
2249         }
2250         if (all_updated && !use_default)
2251                 rss_hf = rss_conf.rss_hf;
2252 }
2253
2254 cmdline_parse_token_string_t cmd_config_rss_port =
2255         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2256 cmdline_parse_token_string_t cmd_config_rss_keyword =
2257         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2258 cmdline_parse_token_string_t cmd_config_rss_all =
2259         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2260 cmdline_parse_token_string_t cmd_config_rss_name =
2261         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2262 cmdline_parse_token_string_t cmd_config_rss_value =
2263         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2264
2265 cmdline_parse_inst_t cmd_config_rss = {
2266         .f = cmd_config_rss_parsed,
2267         .data = NULL,
2268         .help_str = "port config all rss "
2269                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2270         .tokens = {
2271                 (void *)&cmd_config_rss_port,
2272                 (void *)&cmd_config_rss_keyword,
2273                 (void *)&cmd_config_rss_all,
2274                 (void *)&cmd_config_rss_name,
2275                 (void *)&cmd_config_rss_value,
2276                 NULL,
2277         },
2278 };
2279
2280 /* *** configure rss hash key *** */
2281 struct cmd_config_rss_hash_key {
2282         cmdline_fixed_string_t port;
2283         cmdline_fixed_string_t config;
2284         portid_t port_id;
2285         cmdline_fixed_string_t rss_hash_key;
2286         cmdline_fixed_string_t rss_type;
2287         cmdline_fixed_string_t key;
2288 };
2289
2290 static uint8_t
2291 hexa_digit_to_value(char hexa_digit)
2292 {
2293         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2294                 return (uint8_t) (hexa_digit - '0');
2295         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2296                 return (uint8_t) ((hexa_digit - 'a') + 10);
2297         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2298                 return (uint8_t) ((hexa_digit - 'A') + 10);
2299         /* Invalid hexa digit */
2300         return 0xFF;
2301 }
2302
2303 static uint8_t
2304 parse_and_check_key_hexa_digit(char *key, int idx)
2305 {
2306         uint8_t hexa_v;
2307
2308         hexa_v = hexa_digit_to_value(key[idx]);
2309         if (hexa_v == 0xFF)
2310                 printf("invalid key: character %c at position %d is not a "
2311                        "valid hexa digit\n", key[idx], idx);
2312         return hexa_v;
2313 }
2314
2315 static void
2316 cmd_config_rss_hash_key_parsed(void *parsed_result,
2317                                __attribute__((unused)) struct cmdline *cl,
2318                                __attribute__((unused)) void *data)
2319 {
2320         struct cmd_config_rss_hash_key *res = parsed_result;
2321         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2322         uint8_t xdgt0;
2323         uint8_t xdgt1;
2324         int i;
2325         struct rte_eth_dev_info dev_info;
2326         uint8_t hash_key_size;
2327         uint32_t key_len;
2328         int ret;
2329
2330         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2331         if (ret != 0)
2332                 return;
2333
2334         if (dev_info.hash_key_size > 0 &&
2335                         dev_info.hash_key_size <= sizeof(hash_key))
2336                 hash_key_size = dev_info.hash_key_size;
2337         else {
2338                 printf("dev_info did not provide a valid hash key size\n");
2339                 return;
2340         }
2341         /* Check the length of the RSS hash key */
2342         key_len = strlen(res->key);
2343         if (key_len != (hash_key_size * 2)) {
2344                 printf("key length: %d invalid - key must be a string of %d"
2345                            " hexa-decimal numbers\n",
2346                            (int) key_len, hash_key_size * 2);
2347                 return;
2348         }
2349         /* Translate RSS hash key into binary representation */
2350         for (i = 0; i < hash_key_size; i++) {
2351                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2352                 if (xdgt0 == 0xFF)
2353                         return;
2354                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2355                 if (xdgt1 == 0xFF)
2356                         return;
2357                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2358         }
2359         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2360                         hash_key_size);
2361 }
2362
2363 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2364         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2365 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2366         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2367                                  "config");
2368 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2369         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2370 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2371         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2372                                  rss_hash_key, "rss-hash-key");
2373 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2374         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2375                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2376                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2377                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2378                                  "ipv6-tcp-ex#ipv6-udp-ex");
2379 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2380         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2381
2382 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2383         .f = cmd_config_rss_hash_key_parsed,
2384         .data = NULL,
2385         .help_str = "port config <port_id> rss-hash-key "
2386                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2387                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2388                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2389                 "<string of hex digits (variable length, NIC dependent)>",
2390         .tokens = {
2391                 (void *)&cmd_config_rss_hash_key_port,
2392                 (void *)&cmd_config_rss_hash_key_config,
2393                 (void *)&cmd_config_rss_hash_key_port_id,
2394                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2395                 (void *)&cmd_config_rss_hash_key_rss_type,
2396                 (void *)&cmd_config_rss_hash_key_value,
2397                 NULL,
2398         },
2399 };
2400
2401 /* *** configure port rxq/txq ring size *** */
2402 struct cmd_config_rxtx_ring_size {
2403         cmdline_fixed_string_t port;
2404         cmdline_fixed_string_t config;
2405         portid_t portid;
2406         cmdline_fixed_string_t rxtxq;
2407         uint16_t qid;
2408         cmdline_fixed_string_t rsize;
2409         uint16_t size;
2410 };
2411
2412 static void
2413 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2414                                  __attribute__((unused)) struct cmdline *cl,
2415                                  __attribute__((unused)) void *data)
2416 {
2417         struct cmd_config_rxtx_ring_size *res = parsed_result;
2418         struct rte_port *port;
2419         uint8_t isrx;
2420
2421         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2422                 return;
2423
2424         if (res->portid == (portid_t)RTE_PORT_ALL) {
2425                 printf("Invalid port id\n");
2426                 return;
2427         }
2428
2429         port = &ports[res->portid];
2430
2431         if (!strcmp(res->rxtxq, "rxq"))
2432                 isrx = 1;
2433         else if (!strcmp(res->rxtxq, "txq"))
2434                 isrx = 0;
2435         else {
2436                 printf("Unknown parameter\n");
2437                 return;
2438         }
2439
2440         if (isrx && rx_queue_id_is_invalid(res->qid))
2441                 return;
2442         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2443                 return;
2444
2445         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2446                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2447                        rx_free_thresh);
2448                 return;
2449         }
2450
2451         if (isrx)
2452                 port->nb_rx_desc[res->qid] = res->size;
2453         else
2454                 port->nb_tx_desc[res->qid] = res->size;
2455
2456         cmd_reconfig_device_queue(res->portid, 0, 1);
2457 }
2458
2459 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2460         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2461                                  port, "port");
2462 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2463         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2464                                  config, "config");
2465 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2466         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2467                                  portid, UINT16);
2468 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2469         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2470                                  rxtxq, "rxq#txq");
2471 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2472         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2473                               qid, UINT16);
2474 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2475         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2476                                  rsize, "ring_size");
2477 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2478         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2479                               size, UINT16);
2480
2481 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2482         .f = cmd_config_rxtx_ring_size_parsed,
2483         .data = NULL,
2484         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2485         .tokens = {
2486                 (void *)&cmd_config_rxtx_ring_size_port,
2487                 (void *)&cmd_config_rxtx_ring_size_config,
2488                 (void *)&cmd_config_rxtx_ring_size_portid,
2489                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2490                 (void *)&cmd_config_rxtx_ring_size_qid,
2491                 (void *)&cmd_config_rxtx_ring_size_rsize,
2492                 (void *)&cmd_config_rxtx_ring_size_size,
2493                 NULL,
2494         },
2495 };
2496
2497 /* *** configure port rxq/txq start/stop *** */
2498 struct cmd_config_rxtx_queue {
2499         cmdline_fixed_string_t port;
2500         portid_t portid;
2501         cmdline_fixed_string_t rxtxq;
2502         uint16_t qid;
2503         cmdline_fixed_string_t opname;
2504 };
2505
2506 static void
2507 cmd_config_rxtx_queue_parsed(void *parsed_result,
2508                         __attribute__((unused)) struct cmdline *cl,
2509                         __attribute__((unused)) void *data)
2510 {
2511         struct cmd_config_rxtx_queue *res = parsed_result;
2512         uint8_t isrx;
2513         uint8_t isstart;
2514         int ret = 0;
2515
2516         if (test_done == 0) {
2517                 printf("Please stop forwarding first\n");
2518                 return;
2519         }
2520
2521         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2522                 return;
2523
2524         if (port_is_started(res->portid) != 1) {
2525                 printf("Please start port %u first\n", res->portid);
2526                 return;
2527         }
2528
2529         if (!strcmp(res->rxtxq, "rxq"))
2530                 isrx = 1;
2531         else if (!strcmp(res->rxtxq, "txq"))
2532                 isrx = 0;
2533         else {
2534                 printf("Unknown parameter\n");
2535                 return;
2536         }
2537
2538         if (isrx && rx_queue_id_is_invalid(res->qid))
2539                 return;
2540         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2541                 return;
2542
2543         if (!strcmp(res->opname, "start"))
2544                 isstart = 1;
2545         else if (!strcmp(res->opname, "stop"))
2546                 isstart = 0;
2547         else {
2548                 printf("Unknown parameter\n");
2549                 return;
2550         }
2551
2552         if (isstart && isrx)
2553                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2554         else if (!isstart && isrx)
2555                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2556         else if (isstart && !isrx)
2557                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2558         else
2559                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2560
2561         if (ret == -ENOTSUP)
2562                 printf("Function not supported in PMD driver\n");
2563 }
2564
2565 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2566         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2567 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2568         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2569 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2570         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2571 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2572         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2573 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2574         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2575                                                 "start#stop");
2576
2577 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2578         .f = cmd_config_rxtx_queue_parsed,
2579         .data = NULL,
2580         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2581         .tokens = {
2582                 (void *)&cmd_config_rxtx_queue_port,
2583                 (void *)&cmd_config_rxtx_queue_portid,
2584                 (void *)&cmd_config_rxtx_queue_rxtxq,
2585                 (void *)&cmd_config_rxtx_queue_qid,
2586                 (void *)&cmd_config_rxtx_queue_opname,
2587                 NULL,
2588         },
2589 };
2590
2591 /* *** configure port rxq/txq deferred start on/off *** */
2592 struct cmd_config_deferred_start_rxtx_queue {
2593         cmdline_fixed_string_t port;
2594         portid_t port_id;
2595         cmdline_fixed_string_t rxtxq;
2596         uint16_t qid;
2597         cmdline_fixed_string_t opname;
2598         cmdline_fixed_string_t state;
2599 };
2600
2601 static void
2602 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2603                         __attribute__((unused)) struct cmdline *cl,
2604                         __attribute__((unused)) void *data)
2605 {
2606         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2607         struct rte_port *port;
2608         uint8_t isrx;
2609         uint8_t ison;
2610         uint8_t needreconfig = 0;
2611
2612         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2613                 return;
2614
2615         if (port_is_started(res->port_id) != 0) {
2616                 printf("Please stop port %u first\n", res->port_id);
2617                 return;
2618         }
2619
2620         port = &ports[res->port_id];
2621
2622         isrx = !strcmp(res->rxtxq, "rxq");
2623
2624         if (isrx && rx_queue_id_is_invalid(res->qid))
2625                 return;
2626         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2627                 return;
2628
2629         ison = !strcmp(res->state, "on");
2630
2631         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2632                 port->rx_conf[res->qid].rx_deferred_start = ison;
2633                 needreconfig = 1;
2634         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2635                 port->tx_conf[res->qid].tx_deferred_start = ison;
2636                 needreconfig = 1;
2637         }
2638
2639         if (needreconfig)
2640                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2641 }
2642
2643 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2644         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2645                                                 port, "port");
2646 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2647         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2648                                                 port_id, UINT16);
2649 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2650         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2651                                                 rxtxq, "rxq#txq");
2652 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2653         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2654                                                 qid, UINT16);
2655 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2656         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2657                                                 opname, "deferred_start");
2658 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2659         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2660                                                 state, "on#off");
2661
2662 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2663         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2664         .data = NULL,
2665         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2666         .tokens = {
2667                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2668                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2669                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2670                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2671                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2672                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2673                 NULL,
2674         },
2675 };
2676
2677 /* *** configure port rxq/txq setup *** */
2678 struct cmd_setup_rxtx_queue {
2679         cmdline_fixed_string_t port;
2680         portid_t portid;
2681         cmdline_fixed_string_t rxtxq;
2682         uint16_t qid;
2683         cmdline_fixed_string_t setup;
2684 };
2685
2686 /* Common CLI fields for queue setup */
2687 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2688         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2689 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2690         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2691 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2692         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2693 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2694         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2695 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2696         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2697
2698 static void
2699 cmd_setup_rxtx_queue_parsed(
2700         void *parsed_result,
2701         __attribute__((unused)) struct cmdline *cl,
2702         __attribute__((unused)) void *data)
2703 {
2704         struct cmd_setup_rxtx_queue *res = parsed_result;
2705         struct rte_port *port;
2706         struct rte_mempool *mp;
2707         unsigned int socket_id;
2708         uint8_t isrx = 0;
2709         int ret;
2710
2711         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2712                 return;
2713
2714         if (res->portid == (portid_t)RTE_PORT_ALL) {
2715                 printf("Invalid port id\n");
2716                 return;
2717         }
2718
2719         if (!strcmp(res->rxtxq, "rxq"))
2720                 isrx = 1;
2721         else if (!strcmp(res->rxtxq, "txq"))
2722                 isrx = 0;
2723         else {
2724                 printf("Unknown parameter\n");
2725                 return;
2726         }
2727
2728         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2729                 printf("Invalid rx queue\n");
2730                 return;
2731         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2732                 printf("Invalid tx queue\n");
2733                 return;
2734         }
2735
2736         port = &ports[res->portid];
2737         if (isrx) {
2738                 socket_id = rxring_numa[res->portid];
2739                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2740                         socket_id = port->socket_id;
2741
2742                 mp = mbuf_pool_find(socket_id);
2743                 if (mp == NULL) {
2744                         printf("Failed to setup RX queue: "
2745                                 "No mempool allocation"
2746                                 " on the socket %d\n",
2747                                 rxring_numa[res->portid]);
2748                         return;
2749                 }
2750                 ret = rte_eth_rx_queue_setup(res->portid,
2751                                              res->qid,
2752                                              port->nb_rx_desc[res->qid],
2753                                              socket_id,
2754                                              &port->rx_conf[res->qid],
2755                                              mp);
2756                 if (ret)
2757                         printf("Failed to setup RX queue\n");
2758         } else {
2759                 socket_id = txring_numa[res->portid];
2760                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2761                         socket_id = port->socket_id;
2762
2763                 ret = rte_eth_tx_queue_setup(res->portid,
2764                                              res->qid,
2765                                              port->nb_tx_desc[res->qid],
2766                                              socket_id,
2767                                              &port->tx_conf[res->qid]);
2768                 if (ret)
2769                         printf("Failed to setup TX queue\n");
2770         }
2771 }
2772
2773 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2774         .f = cmd_setup_rxtx_queue_parsed,
2775         .data = NULL,
2776         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2777         .tokens = {
2778                 (void *)&cmd_setup_rxtx_queue_port,
2779                 (void *)&cmd_setup_rxtx_queue_portid,
2780                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2781                 (void *)&cmd_setup_rxtx_queue_qid,
2782                 (void *)&cmd_setup_rxtx_queue_setup,
2783                 NULL,
2784         },
2785 };
2786
2787
2788 /* *** Configure RSS RETA *** */
2789 struct cmd_config_rss_reta {
2790         cmdline_fixed_string_t port;
2791         cmdline_fixed_string_t keyword;
2792         portid_t port_id;
2793         cmdline_fixed_string_t name;
2794         cmdline_fixed_string_t list_name;
2795         cmdline_fixed_string_t list_of_items;
2796 };
2797
2798 static int
2799 parse_reta_config(const char *str,
2800                   struct rte_eth_rss_reta_entry64 *reta_conf,
2801                   uint16_t nb_entries)
2802 {
2803         int i;
2804         unsigned size;
2805         uint16_t hash_index, idx, shift;
2806         uint16_t nb_queue;
2807         char s[256];
2808         const char *p, *p0 = str;
2809         char *end;
2810         enum fieldnames {
2811                 FLD_HASH_INDEX = 0,
2812                 FLD_QUEUE,
2813                 _NUM_FLD
2814         };
2815         unsigned long int_fld[_NUM_FLD];
2816         char *str_fld[_NUM_FLD];
2817
2818         while ((p = strchr(p0,'(')) != NULL) {
2819                 ++p;
2820                 if((p0 = strchr(p,')')) == NULL)
2821                         return -1;
2822
2823                 size = p0 - p;
2824                 if(size >= sizeof(s))
2825                         return -1;
2826
2827                 snprintf(s, sizeof(s), "%.*s", size, p);
2828                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2829                         return -1;
2830                 for (i = 0; i < _NUM_FLD; i++) {
2831                         errno = 0;
2832                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2833                         if (errno != 0 || end == str_fld[i] ||
2834                                         int_fld[i] > 65535)
2835                                 return -1;
2836                 }
2837
2838                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2839                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2840
2841                 if (hash_index >= nb_entries) {
2842                         printf("Invalid RETA hash index=%d\n", hash_index);
2843                         return -1;
2844                 }
2845
2846                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2847                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2848                 reta_conf[idx].mask |= (1ULL << shift);
2849                 reta_conf[idx].reta[shift] = nb_queue;
2850         }
2851
2852         return 0;
2853 }
2854
2855 static void
2856 cmd_set_rss_reta_parsed(void *parsed_result,
2857                         __attribute__((unused)) struct cmdline *cl,
2858                         __attribute__((unused)) void *data)
2859 {
2860         int ret;
2861         struct rte_eth_dev_info dev_info;
2862         struct rte_eth_rss_reta_entry64 reta_conf[8];
2863         struct cmd_config_rss_reta *res = parsed_result;
2864
2865         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2866         if (ret != 0)
2867                 return;
2868
2869         if (dev_info.reta_size == 0) {
2870                 printf("Redirection table size is 0 which is "
2871                                         "invalid for RSS\n");
2872                 return;
2873         } else
2874                 printf("The reta size of port %d is %u\n",
2875                         res->port_id, dev_info.reta_size);
2876         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2877                 printf("Currently do not support more than %u entries of "
2878                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2879                 return;
2880         }
2881
2882         memset(reta_conf, 0, sizeof(reta_conf));
2883         if (!strcmp(res->list_name, "reta")) {
2884                 if (parse_reta_config(res->list_of_items, reta_conf,
2885                                                 dev_info.reta_size)) {
2886                         printf("Invalid RSS Redirection Table "
2887                                         "config entered\n");
2888                         return;
2889                 }
2890                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2891                                 reta_conf, dev_info.reta_size);
2892                 if (ret != 0)
2893                         printf("Bad redirection table parameter, "
2894                                         "return code = %d \n", ret);
2895         }
2896 }
2897
2898 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2899         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2900 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2901         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2902 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2903         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2904 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2905         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2906 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2907         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2908 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2909         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2910                                  NULL);
2911 cmdline_parse_inst_t cmd_config_rss_reta = {
2912         .f = cmd_set_rss_reta_parsed,
2913         .data = NULL,
2914         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2915         .tokens = {
2916                 (void *)&cmd_config_rss_reta_port,
2917                 (void *)&cmd_config_rss_reta_keyword,
2918                 (void *)&cmd_config_rss_reta_port_id,
2919                 (void *)&cmd_config_rss_reta_name,
2920                 (void *)&cmd_config_rss_reta_list_name,
2921                 (void *)&cmd_config_rss_reta_list_of_items,
2922                 NULL,
2923         },
2924 };
2925
2926 /* *** SHOW PORT RETA INFO *** */
2927 struct cmd_showport_reta {
2928         cmdline_fixed_string_t show;
2929         cmdline_fixed_string_t port;
2930         portid_t port_id;
2931         cmdline_fixed_string_t rss;
2932         cmdline_fixed_string_t reta;
2933         uint16_t size;
2934         cmdline_fixed_string_t list_of_items;
2935 };
2936
2937 static int
2938 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2939                            uint16_t nb_entries,
2940                            char *str)
2941 {
2942         uint32_t size;
2943         const char *p, *p0 = str;
2944         char s[256];
2945         char *end;
2946         char *str_fld[8];
2947         uint16_t i;
2948         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2949                         RTE_RETA_GROUP_SIZE;
2950         int ret;
2951
2952         p = strchr(p0, '(');
2953         if (p == NULL)
2954                 return -1;
2955         p++;
2956         p0 = strchr(p, ')');
2957         if (p0 == NULL)
2958                 return -1;
2959         size = p0 - p;
2960         if (size >= sizeof(s)) {
2961                 printf("The string size exceeds the internal buffer size\n");
2962                 return -1;
2963         }
2964         snprintf(s, sizeof(s), "%.*s", size, p);
2965         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2966         if (ret <= 0 || ret != num) {
2967                 printf("The bits of masks do not match the number of "
2968                                         "reta entries: %u\n", num);
2969                 return -1;
2970         }
2971         for (i = 0; i < ret; i++)
2972                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2973
2974         return 0;
2975 }
2976
2977 static void
2978 cmd_showport_reta_parsed(void *parsed_result,
2979                          __attribute__((unused)) struct cmdline *cl,
2980                          __attribute__((unused)) void *data)
2981 {
2982         struct cmd_showport_reta *res = parsed_result;
2983         struct rte_eth_rss_reta_entry64 reta_conf[8];
2984         struct rte_eth_dev_info dev_info;
2985         uint16_t max_reta_size;
2986         int ret;
2987
2988         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2989         if (ret != 0)
2990                 return;
2991
2992         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2993         if (res->size == 0 || res->size > max_reta_size) {
2994                 printf("Invalid redirection table size: %u (1-%u)\n",
2995                         res->size, max_reta_size);
2996                 return;
2997         }
2998
2999         memset(reta_conf, 0, sizeof(reta_conf));
3000         if (showport_parse_reta_config(reta_conf, res->size,
3001                                 res->list_of_items) < 0) {
3002                 printf("Invalid string: %s for reta masks\n",
3003                                         res->list_of_items);
3004                 return;
3005         }
3006         port_rss_reta_info(res->port_id, reta_conf, res->size);
3007 }
3008
3009 cmdline_parse_token_string_t cmd_showport_reta_show =
3010         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3011 cmdline_parse_token_string_t cmd_showport_reta_port =
3012         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3013 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3014         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3015 cmdline_parse_token_string_t cmd_showport_reta_rss =
3016         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3017 cmdline_parse_token_string_t cmd_showport_reta_reta =
3018         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3019 cmdline_parse_token_num_t cmd_showport_reta_size =
3020         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3021 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3022         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3023                                         list_of_items, NULL);
3024
3025 cmdline_parse_inst_t cmd_showport_reta = {
3026         .f = cmd_showport_reta_parsed,
3027         .data = NULL,
3028         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3029         .tokens = {
3030                 (void *)&cmd_showport_reta_show,
3031                 (void *)&cmd_showport_reta_port,
3032                 (void *)&cmd_showport_reta_port_id,
3033                 (void *)&cmd_showport_reta_rss,
3034                 (void *)&cmd_showport_reta_reta,
3035                 (void *)&cmd_showport_reta_size,
3036                 (void *)&cmd_showport_reta_list_of_items,
3037                 NULL,
3038         },
3039 };
3040
3041 /* *** Show RSS hash configuration *** */
3042 struct cmd_showport_rss_hash {
3043         cmdline_fixed_string_t show;
3044         cmdline_fixed_string_t port;
3045         portid_t port_id;
3046         cmdline_fixed_string_t rss_hash;
3047         cmdline_fixed_string_t rss_type;
3048         cmdline_fixed_string_t key; /* optional argument */
3049 };
3050
3051 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3052                                 __attribute__((unused)) struct cmdline *cl,
3053                                 void *show_rss_key)
3054 {
3055         struct cmd_showport_rss_hash *res = parsed_result;
3056
3057         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3058 }
3059
3060 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3061         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3062 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3063         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3064 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3065         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3066 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3067         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3068                                  "rss-hash");
3069 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3070         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3071
3072 cmdline_parse_inst_t cmd_showport_rss_hash = {
3073         .f = cmd_showport_rss_hash_parsed,
3074         .data = NULL,
3075         .help_str = "show port <port_id> rss-hash",
3076         .tokens = {
3077                 (void *)&cmd_showport_rss_hash_show,
3078                 (void *)&cmd_showport_rss_hash_port,
3079                 (void *)&cmd_showport_rss_hash_port_id,
3080                 (void *)&cmd_showport_rss_hash_rss_hash,
3081                 NULL,
3082         },
3083 };
3084
3085 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3086         .f = cmd_showport_rss_hash_parsed,
3087         .data = (void *)1,
3088         .help_str = "show port <port_id> rss-hash key",
3089         .tokens = {
3090                 (void *)&cmd_showport_rss_hash_show,
3091                 (void *)&cmd_showport_rss_hash_port,
3092                 (void *)&cmd_showport_rss_hash_port_id,
3093                 (void *)&cmd_showport_rss_hash_rss_hash,
3094                 (void *)&cmd_showport_rss_hash_rss_key,
3095                 NULL,
3096         },
3097 };
3098
3099 /* *** Configure DCB *** */
3100 struct cmd_config_dcb {
3101         cmdline_fixed_string_t port;
3102         cmdline_fixed_string_t config;
3103         portid_t port_id;
3104         cmdline_fixed_string_t dcb;
3105         cmdline_fixed_string_t vt;
3106         cmdline_fixed_string_t vt_en;
3107         uint8_t num_tcs;
3108         cmdline_fixed_string_t pfc;
3109         cmdline_fixed_string_t pfc_en;
3110 };
3111
3112 static void
3113 cmd_config_dcb_parsed(void *parsed_result,
3114                         __attribute__((unused)) struct cmdline *cl,
3115                         __attribute__((unused)) void *data)
3116 {
3117         struct cmd_config_dcb *res = parsed_result;
3118         portid_t port_id = res->port_id;
3119         struct rte_port *port;
3120         uint8_t pfc_en;
3121         int ret;
3122
3123         port = &ports[port_id];
3124         /** Check if the port is not started **/
3125         if (port->port_status != RTE_PORT_STOPPED) {
3126                 printf("Please stop port %d first\n", port_id);
3127                 return;
3128         }
3129
3130         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3131                 printf("The invalid number of traffic class,"
3132                         " only 4 or 8 allowed.\n");
3133                 return;
3134         }
3135
3136         if (nb_fwd_lcores < res->num_tcs) {
3137                 printf("nb_cores shouldn't be less than number of TCs.\n");
3138                 return;
3139         }
3140         if (!strncmp(res->pfc_en, "on", 2))
3141                 pfc_en = 1;
3142         else
3143                 pfc_en = 0;
3144
3145         /* DCB in VT mode */
3146         if (!strncmp(res->vt_en, "on", 2))
3147                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3148                                 (enum rte_eth_nb_tcs)res->num_tcs,
3149                                 pfc_en);
3150         else
3151                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3152                                 (enum rte_eth_nb_tcs)res->num_tcs,
3153                                 pfc_en);
3154
3155
3156         if (ret != 0) {
3157                 printf("Cannot initialize network ports.\n");
3158                 return;
3159         }
3160
3161         cmd_reconfig_device_queue(port_id, 1, 1);
3162 }
3163
3164 cmdline_parse_token_string_t cmd_config_dcb_port =
3165         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3166 cmdline_parse_token_string_t cmd_config_dcb_config =
3167         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3168 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3169         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3170 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3171         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3172 cmdline_parse_token_string_t cmd_config_dcb_vt =
3173         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3174 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3175         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3176 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3177         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3178 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3179         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3180 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3181         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3182
3183 cmdline_parse_inst_t cmd_config_dcb = {
3184         .f = cmd_config_dcb_parsed,
3185         .data = NULL,
3186         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3187         .tokens = {
3188                 (void *)&cmd_config_dcb_port,
3189                 (void *)&cmd_config_dcb_config,
3190                 (void *)&cmd_config_dcb_port_id,
3191                 (void *)&cmd_config_dcb_dcb,
3192                 (void *)&cmd_config_dcb_vt,
3193                 (void *)&cmd_config_dcb_vt_en,
3194                 (void *)&cmd_config_dcb_num_tcs,
3195                 (void *)&cmd_config_dcb_pfc,
3196                 (void *)&cmd_config_dcb_pfc_en,
3197                 NULL,
3198         },
3199 };
3200
3201 /* *** configure number of packets per burst *** */
3202 struct cmd_config_burst {
3203         cmdline_fixed_string_t port;
3204         cmdline_fixed_string_t keyword;
3205         cmdline_fixed_string_t all;
3206         cmdline_fixed_string_t name;
3207         uint16_t value;
3208 };
3209
3210 static void
3211 cmd_config_burst_parsed(void *parsed_result,
3212                         __attribute__((unused)) struct cmdline *cl,
3213                         __attribute__((unused)) void *data)
3214 {
3215         struct cmd_config_burst *res = parsed_result;
3216         struct rte_eth_dev_info dev_info;
3217         uint16_t rec_nb_pkts;
3218         int ret;
3219
3220         if (!all_ports_stopped()) {
3221                 printf("Please stop all ports first\n");
3222                 return;
3223         }
3224
3225         if (!strcmp(res->name, "burst")) {
3226                 if (res->value == 0) {
3227                         /* If user gives a value of zero, query the PMD for
3228                          * its recommended Rx burst size. Testpmd uses a single
3229                          * size for all ports, so assume all ports are the same
3230                          * NIC model and use the values from Port 0.
3231                          */
3232                         ret = eth_dev_info_get_print_err(0, &dev_info);
3233                         if (ret != 0)
3234                                 return;
3235
3236                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3237
3238                         if (rec_nb_pkts == 0) {
3239                                 printf("PMD does not recommend a burst size.\n"
3240                                         "User provided value must be between"
3241                                         " 1 and %d\n", MAX_PKT_BURST);
3242                                 return;
3243                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3244                                 printf("PMD recommended burst size of %d"
3245                                         " exceeds maximum value of %d\n",
3246                                         rec_nb_pkts, MAX_PKT_BURST);
3247                                 return;
3248                         }
3249                         printf("Using PMD-provided burst value of %d\n",
3250                                 rec_nb_pkts);
3251                         nb_pkt_per_burst = rec_nb_pkts;
3252                 } else if (res->value > MAX_PKT_BURST) {
3253                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3254                         return;
3255                 } else
3256                         nb_pkt_per_burst = res->value;
3257         } else {
3258                 printf("Unknown parameter\n");
3259                 return;
3260         }
3261
3262         init_port_config();
3263
3264         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3265 }
3266
3267 cmdline_parse_token_string_t cmd_config_burst_port =
3268         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3269 cmdline_parse_token_string_t cmd_config_burst_keyword =
3270         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3271 cmdline_parse_token_string_t cmd_config_burst_all =
3272         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3273 cmdline_parse_token_string_t cmd_config_burst_name =
3274         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3275 cmdline_parse_token_num_t cmd_config_burst_value =
3276         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3277
3278 cmdline_parse_inst_t cmd_config_burst = {
3279         .f = cmd_config_burst_parsed,
3280         .data = NULL,
3281         .help_str = "port config all burst <value>",
3282         .tokens = {
3283                 (void *)&cmd_config_burst_port,
3284                 (void *)&cmd_config_burst_keyword,
3285                 (void *)&cmd_config_burst_all,
3286                 (void *)&cmd_config_burst_name,
3287                 (void *)&cmd_config_burst_value,
3288                 NULL,
3289         },
3290 };
3291
3292 /* *** configure rx/tx queues *** */
3293 struct cmd_config_thresh {
3294         cmdline_fixed_string_t port;
3295         cmdline_fixed_string_t keyword;
3296         cmdline_fixed_string_t all;
3297         cmdline_fixed_string_t name;
3298         uint8_t value;
3299 };
3300
3301 static void
3302 cmd_config_thresh_parsed(void *parsed_result,
3303                         __attribute__((unused)) struct cmdline *cl,
3304                         __attribute__((unused)) void *data)
3305 {
3306         struct cmd_config_thresh *res = parsed_result;
3307
3308         if (!all_ports_stopped()) {
3309                 printf("Please stop all ports first\n");
3310                 return;
3311         }
3312
3313         if (!strcmp(res->name, "txpt"))
3314                 tx_pthresh = res->value;
3315         else if(!strcmp(res->name, "txht"))
3316                 tx_hthresh = res->value;
3317         else if(!strcmp(res->name, "txwt"))
3318                 tx_wthresh = res->value;
3319         else if(!strcmp(res->name, "rxpt"))
3320                 rx_pthresh = res->value;
3321         else if(!strcmp(res->name, "rxht"))
3322                 rx_hthresh = res->value;
3323         else if(!strcmp(res->name, "rxwt"))
3324                 rx_wthresh = res->value;
3325         else {
3326                 printf("Unknown parameter\n");
3327                 return;
3328         }
3329
3330         init_port_config();
3331
3332         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3333 }
3334
3335 cmdline_parse_token_string_t cmd_config_thresh_port =
3336         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3337 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3338         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3339 cmdline_parse_token_string_t cmd_config_thresh_all =
3340         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3341 cmdline_parse_token_string_t cmd_config_thresh_name =
3342         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3343                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3344 cmdline_parse_token_num_t cmd_config_thresh_value =
3345         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3346
3347 cmdline_parse_inst_t cmd_config_thresh = {
3348         .f = cmd_config_thresh_parsed,
3349         .data = NULL,
3350         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3351         .tokens = {
3352                 (void *)&cmd_config_thresh_port,
3353                 (void *)&cmd_config_thresh_keyword,
3354                 (void *)&cmd_config_thresh_all,
3355                 (void *)&cmd_config_thresh_name,
3356                 (void *)&cmd_config_thresh_value,
3357                 NULL,
3358         },
3359 };
3360
3361 /* *** configure free/rs threshold *** */
3362 struct cmd_config_threshold {
3363         cmdline_fixed_string_t port;
3364         cmdline_fixed_string_t keyword;
3365         cmdline_fixed_string_t all;
3366         cmdline_fixed_string_t name;
3367         uint16_t value;
3368 };
3369
3370 static void
3371 cmd_config_threshold_parsed(void *parsed_result,
3372                         __attribute__((unused)) struct cmdline *cl,
3373                         __attribute__((unused)) void *data)
3374 {
3375         struct cmd_config_threshold *res = parsed_result;
3376
3377         if (!all_ports_stopped()) {
3378                 printf("Please stop all ports first\n");
3379                 return;
3380         }
3381
3382         if (!strcmp(res->name, "txfreet"))
3383                 tx_free_thresh = res->value;
3384         else if (!strcmp(res->name, "txrst"))
3385                 tx_rs_thresh = res->value;
3386         else if (!strcmp(res->name, "rxfreet"))
3387                 rx_free_thresh = res->value;
3388         else {
3389                 printf("Unknown parameter\n");
3390                 return;
3391         }
3392
3393         init_port_config();
3394
3395         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3396 }
3397
3398 cmdline_parse_token_string_t cmd_config_threshold_port =
3399         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3400 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3401         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3402                                                                 "config");
3403 cmdline_parse_token_string_t cmd_config_threshold_all =
3404         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3405 cmdline_parse_token_string_t cmd_config_threshold_name =
3406         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3407                                                 "txfreet#txrst#rxfreet");
3408 cmdline_parse_token_num_t cmd_config_threshold_value =
3409         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3410
3411 cmdline_parse_inst_t cmd_config_threshold = {
3412         .f = cmd_config_threshold_parsed,
3413         .data = NULL,
3414         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3415         .tokens = {
3416                 (void *)&cmd_config_threshold_port,
3417                 (void *)&cmd_config_threshold_keyword,
3418                 (void *)&cmd_config_threshold_all,
3419                 (void *)&cmd_config_threshold_name,
3420                 (void *)&cmd_config_threshold_value,
3421                 NULL,
3422         },
3423 };
3424
3425 /* *** stop *** */
3426 struct cmd_stop_result {
3427         cmdline_fixed_string_t stop;
3428 };
3429
3430 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3431                             __attribute__((unused)) struct cmdline *cl,
3432                             __attribute__((unused)) void *data)
3433 {
3434         stop_packet_forwarding();
3435 }
3436
3437 cmdline_parse_token_string_t cmd_stop_stop =
3438         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3439
3440 cmdline_parse_inst_t cmd_stop = {
3441         .f = cmd_stop_parsed,
3442         .data = NULL,
3443         .help_str = "stop: Stop packet forwarding",
3444         .tokens = {
3445                 (void *)&cmd_stop_stop,
3446                 NULL,
3447         },
3448 };
3449
3450 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3451
3452 unsigned int
3453 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3454                 unsigned int *parsed_items, int check_unique_values)
3455 {
3456         unsigned int nb_item;
3457         unsigned int value;
3458         unsigned int i;
3459         unsigned int j;
3460         int value_ok;
3461         char c;
3462
3463         /*
3464          * First parse all items in the list and store their value.
3465          */
3466         value = 0;
3467         nb_item = 0;
3468         value_ok = 0;
3469         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3470                 c = str[i];
3471                 if ((c >= '0') && (c <= '9')) {
3472                         value = (unsigned int) (value * 10 + (c - '0'));
3473                         value_ok = 1;
3474                         continue;
3475                 }
3476                 if (c != ',') {
3477                         printf("character %c is not a decimal digit\n", c);
3478                         return 0;
3479                 }
3480                 if (! value_ok) {
3481                         printf("No valid value before comma\n");
3482                         return 0;
3483                 }
3484                 if (nb_item < max_items) {
3485                         parsed_items[nb_item] = value;
3486                         value_ok = 0;
3487                         value = 0;
3488                 }
3489                 nb_item++;
3490         }
3491         if (nb_item >= max_items) {
3492                 printf("Number of %s = %u > %u (maximum items)\n",
3493                        item_name, nb_item + 1, max_items);
3494                 return 0;
3495         }
3496         parsed_items[nb_item++] = value;
3497         if (! check_unique_values)
3498                 return nb_item;
3499
3500         /*
3501          * Then, check that all values in the list are differents.
3502          * No optimization here...
3503          */
3504         for (i = 0; i < nb_item; i++) {
3505                 for (j = i + 1; j < nb_item; j++) {
3506                         if (parsed_items[j] == parsed_items[i]) {
3507                                 printf("duplicated %s %u at index %u and %u\n",
3508                                        item_name, parsed_items[i], i, j);
3509                                 return 0;
3510                         }
3511                 }
3512         }
3513         return nb_item;
3514 }
3515
3516 struct cmd_set_list_result {
3517         cmdline_fixed_string_t cmd_keyword;
3518         cmdline_fixed_string_t list_name;
3519         cmdline_fixed_string_t list_of_items;
3520 };
3521
3522 static void cmd_set_list_parsed(void *parsed_result,
3523                                 __attribute__((unused)) struct cmdline *cl,
3524                                 __attribute__((unused)) void *data)
3525 {
3526         struct cmd_set_list_result *res;
3527         union {
3528                 unsigned int lcorelist[RTE_MAX_LCORE];
3529                 unsigned int portlist[RTE_MAX_ETHPORTS];
3530         } parsed_items;
3531         unsigned int nb_item;
3532
3533         if (test_done == 0) {
3534                 printf("Please stop forwarding first\n");
3535                 return;
3536         }
3537
3538         res = parsed_result;
3539         if (!strcmp(res->list_name, "corelist")) {
3540                 nb_item = parse_item_list(res->list_of_items, "core",
3541                                           RTE_MAX_LCORE,
3542                                           parsed_items.lcorelist, 1);
3543                 if (nb_item > 0) {
3544                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3545                         fwd_config_setup();
3546                 }
3547                 return;
3548         }
3549         if (!strcmp(res->list_name, "portlist")) {
3550                 nb_item = parse_item_list(res->list_of_items, "port",
3551                                           RTE_MAX_ETHPORTS,
3552                                           parsed_items.portlist, 1);
3553                 if (nb_item > 0) {
3554                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3555                         fwd_config_setup();
3556                 }
3557         }
3558 }
3559
3560 cmdline_parse_token_string_t cmd_set_list_keyword =
3561         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3562                                  "set");
3563 cmdline_parse_token_string_t cmd_set_list_name =
3564         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3565                                  "corelist#portlist");
3566 cmdline_parse_token_string_t cmd_set_list_of_items =
3567         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3568                                  NULL);
3569
3570 cmdline_parse_inst_t cmd_set_fwd_list = {
3571         .f = cmd_set_list_parsed,
3572         .data = NULL,
3573         .help_str = "set corelist|portlist <list0[,list1]*>",
3574         .tokens = {
3575                 (void *)&cmd_set_list_keyword,
3576                 (void *)&cmd_set_list_name,
3577                 (void *)&cmd_set_list_of_items,
3578                 NULL,
3579         },
3580 };
3581
3582 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3583
3584 struct cmd_setmask_result {
3585         cmdline_fixed_string_t set;
3586         cmdline_fixed_string_t mask;
3587         uint64_t hexavalue;
3588 };
3589
3590 static void cmd_set_mask_parsed(void *parsed_result,
3591                                 __attribute__((unused)) struct cmdline *cl,
3592                                 __attribute__((unused)) void *data)
3593 {
3594         struct cmd_setmask_result *res = parsed_result;
3595
3596         if (test_done == 0) {
3597                 printf("Please stop forwarding first\n");
3598                 return;
3599         }
3600         if (!strcmp(res->mask, "coremask")) {
3601                 set_fwd_lcores_mask(res->hexavalue);
3602                 fwd_config_setup();
3603         } else if (!strcmp(res->mask, "portmask")) {
3604                 set_fwd_ports_mask(res->hexavalue);
3605                 fwd_config_setup();
3606         }
3607 }
3608
3609 cmdline_parse_token_string_t cmd_setmask_set =
3610         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3611 cmdline_parse_token_string_t cmd_setmask_mask =
3612         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3613                                  "coremask#portmask");
3614 cmdline_parse_token_num_t cmd_setmask_value =
3615         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3616
3617 cmdline_parse_inst_t cmd_set_fwd_mask = {
3618         .f = cmd_set_mask_parsed,
3619         .data = NULL,
3620         .help_str = "set coremask|portmask <hexadecimal value>",
3621         .tokens = {
3622                 (void *)&cmd_setmask_set,
3623                 (void *)&cmd_setmask_mask,
3624                 (void *)&cmd_setmask_value,
3625                 NULL,
3626         },
3627 };
3628
3629 /*
3630  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3631  */
3632 struct cmd_set_result {
3633         cmdline_fixed_string_t set;
3634         cmdline_fixed_string_t what;
3635         uint16_t value;
3636 };
3637
3638 static void cmd_set_parsed(void *parsed_result,
3639                            __attribute__((unused)) struct cmdline *cl,
3640                            __attribute__((unused)) void *data)
3641 {
3642         struct cmd_set_result *res = parsed_result;
3643         if (!strcmp(res->what, "nbport")) {
3644                 set_fwd_ports_number(res->value);
3645                 fwd_config_setup();
3646         } else if (!strcmp(res->what, "nbcore")) {
3647                 set_fwd_lcores_number(res->value);
3648                 fwd_config_setup();
3649         } else if (!strcmp(res->what, "burst"))
3650                 set_nb_pkt_per_burst(res->value);
3651         else if (!strcmp(res->what, "verbose"))
3652                 set_verbose_level(res->value);
3653 }
3654
3655 cmdline_parse_token_string_t cmd_set_set =
3656         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3657 cmdline_parse_token_string_t cmd_set_what =
3658         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3659                                  "nbport#nbcore#burst#verbose");
3660 cmdline_parse_token_num_t cmd_set_value =
3661         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3662
3663 cmdline_parse_inst_t cmd_set_numbers = {
3664         .f = cmd_set_parsed,
3665         .data = NULL,
3666         .help_str = "set nbport|nbcore|burst|verbose <value>",
3667         .tokens = {
3668                 (void *)&cmd_set_set,
3669                 (void *)&cmd_set_what,
3670                 (void *)&cmd_set_value,
3671                 NULL,
3672         },
3673 };
3674
3675 /* *** SET LOG LEVEL CONFIGURATION *** */
3676
3677 struct cmd_set_log_result {
3678         cmdline_fixed_string_t set;
3679         cmdline_fixed_string_t log;
3680         cmdline_fixed_string_t type;
3681         uint32_t level;
3682 };
3683
3684 static void
3685 cmd_set_log_parsed(void *parsed_result,
3686                    __attribute__((unused)) struct cmdline *cl,
3687                    __attribute__((unused)) void *data)
3688 {
3689         struct cmd_set_log_result *res;
3690         int ret;
3691
3692         res = parsed_result;
3693         if (!strcmp(res->type, "global"))
3694                 rte_log_set_global_level(res->level);
3695         else {
3696                 ret = rte_log_set_level_regexp(res->type, res->level);
3697                 if (ret < 0)
3698                         printf("Unable to set log level\n");
3699         }
3700 }
3701
3702 cmdline_parse_token_string_t cmd_set_log_set =
3703         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3704 cmdline_parse_token_string_t cmd_set_log_log =
3705         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3706 cmdline_parse_token_string_t cmd_set_log_type =
3707         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3708 cmdline_parse_token_num_t cmd_set_log_level =
3709         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3710
3711 cmdline_parse_inst_t cmd_set_log = {
3712         .f = cmd_set_log_parsed,
3713         .data = NULL,
3714         .help_str = "set log global|<type> <level>",
3715         .tokens = {
3716                 (void *)&cmd_set_log_set,
3717                 (void *)&cmd_set_log_log,
3718                 (void *)&cmd_set_log_type,
3719                 (void *)&cmd_set_log_level,
3720                 NULL,
3721         },
3722 };
3723
3724 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3725
3726 struct cmd_set_txpkts_result {
3727         cmdline_fixed_string_t cmd_keyword;
3728         cmdline_fixed_string_t txpkts;
3729         cmdline_fixed_string_t seg_lengths;
3730 };
3731
3732 static void
3733 cmd_set_txpkts_parsed(void *parsed_result,
3734                       __attribute__((unused)) struct cmdline *cl,
3735                       __attribute__((unused)) void *data)
3736 {
3737         struct cmd_set_txpkts_result *res;
3738         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3739         unsigned int nb_segs;
3740
3741         res = parsed_result;
3742         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3743                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3744         if (nb_segs > 0)
3745                 set_tx_pkt_segments(seg_lengths, nb_segs);
3746 }
3747
3748 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3749         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3750                                  cmd_keyword, "set");
3751 cmdline_parse_token_string_t cmd_set_txpkts_name =
3752         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3753                                  txpkts, "txpkts");
3754 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3755         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3756                                  seg_lengths, NULL);
3757
3758 cmdline_parse_inst_t cmd_set_txpkts = {
3759         .f = cmd_set_txpkts_parsed,
3760         .data = NULL,
3761         .help_str = "set txpkts <len0[,len1]*>",
3762         .tokens = {
3763                 (void *)&cmd_set_txpkts_keyword,
3764                 (void *)&cmd_set_txpkts_name,
3765                 (void *)&cmd_set_txpkts_lengths,
3766                 NULL,
3767         },
3768 };
3769
3770 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3771
3772 struct cmd_set_txsplit_result {
3773         cmdline_fixed_string_t cmd_keyword;
3774         cmdline_fixed_string_t txsplit;
3775         cmdline_fixed_string_t mode;
3776 };
3777
3778 static void
3779 cmd_set_txsplit_parsed(void *parsed_result,
3780                       __attribute__((unused)) struct cmdline *cl,
3781                       __attribute__((unused)) void *data)
3782 {
3783         struct cmd_set_txsplit_result *res;
3784
3785         res = parsed_result;
3786         set_tx_pkt_split(res->mode);
3787 }
3788
3789 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3790         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3791                                  cmd_keyword, "set");
3792 cmdline_parse_token_string_t cmd_set_txsplit_name =
3793         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3794                                  txsplit, "txsplit");
3795 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3796         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3797                                  mode, NULL);
3798
3799 cmdline_parse_inst_t cmd_set_txsplit = {
3800         .f = cmd_set_txsplit_parsed,
3801         .data = NULL,
3802         .help_str = "set txsplit on|off|rand",
3803         .tokens = {
3804                 (void *)&cmd_set_txsplit_keyword,
3805                 (void *)&cmd_set_txsplit_name,
3806                 (void *)&cmd_set_txsplit_mode,
3807                 NULL,
3808         },
3809 };
3810
3811 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3812 struct cmd_rx_vlan_filter_all_result {
3813         cmdline_fixed_string_t rx_vlan;
3814         cmdline_fixed_string_t what;
3815         cmdline_fixed_string_t all;
3816         portid_t port_id;
3817 };
3818
3819 static void
3820 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3821                               __attribute__((unused)) struct cmdline *cl,
3822                               __attribute__((unused)) void *data)
3823 {
3824         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3825
3826         if (!strcmp(res->what, "add"))
3827                 rx_vlan_all_filter_set(res->port_id, 1);
3828         else
3829                 rx_vlan_all_filter_set(res->port_id, 0);
3830 }
3831
3832 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3833         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3834                                  rx_vlan, "rx_vlan");
3835 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3836         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3837                                  what, "add#rm");
3838 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3839         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3840                                  all, "all");
3841 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3842         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3843                               port_id, UINT16);
3844
3845 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3846         .f = cmd_rx_vlan_filter_all_parsed,
3847         .data = NULL,
3848         .help_str = "rx_vlan add|rm all <port_id>: "
3849                 "Add/Remove all identifiers to/from the set of VLAN "
3850                 "identifiers filtered by a port",
3851         .tokens = {
3852                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3853                 (void *)&cmd_rx_vlan_filter_all_what,
3854                 (void *)&cmd_rx_vlan_filter_all_all,
3855                 (void *)&cmd_rx_vlan_filter_all_portid,
3856                 NULL,
3857         },
3858 };
3859
3860 /* *** VLAN OFFLOAD SET ON A PORT *** */
3861 struct cmd_vlan_offload_result {
3862         cmdline_fixed_string_t vlan;
3863         cmdline_fixed_string_t set;
3864         cmdline_fixed_string_t vlan_type;
3865         cmdline_fixed_string_t what;
3866         cmdline_fixed_string_t on;
3867         cmdline_fixed_string_t port_id;
3868 };
3869
3870 static void
3871 cmd_vlan_offload_parsed(void *parsed_result,
3872                           __attribute__((unused)) struct cmdline *cl,
3873                           __attribute__((unused)) void *data)
3874 {
3875         int on;
3876         struct cmd_vlan_offload_result *res = parsed_result;
3877         char *str;
3878         int i, len = 0;
3879         portid_t port_id = 0;
3880         unsigned int tmp;
3881
3882         str = res->port_id;
3883         len = strnlen(str, STR_TOKEN_SIZE);
3884         i = 0;
3885         /* Get port_id first */
3886         while(i < len){
3887                 if(str[i] == ',')
3888                         break;
3889
3890                 i++;
3891         }
3892         str[i]='\0';
3893         tmp = strtoul(str, NULL, 0);
3894         /* If port_id greater that what portid_t can represent, return */
3895         if(tmp >= RTE_MAX_ETHPORTS)
3896                 return;
3897         port_id = (portid_t)tmp;
3898
3899         if (!strcmp(res->on, "on"))
3900                 on = 1;
3901         else
3902                 on = 0;
3903
3904         if (!strcmp(res->what, "strip"))
3905                 rx_vlan_strip_set(port_id,  on);
3906         else if(!strcmp(res->what, "stripq")){
3907                 uint16_t queue_id = 0;
3908
3909                 /* No queue_id, return */
3910                 if(i + 1 >= len) {
3911                         printf("must specify (port,queue_id)\n");
3912                         return;
3913                 }
3914                 tmp = strtoul(str + i + 1, NULL, 0);
3915                 /* If queue_id greater that what 16-bits can represent, return */
3916                 if(tmp > 0xffff)
3917                         return;
3918
3919                 queue_id = (uint16_t)tmp;
3920                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3921         }
3922         else if (!strcmp(res->what, "filter"))
3923                 rx_vlan_filter_set(port_id, on);
3924         else
3925                 vlan_extend_set(port_id, on);
3926
3927         return;
3928 }
3929
3930 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3931         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3932                                  vlan, "vlan");
3933 cmdline_parse_token_string_t cmd_vlan_offload_set =
3934         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3935                                  set, "set");
3936 cmdline_parse_token_string_t cmd_vlan_offload_what =
3937         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3938                                  what, "strip#filter#qinq#stripq");
3939 cmdline_parse_token_string_t cmd_vlan_offload_on =
3940         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3941                               on, "on#off");
3942 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3943         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3944                               port_id, NULL);
3945
3946 cmdline_parse_inst_t cmd_vlan_offload = {
3947         .f = cmd_vlan_offload_parsed,
3948         .data = NULL,
3949         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3950                 "<port_id[,queue_id]>: "
3951                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3952         .tokens = {
3953                 (void *)&cmd_vlan_offload_vlan,
3954                 (void *)&cmd_vlan_offload_set,
3955                 (void *)&cmd_vlan_offload_what,
3956                 (void *)&cmd_vlan_offload_on,
3957                 (void *)&cmd_vlan_offload_portid,
3958                 NULL,
3959         },
3960 };
3961
3962 /* *** VLAN TPID SET ON A PORT *** */
3963 struct cmd_vlan_tpid_result {
3964         cmdline_fixed_string_t vlan;
3965         cmdline_fixed_string_t set;
3966         cmdline_fixed_string_t vlan_type;
3967         cmdline_fixed_string_t what;
3968         uint16_t tp_id;
3969         portid_t port_id;
3970 };
3971
3972 static void
3973 cmd_vlan_tpid_parsed(void *parsed_result,
3974                           __attribute__((unused)) struct cmdline *cl,
3975                           __attribute__((unused)) void *data)
3976 {
3977         struct cmd_vlan_tpid_result *res = parsed_result;
3978         enum rte_vlan_type vlan_type;
3979
3980         if (!strcmp(res->vlan_type, "inner"))
3981                 vlan_type = ETH_VLAN_TYPE_INNER;
3982         else if (!strcmp(res->vlan_type, "outer"))
3983                 vlan_type = ETH_VLAN_TYPE_OUTER;
3984         else {
3985                 printf("Unknown vlan type\n");
3986                 return;
3987         }
3988         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3989 }
3990
3991 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3992         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3993                                  vlan, "vlan");
3994 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3995         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3996                                  set, "set");
3997 cmdline_parse_token_string_t cmd_vlan_type =
3998         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3999                                  vlan_type, "inner#outer");
4000 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4001         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4002                                  what, "tpid");
4003 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4004         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4005                               tp_id, UINT16);
4006 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4007         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4008                               port_id, UINT16);
4009
4010 cmdline_parse_inst_t cmd_vlan_tpid = {
4011         .f = cmd_vlan_tpid_parsed,
4012         .data = NULL,
4013         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4014                 "Set the VLAN Ether type",
4015         .tokens = {
4016                 (void *)&cmd_vlan_tpid_vlan,
4017                 (void *)&cmd_vlan_tpid_set,
4018                 (void *)&cmd_vlan_type,
4019                 (void *)&cmd_vlan_tpid_what,
4020                 (void *)&cmd_vlan_tpid_tpid,
4021                 (void *)&cmd_vlan_tpid_portid,
4022                 NULL,
4023         },
4024 };
4025
4026 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4027 struct cmd_rx_vlan_filter_result {
4028         cmdline_fixed_string_t rx_vlan;
4029         cmdline_fixed_string_t what;
4030         uint16_t vlan_id;
4031         portid_t port_id;
4032 };
4033
4034 static void
4035 cmd_rx_vlan_filter_parsed(void *parsed_result,
4036                           __attribute__((unused)) struct cmdline *cl,
4037                           __attribute__((unused)) void *data)
4038 {
4039         struct cmd_rx_vlan_filter_result *res = parsed_result;
4040
4041         if (!strcmp(res->what, "add"))
4042                 rx_vft_set(res->port_id, res->vlan_id, 1);
4043         else
4044                 rx_vft_set(res->port_id, res->vlan_id, 0);
4045 }
4046
4047 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4048         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4049                                  rx_vlan, "rx_vlan");
4050 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4051         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4052                                  what, "add#rm");
4053 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4054         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4055                               vlan_id, UINT16);
4056 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4057         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4058                               port_id, UINT16);
4059
4060 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4061         .f = cmd_rx_vlan_filter_parsed,
4062         .data = NULL,
4063         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4064                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4065                 "identifiers filtered by a port",
4066         .tokens = {
4067                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4068                 (void *)&cmd_rx_vlan_filter_what,
4069                 (void *)&cmd_rx_vlan_filter_vlanid,
4070                 (void *)&cmd_rx_vlan_filter_portid,
4071                 NULL,
4072         },
4073 };
4074
4075 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4076 struct cmd_tx_vlan_set_result {
4077         cmdline_fixed_string_t tx_vlan;
4078         cmdline_fixed_string_t set;
4079         portid_t port_id;
4080         uint16_t vlan_id;
4081 };
4082
4083 static void
4084 cmd_tx_vlan_set_parsed(void *parsed_result,
4085                        __attribute__((unused)) struct cmdline *cl,
4086                        __attribute__((unused)) void *data)
4087 {
4088         struct cmd_tx_vlan_set_result *res = parsed_result;
4089
4090         if (!port_is_stopped(res->port_id)) {
4091                 printf("Please stop port %d first\n", res->port_id);
4092                 return;
4093         }
4094
4095         tx_vlan_set(res->port_id, res->vlan_id);
4096
4097         cmd_reconfig_device_queue(res->port_id, 1, 1);
4098 }
4099
4100 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4101         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4102                                  tx_vlan, "tx_vlan");
4103 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4104         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4105                                  set, "set");
4106 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4107         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4108                               port_id, UINT16);
4109 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4110         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4111                               vlan_id, UINT16);
4112
4113 cmdline_parse_inst_t cmd_tx_vlan_set = {
4114         .f = cmd_tx_vlan_set_parsed,
4115         .data = NULL,
4116         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4117                 "Enable hardware insertion of a single VLAN header "
4118                 "with a given TAG Identifier in packets sent on a port",
4119         .tokens = {
4120                 (void *)&cmd_tx_vlan_set_tx_vlan,
4121                 (void *)&cmd_tx_vlan_set_set,
4122                 (void *)&cmd_tx_vlan_set_portid,
4123                 (void *)&cmd_tx_vlan_set_vlanid,
4124                 NULL,
4125         },
4126 };
4127
4128 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4129 struct cmd_tx_vlan_set_qinq_result {
4130         cmdline_fixed_string_t tx_vlan;
4131         cmdline_fixed_string_t set;
4132         portid_t port_id;
4133         uint16_t vlan_id;
4134         uint16_t vlan_id_outer;
4135 };
4136
4137 static void
4138 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4139                             __attribute__((unused)) struct cmdline *cl,
4140                             __attribute__((unused)) void *data)
4141 {
4142         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4143
4144         if (!port_is_stopped(res->port_id)) {
4145                 printf("Please stop port %d first\n", res->port_id);
4146                 return;
4147         }
4148
4149         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4150
4151         cmd_reconfig_device_queue(res->port_id, 1, 1);
4152 }
4153
4154 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4155         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4156                 tx_vlan, "tx_vlan");
4157 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4158         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4159                 set, "set");
4160 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4161         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4162                 port_id, UINT16);
4163 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4164         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4165                 vlan_id, UINT16);
4166 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4167         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4168                 vlan_id_outer, UINT16);
4169
4170 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4171         .f = cmd_tx_vlan_set_qinq_parsed,
4172         .data = NULL,
4173         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4174                 "Enable hardware insertion of double VLAN header "
4175                 "with given TAG Identifiers in packets sent on a port",
4176         .tokens = {
4177                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4178                 (void *)&cmd_tx_vlan_set_qinq_set,
4179                 (void *)&cmd_tx_vlan_set_qinq_portid,
4180                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4181                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4182                 NULL,
4183         },
4184 };
4185
4186 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4187 struct cmd_tx_vlan_set_pvid_result {
4188         cmdline_fixed_string_t tx_vlan;
4189         cmdline_fixed_string_t set;
4190         cmdline_fixed_string_t pvid;
4191         portid_t port_id;
4192         uint16_t vlan_id;
4193         cmdline_fixed_string_t mode;
4194 };
4195
4196 static void
4197 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4198                             __attribute__((unused)) struct cmdline *cl,
4199                             __attribute__((unused)) void *data)
4200 {
4201         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4202
4203         if (strcmp(res->mode, "on") == 0)
4204                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4205         else
4206                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4207 }
4208
4209 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4210         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4211                                  tx_vlan, "tx_vlan");
4212 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4213         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4214                                  set, "set");
4215 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4216         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4217                                  pvid, "pvid");
4218 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4219         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4220                              port_id, UINT16);
4221 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4222         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4223                               vlan_id, UINT16);
4224 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4225         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4226                                  mode, "on#off");
4227
4228 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4229         .f = cmd_tx_vlan_set_pvid_parsed,
4230         .data = NULL,
4231         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4232         .tokens = {
4233                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4234                 (void *)&cmd_tx_vlan_set_pvid_set,
4235                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4236                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4237                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4238                 (void *)&cmd_tx_vlan_set_pvid_mode,
4239                 NULL,
4240         },
4241 };
4242
4243 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4244 struct cmd_tx_vlan_reset_result {
4245         cmdline_fixed_string_t tx_vlan;
4246         cmdline_fixed_string_t reset;
4247         portid_t port_id;
4248 };
4249
4250 static void
4251 cmd_tx_vlan_reset_parsed(void *parsed_result,
4252                          __attribute__((unused)) struct cmdline *cl,
4253                          __attribute__((unused)) void *data)
4254 {
4255         struct cmd_tx_vlan_reset_result *res = parsed_result;
4256
4257         if (!port_is_stopped(res->port_id)) {
4258                 printf("Please stop port %d first\n", res->port_id);
4259                 return;
4260         }
4261
4262         tx_vlan_reset(res->port_id);
4263
4264         cmd_reconfig_device_queue(res->port_id, 1, 1);
4265 }
4266
4267 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4268         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4269                                  tx_vlan, "tx_vlan");
4270 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4271         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4272                                  reset, "reset");
4273 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4274         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4275                               port_id, UINT16);
4276
4277 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4278         .f = cmd_tx_vlan_reset_parsed,
4279         .data = NULL,
4280         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4281                 "VLAN header in packets sent on a port",
4282         .tokens = {
4283                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4284                 (void *)&cmd_tx_vlan_reset_reset,
4285                 (void *)&cmd_tx_vlan_reset_portid,
4286                 NULL,
4287         },
4288 };
4289
4290
4291 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4292 struct cmd_csum_result {
4293         cmdline_fixed_string_t csum;
4294         cmdline_fixed_string_t mode;
4295         cmdline_fixed_string_t proto;
4296         cmdline_fixed_string_t hwsw;
4297         portid_t port_id;
4298 };
4299
4300 static void
4301 csum_show(int port_id)
4302 {
4303         struct rte_eth_dev_info dev_info;
4304         uint64_t tx_offloads;
4305         int ret;
4306
4307         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4308         printf("Parse tunnel is %s\n",
4309                 (ports[port_id].parse_tunnel) ? "on" : "off");
4310         printf("IP checksum offload is %s\n",
4311                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4312         printf("UDP checksum offload is %s\n",
4313                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4314         printf("TCP checksum offload is %s\n",
4315                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4316         printf("SCTP checksum offload is %s\n",
4317                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4318         printf("Outer-Ip checksum offload is %s\n",
4319                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4320         printf("Outer-Udp checksum offload is %s\n",
4321                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4322
4323         /* display warnings if configuration is not supported by the NIC */
4324         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4325         if (ret != 0)
4326                 return;
4327
4328         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4329                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4330                 printf("Warning: hardware IP checksum enabled but not "
4331                         "supported by port %d\n", port_id);
4332         }
4333         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4334                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4335                 printf("Warning: hardware UDP checksum enabled but not "
4336                         "supported by port %d\n", port_id);
4337         }
4338         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4339                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4340                 printf("Warning: hardware TCP checksum enabled but not "
4341                         "supported by port %d\n", port_id);
4342         }
4343         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4344                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4345                 printf("Warning: hardware SCTP checksum enabled but not "
4346                         "supported by port %d\n", port_id);
4347         }
4348         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4349                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4350                 printf("Warning: hardware outer IP checksum enabled but not "
4351                         "supported by port %d\n", port_id);
4352         }
4353         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4354                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4355                         == 0) {
4356                 printf("Warning: hardware outer UDP checksum enabled but not "
4357                         "supported by port %d\n", port_id);
4358         }
4359 }
4360
4361 static void
4362 cmd_config_queue_tx_offloads(struct rte_port *port)
4363 {
4364         int k;
4365
4366         /* Apply queue tx offloads configuration */
4367         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4368                 port->tx_conf[k].offloads =
4369                         port->dev_conf.txmode.offloads;
4370 }
4371
4372 static void
4373 cmd_csum_parsed(void *parsed_result,
4374                        __attribute__((unused)) struct cmdline *cl,
4375                        __attribute__((unused)) void *data)
4376 {
4377         struct cmd_csum_result *res = parsed_result;
4378         int hw = 0;
4379         uint64_t csum_offloads = 0;
4380         struct rte_eth_dev_info dev_info;
4381         int ret;
4382
4383         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4384                 printf("invalid port %d\n", res->port_id);
4385                 return;
4386         }
4387         if (!port_is_stopped(res->port_id)) {
4388                 printf("Please stop port %d first\n", res->port_id);
4389                 return;
4390         }
4391
4392         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4393         if (ret != 0)
4394                 return;
4395
4396         if (!strcmp(res->mode, "set")) {
4397
4398                 if (!strcmp(res->hwsw, "hw"))
4399                         hw = 1;
4400
4401                 if (!strcmp(res->proto, "ip")) {
4402                         if (hw == 0 || (dev_info.tx_offload_capa &
4403                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4404                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4405                         } else {
4406                                 printf("IP checksum offload is not supported "
4407                                        "by port %u\n", res->port_id);
4408                         }
4409                 } else if (!strcmp(res->proto, "udp")) {
4410                         if (hw == 0 || (dev_info.tx_offload_capa &
4411                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4412                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4413                         } else {
4414                                 printf("UDP checksum offload is not supported "
4415                                        "by port %u\n", res->port_id);
4416                         }
4417                 } else if (!strcmp(res->proto, "tcp")) {
4418                         if (hw == 0 || (dev_info.tx_offload_capa &
4419                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4420                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4421                         } else {
4422                                 printf("TCP checksum offload is not supported "
4423                                        "by port %u\n", res->port_id);
4424                         }
4425                 } else if (!strcmp(res->proto, "sctp")) {
4426                         if (hw == 0 || (dev_info.tx_offload_capa &
4427                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4428                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4429                         } else {
4430                                 printf("SCTP checksum offload is not supported "
4431                                        "by port %u\n", res->port_id);
4432                         }
4433                 } else if (!strcmp(res->proto, "outer-ip")) {
4434                         if (hw == 0 || (dev_info.tx_offload_capa &
4435                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4436                                 csum_offloads |=
4437                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4438                         } else {
4439                                 printf("Outer IP checksum offload is not "
4440                                        "supported by port %u\n", res->port_id);
4441                         }
4442                 } else if (!strcmp(res->proto, "outer-udp")) {
4443                         if (hw == 0 || (dev_info.tx_offload_capa &
4444                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4445                                 csum_offloads |=
4446                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4447                         } else {
4448                                 printf("Outer UDP checksum offload is not "
4449                                        "supported by port %u\n", res->port_id);
4450                         }
4451                 }
4452
4453                 if (hw) {
4454                         ports[res->port_id].dev_conf.txmode.offloads |=
4455                                                         csum_offloads;
4456                 } else {
4457                         ports[res->port_id].dev_conf.txmode.offloads &=
4458                                                         (~csum_offloads);
4459                 }
4460                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4461         }
4462         csum_show(res->port_id);
4463
4464         cmd_reconfig_device_queue(res->port_id, 1, 1);
4465 }
4466
4467 cmdline_parse_token_string_t cmd_csum_csum =
4468         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4469                                 csum, "csum");
4470 cmdline_parse_token_string_t cmd_csum_mode =
4471         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4472                                 mode, "set");
4473 cmdline_parse_token_string_t cmd_csum_proto =
4474         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4475                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4476 cmdline_parse_token_string_t cmd_csum_hwsw =
4477         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4478                                 hwsw, "hw#sw");
4479 cmdline_parse_token_num_t cmd_csum_portid =
4480         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4481                                 port_id, UINT16);
4482
4483 cmdline_parse_inst_t cmd_csum_set = {
4484         .f = cmd_csum_parsed,
4485         .data = NULL,
4486         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4487                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4488                 "using csum forward engine",
4489         .tokens = {
4490                 (void *)&cmd_csum_csum,
4491                 (void *)&cmd_csum_mode,
4492                 (void *)&cmd_csum_proto,
4493                 (void *)&cmd_csum_hwsw,
4494                 (void *)&cmd_csum_portid,
4495                 NULL,
4496         },
4497 };
4498
4499 cmdline_parse_token_string_t cmd_csum_mode_show =
4500         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4501                                 mode, "show");
4502
4503 cmdline_parse_inst_t cmd_csum_show = {
4504         .f = cmd_csum_parsed,
4505         .data = NULL,
4506         .help_str = "csum show <port_id>: Show checksum offload configuration",
4507         .tokens = {
4508                 (void *)&cmd_csum_csum,
4509                 (void *)&cmd_csum_mode_show,
4510                 (void *)&cmd_csum_portid,
4511                 NULL,
4512         },
4513 };
4514
4515 /* Enable/disable tunnel parsing */
4516 struct cmd_csum_tunnel_result {
4517         cmdline_fixed_string_t csum;
4518         cmdline_fixed_string_t parse;
4519         cmdline_fixed_string_t onoff;
4520         portid_t port_id;
4521 };
4522
4523 static void
4524 cmd_csum_tunnel_parsed(void *parsed_result,
4525                        __attribute__((unused)) struct cmdline *cl,
4526                        __attribute__((unused)) void *data)
4527 {
4528         struct cmd_csum_tunnel_result *res = parsed_result;
4529
4530         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4531                 return;
4532
4533         if (!strcmp(res->onoff, "on"))
4534                 ports[res->port_id].parse_tunnel = 1;
4535         else
4536                 ports[res->port_id].parse_tunnel = 0;
4537
4538         csum_show(res->port_id);
4539 }
4540
4541 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4542         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4543                                 csum, "csum");
4544 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4545         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4546                                 parse, "parse-tunnel");
4547 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4548         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4549                                 onoff, "on#off");
4550 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4551         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4552                                 port_id, UINT16);
4553
4554 cmdline_parse_inst_t cmd_csum_tunnel = {
4555         .f = cmd_csum_tunnel_parsed,
4556         .data = NULL,
4557         .help_str = "csum parse-tunnel on|off <port_id>: "
4558                 "Enable/Disable parsing of tunnels for csum engine",
4559         .tokens = {
4560                 (void *)&cmd_csum_tunnel_csum,
4561                 (void *)&cmd_csum_tunnel_parse,
4562                 (void *)&cmd_csum_tunnel_onoff,
4563                 (void *)&cmd_csum_tunnel_portid,
4564                 NULL,
4565         },
4566 };
4567
4568 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4569 struct cmd_tso_set_result {
4570         cmdline_fixed_string_t tso;
4571         cmdline_fixed_string_t mode;
4572         uint16_t tso_segsz;
4573         portid_t port_id;
4574 };
4575
4576 static void
4577 cmd_tso_set_parsed(void *parsed_result,
4578                        __attribute__((unused)) struct cmdline *cl,
4579                        __attribute__((unused)) void *data)
4580 {
4581         struct cmd_tso_set_result *res = parsed_result;
4582         struct rte_eth_dev_info dev_info;
4583         int ret;
4584
4585         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4586                 return;
4587         if (!port_is_stopped(res->port_id)) {
4588                 printf("Please stop port %d first\n", res->port_id);
4589                 return;
4590         }
4591
4592         if (!strcmp(res->mode, "set"))
4593                 ports[res->port_id].tso_segsz = res->tso_segsz;
4594
4595         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4596         if (ret != 0)
4597                 return;
4598
4599         if ((ports[res->port_id].tso_segsz != 0) &&
4600                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4601                 printf("Error: TSO is not supported by port %d\n",
4602                        res->port_id);
4603                 return;
4604         }
4605
4606         if (ports[res->port_id].tso_segsz == 0) {
4607                 ports[res->port_id].dev_conf.txmode.offloads &=
4608                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4609                 printf("TSO for non-tunneled packets is disabled\n");
4610         } else {
4611                 ports[res->port_id].dev_conf.txmode.offloads |=
4612                                                 DEV_TX_OFFLOAD_TCP_TSO;
4613                 printf("TSO segment size for non-tunneled packets is %d\n",
4614                         ports[res->port_id].tso_segsz);
4615         }
4616         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4617
4618         /* display warnings if configuration is not supported by the NIC */
4619         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4620         if (ret != 0)
4621                 return;
4622
4623         if ((ports[res->port_id].tso_segsz != 0) &&
4624                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4625                 printf("Warning: TSO enabled but not "
4626                         "supported by port %d\n", res->port_id);
4627         }
4628
4629         cmd_reconfig_device_queue(res->port_id, 1, 1);
4630 }
4631
4632 cmdline_parse_token_string_t cmd_tso_set_tso =
4633         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4634                                 tso, "tso");
4635 cmdline_parse_token_string_t cmd_tso_set_mode =
4636         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4637                                 mode, "set");
4638 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4639         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4640                                 tso_segsz, UINT16);
4641 cmdline_parse_token_num_t cmd_tso_set_portid =
4642         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4643                                 port_id, UINT16);
4644
4645 cmdline_parse_inst_t cmd_tso_set = {
4646         .f = cmd_tso_set_parsed,
4647         .data = NULL,
4648         .help_str = "tso set <tso_segsz> <port_id>: "
4649                 "Set TSO segment size of non-tunneled packets for csum engine "
4650                 "(0 to disable)",
4651         .tokens = {
4652                 (void *)&cmd_tso_set_tso,
4653                 (void *)&cmd_tso_set_mode,
4654                 (void *)&cmd_tso_set_tso_segsz,
4655                 (void *)&cmd_tso_set_portid,
4656                 NULL,
4657         },
4658 };
4659
4660 cmdline_parse_token_string_t cmd_tso_show_mode =
4661         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4662                                 mode, "show");
4663
4664
4665 cmdline_parse_inst_t cmd_tso_show = {
4666         .f = cmd_tso_set_parsed,
4667         .data = NULL,
4668         .help_str = "tso show <port_id>: "
4669                 "Show TSO segment size of non-tunneled packets for csum engine",
4670         .tokens = {
4671                 (void *)&cmd_tso_set_tso,
4672                 (void *)&cmd_tso_show_mode,
4673                 (void *)&cmd_tso_set_portid,
4674                 NULL,
4675         },
4676 };
4677
4678 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4679 struct cmd_tunnel_tso_set_result {
4680         cmdline_fixed_string_t tso;
4681         cmdline_fixed_string_t mode;
4682         uint16_t tso_segsz;
4683         portid_t port_id;
4684 };
4685
4686 static struct rte_eth_dev_info
4687 check_tunnel_tso_nic_support(portid_t port_id)
4688 {
4689         struct rte_eth_dev_info dev_info;
4690
4691         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4692                 return dev_info;
4693
4694         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4695                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4696                        "not enabled for port %d\n", port_id);
4697         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4698                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4699                        "not enabled for port %d\n", port_id);
4700         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4701                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4702                        "not enabled for port %d\n", port_id);
4703         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4704                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4705                        "not enabled for port %d\n", port_id);
4706         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4707                 printf("Warning: IP TUNNEL TSO not supported therefore "
4708                        "not enabled for port %d\n", port_id);
4709         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4710                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4711                        "not enabled for port %d\n", port_id);
4712         return dev_info;
4713 }
4714
4715 static void
4716 cmd_tunnel_tso_set_parsed(void *parsed_result,
4717                           __attribute__((unused)) struct cmdline *cl,
4718                           __attribute__((unused)) void *data)
4719 {
4720         struct cmd_tunnel_tso_set_result *res = parsed_result;
4721         struct rte_eth_dev_info dev_info;
4722
4723         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4724                 return;
4725         if (!port_is_stopped(res->port_id)) {
4726                 printf("Please stop port %d first\n", res->port_id);
4727                 return;
4728         }
4729
4730         if (!strcmp(res->mode, "set"))
4731                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4732
4733         dev_info = check_tunnel_tso_nic_support(res->port_id);
4734         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4735                 ports[res->port_id].dev_conf.txmode.offloads &=
4736                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4737                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4738                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4739                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4740                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4741                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4742                 printf("TSO for tunneled packets is disabled\n");
4743         } else {
4744                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4745                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4746                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4747                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4748                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4749                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4750
4751                 ports[res->port_id].dev_conf.txmode.offloads |=
4752                         (tso_offloads & dev_info.tx_offload_capa);
4753                 printf("TSO segment size for tunneled packets is %d\n",
4754                         ports[res->port_id].tunnel_tso_segsz);
4755
4756                 /* Below conditions are needed to make it work:
4757                  * (1) tunnel TSO is supported by the NIC;
4758                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4759                  * are recognized;
4760                  * (3) for tunneled pkts with outer L3 of IPv4,
4761                  * "csum set outer-ip" must be set to hw, because after tso,
4762                  * total_len of outer IP header is changed, and the checksum
4763                  * of outer IP header calculated by sw should be wrong; that
4764                  * is not necessary for IPv6 tunneled pkts because there's no
4765                  * checksum in IP header anymore.
4766                  */
4767
4768                 if (!ports[res->port_id].parse_tunnel)
4769                         printf("Warning: csum parse_tunnel must be set "
4770                                 "so that tunneled packets are recognized\n");
4771                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4772                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4773                         printf("Warning: csum set outer-ip must be set to hw "
4774                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4775         }
4776
4777         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4778         cmd_reconfig_device_queue(res->port_id, 1, 1);
4779 }
4780
4781 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4782         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4783                                 tso, "tunnel_tso");
4784 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4785         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4786                                 mode, "set");
4787 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4788         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4789                                 tso_segsz, UINT16);
4790 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4791         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4792                                 port_id, UINT16);
4793
4794 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4795         .f = cmd_tunnel_tso_set_parsed,
4796         .data = NULL,
4797         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4798                 "Set TSO segment size of tunneled packets for csum engine "
4799                 "(0 to disable)",
4800         .tokens = {
4801                 (void *)&cmd_tunnel_tso_set_tso,
4802                 (void *)&cmd_tunnel_tso_set_mode,
4803                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4804                 (void *)&cmd_tunnel_tso_set_portid,
4805                 NULL,
4806         },
4807 };
4808
4809 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4810         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4811                                 mode, "show");
4812
4813
4814 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4815         .f = cmd_tunnel_tso_set_parsed,
4816         .data = NULL,
4817         .help_str = "tunnel_tso show <port_id> "
4818                 "Show TSO segment size of tunneled packets for csum engine",
4819         .tokens = {
4820                 (void *)&cmd_tunnel_tso_set_tso,
4821                 (void *)&cmd_tunnel_tso_show_mode,
4822                 (void *)&cmd_tunnel_tso_set_portid,
4823                 NULL,
4824         },
4825 };
4826
4827 /* *** SET GRO FOR A PORT *** */
4828 struct cmd_gro_enable_result {
4829         cmdline_fixed_string_t cmd_set;
4830         cmdline_fixed_string_t cmd_port;
4831         cmdline_fixed_string_t cmd_keyword;
4832         cmdline_fixed_string_t cmd_onoff;
4833         portid_t cmd_pid;
4834 };
4835
4836 static void
4837 cmd_gro_enable_parsed(void *parsed_result,
4838                 __attribute__((unused)) struct cmdline *cl,
4839                 __attribute__((unused)) void *data)
4840 {
4841         struct cmd_gro_enable_result *res;
4842
4843         res = parsed_result;
4844         if (!strcmp(res->cmd_keyword, "gro"))
4845                 setup_gro(res->cmd_onoff, res->cmd_pid);
4846 }
4847
4848 cmdline_parse_token_string_t cmd_gro_enable_set =
4849         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4850                         cmd_set, "set");
4851 cmdline_parse_token_string_t cmd_gro_enable_port =
4852         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4853                         cmd_keyword, "port");
4854 cmdline_parse_token_num_t cmd_gro_enable_pid =
4855         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4856                         cmd_pid, UINT16);
4857 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4858         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4859                         cmd_keyword, "gro");
4860 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4861         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4862                         cmd_onoff, "on#off");
4863
4864 cmdline_parse_inst_t cmd_gro_enable = {
4865         .f = cmd_gro_enable_parsed,
4866         .data = NULL,
4867         .help_str = "set port <port_id> gro on|off",
4868         .tokens = {
4869                 (void *)&cmd_gro_enable_set,
4870                 (void *)&cmd_gro_enable_port,
4871                 (void *)&cmd_gro_enable_pid,
4872                 (void *)&cmd_gro_enable_keyword,
4873                 (void *)&cmd_gro_enable_onoff,
4874                 NULL,
4875         },
4876 };
4877
4878 /* *** DISPLAY GRO CONFIGURATION *** */
4879 struct cmd_gro_show_result {
4880         cmdline_fixed_string_t cmd_show;
4881         cmdline_fixed_string_t cmd_port;
4882         cmdline_fixed_string_t cmd_keyword;
4883         portid_t cmd_pid;
4884 };
4885
4886 static void
4887 cmd_gro_show_parsed(void *parsed_result,
4888                 __attribute__((unused)) struct cmdline *cl,
4889                 __attribute__((unused)) void *data)
4890 {
4891         struct cmd_gro_show_result *res;
4892
4893         res = parsed_result;
4894         if (!strcmp(res->cmd_keyword, "gro"))
4895                 show_gro(res->cmd_pid);
4896 }
4897
4898 cmdline_parse_token_string_t cmd_gro_show_show =
4899         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4900                         cmd_show, "show");
4901 cmdline_parse_token_string_t cmd_gro_show_port =
4902         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4903                         cmd_port, "port");
4904 cmdline_parse_token_num_t cmd_gro_show_pid =
4905         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4906                         cmd_pid, UINT16);
4907 cmdline_parse_token_string_t cmd_gro_show_keyword =
4908         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4909                         cmd_keyword, "gro");
4910
4911 cmdline_parse_inst_t cmd_gro_show = {
4912         .f = cmd_gro_show_parsed,
4913         .data = NULL,
4914         .help_str = "show port <port_id> gro",
4915         .tokens = {
4916                 (void *)&cmd_gro_show_show,
4917                 (void *)&cmd_gro_show_port,
4918                 (void *)&cmd_gro_show_pid,
4919                 (void *)&cmd_gro_show_keyword,
4920                 NULL,
4921         },
4922 };
4923
4924 /* *** SET FLUSH CYCLES FOR GRO *** */
4925 struct cmd_gro_flush_result {
4926         cmdline_fixed_string_t cmd_set;
4927         cmdline_fixed_string_t cmd_keyword;
4928         cmdline_fixed_string_t cmd_flush;
4929         uint8_t cmd_cycles;
4930 };
4931
4932 static void
4933 cmd_gro_flush_parsed(void *parsed_result,
4934                 __attribute__((unused)) struct cmdline *cl,
4935                 __attribute__((unused)) void *data)
4936 {
4937         struct cmd_gro_flush_result *res;
4938
4939         res = parsed_result;
4940         if ((!strcmp(res->cmd_keyword, "gro")) &&
4941                         (!strcmp(res->cmd_flush, "flush")))
4942                 setup_gro_flush_cycles(res->cmd_cycles);
4943 }
4944
4945 cmdline_parse_token_string_t cmd_gro_flush_set =
4946         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4947                         cmd_set, "set");
4948 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4949         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4950                         cmd_keyword, "gro");
4951 cmdline_parse_token_string_t cmd_gro_flush_flush =
4952         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4953                         cmd_flush, "flush");
4954 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4955         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4956                         cmd_cycles, UINT8);
4957
4958 cmdline_parse_inst_t cmd_gro_flush = {
4959         .f = cmd_gro_flush_parsed,
4960         .data = NULL,
4961         .help_str = "set gro flush <cycles>",
4962         .tokens = {
4963                 (void *)&cmd_gro_flush_set,
4964                 (void *)&cmd_gro_flush_keyword,
4965                 (void *)&cmd_gro_flush_flush,
4966                 (void *)&cmd_gro_flush_cycles,
4967                 NULL,
4968         },
4969 };
4970
4971 /* *** ENABLE/DISABLE GSO *** */
4972 struct cmd_gso_enable_result {
4973         cmdline_fixed_string_t cmd_set;
4974         cmdline_fixed_string_t cmd_port;
4975         cmdline_fixed_string_t cmd_keyword;
4976         cmdline_fixed_string_t cmd_mode;
4977         portid_t cmd_pid;
4978 };
4979
4980 static void
4981 cmd_gso_enable_parsed(void *parsed_result,
4982                 __attribute__((unused)) struct cmdline *cl,
4983                 __attribute__((unused)) void *data)
4984 {
4985         struct cmd_gso_enable_result *res;
4986
4987         res = parsed_result;
4988         if (!strcmp(res->cmd_keyword, "gso"))
4989                 setup_gso(res->cmd_mode, res->cmd_pid);
4990 }
4991
4992 cmdline_parse_token_string_t cmd_gso_enable_set =
4993         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4994                         cmd_set, "set");
4995 cmdline_parse_token_string_t cmd_gso_enable_port =
4996         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4997                         cmd_port, "port");
4998 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4999         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5000                         cmd_keyword, "gso");
5001 cmdline_parse_token_string_t cmd_gso_enable_mode =
5002         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5003                         cmd_mode, "on#off");
5004 cmdline_parse_token_num_t cmd_gso_enable_pid =
5005         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5006                         cmd_pid, UINT16);
5007
5008 cmdline_parse_inst_t cmd_gso_enable = {
5009         .f = cmd_gso_enable_parsed,
5010         .data = NULL,
5011         .help_str = "set port <port_id> gso on|off",
5012         .tokens = {
5013                 (void *)&cmd_gso_enable_set,
5014                 (void *)&cmd_gso_enable_port,
5015                 (void *)&cmd_gso_enable_pid,
5016                 (void *)&cmd_gso_enable_keyword,
5017                 (void *)&cmd_gso_enable_mode,
5018                 NULL,
5019         },
5020 };
5021
5022 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5023 struct cmd_gso_size_result {
5024         cmdline_fixed_string_t cmd_set;
5025         cmdline_fixed_string_t cmd_keyword;
5026         cmdline_fixed_string_t cmd_segsz;
5027         uint16_t cmd_size;
5028 };
5029
5030 static void
5031 cmd_gso_size_parsed(void *parsed_result,
5032                        __attribute__((unused)) struct cmdline *cl,
5033                        __attribute__((unused)) void *data)
5034 {
5035         struct cmd_gso_size_result *res = parsed_result;
5036
5037         if (test_done == 0) {
5038                 printf("Before setting GSO segsz, please first"
5039                                 " stop fowarding\n");
5040                 return;
5041         }
5042
5043         if (!strcmp(res->cmd_keyword, "gso") &&
5044                         !strcmp(res->cmd_segsz, "segsz")) {
5045                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5046                         printf("gso_size should be larger than %zu."
5047                                         " Please input a legal value\n",
5048                                         RTE_GSO_SEG_SIZE_MIN);
5049                 else
5050                         gso_max_segment_size = res->cmd_size;
5051         }
5052 }
5053
5054 cmdline_parse_token_string_t cmd_gso_size_set =
5055         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5056                                 cmd_set, "set");
5057 cmdline_parse_token_string_t cmd_gso_size_keyword =
5058         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5059                                 cmd_keyword, "gso");
5060 cmdline_parse_token_string_t cmd_gso_size_segsz =
5061         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5062                                 cmd_segsz, "segsz");
5063 cmdline_parse_token_num_t cmd_gso_size_size =
5064         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5065                                 cmd_size, UINT16);
5066
5067 cmdline_parse_inst_t cmd_gso_size = {
5068         .f = cmd_gso_size_parsed,
5069         .data = NULL,
5070         .help_str = "set gso segsz <length>",
5071         .tokens = {
5072                 (void *)&cmd_gso_size_set,
5073                 (void *)&cmd_gso_size_keyword,
5074                 (void *)&cmd_gso_size_segsz,
5075                 (void *)&cmd_gso_size_size,
5076                 NULL,
5077         },
5078 };
5079
5080 /* *** SHOW GSO CONFIGURATION *** */
5081 struct cmd_gso_show_result {
5082         cmdline_fixed_string_t cmd_show;
5083         cmdline_fixed_string_t cmd_port;
5084         cmdline_fixed_string_t cmd_keyword;
5085         portid_t cmd_pid;
5086 };
5087
5088 static void
5089 cmd_gso_show_parsed(void *parsed_result,
5090                        __attribute__((unused)) struct cmdline *cl,
5091                        __attribute__((unused)) void *data)
5092 {
5093         struct cmd_gso_show_result *res = parsed_result;
5094
5095         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5096                 printf("invalid port id %u\n", res->cmd_pid);
5097                 return;
5098         }
5099         if (!strcmp(res->cmd_keyword, "gso")) {
5100                 if (gso_ports[res->cmd_pid].enable) {
5101                         printf("Max GSO'd packet size: %uB\n"
5102                                         "Supported GSO types: TCP/IPv4, "
5103                                         "UDP/IPv4, VxLAN with inner "
5104                                         "TCP/IPv4 packet, GRE with inner "
5105                                         "TCP/IPv4 packet\n",
5106                                         gso_max_segment_size);
5107                 } else
5108                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5109         }
5110 }
5111
5112 cmdline_parse_token_string_t cmd_gso_show_show =
5113 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5114                 cmd_show, "show");
5115 cmdline_parse_token_string_t cmd_gso_show_port =
5116 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5117                 cmd_port, "port");
5118 cmdline_parse_token_string_t cmd_gso_show_keyword =
5119         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5120                                 cmd_keyword, "gso");
5121 cmdline_parse_token_num_t cmd_gso_show_pid =
5122         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5123                                 cmd_pid, UINT16);
5124
5125 cmdline_parse_inst_t cmd_gso_show = {
5126         .f = cmd_gso_show_parsed,
5127         .data = NULL,
5128         .help_str = "show port <port_id> gso",
5129         .tokens = {
5130                 (void *)&cmd_gso_show_show,
5131                 (void *)&cmd_gso_show_port,
5132                 (void *)&cmd_gso_show_pid,
5133                 (void *)&cmd_gso_show_keyword,
5134                 NULL,
5135         },
5136 };
5137
5138 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5139 struct cmd_set_flush_rx {
5140         cmdline_fixed_string_t set;
5141         cmdline_fixed_string_t flush_rx;
5142         cmdline_fixed_string_t mode;
5143 };
5144
5145 static void
5146 cmd_set_flush_rx_parsed(void *parsed_result,
5147                 __attribute__((unused)) struct cmdline *cl,
5148                 __attribute__((unused)) void *data)
5149 {
5150         struct cmd_set_flush_rx *res = parsed_result;
5151         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5152 }
5153
5154 cmdline_parse_token_string_t cmd_setflushrx_set =
5155         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5156                         set, "set");
5157 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5158         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5159                         flush_rx, "flush_rx");
5160 cmdline_parse_token_string_t cmd_setflushrx_mode =
5161         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5162                         mode, "on#off");
5163
5164
5165 cmdline_parse_inst_t cmd_set_flush_rx = {
5166         .f = cmd_set_flush_rx_parsed,
5167         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5168         .data = NULL,
5169         .tokens = {
5170                 (void *)&cmd_setflushrx_set,
5171                 (void *)&cmd_setflushrx_flush_rx,
5172                 (void *)&cmd_setflushrx_mode,
5173                 NULL,
5174         },
5175 };
5176
5177 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5178 struct cmd_set_link_check {
5179         cmdline_fixed_string_t set;
5180         cmdline_fixed_string_t link_check;
5181         cmdline_fixed_string_t mode;
5182 };
5183
5184 static void
5185 cmd_set_link_check_parsed(void *parsed_result,
5186                 __attribute__((unused)) struct cmdline *cl,
5187                 __attribute__((unused)) void *data)
5188 {
5189         struct cmd_set_link_check *res = parsed_result;
5190         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5191 }
5192
5193 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5194         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5195                         set, "set");
5196 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5197         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5198                         link_check, "link_check");
5199 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5200         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5201                         mode, "on#off");
5202
5203
5204 cmdline_parse_inst_t cmd_set_link_check = {
5205         .f = cmd_set_link_check_parsed,
5206         .help_str = "set link_check on|off: Enable/Disable link status check "
5207                     "when starting/stopping a port",
5208         .data = NULL,
5209         .tokens = {
5210                 (void *)&cmd_setlinkcheck_set,
5211                 (void *)&cmd_setlinkcheck_link_check,
5212                 (void *)&cmd_setlinkcheck_mode,
5213                 NULL,
5214         },
5215 };
5216
5217 /* *** SET NIC BYPASS MODE *** */
5218 struct cmd_set_bypass_mode_result {
5219         cmdline_fixed_string_t set;
5220         cmdline_fixed_string_t bypass;
5221         cmdline_fixed_string_t mode;
5222         cmdline_fixed_string_t value;
5223         portid_t port_id;
5224 };
5225
5226 static void
5227 cmd_set_bypass_mode_parsed(void *parsed_result,
5228                 __attribute__((unused)) struct cmdline *cl,
5229                 __attribute__((unused)) void *data)
5230 {
5231         struct cmd_set_bypass_mode_result *res = parsed_result;
5232         portid_t port_id = res->port_id;
5233         int32_t rc = -EINVAL;
5234
5235 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5236         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5237
5238         if (!strcmp(res->value, "bypass"))
5239                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5240         else if (!strcmp(res->value, "isolate"))
5241                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5242         else
5243                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5244
5245         /* Set the bypass mode for the relevant port. */
5246         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5247 #endif
5248         if (rc != 0)
5249                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5250 }
5251
5252 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5253         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5254                         set, "set");
5255 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5256         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5257                         bypass, "bypass");
5258 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5259         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5260                         mode, "mode");
5261 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5262         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5263                         value, "normal#bypass#isolate");
5264 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5265         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5266                                 port_id, UINT16);
5267
5268 cmdline_parse_inst_t cmd_set_bypass_mode = {
5269         .f = cmd_set_bypass_mode_parsed,
5270         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5271                     "Set the NIC bypass mode for port_id",
5272         .data = NULL,
5273         .tokens = {
5274                 (void *)&cmd_setbypass_mode_set,
5275                 (void *)&cmd_setbypass_mode_bypass,
5276                 (void *)&cmd_setbypass_mode_mode,
5277                 (void *)&cmd_setbypass_mode_value,
5278                 (void *)&cmd_setbypass_mode_port,
5279                 NULL,
5280         },
5281 };
5282
5283 /* *** SET NIC BYPASS EVENT *** */
5284 struct cmd_set_bypass_event_result {
5285         cmdline_fixed_string_t set;
5286         cmdline_fixed_string_t bypass;
5287         cmdline_fixed_string_t event;
5288         cmdline_fixed_string_t event_value;
5289         cmdline_fixed_string_t mode;
5290         cmdline_fixed_string_t mode_value;
5291         portid_t port_id;
5292 };
5293
5294 static void
5295 cmd_set_bypass_event_parsed(void *parsed_result,
5296                 __attribute__((unused)) struct cmdline *cl,
5297                 __attribute__((unused)) void *data)
5298 {
5299         int32_t rc = -EINVAL;
5300         struct cmd_set_bypass_event_result *res = parsed_result;
5301         portid_t port_id = res->port_id;
5302
5303 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5304         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5305         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5306
5307         if (!strcmp(res->event_value, "timeout"))
5308                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5309         else if (!strcmp(res->event_value, "os_on"))
5310                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5311         else if (!strcmp(res->event_value, "os_off"))
5312                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5313         else if (!strcmp(res->event_value, "power_on"))
5314                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5315         else if (!strcmp(res->event_value, "power_off"))
5316                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5317         else
5318                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5319
5320         if (!strcmp(res->mode_value, "bypass"))
5321                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5322         else if (!strcmp(res->mode_value, "isolate"))
5323                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5324         else
5325                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5326
5327         /* Set the watchdog timeout. */
5328         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5329
5330                 rc = -EINVAL;
5331                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5332                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5333                                                            bypass_timeout);
5334                 }
5335                 if (rc != 0) {
5336                         printf("Failed to set timeout value %u "
5337                         "for port %d, errto code: %d.\n",
5338                         bypass_timeout, port_id, rc);
5339                 }
5340         }
5341
5342         /* Set the bypass event to transition to bypass mode. */
5343         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5344                                               bypass_mode);
5345 #endif
5346
5347         if (rc != 0)
5348                 printf("\t Failed to set bypass event for port = %d.\n",
5349                        port_id);
5350 }
5351
5352 cmdline_parse_token_string_t cmd_setbypass_event_set =
5353         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5354                         set, "set");
5355 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5356         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5357                         bypass, "bypass");
5358 cmdline_parse_token_string_t cmd_setbypass_event_event =
5359         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5360                         event, "event");
5361 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5362         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5363                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5364 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5365         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5366                         mode, "mode");
5367 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5368         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5369                         mode_value, "normal#bypass#isolate");
5370 cmdline_parse_token_num_t cmd_setbypass_event_port =
5371         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5372                                 port_id, UINT16);
5373
5374 cmdline_parse_inst_t cmd_set_bypass_event = {
5375         .f = cmd_set_bypass_event_parsed,
5376         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5377                 "power_off mode normal|bypass|isolate <port_id>: "
5378                 "Set the NIC bypass event mode for port_id",
5379         .data = NULL,
5380         .tokens = {
5381                 (void *)&cmd_setbypass_event_set,
5382                 (void *)&cmd_setbypass_event_bypass,
5383                 (void *)&cmd_setbypass_event_event,
5384                 (void *)&cmd_setbypass_event_event_value,
5385                 (void *)&cmd_setbypass_event_mode,
5386                 (void *)&cmd_setbypass_event_mode_value,
5387                 (void *)&cmd_setbypass_event_port,
5388                 NULL,
5389         },
5390 };
5391
5392
5393 /* *** SET NIC BYPASS TIMEOUT *** */
5394 struct cmd_set_bypass_timeout_result {
5395         cmdline_fixed_string_t set;
5396         cmdline_fixed_string_t bypass;
5397         cmdline_fixed_string_t timeout;
5398         cmdline_fixed_string_t value;
5399 };
5400
5401 static void
5402 cmd_set_bypass_timeout_parsed(void *parsed_result,
5403                 __attribute__((unused)) struct cmdline *cl,
5404                 __attribute__((unused)) void *data)
5405 {
5406         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5407
5408 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5409         if (!strcmp(res->value, "1.5"))
5410                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5411         else if (!strcmp(res->value, "2"))
5412                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5413         else if (!strcmp(res->value, "3"))
5414                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5415         else if (!strcmp(res->value, "4"))
5416                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5417         else if (!strcmp(res->value, "8"))
5418                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5419         else if (!strcmp(res->value, "16"))
5420                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5421         else if (!strcmp(res->value, "32"))
5422                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5423         else
5424                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5425 #endif
5426 }
5427
5428 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5429         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5430                         set, "set");
5431 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5432         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5433                         bypass, "bypass");
5434 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5435         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5436                         timeout, "timeout");
5437 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5438         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5439                         value, "0#1.5#2#3#4#8#16#32");
5440
5441 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5442         .f = cmd_set_bypass_timeout_parsed,
5443         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5444                 "Set the NIC bypass watchdog timeout in seconds",
5445         .data = NULL,
5446         .tokens = {
5447                 (void *)&cmd_setbypass_timeout_set,
5448                 (void *)&cmd_setbypass_timeout_bypass,
5449                 (void *)&cmd_setbypass_timeout_timeout,
5450                 (void *)&cmd_setbypass_timeout_value,
5451                 NULL,
5452         },
5453 };
5454
5455 /* *** SHOW NIC BYPASS MODE *** */
5456 struct cmd_show_bypass_config_result {
5457         cmdline_fixed_string_t show;
5458         cmdline_fixed_string_t bypass;
5459         cmdline_fixed_string_t config;
5460         portid_t port_id;
5461 };
5462
5463 static void
5464 cmd_show_bypass_config_parsed(void *parsed_result,
5465                 __attribute__((unused)) struct cmdline *cl,
5466                 __attribute__((unused)) void *data)
5467 {
5468         struct cmd_show_bypass_config_result *res = parsed_result;
5469         portid_t port_id = res->port_id;
5470         int rc = -EINVAL;
5471 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5472         uint32_t event_mode;
5473         uint32_t bypass_mode;
5474         uint32_t timeout = bypass_timeout;
5475         int i;
5476
5477         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5478                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5479         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5480                 {"UNKNOWN", "normal", "bypass", "isolate"};
5481         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5482                 "NONE",
5483                 "OS/board on",
5484                 "power supply on",
5485                 "OS/board off",
5486                 "power supply off",
5487                 "timeout"};
5488         int num_events = (sizeof events) / (sizeof events[0]);
5489
5490         /* Display the bypass mode.*/
5491         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5492                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5493                 return;
5494         }
5495         else {
5496                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5497                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5498
5499                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5500         }
5501
5502         /* Display the bypass timeout.*/
5503         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5504                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5505
5506         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5507
5508         /* Display the bypass events and associated modes. */
5509         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5510
5511                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5512                         printf("\tFailed to get bypass mode for event = %s\n",
5513                                 events[i]);
5514                 } else {
5515                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5516                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5517
5518                         printf("\tbypass event: %-16s = %s\n", events[i],
5519                                 modes[event_mode]);
5520                 }
5521         }
5522 #endif
5523         if (rc != 0)
5524                 printf("\tFailed to get bypass configuration for port = %d\n",
5525                        port_id);
5526 }
5527
5528 cmdline_parse_token_string_t cmd_showbypass_config_show =
5529         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5530                         show, "show");
5531 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5532         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5533                         bypass, "bypass");
5534 cmdline_parse_token_string_t cmd_showbypass_config_config =
5535         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5536                         config, "config");
5537 cmdline_parse_token_num_t cmd_showbypass_config_port =
5538         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5539                                 port_id, UINT16);
5540
5541 cmdline_parse_inst_t cmd_show_bypass_config = {
5542         .f = cmd_show_bypass_config_parsed,
5543         .help_str = "show bypass config <port_id>: "
5544                     "Show the NIC bypass config for port_id",
5545         .data = NULL,
5546         .tokens = {
5547                 (void *)&cmd_showbypass_config_show,
5548                 (void *)&cmd_showbypass_config_bypass,
5549                 (void *)&cmd_showbypass_config_config,
5550                 (void *)&cmd_showbypass_config_port,
5551                 NULL,
5552         },
5553 };
5554
5555 #ifdef RTE_LIBRTE_PMD_BOND
5556 /* *** SET BONDING MODE *** */
5557 struct cmd_set_bonding_mode_result {
5558         cmdline_fixed_string_t set;
5559         cmdline_fixed_string_t bonding;
5560         cmdline_fixed_string_t mode;
5561         uint8_t value;
5562         portid_t port_id;
5563 };
5564
5565 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5566                 __attribute__((unused))  struct cmdline *cl,
5567                 __attribute__((unused)) void *data)
5568 {
5569         struct cmd_set_bonding_mode_result *res = parsed_result;
5570         portid_t port_id = res->port_id;
5571
5572         /* Set the bonding mode for the relevant port. */
5573         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5574                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5575 }
5576
5577 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5578 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5579                 set, "set");
5580 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5581 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5582                 bonding, "bonding");
5583 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5584 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5585                 mode, "mode");
5586 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5587 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5588                 value, UINT8);
5589 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5590 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5591                 port_id, UINT16);
5592
5593 cmdline_parse_inst_t cmd_set_bonding_mode = {
5594                 .f = cmd_set_bonding_mode_parsed,
5595                 .help_str = "set bonding mode <mode_value> <port_id>: "
5596                         "Set the bonding mode for port_id",
5597                 .data = NULL,
5598                 .tokens = {
5599                                 (void *) &cmd_setbonding_mode_set,
5600                                 (void *) &cmd_setbonding_mode_bonding,
5601                                 (void *) &cmd_setbonding_mode_mode,
5602                                 (void *) &cmd_setbonding_mode_value,
5603                                 (void *) &cmd_setbonding_mode_port,
5604                                 NULL
5605                 }
5606 };
5607
5608 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5609 struct cmd_set_bonding_lacp_dedicated_queues_result {
5610         cmdline_fixed_string_t set;
5611         cmdline_fixed_string_t bonding;
5612         cmdline_fixed_string_t lacp;
5613         cmdline_fixed_string_t dedicated_queues;
5614         portid_t port_id;
5615         cmdline_fixed_string_t mode;
5616 };
5617
5618 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5619                 __attribute__((unused))  struct cmdline *cl,
5620                 __attribute__((unused)) void *data)
5621 {
5622         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5623         portid_t port_id = res->port_id;
5624         struct rte_port *port;
5625
5626         port = &ports[port_id];
5627
5628         /** Check if the port is not started **/
5629         if (port->port_status != RTE_PORT_STOPPED) {
5630                 printf("Please stop port %d first\n", port_id);
5631                 return;
5632         }
5633
5634         if (!strcmp(res->mode, "enable")) {
5635                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5636                         printf("Dedicate queues for LACP control packets"
5637                                         " enabled\n");
5638                 else
5639                         printf("Enabling dedicate queues for LACP control "
5640                                         "packets on port %d failed\n", port_id);
5641         } else if (!strcmp(res->mode, "disable")) {
5642                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5643                         printf("Dedicated queues for LACP control packets "
5644                                         "disabled\n");
5645                 else
5646                         printf("Disabling dedicated queues for LACP control "
5647                                         "traffic on port %d failed\n", port_id);
5648         }
5649 }
5650
5651 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5652 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5653                 set, "set");
5654 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5655 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5656                 bonding, "bonding");
5657 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5658 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5659                 lacp, "lacp");
5660 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5661 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5662                 dedicated_queues, "dedicated_queues");
5663 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5664 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5665                 port_id, UINT16);
5666 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5667 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5668                 mode, "enable#disable");
5669
5670 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5671                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5672                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5673                         "enable|disable: "
5674                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5675                 .data = NULL,
5676                 .tokens = {
5677                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5678                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5679                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5680                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5681                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5682                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5683                         NULL
5684                 }
5685 };
5686
5687 /* *** SET BALANCE XMIT POLICY *** */
5688 struct cmd_set_bonding_balance_xmit_policy_result {
5689         cmdline_fixed_string_t set;
5690         cmdline_fixed_string_t bonding;
5691         cmdline_fixed_string_t balance_xmit_policy;
5692         portid_t port_id;
5693         cmdline_fixed_string_t policy;
5694 };
5695
5696 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5697                 __attribute__((unused))  struct cmdline *cl,
5698                 __attribute__((unused)) void *data)
5699 {
5700         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5701         portid_t port_id = res->port_id;
5702         uint8_t policy;
5703
5704         if (!strcmp(res->policy, "l2")) {
5705                 policy = BALANCE_XMIT_POLICY_LAYER2;
5706         } else if (!strcmp(res->policy, "l23")) {
5707                 policy = BALANCE_XMIT_POLICY_LAYER23;
5708         } else if (!strcmp(res->policy, "l34")) {
5709                 policy = BALANCE_XMIT_POLICY_LAYER34;
5710         } else {
5711                 printf("\t Invalid xmit policy selection");
5712                 return;
5713         }
5714
5715         /* Set the bonding mode for the relevant port. */
5716         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5717                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5718                                 port_id);
5719         }
5720 }
5721
5722 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5723 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5724                 set, "set");
5725 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5726 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5727                 bonding, "bonding");
5728 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5729 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5730                 balance_xmit_policy, "balance_xmit_policy");
5731 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5732 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5733                 port_id, UINT16);
5734 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5735 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5736                 policy, "l2#l23#l34");
5737
5738 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5739                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5740                 .help_str = "set bonding balance_xmit_policy <port_id> "
5741                         "l2|l23|l34: "
5742                         "Set the bonding balance_xmit_policy for port_id",
5743                 .data = NULL,
5744                 .tokens = {
5745                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5746                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5747                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5748                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5749                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5750                                 NULL
5751                 }
5752 };
5753
5754 /* *** SHOW NIC BONDING CONFIGURATION *** */
5755 struct cmd_show_bonding_config_result {
5756         cmdline_fixed_string_t show;
5757         cmdline_fixed_string_t bonding;
5758         cmdline_fixed_string_t config;
5759         portid_t port_id;
5760 };
5761
5762 static void cmd_show_bonding_config_parsed(void *parsed_result,
5763                 __attribute__((unused))  struct cmdline *cl,
5764                 __attribute__((unused)) void *data)
5765 {
5766         struct cmd_show_bonding_config_result *res = parsed_result;
5767         int bonding_mode, agg_mode;
5768         portid_t slaves[RTE_MAX_ETHPORTS];
5769         int num_slaves, num_active_slaves;
5770         int primary_id;
5771         int i;
5772         portid_t port_id = res->port_id;
5773
5774         /* Display the bonding mode.*/
5775         bonding_mode = rte_eth_bond_mode_get(port_id);
5776         if (bonding_mode < 0) {
5777                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5778                 return;
5779         } else
5780                 printf("\tBonding mode: %d\n", bonding_mode);
5781
5782         if (bonding_mode == BONDING_MODE_BALANCE) {
5783                 int balance_xmit_policy;
5784
5785                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5786                 if (balance_xmit_policy < 0) {
5787                         printf("\tFailed to get balance xmit policy for port = %d\n",
5788                                         port_id);
5789                         return;
5790                 } else {
5791                         printf("\tBalance Xmit Policy: ");
5792
5793                         switch (balance_xmit_policy) {
5794                         case BALANCE_XMIT_POLICY_LAYER2:
5795                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5796                                 break;
5797                         case BALANCE_XMIT_POLICY_LAYER23:
5798                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5799                                 break;
5800                         case BALANCE_XMIT_POLICY_LAYER34:
5801                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5802                                 break;
5803                         }
5804                         printf("\n");
5805                 }
5806         }
5807
5808         if (bonding_mode == BONDING_MODE_8023AD) {
5809                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5810                 printf("\tIEEE802.3AD Aggregator Mode: ");
5811                 switch (agg_mode) {
5812                 case AGG_BANDWIDTH:
5813                         printf("bandwidth");
5814                         break;
5815                 case AGG_STABLE:
5816                         printf("stable");
5817                         break;
5818                 case AGG_COUNT:
5819                         printf("count");
5820                         break;
5821                 }
5822                 printf("\n");
5823         }
5824
5825         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5826
5827         if (num_slaves < 0) {
5828                 printf("\tFailed to get slave list for port = %d\n", port_id);
5829                 return;
5830         }
5831         if (num_slaves > 0) {
5832                 printf("\tSlaves (%d): [", num_slaves);
5833                 for (i = 0; i < num_slaves - 1; i++)
5834                         printf("%d ", slaves[i]);
5835
5836                 printf("%d]\n", slaves[num_slaves - 1]);
5837         } else {
5838                 printf("\tSlaves: []\n");
5839
5840         }
5841
5842         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5843                         RTE_MAX_ETHPORTS);
5844
5845         if (num_active_slaves < 0) {
5846                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5847                 return;
5848         }
5849         if (num_active_slaves > 0) {
5850                 printf("\tActive Slaves (%d): [", num_active_slaves);
5851                 for (i = 0; i < num_active_slaves - 1; i++)
5852                         printf("%d ", slaves[i]);
5853
5854                 printf("%d]\n", slaves[num_active_slaves - 1]);
5855
5856         } else {
5857                 printf("\tActive Slaves: []\n");
5858
5859         }
5860
5861         primary_id = rte_eth_bond_primary_get(port_id);
5862         if (primary_id < 0) {
5863                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5864                 return;
5865         } else
5866                 printf("\tPrimary: [%d]\n", primary_id);
5867
5868 }
5869
5870 cmdline_parse_token_string_t cmd_showbonding_config_show =
5871 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5872                 show, "show");
5873 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5874 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5875                 bonding, "bonding");
5876 cmdline_parse_token_string_t cmd_showbonding_config_config =
5877 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5878                 config, "config");
5879 cmdline_parse_token_num_t cmd_showbonding_config_port =
5880 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5881                 port_id, UINT16);
5882
5883 cmdline_parse_inst_t cmd_show_bonding_config = {
5884                 .f = cmd_show_bonding_config_parsed,
5885                 .help_str = "show bonding config <port_id>: "
5886                         "Show the bonding config for port_id",
5887                 .data = NULL,
5888                 .tokens = {
5889                                 (void *)&cmd_showbonding_config_show,
5890                                 (void *)&cmd_showbonding_config_bonding,
5891                                 (void *)&cmd_showbonding_config_config,
5892                                 (void *)&cmd_showbonding_config_port,
5893                                 NULL
5894                 }
5895 };
5896
5897 /* *** SET BONDING PRIMARY *** */
5898 struct cmd_set_bonding_primary_result {
5899         cmdline_fixed_string_t set;
5900         cmdline_fixed_string_t bonding;
5901         cmdline_fixed_string_t primary;
5902         portid_t slave_id;
5903         portid_t port_id;
5904 };
5905
5906 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5907                 __attribute__((unused))  struct cmdline *cl,
5908                 __attribute__((unused)) void *data)
5909 {
5910         struct cmd_set_bonding_primary_result *res = parsed_result;
5911         portid_t master_port_id = res->port_id;
5912         portid_t slave_port_id = res->slave_id;
5913
5914         /* Set the primary slave for a bonded device. */
5915         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5916                 printf("\t Failed to set primary slave for port = %d.\n",
5917                                 master_port_id);
5918                 return;
5919         }
5920         init_port_config();
5921 }
5922
5923 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5924 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5925                 set, "set");
5926 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5928                 bonding, "bonding");
5929 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5930 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5931                 primary, "primary");
5932 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5933 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5934                 slave_id, UINT16);
5935 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5936 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5937                 port_id, UINT16);
5938
5939 cmdline_parse_inst_t cmd_set_bonding_primary = {
5940                 .f = cmd_set_bonding_primary_parsed,
5941                 .help_str = "set bonding primary <slave_id> <port_id>: "
5942                         "Set the primary slave for port_id",
5943                 .data = NULL,
5944                 .tokens = {
5945                                 (void *)&cmd_setbonding_primary_set,
5946                                 (void *)&cmd_setbonding_primary_bonding,
5947                                 (void *)&cmd_setbonding_primary_primary,
5948                                 (void *)&cmd_setbonding_primary_slave,
5949                                 (void *)&cmd_setbonding_primary_port,
5950                                 NULL
5951                 }
5952 };
5953
5954 /* *** ADD SLAVE *** */
5955 struct cmd_add_bonding_slave_result {
5956         cmdline_fixed_string_t add;
5957         cmdline_fixed_string_t bonding;
5958         cmdline_fixed_string_t slave;
5959         portid_t slave_id;
5960         portid_t port_id;
5961 };
5962
5963 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5964                 __attribute__((unused))  struct cmdline *cl,
5965                 __attribute__((unused)) void *data)
5966 {
5967         struct cmd_add_bonding_slave_result *res = parsed_result;
5968         portid_t master_port_id = res->port_id;
5969         portid_t slave_port_id = res->slave_id;
5970
5971         /* add the slave for a bonded device. */
5972         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5973                 printf("\t Failed to add slave %d to master port = %d.\n",
5974                                 slave_port_id, master_port_id);
5975                 return;
5976         }
5977         init_port_config();
5978         set_port_slave_flag(slave_port_id);
5979 }
5980
5981 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5982 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5983                 add, "add");
5984 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5985 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5986                 bonding, "bonding");
5987 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5988 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5989                 slave, "slave");
5990 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5991 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5992                 slave_id, UINT16);
5993 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5994 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5995                 port_id, UINT16);
5996
5997 cmdline_parse_inst_t cmd_add_bonding_slave = {
5998                 .f = cmd_add_bonding_slave_parsed,
5999                 .help_str = "add bonding slave <slave_id> <port_id>: "
6000                         "Add a slave device to a bonded device",
6001                 .data = NULL,
6002                 .tokens = {
6003                                 (void *)&cmd_addbonding_slave_add,
6004                                 (void *)&cmd_addbonding_slave_bonding,
6005                                 (void *)&cmd_addbonding_slave_slave,
6006                                 (void *)&cmd_addbonding_slave_slaveid,
6007                                 (void *)&cmd_addbonding_slave_port,
6008                                 NULL
6009                 }
6010 };
6011
6012 /* *** REMOVE SLAVE *** */
6013 struct cmd_remove_bonding_slave_result {
6014         cmdline_fixed_string_t remove;
6015         cmdline_fixed_string_t bonding;
6016         cmdline_fixed_string_t slave;
6017         portid_t slave_id;
6018         portid_t port_id;
6019 };
6020
6021 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6022                 __attribute__((unused))  struct cmdline *cl,
6023                 __attribute__((unused)) void *data)
6024 {
6025         struct cmd_remove_bonding_slave_result *res = parsed_result;
6026         portid_t master_port_id = res->port_id;
6027         portid_t slave_port_id = res->slave_id;
6028
6029         /* remove the slave from a bonded device. */
6030         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6031                 printf("\t Failed to remove slave %d from master port = %d.\n",
6032                                 slave_port_id, master_port_id);
6033                 return;
6034         }
6035         init_port_config();
6036         clear_port_slave_flag(slave_port_id);
6037 }
6038
6039 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6040                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6041                                 remove, "remove");
6042 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6043                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6044                                 bonding, "bonding");
6045 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6046                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6047                                 slave, "slave");
6048 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6049                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6050                                 slave_id, UINT16);
6051 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6052                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6053                                 port_id, UINT16);
6054
6055 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6056                 .f = cmd_remove_bonding_slave_parsed,
6057                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6058                         "Remove a slave device from a bonded device",
6059                 .data = NULL,
6060                 .tokens = {
6061                                 (void *)&cmd_removebonding_slave_remove,
6062                                 (void *)&cmd_removebonding_slave_bonding,
6063                                 (void *)&cmd_removebonding_slave_slave,
6064                                 (void *)&cmd_removebonding_slave_slaveid,
6065                                 (void *)&cmd_removebonding_slave_port,
6066                                 NULL
6067                 }
6068 };
6069
6070 /* *** CREATE BONDED DEVICE *** */
6071 struct cmd_create_bonded_device_result {
6072         cmdline_fixed_string_t create;
6073         cmdline_fixed_string_t bonded;
6074         cmdline_fixed_string_t device;
6075         uint8_t mode;
6076         uint8_t socket;
6077 };
6078
6079 static int bond_dev_num = 0;
6080
6081 static void cmd_create_bonded_device_parsed(void *parsed_result,
6082                 __attribute__((unused))  struct cmdline *cl,
6083                 __attribute__((unused)) void *data)
6084 {
6085         struct cmd_create_bonded_device_result *res = parsed_result;
6086         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6087         int port_id;
6088         int ret;
6089
6090         if (test_done == 0) {
6091                 printf("Please stop forwarding first\n");
6092                 return;
6093         }
6094
6095         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6096                         bond_dev_num++);
6097
6098         /* Create a new bonded device. */
6099         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6100         if (port_id < 0) {
6101                 printf("\t Failed to create bonded device.\n");
6102                 return;
6103         } else {
6104                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6105                                 port_id);
6106
6107                 /* Update number of ports */
6108                 nb_ports = rte_eth_dev_count_avail();
6109                 reconfig(port_id, res->socket);
6110                 ret = rte_eth_promiscuous_enable(port_id);
6111                 if (ret != 0)
6112                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6113                                 port_id, rte_strerror(-ret));
6114
6115                 ports[port_id].need_setup = 0;
6116                 ports[port_id].port_status = RTE_PORT_STOPPED;
6117         }
6118
6119 }
6120
6121 cmdline_parse_token_string_t cmd_createbonded_device_create =
6122                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6123                                 create, "create");
6124 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6125                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6126                                 bonded, "bonded");
6127 cmdline_parse_token_string_t cmd_createbonded_device_device =
6128                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6129                                 device, "device");
6130 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6131                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6132                                 mode, UINT8);
6133 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6134                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6135                                 socket, UINT8);
6136
6137 cmdline_parse_inst_t cmd_create_bonded_device = {
6138                 .f = cmd_create_bonded_device_parsed,
6139                 .help_str = "create bonded device <mode> <socket>: "
6140                         "Create a new bonded device with specific bonding mode and socket",
6141                 .data = NULL,
6142                 .tokens = {
6143                                 (void *)&cmd_createbonded_device_create,
6144                                 (void *)&cmd_createbonded_device_bonded,
6145                                 (void *)&cmd_createbonded_device_device,
6146                                 (void *)&cmd_createbonded_device_mode,
6147                                 (void *)&cmd_createbonded_device_socket,
6148                                 NULL
6149                 }
6150 };
6151
6152 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6153 struct cmd_set_bond_mac_addr_result {
6154         cmdline_fixed_string_t set;
6155         cmdline_fixed_string_t bonding;
6156         cmdline_fixed_string_t mac_addr;
6157         uint16_t port_num;
6158         struct rte_ether_addr address;
6159 };
6160
6161 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6162                 __attribute__((unused))  struct cmdline *cl,
6163                 __attribute__((unused)) void *data)
6164 {
6165         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6166         int ret;
6167
6168         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6169                 return;
6170
6171         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6172
6173         /* check the return value and print it if is < 0 */
6174         if (ret < 0)
6175                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6176 }
6177
6178 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6179                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6180 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6181                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6182                                 "bonding");
6183 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6184                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6185                                 "mac_addr");
6186 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6187                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6188                                 port_num, UINT16);
6189 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6190                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6191
6192 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6193                 .f = cmd_set_bond_mac_addr_parsed,
6194                 .data = (void *) 0,
6195                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6196                 .tokens = {
6197                                 (void *)&cmd_set_bond_mac_addr_set,
6198                                 (void *)&cmd_set_bond_mac_addr_bonding,
6199                                 (void *)&cmd_set_bond_mac_addr_mac,
6200                                 (void *)&cmd_set_bond_mac_addr_portnum,
6201                                 (void *)&cmd_set_bond_mac_addr_addr,
6202                                 NULL
6203                 }
6204 };
6205
6206
6207 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6208 struct cmd_set_bond_mon_period_result {
6209         cmdline_fixed_string_t set;
6210         cmdline_fixed_string_t bonding;
6211         cmdline_fixed_string_t mon_period;
6212         uint16_t port_num;
6213         uint32_t period_ms;
6214 };
6215
6216 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6217                 __attribute__((unused))  struct cmdline *cl,
6218                 __attribute__((unused)) void *data)
6219 {
6220         struct cmd_set_bond_mon_period_result *res = parsed_result;
6221         int ret;
6222
6223         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6224
6225         /* check the return value and print it if is < 0 */
6226         if (ret < 0)
6227                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6228 }
6229
6230 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6231                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6232                                 set, "set");
6233 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6234                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6235                                 bonding, "bonding");
6236 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6237                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6238                                 mon_period,     "mon_period");
6239 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6240                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6241                                 port_num, UINT16);
6242 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6243                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6244                                 period_ms, UINT32);
6245
6246 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6247                 .f = cmd_set_bond_mon_period_parsed,
6248                 .data = (void *) 0,
6249                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6250                 .tokens = {
6251                                 (void *)&cmd_set_bond_mon_period_set,
6252                                 (void *)&cmd_set_bond_mon_period_bonding,
6253                                 (void *)&cmd_set_bond_mon_period_mon_period,
6254                                 (void *)&cmd_set_bond_mon_period_portnum,
6255                                 (void *)&cmd_set_bond_mon_period_period_ms,
6256                                 NULL
6257                 }
6258 };
6259
6260
6261
6262 struct cmd_set_bonding_agg_mode_policy_result {
6263         cmdline_fixed_string_t set;
6264         cmdline_fixed_string_t bonding;
6265         cmdline_fixed_string_t agg_mode;
6266         uint16_t port_num;
6267         cmdline_fixed_string_t policy;
6268 };
6269
6270
6271 static void
6272 cmd_set_bonding_agg_mode(void *parsed_result,
6273                 __attribute__((unused)) struct cmdline *cl,
6274                 __attribute__((unused)) void *data)
6275 {
6276         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6277         uint8_t policy = AGG_BANDWIDTH;
6278
6279         if (!strcmp(res->policy, "bandwidth"))
6280                 policy = AGG_BANDWIDTH;
6281         else if (!strcmp(res->policy, "stable"))
6282                 policy = AGG_STABLE;
6283         else if (!strcmp(res->policy, "count"))
6284                 policy = AGG_COUNT;
6285
6286         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6287 }
6288
6289
6290 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6291         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6292                                 set, "set");
6293 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6294         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6295                                 bonding, "bonding");
6296
6297 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6298         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6299                                 agg_mode, "agg_mode");
6300
6301 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6302         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6303                                 port_num, UINT16);
6304
6305 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6306         TOKEN_STRING_INITIALIZER(
6307                         struct cmd_set_bonding_balance_xmit_policy_result,
6308                 policy, "stable#bandwidth#count");
6309
6310 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6311         .f = cmd_set_bonding_agg_mode,
6312         .data = (void *) 0,
6313         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6314         .tokens = {
6315                         (void *)&cmd_set_bonding_agg_mode_set,
6316                         (void *)&cmd_set_bonding_agg_mode_bonding,
6317                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6318                         (void *)&cmd_set_bonding_agg_mode_portnum,
6319                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6320                         NULL
6321                 }
6322 };
6323
6324
6325 #endif /* RTE_LIBRTE_PMD_BOND */
6326
6327 /* *** SET FORWARDING MODE *** */
6328 struct cmd_set_fwd_mode_result {
6329         cmdline_fixed_string_t set;
6330         cmdline_fixed_string_t fwd;
6331         cmdline_fixed_string_t mode;
6332 };
6333
6334 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6335                                     __attribute__((unused)) struct cmdline *cl,
6336                                     __attribute__((unused)) void *data)
6337 {
6338         struct cmd_set_fwd_mode_result *res = parsed_result;
6339
6340         retry_enabled = 0;
6341         set_pkt_forwarding_mode(res->mode);
6342 }
6343
6344 cmdline_parse_token_string_t cmd_setfwd_set =
6345         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6346 cmdline_parse_token_string_t cmd_setfwd_fwd =
6347         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6348 cmdline_parse_token_string_t cmd_setfwd_mode =
6349         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6350                 "" /* defined at init */);
6351
6352 cmdline_parse_inst_t cmd_set_fwd_mode = {
6353         .f = cmd_set_fwd_mode_parsed,
6354         .data = NULL,
6355         .help_str = NULL, /* defined at init */
6356         .tokens = {
6357                 (void *)&cmd_setfwd_set,
6358                 (void *)&cmd_setfwd_fwd,
6359                 (void *)&cmd_setfwd_mode,
6360                 NULL,
6361         },
6362 };
6363
6364 static void cmd_set_fwd_mode_init(void)
6365 {
6366         char *modes, *c;
6367         static char token[128];
6368         static char help[256];
6369         cmdline_parse_token_string_t *token_struct;
6370
6371         modes = list_pkt_forwarding_modes();
6372         snprintf(help, sizeof(help), "set fwd %s: "
6373                 "Set packet forwarding mode", modes);
6374         cmd_set_fwd_mode.help_str = help;
6375
6376         /* string token separator is # */
6377         for (c = token; *modes != '\0'; modes++)
6378                 if (*modes == '|')
6379                         *c++ = '#';
6380                 else
6381                         *c++ = *modes;
6382         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6383         token_struct->string_data.str = token;
6384 }
6385
6386 /* *** SET RETRY FORWARDING MODE *** */
6387 struct cmd_set_fwd_retry_mode_result {
6388         cmdline_fixed_string_t set;
6389         cmdline_fixed_string_t fwd;
6390         cmdline_fixed_string_t mode;
6391         cmdline_fixed_string_t retry;
6392 };
6393
6394 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6395                             __attribute__((unused)) struct cmdline *cl,
6396                             __attribute__((unused)) void *data)
6397 {
6398         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6399
6400         retry_enabled = 1;
6401         set_pkt_forwarding_mode(res->mode);
6402 }
6403
6404 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6405         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6406                         set, "set");
6407 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6408         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6409                         fwd, "fwd");
6410 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6411         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6412                         mode,
6413                 "" /* defined at init */);
6414 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6415         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6416                         retry, "retry");
6417
6418 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6419         .f = cmd_set_fwd_retry_mode_parsed,
6420         .data = NULL,
6421         .help_str = NULL, /* defined at init */
6422         .tokens = {
6423                 (void *)&cmd_setfwd_retry_set,
6424                 (void *)&cmd_setfwd_retry_fwd,
6425                 (void *)&cmd_setfwd_retry_mode,
6426                 (void *)&cmd_setfwd_retry_retry,
6427                 NULL,
6428         },
6429 };
6430
6431 static void cmd_set_fwd_retry_mode_init(void)
6432 {
6433         char *modes, *c;
6434         static char token[128];
6435         static char help[256];
6436         cmdline_parse_token_string_t *token_struct;
6437
6438         modes = list_pkt_forwarding_retry_modes();
6439         snprintf(help, sizeof(help), "set fwd %s retry: "
6440                 "Set packet forwarding mode with retry", modes);
6441         cmd_set_fwd_retry_mode.help_str = help;
6442
6443         /* string token separator is # */
6444         for (c = token; *modes != '\0'; modes++)
6445                 if (*modes == '|')
6446                         *c++ = '#';
6447                 else
6448                         *c++ = *modes;
6449         token_struct = (cmdline_parse_token_string_t *)
6450                 cmd_set_fwd_retry_mode.tokens[2];
6451         token_struct->string_data.str = token;
6452 }
6453
6454 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6455 struct cmd_set_burst_tx_retry_result {
6456         cmdline_fixed_string_t set;
6457         cmdline_fixed_string_t burst;
6458         cmdline_fixed_string_t tx;
6459         cmdline_fixed_string_t delay;
6460         uint32_t time;
6461         cmdline_fixed_string_t retry;
6462         uint32_t retry_num;
6463 };
6464
6465 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6466                                         __attribute__((unused)) struct cmdline *cl,
6467                                         __attribute__((unused)) void *data)
6468 {
6469         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6470
6471         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6472                 && !strcmp(res->tx, "tx")) {
6473                 if (!strcmp(res->delay, "delay"))
6474                         burst_tx_delay_time = res->time;
6475                 if (!strcmp(res->retry, "retry"))
6476                         burst_tx_retry_num = res->retry_num;
6477         }
6478
6479 }
6480
6481 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6482         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6483 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6484         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6485                                  "burst");
6486 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6487         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6488 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6489         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6490 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6491         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6492 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6493         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6494 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6495         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6496
6497 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6498         .f = cmd_set_burst_tx_retry_parsed,
6499         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6500         .tokens = {
6501                 (void *)&cmd_set_burst_tx_retry_set,
6502                 (void *)&cmd_set_burst_tx_retry_burst,
6503                 (void *)&cmd_set_burst_tx_retry_tx,
6504                 (void *)&cmd_set_burst_tx_retry_delay,
6505                 (void *)&cmd_set_burst_tx_retry_time,
6506                 (void *)&cmd_set_burst_tx_retry_retry,
6507                 (void *)&cmd_set_burst_tx_retry_retry_num,
6508                 NULL,
6509         },
6510 };
6511
6512 /* *** SET PROMISC MODE *** */
6513 struct cmd_set_promisc_mode_result {
6514         cmdline_fixed_string_t set;
6515         cmdline_fixed_string_t promisc;
6516         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6517         uint16_t port_num;               /* valid if "allports" argument == 0 */
6518         cmdline_fixed_string_t mode;
6519 };
6520
6521 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6522                                         __attribute__((unused)) struct cmdline *cl,
6523                                         void *allports)
6524 {
6525         struct cmd_set_promisc_mode_result *res = parsed_result;
6526         int enable;
6527         portid_t i;
6528
6529         if (!strcmp(res->mode, "on"))
6530                 enable = 1;
6531         else
6532                 enable = 0;
6533
6534         /* all ports */
6535         if (allports) {
6536                 RTE_ETH_FOREACH_DEV(i)
6537                         eth_set_promisc_mode(i, enable);
6538         } else {
6539                 eth_set_promisc_mode(res->port_num, enable);
6540         }
6541 }
6542
6543 cmdline_parse_token_string_t cmd_setpromisc_set =
6544         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6545 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6546         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6547                                  "promisc");
6548 cmdline_parse_token_string_t cmd_setpromisc_portall =
6549         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6550                                  "all");
6551 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6552         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6553                               UINT16);
6554 cmdline_parse_token_string_t cmd_setpromisc_mode =
6555         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6556                                  "on#off");
6557
6558 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6559         .f = cmd_set_promisc_mode_parsed,
6560         .data = (void *)1,
6561         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6562         .tokens = {
6563                 (void *)&cmd_setpromisc_set,
6564                 (void *)&cmd_setpromisc_promisc,
6565                 (void *)&cmd_setpromisc_portall,
6566                 (void *)&cmd_setpromisc_mode,
6567                 NULL,
6568         },
6569 };
6570
6571 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6572         .f = cmd_set_promisc_mode_parsed,
6573         .data = (void *)0,
6574         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6575         .tokens = {
6576                 (void *)&cmd_setpromisc_set,
6577                 (void *)&cmd_setpromisc_promisc,
6578                 (void *)&cmd_setpromisc_portnum,
6579                 (void *)&cmd_setpromisc_mode,
6580                 NULL,
6581         },
6582 };
6583
6584 /* *** SET ALLMULTI MODE *** */
6585 struct cmd_set_allmulti_mode_result {
6586         cmdline_fixed_string_t set;
6587         cmdline_fixed_string_t allmulti;
6588         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6589         uint16_t port_num;               /* valid if "allports" argument == 0 */
6590         cmdline_fixed_string_t mode;
6591 };
6592
6593 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6594                                         __attribute__((unused)) struct cmdline *cl,
6595                                         void *allports)
6596 {
6597         struct cmd_set_allmulti_mode_result *res = parsed_result;
6598         int enable;
6599         portid_t i;
6600
6601         if (!strcmp(res->mode, "on"))
6602                 enable = 1;
6603         else
6604                 enable = 0;
6605
6606         /* all ports */
6607         if (allports) {
6608                 RTE_ETH_FOREACH_DEV(i) {
6609                         eth_set_allmulticast_mode(i, enable);
6610                 }
6611         }
6612         else {
6613                 eth_set_allmulticast_mode(res->port_num, enable);
6614         }
6615 }
6616
6617 cmdline_parse_token_string_t cmd_setallmulti_set =
6618         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6619 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6620         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6621                                  "allmulti");
6622 cmdline_parse_token_string_t cmd_setallmulti_portall =
6623         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6624                                  "all");
6625 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6626         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6627                               UINT16);
6628 cmdline_parse_token_string_t cmd_setallmulti_mode =
6629         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6630                                  "on#off");
6631
6632 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6633         .f = cmd_set_allmulti_mode_parsed,
6634         .data = (void *)1,
6635         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6636         .tokens = {
6637                 (void *)&cmd_setallmulti_set,
6638                 (void *)&cmd_setallmulti_allmulti,
6639                 (void *)&cmd_setallmulti_portall,
6640                 (void *)&cmd_setallmulti_mode,
6641                 NULL,
6642         },
6643 };
6644
6645 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6646         .f = cmd_set_allmulti_mode_parsed,
6647         .data = (void *)0,
6648         .help_str = "set allmulti <port_id> on|off: "
6649                 "Set allmulti mode on port_id",
6650         .tokens = {
6651                 (void *)&cmd_setallmulti_set,
6652                 (void *)&cmd_setallmulti_allmulti,
6653                 (void *)&cmd_setallmulti_portnum,
6654                 (void *)&cmd_setallmulti_mode,
6655                 NULL,
6656         },
6657 };
6658
6659 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6660 struct cmd_link_flow_ctrl_set_result {
6661         cmdline_fixed_string_t set;
6662         cmdline_fixed_string_t flow_ctrl;
6663         cmdline_fixed_string_t rx;
6664         cmdline_fixed_string_t rx_lfc_mode;
6665         cmdline_fixed_string_t tx;
6666         cmdline_fixed_string_t tx_lfc_mode;
6667         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6668         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6669         cmdline_fixed_string_t autoneg_str;
6670         cmdline_fixed_string_t autoneg;
6671         cmdline_fixed_string_t hw_str;
6672         uint32_t high_water;
6673         cmdline_fixed_string_t lw_str;
6674         uint32_t low_water;
6675         cmdline_fixed_string_t pt_str;
6676         uint16_t pause_time;
6677         cmdline_fixed_string_t xon_str;
6678         uint16_t send_xon;
6679         portid_t port_id;
6680 };
6681
6682 cmdline_parse_token_string_t cmd_lfc_set_set =
6683         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6684                                 set, "set");
6685 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6686         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6687                                 flow_ctrl, "flow_ctrl");
6688 cmdline_parse_token_string_t cmd_lfc_set_rx =
6689         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6690                                 rx, "rx");
6691 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6692         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6693                                 rx_lfc_mode, "on#off");
6694 cmdline_parse_token_string_t cmd_lfc_set_tx =
6695         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6696                                 tx, "tx");
6697 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6698         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6699                                 tx_lfc_mode, "on#off");
6700 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6701         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6702                                 hw_str, "high_water");
6703 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6704         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6705                                 high_water, UINT32);
6706 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6707         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6708                                 lw_str, "low_water");
6709 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6710         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6711                                 low_water, UINT32);
6712 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6713         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6714                                 pt_str, "pause_time");
6715 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6716         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6717                                 pause_time, UINT16);
6718 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6719         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6720                                 xon_str, "send_xon");
6721 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6722         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6723                                 send_xon, UINT16);
6724 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6725         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6726                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6727 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6728         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6729                                 mac_ctrl_frame_fwd_mode, "on#off");
6730 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6731         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6732                                 autoneg_str, "autoneg");
6733 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6734         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6735                                 autoneg, "on#off");
6736 cmdline_parse_token_num_t cmd_lfc_set_portid =
6737         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6738                                 port_id, UINT16);
6739
6740 /* forward declaration */
6741 static void
6742 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6743                               void *data);
6744
6745 cmdline_parse_inst_t cmd_link_flow_control_set = {
6746         .f = cmd_link_flow_ctrl_set_parsed,
6747         .data = NULL,
6748         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6749                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6750                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6751         .tokens = {
6752                 (void *)&cmd_lfc_set_set,
6753                 (void *)&cmd_lfc_set_flow_ctrl,
6754                 (void *)&cmd_lfc_set_rx,
6755                 (void *)&cmd_lfc_set_rx_mode,
6756                 (void *)&cmd_lfc_set_tx,
6757                 (void *)&cmd_lfc_set_tx_mode,
6758                 (void *)&cmd_lfc_set_high_water,
6759                 (void *)&cmd_lfc_set_low_water,
6760                 (void *)&cmd_lfc_set_pause_time,
6761                 (void *)&cmd_lfc_set_send_xon,
6762                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6763                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6764                 (void *)&cmd_lfc_set_autoneg_str,
6765                 (void *)&cmd_lfc_set_autoneg,
6766                 (void *)&cmd_lfc_set_portid,
6767                 NULL,
6768         },
6769 };
6770
6771 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6772         .f = cmd_link_flow_ctrl_set_parsed,
6773         .data = (void *)&cmd_link_flow_control_set_rx,
6774         .help_str = "set flow_ctrl rx on|off <port_id>: "
6775                 "Change rx flow control parameter",
6776         .tokens = {
6777                 (void *)&cmd_lfc_set_set,
6778                 (void *)&cmd_lfc_set_flow_ctrl,
6779                 (void *)&cmd_lfc_set_rx,
6780                 (void *)&cmd_lfc_set_rx_mode,
6781                 (void *)&cmd_lfc_set_portid,
6782                 NULL,
6783         },
6784 };
6785
6786 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6787         .f = cmd_link_flow_ctrl_set_parsed,
6788         .data = (void *)&cmd_link_flow_control_set_tx,
6789         .help_str = "set flow_ctrl tx on|off <port_id>: "
6790                 "Change tx flow control parameter",
6791         .tokens = {
6792                 (void *)&cmd_lfc_set_set,
6793                 (void *)&cmd_lfc_set_flow_ctrl,
6794                 (void *)&cmd_lfc_set_tx,
6795                 (void *)&cmd_lfc_set_tx_mode,
6796                 (void *)&cmd_lfc_set_portid,
6797                 NULL,
6798         },
6799 };
6800
6801 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6802         .f = cmd_link_flow_ctrl_set_parsed,
6803         .data = (void *)&cmd_link_flow_control_set_hw,
6804         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6805                 "Change high water flow control parameter",
6806         .tokens = {
6807                 (void *)&cmd_lfc_set_set,
6808                 (void *)&cmd_lfc_set_flow_ctrl,
6809                 (void *)&cmd_lfc_set_high_water_str,
6810                 (void *)&cmd_lfc_set_high_water,
6811                 (void *)&cmd_lfc_set_portid,
6812                 NULL,
6813         },
6814 };
6815
6816 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6817         .f = cmd_link_flow_ctrl_set_parsed,
6818         .data = (void *)&cmd_link_flow_control_set_lw,
6819         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6820                 "Change low water flow control parameter",
6821         .tokens = {
6822                 (void *)&cmd_lfc_set_set,
6823                 (void *)&cmd_lfc_set_flow_ctrl,
6824                 (void *)&cmd_lfc_set_low_water_str,
6825                 (void *)&cmd_lfc_set_low_water,
6826                 (void *)&cmd_lfc_set_portid,
6827                 NULL,
6828         },
6829 };
6830
6831 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6832         .f = cmd_link_flow_ctrl_set_parsed,
6833         .data = (void *)&cmd_link_flow_control_set_pt,
6834         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6835                 "Change pause time flow control parameter",
6836         .tokens = {
6837                 (void *)&cmd_lfc_set_set,
6838                 (void *)&cmd_lfc_set_flow_ctrl,
6839                 (void *)&cmd_lfc_set_pause_time_str,
6840                 (void *)&cmd_lfc_set_pause_time,
6841                 (void *)&cmd_lfc_set_portid,
6842                 NULL,
6843         },
6844 };
6845
6846 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6847         .f = cmd_link_flow_ctrl_set_parsed,
6848         .data = (void *)&cmd_link_flow_control_set_xon,
6849         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6850                 "Change send_xon flow control parameter",
6851         .tokens = {
6852                 (void *)&cmd_lfc_set_set,
6853                 (void *)&cmd_lfc_set_flow_ctrl,
6854                 (void *)&cmd_lfc_set_send_xon_str,
6855                 (void *)&cmd_lfc_set_send_xon,
6856                 (void *)&cmd_lfc_set_portid,
6857                 NULL,
6858         },
6859 };
6860
6861 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6862         .f = cmd_link_flow_ctrl_set_parsed,
6863         .data = (void *)&cmd_link_flow_control_set_macfwd,
6864         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6865                 "Change mac ctrl fwd flow control parameter",
6866         .tokens = {
6867                 (void *)&cmd_lfc_set_set,
6868                 (void *)&cmd_lfc_set_flow_ctrl,
6869                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6870                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6871                 (void *)&cmd_lfc_set_portid,
6872                 NULL,
6873         },
6874 };
6875
6876 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6877         .f = cmd_link_flow_ctrl_set_parsed,
6878         .data = (void *)&cmd_link_flow_control_set_autoneg,
6879         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6880                 "Change autoneg flow control parameter",
6881         .tokens = {
6882                 (void *)&cmd_lfc_set_set,
6883                 (void *)&cmd_lfc_set_flow_ctrl,
6884                 (void *)&cmd_lfc_set_autoneg_str,
6885                 (void *)&cmd_lfc_set_autoneg,
6886                 (void *)&cmd_lfc_set_portid,
6887                 NULL,
6888         },
6889 };
6890
6891 static void
6892 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6893                               __attribute__((unused)) struct cmdline *cl,
6894                               void *data)
6895 {
6896         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6897         cmdline_parse_inst_t *cmd = data;
6898         struct rte_eth_fc_conf fc_conf;
6899         int rx_fc_en = 0;
6900         int tx_fc_en = 0;
6901         int ret;
6902
6903         /*
6904          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6905          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6906          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6907          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6908          */
6909         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6910                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6911         };
6912
6913         /* Partial command line, retrieve current configuration */
6914         if (cmd) {
6915                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6916                 if (ret != 0) {
6917                         printf("cannot get current flow ctrl parameters, return"
6918                                "code = %d\n", ret);
6919                         return;
6920                 }
6921
6922                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6923                     (fc_conf.mode == RTE_FC_FULL))
6924                         rx_fc_en = 1;
6925                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6926                     (fc_conf.mode == RTE_FC_FULL))
6927                         tx_fc_en = 1;
6928         }
6929
6930         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6931                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6932
6933         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6934                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6935
6936         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6937
6938         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6939                 fc_conf.high_water = res->high_water;
6940
6941         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6942                 fc_conf.low_water = res->low_water;
6943
6944         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6945                 fc_conf.pause_time = res->pause_time;
6946
6947         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6948                 fc_conf.send_xon = res->send_xon;
6949
6950         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6951                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6952                         fc_conf.mac_ctrl_frame_fwd = 1;
6953                 else
6954                         fc_conf.mac_ctrl_frame_fwd = 0;
6955         }
6956
6957         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6958                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6959
6960         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6961         if (ret != 0)
6962                 printf("bad flow contrl parameter, return code = %d \n", ret);
6963 }
6964
6965 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6966 struct cmd_priority_flow_ctrl_set_result {
6967         cmdline_fixed_string_t set;
6968         cmdline_fixed_string_t pfc_ctrl;
6969         cmdline_fixed_string_t rx;
6970         cmdline_fixed_string_t rx_pfc_mode;
6971         cmdline_fixed_string_t tx;
6972         cmdline_fixed_string_t tx_pfc_mode;
6973         uint32_t high_water;
6974         uint32_t low_water;
6975         uint16_t pause_time;
6976         uint8_t  priority;
6977         portid_t port_id;
6978 };
6979
6980 static void
6981 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6982                        __attribute__((unused)) struct cmdline *cl,
6983                        __attribute__((unused)) void *data)
6984 {
6985         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6986         struct rte_eth_pfc_conf pfc_conf;
6987         int rx_fc_enable, tx_fc_enable;
6988         int ret;
6989
6990         /*
6991          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6992          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6993          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6994          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6995          */
6996         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6997                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6998         };
6999
7000         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7001         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7002         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7003         pfc_conf.fc.high_water = res->high_water;
7004         pfc_conf.fc.low_water  = res->low_water;
7005         pfc_conf.fc.pause_time = res->pause_time;
7006         pfc_conf.priority      = res->priority;
7007
7008         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7009         if (ret != 0)
7010                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7011 }
7012
7013 cmdline_parse_token_string_t cmd_pfc_set_set =
7014         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7015                                 set, "set");
7016 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7017         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7018                                 pfc_ctrl, "pfc_ctrl");
7019 cmdline_parse_token_string_t cmd_pfc_set_rx =
7020         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7021                                 rx, "rx");
7022 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7023         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7024                                 rx_pfc_mode, "on#off");
7025 cmdline_parse_token_string_t cmd_pfc_set_tx =
7026         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7027                                 tx, "tx");
7028 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7029         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7030                                 tx_pfc_mode, "on#off");
7031 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7032         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7033                                 high_water, UINT32);
7034 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7035         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7036                                 low_water, UINT32);
7037 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7038         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7039                                 pause_time, UINT16);
7040 cmdline_parse_token_num_t cmd_pfc_set_priority =
7041         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7042                                 priority, UINT8);
7043 cmdline_parse_token_num_t cmd_pfc_set_portid =
7044         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7045                                 port_id, UINT16);
7046
7047 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7048         .f = cmd_priority_flow_ctrl_set_parsed,
7049         .data = NULL,
7050         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7051                 "<pause_time> <priority> <port_id>: "
7052                 "Configure the Ethernet priority flow control",
7053         .tokens = {
7054                 (void *)&cmd_pfc_set_set,
7055                 (void *)&cmd_pfc_set_flow_ctrl,
7056                 (void *)&cmd_pfc_set_rx,
7057                 (void *)&cmd_pfc_set_rx_mode,
7058                 (void *)&cmd_pfc_set_tx,
7059                 (void *)&cmd_pfc_set_tx_mode,
7060                 (void *)&cmd_pfc_set_high_water,
7061                 (void *)&cmd_pfc_set_low_water,
7062                 (void *)&cmd_pfc_set_pause_time,
7063                 (void *)&cmd_pfc_set_priority,
7064                 (void *)&cmd_pfc_set_portid,
7065                 NULL,
7066         },
7067 };
7068
7069 /* *** RESET CONFIGURATION *** */
7070 struct cmd_reset_result {
7071         cmdline_fixed_string_t reset;
7072         cmdline_fixed_string_t def;
7073 };
7074
7075 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7076                              struct cmdline *cl,
7077                              __attribute__((unused)) void *data)
7078 {
7079         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7080         set_def_fwd_config();
7081 }
7082
7083 cmdline_parse_token_string_t cmd_reset_set =
7084         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7085 cmdline_parse_token_string_t cmd_reset_def =
7086         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7087                                  "default");
7088
7089 cmdline_parse_inst_t cmd_reset = {
7090         .f = cmd_reset_parsed,
7091         .data = NULL,
7092         .help_str = "set default: Reset default forwarding configuration",
7093         .tokens = {
7094                 (void *)&cmd_reset_set,
7095                 (void *)&cmd_reset_def,
7096                 NULL,
7097         },
7098 };
7099
7100 /* *** START FORWARDING *** */
7101 struct cmd_start_result {
7102         cmdline_fixed_string_t start;
7103 };
7104
7105 cmdline_parse_token_string_t cmd_start_start =
7106         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7107
7108 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7109                              __attribute__((unused)) struct cmdline *cl,
7110                              __attribute__((unused)) void *data)
7111 {
7112         start_packet_forwarding(0);
7113 }
7114
7115 cmdline_parse_inst_t cmd_start = {
7116         .f = cmd_start_parsed,
7117         .data = NULL,
7118         .help_str = "start: Start packet forwarding",
7119         .tokens = {
7120                 (void *)&cmd_start_start,
7121                 NULL,
7122         },
7123 };
7124
7125 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7126 struct cmd_start_tx_first_result {
7127         cmdline_fixed_string_t start;
7128         cmdline_fixed_string_t tx_first;
7129 };
7130
7131 static void
7132 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7133                           __attribute__((unused)) struct cmdline *cl,
7134                           __attribute__((unused)) void *data)
7135 {
7136         start_packet_forwarding(1);
7137 }
7138
7139 cmdline_parse_token_string_t cmd_start_tx_first_start =
7140         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7141                                  "start");
7142 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7143         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7144                                  tx_first, "tx_first");
7145
7146 cmdline_parse_inst_t cmd_start_tx_first = {
7147         .f = cmd_start_tx_first_parsed,
7148         .data = NULL,
7149         .help_str = "start tx_first: Start packet forwarding, "
7150                 "after sending 1 burst of packets",
7151         .tokens = {
7152                 (void *)&cmd_start_tx_first_start,
7153                 (void *)&cmd_start_tx_first_tx_first,
7154                 NULL,
7155         },
7156 };
7157
7158 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7159 struct cmd_start_tx_first_n_result {
7160         cmdline_fixed_string_t start;
7161         cmdline_fixed_string_t tx_first;
7162         uint32_t tx_num;
7163 };
7164
7165 static void
7166 cmd_start_tx_first_n_parsed(void *parsed_result,
7167                           __attribute__((unused)) struct cmdline *cl,
7168                           __attribute__((unused)) void *data)
7169 {
7170         struct cmd_start_tx_first_n_result *res = parsed_result;
7171
7172         start_packet_forwarding(res->tx_num);
7173 }
7174
7175 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7176         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7177                         start, "start");
7178 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7179         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7180                         tx_first, "tx_first");
7181 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7182         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7183                         tx_num, UINT32);
7184
7185 cmdline_parse_inst_t cmd_start_tx_first_n = {
7186         .f = cmd_start_tx_first_n_parsed,
7187         .data = NULL,
7188         .help_str = "start tx_first <num>: "
7189                 "packet forwarding, after sending <num> bursts of packets",
7190         .tokens = {
7191                 (void *)&cmd_start_tx_first_n_start,
7192                 (void *)&cmd_start_tx_first_n_tx_first,
7193                 (void *)&cmd_start_tx_first_n_tx_num,
7194                 NULL,
7195         },
7196 };
7197
7198 /* *** SET LINK UP *** */
7199 struct cmd_set_link_up_result {
7200         cmdline_fixed_string_t set;
7201         cmdline_fixed_string_t link_up;
7202         cmdline_fixed_string_t port;
7203         portid_t port_id;
7204 };
7205
7206 cmdline_parse_token_string_t cmd_set_link_up_set =
7207         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7208 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7209         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7210                                 "link-up");
7211 cmdline_parse_token_string_t cmd_set_link_up_port =
7212         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7213 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7214         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7215
7216 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7217                              __attribute__((unused)) struct cmdline *cl,
7218                              __attribute__((unused)) void *data)
7219 {
7220         struct cmd_set_link_up_result *res = parsed_result;
7221         dev_set_link_up(res->port_id);
7222 }
7223
7224 cmdline_parse_inst_t cmd_set_link_up = {
7225         .f = cmd_set_link_up_parsed,
7226         .data = NULL,
7227         .help_str = "set link-up port <port id>",
7228         .tokens = {
7229                 (void *)&cmd_set_link_up_set,
7230                 (void *)&cmd_set_link_up_link_up,
7231                 (void *)&cmd_set_link_up_port,
7232                 (void *)&cmd_set_link_up_port_id,
7233                 NULL,
7234         },
7235 };
7236
7237 /* *** SET LINK DOWN *** */
7238 struct cmd_set_link_down_result {
7239         cmdline_fixed_string_t set;
7240         cmdline_fixed_string_t link_down;
7241         cmdline_fixed_string_t port;
7242         portid_t port_id;
7243 };
7244
7245 cmdline_parse_token_string_t cmd_set_link_down_set =
7246         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7247 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7248         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7249                                 "link-down");
7250 cmdline_parse_token_string_t cmd_set_link_down_port =
7251         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7252 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7253         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7254
7255 static void cmd_set_link_down_parsed(
7256                                 __attribute__((unused)) void *parsed_result,
7257                                 __attribute__((unused)) struct cmdline *cl,
7258                                 __attribute__((unused)) void *data)
7259 {
7260         struct cmd_set_link_down_result *res = parsed_result;
7261         dev_set_link_down(res->port_id);
7262 }
7263
7264 cmdline_parse_inst_t cmd_set_link_down = {
7265         .f = cmd_set_link_down_parsed,
7266         .data = NULL,
7267         .help_str = "set link-down port <port id>",
7268         .tokens = {
7269                 (void *)&cmd_set_link_down_set,
7270                 (void *)&cmd_set_link_down_link_down,
7271                 (void *)&cmd_set_link_down_port,
7272                 (void *)&cmd_set_link_down_port_id,
7273                 NULL,
7274         },
7275 };
7276
7277 /* *** SHOW CFG *** */
7278 struct cmd_showcfg_result {
7279         cmdline_fixed_string_t show;
7280         cmdline_fixed_string_t cfg;
7281         cmdline_fixed_string_t what;
7282 };
7283
7284 static void cmd_showcfg_parsed(void *parsed_result,
7285                                __attribute__((unused)) struct cmdline *cl,
7286                                __attribute__((unused)) void *data)
7287 {
7288         struct cmd_showcfg_result *res = parsed_result;
7289         if (!strcmp(res->what, "rxtx"))
7290                 rxtx_config_display();
7291         else if (!strcmp(res->what, "cores"))
7292                 fwd_lcores_config_display();
7293         else if (!strcmp(res->what, "fwd"))
7294                 pkt_fwd_config_display(&cur_fwd_config);
7295         else if (!strcmp(res->what, "txpkts"))
7296                 show_tx_pkt_segments();
7297 }
7298
7299 cmdline_parse_token_string_t cmd_showcfg_show =
7300         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7301 cmdline_parse_token_string_t cmd_showcfg_port =
7302         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7303 cmdline_parse_token_string_t cmd_showcfg_what =
7304         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7305                                  "rxtx#cores#fwd#txpkts");
7306
7307 cmdline_parse_inst_t cmd_showcfg = {
7308         .f = cmd_showcfg_parsed,
7309         .data = NULL,
7310         .help_str = "show config rxtx|cores|fwd|txpkts",
7311         .tokens = {
7312                 (void *)&cmd_showcfg_show,
7313                 (void *)&cmd_showcfg_port,
7314                 (void *)&cmd_showcfg_what,
7315                 NULL,
7316         },
7317 };
7318
7319 /* *** SHOW ALL PORT INFO *** */
7320 struct cmd_showportall_result {
7321         cmdline_fixed_string_t show;
7322         cmdline_fixed_string_t port;
7323         cmdline_fixed_string_t what;
7324         cmdline_fixed_string_t all;
7325 };
7326
7327 static void cmd_showportall_parsed(void *parsed_result,
7328                                 __attribute__((unused)) struct cmdline *cl,
7329                                 __attribute__((unused)) void *data)
7330 {
7331         portid_t i;
7332
7333         struct cmd_showportall_result *res = parsed_result;
7334         if (!strcmp(res->show, "clear")) {
7335                 if (!strcmp(res->what, "stats"))
7336                         RTE_ETH_FOREACH_DEV(i)
7337                                 nic_stats_clear(i);
7338                 else if (!strcmp(res->what, "xstats"))
7339                         RTE_ETH_FOREACH_DEV(i)
7340                                 nic_xstats_clear(i);
7341         } else if (!strcmp(res->what, "info"))
7342                 RTE_ETH_FOREACH_DEV(i)
7343                         port_infos_display(i);
7344         else if (!strcmp(res->what, "summary")) {
7345                 port_summary_header_display();
7346                 RTE_ETH_FOREACH_DEV(i)
7347                         port_summary_display(i);
7348         }
7349         else if (!strcmp(res->what, "stats"))
7350                 RTE_ETH_FOREACH_DEV(i)
7351                         nic_stats_display(i);
7352         else if (!strcmp(res->what, "xstats"))
7353                 RTE_ETH_FOREACH_DEV(i)
7354                         nic_xstats_display(i);
7355         else if (!strcmp(res->what, "fdir"))
7356                 RTE_ETH_FOREACH_DEV(i)
7357                         fdir_get_infos(i);
7358         else if (!strcmp(res->what, "stat_qmap"))
7359                 RTE_ETH_FOREACH_DEV(i)
7360                         nic_stats_mapping_display(i);
7361         else if (!strcmp(res->what, "dcb_tc"))
7362                 RTE_ETH_FOREACH_DEV(i)
7363                         port_dcb_info_display(i);
7364         else if (!strcmp(res->what, "cap"))
7365                 RTE_ETH_FOREACH_DEV(i)
7366                         port_offload_cap_display(i);
7367 }
7368
7369 cmdline_parse_token_string_t cmd_showportall_show =
7370         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7371                                  "show#clear");
7372 cmdline_parse_token_string_t cmd_showportall_port =
7373         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7374 cmdline_parse_token_string_t cmd_showportall_what =
7375         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7376                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7377 cmdline_parse_token_string_t cmd_showportall_all =
7378         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7379 cmdline_parse_inst_t cmd_showportall = {
7380         .f = cmd_showportall_parsed,
7381         .data = NULL,
7382         .help_str = "show|clear port "
7383                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7384         .tokens = {
7385                 (void *)&cmd_showportall_show,
7386                 (void *)&cmd_showportall_port,
7387                 (void *)&cmd_showportall_what,
7388                 (void *)&cmd_showportall_all,
7389                 NULL,
7390         },
7391 };
7392
7393 /* *** SHOW PORT INFO *** */
7394 struct cmd_showport_result {
7395         cmdline_fixed_string_t show;
7396         cmdline_fixed_string_t port;
7397         cmdline_fixed_string_t what;
7398         uint16_t portnum;
7399 };
7400
7401 static void cmd_showport_parsed(void *parsed_result,
7402                                 __attribute__((unused)) struct cmdline *cl,
7403                                 __attribute__((unused)) void *data)
7404 {
7405         struct cmd_showport_result *res = parsed_result;
7406         if (!strcmp(res->show, "clear")) {
7407                 if (!strcmp(res->what, "stats"))
7408                         nic_stats_clear(res->portnum);
7409                 else if (!strcmp(res->what, "xstats"))
7410                         nic_xstats_clear(res->portnum);
7411         } else if (!strcmp(res->what, "info"))
7412                 port_infos_display(res->portnum);
7413         else if (!strcmp(res->what, "summary")) {
7414                 port_summary_header_display();
7415                 port_summary_display(res->portnum);
7416         }
7417         else if (!strcmp(res->what, "stats"))
7418                 nic_stats_display(res->portnum);
7419         else if (!strcmp(res->what, "xstats"))
7420                 nic_xstats_display(res->portnum);
7421         else if (!strcmp(res->what, "fdir"))
7422                  fdir_get_infos(res->portnum);
7423         else if (!strcmp(res->what, "stat_qmap"))
7424                 nic_stats_mapping_display(res->portnum);
7425         else if (!strcmp(res->what, "dcb_tc"))
7426                 port_dcb_info_display(res->portnum);
7427         else if (!strcmp(res->what, "cap"))
7428                 port_offload_cap_display(res->portnum);
7429 }
7430
7431 cmdline_parse_token_string_t cmd_showport_show =
7432         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7433                                  "show#clear");
7434 cmdline_parse_token_string_t cmd_showport_port =
7435         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7436 cmdline_parse_token_string_t cmd_showport_what =
7437         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7438                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7439 cmdline_parse_token_num_t cmd_showport_portnum =
7440         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7441
7442 cmdline_parse_inst_t cmd_showport = {
7443         .f = cmd_showport_parsed,
7444         .data = NULL,
7445         .help_str = "show|clear port "
7446                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7447                 "<port_id>",
7448         .tokens = {
7449                 (void *)&cmd_showport_show,
7450                 (void *)&cmd_showport_port,
7451                 (void *)&cmd_showport_what,
7452                 (void *)&cmd_showport_portnum,
7453                 NULL,
7454         },
7455 };
7456
7457 /* *** SHOW DEVICE INFO *** */
7458 struct cmd_showdevice_result {
7459         cmdline_fixed_string_t show;
7460         cmdline_fixed_string_t device;
7461         cmdline_fixed_string_t what;
7462         cmdline_fixed_string_t identifier;
7463 };
7464
7465 static void cmd_showdevice_parsed(void *parsed_result,
7466                                 __attribute__((unused)) struct cmdline *cl,
7467                                 __attribute__((unused)) void *data)
7468 {
7469         struct cmd_showdevice_result *res = parsed_result;
7470         if (!strcmp(res->what, "info")) {
7471                 if (!strcmp(res->identifier, "all"))
7472                         device_infos_display(NULL);
7473                 else
7474                         device_infos_display(res->identifier);
7475         }
7476 }
7477
7478 cmdline_parse_token_string_t cmd_showdevice_show =
7479         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7480                                  "show");
7481 cmdline_parse_token_string_t cmd_showdevice_device =
7482         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7483 cmdline_parse_token_string_t cmd_showdevice_what =
7484         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7485                                  "info");
7486 cmdline_parse_token_string_t cmd_showdevice_identifier =
7487         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7488                         identifier, NULL);
7489
7490 cmdline_parse_inst_t cmd_showdevice = {
7491         .f = cmd_showdevice_parsed,
7492         .data = NULL,
7493         .help_str = "show device info <identifier>|all",
7494         .tokens = {
7495                 (void *)&cmd_showdevice_show,
7496                 (void *)&cmd_showdevice_device,
7497                 (void *)&cmd_showdevice_what,
7498                 (void *)&cmd_showdevice_identifier,
7499                 NULL,
7500         },
7501 };
7502 /* *** SHOW QUEUE INFO *** */
7503 struct cmd_showqueue_result {
7504         cmdline_fixed_string_t show;
7505         cmdline_fixed_string_t type;
7506         cmdline_fixed_string_t what;
7507         uint16_t portnum;
7508         uint16_t queuenum;
7509 };
7510
7511 static void
7512 cmd_showqueue_parsed(void *parsed_result,
7513         __attribute__((unused)) struct cmdline *cl,
7514         __attribute__((unused)) void *data)
7515 {
7516         struct cmd_showqueue_result *res = parsed_result;
7517
7518         if (!strcmp(res->type, "rxq"))
7519                 rx_queue_infos_display(res->portnum, res->queuenum);
7520         else if (!strcmp(res->type, "txq"))
7521                 tx_queue_infos_display(res->portnum, res->queuenum);
7522 }
7523
7524 cmdline_parse_token_string_t cmd_showqueue_show =
7525         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7526 cmdline_parse_token_string_t cmd_showqueue_type =
7527         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7528 cmdline_parse_token_string_t cmd_showqueue_what =
7529         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7530 cmdline_parse_token_num_t cmd_showqueue_portnum =
7531         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7532 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7533         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7534
7535 cmdline_parse_inst_t cmd_showqueue = {
7536         .f = cmd_showqueue_parsed,
7537         .data = NULL,
7538         .help_str = "show rxq|txq info <port_id> <queue_id>",
7539         .tokens = {
7540                 (void *)&cmd_showqueue_show,
7541                 (void *)&cmd_showqueue_type,
7542                 (void *)&cmd_showqueue_what,
7543                 (void *)&cmd_showqueue_portnum,
7544                 (void *)&cmd_showqueue_queuenum,
7545                 NULL,
7546         },
7547 };
7548
7549 /* show/clear fwd engine statistics */
7550 struct fwd_result {
7551         cmdline_fixed_string_t action;
7552         cmdline_fixed_string_t fwd;
7553         cmdline_fixed_string_t stats;
7554         cmdline_fixed_string_t all;
7555 };
7556
7557 cmdline_parse_token_string_t cmd_fwd_action =
7558         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7559 cmdline_parse_token_string_t cmd_fwd_fwd =
7560         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7561 cmdline_parse_token_string_t cmd_fwd_stats =
7562         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7563 cmdline_parse_token_string_t cmd_fwd_all =
7564         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7565
7566 static void
7567 cmd_showfwdall_parsed(void *parsed_result,
7568                       __rte_unused struct cmdline *cl,
7569                       __rte_unused void *data)
7570 {
7571         struct fwd_result *res = parsed_result;
7572
7573         if (!strcmp(res->action, "show"))
7574                 fwd_stats_display();
7575         else
7576                 fwd_stats_reset();
7577 }
7578
7579 static cmdline_parse_inst_t cmd_showfwdall = {
7580         .f = cmd_showfwdall_parsed,
7581         .data = NULL,
7582         .help_str = "show|clear fwd stats all",
7583         .tokens = {
7584                 (void *)&cmd_fwd_action,
7585                 (void *)&cmd_fwd_fwd,
7586                 (void *)&cmd_fwd_stats,
7587                 (void *)&cmd_fwd_all,
7588                 NULL,
7589         },
7590 };
7591
7592 /* *** READ PORT REGISTER *** */
7593 struct cmd_read_reg_result {
7594         cmdline_fixed_string_t read;
7595         cmdline_fixed_string_t reg;
7596         portid_t port_id;
7597         uint32_t reg_off;
7598 };
7599
7600 static void
7601 cmd_read_reg_parsed(void *parsed_result,
7602                     __attribute__((unused)) struct cmdline *cl,
7603                     __attribute__((unused)) void *data)
7604 {
7605         struct cmd_read_reg_result *res = parsed_result;
7606         port_reg_display(res->port_id, res->reg_off);
7607 }
7608
7609 cmdline_parse_token_string_t cmd_read_reg_read =
7610         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7611 cmdline_parse_token_string_t cmd_read_reg_reg =
7612         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7613 cmdline_parse_token_num_t cmd_read_reg_port_id =
7614         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7615 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7616         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7617
7618 cmdline_parse_inst_t cmd_read_reg = {
7619         .f = cmd_read_reg_parsed,
7620         .data = NULL,
7621         .help_str = "read reg <port_id> <reg_off>",
7622         .tokens = {
7623                 (void *)&cmd_read_reg_read,
7624                 (void *)&cmd_read_reg_reg,
7625                 (void *)&cmd_read_reg_port_id,
7626                 (void *)&cmd_read_reg_reg_off,
7627                 NULL,
7628         },
7629 };
7630
7631 /* *** READ PORT REGISTER BIT FIELD *** */
7632 struct cmd_read_reg_bit_field_result {
7633         cmdline_fixed_string_t read;
7634         cmdline_fixed_string_t regfield;
7635         portid_t port_id;
7636         uint32_t reg_off;
7637         uint8_t bit1_pos;
7638         uint8_t bit2_pos;
7639 };
7640
7641 static void
7642 cmd_read_reg_bit_field_parsed(void *parsed_result,
7643                               __attribute__((unused)) struct cmdline *cl,
7644                               __attribute__((unused)) void *data)
7645 {
7646         struct cmd_read_reg_bit_field_result *res = parsed_result;
7647         port_reg_bit_field_display(res->port_id, res->reg_off,
7648                                    res->bit1_pos, res->bit2_pos);
7649 }
7650
7651 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7652         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7653                                  "read");
7654 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7655         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7656                                  regfield, "regfield");
7657 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7658         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7659                               UINT16);
7660 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7661         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7662                               UINT32);
7663 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7664         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7665                               UINT8);
7666 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7667         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7668                               UINT8);
7669
7670 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7671         .f = cmd_read_reg_bit_field_parsed,
7672         .data = NULL,
7673         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7674         "Read register bit field between bit_x and bit_y included",
7675         .tokens = {
7676                 (void *)&cmd_read_reg_bit_field_read,
7677                 (void *)&cmd_read_reg_bit_field_regfield,
7678                 (void *)&cmd_read_reg_bit_field_port_id,
7679                 (void *)&cmd_read_reg_bit_field_reg_off,
7680                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7681                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7682                 NULL,
7683         },
7684 };
7685
7686 /* *** READ PORT REGISTER BIT *** */
7687 struct cmd_read_reg_bit_result {
7688         cmdline_fixed_string_t read;
7689         cmdline_fixed_string_t regbit;
7690         portid_t port_id;
7691         uint32_t reg_off;
7692         uint8_t bit_pos;
7693 };
7694
7695 static void
7696 cmd_read_reg_bit_parsed(void *parsed_result,
7697                         __attribute__((unused)) struct cmdline *cl,
7698                         __attribute__((unused)) void *data)
7699 {
7700         struct cmd_read_reg_bit_result *res = parsed_result;
7701         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7702 }
7703
7704 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7705         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7706 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7707         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7708                                  regbit, "regbit");
7709 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7710         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7711 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7712         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7713 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7714         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7715
7716 cmdline_parse_inst_t cmd_read_reg_bit = {
7717         .f = cmd_read_reg_bit_parsed,
7718         .data = NULL,
7719         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7720         .tokens = {
7721                 (void *)&cmd_read_reg_bit_read,
7722                 (void *)&cmd_read_reg_bit_regbit,
7723                 (void *)&cmd_read_reg_bit_port_id,
7724                 (void *)&cmd_read_reg_bit_reg_off,
7725                 (void *)&cmd_read_reg_bit_bit_pos,
7726                 NULL,
7727         },
7728 };
7729
7730 /* *** WRITE PORT REGISTER *** */
7731 struct cmd_write_reg_result {
7732         cmdline_fixed_string_t write;
7733         cmdline_fixed_string_t reg;
7734         portid_t port_id;
7735         uint32_t reg_off;
7736         uint32_t value;
7737 };
7738
7739 static void
7740 cmd_write_reg_parsed(void *parsed_result,
7741                      __attribute__((unused)) struct cmdline *cl,
7742                      __attribute__((unused)) void *data)
7743 {
7744         struct cmd_write_reg_result *res = parsed_result;
7745         port_reg_set(res->port_id, res->reg_off, res->value);
7746 }
7747
7748 cmdline_parse_token_string_t cmd_write_reg_write =
7749         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7750 cmdline_parse_token_string_t cmd_write_reg_reg =
7751         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7752 cmdline_parse_token_num_t cmd_write_reg_port_id =
7753         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7754 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7755         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7756 cmdline_parse_token_num_t cmd_write_reg_value =
7757         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7758
7759 cmdline_parse_inst_t cmd_write_reg = {
7760         .f = cmd_write_reg_parsed,
7761         .data = NULL,
7762         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7763         .tokens = {
7764                 (void *)&cmd_write_reg_write,
7765                 (void *)&cmd_write_reg_reg,
7766                 (void *)&cmd_write_reg_port_id,
7767                 (void *)&cmd_write_reg_reg_off,
7768                 (void *)&cmd_write_reg_value,
7769                 NULL,
7770         },
7771 };
7772
7773 /* *** WRITE PORT REGISTER BIT FIELD *** */
7774 struct cmd_write_reg_bit_field_result {
7775         cmdline_fixed_string_t write;
7776         cmdline_fixed_string_t regfield;
7777         portid_t port_id;
7778         uint32_t reg_off;
7779         uint8_t bit1_pos;
7780         uint8_t bit2_pos;
7781         uint32_t value;
7782 };
7783
7784 static void
7785 cmd_write_reg_bit_field_parsed(void *parsed_result,
7786                                __attribute__((unused)) struct cmdline *cl,
7787                                __attribute__((unused)) void *data)
7788 {
7789         struct cmd_write_reg_bit_field_result *res = parsed_result;
7790         port_reg_bit_field_set(res->port_id, res->reg_off,
7791                           res->bit1_pos, res->bit2_pos, res->value);
7792 }
7793
7794 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7795         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7796                                  "write");
7797 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7798         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7799                                  regfield, "regfield");
7800 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7801         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7802                               UINT16);
7803 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7804         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7805                               UINT32);
7806 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7807         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7808                               UINT8);
7809 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7810         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7811                               UINT8);
7812 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7813         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7814                               UINT32);
7815
7816 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7817         .f = cmd_write_reg_bit_field_parsed,
7818         .data = NULL,
7819         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7820                 "<reg_value>: "
7821                 "Set register bit field between bit_x and bit_y included",
7822         .tokens = {
7823                 (void *)&cmd_write_reg_bit_field_write,
7824                 (void *)&cmd_write_reg_bit_field_regfield,
7825                 (void *)&cmd_write_reg_bit_field_port_id,
7826                 (void *)&cmd_write_reg_bit_field_reg_off,
7827                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7828                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7829                 (void *)&cmd_write_reg_bit_field_value,
7830                 NULL,
7831         },
7832 };
7833
7834 /* *** WRITE PORT REGISTER BIT *** */
7835 struct cmd_write_reg_bit_result {
7836         cmdline_fixed_string_t write;
7837         cmdline_fixed_string_t regbit;
7838         portid_t port_id;
7839         uint32_t reg_off;
7840         uint8_t bit_pos;
7841         uint8_t value;
7842 };
7843
7844 static void
7845 cmd_write_reg_bit_parsed(void *parsed_result,
7846                          __attribute__((unused)) struct cmdline *cl,
7847                          __attribute__((unused)) void *data)
7848 {
7849         struct cmd_write_reg_bit_result *res = parsed_result;
7850         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7851 }
7852
7853 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7854         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7855                                  "write");
7856 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7857         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7858                                  regbit, "regbit");
7859 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7860         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7861 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7862         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7863 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7864         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7865 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7866         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7867
7868 cmdline_parse_inst_t cmd_write_reg_bit = {
7869         .f = cmd_write_reg_bit_parsed,
7870         .data = NULL,
7871         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7872                 "0 <= bit_x <= 31",
7873         .tokens = {
7874                 (void *)&cmd_write_reg_bit_write,
7875                 (void *)&cmd_write_reg_bit_regbit,
7876                 (void *)&cmd_write_reg_bit_port_id,
7877                 (void *)&cmd_write_reg_bit_reg_off,
7878                 (void *)&cmd_write_reg_bit_bit_pos,
7879                 (void *)&cmd_write_reg_bit_value,
7880                 NULL,
7881         },
7882 };
7883
7884 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7885 struct cmd_read_rxd_txd_result {
7886         cmdline_fixed_string_t read;
7887         cmdline_fixed_string_t rxd_txd;
7888         portid_t port_id;
7889         uint16_t queue_id;
7890         uint16_t desc_id;
7891 };
7892
7893 static void
7894 cmd_read_rxd_txd_parsed(void *parsed_result,
7895                         __attribute__((unused)) struct cmdline *cl,
7896                         __attribute__((unused)) void *data)
7897 {
7898         struct cmd_read_rxd_txd_result *res = parsed_result;
7899
7900         if (!strcmp(res->rxd_txd, "rxd"))
7901                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7902         else if (!strcmp(res->rxd_txd, "txd"))
7903                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7904 }
7905
7906 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7907         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7908 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7909         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7910                                  "rxd#txd");
7911 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7912         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7913 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7914         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7915 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7916         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7917
7918 cmdline_parse_inst_t cmd_read_rxd_txd = {
7919         .f = cmd_read_rxd_txd_parsed,
7920         .data = NULL,
7921         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7922         .tokens = {
7923                 (void *)&cmd_read_rxd_txd_read,
7924                 (void *)&cmd_read_rxd_txd_rxd_txd,
7925                 (void *)&cmd_read_rxd_txd_port_id,
7926                 (void *)&cmd_read_rxd_txd_queue_id,
7927                 (void *)&cmd_read_rxd_txd_desc_id,
7928                 NULL,
7929         },
7930 };
7931
7932 /* *** QUIT *** */
7933 struct cmd_quit_result {
7934         cmdline_fixed_string_t quit;
7935 };
7936
7937 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7938                             struct cmdline *cl,
7939                             __attribute__((unused)) void *data)
7940 {
7941         cmdline_quit(cl);
7942 }
7943
7944 cmdline_parse_token_string_t cmd_quit_quit =
7945         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7946
7947 cmdline_parse_inst_t cmd_quit = {
7948         .f = cmd_quit_parsed,
7949         .data = NULL,
7950         .help_str = "quit: Exit application",
7951         .tokens = {
7952                 (void *)&cmd_quit_quit,
7953                 NULL,
7954         },
7955 };
7956
7957 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7958 struct cmd_mac_addr_result {
7959         cmdline_fixed_string_t mac_addr_cmd;
7960         cmdline_fixed_string_t what;
7961         uint16_t port_num;
7962         struct rte_ether_addr address;
7963 };
7964
7965 static void cmd_mac_addr_parsed(void *parsed_result,
7966                 __attribute__((unused)) struct cmdline *cl,
7967                 __attribute__((unused)) void *data)
7968 {
7969         struct cmd_mac_addr_result *res = parsed_result;
7970         int ret;
7971
7972         if (strcmp(res->what, "add") == 0)
7973                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7974         else if (strcmp(res->what, "set") == 0)
7975                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7976                                                        &res->address);
7977         else
7978                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7979
7980         /* check the return value and print it if is < 0 */
7981         if(ret < 0)
7982                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7983
7984 }
7985
7986 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7987         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7988                                 "mac_addr");
7989 cmdline_parse_token_string_t cmd_mac_addr_what =
7990         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7991                                 "add#remove#set");
7992 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7993                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7994                                         UINT16);
7995 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7996                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7997
7998 cmdline_parse_inst_t cmd_mac_addr = {
7999         .f = cmd_mac_addr_parsed,
8000         .data = (void *)0,
8001         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8002                         "Add/Remove/Set MAC address on port_id",
8003         .tokens = {
8004                 (void *)&cmd_mac_addr_cmd,
8005                 (void *)&cmd_mac_addr_what,
8006                 (void *)&cmd_mac_addr_portnum,
8007                 (void *)&cmd_mac_addr_addr,
8008                 NULL,
8009         },
8010 };
8011
8012 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8013 struct cmd_eth_peer_result {
8014         cmdline_fixed_string_t set;
8015         cmdline_fixed_string_t eth_peer;
8016         portid_t port_id;
8017         cmdline_fixed_string_t peer_addr;
8018 };
8019
8020 static void cmd_set_eth_peer_parsed(void *parsed_result,
8021                         __attribute__((unused)) struct cmdline *cl,
8022                         __attribute__((unused)) void *data)
8023 {
8024                 struct cmd_eth_peer_result *res = parsed_result;
8025
8026                 if (test_done == 0) {
8027                         printf("Please stop forwarding first\n");
8028                         return;
8029                 }
8030                 if (!strcmp(res->eth_peer, "eth-peer")) {
8031                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8032                         fwd_config_setup();
8033                 }
8034 }
8035 cmdline_parse_token_string_t cmd_eth_peer_set =
8036         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8037 cmdline_parse_token_string_t cmd_eth_peer =
8038         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8039 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8040         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8041 cmdline_parse_token_string_t cmd_eth_peer_addr =
8042         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8043
8044 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8045         .f = cmd_set_eth_peer_parsed,
8046         .data = NULL,
8047         .help_str = "set eth-peer <port_id> <peer_mac>",
8048         .tokens = {
8049                 (void *)&cmd_eth_peer_set,
8050                 (void *)&cmd_eth_peer,
8051                 (void *)&cmd_eth_peer_port_id,
8052                 (void *)&cmd_eth_peer_addr,
8053                 NULL,
8054         },
8055 };
8056
8057 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8058 struct cmd_set_qmap_result {
8059         cmdline_fixed_string_t set;
8060         cmdline_fixed_string_t qmap;
8061         cmdline_fixed_string_t what;
8062         portid_t port_id;
8063         uint16_t queue_id;
8064         uint8_t map_value;
8065 };
8066
8067 static void
8068 cmd_set_qmap_parsed(void *parsed_result,
8069                        __attribute__((unused)) struct cmdline *cl,
8070                        __attribute__((unused)) void *data)
8071 {
8072         struct cmd_set_qmap_result *res = parsed_result;
8073         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8074
8075         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8076 }
8077
8078 cmdline_parse_token_string_t cmd_setqmap_set =
8079         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8080                                  set, "set");
8081 cmdline_parse_token_string_t cmd_setqmap_qmap =
8082         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8083                                  qmap, "stat_qmap");
8084 cmdline_parse_token_string_t cmd_setqmap_what =
8085         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8086                                  what, "tx#rx");
8087 cmdline_parse_token_num_t cmd_setqmap_portid =
8088         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8089                               port_id, UINT16);
8090 cmdline_parse_token_num_t cmd_setqmap_queueid =
8091         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8092                               queue_id, UINT16);
8093 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8094         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8095                               map_value, UINT8);
8096
8097 cmdline_parse_inst_t cmd_set_qmap = {
8098         .f = cmd_set_qmap_parsed,
8099         .data = NULL,
8100         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8101                 "Set statistics mapping value on tx|rx queue_id of port_id",
8102         .tokens = {
8103                 (void *)&cmd_setqmap_set,
8104                 (void *)&cmd_setqmap_qmap,
8105                 (void *)&cmd_setqmap_what,
8106                 (void *)&cmd_setqmap_portid,
8107                 (void *)&cmd_setqmap_queueid,
8108                 (void *)&cmd_setqmap_mapvalue,
8109                 NULL,
8110         },
8111 };
8112
8113 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8114 struct cmd_set_xstats_hide_zero_result {
8115         cmdline_fixed_string_t keyword;
8116         cmdline_fixed_string_t name;
8117         cmdline_fixed_string_t on_off;
8118 };
8119
8120 static void
8121 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8122                         __attribute__((unused)) struct cmdline *cl,
8123                         __attribute__((unused)) void *data)
8124 {
8125         struct cmd_set_xstats_hide_zero_result *res;
8126         uint16_t on_off = 0;
8127
8128         res = parsed_result;
8129         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8130         set_xstats_hide_zero(on_off);
8131 }
8132
8133 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8134         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8135                                  keyword, "set");
8136 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8137         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8138                                  name, "xstats-hide-zero");
8139 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8140         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8141                                  on_off, "on#off");
8142
8143 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8144         .f = cmd_set_xstats_hide_zero_parsed,
8145         .data = NULL,
8146         .help_str = "set xstats-hide-zero on|off",
8147         .tokens = {
8148                 (void *)&cmd_set_xstats_hide_zero_keyword,
8149                 (void *)&cmd_set_xstats_hide_zero_name,
8150                 (void *)&cmd_set_xstats_hide_zero_on_off,
8151                 NULL,
8152         },
8153 };
8154
8155 /* *** CONFIGURE UNICAST HASH TABLE *** */
8156 struct cmd_set_uc_hash_table {
8157         cmdline_fixed_string_t set;
8158         cmdline_fixed_string_t port;
8159         portid_t port_id;
8160         cmdline_fixed_string_t what;
8161         struct rte_ether_addr address;
8162         cmdline_fixed_string_t mode;
8163 };
8164
8165 static void
8166 cmd_set_uc_hash_parsed(void *parsed_result,
8167                        __attribute__((unused)) struct cmdline *cl,
8168                        __attribute__((unused)) void *data)
8169 {
8170         int ret=0;
8171         struct cmd_set_uc_hash_table *res = parsed_result;
8172
8173         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8174
8175         if (strcmp(res->what, "uta") == 0)
8176                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8177                                                 &res->address,(uint8_t)is_on);
8178         if (ret < 0)
8179                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8180
8181 }
8182
8183 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8184         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8185                                  set, "set");
8186 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8187         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8188                                  port, "port");
8189 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8190         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8191                               port_id, UINT16);
8192 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8193         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8194                                  what, "uta");
8195 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8196         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8197                                 address);
8198 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8199         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8200                                  mode, "on#off");
8201
8202 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8203         .f = cmd_set_uc_hash_parsed,
8204         .data = NULL,
8205         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8206         .tokens = {
8207                 (void *)&cmd_set_uc_hash_set,
8208                 (void *)&cmd_set_uc_hash_port,
8209                 (void *)&cmd_set_uc_hash_portid,
8210                 (void *)&cmd_set_uc_hash_what,
8211                 (void *)&cmd_set_uc_hash_mac,
8212                 (void *)&cmd_set_uc_hash_mode,
8213                 NULL,
8214         },
8215 };
8216
8217 struct cmd_set_uc_all_hash_table {
8218         cmdline_fixed_string_t set;
8219         cmdline_fixed_string_t port;
8220         portid_t port_id;
8221         cmdline_fixed_string_t what;
8222         cmdline_fixed_string_t value;
8223         cmdline_fixed_string_t mode;
8224 };
8225
8226 static void
8227 cmd_set_uc_all_hash_parsed(void *parsed_result,
8228                        __attribute__((unused)) struct cmdline *cl,
8229                        __attribute__((unused)) void *data)
8230 {
8231         int ret=0;
8232         struct cmd_set_uc_all_hash_table *res = parsed_result;
8233
8234         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8235
8236         if ((strcmp(res->what, "uta") == 0) &&
8237                 (strcmp(res->value, "all") == 0))
8238                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8239         if (ret < 0)
8240                 printf("bad unicast hash table parameter,"
8241                         "return code = %d \n", ret);
8242 }
8243
8244 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8245         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8246                                  set, "set");
8247 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8248         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8249                                  port, "port");
8250 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8251         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8252                               port_id, UINT16);
8253 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8254         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8255                                  what, "uta");
8256 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8257         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8258                                 value,"all");
8259 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8260         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8261                                  mode, "on#off");
8262
8263 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8264         .f = cmd_set_uc_all_hash_parsed,
8265         .data = NULL,
8266         .help_str = "set port <port_id> uta all on|off",
8267         .tokens = {
8268                 (void *)&cmd_set_uc_all_hash_set,
8269                 (void *)&cmd_set_uc_all_hash_port,
8270                 (void *)&cmd_set_uc_all_hash_portid,
8271                 (void *)&cmd_set_uc_all_hash_what,
8272                 (void *)&cmd_set_uc_all_hash_value,
8273                 (void *)&cmd_set_uc_all_hash_mode,
8274                 NULL,
8275         },
8276 };
8277
8278 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8279 struct cmd_set_vf_macvlan_filter {
8280         cmdline_fixed_string_t set;
8281         cmdline_fixed_string_t port;
8282         portid_t port_id;
8283         cmdline_fixed_string_t vf;
8284         uint8_t vf_id;
8285         struct rte_ether_addr address;
8286         cmdline_fixed_string_t filter_type;
8287         cmdline_fixed_string_t mode;
8288 };
8289
8290 static void
8291 cmd_set_vf_macvlan_parsed(void *parsed_result,
8292                        __attribute__((unused)) struct cmdline *cl,
8293                        __attribute__((unused)) void *data)
8294 {
8295         int is_on, ret = 0;
8296         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8297         struct rte_eth_mac_filter filter;
8298
8299         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8300
8301         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8302
8303         /* set VF MAC filter */
8304         filter.is_vf = 1;
8305
8306         /* set VF ID */
8307         filter.dst_id = res->vf_id;
8308
8309         if (!strcmp(res->filter_type, "exact-mac"))
8310                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8311         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8312                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8313         else if (!strcmp(res->filter_type, "hashmac"))
8314                 filter.filter_type = RTE_MAC_HASH_MATCH;
8315         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8316                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8317
8318         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8319
8320         if (is_on)
8321                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8322                                         RTE_ETH_FILTER_MACVLAN,
8323                                         RTE_ETH_FILTER_ADD,
8324                                          &filter);
8325         else
8326                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8327                                         RTE_ETH_FILTER_MACVLAN,
8328                                         RTE_ETH_FILTER_DELETE,
8329                                         &filter);
8330
8331         if (ret < 0)
8332                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8333
8334 }
8335
8336 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8337         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8338                                  set, "set");
8339 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8340         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8341                                  port, "port");
8342 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8343         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8344                               port_id, UINT16);
8345 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8346         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8347                                  vf, "vf");
8348 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8349         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8350                                 vf_id, UINT8);
8351 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8352         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8353                                 address);
8354 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8355         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8356                                 filter_type, "exact-mac#exact-mac-vlan"
8357                                 "#hashmac#hashmac-vlan");
8358 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8359         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8360                                  mode, "on#off");
8361
8362 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8363         .f = cmd_set_vf_macvlan_parsed,
8364         .data = NULL,
8365         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8366                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8367                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8368                 "hash match rule: hash match of MAC and exact match of VLAN",
8369         .tokens = {
8370                 (void *)&cmd_set_vf_macvlan_set,
8371                 (void *)&cmd_set_vf_macvlan_port,
8372                 (void *)&cmd_set_vf_macvlan_portid,
8373                 (void *)&cmd_set_vf_macvlan_vf,
8374                 (void *)&cmd_set_vf_macvlan_vf_id,
8375                 (void *)&cmd_set_vf_macvlan_mac,
8376                 (void *)&cmd_set_vf_macvlan_filter_type,
8377                 (void *)&cmd_set_vf_macvlan_mode,
8378                 NULL,
8379         },
8380 };
8381
8382 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8383 struct cmd_set_vf_traffic {
8384         cmdline_fixed_string_t set;
8385         cmdline_fixed_string_t port;
8386         portid_t port_id;
8387         cmdline_fixed_string_t vf;
8388         uint8_t vf_id;
8389         cmdline_fixed_string_t what;
8390         cmdline_fixed_string_t mode;
8391 };
8392
8393 static void
8394 cmd_set_vf_traffic_parsed(void *parsed_result,
8395                        __attribute__((unused)) struct cmdline *cl,
8396                        __attribute__((unused)) void *data)
8397 {
8398         struct cmd_set_vf_traffic *res = parsed_result;
8399         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8400         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8401
8402         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8403 }
8404
8405 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8406         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8407                                  set, "set");
8408 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8409         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8410                                  port, "port");
8411 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8412         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8413                               port_id, UINT16);
8414 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8415         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8416                                  vf, "vf");
8417 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8418         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8419                               vf_id, UINT8);
8420 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8421         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8422                                  what, "tx#rx");
8423 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8424         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8425                                  mode, "on#off");
8426
8427 cmdline_parse_inst_t cmd_set_vf_traffic = {
8428         .f = cmd_set_vf_traffic_parsed,
8429         .data = NULL,
8430         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8431         .tokens = {
8432                 (void *)&cmd_setvf_traffic_set,
8433                 (void *)&cmd_setvf_traffic_port,
8434                 (void *)&cmd_setvf_traffic_portid,
8435                 (void *)&cmd_setvf_traffic_vf,
8436                 (void *)&cmd_setvf_traffic_vfid,
8437                 (void *)&cmd_setvf_traffic_what,
8438                 (void *)&cmd_setvf_traffic_mode,
8439                 NULL,
8440         },
8441 };
8442
8443 /* *** CONFIGURE VF RECEIVE MODE *** */
8444 struct cmd_set_vf_rxmode {
8445         cmdline_fixed_string_t set;
8446         cmdline_fixed_string_t port;
8447         portid_t port_id;
8448         cmdline_fixed_string_t vf;
8449         uint8_t vf_id;
8450         cmdline_fixed_string_t what;
8451         cmdline_fixed_string_t mode;
8452         cmdline_fixed_string_t on;
8453 };
8454
8455 static void
8456 cmd_set_vf_rxmode_parsed(void *parsed_result,
8457                        __attribute__((unused)) struct cmdline *cl,
8458                        __attribute__((unused)) void *data)
8459 {
8460         int ret = -ENOTSUP;
8461         uint16_t vf_rxmode = 0;
8462         struct cmd_set_vf_rxmode *res = parsed_result;
8463
8464         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8465         if (!strcmp(res->what,"rxmode")) {
8466                 if (!strcmp(res->mode, "AUPE"))
8467                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8468                 else if (!strcmp(res->mode, "ROPE"))
8469                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8470                 else if (!strcmp(res->mode, "BAM"))
8471                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8472                 else if (!strncmp(res->mode, "MPE",3))
8473                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8474         }
8475
8476         RTE_SET_USED(is_on);
8477
8478 #ifdef RTE_LIBRTE_IXGBE_PMD
8479         if (ret == -ENOTSUP)
8480                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8481                                                   vf_rxmode, (uint8_t)is_on);
8482 #endif
8483 #ifdef RTE_LIBRTE_BNXT_PMD
8484         if (ret == -ENOTSUP)
8485                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8486                                                  vf_rxmode, (uint8_t)is_on);
8487 #endif
8488         if (ret < 0)
8489                 printf("bad VF receive mode parameter, return code = %d \n",
8490                 ret);
8491 }
8492
8493 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8494         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8495                                  set, "set");
8496 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8497         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8498                                  port, "port");
8499 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8500         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8501                               port_id, UINT16);
8502 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8503         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8504                                  vf, "vf");
8505 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8506         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8507                               vf_id, UINT8);
8508 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8509         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8510                                  what, "rxmode");
8511 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8512         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8513                                  mode, "AUPE#ROPE#BAM#MPE");
8514 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8515         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8516                                  on, "on#off");
8517
8518 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8519         .f = cmd_set_vf_rxmode_parsed,
8520         .data = NULL,
8521         .help_str = "set port <port_id> vf <vf_id> rxmode "
8522                 "AUPE|ROPE|BAM|MPE on|off",
8523         .tokens = {
8524                 (void *)&cmd_set_vf_rxmode_set,
8525                 (void *)&cmd_set_vf_rxmode_port,
8526                 (void *)&cmd_set_vf_rxmode_portid,
8527                 (void *)&cmd_set_vf_rxmode_vf,
8528                 (void *)&cmd_set_vf_rxmode_vfid,
8529                 (void *)&cmd_set_vf_rxmode_what,
8530                 (void *)&cmd_set_vf_rxmode_mode,
8531                 (void *)&cmd_set_vf_rxmode_on,
8532                 NULL,
8533         },
8534 };
8535
8536 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8537 struct cmd_vf_mac_addr_result {
8538         cmdline_fixed_string_t mac_addr_cmd;
8539         cmdline_fixed_string_t what;
8540         cmdline_fixed_string_t port;
8541         uint16_t port_num;
8542         cmdline_fixed_string_t vf;
8543         uint8_t vf_num;
8544         struct rte_ether_addr address;
8545 };
8546
8547 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8548                 __attribute__((unused)) struct cmdline *cl,
8549                 __attribute__((unused)) void *data)
8550 {
8551         struct cmd_vf_mac_addr_result *res = parsed_result;
8552         int ret = -ENOTSUP;
8553
8554         if (strcmp(res->what, "add") != 0)
8555                 return;
8556
8557 #ifdef RTE_LIBRTE_I40E_PMD
8558         if (ret == -ENOTSUP)
8559                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8560                                                    &res->address);
8561 #endif
8562 #ifdef RTE_LIBRTE_BNXT_PMD
8563         if (ret == -ENOTSUP)
8564                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8565                                                 res->vf_num);
8566 #endif
8567
8568         if(ret < 0)
8569                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8570
8571 }
8572
8573 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8574         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8575                                 mac_addr_cmd,"mac_addr");
8576 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8577         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8578                                 what,"add");
8579 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8580         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8581                                 port,"port");
8582 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8583         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8584                                 port_num, UINT16);
8585 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8586         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8587                                 vf,"vf");
8588 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8589         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8590                                 vf_num, UINT8);
8591 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8592         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8593                                 address);
8594
8595 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8596         .f = cmd_vf_mac_addr_parsed,
8597         .data = (void *)0,
8598         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8599                 "Add MAC address filtering for a VF on port_id",
8600         .tokens = {
8601                 (void *)&cmd_vf_mac_addr_cmd,
8602                 (void *)&cmd_vf_mac_addr_what,
8603                 (void *)&cmd_vf_mac_addr_port,
8604                 (void *)&cmd_vf_mac_addr_portnum,
8605                 (void *)&cmd_vf_mac_addr_vf,
8606                 (void *)&cmd_vf_mac_addr_vfnum,
8607                 (void *)&cmd_vf_mac_addr_addr,
8608                 NULL,
8609         },
8610 };
8611
8612 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8613 struct cmd_vf_rx_vlan_filter {
8614         cmdline_fixed_string_t rx_vlan;
8615         cmdline_fixed_string_t what;
8616         uint16_t vlan_id;
8617         cmdline_fixed_string_t port;
8618         portid_t port_id;
8619         cmdline_fixed_string_t vf;
8620         uint64_t vf_mask;
8621 };
8622
8623 static void
8624 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8625                           __attribute__((unused)) struct cmdline *cl,
8626                           __attribute__((unused)) void *data)
8627 {
8628         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8629         int ret = -ENOTSUP;
8630
8631         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8632
8633 #ifdef RTE_LIBRTE_IXGBE_PMD
8634         if (ret == -ENOTSUP)
8635                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8636                                 res->vlan_id, res->vf_mask, is_add);
8637 #endif
8638 #ifdef RTE_LIBRTE_I40E_PMD
8639         if (ret == -ENOTSUP)
8640                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8641                                 res->vlan_id, res->vf_mask, is_add);
8642 #endif
8643 #ifdef RTE_LIBRTE_BNXT_PMD
8644         if (ret == -ENOTSUP)
8645                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8646                                 res->vlan_id, res->vf_mask, is_add);
8647 #endif
8648
8649         switch (ret) {
8650         case 0:
8651                 break;
8652         case -EINVAL:
8653                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8654                                 res->vlan_id, res->vf_mask);
8655                 break;
8656         case -ENODEV:
8657                 printf("invalid port_id %d\n", res->port_id);
8658                 break;
8659         case -ENOTSUP:
8660                 printf("function not implemented or supported\n");
8661                 break;
8662         default:
8663                 printf("programming error: (%s)\n", strerror(-ret));
8664         }
8665 }
8666
8667 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8668         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8669                                  rx_vlan, "rx_vlan");
8670 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8671         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8672                                  what, "add#rm");
8673 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8674         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8675                               vlan_id, UINT16);
8676 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8677         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8678                                  port, "port");
8679 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8680         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8681                               port_id, UINT16);
8682 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8683         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8684                                  vf, "vf");
8685 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8686         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8687                               vf_mask, UINT64);
8688
8689 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8690         .f = cmd_vf_rx_vlan_filter_parsed,
8691         .data = NULL,
8692         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8693                 "(vf_mask = hexadecimal VF mask)",
8694         .tokens = {
8695                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8696                 (void *)&cmd_vf_rx_vlan_filter_what,
8697                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8698                 (void *)&cmd_vf_rx_vlan_filter_port,
8699                 (void *)&cmd_vf_rx_vlan_filter_portid,
8700                 (void *)&cmd_vf_rx_vlan_filter_vf,
8701                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8702                 NULL,
8703         },
8704 };
8705
8706 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8707 struct cmd_queue_rate_limit_result {
8708         cmdline_fixed_string_t set;
8709         cmdline_fixed_string_t port;
8710         uint16_t port_num;
8711         cmdline_fixed_string_t queue;
8712         uint8_t queue_num;
8713         cmdline_fixed_string_t rate;
8714         uint16_t rate_num;
8715 };
8716
8717 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8718                 __attribute__((unused)) struct cmdline *cl,
8719                 __attribute__((unused)) void *data)
8720 {
8721         struct cmd_queue_rate_limit_result *res = parsed_result;
8722         int ret = 0;
8723
8724         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8725                 && (strcmp(res->queue, "queue") == 0)
8726                 && (strcmp(res->rate, "rate") == 0))
8727                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8728                                         res->rate_num);
8729         if (ret < 0)
8730                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8731
8732 }
8733
8734 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8735         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8736                                 set, "set");
8737 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8738         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8739                                 port, "port");
8740 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8741         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8742                                 port_num, UINT16);
8743 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8744         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8745                                 queue, "queue");
8746 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8747         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8748                                 queue_num, UINT8);
8749 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8750         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8751                                 rate, "rate");
8752 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8753         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8754                                 rate_num, UINT16);
8755
8756 cmdline_parse_inst_t cmd_queue_rate_limit = {
8757         .f = cmd_queue_rate_limit_parsed,
8758         .data = (void *)0,
8759         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8760                 "Set rate limit for a queue on port_id",
8761         .tokens = {
8762                 (void *)&cmd_queue_rate_limit_set,
8763                 (void *)&cmd_queue_rate_limit_port,
8764                 (void *)&cmd_queue_rate_limit_portnum,
8765                 (void *)&cmd_queue_rate_limit_queue,
8766                 (void *)&cmd_queue_rate_limit_queuenum,
8767                 (void *)&cmd_queue_rate_limit_rate,
8768                 (void *)&cmd_queue_rate_limit_ratenum,
8769                 NULL,
8770         },
8771 };
8772
8773 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8774 struct cmd_vf_rate_limit_result {
8775         cmdline_fixed_string_t set;
8776         cmdline_fixed_string_t port;
8777         uint16_t port_num;
8778         cmdline_fixed_string_t vf;
8779         uint8_t vf_num;
8780         cmdline_fixed_string_t rate;
8781         uint16_t rate_num;
8782         cmdline_fixed_string_t q_msk;
8783         uint64_t q_msk_val;
8784 };
8785
8786 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8787                 __attribute__((unused)) struct cmdline *cl,
8788                 __attribute__((unused)) void *data)
8789 {
8790         struct cmd_vf_rate_limit_result *res = parsed_result;
8791         int ret = 0;
8792
8793         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8794                 && (strcmp(res->vf, "vf") == 0)
8795                 && (strcmp(res->rate, "rate") == 0)
8796                 && (strcmp(res->q_msk, "queue_mask") == 0))
8797                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8798                                         res->rate_num, res->q_msk_val);
8799         if (ret < 0)
8800                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8801
8802 }
8803
8804 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8805         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8806                                 set, "set");
8807 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8808         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8809                                 port, "port");
8810 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8811         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8812                                 port_num, UINT16);
8813 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8814         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8815                                 vf, "vf");
8816 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8817         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8818                                 vf_num, UINT8);
8819 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8820         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8821                                 rate, "rate");
8822 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8823         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8824                                 rate_num, UINT16);
8825 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8826         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8827                                 q_msk, "queue_mask");
8828 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8829         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8830                                 q_msk_val, UINT64);
8831
8832 cmdline_parse_inst_t cmd_vf_rate_limit = {
8833         .f = cmd_vf_rate_limit_parsed,
8834         .data = (void *)0,
8835         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8836                 "queue_mask <queue_mask_value>: "
8837                 "Set rate limit for queues of VF on port_id",
8838         .tokens = {
8839                 (void *)&cmd_vf_rate_limit_set,
8840                 (void *)&cmd_vf_rate_limit_port,
8841                 (void *)&cmd_vf_rate_limit_portnum,
8842                 (void *)&cmd_vf_rate_limit_vf,
8843                 (void *)&cmd_vf_rate_limit_vfnum,
8844                 (void *)&cmd_vf_rate_limit_rate,
8845                 (void *)&cmd_vf_rate_limit_ratenum,
8846                 (void *)&cmd_vf_rate_limit_q_msk,
8847                 (void *)&cmd_vf_rate_limit_q_msk_val,
8848                 NULL,
8849         },
8850 };
8851
8852 /* *** ADD TUNNEL FILTER OF A PORT *** */
8853 struct cmd_tunnel_filter_result {
8854         cmdline_fixed_string_t cmd;
8855         cmdline_fixed_string_t what;
8856         portid_t port_id;
8857         struct rte_ether_addr outer_mac;
8858         struct rte_ether_addr inner_mac;
8859         cmdline_ipaddr_t ip_value;
8860         uint16_t inner_vlan;
8861         cmdline_fixed_string_t tunnel_type;
8862         cmdline_fixed_string_t filter_type;
8863         uint32_t tenant_id;
8864         uint16_t queue_num;
8865 };
8866
8867 static void
8868 cmd_tunnel_filter_parsed(void *parsed_result,
8869                           __attribute__((unused)) struct cmdline *cl,
8870                           __attribute__((unused)) void *data)
8871 {
8872         struct cmd_tunnel_filter_result *res = parsed_result;
8873         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8874         int ret = 0;
8875
8876         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8877
8878         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8879         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8880         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8881
8882         if (res->ip_value.family == AF_INET) {
8883                 tunnel_filter_conf.ip_addr.ipv4_addr =
8884                         res->ip_value.addr.ipv4.s_addr;
8885                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8886         } else {
8887                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8888                         &(res->ip_value.addr.ipv6),
8889                         sizeof(struct in6_addr));
8890                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8891         }
8892
8893         if (!strcmp(res->filter_type, "imac-ivlan"))
8894                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8895         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8896                 tunnel_filter_conf.filter_type =
8897                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8898         else if (!strcmp(res->filter_type, "imac-tenid"))
8899                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8900         else if (!strcmp(res->filter_type, "imac"))
8901                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8902         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8903                 tunnel_filter_conf.filter_type =
8904                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8905         else if (!strcmp(res->filter_type, "oip"))
8906                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8907         else if (!strcmp(res->filter_type, "iip"))
8908                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8909         else {
8910                 printf("The filter type is not supported");
8911                 return;
8912         }
8913
8914         if (!strcmp(res->tunnel_type, "vxlan"))
8915                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8916         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8917                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8918         else if (!strcmp(res->tunnel_type, "nvgre"))
8919                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8920         else if (!strcmp(res->tunnel_type, "ipingre"))
8921                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8922         else {
8923                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8924                 return;
8925         }
8926
8927         tunnel_filter_conf.tenant_id = res->tenant_id;
8928         tunnel_filter_conf.queue_id = res->queue_num;
8929         if (!strcmp(res->what, "add"))
8930                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8931                                         RTE_ETH_FILTER_TUNNEL,
8932                                         RTE_ETH_FILTER_ADD,
8933                                         &tunnel_filter_conf);
8934         else
8935                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8936                                         RTE_ETH_FILTER_TUNNEL,
8937                                         RTE_ETH_FILTER_DELETE,
8938                                         &tunnel_filter_conf);
8939         if (ret < 0)
8940                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8941                                 strerror(-ret));
8942
8943 }
8944 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8945         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8946         cmd, "tunnel_filter");
8947 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8948         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8949         what, "add#rm");
8950 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8951         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8952         port_id, UINT16);
8953 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8954         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8955         outer_mac);
8956 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8957         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8958         inner_mac);
8959 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8960         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8961         inner_vlan, UINT16);
8962 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8963         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8964         ip_value);
8965 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8966         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8967         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8968
8969 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8970         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8971         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8972                 "imac#omac-imac-tenid");
8973 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8974         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8975         tenant_id, UINT32);
8976 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8977         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8978         queue_num, UINT16);
8979
8980 cmdline_parse_inst_t cmd_tunnel_filter = {
8981         .f = cmd_tunnel_filter_parsed,
8982         .data = (void *)0,
8983         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8984                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8985                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8986                 "<queue_id>: Add/Rm tunnel filter of a port",
8987         .tokens = {
8988                 (void *)&cmd_tunnel_filter_cmd,
8989                 (void *)&cmd_tunnel_filter_what,
8990                 (void *)&cmd_tunnel_filter_port_id,
8991                 (void *)&cmd_tunnel_filter_outer_mac,
8992                 (void *)&cmd_tunnel_filter_inner_mac,
8993                 (void *)&cmd_tunnel_filter_ip_value,
8994                 (void *)&cmd_tunnel_filter_innner_vlan,
8995                 (void *)&cmd_tunnel_filter_tunnel_type,
8996                 (void *)&cmd_tunnel_filter_filter_type,
8997                 (void *)&cmd_tunnel_filter_tenant_id,
8998                 (void *)&cmd_tunnel_filter_queue_num,
8999                 NULL,
9000         },
9001 };
9002
9003 /* *** CONFIGURE TUNNEL UDP PORT *** */
9004 struct cmd_tunnel_udp_config {
9005         cmdline_fixed_string_t cmd;
9006         cmdline_fixed_string_t what;
9007         uint16_t udp_port;
9008         portid_t port_id;
9009 };
9010
9011 static void
9012 cmd_tunnel_udp_config_parsed(void *parsed_result,
9013                           __attribute__((unused)) struct cmdline *cl,
9014                           __attribute__((unused)) void *data)
9015 {
9016         struct cmd_tunnel_udp_config *res = parsed_result;
9017         struct rte_eth_udp_tunnel tunnel_udp;
9018         int ret;
9019
9020         tunnel_udp.udp_port = res->udp_port;
9021
9022         if (!strcmp(res->cmd, "rx_vxlan_port"))
9023                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9024
9025         if (!strcmp(res->what, "add"))
9026                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9027                                                       &tunnel_udp);
9028         else
9029                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9030                                                          &tunnel_udp);
9031
9032         if (ret < 0)
9033                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9034 }
9035
9036 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9037         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9038                                 cmd, "rx_vxlan_port");
9039 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9040         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9041                                 what, "add#rm");
9042 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9043         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9044                                 udp_port, UINT16);
9045 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9046         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9047                                 port_id, UINT16);
9048
9049 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9050         .f = cmd_tunnel_udp_config_parsed,
9051         .data = (void *)0,
9052         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9053                 "Add/Remove a tunneling UDP port filter",
9054         .tokens = {
9055                 (void *)&cmd_tunnel_udp_config_cmd,
9056                 (void *)&cmd_tunnel_udp_config_what,
9057                 (void *)&cmd_tunnel_udp_config_udp_port,
9058                 (void *)&cmd_tunnel_udp_config_port_id,
9059                 NULL,
9060         },
9061 };
9062
9063 struct cmd_config_tunnel_udp_port {
9064         cmdline_fixed_string_t port;
9065         cmdline_fixed_string_t config;
9066         portid_t port_id;
9067         cmdline_fixed_string_t udp_tunnel_port;
9068         cmdline_fixed_string_t action;
9069         cmdline_fixed_string_t tunnel_type;
9070         uint16_t udp_port;
9071 };
9072
9073 static void
9074 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9075                                __attribute__((unused)) struct cmdline *cl,
9076                                __attribute__((unused)) void *data)
9077 {
9078         struct cmd_config_tunnel_udp_port *res = parsed_result;
9079         struct rte_eth_udp_tunnel tunnel_udp;
9080         int ret = 0;
9081
9082         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9083                 return;
9084
9085         tunnel_udp.udp_port = res->udp_port;
9086
9087         if (!strcmp(res->tunnel_type, "vxlan")) {
9088                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9089         } else if (!strcmp(res->tunnel_type, "geneve")) {
9090                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9091         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9092                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9093         } else {
9094                 printf("Invalid tunnel type\n");
9095                 return;
9096         }
9097
9098         if (!strcmp(res->action, "add"))
9099                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9100                                                       &tunnel_udp);
9101         else
9102                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9103                                                          &tunnel_udp);
9104
9105         if (ret < 0)
9106                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9107 }
9108
9109 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9110         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9111                                  "port");
9112 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9113         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9114                                  "config");
9115 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9116         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9117                               UINT16);
9118 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9119         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9120                                  udp_tunnel_port,
9121                                  "udp_tunnel_port");
9122 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9123         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9124                                  "add#rm");
9125 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9126         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9127                                  "vxlan#geneve#vxlan-gpe");
9128 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9129         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9130                               UINT16);
9131
9132 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9133         .f = cmd_cfg_tunnel_udp_port_parsed,
9134         .data = NULL,
9135         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9136         .tokens = {
9137                 (void *)&cmd_config_tunnel_udp_port_port,
9138                 (void *)&cmd_config_tunnel_udp_port_config,
9139                 (void *)&cmd_config_tunnel_udp_port_port_id,
9140                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9141                 (void *)&cmd_config_tunnel_udp_port_action,
9142                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9143                 (void *)&cmd_config_tunnel_udp_port_value,
9144                 NULL,
9145         },
9146 };
9147
9148 /* *** GLOBAL CONFIG *** */
9149 struct cmd_global_config_result {
9150         cmdline_fixed_string_t cmd;
9151         portid_t port_id;
9152         cmdline_fixed_string_t cfg_type;
9153         uint8_t len;
9154 };
9155
9156 static void
9157 cmd_global_config_parsed(void *parsed_result,
9158                          __attribute__((unused)) struct cmdline *cl,
9159                          __attribute__((unused)) void *data)
9160 {
9161         struct cmd_global_config_result *res = parsed_result;
9162         struct rte_eth_global_cfg conf;
9163         int ret;
9164
9165         memset(&conf, 0, sizeof(conf));
9166         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9167         conf.cfg.gre_key_len = res->len;
9168         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9169                                       RTE_ETH_FILTER_SET, &conf);
9170         if (ret != 0)
9171                 printf("Global config error\n");
9172 }
9173
9174 cmdline_parse_token_string_t cmd_global_config_cmd =
9175         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9176                 "global_config");
9177 cmdline_parse_token_num_t cmd_global_config_port_id =
9178         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9179                                UINT16);
9180 cmdline_parse_token_string_t cmd_global_config_type =
9181         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9182                 cfg_type, "gre-key-len");
9183 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9184         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9185                 len, UINT8);
9186
9187 cmdline_parse_inst_t cmd_global_config = {
9188         .f = cmd_global_config_parsed,
9189         .data = (void *)NULL,
9190         .help_str = "global_config <port_id> gre-key-len <key_len>",
9191         .tokens = {
9192                 (void *)&cmd_global_config_cmd,
9193                 (void *)&cmd_global_config_port_id,
9194                 (void *)&cmd_global_config_type,
9195                 (void *)&cmd_global_config_gre_key_len,
9196                 NULL,
9197         },
9198 };
9199
9200 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9201 struct cmd_set_mirror_mask_result {
9202         cmdline_fixed_string_t set;
9203         cmdline_fixed_string_t port;
9204         portid_t port_id;
9205         cmdline_fixed_string_t mirror;
9206         uint8_t rule_id;
9207         cmdline_fixed_string_t what;
9208         cmdline_fixed_string_t value;
9209         cmdline_fixed_string_t dstpool;
9210         uint8_t dstpool_id;
9211         cmdline_fixed_string_t on;
9212 };
9213
9214 cmdline_parse_token_string_t cmd_mirror_mask_set =
9215         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9216                                 set, "set");
9217 cmdline_parse_token_string_t cmd_mirror_mask_port =
9218         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9219                                 port, "port");
9220 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9221         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9222                                 port_id, UINT16);
9223 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9224         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9225                                 mirror, "mirror-rule");
9226 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9227         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9228                                 rule_id, UINT8);
9229 cmdline_parse_token_string_t cmd_mirror_mask_what =
9230         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9231                                 what, "pool-mirror-up#pool-mirror-down"
9232                                       "#vlan-mirror");
9233 cmdline_parse_token_string_t cmd_mirror_mask_value =
9234         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9235                                 value, NULL);
9236 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9237         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9238                                 dstpool, "dst-pool");
9239 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9240         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9241                                 dstpool_id, UINT8);
9242 cmdline_parse_token_string_t cmd_mirror_mask_on =
9243         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9244                                 on, "on#off");
9245
9246 static void
9247 cmd_set_mirror_mask_parsed(void *parsed_result,
9248                        __attribute__((unused)) struct cmdline *cl,
9249                        __attribute__((unused)) void *data)
9250 {
9251         int ret,nb_item,i;
9252         struct cmd_set_mirror_mask_result *res = parsed_result;
9253         struct rte_eth_mirror_conf mr_conf;
9254
9255         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9256
9257         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9258
9259         mr_conf.dst_pool = res->dstpool_id;
9260
9261         if (!strcmp(res->what, "pool-mirror-up")) {
9262                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9263                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9264         } else if (!strcmp(res->what, "pool-mirror-down")) {
9265                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9266                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9267         } else if (!strcmp(res->what, "vlan-mirror")) {
9268                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9269                 nb_item = parse_item_list(res->value, "vlan",
9270                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9271                 if (nb_item <= 0)
9272                         return;
9273
9274                 for (i = 0; i < nb_item; i++) {
9275                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9276                                 printf("Invalid vlan_id: must be < 4096\n");
9277                                 return;
9278                         }
9279
9280                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9281                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9282                 }
9283         }
9284
9285         if (!strcmp(res->on, "on"))
9286                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9287                                                 res->rule_id, 1);
9288         else
9289                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9290                                                 res->rule_id, 0);
9291         if (ret < 0)
9292                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9293 }
9294
9295 cmdline_parse_inst_t cmd_set_mirror_mask = {
9296                 .f = cmd_set_mirror_mask_parsed,
9297                 .data = NULL,
9298                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9299                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9300                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9301                 .tokens = {
9302                         (void *)&cmd_mirror_mask_set,
9303                         (void *)&cmd_mirror_mask_port,
9304                         (void *)&cmd_mirror_mask_portid,
9305                         (void *)&cmd_mirror_mask_mirror,
9306                         (void *)&cmd_mirror_mask_ruleid,
9307                         (void *)&cmd_mirror_mask_what,
9308                         (void *)&cmd_mirror_mask_value,
9309                         (void *)&cmd_mirror_mask_dstpool,
9310                         (void *)&cmd_mirror_mask_poolid,
9311                         (void *)&cmd_mirror_mask_on,
9312                         NULL,
9313                 },
9314 };
9315
9316 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9317 struct cmd_set_mirror_link_result {
9318         cmdline_fixed_string_t set;
9319         cmdline_fixed_string_t port;
9320         portid_t port_id;
9321         cmdline_fixed_string_t mirror;
9322         uint8_t rule_id;
9323         cmdline_fixed_string_t what;
9324         cmdline_fixed_string_t dstpool;
9325         uint8_t dstpool_id;
9326         cmdline_fixed_string_t on;
9327 };
9328
9329 cmdline_parse_token_string_t cmd_mirror_link_set =
9330         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9331                                  set, "set");
9332 cmdline_parse_token_string_t cmd_mirror_link_port =
9333         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9334                                 port, "port");
9335 cmdline_parse_token_num_t cmd_mirror_link_portid =
9336         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9337                                 port_id, UINT16);
9338 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9339         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9340                                 mirror, "mirror-rule");
9341 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9342         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9343                             rule_id, UINT8);
9344 cmdline_parse_token_string_t cmd_mirror_link_what =
9345         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9346                                 what, "uplink-mirror#downlink-mirror");
9347 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9348         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9349                                 dstpool, "dst-pool");
9350 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9351         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9352                                 dstpool_id, UINT8);
9353 cmdline_parse_token_string_t cmd_mirror_link_on =
9354         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9355                                 on, "on#off");
9356
9357 static void
9358 cmd_set_mirror_link_parsed(void *parsed_result,
9359                        __attribute__((unused)) struct cmdline *cl,
9360                        __attribute__((unused)) void *data)
9361 {
9362         int ret;
9363         struct cmd_set_mirror_link_result *res = parsed_result;
9364         struct rte_eth_mirror_conf mr_conf;
9365
9366         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9367         if (!strcmp(res->what, "uplink-mirror"))
9368                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9369         else
9370                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9371
9372         mr_conf.dst_pool = res->dstpool_id;
9373
9374         if (!strcmp(res->on, "on"))
9375                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9376                                                 res->rule_id, 1);
9377         else
9378                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9379                                                 res->rule_id, 0);
9380
9381         /* check the return value and print it if is < 0 */
9382         if (ret < 0)
9383                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9384
9385 }
9386
9387 cmdline_parse_inst_t cmd_set_mirror_link = {
9388                 .f = cmd_set_mirror_link_parsed,
9389                 .data = NULL,
9390                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9391                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9392                 .tokens = {
9393                         (void *)&cmd_mirror_link_set,
9394                         (void *)&cmd_mirror_link_port,
9395                         (void *)&cmd_mirror_link_portid,
9396                         (void *)&cmd_mirror_link_mirror,
9397                         (void *)&cmd_mirror_link_ruleid,
9398                         (void *)&cmd_mirror_link_what,
9399                         (void *)&cmd_mirror_link_dstpool,
9400                         (void *)&cmd_mirror_link_poolid,
9401                         (void *)&cmd_mirror_link_on,
9402                         NULL,
9403                 },
9404 };
9405
9406 /* *** RESET VM MIRROR RULE *** */
9407 struct cmd_rm_mirror_rule_result {
9408         cmdline_fixed_string_t reset;
9409         cmdline_fixed_string_t port;
9410         portid_t port_id;
9411         cmdline_fixed_string_t mirror;
9412         uint8_t rule_id;
9413 };
9414
9415 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9416         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9417                                  reset, "reset");
9418 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9419         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9420                                 port, "port");
9421 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9422         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9423                                 port_id, UINT16);
9424 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9425         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9426                                 mirror, "mirror-rule");
9427 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9428         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9429                                 rule_id, UINT8);
9430
9431 static void
9432 cmd_reset_mirror_rule_parsed(void *parsed_result,
9433                        __attribute__((unused)) struct cmdline *cl,
9434                        __attribute__((unused)) void *data)
9435 {
9436         int ret;
9437         struct cmd_set_mirror_link_result *res = parsed_result;
9438         /* check rule_id */
9439         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9440         if(ret < 0)
9441                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9442 }
9443
9444 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9445                 .f = cmd_reset_mirror_rule_parsed,
9446                 .data = NULL,
9447                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9448                 .tokens = {
9449                         (void *)&cmd_rm_mirror_rule_reset,
9450                         (void *)&cmd_rm_mirror_rule_port,
9451                         (void *)&cmd_rm_mirror_rule_portid,
9452                         (void *)&cmd_rm_mirror_rule_mirror,
9453                         (void *)&cmd_rm_mirror_rule_ruleid,
9454                         NULL,
9455                 },
9456 };
9457
9458 /* ******************************************************************************** */
9459
9460 struct cmd_dump_result {
9461         cmdline_fixed_string_t dump;
9462 };
9463
9464 static void
9465 dump_struct_sizes(void)
9466 {
9467 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9468         DUMP_SIZE(struct rte_mbuf);
9469         DUMP_SIZE(struct rte_mempool);
9470         DUMP_SIZE(struct rte_ring);
9471 #undef DUMP_SIZE
9472 }
9473
9474 static void cmd_dump_parsed(void *parsed_result,
9475                             __attribute__((unused)) struct cmdline *cl,
9476                             __attribute__((unused)) void *data)
9477 {
9478         struct cmd_dump_result *res = parsed_result;
9479
9480         if (!strcmp(res->dump, "dump_physmem"))
9481                 rte_dump_physmem_layout(stdout);
9482         else if (!strcmp(res->dump, "dump_memzone"))
9483                 rte_memzone_dump(stdout);
9484         else if (!strcmp(res->dump, "dump_struct_sizes"))
9485                 dump_struct_sizes();
9486         else if (!strcmp(res->dump, "dump_ring"))
9487                 rte_ring_list_dump(stdout);
9488         else if (!strcmp(res->dump, "dump_mempool"))
9489                 rte_mempool_list_dump(stdout);
9490         else if (!strcmp(res->dump, "dump_devargs"))
9491                 rte_devargs_dump(stdout);
9492         else if (!strcmp(res->dump, "dump_log_types"))
9493                 rte_log_dump(stdout);
9494 }
9495
9496 cmdline_parse_token_string_t cmd_dump_dump =
9497         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9498                 "dump_physmem#"
9499                 "dump_memzone#"
9500                 "dump_struct_sizes#"
9501                 "dump_ring#"
9502                 "dump_mempool#"
9503                 "dump_devargs#"
9504                 "dump_log_types");
9505
9506 cmdline_parse_inst_t cmd_dump = {
9507         .f = cmd_dump_parsed,  /* function to call */
9508         .data = NULL,      /* 2nd arg of func */
9509         .help_str = "Dump status",
9510         .tokens = {        /* token list, NULL terminated */
9511                 (void *)&cmd_dump_dump,
9512                 NULL,
9513         },
9514 };
9515
9516 /* ******************************************************************************** */
9517
9518 struct cmd_dump_one_result {
9519         cmdline_fixed_string_t dump;
9520         cmdline_fixed_string_t name;
9521 };
9522
9523 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9524                                 __attribute__((unused)) void *data)
9525 {
9526         struct cmd_dump_one_result *res = parsed_result;
9527
9528         if (!strcmp(res->dump, "dump_ring")) {
9529                 struct rte_ring *r;
9530                 r = rte_ring_lookup(res->name);
9531                 if (r == NULL) {
9532                         cmdline_printf(cl, "Cannot find ring\n");
9533                         return;
9534                 }
9535                 rte_ring_dump(stdout, r);
9536         } else if (!strcmp(res->dump, "dump_mempool")) {
9537                 struct rte_mempool *mp;
9538                 mp = rte_mempool_lookup(res->name);
9539                 if (mp == NULL) {
9540                         cmdline_printf(cl, "Cannot find mempool\n");
9541                         return;
9542                 }
9543                 rte_mempool_dump(stdout, mp);
9544         }
9545 }
9546
9547 cmdline_parse_token_string_t cmd_dump_one_dump =
9548         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9549                                  "dump_ring#dump_mempool");
9550
9551 cmdline_parse_token_string_t cmd_dump_one_name =
9552         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9553
9554 cmdline_parse_inst_t cmd_dump_one = {
9555         .f = cmd_dump_one_parsed,  /* function to call */
9556         .data = NULL,      /* 2nd arg of func */
9557         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9558         .tokens = {        /* token list, NULL terminated */
9559                 (void *)&cmd_dump_one_dump,
9560                 (void *)&cmd_dump_one_name,
9561                 NULL,
9562         },
9563 };
9564
9565 /* *** Add/Del syn filter *** */
9566 struct cmd_syn_filter_result {
9567         cmdline_fixed_string_t filter;
9568         portid_t port_id;
9569         cmdline_fixed_string_t ops;
9570         cmdline_fixed_string_t priority;
9571         cmdline_fixed_string_t high;
9572         cmdline_fixed_string_t queue;
9573         uint16_t queue_id;
9574 };
9575
9576 static void
9577 cmd_syn_filter_parsed(void *parsed_result,
9578                         __attribute__((unused)) struct cmdline *cl,
9579                         __attribute__((unused)) void *data)
9580 {
9581         struct cmd_syn_filter_result *res = parsed_result;
9582         struct rte_eth_syn_filter syn_filter;
9583         int ret = 0;
9584
9585         ret = rte_eth_dev_filter_supported(res->port_id,
9586                                         RTE_ETH_FILTER_SYN);
9587         if (ret < 0) {
9588                 printf("syn filter is not supported on port %u.\n",
9589                                 res->port_id);
9590                 return;
9591         }
9592
9593         memset(&syn_filter, 0, sizeof(syn_filter));
9594
9595         if (!strcmp(res->ops, "add")) {
9596                 if (!strcmp(res->high, "high"))
9597                         syn_filter.hig_pri = 1;
9598                 else
9599                         syn_filter.hig_pri = 0;
9600
9601                 syn_filter.queue = res->queue_id;
9602                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9603                                                 RTE_ETH_FILTER_SYN,
9604                                                 RTE_ETH_FILTER_ADD,
9605                                                 &syn_filter);
9606         } else
9607                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9608                                                 RTE_ETH_FILTER_SYN,
9609                                                 RTE_ETH_FILTER_DELETE,
9610                                                 &syn_filter);
9611
9612         if (ret < 0)
9613                 printf("syn filter programming error: (%s)\n",
9614                                 strerror(-ret));
9615 }
9616
9617 cmdline_parse_token_string_t cmd_syn_filter_filter =
9618         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9619         filter, "syn_filter");
9620 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9621         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9622         port_id, UINT16);
9623 cmdline_parse_token_string_t cmd_syn_filter_ops =
9624         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9625         ops, "add#del");
9626 cmdline_parse_token_string_t cmd_syn_filter_priority =
9627         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9628                                 priority, "priority");
9629 cmdline_parse_token_string_t cmd_syn_filter_high =
9630         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9631                                 high, "high#low");
9632 cmdline_parse_token_string_t cmd_syn_filter_queue =
9633         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9634                                 queue, "queue");
9635 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9636         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9637                                 queue_id, UINT16);
9638
9639 cmdline_parse_inst_t cmd_syn_filter = {
9640         .f = cmd_syn_filter_parsed,
9641         .data = NULL,
9642         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9643                 "<queue_id>: Add/Delete syn filter",
9644         .tokens = {
9645                 (void *)&cmd_syn_filter_filter,
9646                 (void *)&cmd_syn_filter_port_id,
9647                 (void *)&cmd_syn_filter_ops,
9648                 (void *)&cmd_syn_filter_priority,
9649                 (void *)&cmd_syn_filter_high,
9650                 (void *)&cmd_syn_filter_queue,
9651                 (void *)&cmd_syn_filter_queue_id,
9652                 NULL,
9653         },
9654 };
9655
9656 /* *** queue region set *** */
9657 struct cmd_queue_region_result {
9658         cmdline_fixed_string_t set;
9659         cmdline_fixed_string_t port;
9660         portid_t port_id;
9661         cmdline_fixed_string_t cmd;
9662         cmdline_fixed_string_t region;
9663         uint8_t  region_id;
9664         cmdline_fixed_string_t queue_start_index;
9665         uint8_t  queue_id;
9666         cmdline_fixed_string_t queue_num;
9667         uint8_t  queue_num_value;
9668 };
9669
9670 static void
9671 cmd_queue_region_parsed(void *parsed_result,
9672                         __attribute__((unused)) struct cmdline *cl,
9673                         __attribute__((unused)) void *data)
9674 {
9675         struct cmd_queue_region_result *res = parsed_result;
9676         int ret = -ENOTSUP;
9677 #ifdef RTE_LIBRTE_I40E_PMD
9678         struct rte_pmd_i40e_queue_region_conf region_conf;
9679         enum rte_pmd_i40e_queue_region_op op_type;
9680 #endif
9681
9682         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9683                 return;
9684
9685 #ifdef RTE_LIBRTE_I40E_PMD
9686         memset(&region_conf, 0, sizeof(region_conf));
9687         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9688         region_conf.region_id = res->region_id;
9689         region_conf.queue_num = res->queue_num_value;
9690         region_conf.queue_start_index = res->queue_id;
9691
9692         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9693                                 op_type, &region_conf);
9694 #endif
9695
9696         switch (ret) {
9697         case 0:
9698                 break;
9699         case -ENOTSUP:
9700                 printf("function not implemented or supported\n");
9701                 break;
9702         default:
9703                 printf("queue region config error: (%s)\n", strerror(-ret));
9704         }
9705 }
9706
9707 cmdline_parse_token_string_t cmd_queue_region_set =
9708 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9709                 set, "set");
9710 cmdline_parse_token_string_t cmd_queue_region_port =
9711         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9712 cmdline_parse_token_num_t cmd_queue_region_port_id =
9713         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9714                                 port_id, UINT16);
9715 cmdline_parse_token_string_t cmd_queue_region_cmd =
9716         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9717                                  cmd, "queue-region");
9718 cmdline_parse_token_string_t cmd_queue_region_id =
9719         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9720                                 region, "region_id");
9721 cmdline_parse_token_num_t cmd_queue_region_index =
9722         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9723                                 region_id, UINT8);
9724 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9725         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9726                                 queue_start_index, "queue_start_index");
9727 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9728         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9729                                 queue_id, UINT8);
9730 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9731         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9732                                 queue_num, "queue_num");
9733 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9734         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9735                                 queue_num_value, UINT8);
9736
9737 cmdline_parse_inst_t cmd_queue_region = {
9738         .f = cmd_queue_region_parsed,
9739         .data = NULL,
9740         .help_str = "set port <port_id> queue-region region_id <value> "
9741                 "queue_start_index <value> queue_num <value>: Set a queue region",
9742         .tokens = {
9743                 (void *)&cmd_queue_region_set,
9744                 (void *)&cmd_queue_region_port,
9745                 (void *)&cmd_queue_region_port_id,
9746                 (void *)&cmd_queue_region_cmd,
9747                 (void *)&cmd_queue_region_id,
9748                 (void *)&cmd_queue_region_index,
9749                 (void *)&cmd_queue_region_queue_start_index,
9750                 (void *)&cmd_queue_region_queue_id,
9751                 (void *)&cmd_queue_region_queue_num,
9752                 (void *)&cmd_queue_region_queue_num_value,
9753                 NULL,
9754         },
9755 };
9756
9757 /* *** queue region and flowtype set *** */
9758 struct cmd_region_flowtype_result {
9759         cmdline_fixed_string_t set;
9760         cmdline_fixed_string_t port;
9761         portid_t port_id;
9762         cmdline_fixed_string_t cmd;
9763         cmdline_fixed_string_t region;
9764         uint8_t  region_id;
9765         cmdline_fixed_string_t flowtype;
9766         uint8_t  flowtype_id;
9767 };
9768
9769 static void
9770 cmd_region_flowtype_parsed(void *parsed_result,
9771                         __attribute__((unused)) struct cmdline *cl,
9772                         __attribute__((unused)) void *data)
9773 {
9774         struct cmd_region_flowtype_result *res = parsed_result;
9775         int ret = -ENOTSUP;
9776 #ifdef RTE_LIBRTE_I40E_PMD
9777         struct rte_pmd_i40e_queue_region_conf region_conf;
9778         enum rte_pmd_i40e_queue_region_op op_type;
9779 #endif
9780
9781         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9782                 return;
9783
9784 #ifdef RTE_LIBRTE_I40E_PMD
9785         memset(&region_conf, 0, sizeof(region_conf));
9786
9787         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9788         region_conf.region_id = res->region_id;
9789         region_conf.hw_flowtype = res->flowtype_id;
9790
9791         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9792                         op_type, &region_conf);
9793 #endif
9794
9795         switch (ret) {
9796         case 0:
9797                 break;
9798         case -ENOTSUP:
9799                 printf("function not implemented or supported\n");
9800                 break;
9801         default:
9802                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9803         }
9804 }
9805
9806 cmdline_parse_token_string_t cmd_region_flowtype_set =
9807 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9808                                 set, "set");
9809 cmdline_parse_token_string_t cmd_region_flowtype_port =
9810         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9811                                 port, "port");
9812 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9813         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9814                                 port_id, UINT16);
9815 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9816         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9817                                 cmd, "queue-region");
9818 cmdline_parse_token_string_t cmd_region_flowtype_index =
9819         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9820                                 region, "region_id");
9821 cmdline_parse_token_num_t cmd_region_flowtype_id =
9822         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9823                                 region_id, UINT8);
9824 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9825         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9826                                 flowtype, "flowtype");
9827 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9828         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9829                                 flowtype_id, UINT8);
9830 cmdline_parse_inst_t cmd_region_flowtype = {
9831         .f = cmd_region_flowtype_parsed,
9832         .data = NULL,
9833         .help_str = "set port <port_id> queue-region region_id <value> "
9834                 "flowtype <value>: Set a flowtype region index",
9835         .tokens = {
9836                 (void *)&cmd_region_flowtype_set,
9837                 (void *)&cmd_region_flowtype_port,
9838                 (void *)&cmd_region_flowtype_port_index,
9839                 (void *)&cmd_region_flowtype_cmd,
9840                 (void *)&cmd_region_flowtype_index,
9841                 (void *)&cmd_region_flowtype_id,
9842                 (void *)&cmd_region_flowtype_flow_index,
9843                 (void *)&cmd_region_flowtype_flow_id,
9844                 NULL,
9845         },
9846 };
9847
9848 /* *** User Priority (UP) to queue region (region_id) set *** */
9849 struct cmd_user_priority_region_result {
9850         cmdline_fixed_string_t set;
9851         cmdline_fixed_string_t port;
9852         portid_t port_id;
9853         cmdline_fixed_string_t cmd;
9854         cmdline_fixed_string_t user_priority;
9855         uint8_t  user_priority_id;
9856         cmdline_fixed_string_t region;
9857         uint8_t  region_id;
9858 };
9859
9860 static void
9861 cmd_user_priority_region_parsed(void *parsed_result,
9862                         __attribute__((unused)) struct cmdline *cl,
9863                         __attribute__((unused)) void *data)
9864 {
9865         struct cmd_user_priority_region_result *res = parsed_result;
9866         int ret = -ENOTSUP;
9867 #ifdef RTE_LIBRTE_I40E_PMD
9868         struct rte_pmd_i40e_queue_region_conf region_conf;
9869         enum rte_pmd_i40e_queue_region_op op_type;
9870 #endif
9871
9872         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9873                 return;
9874
9875 #ifdef RTE_LIBRTE_I40E_PMD
9876         memset(&region_conf, 0, sizeof(region_conf));
9877         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9878         region_conf.user_priority = res->user_priority_id;
9879         region_conf.region_id = res->region_id;
9880
9881         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9882                                 op_type, &region_conf);
9883 #endif
9884
9885         switch (ret) {
9886         case 0:
9887                 break;
9888         case -ENOTSUP:
9889                 printf("function not implemented or supported\n");
9890                 break;
9891         default:
9892                 printf("user_priority region config error: (%s)\n",
9893                                 strerror(-ret));
9894         }
9895 }
9896
9897 cmdline_parse_token_string_t cmd_user_priority_region_set =
9898         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9899                                 set, "set");
9900 cmdline_parse_token_string_t cmd_user_priority_region_port =
9901         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9902                                 port, "port");
9903 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9904         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9905                                 port_id, UINT16);
9906 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9907         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9908                                 cmd, "queue-region");
9909 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9910         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9911                                 user_priority, "UP");
9912 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9913         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9914                                 user_priority_id, UINT8);
9915 cmdline_parse_token_string_t cmd_user_priority_region_region =
9916         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9917                                 region, "region_id");
9918 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9919         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9920                                 region_id, UINT8);
9921
9922 cmdline_parse_inst_t cmd_user_priority_region = {
9923         .f = cmd_user_priority_region_parsed,
9924         .data = NULL,
9925         .help_str = "set port <port_id> queue-region UP <value> "
9926                 "region_id <value>: Set the mapping of User Priority (UP) "
9927                 "to queue region (region_id) ",
9928         .tokens = {
9929                 (void *)&cmd_user_priority_region_set,
9930                 (void *)&cmd_user_priority_region_port,
9931                 (void *)&cmd_user_priority_region_port_index,
9932                 (void *)&cmd_user_priority_region_cmd,
9933                 (void *)&cmd_user_priority_region_UP,
9934                 (void *)&cmd_user_priority_region_UP_id,
9935                 (void *)&cmd_user_priority_region_region,
9936                 (void *)&cmd_user_priority_region_region_id,
9937                 NULL,
9938         },
9939 };
9940
9941 /* *** flush all queue region related configuration *** */
9942 struct cmd_flush_queue_region_result {
9943         cmdline_fixed_string_t set;
9944         cmdline_fixed_string_t port;
9945         portid_t port_id;
9946         cmdline_fixed_string_t cmd;
9947         cmdline_fixed_string_t flush;
9948         cmdline_fixed_string_t what;
9949 };
9950
9951 static void
9952 cmd_flush_queue_region_parsed(void *parsed_result,
9953                         __attribute__((unused)) struct cmdline *cl,
9954                         __attribute__((unused)) void *data)
9955 {
9956         struct cmd_flush_queue_region_result *res = parsed_result;
9957         int ret = -ENOTSUP;
9958 #ifdef RTE_LIBRTE_I40E_PMD
9959         struct rte_pmd_i40e_queue_region_conf region_conf;
9960         enum rte_pmd_i40e_queue_region_op op_type;
9961 #endif
9962
9963         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9964                 return;
9965
9966 #ifdef RTE_LIBRTE_I40E_PMD
9967         memset(&region_conf, 0, sizeof(region_conf));
9968
9969         if (strcmp(res->what, "on") == 0)
9970                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9971         else
9972                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9973
9974         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9975                                 op_type, &region_conf);
9976 #endif
9977
9978         switch (ret) {
9979         case 0:
9980                 break;
9981         case -ENOTSUP:
9982                 printf("function not implemented or supported\n");
9983                 break;
9984         default:
9985                 printf("queue region config flush error: (%s)\n",
9986                                 strerror(-ret));
9987         }
9988 }
9989
9990 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9991         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9992                                 set, "set");
9993 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9994         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9995                                 port, "port");
9996 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9997         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9998                                 port_id, UINT16);
9999 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10000         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10001                                 cmd, "queue-region");
10002 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10003         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10004                                 flush, "flush");
10005 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10006         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10007                                 what, "on#off");
10008
10009 cmdline_parse_inst_t cmd_flush_queue_region = {
10010         .f = cmd_flush_queue_region_parsed,
10011         .data = NULL,
10012         .help_str = "set port <port_id> queue-region flush on|off"
10013                 ": flush all queue region related configuration",
10014         .tokens = {
10015                 (void *)&cmd_flush_queue_region_set,
10016                 (void *)&cmd_flush_queue_region_port,
10017                 (void *)&cmd_flush_queue_region_port_index,
10018                 (void *)&cmd_flush_queue_region_cmd,
10019                 (void *)&cmd_flush_queue_region_flush,
10020                 (void *)&cmd_flush_queue_region_what,
10021                 NULL,
10022         },
10023 };
10024
10025 /* *** get all queue region related configuration info *** */
10026 struct cmd_show_queue_region_info {
10027         cmdline_fixed_string_t show;
10028         cmdline_fixed_string_t port;
10029         portid_t port_id;
10030         cmdline_fixed_string_t cmd;
10031 };
10032
10033 static void
10034 cmd_show_queue_region_info_parsed(void *parsed_result,
10035                         __attribute__((unused)) struct cmdline *cl,
10036                         __attribute__((unused)) void *data)
10037 {
10038         struct cmd_show_queue_region_info *res = parsed_result;
10039         int ret = -ENOTSUP;
10040 #ifdef RTE_LIBRTE_I40E_PMD
10041         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10042         enum rte_pmd_i40e_queue_region_op op_type;
10043 #endif
10044
10045         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10046                 return;
10047
10048 #ifdef RTE_LIBRTE_I40E_PMD
10049         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10050
10051         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10052
10053         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10054                                         op_type, &rte_pmd_regions);
10055
10056         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10057 #endif
10058
10059         switch (ret) {
10060         case 0:
10061                 break;
10062         case -ENOTSUP:
10063                 printf("function not implemented or supported\n");
10064                 break;
10065         default:
10066                 printf("queue region config info show error: (%s)\n",
10067                                 strerror(-ret));
10068         }
10069 }
10070
10071 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10072 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10073                                 show, "show");
10074 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10075         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10076                                 port, "port");
10077 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10078         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10079                                 port_id, UINT16);
10080 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10081         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10082                                 cmd, "queue-region");
10083
10084 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10085         .f = cmd_show_queue_region_info_parsed,
10086         .data = NULL,
10087         .help_str = "show port <port_id> queue-region"
10088                 ": show all queue region related configuration info",
10089         .tokens = {
10090                 (void *)&cmd_show_queue_region_info_get,
10091                 (void *)&cmd_show_queue_region_info_port,
10092                 (void *)&cmd_show_queue_region_info_port_index,
10093                 (void *)&cmd_show_queue_region_info_cmd,
10094                 NULL,
10095         },
10096 };
10097
10098 /* *** ADD/REMOVE A 2tuple FILTER *** */
10099 struct cmd_2tuple_filter_result {
10100         cmdline_fixed_string_t filter;
10101         portid_t port_id;
10102         cmdline_fixed_string_t ops;
10103         cmdline_fixed_string_t dst_port;
10104         uint16_t dst_port_value;
10105         cmdline_fixed_string_t protocol;
10106         uint8_t protocol_value;
10107         cmdline_fixed_string_t mask;
10108         uint8_t  mask_value;
10109         cmdline_fixed_string_t tcp_flags;
10110         uint8_t tcp_flags_value;
10111         cmdline_fixed_string_t priority;
10112         uint8_t  priority_value;
10113         cmdline_fixed_string_t queue;
10114         uint16_t  queue_id;
10115 };
10116
10117 static void
10118 cmd_2tuple_filter_parsed(void *parsed_result,
10119                         __attribute__((unused)) struct cmdline *cl,
10120                         __attribute__((unused)) void *data)
10121 {
10122         struct rte_eth_ntuple_filter filter;
10123         struct cmd_2tuple_filter_result *res = parsed_result;
10124         int ret = 0;
10125
10126         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10127         if (ret < 0) {
10128                 printf("ntuple filter is not supported on port %u.\n",
10129                         res->port_id);
10130                 return;
10131         }
10132
10133         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10134
10135         filter.flags = RTE_2TUPLE_FLAGS;
10136         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10137         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10138         filter.proto = res->protocol_value;
10139         filter.priority = res->priority_value;
10140         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10141                 printf("nonzero tcp_flags is only meaningful"
10142                         " when protocol is TCP.\n");
10143                 return;
10144         }
10145         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10146                 printf("invalid TCP flags.\n");
10147                 return;
10148         }
10149
10150         if (res->tcp_flags_value != 0) {
10151                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10152                 filter.tcp_flags = res->tcp_flags_value;
10153         }
10154
10155         /* need convert to big endian. */
10156         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10157         filter.queue = res->queue_id;
10158
10159         if (!strcmp(res->ops, "add"))
10160                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10161                                 RTE_ETH_FILTER_NTUPLE,
10162                                 RTE_ETH_FILTER_ADD,
10163                                 &filter);
10164         else
10165                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10166                                 RTE_ETH_FILTER_NTUPLE,
10167                                 RTE_ETH_FILTER_DELETE,
10168                                 &filter);
10169         if (ret < 0)
10170                 printf("2tuple filter programming error: (%s)\n",
10171                         strerror(-ret));
10172
10173 }
10174
10175 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10176         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10177                                  filter, "2tuple_filter");
10178 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10179         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10180                                 port_id, UINT16);
10181 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10182         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10183                                  ops, "add#del");
10184 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10185         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10186                                 dst_port, "dst_port");
10187 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10188         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10189                                 dst_port_value, UINT16);
10190 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10191         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10192                                 protocol, "protocol");
10193 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10194         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10195                                 protocol_value, UINT8);
10196 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10197         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10198                                 mask, "mask");
10199 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10200         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10201                                 mask_value, INT8);
10202 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10203         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10204                                 tcp_flags, "tcp_flags");
10205 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10206         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10207                                 tcp_flags_value, UINT8);
10208 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10209         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10210                                 priority, "priority");
10211 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10212         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10213                                 priority_value, UINT8);
10214 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10215         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10216                                 queue, "queue");
10217 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10218         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10219                                 queue_id, UINT16);
10220
10221 cmdline_parse_inst_t cmd_2tuple_filter = {
10222         .f = cmd_2tuple_filter_parsed,
10223         .data = NULL,
10224         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10225                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10226                 "<queue_id>: Add a 2tuple filter",
10227         .tokens = {
10228                 (void *)&cmd_2tuple_filter_filter,
10229                 (void *)&cmd_2tuple_filter_port_id,
10230                 (void *)&cmd_2tuple_filter_ops,
10231                 (void *)&cmd_2tuple_filter_dst_port,
10232                 (void *)&cmd_2tuple_filter_dst_port_value,
10233                 (void *)&cmd_2tuple_filter_protocol,
10234                 (void *)&cmd_2tuple_filter_protocol_value,
10235                 (void *)&cmd_2tuple_filter_mask,
10236                 (void *)&cmd_2tuple_filter_mask_value,
10237                 (void *)&cmd_2tuple_filter_tcp_flags,
10238                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10239                 (void *)&cmd_2tuple_filter_priority,
10240                 (void *)&cmd_2tuple_filter_priority_value,
10241                 (void *)&cmd_2tuple_filter_queue,
10242                 (void *)&cmd_2tuple_filter_queue_id,
10243                 NULL,
10244         },
10245 };
10246
10247 /* *** ADD/REMOVE A 5tuple FILTER *** */
10248 struct cmd_5tuple_filter_result {
10249         cmdline_fixed_string_t filter;
10250         portid_t port_id;
10251         cmdline_fixed_string_t ops;
10252         cmdline_fixed_string_t dst_ip;
10253         cmdline_ipaddr_t dst_ip_value;
10254         cmdline_fixed_string_t src_ip;
10255         cmdline_ipaddr_t src_ip_value;
10256         cmdline_fixed_string_t dst_port;
10257         uint16_t dst_port_value;
10258         cmdline_fixed_string_t src_port;
10259         uint16_t src_port_value;
10260         cmdline_fixed_string_t protocol;
10261         uint8_t protocol_value;
10262         cmdline_fixed_string_t mask;
10263         uint8_t  mask_value;
10264         cmdline_fixed_string_t tcp_flags;
10265         uint8_t tcp_flags_value;
10266         cmdline_fixed_string_t priority;
10267         uint8_t  priority_value;
10268         cmdline_fixed_string_t queue;
10269         uint16_t  queue_id;
10270 };
10271
10272 static void
10273 cmd_5tuple_filter_parsed(void *parsed_result,
10274                         __attribute__((unused)) struct cmdline *cl,
10275                         __attribute__((unused)) void *data)
10276 {
10277         struct rte_eth_ntuple_filter filter;
10278         struct cmd_5tuple_filter_result *res = parsed_result;
10279         int ret = 0;
10280
10281         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10282         if (ret < 0) {
10283                 printf("ntuple filter is not supported on port %u.\n",
10284                         res->port_id);
10285                 return;
10286         }
10287
10288         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10289
10290         filter.flags = RTE_5TUPLE_FLAGS;
10291         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10292         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10293         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10294         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10295         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10296         filter.proto = res->protocol_value;
10297         filter.priority = res->priority_value;
10298         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10299                 printf("nonzero tcp_flags is only meaningful"
10300                         " when protocol is TCP.\n");
10301                 return;
10302         }
10303         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10304                 printf("invalid TCP flags.\n");
10305                 return;
10306         }
10307
10308         if (res->tcp_flags_value != 0) {
10309                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10310                 filter.tcp_flags = res->tcp_flags_value;
10311         }
10312
10313         if (res->dst_ip_value.family == AF_INET)
10314                 /* no need to convert, already big endian. */
10315                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10316         else {
10317                 if (filter.dst_ip_mask == 0) {
10318                         printf("can not support ipv6 involved compare.\n");
10319                         return;
10320                 }
10321                 filter.dst_ip = 0;
10322         }
10323
10324         if (res->src_ip_value.family == AF_INET)
10325                 /* no need to convert, already big endian. */
10326                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10327         else {
10328                 if (filter.src_ip_mask == 0) {
10329                         printf("can not support ipv6 involved compare.\n");
10330                         return;
10331                 }
10332                 filter.src_ip = 0;
10333         }
10334         /* need convert to big endian. */
10335         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10336         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10337         filter.queue = res->queue_id;
10338
10339         if (!strcmp(res->ops, "add"))
10340                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10341                                 RTE_ETH_FILTER_NTUPLE,
10342                                 RTE_ETH_FILTER_ADD,
10343                                 &filter);
10344         else
10345                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10346                                 RTE_ETH_FILTER_NTUPLE,
10347                                 RTE_ETH_FILTER_DELETE,
10348                                 &filter);
10349         if (ret < 0)
10350                 printf("5tuple filter programming error: (%s)\n",
10351                         strerror(-ret));
10352 }
10353
10354 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10355         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10356                                  filter, "5tuple_filter");
10357 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10358         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10359                                 port_id, UINT16);
10360 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10361         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10362                                  ops, "add#del");
10363 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10364         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10365                                 dst_ip, "dst_ip");
10366 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10367         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10368                                 dst_ip_value);
10369 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10370         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10371                                 src_ip, "src_ip");
10372 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10373         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10374                                 src_ip_value);
10375 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10376         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10377                                 dst_port, "dst_port");
10378 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10379         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10380                                 dst_port_value, UINT16);
10381 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10382         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10383                                 src_port, "src_port");
10384 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10385         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10386                                 src_port_value, UINT16);
10387 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10388         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10389                                 protocol, "protocol");
10390 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10391         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10392                                 protocol_value, UINT8);
10393 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10394         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10395                                 mask, "mask");
10396 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10397         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10398                                 mask_value, INT8);
10399 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10400         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10401                                 tcp_flags, "tcp_flags");
10402 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10403         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10404                                 tcp_flags_value, UINT8);
10405 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10406         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10407                                 priority, "priority");
10408 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10409         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10410                                 priority_value, UINT8);
10411 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10412         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10413                                 queue, "queue");
10414 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10415         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10416                                 queue_id, UINT16);
10417
10418 cmdline_parse_inst_t cmd_5tuple_filter = {
10419         .f = cmd_5tuple_filter_parsed,
10420         .data = NULL,
10421         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10422                 "src_ip <value> dst_port <value> src_port <value> "
10423                 "protocol <value>  mask <value> tcp_flags <value> "
10424                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10425         .tokens = {
10426                 (void *)&cmd_5tuple_filter_filter,
10427                 (void *)&cmd_5tuple_filter_port_id,
10428                 (void *)&cmd_5tuple_filter_ops,
10429                 (void *)&cmd_5tuple_filter_dst_ip,
10430                 (void *)&cmd_5tuple_filter_dst_ip_value,
10431                 (void *)&cmd_5tuple_filter_src_ip,
10432                 (void *)&cmd_5tuple_filter_src_ip_value,
10433                 (void *)&cmd_5tuple_filter_dst_port,
10434                 (void *)&cmd_5tuple_filter_dst_port_value,
10435                 (void *)&cmd_5tuple_filter_src_port,
10436                 (void *)&cmd_5tuple_filter_src_port_value,
10437                 (void *)&cmd_5tuple_filter_protocol,
10438                 (void *)&cmd_5tuple_filter_protocol_value,
10439                 (void *)&cmd_5tuple_filter_mask,
10440                 (void *)&cmd_5tuple_filter_mask_value,
10441                 (void *)&cmd_5tuple_filter_tcp_flags,
10442                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10443                 (void *)&cmd_5tuple_filter_priority,
10444                 (void *)&cmd_5tuple_filter_priority_value,
10445                 (void *)&cmd_5tuple_filter_queue,
10446                 (void *)&cmd_5tuple_filter_queue_id,
10447                 NULL,
10448         },
10449 };
10450
10451 /* *** ADD/REMOVE A flex FILTER *** */
10452 struct cmd_flex_filter_result {
10453         cmdline_fixed_string_t filter;
10454         cmdline_fixed_string_t ops;
10455         portid_t port_id;
10456         cmdline_fixed_string_t len;
10457         uint8_t len_value;
10458         cmdline_fixed_string_t bytes;
10459         cmdline_fixed_string_t bytes_value;
10460         cmdline_fixed_string_t mask;
10461         cmdline_fixed_string_t mask_value;
10462         cmdline_fixed_string_t priority;
10463         uint8_t priority_value;
10464         cmdline_fixed_string_t queue;
10465         uint16_t queue_id;
10466 };
10467
10468 static int xdigit2val(unsigned char c)
10469 {
10470         int val;
10471         if (isdigit(c))
10472                 val = c - '0';
10473         else if (isupper(c))
10474                 val = c - 'A' + 10;
10475         else
10476                 val = c - 'a' + 10;
10477         return val;
10478 }
10479
10480 static void
10481 cmd_flex_filter_parsed(void *parsed_result,
10482                           __attribute__((unused)) struct cmdline *cl,
10483                           __attribute__((unused)) void *data)
10484 {
10485         int ret = 0;
10486         struct rte_eth_flex_filter filter;
10487         struct cmd_flex_filter_result *res = parsed_result;
10488         char *bytes_ptr, *mask_ptr;
10489         uint16_t len, i, j = 0;
10490         char c;
10491         int val;
10492         uint8_t byte = 0;
10493
10494         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10495                 printf("the len exceed the max length 128\n");
10496                 return;
10497         }
10498         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10499         filter.len = res->len_value;
10500         filter.priority = res->priority_value;
10501         filter.queue = res->queue_id;
10502         bytes_ptr = res->bytes_value;
10503         mask_ptr = res->mask_value;
10504
10505          /* translate bytes string to array. */
10506         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10507                 (bytes_ptr[1] == 'X')))
10508                 bytes_ptr += 2;
10509         len = strnlen(bytes_ptr, res->len_value * 2);
10510         if (len == 0 || (len % 8 != 0)) {
10511                 printf("please check len and bytes input\n");
10512                 return;
10513         }
10514         for (i = 0; i < len; i++) {
10515                 c = bytes_ptr[i];
10516                 if (isxdigit(c) == 0) {
10517                         /* invalid characters. */
10518                         printf("invalid input\n");
10519                         return;
10520                 }
10521                 val = xdigit2val(c);
10522                 if (i % 2) {
10523                         byte |= val;
10524                         filter.bytes[j] = byte;
10525                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10526                         j++;
10527                         byte = 0;
10528                 } else
10529                         byte |= val << 4;
10530         }
10531         printf("\n");
10532          /* translate mask string to uint8_t array. */
10533         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10534                 (mask_ptr[1] == 'X')))
10535                 mask_ptr += 2;
10536         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10537         if (len == 0) {
10538                 printf("invalid input\n");
10539                 return;
10540         }
10541         j = 0;
10542         byte = 0;
10543         for (i = 0; i < len; i++) {
10544                 c = mask_ptr[i];
10545                 if (isxdigit(c) == 0) {
10546                         /* invalid characters. */
10547                         printf("invalid input\n");
10548                         return;
10549                 }
10550                 val = xdigit2val(c);
10551                 if (i % 2) {
10552                         byte |= val;
10553                         filter.mask[j] = byte;
10554                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10555                         j++;
10556                         byte = 0;
10557                 } else
10558                         byte |= val << 4;
10559         }
10560         printf("\n");
10561
10562         if (!strcmp(res->ops, "add"))
10563                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10564                                 RTE_ETH_FILTER_FLEXIBLE,
10565                                 RTE_ETH_FILTER_ADD,
10566                                 &filter);
10567         else
10568                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10569                                 RTE_ETH_FILTER_FLEXIBLE,
10570                                 RTE_ETH_FILTER_DELETE,
10571                                 &filter);
10572
10573         if (ret < 0)
10574                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10575 }
10576
10577 cmdline_parse_token_string_t cmd_flex_filter_filter =
10578         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10579                                 filter, "flex_filter");
10580 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10581         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10582                                 port_id, UINT16);
10583 cmdline_parse_token_string_t cmd_flex_filter_ops =
10584         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10585                                 ops, "add#del");
10586 cmdline_parse_token_string_t cmd_flex_filter_len =
10587         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10588                                 len, "len");
10589 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10590         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10591                                 len_value, UINT8);
10592 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10593         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10594                                 bytes, "bytes");
10595 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10596         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10597                                 bytes_value, NULL);
10598 cmdline_parse_token_string_t cmd_flex_filter_mask =
10599         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10600                                 mask, "mask");
10601 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10602         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10603                                 mask_value, NULL);
10604 cmdline_parse_token_string_t cmd_flex_filter_priority =
10605         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10606                                 priority, "priority");
10607 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10608         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10609                                 priority_value, UINT8);
10610 cmdline_parse_token_string_t cmd_flex_filter_queue =
10611         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10612                                 queue, "queue");
10613 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10614         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10615                                 queue_id, UINT16);
10616 cmdline_parse_inst_t cmd_flex_filter = {
10617         .f = cmd_flex_filter_parsed,
10618         .data = NULL,
10619         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10620                 "<value> mask <value> priority <value> queue <queue_id>: "
10621                 "Add/Del a flex filter",
10622         .tokens = {
10623                 (void *)&cmd_flex_filter_filter,
10624                 (void *)&cmd_flex_filter_port_id,
10625                 (void *)&cmd_flex_filter_ops,
10626                 (void *)&cmd_flex_filter_len,
10627                 (void *)&cmd_flex_filter_len_value,
10628                 (void *)&cmd_flex_filter_bytes,
10629                 (void *)&cmd_flex_filter_bytes_value,
10630                 (void *)&cmd_flex_filter_mask,
10631                 (void *)&cmd_flex_filter_mask_value,
10632                 (void *)&cmd_flex_filter_priority,
10633                 (void *)&cmd_flex_filter_priority_value,
10634                 (void *)&cmd_flex_filter_queue,
10635                 (void *)&cmd_flex_filter_queue_id,
10636                 NULL,
10637         },
10638 };
10639
10640 /* *** Filters Control *** */
10641
10642 /* *** deal with ethertype filter *** */
10643 struct cmd_ethertype_filter_result {
10644         cmdline_fixed_string_t filter;
10645         portid_t port_id;
10646         cmdline_fixed_string_t ops;
10647         cmdline_fixed_string_t mac;
10648         struct rte_ether_addr mac_addr;
10649         cmdline_fixed_string_t ethertype;
10650         uint16_t ethertype_value;
10651         cmdline_fixed_string_t drop;
10652         cmdline_fixed_string_t queue;
10653         uint16_t  queue_id;
10654 };
10655
10656 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10657         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10658                                  filter, "ethertype_filter");
10659 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10660         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10661                               port_id, UINT16);
10662 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10663         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10664                                  ops, "add#del");
10665 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10666         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10667                                  mac, "mac_addr#mac_ignr");
10668 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10669         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10670                                      mac_addr);
10671 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10672         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10673                                  ethertype, "ethertype");
10674 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10675         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10676                               ethertype_value, UINT16);
10677 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10678         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10679                                  drop, "drop#fwd");
10680 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10681         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10682                                  queue, "queue");
10683 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10684         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10685                               queue_id, UINT16);
10686
10687 static void
10688 cmd_ethertype_filter_parsed(void *parsed_result,
10689                           __attribute__((unused)) struct cmdline *cl,
10690                           __attribute__((unused)) void *data)
10691 {
10692         struct cmd_ethertype_filter_result *res = parsed_result;
10693         struct rte_eth_ethertype_filter filter;
10694         int ret = 0;
10695
10696         ret = rte_eth_dev_filter_supported(res->port_id,
10697                         RTE_ETH_FILTER_ETHERTYPE);
10698         if (ret < 0) {
10699                 printf("ethertype filter is not supported on port %u.\n",
10700                         res->port_id);
10701                 return;
10702         }
10703
10704         memset(&filter, 0, sizeof(filter));
10705         if (!strcmp(res->mac, "mac_addr")) {
10706                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10707                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10708                         sizeof(struct rte_ether_addr));
10709         }
10710         if (!strcmp(res->drop, "drop"))
10711                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10712         filter.ether_type = res->ethertype_value;
10713         filter.queue = res->queue_id;
10714
10715         if (!strcmp(res->ops, "add"))
10716                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10717                                 RTE_ETH_FILTER_ETHERTYPE,
10718                                 RTE_ETH_FILTER_ADD,
10719                                 &filter);
10720         else
10721                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10722                                 RTE_ETH_FILTER_ETHERTYPE,
10723                                 RTE_ETH_FILTER_DELETE,
10724                                 &filter);
10725         if (ret < 0)
10726                 printf("ethertype filter programming error: (%s)\n",
10727                         strerror(-ret));
10728 }
10729
10730 cmdline_parse_inst_t cmd_ethertype_filter = {
10731         .f = cmd_ethertype_filter_parsed,
10732         .data = NULL,
10733         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10734                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10735                 "Add or delete an ethertype filter entry",
10736         .tokens = {
10737                 (void *)&cmd_ethertype_filter_filter,
10738                 (void *)&cmd_ethertype_filter_port_id,
10739                 (void *)&cmd_ethertype_filter_ops,
10740                 (void *)&cmd_ethertype_filter_mac,
10741                 (void *)&cmd_ethertype_filter_mac_addr,
10742                 (void *)&cmd_ethertype_filter_ethertype,
10743                 (void *)&cmd_ethertype_filter_ethertype_value,
10744                 (void *)&cmd_ethertype_filter_drop,
10745                 (void *)&cmd_ethertype_filter_queue,
10746                 (void *)&cmd_ethertype_filter_queue_id,
10747                 NULL,
10748         },
10749 };
10750
10751 /* *** deal with flow director filter *** */
10752 struct cmd_flow_director_result {
10753         cmdline_fixed_string_t flow_director_filter;
10754         portid_t port_id;
10755         cmdline_fixed_string_t mode;
10756         cmdline_fixed_string_t mode_value;
10757         cmdline_fixed_string_t ops;
10758         cmdline_fixed_string_t flow;
10759         cmdline_fixed_string_t flow_type;
10760         cmdline_fixed_string_t ether;
10761         uint16_t ether_type;
10762         cmdline_fixed_string_t src;
10763         cmdline_ipaddr_t ip_src;
10764         uint16_t port_src;
10765         cmdline_fixed_string_t dst;
10766         cmdline_ipaddr_t ip_dst;
10767         uint16_t port_dst;
10768         cmdline_fixed_string_t verify_tag;
10769         uint32_t verify_tag_value;
10770         cmdline_fixed_string_t tos;
10771         uint8_t tos_value;
10772         cmdline_fixed_string_t proto;
10773         uint8_t proto_value;
10774         cmdline_fixed_string_t ttl;
10775         uint8_t ttl_value;
10776         cmdline_fixed_string_t vlan;
10777         uint16_t vlan_value;
10778         cmdline_fixed_string_t flexbytes;
10779         cmdline_fixed_string_t flexbytes_value;
10780         cmdline_fixed_string_t pf_vf;
10781         cmdline_fixed_string_t drop;
10782         cmdline_fixed_string_t queue;
10783         uint16_t  queue_id;
10784         cmdline_fixed_string_t fd_id;
10785         uint32_t  fd_id_value;
10786         cmdline_fixed_string_t mac;
10787         struct rte_ether_addr mac_addr;
10788         cmdline_fixed_string_t tunnel;
10789         cmdline_fixed_string_t tunnel_type;
10790         cmdline_fixed_string_t tunnel_id;
10791         uint32_t tunnel_id_value;
10792         cmdline_fixed_string_t packet;
10793         char filepath[];
10794 };
10795
10796 static inline int
10797 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10798 {
10799         char s[256];
10800         const char *p, *p0 = q_arg;
10801         char *end;
10802         unsigned long int_fld;
10803         char *str_fld[max_num];
10804         int i;
10805         unsigned size;
10806         int ret = -1;
10807
10808         p = strchr(p0, '(');
10809         if (p == NULL)
10810                 return -1;
10811         ++p;
10812         p0 = strchr(p, ')');
10813         if (p0 == NULL)
10814                 return -1;
10815
10816         size = p0 - p;
10817         if (size >= sizeof(s))
10818                 return -1;
10819
10820         snprintf(s, sizeof(s), "%.*s", size, p);
10821         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10822         if (ret < 0 || ret > max_num)
10823                 return -1;
10824         for (i = 0; i < ret; i++) {
10825                 errno = 0;
10826                 int_fld = strtoul(str_fld[i], &end, 0);
10827                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10828                         return -1;
10829                 flexbytes[i] = (uint8_t)int_fld;
10830         }
10831         return ret;
10832 }
10833
10834 static uint16_t
10835 str2flowtype(char *string)
10836 {
10837         uint8_t i = 0;
10838         static const struct {
10839                 char str[32];
10840                 uint16_t type;
10841         } flowtype_str[] = {
10842                 {"raw", RTE_ETH_FLOW_RAW},
10843                 {"ipv4", RTE_ETH_FLOW_IPV4},
10844                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10845                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10846                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10847                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10848                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10849                 {"ipv6", RTE_ETH_FLOW_IPV6},
10850                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10851                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10852                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10853                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10854                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10855                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10856         };
10857
10858         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10859                 if (!strcmp(flowtype_str[i].str, string))
10860                         return flowtype_str[i].type;
10861         }
10862
10863         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10864                 return (uint16_t)atoi(string);
10865
10866         return RTE_ETH_FLOW_UNKNOWN;
10867 }
10868
10869 static enum rte_eth_fdir_tunnel_type
10870 str2fdir_tunneltype(char *string)
10871 {
10872         uint8_t i = 0;
10873
10874         static const struct {
10875                 char str[32];
10876                 enum rte_eth_fdir_tunnel_type type;
10877         } tunneltype_str[] = {
10878                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10879                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10880         };
10881
10882         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10883                 if (!strcmp(tunneltype_str[i].str, string))
10884                         return tunneltype_str[i].type;
10885         }
10886         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10887 }
10888
10889 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10890 do { \
10891         if ((ip_addr).family == AF_INET) \
10892                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10893         else { \
10894                 printf("invalid parameter.\n"); \
10895                 return; \
10896         } \
10897 } while (0)
10898
10899 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10900 do { \
10901         if ((ip_addr).family == AF_INET6) \
10902                 rte_memcpy(&(ip), \
10903                                  &((ip_addr).addr.ipv6), \
10904                                  sizeof(struct in6_addr)); \
10905         else { \
10906                 printf("invalid parameter.\n"); \
10907                 return; \
10908         } \
10909 } while (0)
10910
10911 static void
10912 cmd_flow_director_filter_parsed(void *parsed_result,
10913                           __attribute__((unused)) struct cmdline *cl,
10914                           __attribute__((unused)) void *data)
10915 {
10916         struct cmd_flow_director_result *res = parsed_result;
10917         struct rte_eth_fdir_filter entry;
10918         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10919         char *end;
10920         unsigned long vf_id;
10921         int ret = 0;
10922
10923         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10924         if (ret < 0) {
10925                 printf("flow director is not supported on port %u.\n",
10926                         res->port_id);
10927                 return;
10928         }
10929         memset(flexbytes, 0, sizeof(flexbytes));
10930         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10931
10932         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10933                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10934                         printf("Please set mode to MAC-VLAN.\n");
10935                         return;
10936                 }
10937         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10938                 if (strcmp(res->mode_value, "Tunnel")) {
10939                         printf("Please set mode to Tunnel.\n");
10940                         return;
10941                 }
10942         } else {
10943                 if (!strcmp(res->mode_value, "raw")) {
10944 #ifdef RTE_LIBRTE_I40E_PMD
10945                         struct rte_pmd_i40e_flow_type_mapping
10946                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10947                         struct rte_pmd_i40e_pkt_template_conf conf;
10948                         uint16_t flow_type = str2flowtype(res->flow_type);
10949                         uint16_t i, port = res->port_id;
10950                         uint8_t add;
10951
10952                         memset(&conf, 0, sizeof(conf));
10953
10954                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10955                                 printf("Invalid flow type specified.\n");
10956                                 return;
10957                         }
10958                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10959                                                                  mapping);
10960                         if (ret)
10961                                 return;
10962                         if (mapping[flow_type].pctype == 0ULL) {
10963                                 printf("Invalid flow type specified.\n");
10964                                 return;
10965                         }
10966                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10967                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10968                                         conf.input.pctype = i;
10969                                         break;
10970                                 }
10971                         }
10972
10973                         conf.input.packet = open_file(res->filepath,
10974                                                 &conf.input.length);
10975                         if (!conf.input.packet)
10976                                 return;
10977                         if (!strcmp(res->drop, "drop"))
10978                                 conf.action.behavior =
10979                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10980                         else
10981                                 conf.action.behavior =
10982                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10983                         conf.action.report_status =
10984                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10985                         conf.action.rx_queue = res->queue_id;
10986                         conf.soft_id = res->fd_id_value;
10987                         add  = strcmp(res->ops, "del") ? 1 : 0;
10988                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10989                                                                         &conf,
10990                                                                         add);
10991                         if (ret < 0)
10992                                 printf("flow director config error: (%s)\n",
10993                                        strerror(-ret));
10994                         close_file(conf.input.packet);
10995 #endif
10996                         return;
10997                 } else if (strcmp(res->mode_value, "IP")) {
10998                         printf("Please set mode to IP or raw.\n");
10999                         return;
11000                 }
11001                 entry.input.flow_type = str2flowtype(res->flow_type);
11002         }
11003
11004         ret = parse_flexbytes(res->flexbytes_value,
11005                                         flexbytes,
11006                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11007         if (ret < 0) {
11008                 printf("error: Cannot parse flexbytes input.\n");
11009                 return;
11010         }
11011
11012         switch (entry.input.flow_type) {
11013         case RTE_ETH_FLOW_FRAG_IPV4:
11014         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11015                 entry.input.flow.ip4_flow.proto = res->proto_value;
11016                 /* fall-through */
11017         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11018         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11019                 IPV4_ADDR_TO_UINT(res->ip_dst,
11020                         entry.input.flow.ip4_flow.dst_ip);
11021                 IPV4_ADDR_TO_UINT(res->ip_src,
11022                         entry.input.flow.ip4_flow.src_ip);
11023                 entry.input.flow.ip4_flow.tos = res->tos_value;
11024                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11025                 /* need convert to big endian. */
11026                 entry.input.flow.udp4_flow.dst_port =
11027                                 rte_cpu_to_be_16(res->port_dst);
11028                 entry.input.flow.udp4_flow.src_port =
11029                                 rte_cpu_to_be_16(res->port_src);
11030                 break;
11031         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11032                 IPV4_ADDR_TO_UINT(res->ip_dst,
11033                         entry.input.flow.sctp4_flow.ip.dst_ip);
11034                 IPV4_ADDR_TO_UINT(res->ip_src,
11035                         entry.input.flow.sctp4_flow.ip.src_ip);
11036                 entry.input.flow.ip4_flow.tos = res->tos_value;
11037                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11038                 /* need convert to big endian. */
11039                 entry.input.flow.sctp4_flow.dst_port =
11040                                 rte_cpu_to_be_16(res->port_dst);
11041                 entry.input.flow.sctp4_flow.src_port =
11042                                 rte_cpu_to_be_16(res->port_src);
11043                 entry.input.flow.sctp4_flow.verify_tag =
11044                                 rte_cpu_to_be_32(res->verify_tag_value);
11045                 break;
11046         case RTE_ETH_FLOW_FRAG_IPV6:
11047         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11048                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11049                 /* fall-through */
11050         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11051         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11052                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11053                         entry.input.flow.ipv6_flow.dst_ip);
11054                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11055                         entry.input.flow.ipv6_flow.src_ip);
11056                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11057                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11058                 /* need convert to big endian. */
11059                 entry.input.flow.udp6_flow.dst_port =
11060                                 rte_cpu_to_be_16(res->port_dst);
11061                 entry.input.flow.udp6_flow.src_port =
11062                                 rte_cpu_to_be_16(res->port_src);
11063                 break;
11064         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11065                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11066                         entry.input.flow.sctp6_flow.ip.dst_ip);
11067                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11068                         entry.input.flow.sctp6_flow.ip.src_ip);
11069                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11070                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11071                 /* need convert to big endian. */
11072                 entry.input.flow.sctp6_flow.dst_port =
11073                                 rte_cpu_to_be_16(res->port_dst);
11074                 entry.input.flow.sctp6_flow.src_port =
11075                                 rte_cpu_to_be_16(res->port_src);
11076                 entry.input.flow.sctp6_flow.verify_tag =
11077                                 rte_cpu_to_be_32(res->verify_tag_value);
11078                 break;
11079         case RTE_ETH_FLOW_L2_PAYLOAD:
11080                 entry.input.flow.l2_flow.ether_type =
11081                         rte_cpu_to_be_16(res->ether_type);
11082                 break;
11083         default:
11084                 break;
11085         }
11086
11087         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11088                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11089                                  &res->mac_addr,
11090                                  sizeof(struct rte_ether_addr));
11091
11092         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11093                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11094                                  &res->mac_addr,
11095                                  sizeof(struct rte_ether_addr));
11096                 entry.input.flow.tunnel_flow.tunnel_type =
11097                         str2fdir_tunneltype(res->tunnel_type);
11098                 entry.input.flow.tunnel_flow.tunnel_id =
11099                         rte_cpu_to_be_32(res->tunnel_id_value);
11100         }
11101
11102         rte_memcpy(entry.input.flow_ext.flexbytes,
11103                    flexbytes,
11104                    RTE_ETH_FDIR_MAX_FLEXLEN);
11105
11106         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11107
11108         entry.action.flex_off = 0;  /*use 0 by default */
11109         if (!strcmp(res->drop, "drop"))
11110                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11111         else
11112                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11113
11114         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11115             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11116                 if (!strcmp(res->pf_vf, "pf"))
11117                         entry.input.flow_ext.is_vf = 0;
11118                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11119                         struct rte_eth_dev_info dev_info;
11120
11121                         ret = eth_dev_info_get_print_err(res->port_id,
11122                                                 &dev_info);
11123                         if (ret != 0)
11124                                 return;
11125
11126                         errno = 0;
11127                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11128                         if (errno != 0 || *end != '\0' ||
11129                             vf_id >= dev_info.max_vfs) {
11130                                 printf("invalid parameter %s.\n", res->pf_vf);
11131                                 return;
11132                         }
11133                         entry.input.flow_ext.is_vf = 1;
11134                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11135                 } else {
11136                         printf("invalid parameter %s.\n", res->pf_vf);
11137                         return;
11138                 }
11139         }
11140
11141         /* set to report FD ID by default */
11142         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11143         entry.action.rx_queue = res->queue_id;
11144         entry.soft_id = res->fd_id_value;
11145         if (!strcmp(res->ops, "add"))
11146                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11147                                              RTE_ETH_FILTER_ADD, &entry);
11148         else if (!strcmp(res->ops, "del"))
11149                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11150                                              RTE_ETH_FILTER_DELETE, &entry);
11151         else
11152                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11153                                              RTE_ETH_FILTER_UPDATE, &entry);
11154         if (ret < 0)
11155                 printf("flow director programming error: (%s)\n",
11156                         strerror(-ret));
11157 }
11158
11159 cmdline_parse_token_string_t cmd_flow_director_filter =
11160         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11161                                  flow_director_filter, "flow_director_filter");
11162 cmdline_parse_token_num_t cmd_flow_director_port_id =
11163         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11164                               port_id, UINT16);
11165 cmdline_parse_token_string_t cmd_flow_director_ops =
11166         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11167                                  ops, "add#del#update");
11168 cmdline_parse_token_string_t cmd_flow_director_flow =
11169         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11170                                  flow, "flow");
11171 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11172         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11173                 flow_type, NULL);
11174 cmdline_parse_token_string_t cmd_flow_director_ether =
11175         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11176                                  ether, "ether");
11177 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11178         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11179                               ether_type, UINT16);
11180 cmdline_parse_token_string_t cmd_flow_director_src =
11181         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11182                                  src, "src");
11183 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11184         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11185                                  ip_src);
11186 cmdline_parse_token_num_t cmd_flow_director_port_src =
11187         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11188                               port_src, UINT16);
11189 cmdline_parse_token_string_t cmd_flow_director_dst =
11190         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11191                                  dst, "dst");
11192 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11193         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11194                                  ip_dst);
11195 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11196         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11197                               port_dst, UINT16);
11198 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11199         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11200                                   verify_tag, "verify_tag");
11201 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11202         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11203                               verify_tag_value, UINT32);
11204 cmdline_parse_token_string_t cmd_flow_director_tos =
11205         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11206                                  tos, "tos");
11207 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11208         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11209                               tos_value, UINT8);
11210 cmdline_parse_token_string_t cmd_flow_director_proto =
11211         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11212                                  proto, "proto");
11213 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11214         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11215                               proto_value, UINT8);
11216 cmdline_parse_token_string_t cmd_flow_director_ttl =
11217         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11218                                  ttl, "ttl");
11219 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11220         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11221                               ttl_value, UINT8);
11222 cmdline_parse_token_string_t cmd_flow_director_vlan =
11223         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11224                                  vlan, "vlan");
11225 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11226         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11227                               vlan_value, UINT16);
11228 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11229         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11230                                  flexbytes, "flexbytes");
11231 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11232         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11233                               flexbytes_value, NULL);
11234 cmdline_parse_token_string_t cmd_flow_director_drop =
11235         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11236                                  drop, "drop#fwd");
11237 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11238         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11239                               pf_vf, NULL);
11240 cmdline_parse_token_string_t cmd_flow_director_queue =
11241         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11242                                  queue, "queue");
11243 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11244         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11245                               queue_id, UINT16);
11246 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11247         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11248                                  fd_id, "fd_id");
11249 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11250         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11251                               fd_id_value, UINT32);
11252
11253 cmdline_parse_token_string_t cmd_flow_director_mode =
11254         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11255                                  mode, "mode");
11256 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11257         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11258                                  mode_value, "IP");
11259 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11260         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11261                                  mode_value, "MAC-VLAN");
11262 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11263         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11264                                  mode_value, "Tunnel");
11265 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11267                                  mode_value, "raw");
11268 cmdline_parse_token_string_t cmd_flow_director_mac =
11269         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11270                                  mac, "mac");
11271 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11272         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11273                                     mac_addr);
11274 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11276                                  tunnel, "tunnel");
11277 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11278         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11279                                  tunnel_type, "NVGRE#VxLAN");
11280 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11281         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11282                                  tunnel_id, "tunnel-id");
11283 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11284         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11285                               tunnel_id_value, UINT32);
11286 cmdline_parse_token_string_t cmd_flow_director_packet =
11287         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11288                                  packet, "packet");
11289 cmdline_parse_token_string_t cmd_flow_director_filepath =
11290         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11291                                  filepath, NULL);
11292
11293 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11294         .f = cmd_flow_director_filter_parsed,
11295         .data = NULL,
11296         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11297                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11298                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11299                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11300                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11301                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11302                 "fd_id <fd_id_value>: "
11303                 "Add or delete an ip flow director entry on NIC",
11304         .tokens = {
11305                 (void *)&cmd_flow_director_filter,
11306                 (void *)&cmd_flow_director_port_id,
11307                 (void *)&cmd_flow_director_mode,
11308                 (void *)&cmd_flow_director_mode_ip,
11309                 (void *)&cmd_flow_director_ops,
11310                 (void *)&cmd_flow_director_flow,
11311                 (void *)&cmd_flow_director_flow_type,
11312                 (void *)&cmd_flow_director_src,
11313                 (void *)&cmd_flow_director_ip_src,
11314                 (void *)&cmd_flow_director_dst,
11315                 (void *)&cmd_flow_director_ip_dst,
11316                 (void *)&cmd_flow_director_tos,
11317                 (void *)&cmd_flow_director_tos_value,
11318                 (void *)&cmd_flow_director_proto,
11319                 (void *)&cmd_flow_director_proto_value,
11320                 (void *)&cmd_flow_director_ttl,
11321                 (void *)&cmd_flow_director_ttl_value,
11322                 (void *)&cmd_flow_director_vlan,
11323                 (void *)&cmd_flow_director_vlan_value,
11324                 (void *)&cmd_flow_director_flexbytes,
11325                 (void *)&cmd_flow_director_flexbytes_value,
11326                 (void *)&cmd_flow_director_drop,
11327                 (void *)&cmd_flow_director_pf_vf,
11328                 (void *)&cmd_flow_director_queue,
11329                 (void *)&cmd_flow_director_queue_id,
11330                 (void *)&cmd_flow_director_fd_id,
11331                 (void *)&cmd_flow_director_fd_id_value,
11332                 NULL,
11333         },
11334 };
11335
11336 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11337         .f = cmd_flow_director_filter_parsed,
11338         .data = NULL,
11339         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11340                 "director entry on NIC",
11341         .tokens = {
11342                 (void *)&cmd_flow_director_filter,
11343                 (void *)&cmd_flow_director_port_id,
11344                 (void *)&cmd_flow_director_mode,
11345                 (void *)&cmd_flow_director_mode_ip,
11346                 (void *)&cmd_flow_director_ops,
11347                 (void *)&cmd_flow_director_flow,
11348                 (void *)&cmd_flow_director_flow_type,
11349                 (void *)&cmd_flow_director_src,
11350                 (void *)&cmd_flow_director_ip_src,
11351                 (void *)&cmd_flow_director_port_src,
11352                 (void *)&cmd_flow_director_dst,
11353                 (void *)&cmd_flow_director_ip_dst,
11354                 (void *)&cmd_flow_director_port_dst,
11355                 (void *)&cmd_flow_director_tos,
11356                 (void *)&cmd_flow_director_tos_value,
11357                 (void *)&cmd_flow_director_ttl,
11358                 (void *)&cmd_flow_director_ttl_value,
11359                 (void *)&cmd_flow_director_vlan,
11360                 (void *)&cmd_flow_director_vlan_value,
11361                 (void *)&cmd_flow_director_flexbytes,
11362                 (void *)&cmd_flow_director_flexbytes_value,
11363                 (void *)&cmd_flow_director_drop,
11364                 (void *)&cmd_flow_director_pf_vf,
11365                 (void *)&cmd_flow_director_queue,
11366                 (void *)&cmd_flow_director_queue_id,
11367                 (void *)&cmd_flow_director_fd_id,
11368                 (void *)&cmd_flow_director_fd_id_value,
11369                 NULL,
11370         },
11371 };
11372
11373 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11374         .f = cmd_flow_director_filter_parsed,
11375         .data = NULL,
11376         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11377                 "director entry on NIC",
11378         .tokens = {
11379                 (void *)&cmd_flow_director_filter,
11380                 (void *)&cmd_flow_director_port_id,
11381                 (void *)&cmd_flow_director_mode,
11382                 (void *)&cmd_flow_director_mode_ip,
11383                 (void *)&cmd_flow_director_ops,
11384                 (void *)&cmd_flow_director_flow,
11385                 (void *)&cmd_flow_director_flow_type,
11386                 (void *)&cmd_flow_director_src,
11387                 (void *)&cmd_flow_director_ip_src,
11388                 (void *)&cmd_flow_director_port_src,
11389                 (void *)&cmd_flow_director_dst,
11390                 (void *)&cmd_flow_director_ip_dst,
11391                 (void *)&cmd_flow_director_port_dst,
11392                 (void *)&cmd_flow_director_verify_tag,
11393                 (void *)&cmd_flow_director_verify_tag_value,
11394                 (void *)&cmd_flow_director_tos,
11395                 (void *)&cmd_flow_director_tos_value,
11396                 (void *)&cmd_flow_director_ttl,
11397                 (void *)&cmd_flow_director_ttl_value,
11398                 (void *)&cmd_flow_director_vlan,
11399                 (void *)&cmd_flow_director_vlan_value,
11400                 (void *)&cmd_flow_director_flexbytes,
11401                 (void *)&cmd_flow_director_flexbytes_value,
11402                 (void *)&cmd_flow_director_drop,
11403                 (void *)&cmd_flow_director_pf_vf,
11404                 (void *)&cmd_flow_director_queue,
11405                 (void *)&cmd_flow_director_queue_id,
11406                 (void *)&cmd_flow_director_fd_id,
11407                 (void *)&cmd_flow_director_fd_id_value,
11408                 NULL,
11409         },
11410 };
11411
11412 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11413         .f = cmd_flow_director_filter_parsed,
11414         .data = NULL,
11415         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11416                 "director entry on NIC",
11417         .tokens = {
11418                 (void *)&cmd_flow_director_filter,
11419                 (void *)&cmd_flow_director_port_id,
11420                 (void *)&cmd_flow_director_mode,
11421                 (void *)&cmd_flow_director_mode_ip,
11422                 (void *)&cmd_flow_director_ops,
11423                 (void *)&cmd_flow_director_flow,
11424                 (void *)&cmd_flow_director_flow_type,
11425                 (void *)&cmd_flow_director_ether,
11426                 (void *)&cmd_flow_director_ether_type,
11427                 (void *)&cmd_flow_director_flexbytes,
11428                 (void *)&cmd_flow_director_flexbytes_value,
11429                 (void *)&cmd_flow_director_drop,
11430                 (void *)&cmd_flow_director_pf_vf,
11431                 (void *)&cmd_flow_director_queue,
11432                 (void *)&cmd_flow_director_queue_id,
11433                 (void *)&cmd_flow_director_fd_id,
11434                 (void *)&cmd_flow_director_fd_id_value,
11435                 NULL,
11436         },
11437 };
11438
11439 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11440         .f = cmd_flow_director_filter_parsed,
11441         .data = NULL,
11442         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11443                 "director entry on NIC",
11444         .tokens = {
11445                 (void *)&cmd_flow_director_filter,
11446                 (void *)&cmd_flow_director_port_id,
11447                 (void *)&cmd_flow_director_mode,
11448                 (void *)&cmd_flow_director_mode_mac_vlan,
11449                 (void *)&cmd_flow_director_ops,
11450                 (void *)&cmd_flow_director_mac,
11451                 (void *)&cmd_flow_director_mac_addr,
11452                 (void *)&cmd_flow_director_vlan,
11453                 (void *)&cmd_flow_director_vlan_value,
11454                 (void *)&cmd_flow_director_flexbytes,
11455                 (void *)&cmd_flow_director_flexbytes_value,
11456                 (void *)&cmd_flow_director_drop,
11457                 (void *)&cmd_flow_director_queue,
11458                 (void *)&cmd_flow_director_queue_id,
11459                 (void *)&cmd_flow_director_fd_id,
11460                 (void *)&cmd_flow_director_fd_id_value,
11461                 NULL,
11462         },
11463 };
11464
11465 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11466         .f = cmd_flow_director_filter_parsed,
11467         .data = NULL,
11468         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11469                 "director entry on NIC",
11470         .tokens = {
11471                 (void *)&cmd_flow_director_filter,
11472                 (void *)&cmd_flow_director_port_id,
11473                 (void *)&cmd_flow_director_mode,
11474                 (void *)&cmd_flow_director_mode_tunnel,
11475                 (void *)&cmd_flow_director_ops,
11476                 (void *)&cmd_flow_director_mac,
11477                 (void *)&cmd_flow_director_mac_addr,
11478                 (void *)&cmd_flow_director_vlan,
11479                 (void *)&cmd_flow_director_vlan_value,
11480                 (void *)&cmd_flow_director_tunnel,
11481                 (void *)&cmd_flow_director_tunnel_type,
11482                 (void *)&cmd_flow_director_tunnel_id,
11483                 (void *)&cmd_flow_director_tunnel_id_value,
11484                 (void *)&cmd_flow_director_flexbytes,
11485                 (void *)&cmd_flow_director_flexbytes_value,
11486                 (void *)&cmd_flow_director_drop,
11487                 (void *)&cmd_flow_director_queue,
11488                 (void *)&cmd_flow_director_queue_id,
11489                 (void *)&cmd_flow_director_fd_id,
11490                 (void *)&cmd_flow_director_fd_id_value,
11491                 NULL,
11492         },
11493 };
11494
11495 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11496         .f = cmd_flow_director_filter_parsed,
11497         .data = NULL,
11498         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11499                 "director entry on NIC",
11500         .tokens = {
11501                 (void *)&cmd_flow_director_filter,
11502                 (void *)&cmd_flow_director_port_id,
11503                 (void *)&cmd_flow_director_mode,
11504                 (void *)&cmd_flow_director_mode_raw,
11505                 (void *)&cmd_flow_director_ops,
11506                 (void *)&cmd_flow_director_flow,
11507                 (void *)&cmd_flow_director_flow_type,
11508                 (void *)&cmd_flow_director_drop,
11509                 (void *)&cmd_flow_director_queue,
11510                 (void *)&cmd_flow_director_queue_id,
11511                 (void *)&cmd_flow_director_fd_id,
11512                 (void *)&cmd_flow_director_fd_id_value,
11513                 (void *)&cmd_flow_director_packet,
11514                 (void *)&cmd_flow_director_filepath,
11515                 NULL,
11516         },
11517 };
11518
11519 struct cmd_flush_flow_director_result {
11520         cmdline_fixed_string_t flush_flow_director;
11521         portid_t port_id;
11522 };
11523
11524 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11525         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11526                                  flush_flow_director, "flush_flow_director");
11527 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11528         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11529                               port_id, UINT16);
11530
11531 static void
11532 cmd_flush_flow_director_parsed(void *parsed_result,
11533                           __attribute__((unused)) struct cmdline *cl,
11534                           __attribute__((unused)) void *data)
11535 {
11536         struct cmd_flow_director_result *res = parsed_result;
11537         int ret = 0;
11538
11539         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11540         if (ret < 0) {
11541                 printf("flow director is not supported on port %u.\n",
11542                         res->port_id);
11543                 return;
11544         }
11545
11546         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11547                         RTE_ETH_FILTER_FLUSH, NULL);
11548         if (ret < 0)
11549                 printf("flow director table flushing error: (%s)\n",
11550                         strerror(-ret));
11551 }
11552
11553 cmdline_parse_inst_t cmd_flush_flow_director = {
11554         .f = cmd_flush_flow_director_parsed,
11555         .data = NULL,
11556         .help_str = "flush_flow_director <port_id>: "
11557                 "Flush all flow director entries of a device on NIC",
11558         .tokens = {
11559                 (void *)&cmd_flush_flow_director_flush,
11560                 (void *)&cmd_flush_flow_director_port_id,
11561                 NULL,
11562         },
11563 };
11564
11565 /* *** deal with flow director mask *** */
11566 struct cmd_flow_director_mask_result {
11567         cmdline_fixed_string_t flow_director_mask;
11568         portid_t port_id;
11569         cmdline_fixed_string_t mode;
11570         cmdline_fixed_string_t mode_value;
11571         cmdline_fixed_string_t vlan;
11572         uint16_t vlan_mask;
11573         cmdline_fixed_string_t src_mask;
11574         cmdline_ipaddr_t ipv4_src;
11575         cmdline_ipaddr_t ipv6_src;
11576         uint16_t port_src;
11577         cmdline_fixed_string_t dst_mask;
11578         cmdline_ipaddr_t ipv4_dst;
11579         cmdline_ipaddr_t ipv6_dst;
11580         uint16_t port_dst;
11581         cmdline_fixed_string_t mac;
11582         uint8_t mac_addr_byte_mask;
11583         cmdline_fixed_string_t tunnel_id;
11584         uint32_t tunnel_id_mask;
11585         cmdline_fixed_string_t tunnel_type;
11586         uint8_t tunnel_type_mask;
11587 };
11588
11589 static void
11590 cmd_flow_director_mask_parsed(void *parsed_result,
11591                           __attribute__((unused)) struct cmdline *cl,
11592                           __attribute__((unused)) void *data)
11593 {
11594         struct cmd_flow_director_mask_result *res = parsed_result;
11595         struct rte_eth_fdir_masks *mask;
11596         struct rte_port *port;
11597
11598         port = &ports[res->port_id];
11599         /** Check if the port is not started **/
11600         if (port->port_status != RTE_PORT_STOPPED) {
11601                 printf("Please stop port %d first\n", res->port_id);
11602                 return;
11603         }
11604
11605         mask = &port->dev_conf.fdir_conf.mask;
11606
11607         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11608                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11609                         printf("Please set mode to MAC-VLAN.\n");
11610                         return;
11611                 }
11612
11613                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11614         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11615                 if (strcmp(res->mode_value, "Tunnel")) {
11616                         printf("Please set mode to Tunnel.\n");
11617                         return;
11618                 }
11619
11620                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11621                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11622                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11623                 mask->tunnel_type_mask = res->tunnel_type_mask;
11624         } else {
11625                 if (strcmp(res->mode_value, "IP")) {
11626                         printf("Please set mode to IP.\n");
11627                         return;
11628                 }
11629
11630                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11631                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11632                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11633                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11634                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11635                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11636                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11637         }
11638
11639         cmd_reconfig_device_queue(res->port_id, 1, 1);
11640 }
11641
11642 cmdline_parse_token_string_t cmd_flow_director_mask =
11643         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11644                                  flow_director_mask, "flow_director_mask");
11645 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11646         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11647                               port_id, UINT16);
11648 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11649         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11650                                  vlan, "vlan");
11651 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11652         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11653                               vlan_mask, UINT16);
11654 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11655         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11656                                  src_mask, "src_mask");
11657 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11658         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11659                                  ipv4_src);
11660 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11661         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11662                                  ipv6_src);
11663 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11664         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11665                               port_src, UINT16);
11666 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11667         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11668                                  dst_mask, "dst_mask");
11669 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11670         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11671                                  ipv4_dst);
11672 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11673         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11674                                  ipv6_dst);
11675 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11676         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11677                               port_dst, UINT16);
11678
11679 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11680         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11681                                  mode, "mode");
11682 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11683         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11684                                  mode_value, "IP");
11685 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11686         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11687                                  mode_value, "MAC-VLAN");
11688 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11689         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11690                                  mode_value, "Tunnel");
11691 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11692         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11693                                  mac, "mac");
11694 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11695         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11696                               mac_addr_byte_mask, UINT8);
11697 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11698         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11699                                  tunnel_type, "tunnel-type");
11700 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11701         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11702                               tunnel_type_mask, UINT8);
11703 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11704         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11705                                  tunnel_id, "tunnel-id");
11706 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11707         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11708                               tunnel_id_mask, UINT32);
11709
11710 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11711         .f = cmd_flow_director_mask_parsed,
11712         .data = NULL,
11713         .help_str = "flow_director_mask ... : "
11714                 "Set IP mode flow director's mask on NIC",
11715         .tokens = {
11716                 (void *)&cmd_flow_director_mask,
11717                 (void *)&cmd_flow_director_mask_port_id,
11718                 (void *)&cmd_flow_director_mask_mode,
11719                 (void *)&cmd_flow_director_mask_mode_ip,
11720                 (void *)&cmd_flow_director_mask_vlan,
11721                 (void *)&cmd_flow_director_mask_vlan_value,
11722                 (void *)&cmd_flow_director_mask_src,
11723                 (void *)&cmd_flow_director_mask_ipv4_src,
11724                 (void *)&cmd_flow_director_mask_ipv6_src,
11725                 (void *)&cmd_flow_director_mask_port_src,
11726                 (void *)&cmd_flow_director_mask_dst,
11727                 (void *)&cmd_flow_director_mask_ipv4_dst,
11728                 (void *)&cmd_flow_director_mask_ipv6_dst,
11729                 (void *)&cmd_flow_director_mask_port_dst,
11730                 NULL,
11731         },
11732 };
11733
11734 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11735         .f = cmd_flow_director_mask_parsed,
11736         .data = NULL,
11737         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11738                 "flow director's mask on NIC",
11739         .tokens = {
11740                 (void *)&cmd_flow_director_mask,
11741                 (void *)&cmd_flow_director_mask_port_id,
11742                 (void *)&cmd_flow_director_mask_mode,
11743                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11744                 (void *)&cmd_flow_director_mask_vlan,
11745                 (void *)&cmd_flow_director_mask_vlan_value,
11746                 NULL,
11747         },
11748 };
11749
11750 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11751         .f = cmd_flow_director_mask_parsed,
11752         .data = NULL,
11753         .help_str = "flow_director_mask ... : Set tunnel mode "
11754                 "flow director's mask on NIC",
11755         .tokens = {
11756                 (void *)&cmd_flow_director_mask,
11757                 (void *)&cmd_flow_director_mask_port_id,
11758                 (void *)&cmd_flow_director_mask_mode,
11759                 (void *)&cmd_flow_director_mask_mode_tunnel,
11760                 (void *)&cmd_flow_director_mask_vlan,
11761                 (void *)&cmd_flow_director_mask_vlan_value,
11762                 (void *)&cmd_flow_director_mask_mac,
11763                 (void *)&cmd_flow_director_mask_mac_value,
11764                 (void *)&cmd_flow_director_mask_tunnel_type,
11765                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11766                 (void *)&cmd_flow_director_mask_tunnel_id,
11767                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11768                 NULL,
11769         },
11770 };
11771
11772 /* *** deal with flow director mask on flexible payload *** */
11773 struct cmd_flow_director_flex_mask_result {
11774         cmdline_fixed_string_t flow_director_flexmask;
11775         portid_t port_id;
11776         cmdline_fixed_string_t flow;
11777         cmdline_fixed_string_t flow_type;
11778         cmdline_fixed_string_t mask;
11779 };
11780
11781 static void
11782 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11783                           __attribute__((unused)) struct cmdline *cl,
11784                           __attribute__((unused)) void *data)
11785 {
11786         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11787         struct rte_eth_fdir_info fdir_info;
11788         struct rte_eth_fdir_flex_mask flex_mask;
11789         struct rte_port *port;
11790         uint64_t flow_type_mask;
11791         uint16_t i;
11792         int ret;
11793
11794         port = &ports[res->port_id];
11795         /** Check if the port is not started **/
11796         if (port->port_status != RTE_PORT_STOPPED) {
11797                 printf("Please stop port %d first\n", res->port_id);
11798                 return;
11799         }
11800
11801         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11802         ret = parse_flexbytes(res->mask,
11803                         flex_mask.mask,
11804                         RTE_ETH_FDIR_MAX_FLEXLEN);
11805         if (ret < 0) {
11806                 printf("error: Cannot parse mask input.\n");
11807                 return;
11808         }
11809
11810         memset(&fdir_info, 0, sizeof(fdir_info));
11811         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11812                                 RTE_ETH_FILTER_INFO, &fdir_info);
11813         if (ret < 0) {
11814                 printf("Cannot get FDir filter info\n");
11815                 return;
11816         }
11817
11818         if (!strcmp(res->flow_type, "none")) {
11819                 /* means don't specify the flow type */
11820                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11821                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11822                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11823                                0, sizeof(struct rte_eth_fdir_flex_mask));
11824                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11825                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11826                                  &flex_mask,
11827                                  sizeof(struct rte_eth_fdir_flex_mask));
11828                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11829                 return;
11830         }
11831         flow_type_mask = fdir_info.flow_types_mask[0];
11832         if (!strcmp(res->flow_type, "all")) {
11833                 if (!flow_type_mask) {
11834                         printf("No flow type supported\n");
11835                         return;
11836                 }
11837                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11838                         if (flow_type_mask & (1ULL << i)) {
11839                                 flex_mask.flow_type = i;
11840                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11841                         }
11842                 }
11843                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11844                 return;
11845         }
11846         flex_mask.flow_type = str2flowtype(res->flow_type);
11847         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11848                 printf("Flow type %s not supported on port %d\n",
11849                                 res->flow_type, res->port_id);
11850                 return;
11851         }
11852         fdir_set_flex_mask(res->port_id, &flex_mask);
11853         cmd_reconfig_device_queue(res->port_id, 1, 1);
11854 }
11855
11856 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11857         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11858                                  flow_director_flexmask,
11859                                  "flow_director_flex_mask");
11860 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11861         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11862                               port_id, UINT16);
11863 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11864         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11865                                  flow, "flow");
11866 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11867         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11868                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11869                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11870 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11871         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11872                                  mask, NULL);
11873
11874 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11875         .f = cmd_flow_director_flex_mask_parsed,
11876         .data = NULL,
11877         .help_str = "flow_director_flex_mask ... : "
11878                 "Set flow director's flex mask on NIC",
11879         .tokens = {
11880                 (void *)&cmd_flow_director_flexmask,
11881                 (void *)&cmd_flow_director_flexmask_port_id,
11882                 (void *)&cmd_flow_director_flexmask_flow,
11883                 (void *)&cmd_flow_director_flexmask_flow_type,
11884                 (void *)&cmd_flow_director_flexmask_mask,
11885                 NULL,
11886         },
11887 };
11888
11889 /* *** deal with flow director flexible payload configuration *** */
11890 struct cmd_flow_director_flexpayload_result {
11891         cmdline_fixed_string_t flow_director_flexpayload;
11892         portid_t port_id;
11893         cmdline_fixed_string_t payload_layer;
11894         cmdline_fixed_string_t payload_cfg;
11895 };
11896
11897 static inline int
11898 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11899 {
11900         char s[256];
11901         const char *p, *p0 = q_arg;
11902         char *end;
11903         unsigned long int_fld;
11904         char *str_fld[max_num];
11905         int i;
11906         unsigned size;
11907         int ret = -1;
11908
11909         p = strchr(p0, '(');
11910         if (p == NULL)
11911                 return -1;
11912         ++p;
11913         p0 = strchr(p, ')');
11914         if (p0 == NULL)
11915                 return -1;
11916
11917         size = p0 - p;
11918         if (size >= sizeof(s))
11919                 return -1;
11920
11921         snprintf(s, sizeof(s), "%.*s", size, p);
11922         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11923         if (ret < 0 || ret > max_num)
11924                 return -1;
11925         for (i = 0; i < ret; i++) {
11926                 errno = 0;
11927                 int_fld = strtoul(str_fld[i], &end, 0);
11928                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11929                         return -1;
11930                 offsets[i] = (uint16_t)int_fld;
11931         }
11932         return ret;
11933 }
11934
11935 static void
11936 cmd_flow_director_flxpld_parsed(void *parsed_result,
11937                           __attribute__((unused)) struct cmdline *cl,
11938                           __attribute__((unused)) void *data)
11939 {
11940         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11941         struct rte_eth_flex_payload_cfg flex_cfg;
11942         struct rte_port *port;
11943         int ret = 0;
11944
11945         port = &ports[res->port_id];
11946         /** Check if the port is not started **/
11947         if (port->port_status != RTE_PORT_STOPPED) {
11948                 printf("Please stop port %d first\n", res->port_id);
11949                 return;
11950         }
11951
11952         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11953
11954         if (!strcmp(res->payload_layer, "raw"))
11955                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11956         else if (!strcmp(res->payload_layer, "l2"))
11957                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11958         else if (!strcmp(res->payload_layer, "l3"))
11959                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11960         else if (!strcmp(res->payload_layer, "l4"))
11961                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11962
11963         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11964                             RTE_ETH_FDIR_MAX_FLEXLEN);
11965         if (ret < 0) {
11966                 printf("error: Cannot parse flex payload input.\n");
11967                 return;
11968         }
11969
11970         fdir_set_flex_payload(res->port_id, &flex_cfg);
11971         cmd_reconfig_device_queue(res->port_id, 1, 1);
11972 }
11973
11974 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11975         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11976                                  flow_director_flexpayload,
11977                                  "flow_director_flex_payload");
11978 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11979         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11980                               port_id, UINT16);
11981 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11982         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11983                                  payload_layer, "raw#l2#l3#l4");
11984 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11985         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11986                                  payload_cfg, NULL);
11987
11988 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11989         .f = cmd_flow_director_flxpld_parsed,
11990         .data = NULL,
11991         .help_str = "flow_director_flexpayload ... : "
11992                 "Set flow director's flex payload on NIC",
11993         .tokens = {
11994                 (void *)&cmd_flow_director_flexpayload,
11995                 (void *)&cmd_flow_director_flexpayload_port_id,
11996                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11997                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11998                 NULL,
11999         },
12000 };
12001
12002 /* Generic flow interface command. */
12003 extern cmdline_parse_inst_t cmd_flow;
12004
12005 /* *** Classification Filters Control *** */
12006 /* *** Get symmetric hash enable per port *** */
12007 struct cmd_get_sym_hash_ena_per_port_result {
12008         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12009         portid_t port_id;
12010 };
12011
12012 static void
12013 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12014                                  __rte_unused struct cmdline *cl,
12015                                  __rte_unused void *data)
12016 {
12017         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12018         struct rte_eth_hash_filter_info info;
12019         int ret;
12020
12021         if (rte_eth_dev_filter_supported(res->port_id,
12022                                 RTE_ETH_FILTER_HASH) < 0) {
12023                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12024                                                         res->port_id);
12025                 return;
12026         }
12027
12028         memset(&info, 0, sizeof(info));
12029         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12030         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12031                                                 RTE_ETH_FILTER_GET, &info);
12032
12033         if (ret < 0) {
12034                 printf("Cannot get symmetric hash enable per port "
12035                                         "on port %u\n", res->port_id);
12036                 return;
12037         }
12038
12039         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12040                                 "enabled" : "disabled", res->port_id);
12041 }
12042
12043 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12044         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12045                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12046 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12047         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12048                 port_id, UINT16);
12049
12050 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12051         .f = cmd_get_sym_hash_per_port_parsed,
12052         .data = NULL,
12053         .help_str = "get_sym_hash_ena_per_port <port_id>",
12054         .tokens = {
12055                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12056                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12057                 NULL,
12058         },
12059 };
12060
12061 /* *** Set symmetric hash enable per port *** */
12062 struct cmd_set_sym_hash_ena_per_port_result {
12063         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12064         cmdline_fixed_string_t enable;
12065         portid_t port_id;
12066 };
12067
12068 static void
12069 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12070                                  __rte_unused struct cmdline *cl,
12071                                  __rte_unused void *data)
12072 {
12073         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12074         struct rte_eth_hash_filter_info info;
12075         int ret;
12076
12077         if (rte_eth_dev_filter_supported(res->port_id,
12078                                 RTE_ETH_FILTER_HASH) < 0) {
12079                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12080                                                         res->port_id);
12081                 return;
12082         }
12083
12084         memset(&info, 0, sizeof(info));
12085         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12086         if (!strcmp(res->enable, "enable"))
12087                 info.info.enable = 1;
12088         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12089                                         RTE_ETH_FILTER_SET, &info);
12090         if (ret < 0) {
12091                 printf("Cannot set symmetric hash enable per port on "
12092                                         "port %u\n", res->port_id);
12093                 return;
12094         }
12095         printf("Symmetric hash has been set to %s on port %u\n",
12096                                         res->enable, res->port_id);
12097 }
12098
12099 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12100         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12101                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12102 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12103         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12104                 port_id, UINT16);
12105 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12106         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12107                 enable, "enable#disable");
12108
12109 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12110         .f = cmd_set_sym_hash_per_port_parsed,
12111         .data = NULL,
12112         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12113         .tokens = {
12114                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12115                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12116                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12117                 NULL,
12118         },
12119 };
12120
12121 /* Get global config of hash function */
12122 struct cmd_get_hash_global_config_result {
12123         cmdline_fixed_string_t get_hash_global_config;
12124         portid_t port_id;
12125 };
12126
12127 static char *
12128 flowtype_to_str(uint16_t ftype)
12129 {
12130         uint16_t i;
12131         static struct {
12132                 char str[16];
12133                 uint16_t ftype;
12134         } ftype_table[] = {
12135                 {"ipv4", RTE_ETH_FLOW_IPV4},
12136                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12137                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12138                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12139                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12140                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12141                 {"ipv6", RTE_ETH_FLOW_IPV6},
12142                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12143                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12144                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12145                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12146                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12147                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12148                 {"port", RTE_ETH_FLOW_PORT},
12149                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12150                 {"geneve", RTE_ETH_FLOW_GENEVE},
12151                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12152                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12153         };
12154
12155         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12156                 if (ftype_table[i].ftype == ftype)
12157                         return ftype_table[i].str;
12158         }
12159
12160         return NULL;
12161 }
12162
12163 static void
12164 cmd_get_hash_global_config_parsed(void *parsed_result,
12165                                   __rte_unused struct cmdline *cl,
12166                                   __rte_unused void *data)
12167 {
12168         struct cmd_get_hash_global_config_result *res = parsed_result;
12169         struct rte_eth_hash_filter_info info;
12170         uint32_t idx, offset;
12171         uint16_t i;
12172         char *str;
12173         int ret;
12174
12175         if (rte_eth_dev_filter_supported(res->port_id,
12176                         RTE_ETH_FILTER_HASH) < 0) {
12177                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12178                                                         res->port_id);
12179                 return;
12180         }
12181
12182         memset(&info, 0, sizeof(info));
12183         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12184         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12185                                         RTE_ETH_FILTER_GET, &info);
12186         if (ret < 0) {
12187                 printf("Cannot get hash global configurations by port %d\n",
12188                                                         res->port_id);
12189                 return;
12190         }
12191
12192         switch (info.info.global_conf.hash_func) {
12193         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12194                 printf("Hash function is Toeplitz\n");
12195                 break;
12196         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12197                 printf("Hash function is Simple XOR\n");
12198                 break;
12199         default:
12200                 printf("Unknown hash function\n");
12201                 break;
12202         }
12203
12204         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12205                 idx = i / UINT64_BIT;
12206                 offset = i % UINT64_BIT;
12207                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12208                                                 (1ULL << offset)))
12209                         continue;
12210                 str = flowtype_to_str(i);
12211                 if (!str)
12212                         continue;
12213                 printf("Symmetric hash is %s globally for flow type %s "
12214                                                         "by port %d\n",
12215                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12216                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12217                                                         res->port_id);
12218         }
12219 }
12220
12221 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12222         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12223                 get_hash_global_config, "get_hash_global_config");
12224 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12225         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12226                 port_id, UINT16);
12227
12228 cmdline_parse_inst_t cmd_get_hash_global_config = {
12229         .f = cmd_get_hash_global_config_parsed,
12230         .data = NULL,
12231         .help_str = "get_hash_global_config <port_id>",
12232         .tokens = {
12233                 (void *)&cmd_get_hash_global_config_all,
12234                 (void *)&cmd_get_hash_global_config_port_id,
12235                 NULL,
12236         },
12237 };
12238
12239 /* Set global config of hash function */
12240 struct cmd_set_hash_global_config_result {
12241         cmdline_fixed_string_t set_hash_global_config;
12242         portid_t port_id;
12243         cmdline_fixed_string_t hash_func;
12244         cmdline_fixed_string_t flow_type;
12245         cmdline_fixed_string_t enable;
12246 };
12247
12248 static void
12249 cmd_set_hash_global_config_parsed(void *parsed_result,
12250                                   __rte_unused struct cmdline *cl,
12251                                   __rte_unused void *data)
12252 {
12253         struct cmd_set_hash_global_config_result *res = parsed_result;
12254         struct rte_eth_hash_filter_info info;
12255         uint32_t ftype, idx, offset;
12256         int ret;
12257
12258         if (rte_eth_dev_filter_supported(res->port_id,
12259                                 RTE_ETH_FILTER_HASH) < 0) {
12260                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12261                                                         res->port_id);
12262                 return;
12263         }
12264         memset(&info, 0, sizeof(info));
12265         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12266         if (!strcmp(res->hash_func, "toeplitz"))
12267                 info.info.global_conf.hash_func =
12268                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12269         else if (!strcmp(res->hash_func, "simple_xor"))
12270                 info.info.global_conf.hash_func =
12271                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12272         else if (!strcmp(res->hash_func, "default"))
12273                 info.info.global_conf.hash_func =
12274                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12275
12276         ftype = str2flowtype(res->flow_type);
12277         idx = ftype / UINT64_BIT;
12278         offset = ftype % UINT64_BIT;
12279         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12280         if (!strcmp(res->enable, "enable"))
12281                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12282                                                 (1ULL << offset);
12283         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12284                                         RTE_ETH_FILTER_SET, &info);
12285         if (ret < 0)
12286                 printf("Cannot set global hash configurations by port %d\n",
12287                                                         res->port_id);
12288         else
12289                 printf("Global hash configurations have been set "
12290                         "successfully by port %d\n", res->port_id);
12291 }
12292
12293 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12294         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12295                 set_hash_global_config, "set_hash_global_config");
12296 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12297         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12298                 port_id, UINT16);
12299 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12300         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12301                 hash_func, "toeplitz#simple_xor#default");
12302 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12303         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12304                 flow_type,
12305                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12306                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12307 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12308         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12309                 enable, "enable#disable");
12310
12311 cmdline_parse_inst_t cmd_set_hash_global_config = {
12312         .f = cmd_set_hash_global_config_parsed,
12313         .data = NULL,
12314         .help_str = "set_hash_global_config <port_id> "
12315                 "toeplitz|simple_xor|default "
12316                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12317                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12318                 "l2_payload enable|disable",
12319         .tokens = {
12320                 (void *)&cmd_set_hash_global_config_all,
12321                 (void *)&cmd_set_hash_global_config_port_id,
12322                 (void *)&cmd_set_hash_global_config_hash_func,
12323                 (void *)&cmd_set_hash_global_config_flow_type,
12324                 (void *)&cmd_set_hash_global_config_enable,
12325                 NULL,
12326         },
12327 };
12328
12329 /* Set hash input set */
12330 struct cmd_set_hash_input_set_result {
12331         cmdline_fixed_string_t set_hash_input_set;
12332         portid_t port_id;
12333         cmdline_fixed_string_t flow_type;
12334         cmdline_fixed_string_t inset_field;
12335         cmdline_fixed_string_t select;
12336 };
12337
12338 static enum rte_eth_input_set_field
12339 str2inset(char *string)
12340 {
12341         uint16_t i;
12342
12343         static const struct {
12344                 char str[32];
12345                 enum rte_eth_input_set_field inset;
12346         } inset_table[] = {
12347                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12348                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12349                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12350                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12351                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12352                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12353                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12354                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12355                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12356                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12357                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12358                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12359                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12360                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12361                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12362                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12363                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12364                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12365                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12366                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12367                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12368                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12369                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12370                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12371                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12372                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12373                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12374                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12375                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12376                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12377                 {"none", RTE_ETH_INPUT_SET_NONE},
12378         };
12379
12380         for (i = 0; i < RTE_DIM(inset_table); i++) {
12381                 if (!strcmp(string, inset_table[i].str))
12382                         return inset_table[i].inset;
12383         }
12384
12385         return RTE_ETH_INPUT_SET_UNKNOWN;
12386 }
12387
12388 static void
12389 cmd_set_hash_input_set_parsed(void *parsed_result,
12390                               __rte_unused struct cmdline *cl,
12391                               __rte_unused void *data)
12392 {
12393         struct cmd_set_hash_input_set_result *res = parsed_result;
12394         struct rte_eth_hash_filter_info info;
12395
12396         memset(&info, 0, sizeof(info));
12397         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12398         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12399         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12400         info.info.input_set_conf.inset_size = 1;
12401         if (!strcmp(res->select, "select"))
12402                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12403         else if (!strcmp(res->select, "add"))
12404                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12405         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12406                                 RTE_ETH_FILTER_SET, &info);
12407 }
12408
12409 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12410         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12411                 set_hash_input_set, "set_hash_input_set");
12412 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12413         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12414                 port_id, UINT16);
12415 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12416         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12417                 flow_type, NULL);
12418 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12419         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12420                 inset_field,
12421                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12422                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12423                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12424                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12425                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12426                 "fld-8th#none");
12427 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12428         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12429                 select, "select#add");
12430
12431 cmdline_parse_inst_t cmd_set_hash_input_set = {
12432         .f = cmd_set_hash_input_set_parsed,
12433         .data = NULL,
12434         .help_str = "set_hash_input_set <port_id> "
12435         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12436         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12437         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12438         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12439         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12440         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12441         "fld-7th|fld-8th|none select|add",
12442         .tokens = {
12443                 (void *)&cmd_set_hash_input_set_cmd,
12444                 (void *)&cmd_set_hash_input_set_port_id,
12445                 (void *)&cmd_set_hash_input_set_flow_type,
12446                 (void *)&cmd_set_hash_input_set_field,
12447                 (void *)&cmd_set_hash_input_set_select,
12448                 NULL,
12449         },
12450 };
12451
12452 /* Set flow director input set */
12453 struct cmd_set_fdir_input_set_result {
12454         cmdline_fixed_string_t set_fdir_input_set;
12455         portid_t port_id;
12456         cmdline_fixed_string_t flow_type;
12457         cmdline_fixed_string_t inset_field;
12458         cmdline_fixed_string_t select;
12459 };
12460
12461 static void
12462 cmd_set_fdir_input_set_parsed(void *parsed_result,
12463         __rte_unused struct cmdline *cl,
12464         __rte_unused void *data)
12465 {
12466         struct cmd_set_fdir_input_set_result *res = parsed_result;
12467         struct rte_eth_fdir_filter_info info;
12468
12469         memset(&info, 0, sizeof(info));
12470         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12471         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12472         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12473         info.info.input_set_conf.inset_size = 1;
12474         if (!strcmp(res->select, "select"))
12475                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12476         else if (!strcmp(res->select, "add"))
12477                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12478         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12479                 RTE_ETH_FILTER_SET, &info);
12480 }
12481
12482 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12483         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12484         set_fdir_input_set, "set_fdir_input_set");
12485 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12486         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12487         port_id, UINT16);
12488 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12489         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12490         flow_type,
12491         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12492         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12493 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12494         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12495         inset_field,
12496         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12497         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12498         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12499         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12500         "sctp-veri-tag#none");
12501 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12502         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12503         select, "select#add");
12504
12505 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12506         .f = cmd_set_fdir_input_set_parsed,
12507         .data = NULL,
12508         .help_str = "set_fdir_input_set <port_id> "
12509         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12510         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12511         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12512         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12513         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12514         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12515         "sctp-veri-tag|none select|add",
12516         .tokens = {
12517                 (void *)&cmd_set_fdir_input_set_cmd,
12518                 (void *)&cmd_set_fdir_input_set_port_id,
12519                 (void *)&cmd_set_fdir_input_set_flow_type,
12520                 (void *)&cmd_set_fdir_input_set_field,
12521                 (void *)&cmd_set_fdir_input_set_select,
12522                 NULL,
12523         },
12524 };
12525
12526 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12527 struct cmd_mcast_addr_result {
12528         cmdline_fixed_string_t mcast_addr_cmd;
12529         cmdline_fixed_string_t what;
12530         uint16_t port_num;
12531         struct rte_ether_addr mc_addr;
12532 };
12533
12534 static void cmd_mcast_addr_parsed(void *parsed_result,
12535                 __attribute__((unused)) struct cmdline *cl,
12536                 __attribute__((unused)) void *data)
12537 {
12538         struct cmd_mcast_addr_result *res = parsed_result;
12539
12540         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12541                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12542                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12543                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12544                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12545                 return;
12546         }
12547         if (strcmp(res->what, "add") == 0)
12548                 mcast_addr_add(res->port_num, &res->mc_addr);
12549         else
12550                 mcast_addr_remove(res->port_num, &res->mc_addr);
12551 }
12552
12553 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12554         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12555                                  mcast_addr_cmd, "mcast_addr");
12556 cmdline_parse_token_string_t cmd_mcast_addr_what =
12557         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12558                                  "add#remove");
12559 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12560         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12561 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12562         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12563
12564 cmdline_parse_inst_t cmd_mcast_addr = {
12565         .f = cmd_mcast_addr_parsed,
12566         .data = (void *)0,
12567         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12568                 "Add/Remove multicast MAC address on port_id",
12569         .tokens = {
12570                 (void *)&cmd_mcast_addr_cmd,
12571                 (void *)&cmd_mcast_addr_what,
12572                 (void *)&cmd_mcast_addr_portnum,
12573                 (void *)&cmd_mcast_addr_addr,
12574                 NULL,
12575         },
12576 };
12577
12578 /* l2 tunnel config
12579  * only support E-tag now.
12580  */
12581
12582 /* Ether type config */
12583 struct cmd_config_l2_tunnel_eth_type_result {
12584         cmdline_fixed_string_t port;
12585         cmdline_fixed_string_t config;
12586         cmdline_fixed_string_t all;
12587         portid_t id;
12588         cmdline_fixed_string_t l2_tunnel;
12589         cmdline_fixed_string_t l2_tunnel_type;
12590         cmdline_fixed_string_t eth_type;
12591         uint16_t eth_type_val;
12592 };
12593
12594 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12595         TOKEN_STRING_INITIALIZER
12596                 (struct cmd_config_l2_tunnel_eth_type_result,
12597                  port, "port");
12598 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12599         TOKEN_STRING_INITIALIZER
12600                 (struct cmd_config_l2_tunnel_eth_type_result,
12601                  config, "config");
12602 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12603         TOKEN_STRING_INITIALIZER
12604                 (struct cmd_config_l2_tunnel_eth_type_result,
12605                  all, "all");
12606 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12607         TOKEN_NUM_INITIALIZER
12608                 (struct cmd_config_l2_tunnel_eth_type_result,
12609                  id, UINT16);
12610 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12611         TOKEN_STRING_INITIALIZER
12612                 (struct cmd_config_l2_tunnel_eth_type_result,
12613                  l2_tunnel, "l2-tunnel");
12614 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12615         TOKEN_STRING_INITIALIZER
12616                 (struct cmd_config_l2_tunnel_eth_type_result,
12617                  l2_tunnel_type, "E-tag");
12618 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12619         TOKEN_STRING_INITIALIZER
12620                 (struct cmd_config_l2_tunnel_eth_type_result,
12621                  eth_type, "ether-type");
12622 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12623         TOKEN_NUM_INITIALIZER
12624                 (struct cmd_config_l2_tunnel_eth_type_result,
12625                  eth_type_val, UINT16);
12626
12627 static enum rte_eth_tunnel_type
12628 str2fdir_l2_tunnel_type(char *string)
12629 {
12630         uint32_t i = 0;
12631
12632         static const struct {
12633                 char str[32];
12634                 enum rte_eth_tunnel_type type;
12635         } l2_tunnel_type_str[] = {
12636                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12637         };
12638
12639         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12640                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12641                         return l2_tunnel_type_str[i].type;
12642         }
12643         return RTE_TUNNEL_TYPE_NONE;
12644 }
12645
12646 /* ether type config for all ports */
12647 static void
12648 cmd_config_l2_tunnel_eth_type_all_parsed
12649         (void *parsed_result,
12650          __attribute__((unused)) struct cmdline *cl,
12651          __attribute__((unused)) void *data)
12652 {
12653         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12654         struct rte_eth_l2_tunnel_conf entry;
12655         portid_t pid;
12656
12657         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12658         entry.ether_type = res->eth_type_val;
12659
12660         RTE_ETH_FOREACH_DEV(pid) {
12661                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12662         }
12663 }
12664
12665 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12666         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12667         .data = NULL,
12668         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12669         .tokens = {
12670                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12671                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12672                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12673                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12674                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12675                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12676                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12677                 NULL,
12678         },
12679 };
12680
12681 /* ether type config for a specific port */
12682 static void
12683 cmd_config_l2_tunnel_eth_type_specific_parsed(
12684         void *parsed_result,
12685         __attribute__((unused)) struct cmdline *cl,
12686         __attribute__((unused)) void *data)
12687 {
12688         struct cmd_config_l2_tunnel_eth_type_result *res =
12689                  parsed_result;
12690         struct rte_eth_l2_tunnel_conf entry;
12691
12692         if (port_id_is_invalid(res->id, ENABLED_WARN))
12693                 return;
12694
12695         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12696         entry.ether_type = res->eth_type_val;
12697
12698         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12699 }
12700
12701 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12702         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12703         .data = NULL,
12704         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12705         .tokens = {
12706                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12707                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12708                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12709                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12710                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12711                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12712                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12713                 NULL,
12714         },
12715 };
12716
12717 /* Enable/disable l2 tunnel */
12718 struct cmd_config_l2_tunnel_en_dis_result {
12719         cmdline_fixed_string_t port;
12720         cmdline_fixed_string_t config;
12721         cmdline_fixed_string_t all;
12722         portid_t id;
12723         cmdline_fixed_string_t l2_tunnel;
12724         cmdline_fixed_string_t l2_tunnel_type;
12725         cmdline_fixed_string_t en_dis;
12726 };
12727
12728 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12729         TOKEN_STRING_INITIALIZER
12730                 (struct cmd_config_l2_tunnel_en_dis_result,
12731                  port, "port");
12732 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12733         TOKEN_STRING_INITIALIZER
12734                 (struct cmd_config_l2_tunnel_en_dis_result,
12735                  config, "config");
12736 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12737         TOKEN_STRING_INITIALIZER
12738                 (struct cmd_config_l2_tunnel_en_dis_result,
12739                  all, "all");
12740 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12741         TOKEN_NUM_INITIALIZER
12742                 (struct cmd_config_l2_tunnel_en_dis_result,
12743                  id, UINT16);
12744 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12745         TOKEN_STRING_INITIALIZER
12746                 (struct cmd_config_l2_tunnel_en_dis_result,
12747                  l2_tunnel, "l2-tunnel");
12748 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12749         TOKEN_STRING_INITIALIZER
12750                 (struct cmd_config_l2_tunnel_en_dis_result,
12751                  l2_tunnel_type, "E-tag");
12752 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12753         TOKEN_STRING_INITIALIZER
12754                 (struct cmd_config_l2_tunnel_en_dis_result,
12755                  en_dis, "enable#disable");
12756
12757 /* enable/disable l2 tunnel for all ports */
12758 static void
12759 cmd_config_l2_tunnel_en_dis_all_parsed(
12760         void *parsed_result,
12761         __attribute__((unused)) struct cmdline *cl,
12762         __attribute__((unused)) void *data)
12763 {
12764         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12765         struct rte_eth_l2_tunnel_conf entry;
12766         portid_t pid;
12767         uint8_t en;
12768
12769         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12770
12771         if (!strcmp("enable", res->en_dis))
12772                 en = 1;
12773         else
12774                 en = 0;
12775
12776         RTE_ETH_FOREACH_DEV(pid) {
12777                 rte_eth_dev_l2_tunnel_offload_set(pid,
12778                                                   &entry,
12779                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12780                                                   en);
12781         }
12782 }
12783
12784 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12785         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12786         .data = NULL,
12787         .help_str = "port config all l2-tunnel E-tag enable|disable",
12788         .tokens = {
12789                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12790                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12791                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12792                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12793                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12794                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12795                 NULL,
12796         },
12797 };
12798
12799 /* enable/disable l2 tunnel for a port */
12800 static void
12801 cmd_config_l2_tunnel_en_dis_specific_parsed(
12802         void *parsed_result,
12803         __attribute__((unused)) struct cmdline *cl,
12804         __attribute__((unused)) void *data)
12805 {
12806         struct cmd_config_l2_tunnel_en_dis_result *res =
12807                 parsed_result;
12808         struct rte_eth_l2_tunnel_conf entry;
12809
12810         if (port_id_is_invalid(res->id, ENABLED_WARN))
12811                 return;
12812
12813         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12814
12815         if (!strcmp("enable", res->en_dis))
12816                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12817                                                   &entry,
12818                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12819                                                   1);
12820         else
12821                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12822                                                   &entry,
12823                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12824                                                   0);
12825 }
12826
12827 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12828         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12829         .data = NULL,
12830         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12831         .tokens = {
12832                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12833                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12834                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12835                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12836                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12837                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12838                 NULL,
12839         },
12840 };
12841
12842 /* E-tag configuration */
12843
12844 /* Common result structure for all E-tag configuration */
12845 struct cmd_config_e_tag_result {
12846         cmdline_fixed_string_t e_tag;
12847         cmdline_fixed_string_t set;
12848         cmdline_fixed_string_t insertion;
12849         cmdline_fixed_string_t stripping;
12850         cmdline_fixed_string_t forwarding;
12851         cmdline_fixed_string_t filter;
12852         cmdline_fixed_string_t add;
12853         cmdline_fixed_string_t del;
12854         cmdline_fixed_string_t on;
12855         cmdline_fixed_string_t off;
12856         cmdline_fixed_string_t on_off;
12857         cmdline_fixed_string_t port_tag_id;
12858         uint32_t port_tag_id_val;
12859         cmdline_fixed_string_t e_tag_id;
12860         uint16_t e_tag_id_val;
12861         cmdline_fixed_string_t dst_pool;
12862         uint8_t dst_pool_val;
12863         cmdline_fixed_string_t port;
12864         portid_t port_id;
12865         cmdline_fixed_string_t vf;
12866         uint8_t vf_id;
12867 };
12868
12869 /* Common CLI fields for all E-tag configuration */
12870 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12871         TOKEN_STRING_INITIALIZER
12872                 (struct cmd_config_e_tag_result,
12873                  e_tag, "E-tag");
12874 cmdline_parse_token_string_t cmd_config_e_tag_set =
12875         TOKEN_STRING_INITIALIZER
12876                 (struct cmd_config_e_tag_result,
12877                  set, "set");
12878 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12879         TOKEN_STRING_INITIALIZER
12880                 (struct cmd_config_e_tag_result,
12881                  insertion, "insertion");
12882 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12883         TOKEN_STRING_INITIALIZER
12884                 (struct cmd_config_e_tag_result,
12885                  stripping, "stripping");
12886 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12887         TOKEN_STRING_INITIALIZER
12888                 (struct cmd_config_e_tag_result,
12889                  forwarding, "forwarding");
12890 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12891         TOKEN_STRING_INITIALIZER
12892                 (struct cmd_config_e_tag_result,
12893                  filter, "filter");
12894 cmdline_parse_token_string_t cmd_config_e_tag_add =
12895         TOKEN_STRING_INITIALIZER
12896                 (struct cmd_config_e_tag_result,
12897                  add, "add");
12898 cmdline_parse_token_string_t cmd_config_e_tag_del =
12899         TOKEN_STRING_INITIALIZER
12900                 (struct cmd_config_e_tag_result,
12901                  del, "del");
12902 cmdline_parse_token_string_t cmd_config_e_tag_on =
12903         TOKEN_STRING_INITIALIZER
12904                 (struct cmd_config_e_tag_result,
12905                  on, "on");
12906 cmdline_parse_token_string_t cmd_config_e_tag_off =
12907         TOKEN_STRING_INITIALIZER
12908                 (struct cmd_config_e_tag_result,
12909                  off, "off");
12910 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12911         TOKEN_STRING_INITIALIZER
12912                 (struct cmd_config_e_tag_result,
12913                  on_off, "on#off");
12914 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12915         TOKEN_STRING_INITIALIZER
12916                 (struct cmd_config_e_tag_result,
12917                  port_tag_id, "port-tag-id");
12918 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12919         TOKEN_NUM_INITIALIZER
12920                 (struct cmd_config_e_tag_result,
12921                  port_tag_id_val, UINT32);
12922 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12923         TOKEN_STRING_INITIALIZER
12924                 (struct cmd_config_e_tag_result,
12925                  e_tag_id, "e-tag-id");
12926 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12927         TOKEN_NUM_INITIALIZER
12928                 (struct cmd_config_e_tag_result,
12929                  e_tag_id_val, UINT16);
12930 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12931         TOKEN_STRING_INITIALIZER
12932                 (struct cmd_config_e_tag_result,
12933                  dst_pool, "dst-pool");
12934 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12935         TOKEN_NUM_INITIALIZER
12936                 (struct cmd_config_e_tag_result,
12937                  dst_pool_val, UINT8);
12938 cmdline_parse_token_string_t cmd_config_e_tag_port =
12939         TOKEN_STRING_INITIALIZER
12940                 (struct cmd_config_e_tag_result,
12941                  port, "port");
12942 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12943         TOKEN_NUM_INITIALIZER
12944                 (struct cmd_config_e_tag_result,
12945                  port_id, UINT16);
12946 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12947         TOKEN_STRING_INITIALIZER
12948                 (struct cmd_config_e_tag_result,
12949                  vf, "vf");
12950 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12951         TOKEN_NUM_INITIALIZER
12952                 (struct cmd_config_e_tag_result,
12953                  vf_id, UINT8);
12954
12955 /* E-tag insertion configuration */
12956 static void
12957 cmd_config_e_tag_insertion_en_parsed(
12958         void *parsed_result,
12959         __attribute__((unused)) struct cmdline *cl,
12960         __attribute__((unused)) void *data)
12961 {
12962         struct cmd_config_e_tag_result *res =
12963                 parsed_result;
12964         struct rte_eth_l2_tunnel_conf entry;
12965
12966         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12967                 return;
12968
12969         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12970         entry.tunnel_id = res->port_tag_id_val;
12971         entry.vf_id = res->vf_id;
12972         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12973                                           &entry,
12974                                           ETH_L2_TUNNEL_INSERTION_MASK,
12975                                           1);
12976 }
12977
12978 static void
12979 cmd_config_e_tag_insertion_dis_parsed(
12980         void *parsed_result,
12981         __attribute__((unused)) struct cmdline *cl,
12982         __attribute__((unused)) void *data)
12983 {
12984         struct cmd_config_e_tag_result *res =
12985                 parsed_result;
12986         struct rte_eth_l2_tunnel_conf entry;
12987
12988         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12989                 return;
12990
12991         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12992         entry.vf_id = res->vf_id;
12993
12994         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12995                                           &entry,
12996                                           ETH_L2_TUNNEL_INSERTION_MASK,
12997                                           0);
12998 }
12999
13000 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13001         .f = cmd_config_e_tag_insertion_en_parsed,
13002         .data = NULL,
13003         .help_str = "E-tag ... : E-tag insertion enable",
13004         .tokens = {
13005                 (void *)&cmd_config_e_tag_e_tag,
13006                 (void *)&cmd_config_e_tag_set,
13007                 (void *)&cmd_config_e_tag_insertion,
13008                 (void *)&cmd_config_e_tag_on,
13009                 (void *)&cmd_config_e_tag_port_tag_id,
13010                 (void *)&cmd_config_e_tag_port_tag_id_val,
13011                 (void *)&cmd_config_e_tag_port,
13012                 (void *)&cmd_config_e_tag_port_id,
13013                 (void *)&cmd_config_e_tag_vf,
13014                 (void *)&cmd_config_e_tag_vf_id,
13015                 NULL,
13016         },
13017 };
13018
13019 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13020         .f = cmd_config_e_tag_insertion_dis_parsed,
13021         .data = NULL,
13022         .help_str = "E-tag ... : E-tag insertion disable",
13023         .tokens = {
13024                 (void *)&cmd_config_e_tag_e_tag,
13025                 (void *)&cmd_config_e_tag_set,
13026                 (void *)&cmd_config_e_tag_insertion,
13027                 (void *)&cmd_config_e_tag_off,
13028                 (void *)&cmd_config_e_tag_port,
13029                 (void *)&cmd_config_e_tag_port_id,
13030                 (void *)&cmd_config_e_tag_vf,
13031                 (void *)&cmd_config_e_tag_vf_id,
13032                 NULL,
13033         },
13034 };
13035
13036 /* E-tag stripping configuration */
13037 static void
13038 cmd_config_e_tag_stripping_parsed(
13039         void *parsed_result,
13040         __attribute__((unused)) struct cmdline *cl,
13041         __attribute__((unused)) void *data)
13042 {
13043         struct cmd_config_e_tag_result *res =
13044                 parsed_result;
13045         struct rte_eth_l2_tunnel_conf entry;
13046
13047         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13048                 return;
13049
13050         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13051
13052         if (!strcmp(res->on_off, "on"))
13053                 rte_eth_dev_l2_tunnel_offload_set
13054                         (res->port_id,
13055                          &entry,
13056                          ETH_L2_TUNNEL_STRIPPING_MASK,
13057                          1);
13058         else
13059                 rte_eth_dev_l2_tunnel_offload_set
13060                         (res->port_id,
13061                          &entry,
13062                          ETH_L2_TUNNEL_STRIPPING_MASK,
13063                          0);
13064 }
13065
13066 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13067         .f = cmd_config_e_tag_stripping_parsed,
13068         .data = NULL,
13069         .help_str = "E-tag ... : E-tag stripping enable/disable",
13070         .tokens = {
13071                 (void *)&cmd_config_e_tag_e_tag,
13072                 (void *)&cmd_config_e_tag_set,
13073                 (void *)&cmd_config_e_tag_stripping,
13074                 (void *)&cmd_config_e_tag_on_off,
13075                 (void *)&cmd_config_e_tag_port,
13076                 (void *)&cmd_config_e_tag_port_id,
13077                 NULL,
13078         },
13079 };
13080
13081 /* E-tag forwarding configuration */
13082 static void
13083 cmd_config_e_tag_forwarding_parsed(
13084         void *parsed_result,
13085         __attribute__((unused)) struct cmdline *cl,
13086         __attribute__((unused)) void *data)
13087 {
13088         struct cmd_config_e_tag_result *res = parsed_result;
13089         struct rte_eth_l2_tunnel_conf entry;
13090
13091         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13092                 return;
13093
13094         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13095
13096         if (!strcmp(res->on_off, "on"))
13097                 rte_eth_dev_l2_tunnel_offload_set
13098                         (res->port_id,
13099                          &entry,
13100                          ETH_L2_TUNNEL_FORWARDING_MASK,
13101                          1);
13102         else
13103                 rte_eth_dev_l2_tunnel_offload_set
13104                         (res->port_id,
13105                          &entry,
13106                          ETH_L2_TUNNEL_FORWARDING_MASK,
13107                          0);
13108 }
13109
13110 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13111         .f = cmd_config_e_tag_forwarding_parsed,
13112         .data = NULL,
13113         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13114         .tokens = {
13115                 (void *)&cmd_config_e_tag_e_tag,
13116                 (void *)&cmd_config_e_tag_set,
13117                 (void *)&cmd_config_e_tag_forwarding,
13118                 (void *)&cmd_config_e_tag_on_off,
13119                 (void *)&cmd_config_e_tag_port,
13120                 (void *)&cmd_config_e_tag_port_id,
13121                 NULL,
13122         },
13123 };
13124
13125 /* E-tag filter configuration */
13126 static void
13127 cmd_config_e_tag_filter_add_parsed(
13128         void *parsed_result,
13129         __attribute__((unused)) struct cmdline *cl,
13130         __attribute__((unused)) void *data)
13131 {
13132         struct cmd_config_e_tag_result *res = parsed_result;
13133         struct rte_eth_l2_tunnel_conf entry;
13134         int ret = 0;
13135
13136         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13137                 return;
13138
13139         if (res->e_tag_id_val > 0x3fff) {
13140                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13141                 return;
13142         }
13143
13144         ret = rte_eth_dev_filter_supported(res->port_id,
13145                                            RTE_ETH_FILTER_L2_TUNNEL);
13146         if (ret < 0) {
13147                 printf("E-tag filter is not supported on port %u.\n",
13148                        res->port_id);
13149                 return;
13150         }
13151
13152         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13153         entry.tunnel_id = res->e_tag_id_val;
13154         entry.pool = res->dst_pool_val;
13155
13156         ret = rte_eth_dev_filter_ctrl(res->port_id,
13157                                       RTE_ETH_FILTER_L2_TUNNEL,
13158                                       RTE_ETH_FILTER_ADD,
13159                                       &entry);
13160         if (ret < 0)
13161                 printf("E-tag filter programming error: (%s)\n",
13162                        strerror(-ret));
13163 }
13164
13165 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13166         .f = cmd_config_e_tag_filter_add_parsed,
13167         .data = NULL,
13168         .help_str = "E-tag ... : E-tag filter add",
13169         .tokens = {
13170                 (void *)&cmd_config_e_tag_e_tag,
13171                 (void *)&cmd_config_e_tag_set,
13172                 (void *)&cmd_config_e_tag_filter,
13173                 (void *)&cmd_config_e_tag_add,
13174                 (void *)&cmd_config_e_tag_e_tag_id,
13175                 (void *)&cmd_config_e_tag_e_tag_id_val,
13176                 (void *)&cmd_config_e_tag_dst_pool,
13177                 (void *)&cmd_config_e_tag_dst_pool_val,
13178                 (void *)&cmd_config_e_tag_port,
13179                 (void *)&cmd_config_e_tag_port_id,
13180                 NULL,
13181         },
13182 };
13183
13184 static void
13185 cmd_config_e_tag_filter_del_parsed(
13186         void *parsed_result,
13187         __attribute__((unused)) struct cmdline *cl,
13188         __attribute__((unused)) void *data)
13189 {
13190         struct cmd_config_e_tag_result *res = parsed_result;
13191         struct rte_eth_l2_tunnel_conf entry;
13192         int ret = 0;
13193
13194         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13195                 return;
13196
13197         if (res->e_tag_id_val > 0x3fff) {
13198                 printf("e-tag-id must be less than 0x3fff.\n");
13199                 return;
13200         }
13201
13202         ret = rte_eth_dev_filter_supported(res->port_id,
13203                                            RTE_ETH_FILTER_L2_TUNNEL);
13204         if (ret < 0) {
13205                 printf("E-tag filter is not supported on port %u.\n",
13206                        res->port_id);
13207                 return;
13208         }
13209
13210         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13211         entry.tunnel_id = res->e_tag_id_val;
13212
13213         ret = rte_eth_dev_filter_ctrl(res->port_id,
13214                                       RTE_ETH_FILTER_L2_TUNNEL,
13215                                       RTE_ETH_FILTER_DELETE,
13216                                       &entry);
13217         if (ret < 0)
13218                 printf("E-tag filter programming error: (%s)\n",
13219                        strerror(-ret));
13220 }
13221
13222 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13223         .f = cmd_config_e_tag_filter_del_parsed,
13224         .data = NULL,
13225         .help_str = "E-tag ... : E-tag filter delete",
13226         .tokens = {
13227                 (void *)&cmd_config_e_tag_e_tag,
13228                 (void *)&cmd_config_e_tag_set,
13229                 (void *)&cmd_config_e_tag_filter,
13230                 (void *)&cmd_config_e_tag_del,
13231                 (void *)&cmd_config_e_tag_e_tag_id,
13232                 (void *)&cmd_config_e_tag_e_tag_id_val,
13233                 (void *)&cmd_config_e_tag_port,
13234                 (void *)&cmd_config_e_tag_port_id,
13235                 NULL,
13236         },
13237 };
13238
13239 /* vf vlan anti spoof configuration */
13240
13241 /* Common result structure for vf vlan anti spoof */
13242 struct cmd_vf_vlan_anti_spoof_result {
13243         cmdline_fixed_string_t set;
13244         cmdline_fixed_string_t vf;
13245         cmdline_fixed_string_t vlan;
13246         cmdline_fixed_string_t antispoof;
13247         portid_t port_id;
13248         uint32_t vf_id;
13249         cmdline_fixed_string_t on_off;
13250 };
13251
13252 /* Common CLI fields for vf vlan anti spoof enable disable */
13253 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13254         TOKEN_STRING_INITIALIZER
13255                 (struct cmd_vf_vlan_anti_spoof_result,
13256                  set, "set");
13257 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13258         TOKEN_STRING_INITIALIZER
13259                 (struct cmd_vf_vlan_anti_spoof_result,
13260                  vf, "vf");
13261 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13262         TOKEN_STRING_INITIALIZER
13263                 (struct cmd_vf_vlan_anti_spoof_result,
13264                  vlan, "vlan");
13265 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13266         TOKEN_STRING_INITIALIZER
13267                 (struct cmd_vf_vlan_anti_spoof_result,
13268                  antispoof, "antispoof");
13269 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13270         TOKEN_NUM_INITIALIZER
13271                 (struct cmd_vf_vlan_anti_spoof_result,
13272                  port_id, UINT16);
13273 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13274         TOKEN_NUM_INITIALIZER
13275                 (struct cmd_vf_vlan_anti_spoof_result,
13276                  vf_id, UINT32);
13277 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13278         TOKEN_STRING_INITIALIZER
13279                 (struct cmd_vf_vlan_anti_spoof_result,
13280                  on_off, "on#off");
13281
13282 static void
13283 cmd_set_vf_vlan_anti_spoof_parsed(
13284         void *parsed_result,
13285         __attribute__((unused)) struct cmdline *cl,
13286         __attribute__((unused)) void *data)
13287 {
13288         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13289         int ret = -ENOTSUP;
13290
13291         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13292
13293         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13294                 return;
13295
13296 #ifdef RTE_LIBRTE_IXGBE_PMD
13297         if (ret == -ENOTSUP)
13298                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13299                                 res->vf_id, is_on);
13300 #endif
13301 #ifdef RTE_LIBRTE_I40E_PMD
13302         if (ret == -ENOTSUP)
13303                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13304                                 res->vf_id, is_on);
13305 #endif
13306 #ifdef RTE_LIBRTE_BNXT_PMD
13307         if (ret == -ENOTSUP)
13308                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13309                                 res->vf_id, is_on);
13310 #endif
13311
13312         switch (ret) {
13313         case 0:
13314                 break;
13315         case -EINVAL:
13316                 printf("invalid vf_id %d\n", res->vf_id);
13317                 break;
13318         case -ENODEV:
13319                 printf("invalid port_id %d\n", res->port_id);
13320                 break;
13321         case -ENOTSUP:
13322                 printf("function not implemented\n");
13323                 break;
13324         default:
13325                 printf("programming error: (%s)\n", strerror(-ret));
13326         }
13327 }
13328
13329 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13330         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13331         .data = NULL,
13332         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13333         .tokens = {
13334                 (void *)&cmd_vf_vlan_anti_spoof_set,
13335                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13336                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13337                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13338                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13339                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13340                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13341                 NULL,
13342         },
13343 };
13344
13345 /* vf mac anti spoof configuration */
13346
13347 /* Common result structure for vf mac anti spoof */
13348 struct cmd_vf_mac_anti_spoof_result {
13349         cmdline_fixed_string_t set;
13350         cmdline_fixed_string_t vf;
13351         cmdline_fixed_string_t mac;
13352         cmdline_fixed_string_t antispoof;
13353         portid_t port_id;
13354         uint32_t vf_id;
13355         cmdline_fixed_string_t on_off;
13356 };
13357
13358 /* Common CLI fields for vf mac anti spoof enable disable */
13359 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13360         TOKEN_STRING_INITIALIZER
13361                 (struct cmd_vf_mac_anti_spoof_result,
13362                  set, "set");
13363 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13364         TOKEN_STRING_INITIALIZER
13365                 (struct cmd_vf_mac_anti_spoof_result,
13366                  vf, "vf");
13367 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13368         TOKEN_STRING_INITIALIZER
13369                 (struct cmd_vf_mac_anti_spoof_result,
13370                  mac, "mac");
13371 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13372         TOKEN_STRING_INITIALIZER
13373                 (struct cmd_vf_mac_anti_spoof_result,
13374                  antispoof, "antispoof");
13375 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13376         TOKEN_NUM_INITIALIZER
13377                 (struct cmd_vf_mac_anti_spoof_result,
13378                  port_id, UINT16);
13379 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13380         TOKEN_NUM_INITIALIZER
13381                 (struct cmd_vf_mac_anti_spoof_result,
13382                  vf_id, UINT32);
13383 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13384         TOKEN_STRING_INITIALIZER
13385                 (struct cmd_vf_mac_anti_spoof_result,
13386                  on_off, "on#off");
13387
13388 static void
13389 cmd_set_vf_mac_anti_spoof_parsed(
13390         void *parsed_result,
13391         __attribute__((unused)) struct cmdline *cl,
13392         __attribute__((unused)) void *data)
13393 {
13394         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13395         int ret = -ENOTSUP;
13396
13397         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13398
13399         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13400                 return;
13401
13402 #ifdef RTE_LIBRTE_IXGBE_PMD
13403         if (ret == -ENOTSUP)
13404                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13405                         res->vf_id, is_on);
13406 #endif
13407 #ifdef RTE_LIBRTE_I40E_PMD
13408         if (ret == -ENOTSUP)
13409                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13410                         res->vf_id, is_on);
13411 #endif
13412 #ifdef RTE_LIBRTE_BNXT_PMD
13413         if (ret == -ENOTSUP)
13414                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13415                         res->vf_id, is_on);
13416 #endif
13417
13418         switch (ret) {
13419         case 0:
13420                 break;
13421         case -EINVAL:
13422                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13423                 break;
13424         case -ENODEV:
13425                 printf("invalid port_id %d\n", res->port_id);
13426                 break;
13427         case -ENOTSUP:
13428                 printf("function not implemented\n");
13429                 break;
13430         default:
13431                 printf("programming error: (%s)\n", strerror(-ret));
13432         }
13433 }
13434
13435 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13436         .f = cmd_set_vf_mac_anti_spoof_parsed,
13437         .data = NULL,
13438         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13439         .tokens = {
13440                 (void *)&cmd_vf_mac_anti_spoof_set,
13441                 (void *)&cmd_vf_mac_anti_spoof_vf,
13442                 (void *)&cmd_vf_mac_anti_spoof_mac,
13443                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13444                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13445                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13446                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13447                 NULL,
13448         },
13449 };
13450
13451 /* vf vlan strip queue configuration */
13452
13453 /* Common result structure for vf mac anti spoof */
13454 struct cmd_vf_vlan_stripq_result {
13455         cmdline_fixed_string_t set;
13456         cmdline_fixed_string_t vf;
13457         cmdline_fixed_string_t vlan;
13458         cmdline_fixed_string_t stripq;
13459         portid_t port_id;
13460         uint16_t vf_id;
13461         cmdline_fixed_string_t on_off;
13462 };
13463
13464 /* Common CLI fields for vf vlan strip enable disable */
13465 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13466         TOKEN_STRING_INITIALIZER
13467                 (struct cmd_vf_vlan_stripq_result,
13468                  set, "set");
13469 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13470         TOKEN_STRING_INITIALIZER
13471                 (struct cmd_vf_vlan_stripq_result,
13472                  vf, "vf");
13473 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13474         TOKEN_STRING_INITIALIZER
13475                 (struct cmd_vf_vlan_stripq_result,
13476                  vlan, "vlan");
13477 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13478         TOKEN_STRING_INITIALIZER
13479                 (struct cmd_vf_vlan_stripq_result,
13480                  stripq, "stripq");
13481 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13482         TOKEN_NUM_INITIALIZER
13483                 (struct cmd_vf_vlan_stripq_result,
13484                  port_id, UINT16);
13485 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13486         TOKEN_NUM_INITIALIZER
13487                 (struct cmd_vf_vlan_stripq_result,
13488                  vf_id, UINT16);
13489 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13490         TOKEN_STRING_INITIALIZER
13491                 (struct cmd_vf_vlan_stripq_result,
13492                  on_off, "on#off");
13493
13494 static void
13495 cmd_set_vf_vlan_stripq_parsed(
13496         void *parsed_result,
13497         __attribute__((unused)) struct cmdline *cl,
13498         __attribute__((unused)) void *data)
13499 {
13500         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13501         int ret = -ENOTSUP;
13502
13503         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13504
13505         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13506                 return;
13507
13508 #ifdef RTE_LIBRTE_IXGBE_PMD
13509         if (ret == -ENOTSUP)
13510                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13511                         res->vf_id, is_on);
13512 #endif
13513 #ifdef RTE_LIBRTE_I40E_PMD
13514         if (ret == -ENOTSUP)
13515                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13516                         res->vf_id, is_on);
13517 #endif
13518 #ifdef RTE_LIBRTE_BNXT_PMD
13519         if (ret == -ENOTSUP)
13520                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13521                         res->vf_id, is_on);
13522 #endif
13523
13524         switch (ret) {
13525         case 0:
13526                 break;
13527         case -EINVAL:
13528                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13529                 break;
13530         case -ENODEV:
13531                 printf("invalid port_id %d\n", res->port_id);
13532                 break;
13533         case -ENOTSUP:
13534                 printf("function not implemented\n");
13535                 break;
13536         default:
13537                 printf("programming error: (%s)\n", strerror(-ret));
13538         }
13539 }
13540
13541 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13542         .f = cmd_set_vf_vlan_stripq_parsed,
13543         .data = NULL,
13544         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13545         .tokens = {
13546                 (void *)&cmd_vf_vlan_stripq_set,
13547                 (void *)&cmd_vf_vlan_stripq_vf,
13548                 (void *)&cmd_vf_vlan_stripq_vlan,
13549                 (void *)&cmd_vf_vlan_stripq_stripq,
13550                 (void *)&cmd_vf_vlan_stripq_port_id,
13551                 (void *)&cmd_vf_vlan_stripq_vf_id,
13552                 (void *)&cmd_vf_vlan_stripq_on_off,
13553                 NULL,
13554         },
13555 };
13556
13557 /* vf vlan insert configuration */
13558
13559 /* Common result structure for vf vlan insert */
13560 struct cmd_vf_vlan_insert_result {
13561         cmdline_fixed_string_t set;
13562         cmdline_fixed_string_t vf;
13563         cmdline_fixed_string_t vlan;
13564         cmdline_fixed_string_t insert;
13565         portid_t port_id;
13566         uint16_t vf_id;
13567         uint16_t vlan_id;
13568 };
13569
13570 /* Common CLI fields for vf vlan insert enable disable */
13571 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13572         TOKEN_STRING_INITIALIZER
13573                 (struct cmd_vf_vlan_insert_result,
13574                  set, "set");
13575 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13576         TOKEN_STRING_INITIALIZER
13577                 (struct cmd_vf_vlan_insert_result,
13578                  vf, "vf");
13579 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13580         TOKEN_STRING_INITIALIZER
13581                 (struct cmd_vf_vlan_insert_result,
13582                  vlan, "vlan");
13583 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13584         TOKEN_STRING_INITIALIZER
13585                 (struct cmd_vf_vlan_insert_result,
13586                  insert, "insert");
13587 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13588         TOKEN_NUM_INITIALIZER
13589                 (struct cmd_vf_vlan_insert_result,
13590                  port_id, UINT16);
13591 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13592         TOKEN_NUM_INITIALIZER
13593                 (struct cmd_vf_vlan_insert_result,
13594                  vf_id, UINT16);
13595 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13596         TOKEN_NUM_INITIALIZER
13597                 (struct cmd_vf_vlan_insert_result,
13598                  vlan_id, UINT16);
13599
13600 static void
13601 cmd_set_vf_vlan_insert_parsed(
13602         void *parsed_result,
13603         __attribute__((unused)) struct cmdline *cl,
13604         __attribute__((unused)) void *data)
13605 {
13606         struct cmd_vf_vlan_insert_result *res = parsed_result;
13607         int ret = -ENOTSUP;
13608
13609         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13610                 return;
13611
13612 #ifdef RTE_LIBRTE_IXGBE_PMD
13613         if (ret == -ENOTSUP)
13614                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13615                         res->vlan_id);
13616 #endif
13617 #ifdef RTE_LIBRTE_I40E_PMD
13618         if (ret == -ENOTSUP)
13619                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13620                         res->vlan_id);
13621 #endif
13622 #ifdef RTE_LIBRTE_BNXT_PMD
13623         if (ret == -ENOTSUP)
13624                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13625                         res->vlan_id);
13626 #endif
13627
13628         switch (ret) {
13629         case 0:
13630                 break;
13631         case -EINVAL:
13632                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13633                 break;
13634         case -ENODEV:
13635                 printf("invalid port_id %d\n", res->port_id);
13636                 break;
13637         case -ENOTSUP:
13638                 printf("function not implemented\n");
13639                 break;
13640         default:
13641                 printf("programming error: (%s)\n", strerror(-ret));
13642         }
13643 }
13644
13645 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13646         .f = cmd_set_vf_vlan_insert_parsed,
13647         .data = NULL,
13648         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13649         .tokens = {
13650                 (void *)&cmd_vf_vlan_insert_set,
13651                 (void *)&cmd_vf_vlan_insert_vf,
13652                 (void *)&cmd_vf_vlan_insert_vlan,
13653                 (void *)&cmd_vf_vlan_insert_insert,
13654                 (void *)&cmd_vf_vlan_insert_port_id,
13655                 (void *)&cmd_vf_vlan_insert_vf_id,
13656                 (void *)&cmd_vf_vlan_insert_vlan_id,
13657                 NULL,
13658         },
13659 };
13660
13661 /* tx loopback configuration */
13662
13663 /* Common result structure for tx loopback */
13664 struct cmd_tx_loopback_result {
13665         cmdline_fixed_string_t set;
13666         cmdline_fixed_string_t tx;
13667         cmdline_fixed_string_t loopback;
13668         portid_t port_id;
13669         cmdline_fixed_string_t on_off;
13670 };
13671
13672 /* Common CLI fields for tx loopback enable disable */
13673 cmdline_parse_token_string_t cmd_tx_loopback_set =
13674         TOKEN_STRING_INITIALIZER
13675                 (struct cmd_tx_loopback_result,
13676                  set, "set");
13677 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13678         TOKEN_STRING_INITIALIZER
13679                 (struct cmd_tx_loopback_result,
13680                  tx, "tx");
13681 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13682         TOKEN_STRING_INITIALIZER
13683                 (struct cmd_tx_loopback_result,
13684                  loopback, "loopback");
13685 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13686         TOKEN_NUM_INITIALIZER
13687                 (struct cmd_tx_loopback_result,
13688                  port_id, UINT16);
13689 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13690         TOKEN_STRING_INITIALIZER
13691                 (struct cmd_tx_loopback_result,
13692                  on_off, "on#off");
13693
13694 static void
13695 cmd_set_tx_loopback_parsed(
13696         void *parsed_result,
13697         __attribute__((unused)) struct cmdline *cl,
13698         __attribute__((unused)) void *data)
13699 {
13700         struct cmd_tx_loopback_result *res = parsed_result;
13701         int ret = -ENOTSUP;
13702
13703         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13704
13705         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13706                 return;
13707
13708 #ifdef RTE_LIBRTE_IXGBE_PMD
13709         if (ret == -ENOTSUP)
13710                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13711 #endif
13712 #ifdef RTE_LIBRTE_I40E_PMD
13713         if (ret == -ENOTSUP)
13714                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13715 #endif
13716 #ifdef RTE_LIBRTE_BNXT_PMD
13717         if (ret == -ENOTSUP)
13718                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13719 #endif
13720 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13721         if (ret == -ENOTSUP)
13722                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13723 #endif
13724
13725         switch (ret) {
13726         case 0:
13727                 break;
13728         case -EINVAL:
13729                 printf("invalid is_on %d\n", is_on);
13730                 break;
13731         case -ENODEV:
13732                 printf("invalid port_id %d\n", res->port_id);
13733                 break;
13734         case -ENOTSUP:
13735                 printf("function not implemented\n");
13736                 break;
13737         default:
13738                 printf("programming error: (%s)\n", strerror(-ret));
13739         }
13740 }
13741
13742 cmdline_parse_inst_t cmd_set_tx_loopback = {
13743         .f = cmd_set_tx_loopback_parsed,
13744         .data = NULL,
13745         .help_str = "set tx loopback <port_id> on|off",
13746         .tokens = {
13747                 (void *)&cmd_tx_loopback_set,
13748                 (void *)&cmd_tx_loopback_tx,
13749                 (void *)&cmd_tx_loopback_loopback,
13750                 (void *)&cmd_tx_loopback_port_id,
13751                 (void *)&cmd_tx_loopback_on_off,
13752                 NULL,
13753         },
13754 };
13755
13756 /* all queues drop enable configuration */
13757
13758 /* Common result structure for all queues drop enable */
13759 struct cmd_all_queues_drop_en_result {
13760         cmdline_fixed_string_t set;
13761         cmdline_fixed_string_t all;
13762         cmdline_fixed_string_t queues;
13763         cmdline_fixed_string_t drop;
13764         portid_t port_id;
13765         cmdline_fixed_string_t on_off;
13766 };
13767
13768 /* Common CLI fields for tx loopback enable disable */
13769 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13770         TOKEN_STRING_INITIALIZER
13771                 (struct cmd_all_queues_drop_en_result,
13772                  set, "set");
13773 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13774         TOKEN_STRING_INITIALIZER
13775                 (struct cmd_all_queues_drop_en_result,
13776                  all, "all");
13777 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13778         TOKEN_STRING_INITIALIZER
13779                 (struct cmd_all_queues_drop_en_result,
13780                  queues, "queues");
13781 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13782         TOKEN_STRING_INITIALIZER
13783                 (struct cmd_all_queues_drop_en_result,
13784                  drop, "drop");
13785 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13786         TOKEN_NUM_INITIALIZER
13787                 (struct cmd_all_queues_drop_en_result,
13788                  port_id, UINT16);
13789 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13790         TOKEN_STRING_INITIALIZER
13791                 (struct cmd_all_queues_drop_en_result,
13792                  on_off, "on#off");
13793
13794 static void
13795 cmd_set_all_queues_drop_en_parsed(
13796         void *parsed_result,
13797         __attribute__((unused)) struct cmdline *cl,
13798         __attribute__((unused)) void *data)
13799 {
13800         struct cmd_all_queues_drop_en_result *res = parsed_result;
13801         int ret = -ENOTSUP;
13802         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13803
13804         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13805                 return;
13806
13807 #ifdef RTE_LIBRTE_IXGBE_PMD
13808         if (ret == -ENOTSUP)
13809                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13810 #endif
13811 #ifdef RTE_LIBRTE_BNXT_PMD
13812         if (ret == -ENOTSUP)
13813                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13814 #endif
13815         switch (ret) {
13816         case 0:
13817                 break;
13818         case -EINVAL:
13819                 printf("invalid is_on %d\n", is_on);
13820                 break;
13821         case -ENODEV:
13822                 printf("invalid port_id %d\n", res->port_id);
13823                 break;
13824         case -ENOTSUP:
13825                 printf("function not implemented\n");
13826                 break;
13827         default:
13828                 printf("programming error: (%s)\n", strerror(-ret));
13829         }
13830 }
13831
13832 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13833         .f = cmd_set_all_queues_drop_en_parsed,
13834         .data = NULL,
13835         .help_str = "set all queues drop <port_id> on|off",
13836         .tokens = {
13837                 (void *)&cmd_all_queues_drop_en_set,
13838                 (void *)&cmd_all_queues_drop_en_all,
13839                 (void *)&cmd_all_queues_drop_en_queues,
13840                 (void *)&cmd_all_queues_drop_en_drop,
13841                 (void *)&cmd_all_queues_drop_en_port_id,
13842                 (void *)&cmd_all_queues_drop_en_on_off,
13843                 NULL,
13844         },
13845 };
13846
13847 /* vf split drop enable configuration */
13848
13849 /* Common result structure for vf split drop enable */
13850 struct cmd_vf_split_drop_en_result {
13851         cmdline_fixed_string_t set;
13852         cmdline_fixed_string_t vf;
13853         cmdline_fixed_string_t split;
13854         cmdline_fixed_string_t drop;
13855         portid_t port_id;
13856         uint16_t vf_id;
13857         cmdline_fixed_string_t on_off;
13858 };
13859
13860 /* Common CLI fields for vf split drop enable disable */
13861 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13862         TOKEN_STRING_INITIALIZER
13863                 (struct cmd_vf_split_drop_en_result,
13864                  set, "set");
13865 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13866         TOKEN_STRING_INITIALIZER
13867                 (struct cmd_vf_split_drop_en_result,
13868                  vf, "vf");
13869 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13870         TOKEN_STRING_INITIALIZER
13871                 (struct cmd_vf_split_drop_en_result,
13872                  split, "split");
13873 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13874         TOKEN_STRING_INITIALIZER
13875                 (struct cmd_vf_split_drop_en_result,
13876                  drop, "drop");
13877 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13878         TOKEN_NUM_INITIALIZER
13879                 (struct cmd_vf_split_drop_en_result,
13880                  port_id, UINT16);
13881 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13882         TOKEN_NUM_INITIALIZER
13883                 (struct cmd_vf_split_drop_en_result,
13884                  vf_id, UINT16);
13885 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13886         TOKEN_STRING_INITIALIZER
13887                 (struct cmd_vf_split_drop_en_result,
13888                  on_off, "on#off");
13889
13890 static void
13891 cmd_set_vf_split_drop_en_parsed(
13892         void *parsed_result,
13893         __attribute__((unused)) struct cmdline *cl,
13894         __attribute__((unused)) void *data)
13895 {
13896         struct cmd_vf_split_drop_en_result *res = parsed_result;
13897         int ret = -ENOTSUP;
13898         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13899
13900         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13901                 return;
13902
13903 #ifdef RTE_LIBRTE_IXGBE_PMD
13904         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13905                         is_on);
13906 #endif
13907         switch (ret) {
13908         case 0:
13909                 break;
13910         case -EINVAL:
13911                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13912                 break;
13913         case -ENODEV:
13914                 printf("invalid port_id %d\n", res->port_id);
13915                 break;
13916         case -ENOTSUP:
13917                 printf("not supported on port %d\n", res->port_id);
13918                 break;
13919         default:
13920                 printf("programming error: (%s)\n", strerror(-ret));
13921         }
13922 }
13923
13924 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13925         .f = cmd_set_vf_split_drop_en_parsed,
13926         .data = NULL,
13927         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13928         .tokens = {
13929                 (void *)&cmd_vf_split_drop_en_set,
13930                 (void *)&cmd_vf_split_drop_en_vf,
13931                 (void *)&cmd_vf_split_drop_en_split,
13932                 (void *)&cmd_vf_split_drop_en_drop,
13933                 (void *)&cmd_vf_split_drop_en_port_id,
13934                 (void *)&cmd_vf_split_drop_en_vf_id,
13935                 (void *)&cmd_vf_split_drop_en_on_off,
13936                 NULL,
13937         },
13938 };
13939
13940 /* vf mac address configuration */
13941
13942 /* Common result structure for vf mac address */
13943 struct cmd_set_vf_mac_addr_result {
13944         cmdline_fixed_string_t set;
13945         cmdline_fixed_string_t vf;
13946         cmdline_fixed_string_t mac;
13947         cmdline_fixed_string_t addr;
13948         portid_t port_id;
13949         uint16_t vf_id;
13950         struct rte_ether_addr mac_addr;
13951
13952 };
13953
13954 /* Common CLI fields for vf split drop enable disable */
13955 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13956         TOKEN_STRING_INITIALIZER
13957                 (struct cmd_set_vf_mac_addr_result,
13958                  set, "set");
13959 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13960         TOKEN_STRING_INITIALIZER
13961                 (struct cmd_set_vf_mac_addr_result,
13962                  vf, "vf");
13963 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13964         TOKEN_STRING_INITIALIZER
13965                 (struct cmd_set_vf_mac_addr_result,
13966                  mac, "mac");
13967 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13968         TOKEN_STRING_INITIALIZER
13969                 (struct cmd_set_vf_mac_addr_result,
13970                  addr, "addr");
13971 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13972         TOKEN_NUM_INITIALIZER
13973                 (struct cmd_set_vf_mac_addr_result,
13974                  port_id, UINT16);
13975 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13976         TOKEN_NUM_INITIALIZER
13977                 (struct cmd_set_vf_mac_addr_result,
13978                  vf_id, UINT16);
13979 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13980         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13981                  mac_addr);
13982
13983 static void
13984 cmd_set_vf_mac_addr_parsed(
13985         void *parsed_result,
13986         __attribute__((unused)) struct cmdline *cl,
13987         __attribute__((unused)) void *data)
13988 {
13989         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13990         int ret = -ENOTSUP;
13991
13992         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13993                 return;
13994
13995 #ifdef RTE_LIBRTE_IXGBE_PMD
13996         if (ret == -ENOTSUP)
13997                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13998                                 &res->mac_addr);
13999 #endif
14000 #ifdef RTE_LIBRTE_I40E_PMD
14001         if (ret == -ENOTSUP)
14002                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14003                                 &res->mac_addr);
14004 #endif
14005 #ifdef RTE_LIBRTE_BNXT_PMD
14006         if (ret == -ENOTSUP)
14007                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14008                                 &res->mac_addr);
14009 #endif
14010
14011         switch (ret) {
14012         case 0:
14013                 break;
14014         case -EINVAL:
14015                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14016                 break;
14017         case -ENODEV:
14018                 printf("invalid port_id %d\n", res->port_id);
14019                 break;
14020         case -ENOTSUP:
14021                 printf("function not implemented\n");
14022                 break;
14023         default:
14024                 printf("programming error: (%s)\n", strerror(-ret));
14025         }
14026 }
14027
14028 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14029         .f = cmd_set_vf_mac_addr_parsed,
14030         .data = NULL,
14031         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14032         .tokens = {
14033                 (void *)&cmd_set_vf_mac_addr_set,
14034                 (void *)&cmd_set_vf_mac_addr_vf,
14035                 (void *)&cmd_set_vf_mac_addr_mac,
14036                 (void *)&cmd_set_vf_mac_addr_addr,
14037                 (void *)&cmd_set_vf_mac_addr_port_id,
14038                 (void *)&cmd_set_vf_mac_addr_vf_id,
14039                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14040                 NULL,
14041         },
14042 };
14043
14044 /* MACsec configuration */
14045
14046 /* Common result structure for MACsec offload enable */
14047 struct cmd_macsec_offload_on_result {
14048         cmdline_fixed_string_t set;
14049         cmdline_fixed_string_t macsec;
14050         cmdline_fixed_string_t offload;
14051         portid_t port_id;
14052         cmdline_fixed_string_t on;
14053         cmdline_fixed_string_t encrypt;
14054         cmdline_fixed_string_t en_on_off;
14055         cmdline_fixed_string_t replay_protect;
14056         cmdline_fixed_string_t rp_on_off;
14057 };
14058
14059 /* Common CLI fields for MACsec offload disable */
14060 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14061         TOKEN_STRING_INITIALIZER
14062                 (struct cmd_macsec_offload_on_result,
14063                  set, "set");
14064 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14065         TOKEN_STRING_INITIALIZER
14066                 (struct cmd_macsec_offload_on_result,
14067                  macsec, "macsec");
14068 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14069         TOKEN_STRING_INITIALIZER
14070                 (struct cmd_macsec_offload_on_result,
14071                  offload, "offload");
14072 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14073         TOKEN_NUM_INITIALIZER
14074                 (struct cmd_macsec_offload_on_result,
14075                  port_id, UINT16);
14076 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14077         TOKEN_STRING_INITIALIZER
14078                 (struct cmd_macsec_offload_on_result,
14079                  on, "on");
14080 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14081         TOKEN_STRING_INITIALIZER
14082                 (struct cmd_macsec_offload_on_result,
14083                  encrypt, "encrypt");
14084 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14085         TOKEN_STRING_INITIALIZER
14086                 (struct cmd_macsec_offload_on_result,
14087                  en_on_off, "on#off");
14088 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14089         TOKEN_STRING_INITIALIZER
14090                 (struct cmd_macsec_offload_on_result,
14091                  replay_protect, "replay-protect");
14092 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14093         TOKEN_STRING_INITIALIZER
14094                 (struct cmd_macsec_offload_on_result,
14095                  rp_on_off, "on#off");
14096
14097 static void
14098 cmd_set_macsec_offload_on_parsed(
14099         void *parsed_result,
14100         __attribute__((unused)) struct cmdline *cl,
14101         __attribute__((unused)) void *data)
14102 {
14103         struct cmd_macsec_offload_on_result *res = parsed_result;
14104         int ret = -ENOTSUP;
14105         portid_t port_id = res->port_id;
14106         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14107         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14108         struct rte_eth_dev_info dev_info;
14109
14110         if (port_id_is_invalid(port_id, ENABLED_WARN))
14111                 return;
14112         if (!port_is_stopped(port_id)) {
14113                 printf("Please stop port %d first\n", port_id);
14114                 return;
14115         }
14116
14117         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14118         if (ret != 0)
14119                 return;
14120
14121         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14122 #ifdef RTE_LIBRTE_IXGBE_PMD
14123                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14124 #endif
14125         }
14126         RTE_SET_USED(en);
14127         RTE_SET_USED(rp);
14128
14129         switch (ret) {
14130         case 0:
14131                 ports[port_id].dev_conf.txmode.offloads |=
14132                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14133                 cmd_reconfig_device_queue(port_id, 1, 1);
14134                 break;
14135         case -ENODEV:
14136                 printf("invalid port_id %d\n", port_id);
14137                 break;
14138         case -ENOTSUP:
14139                 printf("not supported on port %d\n", port_id);
14140                 break;
14141         default:
14142                 printf("programming error: (%s)\n", strerror(-ret));
14143         }
14144 }
14145
14146 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14147         .f = cmd_set_macsec_offload_on_parsed,
14148         .data = NULL,
14149         .help_str = "set macsec offload <port_id> on "
14150                 "encrypt on|off replay-protect on|off",
14151         .tokens = {
14152                 (void *)&cmd_macsec_offload_on_set,
14153                 (void *)&cmd_macsec_offload_on_macsec,
14154                 (void *)&cmd_macsec_offload_on_offload,
14155                 (void *)&cmd_macsec_offload_on_port_id,
14156                 (void *)&cmd_macsec_offload_on_on,
14157                 (void *)&cmd_macsec_offload_on_encrypt,
14158                 (void *)&cmd_macsec_offload_on_en_on_off,
14159                 (void *)&cmd_macsec_offload_on_replay_protect,
14160                 (void *)&cmd_macsec_offload_on_rp_on_off,
14161                 NULL,
14162         },
14163 };
14164
14165 /* Common result structure for MACsec offload disable */
14166 struct cmd_macsec_offload_off_result {
14167         cmdline_fixed_string_t set;
14168         cmdline_fixed_string_t macsec;
14169         cmdline_fixed_string_t offload;
14170         portid_t port_id;
14171         cmdline_fixed_string_t off;
14172 };
14173
14174 /* Common CLI fields for MACsec offload disable */
14175 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14176         TOKEN_STRING_INITIALIZER
14177                 (struct cmd_macsec_offload_off_result,
14178                  set, "set");
14179 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14180         TOKEN_STRING_INITIALIZER
14181                 (struct cmd_macsec_offload_off_result,
14182                  macsec, "macsec");
14183 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14184         TOKEN_STRING_INITIALIZER
14185                 (struct cmd_macsec_offload_off_result,
14186                  offload, "offload");
14187 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14188         TOKEN_NUM_INITIALIZER
14189                 (struct cmd_macsec_offload_off_result,
14190                  port_id, UINT16);
14191 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14192         TOKEN_STRING_INITIALIZER
14193                 (struct cmd_macsec_offload_off_result,
14194                  off, "off");
14195
14196 static void
14197 cmd_set_macsec_offload_off_parsed(
14198         void *parsed_result,
14199         __attribute__((unused)) struct cmdline *cl,
14200         __attribute__((unused)) void *data)
14201 {
14202         struct cmd_macsec_offload_off_result *res = parsed_result;
14203         int ret = -ENOTSUP;
14204         struct rte_eth_dev_info dev_info;
14205         portid_t port_id = res->port_id;
14206
14207         if (port_id_is_invalid(port_id, ENABLED_WARN))
14208                 return;
14209         if (!port_is_stopped(port_id)) {
14210                 printf("Please stop port %d first\n", port_id);
14211                 return;
14212         }
14213
14214         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14215         if (ret != 0)
14216                 return;
14217
14218         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14219 #ifdef RTE_LIBRTE_IXGBE_PMD
14220                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14221 #endif
14222         }
14223         switch (ret) {
14224         case 0:
14225                 ports[port_id].dev_conf.txmode.offloads &=
14226                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14227                 cmd_reconfig_device_queue(port_id, 1, 1);
14228                 break;
14229         case -ENODEV:
14230                 printf("invalid port_id %d\n", port_id);
14231                 break;
14232         case -ENOTSUP:
14233                 printf("not supported on port %d\n", port_id);
14234                 break;
14235         default:
14236                 printf("programming error: (%s)\n", strerror(-ret));
14237         }
14238 }
14239
14240 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14241         .f = cmd_set_macsec_offload_off_parsed,
14242         .data = NULL,
14243         .help_str = "set macsec offload <port_id> off",
14244         .tokens = {
14245                 (void *)&cmd_macsec_offload_off_set,
14246                 (void *)&cmd_macsec_offload_off_macsec,
14247                 (void *)&cmd_macsec_offload_off_offload,
14248                 (void *)&cmd_macsec_offload_off_port_id,
14249                 (void *)&cmd_macsec_offload_off_off,
14250                 NULL,
14251         },
14252 };
14253
14254 /* Common result structure for MACsec secure connection configure */
14255 struct cmd_macsec_sc_result {
14256         cmdline_fixed_string_t set;
14257         cmdline_fixed_string_t macsec;
14258         cmdline_fixed_string_t sc;
14259         cmdline_fixed_string_t tx_rx;
14260         portid_t port_id;
14261         struct rte_ether_addr mac;
14262         uint16_t pi;
14263 };
14264
14265 /* Common CLI fields for MACsec secure connection configure */
14266 cmdline_parse_token_string_t cmd_macsec_sc_set =
14267         TOKEN_STRING_INITIALIZER
14268                 (struct cmd_macsec_sc_result,
14269                  set, "set");
14270 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14271         TOKEN_STRING_INITIALIZER
14272                 (struct cmd_macsec_sc_result,
14273                  macsec, "macsec");
14274 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14275         TOKEN_STRING_INITIALIZER
14276                 (struct cmd_macsec_sc_result,
14277                  sc, "sc");
14278 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14279         TOKEN_STRING_INITIALIZER
14280                 (struct cmd_macsec_sc_result,
14281                  tx_rx, "tx#rx");
14282 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14283         TOKEN_NUM_INITIALIZER
14284                 (struct cmd_macsec_sc_result,
14285                  port_id, UINT16);
14286 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14287         TOKEN_ETHERADDR_INITIALIZER
14288                 (struct cmd_macsec_sc_result,
14289                  mac);
14290 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14291         TOKEN_NUM_INITIALIZER
14292                 (struct cmd_macsec_sc_result,
14293                  pi, UINT16);
14294
14295 static void
14296 cmd_set_macsec_sc_parsed(
14297         void *parsed_result,
14298         __attribute__((unused)) struct cmdline *cl,
14299         __attribute__((unused)) void *data)
14300 {
14301         struct cmd_macsec_sc_result *res = parsed_result;
14302         int ret = -ENOTSUP;
14303         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14304
14305 #ifdef RTE_LIBRTE_IXGBE_PMD
14306         ret = is_tx ?
14307                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14308                                 res->mac.addr_bytes) :
14309                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14310                                 res->mac.addr_bytes, res->pi);
14311 #endif
14312         RTE_SET_USED(is_tx);
14313
14314         switch (ret) {
14315         case 0:
14316                 break;
14317         case -ENODEV:
14318                 printf("invalid port_id %d\n", res->port_id);
14319                 break;
14320         case -ENOTSUP:
14321                 printf("not supported on port %d\n", res->port_id);
14322                 break;
14323         default:
14324                 printf("programming error: (%s)\n", strerror(-ret));
14325         }
14326 }
14327
14328 cmdline_parse_inst_t cmd_set_macsec_sc = {
14329         .f = cmd_set_macsec_sc_parsed,
14330         .data = NULL,
14331         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14332         .tokens = {
14333                 (void *)&cmd_macsec_sc_set,
14334                 (void *)&cmd_macsec_sc_macsec,
14335                 (void *)&cmd_macsec_sc_sc,
14336                 (void *)&cmd_macsec_sc_tx_rx,
14337                 (void *)&cmd_macsec_sc_port_id,
14338                 (void *)&cmd_macsec_sc_mac,
14339                 (void *)&cmd_macsec_sc_pi,
14340                 NULL,
14341         },
14342 };
14343
14344 /* Common result structure for MACsec secure connection configure */
14345 struct cmd_macsec_sa_result {
14346         cmdline_fixed_string_t set;
14347         cmdline_fixed_string_t macsec;
14348         cmdline_fixed_string_t sa;
14349         cmdline_fixed_string_t tx_rx;
14350         portid_t port_id;
14351         uint8_t idx;
14352         uint8_t an;
14353         uint32_t pn;
14354         cmdline_fixed_string_t key;
14355 };
14356
14357 /* Common CLI fields for MACsec secure connection configure */
14358 cmdline_parse_token_string_t cmd_macsec_sa_set =
14359         TOKEN_STRING_INITIALIZER
14360                 (struct cmd_macsec_sa_result,
14361                  set, "set");
14362 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14363         TOKEN_STRING_INITIALIZER
14364                 (struct cmd_macsec_sa_result,
14365                  macsec, "macsec");
14366 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14367         TOKEN_STRING_INITIALIZER
14368                 (struct cmd_macsec_sa_result,
14369                  sa, "sa");
14370 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14371         TOKEN_STRING_INITIALIZER
14372                 (struct cmd_macsec_sa_result,
14373                  tx_rx, "tx#rx");
14374 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14375         TOKEN_NUM_INITIALIZER
14376                 (struct cmd_macsec_sa_result,
14377                  port_id, UINT16);
14378 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14379         TOKEN_NUM_INITIALIZER
14380                 (struct cmd_macsec_sa_result,
14381                  idx, UINT8);
14382 cmdline_parse_token_num_t cmd_macsec_sa_an =
14383         TOKEN_NUM_INITIALIZER
14384                 (struct cmd_macsec_sa_result,
14385                  an, UINT8);
14386 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14387         TOKEN_NUM_INITIALIZER
14388                 (struct cmd_macsec_sa_result,
14389                  pn, UINT32);
14390 cmdline_parse_token_string_t cmd_macsec_sa_key =
14391         TOKEN_STRING_INITIALIZER
14392                 (struct cmd_macsec_sa_result,
14393                  key, NULL);
14394
14395 static void
14396 cmd_set_macsec_sa_parsed(
14397         void *parsed_result,
14398         __attribute__((unused)) struct cmdline *cl,
14399         __attribute__((unused)) void *data)
14400 {
14401         struct cmd_macsec_sa_result *res = parsed_result;
14402         int ret = -ENOTSUP;
14403         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14404         uint8_t key[16] = { 0 };
14405         uint8_t xdgt0;
14406         uint8_t xdgt1;
14407         int key_len;
14408         int i;
14409
14410         key_len = strlen(res->key) / 2;
14411         if (key_len > 16)
14412                 key_len = 16;
14413
14414         for (i = 0; i < key_len; i++) {
14415                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14416                 if (xdgt0 == 0xFF)
14417                         return;
14418                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14419                 if (xdgt1 == 0xFF)
14420                         return;
14421                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14422         }
14423
14424 #ifdef RTE_LIBRTE_IXGBE_PMD
14425         ret = is_tx ?
14426                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14427                         res->idx, res->an, res->pn, key) :
14428                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14429                         res->idx, res->an, res->pn, key);
14430 #endif
14431         RTE_SET_USED(is_tx);
14432         RTE_SET_USED(key);
14433
14434         switch (ret) {
14435         case 0:
14436                 break;
14437         case -EINVAL:
14438                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14439                 break;
14440         case -ENODEV:
14441                 printf("invalid port_id %d\n", res->port_id);
14442                 break;
14443         case -ENOTSUP:
14444                 printf("not supported on port %d\n", res->port_id);
14445                 break;
14446         default:
14447                 printf("programming error: (%s)\n", strerror(-ret));
14448         }
14449 }
14450
14451 cmdline_parse_inst_t cmd_set_macsec_sa = {
14452         .f = cmd_set_macsec_sa_parsed,
14453         .data = NULL,
14454         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14455         .tokens = {
14456                 (void *)&cmd_macsec_sa_set,
14457                 (void *)&cmd_macsec_sa_macsec,
14458                 (void *)&cmd_macsec_sa_sa,
14459                 (void *)&cmd_macsec_sa_tx_rx,
14460                 (void *)&cmd_macsec_sa_port_id,
14461                 (void *)&cmd_macsec_sa_idx,
14462                 (void *)&cmd_macsec_sa_an,
14463                 (void *)&cmd_macsec_sa_pn,
14464                 (void *)&cmd_macsec_sa_key,
14465                 NULL,
14466         },
14467 };
14468
14469 /* VF unicast promiscuous mode configuration */
14470
14471 /* Common result structure for VF unicast promiscuous mode */
14472 struct cmd_vf_promisc_result {
14473         cmdline_fixed_string_t set;
14474         cmdline_fixed_string_t vf;
14475         cmdline_fixed_string_t promisc;
14476         portid_t port_id;
14477         uint32_t vf_id;
14478         cmdline_fixed_string_t on_off;
14479 };
14480
14481 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14482 cmdline_parse_token_string_t cmd_vf_promisc_set =
14483         TOKEN_STRING_INITIALIZER
14484                 (struct cmd_vf_promisc_result,
14485                  set, "set");
14486 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14487         TOKEN_STRING_INITIALIZER
14488                 (struct cmd_vf_promisc_result,
14489                  vf, "vf");
14490 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14491         TOKEN_STRING_INITIALIZER
14492                 (struct cmd_vf_promisc_result,
14493                  promisc, "promisc");
14494 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14495         TOKEN_NUM_INITIALIZER
14496                 (struct cmd_vf_promisc_result,
14497                  port_id, UINT16);
14498 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14499         TOKEN_NUM_INITIALIZER
14500                 (struct cmd_vf_promisc_result,
14501                  vf_id, UINT32);
14502 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14503         TOKEN_STRING_INITIALIZER
14504                 (struct cmd_vf_promisc_result,
14505                  on_off, "on#off");
14506
14507 static void
14508 cmd_set_vf_promisc_parsed(
14509         void *parsed_result,
14510         __attribute__((unused)) struct cmdline *cl,
14511         __attribute__((unused)) void *data)
14512 {
14513         struct cmd_vf_promisc_result *res = parsed_result;
14514         int ret = -ENOTSUP;
14515
14516         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14517
14518         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14519                 return;
14520
14521 #ifdef RTE_LIBRTE_I40E_PMD
14522         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14523                                                   res->vf_id, is_on);
14524 #endif
14525
14526         switch (ret) {
14527         case 0:
14528                 break;
14529         case -EINVAL:
14530                 printf("invalid vf_id %d\n", res->vf_id);
14531                 break;
14532         case -ENODEV:
14533                 printf("invalid port_id %d\n", res->port_id);
14534                 break;
14535         case -ENOTSUP:
14536                 printf("function not implemented\n");
14537                 break;
14538         default:
14539                 printf("programming error: (%s)\n", strerror(-ret));
14540         }
14541 }
14542
14543 cmdline_parse_inst_t cmd_set_vf_promisc = {
14544         .f = cmd_set_vf_promisc_parsed,
14545         .data = NULL,
14546         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14547                 "Set unicast promiscuous mode for a VF from the PF",
14548         .tokens = {
14549                 (void *)&cmd_vf_promisc_set,
14550                 (void *)&cmd_vf_promisc_vf,
14551                 (void *)&cmd_vf_promisc_promisc,
14552                 (void *)&cmd_vf_promisc_port_id,
14553                 (void *)&cmd_vf_promisc_vf_id,
14554                 (void *)&cmd_vf_promisc_on_off,
14555                 NULL,
14556         },
14557 };
14558
14559 /* VF multicast promiscuous mode configuration */
14560
14561 /* Common result structure for VF multicast promiscuous mode */
14562 struct cmd_vf_allmulti_result {
14563         cmdline_fixed_string_t set;
14564         cmdline_fixed_string_t vf;
14565         cmdline_fixed_string_t allmulti;
14566         portid_t port_id;
14567         uint32_t vf_id;
14568         cmdline_fixed_string_t on_off;
14569 };
14570
14571 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14572 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14573         TOKEN_STRING_INITIALIZER
14574                 (struct cmd_vf_allmulti_result,
14575                  set, "set");
14576 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14577         TOKEN_STRING_INITIALIZER
14578                 (struct cmd_vf_allmulti_result,
14579                  vf, "vf");
14580 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14581         TOKEN_STRING_INITIALIZER
14582                 (struct cmd_vf_allmulti_result,
14583                  allmulti, "allmulti");
14584 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14585         TOKEN_NUM_INITIALIZER
14586                 (struct cmd_vf_allmulti_result,
14587                  port_id, UINT16);
14588 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14589         TOKEN_NUM_INITIALIZER
14590                 (struct cmd_vf_allmulti_result,
14591                  vf_id, UINT32);
14592 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14593         TOKEN_STRING_INITIALIZER
14594                 (struct cmd_vf_allmulti_result,
14595                  on_off, "on#off");
14596
14597 static void
14598 cmd_set_vf_allmulti_parsed(
14599         void *parsed_result,
14600         __attribute__((unused)) struct cmdline *cl,
14601         __attribute__((unused)) void *data)
14602 {
14603         struct cmd_vf_allmulti_result *res = parsed_result;
14604         int ret = -ENOTSUP;
14605
14606         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14607
14608         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14609                 return;
14610
14611 #ifdef RTE_LIBRTE_I40E_PMD
14612         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14613                                                     res->vf_id, is_on);
14614 #endif
14615
14616         switch (ret) {
14617         case 0:
14618                 break;
14619         case -EINVAL:
14620                 printf("invalid vf_id %d\n", res->vf_id);
14621                 break;
14622         case -ENODEV:
14623                 printf("invalid port_id %d\n", res->port_id);
14624                 break;
14625         case -ENOTSUP:
14626                 printf("function not implemented\n");
14627                 break;
14628         default:
14629                 printf("programming error: (%s)\n", strerror(-ret));
14630         }
14631 }
14632
14633 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14634         .f = cmd_set_vf_allmulti_parsed,
14635         .data = NULL,
14636         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14637                 "Set multicast promiscuous mode for a VF from the PF",
14638         .tokens = {
14639                 (void *)&cmd_vf_allmulti_set,
14640                 (void *)&cmd_vf_allmulti_vf,
14641                 (void *)&cmd_vf_allmulti_allmulti,
14642                 (void *)&cmd_vf_allmulti_port_id,
14643                 (void *)&cmd_vf_allmulti_vf_id,
14644                 (void *)&cmd_vf_allmulti_on_off,
14645                 NULL,
14646         },
14647 };
14648
14649 /* vf broadcast mode configuration */
14650
14651 /* Common result structure for vf broadcast */
14652 struct cmd_set_vf_broadcast_result {
14653         cmdline_fixed_string_t set;
14654         cmdline_fixed_string_t vf;
14655         cmdline_fixed_string_t broadcast;
14656         portid_t port_id;
14657         uint16_t vf_id;
14658         cmdline_fixed_string_t on_off;
14659 };
14660
14661 /* Common CLI fields for vf broadcast enable disable */
14662 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14663         TOKEN_STRING_INITIALIZER
14664                 (struct cmd_set_vf_broadcast_result,
14665                  set, "set");
14666 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14667         TOKEN_STRING_INITIALIZER
14668                 (struct cmd_set_vf_broadcast_result,
14669                  vf, "vf");
14670 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14671         TOKEN_STRING_INITIALIZER
14672                 (struct cmd_set_vf_broadcast_result,
14673                  broadcast, "broadcast");
14674 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14675         TOKEN_NUM_INITIALIZER
14676                 (struct cmd_set_vf_broadcast_result,
14677                  port_id, UINT16);
14678 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14679         TOKEN_NUM_INITIALIZER
14680                 (struct cmd_set_vf_broadcast_result,
14681                  vf_id, UINT16);
14682 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14683         TOKEN_STRING_INITIALIZER
14684                 (struct cmd_set_vf_broadcast_result,
14685                  on_off, "on#off");
14686
14687 static void
14688 cmd_set_vf_broadcast_parsed(
14689         void *parsed_result,
14690         __attribute__((unused)) struct cmdline *cl,
14691         __attribute__((unused)) void *data)
14692 {
14693         struct cmd_set_vf_broadcast_result *res = parsed_result;
14694         int ret = -ENOTSUP;
14695
14696         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14697
14698         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14699                 return;
14700
14701 #ifdef RTE_LIBRTE_I40E_PMD
14702         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14703                                             res->vf_id, is_on);
14704 #endif
14705
14706         switch (ret) {
14707         case 0:
14708                 break;
14709         case -EINVAL:
14710                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14711                 break;
14712         case -ENODEV:
14713                 printf("invalid port_id %d\n", res->port_id);
14714                 break;
14715         case -ENOTSUP:
14716                 printf("function not implemented\n");
14717                 break;
14718         default:
14719                 printf("programming error: (%s)\n", strerror(-ret));
14720         }
14721 }
14722
14723 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14724         .f = cmd_set_vf_broadcast_parsed,
14725         .data = NULL,
14726         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14727         .tokens = {
14728                 (void *)&cmd_set_vf_broadcast_set,
14729                 (void *)&cmd_set_vf_broadcast_vf,
14730                 (void *)&cmd_set_vf_broadcast_broadcast,
14731                 (void *)&cmd_set_vf_broadcast_port_id,
14732                 (void *)&cmd_set_vf_broadcast_vf_id,
14733                 (void *)&cmd_set_vf_broadcast_on_off,
14734                 NULL,
14735         },
14736 };
14737
14738 /* vf vlan tag configuration */
14739
14740 /* Common result structure for vf vlan tag */
14741 struct cmd_set_vf_vlan_tag_result {
14742         cmdline_fixed_string_t set;
14743         cmdline_fixed_string_t vf;
14744         cmdline_fixed_string_t vlan;
14745         cmdline_fixed_string_t tag;
14746         portid_t port_id;
14747         uint16_t vf_id;
14748         cmdline_fixed_string_t on_off;
14749 };
14750
14751 /* Common CLI fields for vf vlan tag enable disable */
14752 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14753         TOKEN_STRING_INITIALIZER
14754                 (struct cmd_set_vf_vlan_tag_result,
14755                  set, "set");
14756 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14757         TOKEN_STRING_INITIALIZER
14758                 (struct cmd_set_vf_vlan_tag_result,
14759                  vf, "vf");
14760 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14761         TOKEN_STRING_INITIALIZER
14762                 (struct cmd_set_vf_vlan_tag_result,
14763                  vlan, "vlan");
14764 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14765         TOKEN_STRING_INITIALIZER
14766                 (struct cmd_set_vf_vlan_tag_result,
14767                  tag, "tag");
14768 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14769         TOKEN_NUM_INITIALIZER
14770                 (struct cmd_set_vf_vlan_tag_result,
14771                  port_id, UINT16);
14772 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14773         TOKEN_NUM_INITIALIZER
14774                 (struct cmd_set_vf_vlan_tag_result,
14775                  vf_id, UINT16);
14776 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14777         TOKEN_STRING_INITIALIZER
14778                 (struct cmd_set_vf_vlan_tag_result,
14779                  on_off, "on#off");
14780
14781 static void
14782 cmd_set_vf_vlan_tag_parsed(
14783         void *parsed_result,
14784         __attribute__((unused)) struct cmdline *cl,
14785         __attribute__((unused)) void *data)
14786 {
14787         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14788         int ret = -ENOTSUP;
14789
14790         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14791
14792         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14793                 return;
14794
14795 #ifdef RTE_LIBRTE_I40E_PMD
14796         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14797                                            res->vf_id, is_on);
14798 #endif
14799
14800         switch (ret) {
14801         case 0:
14802                 break;
14803         case -EINVAL:
14804                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14805                 break;
14806         case -ENODEV:
14807                 printf("invalid port_id %d\n", res->port_id);
14808                 break;
14809         case -ENOTSUP:
14810                 printf("function not implemented\n");
14811                 break;
14812         default:
14813                 printf("programming error: (%s)\n", strerror(-ret));
14814         }
14815 }
14816
14817 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14818         .f = cmd_set_vf_vlan_tag_parsed,
14819         .data = NULL,
14820         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14821         .tokens = {
14822                 (void *)&cmd_set_vf_vlan_tag_set,
14823                 (void *)&cmd_set_vf_vlan_tag_vf,
14824                 (void *)&cmd_set_vf_vlan_tag_vlan,
14825                 (void *)&cmd_set_vf_vlan_tag_tag,
14826                 (void *)&cmd_set_vf_vlan_tag_port_id,
14827                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14828                 (void *)&cmd_set_vf_vlan_tag_on_off,
14829                 NULL,
14830         },
14831 };
14832
14833 /* Common definition of VF and TC TX bandwidth configuration */
14834 struct cmd_vf_tc_bw_result {
14835         cmdline_fixed_string_t set;
14836         cmdline_fixed_string_t vf;
14837         cmdline_fixed_string_t tc;
14838         cmdline_fixed_string_t tx;
14839         cmdline_fixed_string_t min_bw;
14840         cmdline_fixed_string_t max_bw;
14841         cmdline_fixed_string_t strict_link_prio;
14842         portid_t port_id;
14843         uint16_t vf_id;
14844         uint8_t tc_no;
14845         uint32_t bw;
14846         cmdline_fixed_string_t bw_list;
14847         uint8_t tc_map;
14848 };
14849
14850 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14851         TOKEN_STRING_INITIALIZER
14852                 (struct cmd_vf_tc_bw_result,
14853                  set, "set");
14854 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14855         TOKEN_STRING_INITIALIZER
14856                 (struct cmd_vf_tc_bw_result,
14857                  vf, "vf");
14858 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14859         TOKEN_STRING_INITIALIZER
14860                 (struct cmd_vf_tc_bw_result,
14861                  tc, "tc");
14862 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14863         TOKEN_STRING_INITIALIZER
14864                 (struct cmd_vf_tc_bw_result,
14865                  tx, "tx");
14866 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14867         TOKEN_STRING_INITIALIZER
14868                 (struct cmd_vf_tc_bw_result,
14869                  strict_link_prio, "strict-link-priority");
14870 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14871         TOKEN_STRING_INITIALIZER
14872                 (struct cmd_vf_tc_bw_result,
14873                  min_bw, "min-bandwidth");
14874 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14875         TOKEN_STRING_INITIALIZER
14876                 (struct cmd_vf_tc_bw_result,
14877                  max_bw, "max-bandwidth");
14878 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14879         TOKEN_NUM_INITIALIZER
14880                 (struct cmd_vf_tc_bw_result,
14881                  port_id, UINT16);
14882 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14883         TOKEN_NUM_INITIALIZER
14884                 (struct cmd_vf_tc_bw_result,
14885                  vf_id, UINT16);
14886 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14887         TOKEN_NUM_INITIALIZER
14888                 (struct cmd_vf_tc_bw_result,
14889                  tc_no, UINT8);
14890 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14891         TOKEN_NUM_INITIALIZER
14892                 (struct cmd_vf_tc_bw_result,
14893                  bw, UINT32);
14894 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14895         TOKEN_STRING_INITIALIZER
14896                 (struct cmd_vf_tc_bw_result,
14897                  bw_list, NULL);
14898 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14899         TOKEN_NUM_INITIALIZER
14900                 (struct cmd_vf_tc_bw_result,
14901                  tc_map, UINT8);
14902
14903 /* VF max bandwidth setting */
14904 static void
14905 cmd_vf_max_bw_parsed(
14906         void *parsed_result,
14907         __attribute__((unused)) struct cmdline *cl,
14908         __attribute__((unused)) void *data)
14909 {
14910         struct cmd_vf_tc_bw_result *res = parsed_result;
14911         int ret = -ENOTSUP;
14912
14913         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14914                 return;
14915
14916 #ifdef RTE_LIBRTE_I40E_PMD
14917         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14918                                          res->vf_id, res->bw);
14919 #endif
14920
14921         switch (ret) {
14922         case 0:
14923                 break;
14924         case -EINVAL:
14925                 printf("invalid vf_id %d or bandwidth %d\n",
14926                        res->vf_id, res->bw);
14927                 break;
14928         case -ENODEV:
14929                 printf("invalid port_id %d\n", res->port_id);
14930                 break;
14931         case -ENOTSUP:
14932                 printf("function not implemented\n");
14933                 break;
14934         default:
14935                 printf("programming error: (%s)\n", strerror(-ret));
14936         }
14937 }
14938
14939 cmdline_parse_inst_t cmd_vf_max_bw = {
14940         .f = cmd_vf_max_bw_parsed,
14941         .data = NULL,
14942         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14943         .tokens = {
14944                 (void *)&cmd_vf_tc_bw_set,
14945                 (void *)&cmd_vf_tc_bw_vf,
14946                 (void *)&cmd_vf_tc_bw_tx,
14947                 (void *)&cmd_vf_tc_bw_max_bw,
14948                 (void *)&cmd_vf_tc_bw_port_id,
14949                 (void *)&cmd_vf_tc_bw_vf_id,
14950                 (void *)&cmd_vf_tc_bw_bw,
14951                 NULL,
14952         },
14953 };
14954
14955 static int
14956 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14957                            uint8_t *tc_num,
14958                            char *str)
14959 {
14960         uint32_t size;
14961         const char *p, *p0 = str;
14962         char s[256];
14963         char *end;
14964         char *str_fld[16];
14965         uint16_t i;
14966         int ret;
14967
14968         p = strchr(p0, '(');
14969         if (p == NULL) {
14970                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14971                 return -1;
14972         }
14973         p++;
14974         p0 = strchr(p, ')');
14975         if (p0 == NULL) {
14976                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14977                 return -1;
14978         }
14979         size = p0 - p;
14980         if (size >= sizeof(s)) {
14981                 printf("The string size exceeds the internal buffer size\n");
14982                 return -1;
14983         }
14984         snprintf(s, sizeof(s), "%.*s", size, p);
14985         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14986         if (ret <= 0) {
14987                 printf("Failed to get the bandwidth list. ");
14988                 return -1;
14989         }
14990         *tc_num = ret;
14991         for (i = 0; i < ret; i++)
14992                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14993
14994         return 0;
14995 }
14996
14997 /* TC min bandwidth setting */
14998 static void
14999 cmd_vf_tc_min_bw_parsed(
15000         void *parsed_result,
15001         __attribute__((unused)) struct cmdline *cl,
15002         __attribute__((unused)) void *data)
15003 {
15004         struct cmd_vf_tc_bw_result *res = parsed_result;
15005         uint8_t tc_num;
15006         uint8_t bw[16];
15007         int ret = -ENOTSUP;
15008
15009         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15010                 return;
15011
15012         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15013         if (ret)
15014                 return;
15015
15016 #ifdef RTE_LIBRTE_I40E_PMD
15017         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15018                                               tc_num, bw);
15019 #endif
15020
15021         switch (ret) {
15022         case 0:
15023                 break;
15024         case -EINVAL:
15025                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15026                 break;
15027         case -ENODEV:
15028                 printf("invalid port_id %d\n", res->port_id);
15029                 break;
15030         case -ENOTSUP:
15031                 printf("function not implemented\n");
15032                 break;
15033         default:
15034                 printf("programming error: (%s)\n", strerror(-ret));
15035         }
15036 }
15037
15038 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15039         .f = cmd_vf_tc_min_bw_parsed,
15040         .data = NULL,
15041         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15042                     " <bw1, bw2, ...>",
15043         .tokens = {
15044                 (void *)&cmd_vf_tc_bw_set,
15045                 (void *)&cmd_vf_tc_bw_vf,
15046                 (void *)&cmd_vf_tc_bw_tc,
15047                 (void *)&cmd_vf_tc_bw_tx,
15048                 (void *)&cmd_vf_tc_bw_min_bw,
15049                 (void *)&cmd_vf_tc_bw_port_id,
15050                 (void *)&cmd_vf_tc_bw_vf_id,
15051                 (void *)&cmd_vf_tc_bw_bw_list,
15052                 NULL,
15053         },
15054 };
15055
15056 static void
15057 cmd_tc_min_bw_parsed(
15058         void *parsed_result,
15059         __attribute__((unused)) struct cmdline *cl,
15060         __attribute__((unused)) void *data)
15061 {
15062         struct cmd_vf_tc_bw_result *res = parsed_result;
15063         struct rte_port *port;
15064         uint8_t tc_num;
15065         uint8_t bw[16];
15066         int ret = -ENOTSUP;
15067
15068         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15069                 return;
15070
15071         port = &ports[res->port_id];
15072         /** Check if the port is not started **/
15073         if (port->port_status != RTE_PORT_STOPPED) {
15074                 printf("Please stop port %d first\n", res->port_id);
15075                 return;
15076         }
15077
15078         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15079         if (ret)
15080                 return;
15081
15082 #ifdef RTE_LIBRTE_IXGBE_PMD
15083         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15084 #endif
15085
15086         switch (ret) {
15087         case 0:
15088                 break;
15089         case -EINVAL:
15090                 printf("invalid bandwidth\n");
15091                 break;
15092         case -ENODEV:
15093                 printf("invalid port_id %d\n", res->port_id);
15094                 break;
15095         case -ENOTSUP:
15096                 printf("function not implemented\n");
15097                 break;
15098         default:
15099                 printf("programming error: (%s)\n", strerror(-ret));
15100         }
15101 }
15102
15103 cmdline_parse_inst_t cmd_tc_min_bw = {
15104         .f = cmd_tc_min_bw_parsed,
15105         .data = NULL,
15106         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15107         .tokens = {
15108                 (void *)&cmd_vf_tc_bw_set,
15109                 (void *)&cmd_vf_tc_bw_tc,
15110                 (void *)&cmd_vf_tc_bw_tx,
15111                 (void *)&cmd_vf_tc_bw_min_bw,
15112                 (void *)&cmd_vf_tc_bw_port_id,
15113                 (void *)&cmd_vf_tc_bw_bw_list,
15114                 NULL,
15115         },
15116 };
15117
15118 /* TC max bandwidth setting */
15119 static void
15120 cmd_vf_tc_max_bw_parsed(
15121         void *parsed_result,
15122         __attribute__((unused)) struct cmdline *cl,
15123         __attribute__((unused)) void *data)
15124 {
15125         struct cmd_vf_tc_bw_result *res = parsed_result;
15126         int ret = -ENOTSUP;
15127
15128         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15129                 return;
15130
15131 #ifdef RTE_LIBRTE_I40E_PMD
15132         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15133                                             res->tc_no, res->bw);
15134 #endif
15135
15136         switch (ret) {
15137         case 0:
15138                 break;
15139         case -EINVAL:
15140                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15141                        res->vf_id, res->tc_no, res->bw);
15142                 break;
15143         case -ENODEV:
15144                 printf("invalid port_id %d\n", res->port_id);
15145                 break;
15146         case -ENOTSUP:
15147                 printf("function not implemented\n");
15148                 break;
15149         default:
15150                 printf("programming error: (%s)\n", strerror(-ret));
15151         }
15152 }
15153
15154 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15155         .f = cmd_vf_tc_max_bw_parsed,
15156         .data = NULL,
15157         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15158                     " <bandwidth>",
15159         .tokens = {
15160                 (void *)&cmd_vf_tc_bw_set,
15161                 (void *)&cmd_vf_tc_bw_vf,
15162                 (void *)&cmd_vf_tc_bw_tc,
15163                 (void *)&cmd_vf_tc_bw_tx,
15164                 (void *)&cmd_vf_tc_bw_max_bw,
15165                 (void *)&cmd_vf_tc_bw_port_id,
15166                 (void *)&cmd_vf_tc_bw_vf_id,
15167                 (void *)&cmd_vf_tc_bw_tc_no,
15168                 (void *)&cmd_vf_tc_bw_bw,
15169                 NULL,
15170         },
15171 };
15172
15173
15174 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15175
15176 /* *** Set Port default Traffic Management Hierarchy *** */
15177 struct cmd_set_port_tm_hierarchy_default_result {
15178         cmdline_fixed_string_t set;
15179         cmdline_fixed_string_t port;
15180         cmdline_fixed_string_t tm;
15181         cmdline_fixed_string_t hierarchy;
15182         cmdline_fixed_string_t def;
15183         portid_t port_id;
15184 };
15185
15186 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15187         TOKEN_STRING_INITIALIZER(
15188                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15189 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15190         TOKEN_STRING_INITIALIZER(
15191                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15192 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15193         TOKEN_STRING_INITIALIZER(
15194                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15195 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15196         TOKEN_STRING_INITIALIZER(
15197                 struct cmd_set_port_tm_hierarchy_default_result,
15198                         hierarchy, "hierarchy");
15199 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15200         TOKEN_STRING_INITIALIZER(
15201                 struct cmd_set_port_tm_hierarchy_default_result,
15202                         def, "default");
15203 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15204         TOKEN_NUM_INITIALIZER(
15205                 struct cmd_set_port_tm_hierarchy_default_result,
15206                         port_id, UINT16);
15207
15208 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15209         __attribute__((unused)) struct cmdline *cl,
15210         __attribute__((unused)) void *data)
15211 {
15212         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15213         struct rte_port *p;
15214         portid_t port_id = res->port_id;
15215
15216         if (port_id_is_invalid(port_id, ENABLED_WARN))
15217                 return;
15218
15219         p = &ports[port_id];
15220
15221         /* Forward mode: tm */
15222         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15223                 printf("  softnicfwd mode not enabled(error)\n");
15224                 return;
15225         }
15226
15227         /* Set the default tm hierarchy */
15228         p->softport.default_tm_hierarchy_enable = 1;
15229 }
15230
15231 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15232         .f = cmd_set_port_tm_hierarchy_default_parsed,
15233         .data = NULL,
15234         .help_str = "set port tm hierarchy default <port_id>",
15235         .tokens = {
15236                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15237                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15238                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15239                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15240                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15241                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15242                 NULL,
15243         },
15244 };
15245 #endif
15246
15247 /** Set VXLAN encapsulation details */
15248 struct cmd_set_vxlan_result {
15249         cmdline_fixed_string_t set;
15250         cmdline_fixed_string_t vxlan;
15251         cmdline_fixed_string_t pos_token;
15252         cmdline_fixed_string_t ip_version;
15253         uint32_t vlan_present:1;
15254         uint32_t vni;
15255         uint16_t udp_src;
15256         uint16_t udp_dst;
15257         cmdline_ipaddr_t ip_src;
15258         cmdline_ipaddr_t ip_dst;
15259         uint16_t tci;
15260         uint8_t tos;
15261         uint8_t ttl;
15262         struct rte_ether_addr eth_src;
15263         struct rte_ether_addr eth_dst;
15264 };
15265
15266 cmdline_parse_token_string_t cmd_set_vxlan_set =
15267         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15268 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15269         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15270 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15271         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15272                                  "vxlan-tos-ttl");
15273 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15274         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15275                                  "vxlan-with-vlan");
15276 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15277         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15278                                  "ip-version");
15279 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15280         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15281                                  "ipv4#ipv6");
15282 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15283         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15284                                  "vni");
15285 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15286         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15287 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15288         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15289                                  "udp-src");
15290 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15291         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15292 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15293         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15294                                  "udp-dst");
15295 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15296         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15297 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15298         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15299                                  "ip-tos");
15300 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15301         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15302 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15303         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15304                                  "ip-ttl");
15305 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15306         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15307 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15308         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15309                                  "ip-src");
15310 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15311         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15312 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15313         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15314                                  "ip-dst");
15315 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15316         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15317 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15318         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15319                                  "vlan-tci");
15320 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15321         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15322 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15323         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15324                                  "eth-src");
15325 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15326         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15327 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15328         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15329                                  "eth-dst");
15330 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15331         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15332
15333 static void cmd_set_vxlan_parsed(void *parsed_result,
15334         __attribute__((unused)) struct cmdline *cl,
15335         __attribute__((unused)) void *data)
15336 {
15337         struct cmd_set_vxlan_result *res = parsed_result;
15338         union {
15339                 uint32_t vxlan_id;
15340                 uint8_t vni[4];
15341         } id = {
15342                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15343         };
15344
15345         vxlan_encap_conf.select_tos_ttl = 0;
15346         if (strcmp(res->vxlan, "vxlan") == 0)
15347                 vxlan_encap_conf.select_vlan = 0;
15348         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15349                 vxlan_encap_conf.select_vlan = 1;
15350         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15351                 vxlan_encap_conf.select_vlan = 0;
15352                 vxlan_encap_conf.select_tos_ttl = 1;
15353         }
15354         if (strcmp(res->ip_version, "ipv4") == 0)
15355                 vxlan_encap_conf.select_ipv4 = 1;
15356         else if (strcmp(res->ip_version, "ipv6") == 0)
15357                 vxlan_encap_conf.select_ipv4 = 0;
15358         else
15359                 return;
15360         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15361         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15362         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15363         vxlan_encap_conf.ip_tos = res->tos;
15364         vxlan_encap_conf.ip_ttl = res->ttl;
15365         if (vxlan_encap_conf.select_ipv4) {
15366                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15367                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15368         } else {
15369                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15370                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15371         }
15372         if (vxlan_encap_conf.select_vlan)
15373                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15374         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15375                    RTE_ETHER_ADDR_LEN);
15376         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15377                    RTE_ETHER_ADDR_LEN);
15378 }
15379
15380 cmdline_parse_inst_t cmd_set_vxlan = {
15381         .f = cmd_set_vxlan_parsed,
15382         .data = NULL,
15383         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15384                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15385                 " eth-src <eth-src> eth-dst <eth-dst>",
15386         .tokens = {
15387                 (void *)&cmd_set_vxlan_set,
15388                 (void *)&cmd_set_vxlan_vxlan,
15389                 (void *)&cmd_set_vxlan_ip_version,
15390                 (void *)&cmd_set_vxlan_ip_version_value,
15391                 (void *)&cmd_set_vxlan_vni,
15392                 (void *)&cmd_set_vxlan_vni_value,
15393                 (void *)&cmd_set_vxlan_udp_src,
15394                 (void *)&cmd_set_vxlan_udp_src_value,
15395                 (void *)&cmd_set_vxlan_udp_dst,
15396                 (void *)&cmd_set_vxlan_udp_dst_value,
15397                 (void *)&cmd_set_vxlan_ip_src,
15398                 (void *)&cmd_set_vxlan_ip_src_value,
15399                 (void *)&cmd_set_vxlan_ip_dst,
15400                 (void *)&cmd_set_vxlan_ip_dst_value,
15401                 (void *)&cmd_set_vxlan_eth_src,
15402                 (void *)&cmd_set_vxlan_eth_src_value,
15403                 (void *)&cmd_set_vxlan_eth_dst,
15404                 (void *)&cmd_set_vxlan_eth_dst_value,
15405                 NULL,
15406         },
15407 };
15408
15409 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15410         .f = cmd_set_vxlan_parsed,
15411         .data = NULL,
15412         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15413                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15414                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15415                 " eth-dst <eth-dst>",
15416         .tokens = {
15417                 (void *)&cmd_set_vxlan_set,
15418                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15419                 (void *)&cmd_set_vxlan_ip_version,
15420                 (void *)&cmd_set_vxlan_ip_version_value,
15421                 (void *)&cmd_set_vxlan_vni,
15422                 (void *)&cmd_set_vxlan_vni_value,
15423                 (void *)&cmd_set_vxlan_udp_src,
15424                 (void *)&cmd_set_vxlan_udp_src_value,
15425                 (void *)&cmd_set_vxlan_udp_dst,
15426                 (void *)&cmd_set_vxlan_udp_dst_value,
15427                 (void *)&cmd_set_vxlan_ip_tos,
15428                 (void *)&cmd_set_vxlan_ip_tos_value,
15429                 (void *)&cmd_set_vxlan_ip_ttl,
15430                 (void *)&cmd_set_vxlan_ip_ttl_value,
15431                 (void *)&cmd_set_vxlan_ip_src,
15432                 (void *)&cmd_set_vxlan_ip_src_value,
15433                 (void *)&cmd_set_vxlan_ip_dst,
15434                 (void *)&cmd_set_vxlan_ip_dst_value,
15435                 (void *)&cmd_set_vxlan_eth_src,
15436                 (void *)&cmd_set_vxlan_eth_src_value,
15437                 (void *)&cmd_set_vxlan_eth_dst,
15438                 (void *)&cmd_set_vxlan_eth_dst_value,
15439                 NULL,
15440         },
15441 };
15442
15443 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15444         .f = cmd_set_vxlan_parsed,
15445         .data = NULL,
15446         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15447                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15448                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15449                 " <eth-dst>",
15450         .tokens = {
15451                 (void *)&cmd_set_vxlan_set,
15452                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15453                 (void *)&cmd_set_vxlan_ip_version,
15454                 (void *)&cmd_set_vxlan_ip_version_value,
15455                 (void *)&cmd_set_vxlan_vni,
15456                 (void *)&cmd_set_vxlan_vni_value,
15457                 (void *)&cmd_set_vxlan_udp_src,
15458                 (void *)&cmd_set_vxlan_udp_src_value,
15459                 (void *)&cmd_set_vxlan_udp_dst,
15460                 (void *)&cmd_set_vxlan_udp_dst_value,
15461                 (void *)&cmd_set_vxlan_ip_src,
15462                 (void *)&cmd_set_vxlan_ip_src_value,
15463                 (void *)&cmd_set_vxlan_ip_dst,
15464                 (void *)&cmd_set_vxlan_ip_dst_value,
15465                 (void *)&cmd_set_vxlan_vlan,
15466                 (void *)&cmd_set_vxlan_vlan_value,
15467                 (void *)&cmd_set_vxlan_eth_src,
15468                 (void *)&cmd_set_vxlan_eth_src_value,
15469                 (void *)&cmd_set_vxlan_eth_dst,
15470                 (void *)&cmd_set_vxlan_eth_dst_value,
15471                 NULL,
15472         },
15473 };
15474
15475 /** Set NVGRE encapsulation details */
15476 struct cmd_set_nvgre_result {
15477         cmdline_fixed_string_t set;
15478         cmdline_fixed_string_t nvgre;
15479         cmdline_fixed_string_t pos_token;
15480         cmdline_fixed_string_t ip_version;
15481         uint32_t tni;
15482         cmdline_ipaddr_t ip_src;
15483         cmdline_ipaddr_t ip_dst;
15484         uint16_t tci;
15485         struct rte_ether_addr eth_src;
15486         struct rte_ether_addr eth_dst;
15487 };
15488
15489 cmdline_parse_token_string_t cmd_set_nvgre_set =
15490         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15491 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15492         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15493 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15494         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15495                                  "nvgre-with-vlan");
15496 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15497         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15498                                  "ip-version");
15499 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15500         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15501                                  "ipv4#ipv6");
15502 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15503         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15504                                  "tni");
15505 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15506         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15507 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15508         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15509                                  "ip-src");
15510 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15511         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15512 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15513         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15514                                  "ip-dst");
15515 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15516         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15517 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15518         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15519                                  "vlan-tci");
15520 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15521         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15522 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15523         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15524                                  "eth-src");
15525 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15526         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15527 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15528         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15529                                  "eth-dst");
15530 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15531         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15532
15533 static void cmd_set_nvgre_parsed(void *parsed_result,
15534         __attribute__((unused)) struct cmdline *cl,
15535         __attribute__((unused)) void *data)
15536 {
15537         struct cmd_set_nvgre_result *res = parsed_result;
15538         union {
15539                 uint32_t nvgre_tni;
15540                 uint8_t tni[4];
15541         } id = {
15542                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15543         };
15544
15545         if (strcmp(res->nvgre, "nvgre") == 0)
15546                 nvgre_encap_conf.select_vlan = 0;
15547         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15548                 nvgre_encap_conf.select_vlan = 1;
15549         if (strcmp(res->ip_version, "ipv4") == 0)
15550                 nvgre_encap_conf.select_ipv4 = 1;
15551         else if (strcmp(res->ip_version, "ipv6") == 0)
15552                 nvgre_encap_conf.select_ipv4 = 0;
15553         else
15554                 return;
15555         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15556         if (nvgre_encap_conf.select_ipv4) {
15557                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15558                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15559         } else {
15560                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15561                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15562         }
15563         if (nvgre_encap_conf.select_vlan)
15564                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15565         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15566                    RTE_ETHER_ADDR_LEN);
15567         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15568                    RTE_ETHER_ADDR_LEN);
15569 }
15570
15571 cmdline_parse_inst_t cmd_set_nvgre = {
15572         .f = cmd_set_nvgre_parsed,
15573         .data = NULL,
15574         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15575                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15576                 " eth-dst <eth-dst>",
15577         .tokens = {
15578                 (void *)&cmd_set_nvgre_set,
15579                 (void *)&cmd_set_nvgre_nvgre,
15580                 (void *)&cmd_set_nvgre_ip_version,
15581                 (void *)&cmd_set_nvgre_ip_version_value,
15582                 (void *)&cmd_set_nvgre_tni,
15583                 (void *)&cmd_set_nvgre_tni_value,
15584                 (void *)&cmd_set_nvgre_ip_src,
15585                 (void *)&cmd_set_nvgre_ip_src_value,
15586                 (void *)&cmd_set_nvgre_ip_dst,
15587                 (void *)&cmd_set_nvgre_ip_dst_value,
15588                 (void *)&cmd_set_nvgre_eth_src,
15589                 (void *)&cmd_set_nvgre_eth_src_value,
15590                 (void *)&cmd_set_nvgre_eth_dst,
15591                 (void *)&cmd_set_nvgre_eth_dst_value,
15592                 NULL,
15593         },
15594 };
15595
15596 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15597         .f = cmd_set_nvgre_parsed,
15598         .data = NULL,
15599         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15600                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15601                 " eth-src <eth-src> eth-dst <eth-dst>",
15602         .tokens = {
15603                 (void *)&cmd_set_nvgre_set,
15604                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15605                 (void *)&cmd_set_nvgre_ip_version,
15606                 (void *)&cmd_set_nvgre_ip_version_value,
15607                 (void *)&cmd_set_nvgre_tni,
15608                 (void *)&cmd_set_nvgre_tni_value,
15609                 (void *)&cmd_set_nvgre_ip_src,
15610                 (void *)&cmd_set_nvgre_ip_src_value,
15611                 (void *)&cmd_set_nvgre_ip_dst,
15612                 (void *)&cmd_set_nvgre_ip_dst_value,
15613                 (void *)&cmd_set_nvgre_vlan,
15614                 (void *)&cmd_set_nvgre_vlan_value,
15615                 (void *)&cmd_set_nvgre_eth_src,
15616                 (void *)&cmd_set_nvgre_eth_src_value,
15617                 (void *)&cmd_set_nvgre_eth_dst,
15618                 (void *)&cmd_set_nvgre_eth_dst_value,
15619                 NULL,
15620         },
15621 };
15622
15623 /** Set L2 encapsulation details */
15624 struct cmd_set_l2_encap_result {
15625         cmdline_fixed_string_t set;
15626         cmdline_fixed_string_t l2_encap;
15627         cmdline_fixed_string_t pos_token;
15628         cmdline_fixed_string_t ip_version;
15629         uint32_t vlan_present:1;
15630         uint16_t tci;
15631         struct rte_ether_addr eth_src;
15632         struct rte_ether_addr eth_dst;
15633 };
15634
15635 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15636         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15637 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15638         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15639 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15640         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15641                                  "l2_encap-with-vlan");
15642 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15643         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15644                                  "ip-version");
15645 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15646         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15647                                  "ipv4#ipv6");
15648 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15649         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15650                                  "vlan-tci");
15651 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15652         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15653 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15654         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15655                                  "eth-src");
15656 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15657         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15658 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15659         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15660                                  "eth-dst");
15661 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15662         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15663
15664 static void cmd_set_l2_encap_parsed(void *parsed_result,
15665         __attribute__((unused)) struct cmdline *cl,
15666         __attribute__((unused)) void *data)
15667 {
15668         struct cmd_set_l2_encap_result *res = parsed_result;
15669
15670         if (strcmp(res->l2_encap, "l2_encap") == 0)
15671                 l2_encap_conf.select_vlan = 0;
15672         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15673                 l2_encap_conf.select_vlan = 1;
15674         if (strcmp(res->ip_version, "ipv4") == 0)
15675                 l2_encap_conf.select_ipv4 = 1;
15676         else if (strcmp(res->ip_version, "ipv6") == 0)
15677                 l2_encap_conf.select_ipv4 = 0;
15678         else
15679                 return;
15680         if (l2_encap_conf.select_vlan)
15681                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15682         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15683                    RTE_ETHER_ADDR_LEN);
15684         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15685                    RTE_ETHER_ADDR_LEN);
15686 }
15687
15688 cmdline_parse_inst_t cmd_set_l2_encap = {
15689         .f = cmd_set_l2_encap_parsed,
15690         .data = NULL,
15691         .help_str = "set l2_encap ip-version ipv4|ipv6"
15692                 " eth-src <eth-src> eth-dst <eth-dst>",
15693         .tokens = {
15694                 (void *)&cmd_set_l2_encap_set,
15695                 (void *)&cmd_set_l2_encap_l2_encap,
15696                 (void *)&cmd_set_l2_encap_ip_version,
15697                 (void *)&cmd_set_l2_encap_ip_version_value,
15698                 (void *)&cmd_set_l2_encap_eth_src,
15699                 (void *)&cmd_set_l2_encap_eth_src_value,
15700                 (void *)&cmd_set_l2_encap_eth_dst,
15701                 (void *)&cmd_set_l2_encap_eth_dst_value,
15702                 NULL,
15703         },
15704 };
15705
15706 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15707         .f = cmd_set_l2_encap_parsed,
15708         .data = NULL,
15709         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15710                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15711         .tokens = {
15712                 (void *)&cmd_set_l2_encap_set,
15713                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15714                 (void *)&cmd_set_l2_encap_ip_version,
15715                 (void *)&cmd_set_l2_encap_ip_version_value,
15716                 (void *)&cmd_set_l2_encap_vlan,
15717                 (void *)&cmd_set_l2_encap_vlan_value,
15718                 (void *)&cmd_set_l2_encap_eth_src,
15719                 (void *)&cmd_set_l2_encap_eth_src_value,
15720                 (void *)&cmd_set_l2_encap_eth_dst,
15721                 (void *)&cmd_set_l2_encap_eth_dst_value,
15722                 NULL,
15723         },
15724 };
15725
15726 /** Set L2 decapsulation details */
15727 struct cmd_set_l2_decap_result {
15728         cmdline_fixed_string_t set;
15729         cmdline_fixed_string_t l2_decap;
15730         cmdline_fixed_string_t pos_token;
15731         uint32_t vlan_present:1;
15732 };
15733
15734 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15735         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15736 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15737         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15738                                  "l2_decap");
15739 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15740         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15741                                  "l2_decap-with-vlan");
15742
15743 static void cmd_set_l2_decap_parsed(void *parsed_result,
15744         __attribute__((unused)) struct cmdline *cl,
15745         __attribute__((unused)) void *data)
15746 {
15747         struct cmd_set_l2_decap_result *res = parsed_result;
15748
15749         if (strcmp(res->l2_decap, "l2_decap") == 0)
15750                 l2_decap_conf.select_vlan = 0;
15751         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15752                 l2_decap_conf.select_vlan = 1;
15753 }
15754
15755 cmdline_parse_inst_t cmd_set_l2_decap = {
15756         .f = cmd_set_l2_decap_parsed,
15757         .data = NULL,
15758         .help_str = "set l2_decap",
15759         .tokens = {
15760                 (void *)&cmd_set_l2_decap_set,
15761                 (void *)&cmd_set_l2_decap_l2_decap,
15762                 NULL,
15763         },
15764 };
15765
15766 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15767         .f = cmd_set_l2_decap_parsed,
15768         .data = NULL,
15769         .help_str = "set l2_decap-with-vlan",
15770         .tokens = {
15771                 (void *)&cmd_set_l2_decap_set,
15772                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15773                 NULL,
15774         },
15775 };
15776
15777 /** Set MPLSoGRE encapsulation details */
15778 struct cmd_set_mplsogre_encap_result {
15779         cmdline_fixed_string_t set;
15780         cmdline_fixed_string_t mplsogre;
15781         cmdline_fixed_string_t pos_token;
15782         cmdline_fixed_string_t ip_version;
15783         uint32_t vlan_present:1;
15784         uint32_t label;
15785         cmdline_ipaddr_t ip_src;
15786         cmdline_ipaddr_t ip_dst;
15787         uint16_t tci;
15788         struct rte_ether_addr eth_src;
15789         struct rte_ether_addr eth_dst;
15790 };
15791
15792 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15793         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15794                                  "set");
15795 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15796         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15797                                  "mplsogre_encap");
15798 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15799         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15800                                  mplsogre, "mplsogre_encap-with-vlan");
15801 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15802         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15803                                  pos_token, "ip-version");
15804 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15805         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15806                                  ip_version, "ipv4#ipv6");
15807 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15808         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15809                                  pos_token, "label");
15810 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15811         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15812                               UINT32);
15813 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15814         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15815                                  pos_token, "ip-src");
15816 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15817         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15818 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15819         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15820                                  pos_token, "ip-dst");
15821 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15822         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15823 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15824         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15825                                  pos_token, "vlan-tci");
15826 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15827         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15828                               UINT16);
15829 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15830         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15831                                  pos_token, "eth-src");
15832 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15833         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15834                                     eth_src);
15835 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15836         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15837                                  pos_token, "eth-dst");
15838 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15839         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15840                                     eth_dst);
15841
15842 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15843         __attribute__((unused)) struct cmdline *cl,
15844         __attribute__((unused)) void *data)
15845 {
15846         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15847         union {
15848                 uint32_t mplsogre_label;
15849                 uint8_t label[4];
15850         } id = {
15851                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15852         };
15853
15854         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15855                 mplsogre_encap_conf.select_vlan = 0;
15856         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15857                 mplsogre_encap_conf.select_vlan = 1;
15858         if (strcmp(res->ip_version, "ipv4") == 0)
15859                 mplsogre_encap_conf.select_ipv4 = 1;
15860         else if (strcmp(res->ip_version, "ipv6") == 0)
15861                 mplsogre_encap_conf.select_ipv4 = 0;
15862         else
15863                 return;
15864         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15865         if (mplsogre_encap_conf.select_ipv4) {
15866                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15867                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15868         } else {
15869                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15870                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15871         }
15872         if (mplsogre_encap_conf.select_vlan)
15873                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15874         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15875                    RTE_ETHER_ADDR_LEN);
15876         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15877                    RTE_ETHER_ADDR_LEN);
15878 }
15879
15880 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15881         .f = cmd_set_mplsogre_encap_parsed,
15882         .data = NULL,
15883         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15884                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15885                 " eth-dst <eth-dst>",
15886         .tokens = {
15887                 (void *)&cmd_set_mplsogre_encap_set,
15888                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15889                 (void *)&cmd_set_mplsogre_encap_ip_version,
15890                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15891                 (void *)&cmd_set_mplsogre_encap_label,
15892                 (void *)&cmd_set_mplsogre_encap_label_value,
15893                 (void *)&cmd_set_mplsogre_encap_ip_src,
15894                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15895                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15896                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15897                 (void *)&cmd_set_mplsogre_encap_eth_src,
15898                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15899                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15900                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15901                 NULL,
15902         },
15903 };
15904
15905 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15906         .f = cmd_set_mplsogre_encap_parsed,
15907         .data = NULL,
15908         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15909                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15910                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15911         .tokens = {
15912                 (void *)&cmd_set_mplsogre_encap_set,
15913                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15914                 (void *)&cmd_set_mplsogre_encap_ip_version,
15915                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15916                 (void *)&cmd_set_mplsogre_encap_label,
15917                 (void *)&cmd_set_mplsogre_encap_label_value,
15918                 (void *)&cmd_set_mplsogre_encap_ip_src,
15919                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15920                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15921                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15922                 (void *)&cmd_set_mplsogre_encap_vlan,
15923                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15924                 (void *)&cmd_set_mplsogre_encap_eth_src,
15925                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15926                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15927                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15928                 NULL,
15929         },
15930 };
15931
15932 /** Set MPLSoGRE decapsulation details */
15933 struct cmd_set_mplsogre_decap_result {
15934         cmdline_fixed_string_t set;
15935         cmdline_fixed_string_t mplsogre;
15936         cmdline_fixed_string_t pos_token;
15937         cmdline_fixed_string_t ip_version;
15938         uint32_t vlan_present:1;
15939 };
15940
15941 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15942         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15943                                  "set");
15944 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15945         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15946                                  "mplsogre_decap");
15947 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15948         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15949                                  mplsogre, "mplsogre_decap-with-vlan");
15950 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15951         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15952                                  pos_token, "ip-version");
15953 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15954         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15955                                  ip_version, "ipv4#ipv6");
15956
15957 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15958         __attribute__((unused)) struct cmdline *cl,
15959         __attribute__((unused)) void *data)
15960 {
15961         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15962
15963         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15964                 mplsogre_decap_conf.select_vlan = 0;
15965         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15966                 mplsogre_decap_conf.select_vlan = 1;
15967         if (strcmp(res->ip_version, "ipv4") == 0)
15968                 mplsogre_decap_conf.select_ipv4 = 1;
15969         else if (strcmp(res->ip_version, "ipv6") == 0)
15970                 mplsogre_decap_conf.select_ipv4 = 0;
15971 }
15972
15973 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15974         .f = cmd_set_mplsogre_decap_parsed,
15975         .data = NULL,
15976         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15977         .tokens = {
15978                 (void *)&cmd_set_mplsogre_decap_set,
15979                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15980                 (void *)&cmd_set_mplsogre_decap_ip_version,
15981                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15982                 NULL,
15983         },
15984 };
15985
15986 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15987         .f = cmd_set_mplsogre_decap_parsed,
15988         .data = NULL,
15989         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15990         .tokens = {
15991                 (void *)&cmd_set_mplsogre_decap_set,
15992                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15993                 (void *)&cmd_set_mplsogre_decap_ip_version,
15994                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15995                 NULL,
15996         },
15997 };
15998
15999 /** Set MPLSoUDP encapsulation details */
16000 struct cmd_set_mplsoudp_encap_result {
16001         cmdline_fixed_string_t set;
16002         cmdline_fixed_string_t mplsoudp;
16003         cmdline_fixed_string_t pos_token;
16004         cmdline_fixed_string_t ip_version;
16005         uint32_t vlan_present:1;
16006         uint32_t label;
16007         uint16_t udp_src;
16008         uint16_t udp_dst;
16009         cmdline_ipaddr_t ip_src;
16010         cmdline_ipaddr_t ip_dst;
16011         uint16_t tci;
16012         struct rte_ether_addr eth_src;
16013         struct rte_ether_addr eth_dst;
16014 };
16015
16016 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16017         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16018                                  "set");
16019 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16020         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16021                                  "mplsoudp_encap");
16022 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16023         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16024                                  mplsoudp, "mplsoudp_encap-with-vlan");
16025 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16026         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16027                                  pos_token, "ip-version");
16028 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16029         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16030                                  ip_version, "ipv4#ipv6");
16031 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16032         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16033                                  pos_token, "label");
16034 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16035         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16036                               UINT32);
16037 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16038         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16039                                  pos_token, "udp-src");
16040 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16041         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16042                               UINT16);
16043 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16044         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16045                                  pos_token, "udp-dst");
16046 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16047         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16048                               UINT16);
16049 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16050         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16051                                  pos_token, "ip-src");
16052 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16053         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16054 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16055         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16056                                  pos_token, "ip-dst");
16057 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16058         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16059 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16060         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16061                                  pos_token, "vlan-tci");
16062 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16063         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16064                               UINT16);
16065 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16066         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16067                                  pos_token, "eth-src");
16068 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16069         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16070                                     eth_src);
16071 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16072         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16073                                  pos_token, "eth-dst");
16074 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16075         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16076                                     eth_dst);
16077
16078 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16079         __attribute__((unused)) struct cmdline *cl,
16080         __attribute__((unused)) void *data)
16081 {
16082         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16083         union {
16084                 uint32_t mplsoudp_label;
16085                 uint8_t label[4];
16086         } id = {
16087                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16088         };
16089
16090         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16091                 mplsoudp_encap_conf.select_vlan = 0;
16092         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16093                 mplsoudp_encap_conf.select_vlan = 1;
16094         if (strcmp(res->ip_version, "ipv4") == 0)
16095                 mplsoudp_encap_conf.select_ipv4 = 1;
16096         else if (strcmp(res->ip_version, "ipv6") == 0)
16097                 mplsoudp_encap_conf.select_ipv4 = 0;
16098         else
16099                 return;
16100         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16101         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16102         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16103         if (mplsoudp_encap_conf.select_ipv4) {
16104                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16105                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16106         } else {
16107                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16108                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16109         }
16110         if (mplsoudp_encap_conf.select_vlan)
16111                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16112         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16113                    RTE_ETHER_ADDR_LEN);
16114         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16115                    RTE_ETHER_ADDR_LEN);
16116 }
16117
16118 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16119         .f = cmd_set_mplsoudp_encap_parsed,
16120         .data = NULL,
16121         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16122                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16123                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16124         .tokens = {
16125                 (void *)&cmd_set_mplsoudp_encap_set,
16126                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16127                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16128                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16129                 (void *)&cmd_set_mplsoudp_encap_label,
16130                 (void *)&cmd_set_mplsoudp_encap_label_value,
16131                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16132                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16133                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16134                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16135                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16136                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16137                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16138                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16139                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16140                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16141                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16142                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16143                 NULL,
16144         },
16145 };
16146
16147 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16148         .f = cmd_set_mplsoudp_encap_parsed,
16149         .data = NULL,
16150         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16151                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16152                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16153                 " eth-src <eth-src> eth-dst <eth-dst>",
16154         .tokens = {
16155                 (void *)&cmd_set_mplsoudp_encap_set,
16156                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16157                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16158                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16159                 (void *)&cmd_set_mplsoudp_encap_label,
16160                 (void *)&cmd_set_mplsoudp_encap_label_value,
16161                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16162                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16163                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16164                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16165                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16166                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16167                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16168                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16169                 (void *)&cmd_set_mplsoudp_encap_vlan,
16170                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16171                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16172                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16173                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16174                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16175                 NULL,
16176         },
16177 };
16178
16179 /** Set MPLSoUDP decapsulation details */
16180 struct cmd_set_mplsoudp_decap_result {
16181         cmdline_fixed_string_t set;
16182         cmdline_fixed_string_t mplsoudp;
16183         cmdline_fixed_string_t pos_token;
16184         cmdline_fixed_string_t ip_version;
16185         uint32_t vlan_present:1;
16186 };
16187
16188 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16189         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16190                                  "set");
16191 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16192         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16193                                  "mplsoudp_decap");
16194 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16195         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16196                                  mplsoudp, "mplsoudp_decap-with-vlan");
16197 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16198         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16199                                  pos_token, "ip-version");
16200 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16201         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16202                                  ip_version, "ipv4#ipv6");
16203
16204 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16205         __attribute__((unused)) struct cmdline *cl,
16206         __attribute__((unused)) void *data)
16207 {
16208         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16209
16210         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16211                 mplsoudp_decap_conf.select_vlan = 0;
16212         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16213                 mplsoudp_decap_conf.select_vlan = 1;
16214         if (strcmp(res->ip_version, "ipv4") == 0)
16215                 mplsoudp_decap_conf.select_ipv4 = 1;
16216         else if (strcmp(res->ip_version, "ipv6") == 0)
16217                 mplsoudp_decap_conf.select_ipv4 = 0;
16218 }
16219
16220 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16221         .f = cmd_set_mplsoudp_decap_parsed,
16222         .data = NULL,
16223         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16224         .tokens = {
16225                 (void *)&cmd_set_mplsoudp_decap_set,
16226                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16227                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16228                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16229                 NULL,
16230         },
16231 };
16232
16233 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16234         .f = cmd_set_mplsoudp_decap_parsed,
16235         .data = NULL,
16236         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16237         .tokens = {
16238                 (void *)&cmd_set_mplsoudp_decap_set,
16239                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16240                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16241                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16242                 NULL,
16243         },
16244 };
16245
16246 /* Strict link priority scheduling mode setting */
16247 static void
16248 cmd_strict_link_prio_parsed(
16249         void *parsed_result,
16250         __attribute__((unused)) struct cmdline *cl,
16251         __attribute__((unused)) void *data)
16252 {
16253         struct cmd_vf_tc_bw_result *res = parsed_result;
16254         int ret = -ENOTSUP;
16255
16256         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16257                 return;
16258
16259 #ifdef RTE_LIBRTE_I40E_PMD
16260         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16261 #endif
16262
16263         switch (ret) {
16264         case 0:
16265                 break;
16266         case -EINVAL:
16267                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16268                 break;
16269         case -ENODEV:
16270                 printf("invalid port_id %d\n", res->port_id);
16271                 break;
16272         case -ENOTSUP:
16273                 printf("function not implemented\n");
16274                 break;
16275         default:
16276                 printf("programming error: (%s)\n", strerror(-ret));
16277         }
16278 }
16279
16280 cmdline_parse_inst_t cmd_strict_link_prio = {
16281         .f = cmd_strict_link_prio_parsed,
16282         .data = NULL,
16283         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16284         .tokens = {
16285                 (void *)&cmd_vf_tc_bw_set,
16286                 (void *)&cmd_vf_tc_bw_tx,
16287                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16288                 (void *)&cmd_vf_tc_bw_port_id,
16289                 (void *)&cmd_vf_tc_bw_tc_map,
16290                 NULL,
16291         },
16292 };
16293
16294 /* Load dynamic device personalization*/
16295 struct cmd_ddp_add_result {
16296         cmdline_fixed_string_t ddp;
16297         cmdline_fixed_string_t add;
16298         portid_t port_id;
16299         char filepath[];
16300 };
16301
16302 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16303         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16304 cmdline_parse_token_string_t cmd_ddp_add_add =
16305         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16306 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16307         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16308 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16309         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16310
16311 static void
16312 cmd_ddp_add_parsed(
16313         void *parsed_result,
16314         __attribute__((unused)) struct cmdline *cl,
16315         __attribute__((unused)) void *data)
16316 {
16317         struct cmd_ddp_add_result *res = parsed_result;
16318         uint8_t *buff;
16319         uint32_t size;
16320         char *filepath;
16321         char *file_fld[2];
16322         int file_num;
16323         int ret = -ENOTSUP;
16324
16325         if (!all_ports_stopped()) {
16326                 printf("Please stop all ports first\n");
16327                 return;
16328         }
16329
16330         filepath = strdup(res->filepath);
16331         if (filepath == NULL) {
16332                 printf("Failed to allocate memory\n");
16333                 return;
16334         }
16335         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16336
16337         buff = open_file(file_fld[0], &size);
16338         if (!buff) {
16339                 free((void *)filepath);
16340                 return;
16341         }
16342
16343 #ifdef RTE_LIBRTE_I40E_PMD
16344         if (ret == -ENOTSUP)
16345                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16346                                                buff, size,
16347                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16348 #endif
16349
16350         if (ret == -EEXIST)
16351                 printf("Profile has already existed.\n");
16352         else if (ret < 0)
16353                 printf("Failed to load profile.\n");
16354         else if (file_num == 2)
16355                 save_file(file_fld[1], buff, size);
16356
16357         close_file(buff);
16358         free((void *)filepath);
16359 }
16360
16361 cmdline_parse_inst_t cmd_ddp_add = {
16362         .f = cmd_ddp_add_parsed,
16363         .data = NULL,
16364         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16365         .tokens = {
16366                 (void *)&cmd_ddp_add_ddp,
16367                 (void *)&cmd_ddp_add_add,
16368                 (void *)&cmd_ddp_add_port_id,
16369                 (void *)&cmd_ddp_add_filepath,
16370                 NULL,
16371         },
16372 };
16373
16374 /* Delete dynamic device personalization*/
16375 struct cmd_ddp_del_result {
16376         cmdline_fixed_string_t ddp;
16377         cmdline_fixed_string_t del;
16378         portid_t port_id;
16379         char filepath[];
16380 };
16381
16382 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16383         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16384 cmdline_parse_token_string_t cmd_ddp_del_del =
16385         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16386 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16387         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16388 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16389         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16390
16391 static void
16392 cmd_ddp_del_parsed(
16393         void *parsed_result,
16394         __attribute__((unused)) struct cmdline *cl,
16395         __attribute__((unused)) void *data)
16396 {
16397         struct cmd_ddp_del_result *res = parsed_result;
16398         uint8_t *buff;
16399         uint32_t size;
16400         int ret = -ENOTSUP;
16401
16402         if (!all_ports_stopped()) {
16403                 printf("Please stop all ports first\n");
16404                 return;
16405         }
16406
16407         buff = open_file(res->filepath, &size);
16408         if (!buff)
16409                 return;
16410
16411 #ifdef RTE_LIBRTE_I40E_PMD
16412         if (ret == -ENOTSUP)
16413                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16414                                                buff, size,
16415                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16416 #endif
16417
16418         if (ret == -EACCES)
16419                 printf("Profile does not exist.\n");
16420         else if (ret < 0)
16421                 printf("Failed to delete profile.\n");
16422
16423         close_file(buff);
16424 }
16425
16426 cmdline_parse_inst_t cmd_ddp_del = {
16427         .f = cmd_ddp_del_parsed,
16428         .data = NULL,
16429         .help_str = "ddp del <port_id> <backup_profile_path>",
16430         .tokens = {
16431                 (void *)&cmd_ddp_del_ddp,
16432                 (void *)&cmd_ddp_del_del,
16433                 (void *)&cmd_ddp_del_port_id,
16434                 (void *)&cmd_ddp_del_filepath,
16435                 NULL,
16436         },
16437 };
16438
16439 /* Get dynamic device personalization profile info */
16440 struct cmd_ddp_info_result {
16441         cmdline_fixed_string_t ddp;
16442         cmdline_fixed_string_t get;
16443         cmdline_fixed_string_t info;
16444         char filepath[];
16445 };
16446
16447 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16448         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16449 cmdline_parse_token_string_t cmd_ddp_info_get =
16450         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16451 cmdline_parse_token_string_t cmd_ddp_info_info =
16452         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16453 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16454         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16455
16456 static void
16457 cmd_ddp_info_parsed(
16458         void *parsed_result,
16459         __attribute__((unused)) struct cmdline *cl,
16460         __attribute__((unused)) void *data)
16461 {
16462         struct cmd_ddp_info_result *res = parsed_result;
16463         uint8_t *pkg;
16464         uint32_t pkg_size;
16465         int ret = -ENOTSUP;
16466 #ifdef RTE_LIBRTE_I40E_PMD
16467         uint32_t i, j, n;
16468         uint8_t *buff;
16469         uint32_t buff_size = 0;
16470         struct rte_pmd_i40e_profile_info info;
16471         uint32_t dev_num = 0;
16472         struct rte_pmd_i40e_ddp_device_id *devs;
16473         uint32_t proto_num = 0;
16474         struct rte_pmd_i40e_proto_info *proto = NULL;
16475         uint32_t pctype_num = 0;
16476         struct rte_pmd_i40e_ptype_info *pctype;
16477         uint32_t ptype_num = 0;
16478         struct rte_pmd_i40e_ptype_info *ptype;
16479         uint8_t proto_id;
16480
16481 #endif
16482
16483         pkg = open_file(res->filepath, &pkg_size);
16484         if (!pkg)
16485                 return;
16486
16487 #ifdef RTE_LIBRTE_I40E_PMD
16488         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16489                                 (uint8_t *)&info, sizeof(info),
16490                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16491         if (!ret) {
16492                 printf("Global Track id:       0x%x\n", info.track_id);
16493                 printf("Global Version:        %d.%d.%d.%d\n",
16494                         info.version.major,
16495                         info.version.minor,
16496                         info.version.update,
16497                         info.version.draft);
16498                 printf("Global Package name:   %s\n\n", info.name);
16499         }
16500
16501         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16502                                 (uint8_t *)&info, sizeof(info),
16503                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16504         if (!ret) {
16505                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16506                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16507                         info.version.major,
16508                         info.version.minor,
16509                         info.version.update,
16510                         info.version.draft);
16511                 printf("i40e Profile name:     %s\n\n", info.name);
16512         }
16513
16514         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16515                                 (uint8_t *)&buff_size, sizeof(buff_size),
16516                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16517         if (!ret && buff_size) {
16518                 buff = (uint8_t *)malloc(buff_size);
16519                 if (buff) {
16520                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16521                                                 buff, buff_size,
16522                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16523                         if (!ret)
16524                                 printf("Package Notes:\n%s\n\n", buff);
16525                         free(buff);
16526                 }
16527         }
16528
16529         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16530                                 (uint8_t *)&dev_num, sizeof(dev_num),
16531                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16532         if (!ret && dev_num) {
16533                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16534                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16535                 if (devs) {
16536                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16537                                                 (uint8_t *)devs, buff_size,
16538                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16539                         if (!ret) {
16540                                 printf("List of supported devices:\n");
16541                                 for (i = 0; i < dev_num; i++) {
16542                                         printf("  %04X:%04X %04X:%04X\n",
16543                                                 devs[i].vendor_dev_id >> 16,
16544                                                 devs[i].vendor_dev_id & 0xFFFF,
16545                                                 devs[i].sub_vendor_dev_id >> 16,
16546                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16547                                 }
16548                                 printf("\n");
16549                         }
16550                         free(devs);
16551                 }
16552         }
16553
16554         /* get information about protocols and packet types */
16555         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16556                 (uint8_t *)&proto_num, sizeof(proto_num),
16557                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16558         if (ret || !proto_num)
16559                 goto no_print_return;
16560
16561         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16562         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16563         if (!proto)
16564                 goto no_print_return;
16565
16566         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16567                                         buff_size,
16568                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16569         if (!ret) {
16570                 printf("List of used protocols:\n");
16571                 for (i = 0; i < proto_num; i++)
16572                         printf("  %2u: %s\n", proto[i].proto_id,
16573                                proto[i].name);
16574                 printf("\n");
16575         }
16576         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16577                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16578                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16579         if (ret || !pctype_num)
16580                 goto no_print_pctypes;
16581
16582         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16583         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16584         if (!pctype)
16585                 goto no_print_pctypes;
16586
16587         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16588                                         buff_size,
16589                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16590         if (ret) {
16591                 free(pctype);
16592                 goto no_print_pctypes;
16593         }
16594
16595         printf("List of defined packet classification types:\n");
16596         for (i = 0; i < pctype_num; i++) {
16597                 printf("  %2u:", pctype[i].ptype_id);
16598                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16599                         proto_id = pctype[i].protocols[j];
16600                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16601                                 for (n = 0; n < proto_num; n++) {
16602                                         if (proto[n].proto_id == proto_id) {
16603                                                 printf(" %s", proto[n].name);
16604                                                 break;
16605                                         }
16606                                 }
16607                         }
16608                 }
16609                 printf("\n");
16610         }
16611         printf("\n");
16612         free(pctype);
16613
16614 no_print_pctypes:
16615
16616         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16617                                         sizeof(ptype_num),
16618                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16619         if (ret || !ptype_num)
16620                 goto no_print_return;
16621
16622         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16623         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16624         if (!ptype)
16625                 goto no_print_return;
16626
16627         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16628                                         buff_size,
16629                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16630         if (ret) {
16631                 free(ptype);
16632                 goto no_print_return;
16633         }
16634         printf("List of defined packet types:\n");
16635         for (i = 0; i < ptype_num; i++) {
16636                 printf("  %2u:", ptype[i].ptype_id);
16637                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16638                         proto_id = ptype[i].protocols[j];
16639                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16640                                 for (n = 0; n < proto_num; n++) {
16641                                         if (proto[n].proto_id == proto_id) {
16642                                                 printf(" %s", proto[n].name);
16643                                                 break;
16644                                         }
16645                                 }
16646                         }
16647                 }
16648                 printf("\n");
16649         }
16650         free(ptype);
16651         printf("\n");
16652
16653         ret = 0;
16654 no_print_return:
16655         if (proto)
16656                 free(proto);
16657 #endif
16658         if (ret == -ENOTSUP)
16659                 printf("Function not supported in PMD driver\n");
16660         close_file(pkg);
16661 }
16662
16663 cmdline_parse_inst_t cmd_ddp_get_info = {
16664         .f = cmd_ddp_info_parsed,
16665         .data = NULL,
16666         .help_str = "ddp get info <profile_path>",
16667         .tokens = {
16668                 (void *)&cmd_ddp_info_ddp,
16669                 (void *)&cmd_ddp_info_get,
16670                 (void *)&cmd_ddp_info_info,
16671                 (void *)&cmd_ddp_info_filepath,
16672                 NULL,
16673         },
16674 };
16675
16676 /* Get dynamic device personalization profile info list*/
16677 #define PROFILE_INFO_SIZE 48
16678 #define MAX_PROFILE_NUM 16
16679
16680 struct cmd_ddp_get_list_result {
16681         cmdline_fixed_string_t ddp;
16682         cmdline_fixed_string_t get;
16683         cmdline_fixed_string_t list;
16684         portid_t port_id;
16685 };
16686
16687 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16688         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16689 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16690         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16691 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16692         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16693 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16694         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16695
16696 static void
16697 cmd_ddp_get_list_parsed(
16698         __attribute__((unused)) void *parsed_result,
16699         __attribute__((unused)) struct cmdline *cl,
16700         __attribute__((unused)) void *data)
16701 {
16702 #ifdef RTE_LIBRTE_I40E_PMD
16703         struct cmd_ddp_get_list_result *res = parsed_result;
16704         struct rte_pmd_i40e_profile_list *p_list;
16705         struct rte_pmd_i40e_profile_info *p_info;
16706         uint32_t p_num;
16707         uint32_t size;
16708         uint32_t i;
16709 #endif
16710         int ret = -ENOTSUP;
16711
16712 #ifdef RTE_LIBRTE_I40E_PMD
16713         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16714         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16715         if (!p_list)
16716                 printf("%s: Failed to malloc buffer\n", __func__);
16717
16718         if (ret == -ENOTSUP)
16719                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16720                                                 (uint8_t *)p_list, size);
16721
16722         if (!ret) {
16723                 p_num = p_list->p_count;
16724                 printf("Profile number is: %d\n\n", p_num);
16725
16726                 for (i = 0; i < p_num; i++) {
16727                         p_info = &p_list->p_info[i];
16728                         printf("Profile %d:\n", i);
16729                         printf("Track id:     0x%x\n", p_info->track_id);
16730                         printf("Version:      %d.%d.%d.%d\n",
16731                                p_info->version.major,
16732                                p_info->version.minor,
16733                                p_info->version.update,
16734                                p_info->version.draft);
16735                         printf("Profile name: %s\n\n", p_info->name);
16736                 }
16737         }
16738
16739         free(p_list);
16740 #endif
16741
16742         if (ret < 0)
16743                 printf("Failed to get ddp list\n");
16744 }
16745
16746 cmdline_parse_inst_t cmd_ddp_get_list = {
16747         .f = cmd_ddp_get_list_parsed,
16748         .data = NULL,
16749         .help_str = "ddp get list <port_id>",
16750         .tokens = {
16751                 (void *)&cmd_ddp_get_list_ddp,
16752                 (void *)&cmd_ddp_get_list_get,
16753                 (void *)&cmd_ddp_get_list_list,
16754                 (void *)&cmd_ddp_get_list_port_id,
16755                 NULL,
16756         },
16757 };
16758
16759 /* Configure input set */
16760 struct cmd_cfg_input_set_result {
16761         cmdline_fixed_string_t port;
16762         cmdline_fixed_string_t cfg;
16763         portid_t port_id;
16764         cmdline_fixed_string_t pctype;
16765         uint8_t pctype_id;
16766         cmdline_fixed_string_t inset_type;
16767         cmdline_fixed_string_t opt;
16768         cmdline_fixed_string_t field;
16769         uint8_t field_idx;
16770 };
16771
16772 static void
16773 cmd_cfg_input_set_parsed(
16774         __attribute__((unused)) void *parsed_result,
16775         __attribute__((unused)) struct cmdline *cl,
16776         __attribute__((unused)) void *data)
16777 {
16778 #ifdef RTE_LIBRTE_I40E_PMD
16779         struct cmd_cfg_input_set_result *res = parsed_result;
16780         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16781         struct rte_pmd_i40e_inset inset;
16782 #endif
16783         int ret = -ENOTSUP;
16784
16785         if (!all_ports_stopped()) {
16786                 printf("Please stop all ports first\n");
16787                 return;
16788         }
16789
16790 #ifdef RTE_LIBRTE_I40E_PMD
16791         if (!strcmp(res->inset_type, "hash_inset"))
16792                 inset_type = INSET_HASH;
16793         else if (!strcmp(res->inset_type, "fdir_inset"))
16794                 inset_type = INSET_FDIR;
16795         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16796                 inset_type = INSET_FDIR_FLX;
16797         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16798                                      &inset, inset_type);
16799         if (ret) {
16800                 printf("Failed to get input set.\n");
16801                 return;
16802         }
16803
16804         if (!strcmp(res->opt, "get")) {
16805                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16806                                                    res->field_idx);
16807                 if (ret)
16808                         printf("Field index %d is enabled.\n", res->field_idx);
16809                 else
16810                         printf("Field index %d is disabled.\n", res->field_idx);
16811                 return;
16812         } else if (!strcmp(res->opt, "set"))
16813                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16814                                                    res->field_idx);
16815         else if (!strcmp(res->opt, "clear"))
16816                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16817                                                      res->field_idx);
16818         if (ret) {
16819                 printf("Failed to configure input set field.\n");
16820                 return;
16821         }
16822
16823         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16824                                      &inset, inset_type);
16825         if (ret) {
16826                 printf("Failed to set input set.\n");
16827                 return;
16828         }
16829 #endif
16830
16831         if (ret == -ENOTSUP)
16832                 printf("Function not supported\n");
16833 }
16834
16835 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16836         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16837                                  port, "port");
16838 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16839         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16840                                  cfg, "config");
16841 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16842         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16843                               port_id, UINT16);
16844 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16845         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16846                                  pctype, "pctype");
16847 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16848         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16849                               pctype_id, UINT8);
16850 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16851         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16852                                  inset_type,
16853                                  "hash_inset#fdir_inset#fdir_flx_inset");
16854 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16855         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16856                                  opt, "get#set#clear");
16857 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16858         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16859                                  field, "field");
16860 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16861         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16862                               field_idx, UINT8);
16863
16864 cmdline_parse_inst_t cmd_cfg_input_set = {
16865         .f = cmd_cfg_input_set_parsed,
16866         .data = NULL,
16867         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16868                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16869         .tokens = {
16870                 (void *)&cmd_cfg_input_set_port,
16871                 (void *)&cmd_cfg_input_set_cfg,
16872                 (void *)&cmd_cfg_input_set_port_id,
16873                 (void *)&cmd_cfg_input_set_pctype,
16874                 (void *)&cmd_cfg_input_set_pctype_id,
16875                 (void *)&cmd_cfg_input_set_inset_type,
16876                 (void *)&cmd_cfg_input_set_opt,
16877                 (void *)&cmd_cfg_input_set_field,
16878                 (void *)&cmd_cfg_input_set_field_idx,
16879                 NULL,
16880         },
16881 };
16882
16883 /* Clear input set */
16884 struct cmd_clear_input_set_result {
16885         cmdline_fixed_string_t port;
16886         cmdline_fixed_string_t cfg;
16887         portid_t port_id;
16888         cmdline_fixed_string_t pctype;
16889         uint8_t pctype_id;
16890         cmdline_fixed_string_t inset_type;
16891         cmdline_fixed_string_t clear;
16892         cmdline_fixed_string_t all;
16893 };
16894
16895 static void
16896 cmd_clear_input_set_parsed(
16897         __attribute__((unused)) void *parsed_result,
16898         __attribute__((unused)) struct cmdline *cl,
16899         __attribute__((unused)) void *data)
16900 {
16901 #ifdef RTE_LIBRTE_I40E_PMD
16902         struct cmd_clear_input_set_result *res = parsed_result;
16903         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16904         struct rte_pmd_i40e_inset inset;
16905 #endif
16906         int ret = -ENOTSUP;
16907
16908         if (!all_ports_stopped()) {
16909                 printf("Please stop all ports first\n");
16910                 return;
16911         }
16912
16913 #ifdef RTE_LIBRTE_I40E_PMD
16914         if (!strcmp(res->inset_type, "hash_inset"))
16915                 inset_type = INSET_HASH;
16916         else if (!strcmp(res->inset_type, "fdir_inset"))
16917                 inset_type = INSET_FDIR;
16918         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16919                 inset_type = INSET_FDIR_FLX;
16920
16921         memset(&inset, 0, sizeof(inset));
16922
16923         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16924                                      &inset, inset_type);
16925         if (ret) {
16926                 printf("Failed to clear input set.\n");
16927                 return;
16928         }
16929
16930 #endif
16931
16932         if (ret == -ENOTSUP)
16933                 printf("Function not supported\n");
16934 }
16935
16936 cmdline_parse_token_string_t cmd_clear_input_set_port =
16937         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16938                                  port, "port");
16939 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16940         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16941                                  cfg, "config");
16942 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16943         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16944                               port_id, UINT16);
16945 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16946         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16947                                  pctype, "pctype");
16948 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16949         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16950                               pctype_id, UINT8);
16951 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16952         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16953                                  inset_type,
16954                                  "hash_inset#fdir_inset#fdir_flx_inset");
16955 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16956         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16957                                  clear, "clear");
16958 cmdline_parse_token_string_t cmd_clear_input_set_all =
16959         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16960                                  all, "all");
16961
16962 cmdline_parse_inst_t cmd_clear_input_set = {
16963         .f = cmd_clear_input_set_parsed,
16964         .data = NULL,
16965         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16966                     "fdir_inset|fdir_flx_inset clear all",
16967         .tokens = {
16968                 (void *)&cmd_clear_input_set_port,
16969                 (void *)&cmd_clear_input_set_cfg,
16970                 (void *)&cmd_clear_input_set_port_id,
16971                 (void *)&cmd_clear_input_set_pctype,
16972                 (void *)&cmd_clear_input_set_pctype_id,
16973                 (void *)&cmd_clear_input_set_inset_type,
16974                 (void *)&cmd_clear_input_set_clear,
16975                 (void *)&cmd_clear_input_set_all,
16976                 NULL,
16977         },
16978 };
16979
16980 /* show vf stats */
16981
16982 /* Common result structure for show vf stats */
16983 struct cmd_show_vf_stats_result {
16984         cmdline_fixed_string_t show;
16985         cmdline_fixed_string_t vf;
16986         cmdline_fixed_string_t stats;
16987         portid_t port_id;
16988         uint16_t vf_id;
16989 };
16990
16991 /* Common CLI fields show vf stats*/
16992 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16993         TOKEN_STRING_INITIALIZER
16994                 (struct cmd_show_vf_stats_result,
16995                  show, "show");
16996 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16997         TOKEN_STRING_INITIALIZER
16998                 (struct cmd_show_vf_stats_result,
16999                  vf, "vf");
17000 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17001         TOKEN_STRING_INITIALIZER
17002                 (struct cmd_show_vf_stats_result,
17003                  stats, "stats");
17004 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17005         TOKEN_NUM_INITIALIZER
17006                 (struct cmd_show_vf_stats_result,
17007                  port_id, UINT16);
17008 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17009         TOKEN_NUM_INITIALIZER
17010                 (struct cmd_show_vf_stats_result,
17011                  vf_id, UINT16);
17012
17013 static void
17014 cmd_show_vf_stats_parsed(
17015         void *parsed_result,
17016         __attribute__((unused)) struct cmdline *cl,
17017         __attribute__((unused)) void *data)
17018 {
17019         struct cmd_show_vf_stats_result *res = parsed_result;
17020         struct rte_eth_stats stats;
17021         int ret = -ENOTSUP;
17022         static const char *nic_stats_border = "########################";
17023
17024         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17025                 return;
17026
17027         memset(&stats, 0, sizeof(stats));
17028
17029 #ifdef RTE_LIBRTE_I40E_PMD
17030         if (ret == -ENOTSUP)
17031                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17032                                                 res->vf_id,
17033                                                 &stats);
17034 #endif
17035 #ifdef RTE_LIBRTE_BNXT_PMD
17036         if (ret == -ENOTSUP)
17037                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17038                                                 res->vf_id,
17039                                                 &stats);
17040 #endif
17041
17042         switch (ret) {
17043         case 0:
17044                 break;
17045         case -EINVAL:
17046                 printf("invalid vf_id %d\n", res->vf_id);
17047                 break;
17048         case -ENODEV:
17049                 printf("invalid port_id %d\n", res->port_id);
17050                 break;
17051         case -ENOTSUP:
17052                 printf("function not implemented\n");
17053                 break;
17054         default:
17055                 printf("programming error: (%s)\n", strerror(-ret));
17056         }
17057
17058         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17059                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17060
17061         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17062                "%-"PRIu64"\n",
17063                stats.ipackets, stats.imissed, stats.ibytes);
17064         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17065         printf("  RX-nombuf:  %-10"PRIu64"\n",
17066                stats.rx_nombuf);
17067         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17068                "%-"PRIu64"\n",
17069                stats.opackets, stats.oerrors, stats.obytes);
17070
17071         printf("  %s############################%s\n",
17072                                nic_stats_border, nic_stats_border);
17073 }
17074
17075 cmdline_parse_inst_t cmd_show_vf_stats = {
17076         .f = cmd_show_vf_stats_parsed,
17077         .data = NULL,
17078         .help_str = "show vf stats <port_id> <vf_id>",
17079         .tokens = {
17080                 (void *)&cmd_show_vf_stats_show,
17081                 (void *)&cmd_show_vf_stats_vf,
17082                 (void *)&cmd_show_vf_stats_stats,
17083                 (void *)&cmd_show_vf_stats_port_id,
17084                 (void *)&cmd_show_vf_stats_vf_id,
17085                 NULL,
17086         },
17087 };
17088
17089 /* clear vf stats */
17090
17091 /* Common result structure for clear vf stats */
17092 struct cmd_clear_vf_stats_result {
17093         cmdline_fixed_string_t clear;
17094         cmdline_fixed_string_t vf;
17095         cmdline_fixed_string_t stats;
17096         portid_t port_id;
17097         uint16_t vf_id;
17098 };
17099
17100 /* Common CLI fields clear vf stats*/
17101 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17102         TOKEN_STRING_INITIALIZER
17103                 (struct cmd_clear_vf_stats_result,
17104                  clear, "clear");
17105 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17106         TOKEN_STRING_INITIALIZER
17107                 (struct cmd_clear_vf_stats_result,
17108                  vf, "vf");
17109 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17110         TOKEN_STRING_INITIALIZER
17111                 (struct cmd_clear_vf_stats_result,
17112                  stats, "stats");
17113 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17114         TOKEN_NUM_INITIALIZER
17115                 (struct cmd_clear_vf_stats_result,
17116                  port_id, UINT16);
17117 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17118         TOKEN_NUM_INITIALIZER
17119                 (struct cmd_clear_vf_stats_result,
17120                  vf_id, UINT16);
17121
17122 static void
17123 cmd_clear_vf_stats_parsed(
17124         void *parsed_result,
17125         __attribute__((unused)) struct cmdline *cl,
17126         __attribute__((unused)) void *data)
17127 {
17128         struct cmd_clear_vf_stats_result *res = parsed_result;
17129         int ret = -ENOTSUP;
17130
17131         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17132                 return;
17133
17134 #ifdef RTE_LIBRTE_I40E_PMD
17135         if (ret == -ENOTSUP)
17136                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17137                                                   res->vf_id);
17138 #endif
17139 #ifdef RTE_LIBRTE_BNXT_PMD
17140         if (ret == -ENOTSUP)
17141                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17142                                                   res->vf_id);
17143 #endif
17144
17145         switch (ret) {
17146         case 0:
17147                 break;
17148         case -EINVAL:
17149                 printf("invalid vf_id %d\n", res->vf_id);
17150                 break;
17151         case -ENODEV:
17152                 printf("invalid port_id %d\n", res->port_id);
17153                 break;
17154         case -ENOTSUP:
17155                 printf("function not implemented\n");
17156                 break;
17157         default:
17158                 printf("programming error: (%s)\n", strerror(-ret));
17159         }
17160 }
17161
17162 cmdline_parse_inst_t cmd_clear_vf_stats = {
17163         .f = cmd_clear_vf_stats_parsed,
17164         .data = NULL,
17165         .help_str = "clear vf stats <port_id> <vf_id>",
17166         .tokens = {
17167                 (void *)&cmd_clear_vf_stats_clear,
17168                 (void *)&cmd_clear_vf_stats_vf,
17169                 (void *)&cmd_clear_vf_stats_stats,
17170                 (void *)&cmd_clear_vf_stats_port_id,
17171                 (void *)&cmd_clear_vf_stats_vf_id,
17172                 NULL,
17173         },
17174 };
17175
17176 /* port config pctype mapping reset */
17177
17178 /* Common result structure for port config pctype mapping reset */
17179 struct cmd_pctype_mapping_reset_result {
17180         cmdline_fixed_string_t port;
17181         cmdline_fixed_string_t config;
17182         portid_t port_id;
17183         cmdline_fixed_string_t pctype;
17184         cmdline_fixed_string_t mapping;
17185         cmdline_fixed_string_t reset;
17186 };
17187
17188 /* Common CLI fields for port config pctype mapping reset*/
17189 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17190         TOKEN_STRING_INITIALIZER
17191                 (struct cmd_pctype_mapping_reset_result,
17192                  port, "port");
17193 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17194         TOKEN_STRING_INITIALIZER
17195                 (struct cmd_pctype_mapping_reset_result,
17196                  config, "config");
17197 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17198         TOKEN_NUM_INITIALIZER
17199                 (struct cmd_pctype_mapping_reset_result,
17200                  port_id, UINT16);
17201 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17202         TOKEN_STRING_INITIALIZER
17203                 (struct cmd_pctype_mapping_reset_result,
17204                  pctype, "pctype");
17205 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17206         TOKEN_STRING_INITIALIZER
17207                 (struct cmd_pctype_mapping_reset_result,
17208                  mapping, "mapping");
17209 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17210         TOKEN_STRING_INITIALIZER
17211                 (struct cmd_pctype_mapping_reset_result,
17212                  reset, "reset");
17213
17214 static void
17215 cmd_pctype_mapping_reset_parsed(
17216         void *parsed_result,
17217         __attribute__((unused)) struct cmdline *cl,
17218         __attribute__((unused)) void *data)
17219 {
17220         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17221         int ret = -ENOTSUP;
17222
17223         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17224                 return;
17225
17226 #ifdef RTE_LIBRTE_I40E_PMD
17227         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17228 #endif
17229
17230         switch (ret) {
17231         case 0:
17232                 break;
17233         case -ENODEV:
17234                 printf("invalid port_id %d\n", res->port_id);
17235                 break;
17236         case -ENOTSUP:
17237                 printf("function not implemented\n");
17238                 break;
17239         default:
17240                 printf("programming error: (%s)\n", strerror(-ret));
17241         }
17242 }
17243
17244 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17245         .f = cmd_pctype_mapping_reset_parsed,
17246         .data = NULL,
17247         .help_str = "port config <port_id> pctype mapping reset",
17248         .tokens = {
17249                 (void *)&cmd_pctype_mapping_reset_port,
17250                 (void *)&cmd_pctype_mapping_reset_config,
17251                 (void *)&cmd_pctype_mapping_reset_port_id,
17252                 (void *)&cmd_pctype_mapping_reset_pctype,
17253                 (void *)&cmd_pctype_mapping_reset_mapping,
17254                 (void *)&cmd_pctype_mapping_reset_reset,
17255                 NULL,
17256         },
17257 };
17258
17259 /* show port pctype mapping */
17260
17261 /* Common result structure for show port pctype mapping */
17262 struct cmd_pctype_mapping_get_result {
17263         cmdline_fixed_string_t show;
17264         cmdline_fixed_string_t port;
17265         portid_t port_id;
17266         cmdline_fixed_string_t pctype;
17267         cmdline_fixed_string_t mapping;
17268 };
17269
17270 /* Common CLI fields for pctype mapping get */
17271 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17272         TOKEN_STRING_INITIALIZER
17273                 (struct cmd_pctype_mapping_get_result,
17274                  show, "show");
17275 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17276         TOKEN_STRING_INITIALIZER
17277                 (struct cmd_pctype_mapping_get_result,
17278                  port, "port");
17279 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17280         TOKEN_NUM_INITIALIZER
17281                 (struct cmd_pctype_mapping_get_result,
17282                  port_id, UINT16);
17283 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17284         TOKEN_STRING_INITIALIZER
17285                 (struct cmd_pctype_mapping_get_result,
17286                  pctype, "pctype");
17287 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17288         TOKEN_STRING_INITIALIZER
17289                 (struct cmd_pctype_mapping_get_result,
17290                  mapping, "mapping");
17291
17292 static void
17293 cmd_pctype_mapping_get_parsed(
17294         void *parsed_result,
17295         __attribute__((unused)) struct cmdline *cl,
17296         __attribute__((unused)) void *data)
17297 {
17298         struct cmd_pctype_mapping_get_result *res = parsed_result;
17299         int ret = -ENOTSUP;
17300 #ifdef RTE_LIBRTE_I40E_PMD
17301         struct rte_pmd_i40e_flow_type_mapping
17302                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17303         int i, j, first_pctype;
17304 #endif
17305
17306         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17307                 return;
17308
17309 #ifdef RTE_LIBRTE_I40E_PMD
17310         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17311 #endif
17312
17313         switch (ret) {
17314         case 0:
17315                 break;
17316         case -ENODEV:
17317                 printf("invalid port_id %d\n", res->port_id);
17318                 return;
17319         case -ENOTSUP:
17320                 printf("function not implemented\n");
17321                 return;
17322         default:
17323                 printf("programming error: (%s)\n", strerror(-ret));
17324                 return;
17325         }
17326
17327 #ifdef RTE_LIBRTE_I40E_PMD
17328         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17329                 if (mapping[i].pctype != 0ULL) {
17330                         first_pctype = 1;
17331
17332                         printf("pctype: ");
17333                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17334                                 if (mapping[i].pctype & (1ULL << j)) {
17335                                         printf(first_pctype ?
17336                                                "%02d" : ",%02d", j);
17337                                         first_pctype = 0;
17338                                 }
17339                         }
17340                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17341                 }
17342         }
17343 #endif
17344 }
17345
17346 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17347         .f = cmd_pctype_mapping_get_parsed,
17348         .data = NULL,
17349         .help_str = "show port <port_id> pctype mapping",
17350         .tokens = {
17351                 (void *)&cmd_pctype_mapping_get_show,
17352                 (void *)&cmd_pctype_mapping_get_port,
17353                 (void *)&cmd_pctype_mapping_get_port_id,
17354                 (void *)&cmd_pctype_mapping_get_pctype,
17355                 (void *)&cmd_pctype_mapping_get_mapping,
17356                 NULL,
17357         },
17358 };
17359
17360 /* port config pctype mapping update */
17361
17362 /* Common result structure for port config pctype mapping update */
17363 struct cmd_pctype_mapping_update_result {
17364         cmdline_fixed_string_t port;
17365         cmdline_fixed_string_t config;
17366         portid_t port_id;
17367         cmdline_fixed_string_t pctype;
17368         cmdline_fixed_string_t mapping;
17369         cmdline_fixed_string_t update;
17370         cmdline_fixed_string_t pctype_list;
17371         uint16_t flow_type;
17372 };
17373
17374 /* Common CLI fields for pctype mapping update*/
17375 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17376         TOKEN_STRING_INITIALIZER
17377                 (struct cmd_pctype_mapping_update_result,
17378                  port, "port");
17379 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17380         TOKEN_STRING_INITIALIZER
17381                 (struct cmd_pctype_mapping_update_result,
17382                  config, "config");
17383 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17384         TOKEN_NUM_INITIALIZER
17385                 (struct cmd_pctype_mapping_update_result,
17386                  port_id, UINT16);
17387 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17388         TOKEN_STRING_INITIALIZER
17389                 (struct cmd_pctype_mapping_update_result,
17390                  pctype, "pctype");
17391 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17392         TOKEN_STRING_INITIALIZER
17393                 (struct cmd_pctype_mapping_update_result,
17394                  mapping, "mapping");
17395 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17396         TOKEN_STRING_INITIALIZER
17397                 (struct cmd_pctype_mapping_update_result,
17398                  update, "update");
17399 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17400         TOKEN_STRING_INITIALIZER
17401                 (struct cmd_pctype_mapping_update_result,
17402                  pctype_list, NULL);
17403 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17404         TOKEN_NUM_INITIALIZER
17405                 (struct cmd_pctype_mapping_update_result,
17406                  flow_type, UINT16);
17407
17408 static void
17409 cmd_pctype_mapping_update_parsed(
17410         void *parsed_result,
17411         __attribute__((unused)) struct cmdline *cl,
17412         __attribute__((unused)) void *data)
17413 {
17414         struct cmd_pctype_mapping_update_result *res = parsed_result;
17415         int ret = -ENOTSUP;
17416 #ifdef RTE_LIBRTE_I40E_PMD
17417         struct rte_pmd_i40e_flow_type_mapping mapping;
17418         unsigned int i;
17419         unsigned int nb_item;
17420         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17421 #endif
17422
17423         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17424                 return;
17425
17426 #ifdef RTE_LIBRTE_I40E_PMD
17427         nb_item = parse_item_list(res->pctype_list, "pctypes",
17428                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17429         mapping.flow_type = res->flow_type;
17430         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17431                 mapping.pctype |= (1ULL << pctype_list[i]);
17432         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17433                                                 &mapping,
17434                                                 1,
17435                                                 0);
17436 #endif
17437
17438         switch (ret) {
17439         case 0:
17440                 break;
17441         case -EINVAL:
17442                 printf("invalid pctype or flow type\n");
17443                 break;
17444         case -ENODEV:
17445                 printf("invalid port_id %d\n", res->port_id);
17446                 break;
17447         case -ENOTSUP:
17448                 printf("function not implemented\n");
17449                 break;
17450         default:
17451                 printf("programming error: (%s)\n", strerror(-ret));
17452         }
17453 }
17454
17455 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17456         .f = cmd_pctype_mapping_update_parsed,
17457         .data = NULL,
17458         .help_str = "port config <port_id> pctype mapping update"
17459         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17460         .tokens = {
17461                 (void *)&cmd_pctype_mapping_update_port,
17462                 (void *)&cmd_pctype_mapping_update_config,
17463                 (void *)&cmd_pctype_mapping_update_port_id,
17464                 (void *)&cmd_pctype_mapping_update_pctype,
17465                 (void *)&cmd_pctype_mapping_update_mapping,
17466                 (void *)&cmd_pctype_mapping_update_update,
17467                 (void *)&cmd_pctype_mapping_update_pc_type,
17468                 (void *)&cmd_pctype_mapping_update_flow_type,
17469                 NULL,
17470         },
17471 };
17472
17473 /* ptype mapping get */
17474
17475 /* Common result structure for ptype mapping get */
17476 struct cmd_ptype_mapping_get_result {
17477         cmdline_fixed_string_t ptype;
17478         cmdline_fixed_string_t mapping;
17479         cmdline_fixed_string_t get;
17480         portid_t port_id;
17481         uint8_t valid_only;
17482 };
17483
17484 /* Common CLI fields for ptype mapping get */
17485 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17486         TOKEN_STRING_INITIALIZER
17487                 (struct cmd_ptype_mapping_get_result,
17488                  ptype, "ptype");
17489 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17490         TOKEN_STRING_INITIALIZER
17491                 (struct cmd_ptype_mapping_get_result,
17492                  mapping, "mapping");
17493 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17494         TOKEN_STRING_INITIALIZER
17495                 (struct cmd_ptype_mapping_get_result,
17496                  get, "get");
17497 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17498         TOKEN_NUM_INITIALIZER
17499                 (struct cmd_ptype_mapping_get_result,
17500                  port_id, UINT16);
17501 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17502         TOKEN_NUM_INITIALIZER
17503                 (struct cmd_ptype_mapping_get_result,
17504                  valid_only, UINT8);
17505
17506 static void
17507 cmd_ptype_mapping_get_parsed(
17508         void *parsed_result,
17509         __attribute__((unused)) struct cmdline *cl,
17510         __attribute__((unused)) void *data)
17511 {
17512         struct cmd_ptype_mapping_get_result *res = parsed_result;
17513         int ret = -ENOTSUP;
17514 #ifdef RTE_LIBRTE_I40E_PMD
17515         int max_ptype_num = 256;
17516         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17517         uint16_t count;
17518         int i;
17519 #endif
17520
17521         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17522                 return;
17523
17524 #ifdef RTE_LIBRTE_I40E_PMD
17525         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17526                                         mapping,
17527                                         max_ptype_num,
17528                                         &count,
17529                                         res->valid_only);
17530 #endif
17531
17532         switch (ret) {
17533         case 0:
17534                 break;
17535         case -ENODEV:
17536                 printf("invalid port_id %d\n", res->port_id);
17537                 break;
17538         case -ENOTSUP:
17539                 printf("function not implemented\n");
17540                 break;
17541         default:
17542                 printf("programming error: (%s)\n", strerror(-ret));
17543         }
17544
17545 #ifdef RTE_LIBRTE_I40E_PMD
17546         if (!ret) {
17547                 for (i = 0; i < count; i++)
17548                         printf("%3d\t0x%08x\n",
17549                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17550         }
17551 #endif
17552 }
17553
17554 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17555         .f = cmd_ptype_mapping_get_parsed,
17556         .data = NULL,
17557         .help_str = "ptype mapping get <port_id> <valid_only>",
17558         .tokens = {
17559                 (void *)&cmd_ptype_mapping_get_ptype,
17560                 (void *)&cmd_ptype_mapping_get_mapping,
17561                 (void *)&cmd_ptype_mapping_get_get,
17562                 (void *)&cmd_ptype_mapping_get_port_id,
17563                 (void *)&cmd_ptype_mapping_get_valid_only,
17564                 NULL,
17565         },
17566 };
17567
17568 /* ptype mapping replace */
17569
17570 /* Common result structure for ptype mapping replace */
17571 struct cmd_ptype_mapping_replace_result {
17572         cmdline_fixed_string_t ptype;
17573         cmdline_fixed_string_t mapping;
17574         cmdline_fixed_string_t replace;
17575         portid_t port_id;
17576         uint32_t target;
17577         uint8_t mask;
17578         uint32_t pkt_type;
17579 };
17580
17581 /* Common CLI fields for ptype mapping replace */
17582 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17583         TOKEN_STRING_INITIALIZER
17584                 (struct cmd_ptype_mapping_replace_result,
17585                  ptype, "ptype");
17586 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17587         TOKEN_STRING_INITIALIZER
17588                 (struct cmd_ptype_mapping_replace_result,
17589                  mapping, "mapping");
17590 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17591         TOKEN_STRING_INITIALIZER
17592                 (struct cmd_ptype_mapping_replace_result,
17593                  replace, "replace");
17594 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17595         TOKEN_NUM_INITIALIZER
17596                 (struct cmd_ptype_mapping_replace_result,
17597                  port_id, UINT16);
17598 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17599         TOKEN_NUM_INITIALIZER
17600                 (struct cmd_ptype_mapping_replace_result,
17601                  target, UINT32);
17602 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17603         TOKEN_NUM_INITIALIZER
17604                 (struct cmd_ptype_mapping_replace_result,
17605                  mask, UINT8);
17606 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17607         TOKEN_NUM_INITIALIZER
17608                 (struct cmd_ptype_mapping_replace_result,
17609                  pkt_type, UINT32);
17610
17611 static void
17612 cmd_ptype_mapping_replace_parsed(
17613         void *parsed_result,
17614         __attribute__((unused)) struct cmdline *cl,
17615         __attribute__((unused)) void *data)
17616 {
17617         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17618         int ret = -ENOTSUP;
17619
17620         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17621                 return;
17622
17623 #ifdef RTE_LIBRTE_I40E_PMD
17624         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17625                                         res->target,
17626                                         res->mask,
17627                                         res->pkt_type);
17628 #endif
17629
17630         switch (ret) {
17631         case 0:
17632                 break;
17633         case -EINVAL:
17634                 printf("invalid ptype 0x%8x or 0x%8x\n",
17635                                 res->target, res->pkt_type);
17636                 break;
17637         case -ENODEV:
17638                 printf("invalid port_id %d\n", res->port_id);
17639                 break;
17640         case -ENOTSUP:
17641                 printf("function not implemented\n");
17642                 break;
17643         default:
17644                 printf("programming error: (%s)\n", strerror(-ret));
17645         }
17646 }
17647
17648 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17649         .f = cmd_ptype_mapping_replace_parsed,
17650         .data = NULL,
17651         .help_str =
17652                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17653         .tokens = {
17654                 (void *)&cmd_ptype_mapping_replace_ptype,
17655                 (void *)&cmd_ptype_mapping_replace_mapping,
17656                 (void *)&cmd_ptype_mapping_replace_replace,
17657                 (void *)&cmd_ptype_mapping_replace_port_id,
17658                 (void *)&cmd_ptype_mapping_replace_target,
17659                 (void *)&cmd_ptype_mapping_replace_mask,
17660                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17661                 NULL,
17662         },
17663 };
17664
17665 /* ptype mapping reset */
17666
17667 /* Common result structure for ptype mapping reset */
17668 struct cmd_ptype_mapping_reset_result {
17669         cmdline_fixed_string_t ptype;
17670         cmdline_fixed_string_t mapping;
17671         cmdline_fixed_string_t reset;
17672         portid_t port_id;
17673 };
17674
17675 /* Common CLI fields for ptype mapping reset*/
17676 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17677         TOKEN_STRING_INITIALIZER
17678                 (struct cmd_ptype_mapping_reset_result,
17679                  ptype, "ptype");
17680 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17681         TOKEN_STRING_INITIALIZER
17682                 (struct cmd_ptype_mapping_reset_result,
17683                  mapping, "mapping");
17684 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17685         TOKEN_STRING_INITIALIZER
17686                 (struct cmd_ptype_mapping_reset_result,
17687                  reset, "reset");
17688 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17689         TOKEN_NUM_INITIALIZER
17690                 (struct cmd_ptype_mapping_reset_result,
17691                  port_id, UINT16);
17692
17693 static void
17694 cmd_ptype_mapping_reset_parsed(
17695         void *parsed_result,
17696         __attribute__((unused)) struct cmdline *cl,
17697         __attribute__((unused)) void *data)
17698 {
17699         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17700         int ret = -ENOTSUP;
17701
17702         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17703                 return;
17704
17705 #ifdef RTE_LIBRTE_I40E_PMD
17706         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17707 #endif
17708
17709         switch (ret) {
17710         case 0:
17711                 break;
17712         case -ENODEV:
17713                 printf("invalid port_id %d\n", res->port_id);
17714                 break;
17715         case -ENOTSUP:
17716                 printf("function not implemented\n");
17717                 break;
17718         default:
17719                 printf("programming error: (%s)\n", strerror(-ret));
17720         }
17721 }
17722
17723 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17724         .f = cmd_ptype_mapping_reset_parsed,
17725         .data = NULL,
17726         .help_str = "ptype mapping reset <port_id>",
17727         .tokens = {
17728                 (void *)&cmd_ptype_mapping_reset_ptype,
17729                 (void *)&cmd_ptype_mapping_reset_mapping,
17730                 (void *)&cmd_ptype_mapping_reset_reset,
17731                 (void *)&cmd_ptype_mapping_reset_port_id,
17732                 NULL,
17733         },
17734 };
17735
17736 /* ptype mapping update */
17737
17738 /* Common result structure for ptype mapping update */
17739 struct cmd_ptype_mapping_update_result {
17740         cmdline_fixed_string_t ptype;
17741         cmdline_fixed_string_t mapping;
17742         cmdline_fixed_string_t reset;
17743         portid_t port_id;
17744         uint8_t hw_ptype;
17745         uint32_t sw_ptype;
17746 };
17747
17748 /* Common CLI fields for ptype mapping update*/
17749 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17750         TOKEN_STRING_INITIALIZER
17751                 (struct cmd_ptype_mapping_update_result,
17752                  ptype, "ptype");
17753 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17754         TOKEN_STRING_INITIALIZER
17755                 (struct cmd_ptype_mapping_update_result,
17756                  mapping, "mapping");
17757 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17758         TOKEN_STRING_INITIALIZER
17759                 (struct cmd_ptype_mapping_update_result,
17760                  reset, "update");
17761 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17762         TOKEN_NUM_INITIALIZER
17763                 (struct cmd_ptype_mapping_update_result,
17764                  port_id, UINT16);
17765 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17766         TOKEN_NUM_INITIALIZER
17767                 (struct cmd_ptype_mapping_update_result,
17768                  hw_ptype, UINT8);
17769 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17770         TOKEN_NUM_INITIALIZER
17771                 (struct cmd_ptype_mapping_update_result,
17772                  sw_ptype, UINT32);
17773
17774 static void
17775 cmd_ptype_mapping_update_parsed(
17776         void *parsed_result,
17777         __attribute__((unused)) struct cmdline *cl,
17778         __attribute__((unused)) void *data)
17779 {
17780         struct cmd_ptype_mapping_update_result *res = parsed_result;
17781         int ret = -ENOTSUP;
17782 #ifdef RTE_LIBRTE_I40E_PMD
17783         struct rte_pmd_i40e_ptype_mapping mapping;
17784 #endif
17785         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17786                 return;
17787
17788 #ifdef RTE_LIBRTE_I40E_PMD
17789         mapping.hw_ptype = res->hw_ptype;
17790         mapping.sw_ptype = res->sw_ptype;
17791         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17792                                                 &mapping,
17793                                                 1,
17794                                                 0);
17795 #endif
17796
17797         switch (ret) {
17798         case 0:
17799                 break;
17800         case -EINVAL:
17801                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17802                 break;
17803         case -ENODEV:
17804                 printf("invalid port_id %d\n", res->port_id);
17805                 break;
17806         case -ENOTSUP:
17807                 printf("function not implemented\n");
17808                 break;
17809         default:
17810                 printf("programming error: (%s)\n", strerror(-ret));
17811         }
17812 }
17813
17814 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17815         .f = cmd_ptype_mapping_update_parsed,
17816         .data = NULL,
17817         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17818         .tokens = {
17819                 (void *)&cmd_ptype_mapping_update_ptype,
17820                 (void *)&cmd_ptype_mapping_update_mapping,
17821                 (void *)&cmd_ptype_mapping_update_update,
17822                 (void *)&cmd_ptype_mapping_update_port_id,
17823                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17824                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17825                 NULL,
17826         },
17827 };
17828
17829 /* Common result structure for file commands */
17830 struct cmd_cmdfile_result {
17831         cmdline_fixed_string_t load;
17832         cmdline_fixed_string_t filename;
17833 };
17834
17835 /* Common CLI fields for file commands */
17836 cmdline_parse_token_string_t cmd_load_cmdfile =
17837         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17838 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17839         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17840
17841 static void
17842 cmd_load_from_file_parsed(
17843         void *parsed_result,
17844         __attribute__((unused)) struct cmdline *cl,
17845         __attribute__((unused)) void *data)
17846 {
17847         struct cmd_cmdfile_result *res = parsed_result;
17848
17849         cmdline_read_from_file(res->filename);
17850 }
17851
17852 cmdline_parse_inst_t cmd_load_from_file = {
17853         .f = cmd_load_from_file_parsed,
17854         .data = NULL,
17855         .help_str = "load <filename>",
17856         .tokens = {
17857                 (void *)&cmd_load_cmdfile,
17858                 (void *)&cmd_load_cmdfile_filename,
17859                 NULL,
17860         },
17861 };
17862
17863 /* Get Rx offloads capabilities */
17864 struct cmd_rx_offload_get_capa_result {
17865         cmdline_fixed_string_t show;
17866         cmdline_fixed_string_t port;
17867         portid_t port_id;
17868         cmdline_fixed_string_t rx_offload;
17869         cmdline_fixed_string_t capabilities;
17870 };
17871
17872 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17873         TOKEN_STRING_INITIALIZER
17874                 (struct cmd_rx_offload_get_capa_result,
17875                  show, "show");
17876 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17877         TOKEN_STRING_INITIALIZER
17878                 (struct cmd_rx_offload_get_capa_result,
17879                  port, "port");
17880 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17881         TOKEN_NUM_INITIALIZER
17882                 (struct cmd_rx_offload_get_capa_result,
17883                  port_id, UINT16);
17884 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17885         TOKEN_STRING_INITIALIZER
17886                 (struct cmd_rx_offload_get_capa_result,
17887                  rx_offload, "rx_offload");
17888 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17889         TOKEN_STRING_INITIALIZER
17890                 (struct cmd_rx_offload_get_capa_result,
17891                  capabilities, "capabilities");
17892
17893 static void
17894 print_rx_offloads(uint64_t offloads)
17895 {
17896         uint64_t single_offload;
17897         int begin;
17898         int end;
17899         int bit;
17900
17901         if (offloads == 0)
17902                 return;
17903
17904         begin = __builtin_ctzll(offloads);
17905         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17906
17907         single_offload = 1ULL << begin;
17908         for (bit = begin; bit < end; bit++) {
17909                 if (offloads & single_offload)
17910                         printf(" %s",
17911                                rte_eth_dev_rx_offload_name(single_offload));
17912                 single_offload <<= 1;
17913         }
17914 }
17915
17916 static void
17917 cmd_rx_offload_get_capa_parsed(
17918         void *parsed_result,
17919         __attribute__((unused)) struct cmdline *cl,
17920         __attribute__((unused)) void *data)
17921 {
17922         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17923         struct rte_eth_dev_info dev_info;
17924         portid_t port_id = res->port_id;
17925         uint64_t queue_offloads;
17926         uint64_t port_offloads;
17927         int ret;
17928
17929         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17930         if (ret != 0)
17931                 return;
17932
17933         queue_offloads = dev_info.rx_queue_offload_capa;
17934         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17935
17936         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17937         printf("  Per Queue :");
17938         print_rx_offloads(queue_offloads);
17939
17940         printf("\n");
17941         printf("  Per Port  :");
17942         print_rx_offloads(port_offloads);
17943         printf("\n\n");
17944 }
17945
17946 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17947         .f = cmd_rx_offload_get_capa_parsed,
17948         .data = NULL,
17949         .help_str = "show port <port_id> rx_offload capabilities",
17950         .tokens = {
17951                 (void *)&cmd_rx_offload_get_capa_show,
17952                 (void *)&cmd_rx_offload_get_capa_port,
17953                 (void *)&cmd_rx_offload_get_capa_port_id,
17954                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17955                 (void *)&cmd_rx_offload_get_capa_capabilities,
17956                 NULL,
17957         }
17958 };
17959
17960 /* Get Rx offloads configuration */
17961 struct cmd_rx_offload_get_configuration_result {
17962         cmdline_fixed_string_t show;
17963         cmdline_fixed_string_t port;
17964         portid_t port_id;
17965         cmdline_fixed_string_t rx_offload;
17966         cmdline_fixed_string_t configuration;
17967 };
17968
17969 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17970         TOKEN_STRING_INITIALIZER
17971                 (struct cmd_rx_offload_get_configuration_result,
17972                  show, "show");
17973 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17974         TOKEN_STRING_INITIALIZER
17975                 (struct cmd_rx_offload_get_configuration_result,
17976                  port, "port");
17977 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17978         TOKEN_NUM_INITIALIZER
17979                 (struct cmd_rx_offload_get_configuration_result,
17980                  port_id, UINT16);
17981 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17982         TOKEN_STRING_INITIALIZER
17983                 (struct cmd_rx_offload_get_configuration_result,
17984                  rx_offload, "rx_offload");
17985 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17986         TOKEN_STRING_INITIALIZER
17987                 (struct cmd_rx_offload_get_configuration_result,
17988                  configuration, "configuration");
17989
17990 static void
17991 cmd_rx_offload_get_configuration_parsed(
17992         void *parsed_result,
17993         __attribute__((unused)) struct cmdline *cl,
17994         __attribute__((unused)) void *data)
17995 {
17996         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17997         struct rte_eth_dev_info dev_info;
17998         portid_t port_id = res->port_id;
17999         struct rte_port *port = &ports[port_id];
18000         uint64_t port_offloads;
18001         uint64_t queue_offloads;
18002         uint16_t nb_rx_queues;
18003         int q;
18004         int ret;
18005
18006         printf("Rx Offloading Configuration of port %d :\n", port_id);
18007
18008         port_offloads = port->dev_conf.rxmode.offloads;
18009         printf("  Port :");
18010         print_rx_offloads(port_offloads);
18011         printf("\n");
18012
18013         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18014         if (ret != 0)
18015                 return;
18016
18017         nb_rx_queues = dev_info.nb_rx_queues;
18018         for (q = 0; q < nb_rx_queues; q++) {
18019                 queue_offloads = port->rx_conf[q].offloads;
18020                 printf("  Queue[%2d] :", q);
18021                 print_rx_offloads(queue_offloads);
18022                 printf("\n");
18023         }
18024         printf("\n");
18025 }
18026
18027 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18028         .f = cmd_rx_offload_get_configuration_parsed,
18029         .data = NULL,
18030         .help_str = "show port <port_id> rx_offload configuration",
18031         .tokens = {
18032                 (void *)&cmd_rx_offload_get_configuration_show,
18033                 (void *)&cmd_rx_offload_get_configuration_port,
18034                 (void *)&cmd_rx_offload_get_configuration_port_id,
18035                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18036                 (void *)&cmd_rx_offload_get_configuration_configuration,
18037                 NULL,
18038         }
18039 };
18040
18041 /* Enable/Disable a per port offloading */
18042 struct cmd_config_per_port_rx_offload_result {
18043         cmdline_fixed_string_t port;
18044         cmdline_fixed_string_t config;
18045         portid_t port_id;
18046         cmdline_fixed_string_t rx_offload;
18047         cmdline_fixed_string_t offload;
18048         cmdline_fixed_string_t on_off;
18049 };
18050
18051 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18052         TOKEN_STRING_INITIALIZER
18053                 (struct cmd_config_per_port_rx_offload_result,
18054                  port, "port");
18055 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18056         TOKEN_STRING_INITIALIZER
18057                 (struct cmd_config_per_port_rx_offload_result,
18058                  config, "config");
18059 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18060         TOKEN_NUM_INITIALIZER
18061                 (struct cmd_config_per_port_rx_offload_result,
18062                  port_id, UINT16);
18063 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18064         TOKEN_STRING_INITIALIZER
18065                 (struct cmd_config_per_port_rx_offload_result,
18066                  rx_offload, "rx_offload");
18067 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18068         TOKEN_STRING_INITIALIZER
18069                 (struct cmd_config_per_port_rx_offload_result,
18070                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18071                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18072                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18073                            "crc_strip#scatter#timestamp#security#keep_crc");
18074 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18075         TOKEN_STRING_INITIALIZER
18076                 (struct cmd_config_per_port_rx_offload_result,
18077                  on_off, "on#off");
18078
18079 static uint64_t
18080 search_rx_offload(const char *name)
18081 {
18082         uint64_t single_offload;
18083         const char *single_name;
18084         int found = 0;
18085         unsigned int bit;
18086
18087         single_offload = 1;
18088         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18089                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18090                 if (!strcasecmp(single_name, name)) {
18091                         found = 1;
18092                         break;
18093                 }
18094                 single_offload <<= 1;
18095         }
18096
18097         if (found)
18098                 return single_offload;
18099
18100         return 0;
18101 }
18102
18103 static void
18104 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18105                                 __attribute__((unused)) struct cmdline *cl,
18106                                 __attribute__((unused)) void *data)
18107 {
18108         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18109         portid_t port_id = res->port_id;
18110         struct rte_eth_dev_info dev_info;
18111         struct rte_port *port = &ports[port_id];
18112         uint64_t single_offload;
18113         uint16_t nb_rx_queues;
18114         int q;
18115         int ret;
18116
18117         if (port->port_status != RTE_PORT_STOPPED) {
18118                 printf("Error: Can't config offload when Port %d "
18119                        "is not stopped\n", port_id);
18120                 return;
18121         }
18122
18123         single_offload = search_rx_offload(res->offload);
18124         if (single_offload == 0) {
18125                 printf("Unknown offload name: %s\n", res->offload);
18126                 return;
18127         }
18128
18129         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18130         if (ret != 0)
18131                 return;
18132
18133         nb_rx_queues = dev_info.nb_rx_queues;
18134         if (!strcmp(res->on_off, "on")) {
18135                 port->dev_conf.rxmode.offloads |= single_offload;
18136                 for (q = 0; q < nb_rx_queues; q++)
18137                         port->rx_conf[q].offloads |= single_offload;
18138         } else {
18139                 port->dev_conf.rxmode.offloads &= ~single_offload;
18140                 for (q = 0; q < nb_rx_queues; q++)
18141                         port->rx_conf[q].offloads &= ~single_offload;
18142         }
18143
18144         cmd_reconfig_device_queue(port_id, 1, 1);
18145 }
18146
18147 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18148         .f = cmd_config_per_port_rx_offload_parsed,
18149         .data = NULL,
18150         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18151                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18152                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18153                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18154                     "on|off",
18155         .tokens = {
18156                 (void *)&cmd_config_per_port_rx_offload_result_port,
18157                 (void *)&cmd_config_per_port_rx_offload_result_config,
18158                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18159                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18160                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18161                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18162                 NULL,
18163         }
18164 };
18165
18166 /* Enable/Disable a per queue offloading */
18167 struct cmd_config_per_queue_rx_offload_result {
18168         cmdline_fixed_string_t port;
18169         portid_t port_id;
18170         cmdline_fixed_string_t rxq;
18171         uint16_t queue_id;
18172         cmdline_fixed_string_t rx_offload;
18173         cmdline_fixed_string_t offload;
18174         cmdline_fixed_string_t on_off;
18175 };
18176
18177 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18178         TOKEN_STRING_INITIALIZER
18179                 (struct cmd_config_per_queue_rx_offload_result,
18180                  port, "port");
18181 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18182         TOKEN_NUM_INITIALIZER
18183                 (struct cmd_config_per_queue_rx_offload_result,
18184                  port_id, UINT16);
18185 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18186         TOKEN_STRING_INITIALIZER
18187                 (struct cmd_config_per_queue_rx_offload_result,
18188                  rxq, "rxq");
18189 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18190         TOKEN_NUM_INITIALIZER
18191                 (struct cmd_config_per_queue_rx_offload_result,
18192                  queue_id, UINT16);
18193 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18194         TOKEN_STRING_INITIALIZER
18195                 (struct cmd_config_per_queue_rx_offload_result,
18196                  rx_offload, "rx_offload");
18197 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18198         TOKEN_STRING_INITIALIZER
18199                 (struct cmd_config_per_queue_rx_offload_result,
18200                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18201                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18202                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18203                            "crc_strip#scatter#timestamp#security#keep_crc");
18204 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18205         TOKEN_STRING_INITIALIZER
18206                 (struct cmd_config_per_queue_rx_offload_result,
18207                  on_off, "on#off");
18208
18209 static void
18210 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18211                                 __attribute__((unused)) struct cmdline *cl,
18212                                 __attribute__((unused)) void *data)
18213 {
18214         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18215         struct rte_eth_dev_info dev_info;
18216         portid_t port_id = res->port_id;
18217         uint16_t queue_id = res->queue_id;
18218         struct rte_port *port = &ports[port_id];
18219         uint64_t single_offload;
18220         int ret;
18221
18222         if (port->port_status != RTE_PORT_STOPPED) {
18223                 printf("Error: Can't config offload when Port %d "
18224                        "is not stopped\n", port_id);
18225                 return;
18226         }
18227
18228         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18229         if (ret != 0)
18230                 return;
18231
18232         if (queue_id >= dev_info.nb_rx_queues) {
18233                 printf("Error: input queue_id should be 0 ... "
18234                        "%d\n", dev_info.nb_rx_queues - 1);
18235                 return;
18236         }
18237
18238         single_offload = search_rx_offload(res->offload);
18239         if (single_offload == 0) {
18240                 printf("Unknown offload name: %s\n", res->offload);
18241                 return;
18242         }
18243
18244         if (!strcmp(res->on_off, "on"))
18245                 port->rx_conf[queue_id].offloads |= single_offload;
18246         else
18247                 port->rx_conf[queue_id].offloads &= ~single_offload;
18248
18249         cmd_reconfig_device_queue(port_id, 1, 1);
18250 }
18251
18252 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18253         .f = cmd_config_per_queue_rx_offload_parsed,
18254         .data = NULL,
18255         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18256                     "vlan_strip|ipv4_cksum|"
18257                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18258                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18259                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18260                     "on|off",
18261         .tokens = {
18262                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18263                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18264                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18265                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18266                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18267                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18268                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18269                 NULL,
18270         }
18271 };
18272
18273 /* Get Tx offloads capabilities */
18274 struct cmd_tx_offload_get_capa_result {
18275         cmdline_fixed_string_t show;
18276         cmdline_fixed_string_t port;
18277         portid_t port_id;
18278         cmdline_fixed_string_t tx_offload;
18279         cmdline_fixed_string_t capabilities;
18280 };
18281
18282 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18283         TOKEN_STRING_INITIALIZER
18284                 (struct cmd_tx_offload_get_capa_result,
18285                  show, "show");
18286 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18287         TOKEN_STRING_INITIALIZER
18288                 (struct cmd_tx_offload_get_capa_result,
18289                  port, "port");
18290 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18291         TOKEN_NUM_INITIALIZER
18292                 (struct cmd_tx_offload_get_capa_result,
18293                  port_id, UINT16);
18294 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18295         TOKEN_STRING_INITIALIZER
18296                 (struct cmd_tx_offload_get_capa_result,
18297                  tx_offload, "tx_offload");
18298 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18299         TOKEN_STRING_INITIALIZER
18300                 (struct cmd_tx_offload_get_capa_result,
18301                  capabilities, "capabilities");
18302
18303 static void
18304 print_tx_offloads(uint64_t offloads)
18305 {
18306         uint64_t single_offload;
18307         int begin;
18308         int end;
18309         int bit;
18310
18311         if (offloads == 0)
18312                 return;
18313
18314         begin = __builtin_ctzll(offloads);
18315         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18316
18317         single_offload = 1ULL << begin;
18318         for (bit = begin; bit < end; bit++) {
18319                 if (offloads & single_offload)
18320                         printf(" %s",
18321                                rte_eth_dev_tx_offload_name(single_offload));
18322                 single_offload <<= 1;
18323         }
18324 }
18325
18326 static void
18327 cmd_tx_offload_get_capa_parsed(
18328         void *parsed_result,
18329         __attribute__((unused)) struct cmdline *cl,
18330         __attribute__((unused)) void *data)
18331 {
18332         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18333         struct rte_eth_dev_info dev_info;
18334         portid_t port_id = res->port_id;
18335         uint64_t queue_offloads;
18336         uint64_t port_offloads;
18337         int ret;
18338
18339         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18340         if (ret != 0)
18341                 return;
18342
18343         queue_offloads = dev_info.tx_queue_offload_capa;
18344         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18345
18346         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18347         printf("  Per Queue :");
18348         print_tx_offloads(queue_offloads);
18349
18350         printf("\n");
18351         printf("  Per Port  :");
18352         print_tx_offloads(port_offloads);
18353         printf("\n\n");
18354 }
18355
18356 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18357         .f = cmd_tx_offload_get_capa_parsed,
18358         .data = NULL,
18359         .help_str = "show port <port_id> tx_offload capabilities",
18360         .tokens = {
18361                 (void *)&cmd_tx_offload_get_capa_show,
18362                 (void *)&cmd_tx_offload_get_capa_port,
18363                 (void *)&cmd_tx_offload_get_capa_port_id,
18364                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18365                 (void *)&cmd_tx_offload_get_capa_capabilities,
18366                 NULL,
18367         }
18368 };
18369
18370 /* Get Tx offloads configuration */
18371 struct cmd_tx_offload_get_configuration_result {
18372         cmdline_fixed_string_t show;
18373         cmdline_fixed_string_t port;
18374         portid_t port_id;
18375         cmdline_fixed_string_t tx_offload;
18376         cmdline_fixed_string_t configuration;
18377 };
18378
18379 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18380         TOKEN_STRING_INITIALIZER
18381                 (struct cmd_tx_offload_get_configuration_result,
18382                  show, "show");
18383 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18384         TOKEN_STRING_INITIALIZER
18385                 (struct cmd_tx_offload_get_configuration_result,
18386                  port, "port");
18387 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18388         TOKEN_NUM_INITIALIZER
18389                 (struct cmd_tx_offload_get_configuration_result,
18390                  port_id, UINT16);
18391 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18392         TOKEN_STRING_INITIALIZER
18393                 (struct cmd_tx_offload_get_configuration_result,
18394                  tx_offload, "tx_offload");
18395 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18396         TOKEN_STRING_INITIALIZER
18397                 (struct cmd_tx_offload_get_configuration_result,
18398                  configuration, "configuration");
18399
18400 static void
18401 cmd_tx_offload_get_configuration_parsed(
18402         void *parsed_result,
18403         __attribute__((unused)) struct cmdline *cl,
18404         __attribute__((unused)) void *data)
18405 {
18406         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18407         struct rte_eth_dev_info dev_info;
18408         portid_t port_id = res->port_id;
18409         struct rte_port *port = &ports[port_id];
18410         uint64_t port_offloads;
18411         uint64_t queue_offloads;
18412         uint16_t nb_tx_queues;
18413         int q;
18414         int ret;
18415
18416         printf("Tx Offloading Configuration of port %d :\n", port_id);
18417
18418         port_offloads = port->dev_conf.txmode.offloads;
18419         printf("  Port :");
18420         print_tx_offloads(port_offloads);
18421         printf("\n");
18422
18423         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18424         if (ret != 0)
18425                 return;
18426
18427         nb_tx_queues = dev_info.nb_tx_queues;
18428         for (q = 0; q < nb_tx_queues; q++) {
18429                 queue_offloads = port->tx_conf[q].offloads;
18430                 printf("  Queue[%2d] :", q);
18431                 print_tx_offloads(queue_offloads);
18432                 printf("\n");
18433         }
18434         printf("\n");
18435 }
18436
18437 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18438         .f = cmd_tx_offload_get_configuration_parsed,
18439         .data = NULL,
18440         .help_str = "show port <port_id> tx_offload configuration",
18441         .tokens = {
18442                 (void *)&cmd_tx_offload_get_configuration_show,
18443                 (void *)&cmd_tx_offload_get_configuration_port,
18444                 (void *)&cmd_tx_offload_get_configuration_port_id,
18445                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18446                 (void *)&cmd_tx_offload_get_configuration_configuration,
18447                 NULL,
18448         }
18449 };
18450
18451 /* Enable/Disable a per port offloading */
18452 struct cmd_config_per_port_tx_offload_result {
18453         cmdline_fixed_string_t port;
18454         cmdline_fixed_string_t config;
18455         portid_t port_id;
18456         cmdline_fixed_string_t tx_offload;
18457         cmdline_fixed_string_t offload;
18458         cmdline_fixed_string_t on_off;
18459 };
18460
18461 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18462         TOKEN_STRING_INITIALIZER
18463                 (struct cmd_config_per_port_tx_offload_result,
18464                  port, "port");
18465 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18466         TOKEN_STRING_INITIALIZER
18467                 (struct cmd_config_per_port_tx_offload_result,
18468                  config, "config");
18469 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18470         TOKEN_NUM_INITIALIZER
18471                 (struct cmd_config_per_port_tx_offload_result,
18472                  port_id, UINT16);
18473 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18474         TOKEN_STRING_INITIALIZER
18475                 (struct cmd_config_per_port_tx_offload_result,
18476                  tx_offload, "tx_offload");
18477 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18478         TOKEN_STRING_INITIALIZER
18479                 (struct cmd_config_per_port_tx_offload_result,
18480                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18481                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18482                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18483                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18484                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18485                           "match_metadata");
18486 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18487         TOKEN_STRING_INITIALIZER
18488                 (struct cmd_config_per_port_tx_offload_result,
18489                  on_off, "on#off");
18490
18491 static uint64_t
18492 search_tx_offload(const char *name)
18493 {
18494         uint64_t single_offload;
18495         const char *single_name;
18496         int found = 0;
18497         unsigned int bit;
18498
18499         single_offload = 1;
18500         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18501                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18502                 if (single_name == NULL)
18503                         break;
18504                 if (!strcasecmp(single_name, name)) {
18505                         found = 1;
18506                         break;
18507                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18508                         break;
18509                 single_offload <<= 1;
18510         }
18511
18512         if (found)
18513                 return single_offload;
18514
18515         return 0;
18516 }
18517
18518 static void
18519 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18520                                 __attribute__((unused)) struct cmdline *cl,
18521                                 __attribute__((unused)) void *data)
18522 {
18523         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18524         portid_t port_id = res->port_id;
18525         struct rte_eth_dev_info dev_info;
18526         struct rte_port *port = &ports[port_id];
18527         uint64_t single_offload;
18528         uint16_t nb_tx_queues;
18529         int q;
18530         int ret;
18531
18532         if (port->port_status != RTE_PORT_STOPPED) {
18533                 printf("Error: Can't config offload when Port %d "
18534                        "is not stopped\n", port_id);
18535                 return;
18536         }
18537
18538         single_offload = search_tx_offload(res->offload);
18539         if (single_offload == 0) {
18540                 printf("Unknown offload name: %s\n", res->offload);
18541                 return;
18542         }
18543
18544         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18545         if (ret != 0)
18546                 return;
18547
18548         nb_tx_queues = dev_info.nb_tx_queues;
18549         if (!strcmp(res->on_off, "on")) {
18550                 port->dev_conf.txmode.offloads |= single_offload;
18551                 for (q = 0; q < nb_tx_queues; q++)
18552                         port->tx_conf[q].offloads |= single_offload;
18553         } else {
18554                 port->dev_conf.txmode.offloads &= ~single_offload;
18555                 for (q = 0; q < nb_tx_queues; q++)
18556                         port->tx_conf[q].offloads &= ~single_offload;
18557         }
18558
18559         cmd_reconfig_device_queue(port_id, 1, 1);
18560 }
18561
18562 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18563         .f = cmd_config_per_port_tx_offload_parsed,
18564         .data = NULL,
18565         .help_str = "port config <port_id> tx_offload "
18566                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18567                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18568                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18569                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18570                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18571                     "match_metadata on|off",
18572         .tokens = {
18573                 (void *)&cmd_config_per_port_tx_offload_result_port,
18574                 (void *)&cmd_config_per_port_tx_offload_result_config,
18575                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18576                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18577                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18578                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18579                 NULL,
18580         }
18581 };
18582
18583 /* Enable/Disable a per queue offloading */
18584 struct cmd_config_per_queue_tx_offload_result {
18585         cmdline_fixed_string_t port;
18586         portid_t port_id;
18587         cmdline_fixed_string_t txq;
18588         uint16_t queue_id;
18589         cmdline_fixed_string_t tx_offload;
18590         cmdline_fixed_string_t offload;
18591         cmdline_fixed_string_t on_off;
18592 };
18593
18594 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18595         TOKEN_STRING_INITIALIZER
18596                 (struct cmd_config_per_queue_tx_offload_result,
18597                  port, "port");
18598 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18599         TOKEN_NUM_INITIALIZER
18600                 (struct cmd_config_per_queue_tx_offload_result,
18601                  port_id, UINT16);
18602 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18603         TOKEN_STRING_INITIALIZER
18604                 (struct cmd_config_per_queue_tx_offload_result,
18605                  txq, "txq");
18606 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18607         TOKEN_NUM_INITIALIZER
18608                 (struct cmd_config_per_queue_tx_offload_result,
18609                  queue_id, UINT16);
18610 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18611         TOKEN_STRING_INITIALIZER
18612                 (struct cmd_config_per_queue_tx_offload_result,
18613                  tx_offload, "tx_offload");
18614 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18615         TOKEN_STRING_INITIALIZER
18616                 (struct cmd_config_per_queue_tx_offload_result,
18617                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18618                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18619                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18620                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18621                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18622 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18623         TOKEN_STRING_INITIALIZER
18624                 (struct cmd_config_per_queue_tx_offload_result,
18625                  on_off, "on#off");
18626
18627 static void
18628 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18629                                 __attribute__((unused)) struct cmdline *cl,
18630                                 __attribute__((unused)) void *data)
18631 {
18632         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18633         struct rte_eth_dev_info dev_info;
18634         portid_t port_id = res->port_id;
18635         uint16_t queue_id = res->queue_id;
18636         struct rte_port *port = &ports[port_id];
18637         uint64_t single_offload;
18638         int ret;
18639
18640         if (port->port_status != RTE_PORT_STOPPED) {
18641                 printf("Error: Can't config offload when Port %d "
18642                        "is not stopped\n", port_id);
18643                 return;
18644         }
18645
18646         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18647         if (ret != 0)
18648                 return;
18649
18650         if (queue_id >= dev_info.nb_tx_queues) {
18651                 printf("Error: input queue_id should be 0 ... "
18652                        "%d\n", dev_info.nb_tx_queues - 1);
18653                 return;
18654         }
18655
18656         single_offload = search_tx_offload(res->offload);
18657         if (single_offload == 0) {
18658                 printf("Unknown offload name: %s\n", res->offload);
18659                 return;
18660         }
18661
18662         if (!strcmp(res->on_off, "on"))
18663                 port->tx_conf[queue_id].offloads |= single_offload;
18664         else
18665                 port->tx_conf[queue_id].offloads &= ~single_offload;
18666
18667         cmd_reconfig_device_queue(port_id, 1, 1);
18668 }
18669
18670 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18671         .f = cmd_config_per_queue_tx_offload_parsed,
18672         .data = NULL,
18673         .help_str = "port <port_id> txq <queue_id> tx_offload "
18674                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18675                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18676                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18677                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18678                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18679                     "on|off",
18680         .tokens = {
18681                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18682                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18683                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18684                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18685                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18686                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18687                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18688                 NULL,
18689         }
18690 };
18691
18692 /* *** configure tx_metadata for specific port *** */
18693 struct cmd_config_tx_metadata_specific_result {
18694         cmdline_fixed_string_t port;
18695         cmdline_fixed_string_t keyword;
18696         uint16_t port_id;
18697         cmdline_fixed_string_t item;
18698         uint32_t value;
18699 };
18700
18701 static void
18702 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18703                                 __attribute__((unused)) struct cmdline *cl,
18704                                 __attribute__((unused)) void *data)
18705 {
18706         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18707
18708         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18709                 return;
18710         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18711         /* Add/remove callback to insert valid metadata in every Tx packet. */
18712         if (ports[res->port_id].tx_metadata)
18713                 add_tx_md_callback(res->port_id);
18714         else
18715                 remove_tx_md_callback(res->port_id);
18716 }
18717
18718 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18719         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18720                         port, "port");
18721 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18722         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18723                         keyword, "config");
18724 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18725         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18726                         port_id, UINT16);
18727 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18728         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18729                         item, "tx_metadata");
18730 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18731         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18732                         value, UINT32);
18733
18734 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18735         .f = cmd_config_tx_metadata_specific_parsed,
18736         .data = NULL,
18737         .help_str = "port config <port_id> tx_metadata <value>",
18738         .tokens = {
18739                 (void *)&cmd_config_tx_metadata_specific_port,
18740                 (void *)&cmd_config_tx_metadata_specific_keyword,
18741                 (void *)&cmd_config_tx_metadata_specific_id,
18742                 (void *)&cmd_config_tx_metadata_specific_item,
18743                 (void *)&cmd_config_tx_metadata_specific_value,
18744                 NULL,
18745         },
18746 };
18747
18748 /* *** display tx_metadata per port configuration *** */
18749 struct cmd_show_tx_metadata_result {
18750         cmdline_fixed_string_t cmd_show;
18751         cmdline_fixed_string_t cmd_port;
18752         cmdline_fixed_string_t cmd_keyword;
18753         portid_t cmd_pid;
18754 };
18755
18756 static void
18757 cmd_show_tx_metadata_parsed(void *parsed_result,
18758                 __attribute__((unused)) struct cmdline *cl,
18759                 __attribute__((unused)) void *data)
18760 {
18761         struct cmd_show_tx_metadata_result *res = parsed_result;
18762
18763         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18764                 printf("invalid port id %u\n", res->cmd_pid);
18765                 return;
18766         }
18767         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18768                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18769                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18770         }
18771 }
18772
18773 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18774         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18775                         cmd_show, "show");
18776 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18777         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18778                         cmd_port, "port");
18779 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18780         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18781                         cmd_pid, UINT16);
18782 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18783         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18784                         cmd_keyword, "tx_metadata");
18785
18786 cmdline_parse_inst_t cmd_show_tx_metadata = {
18787         .f = cmd_show_tx_metadata_parsed,
18788         .data = NULL,
18789         .help_str = "show port <port_id> tx_metadata",
18790         .tokens = {
18791                 (void *)&cmd_show_tx_metadata_show,
18792                 (void *)&cmd_show_tx_metadata_port,
18793                 (void *)&cmd_show_tx_metadata_pid,
18794                 (void *)&cmd_show_tx_metadata_keyword,
18795                 NULL,
18796         },
18797 };
18798
18799 /* ******************************************************************************** */
18800
18801 /* list of instructions */
18802 cmdline_parse_ctx_t main_ctx[] = {
18803         (cmdline_parse_inst_t *)&cmd_help_brief,
18804         (cmdline_parse_inst_t *)&cmd_help_long,
18805         (cmdline_parse_inst_t *)&cmd_quit,
18806         (cmdline_parse_inst_t *)&cmd_load_from_file,
18807         (cmdline_parse_inst_t *)&cmd_showport,
18808         (cmdline_parse_inst_t *)&cmd_showqueue,
18809         (cmdline_parse_inst_t *)&cmd_showportall,
18810         (cmdline_parse_inst_t *)&cmd_showdevice,
18811         (cmdline_parse_inst_t *)&cmd_showcfg,
18812         (cmdline_parse_inst_t *)&cmd_showfwdall,
18813         (cmdline_parse_inst_t *)&cmd_start,
18814         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18815         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18816         (cmdline_parse_inst_t *)&cmd_set_link_up,
18817         (cmdline_parse_inst_t *)&cmd_set_link_down,
18818         (cmdline_parse_inst_t *)&cmd_reset,
18819         (cmdline_parse_inst_t *)&cmd_set_numbers,
18820         (cmdline_parse_inst_t *)&cmd_set_log,
18821         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18822         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18823         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18824         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18825         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18826         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18827         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18828         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18829         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18830         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18831         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18832         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18833         (cmdline_parse_inst_t *)&cmd_set_link_check,
18834         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18835         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18836         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18837         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18838 #ifdef RTE_LIBRTE_PMD_BOND
18839         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18840         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18841         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18842         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18843         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18844         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18845         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18846         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18847         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18848         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18849         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18850 #endif
18851         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18852         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18853         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18854         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18855         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18856         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18857         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18858         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18859         (cmdline_parse_inst_t *)&cmd_csum_set,
18860         (cmdline_parse_inst_t *)&cmd_csum_show,
18861         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18862         (cmdline_parse_inst_t *)&cmd_tso_set,
18863         (cmdline_parse_inst_t *)&cmd_tso_show,
18864         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18865         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18866         (cmdline_parse_inst_t *)&cmd_gro_enable,
18867         (cmdline_parse_inst_t *)&cmd_gro_flush,
18868         (cmdline_parse_inst_t *)&cmd_gro_show,
18869         (cmdline_parse_inst_t *)&cmd_gso_enable,
18870         (cmdline_parse_inst_t *)&cmd_gso_size,
18871         (cmdline_parse_inst_t *)&cmd_gso_show,
18872         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18873         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18874         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18875         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18876         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18877         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18878         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18879         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18880         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18881         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18882         (cmdline_parse_inst_t *)&cmd_config_dcb,
18883         (cmdline_parse_inst_t *)&cmd_read_reg,
18884         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18885         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18886         (cmdline_parse_inst_t *)&cmd_write_reg,
18887         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18888         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18889         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18890         (cmdline_parse_inst_t *)&cmd_stop,
18891         (cmdline_parse_inst_t *)&cmd_mac_addr,
18892         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18893         (cmdline_parse_inst_t *)&cmd_set_qmap,
18894         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18895         (cmdline_parse_inst_t *)&cmd_operate_port,
18896         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18897         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18898         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18899         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
18900         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18901         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18902         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18903         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18904         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18905         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18906         (cmdline_parse_inst_t *)&cmd_config_mtu,
18907         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18908         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18909         (cmdline_parse_inst_t *)&cmd_config_rss,
18910         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18911         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18912         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18913         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18914         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18915         (cmdline_parse_inst_t *)&cmd_showport_reta,
18916         (cmdline_parse_inst_t *)&cmd_config_burst,
18917         (cmdline_parse_inst_t *)&cmd_config_thresh,
18918         (cmdline_parse_inst_t *)&cmd_config_threshold,
18919         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18920         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18921         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18922         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18923         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18924         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18925         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18926         (cmdline_parse_inst_t *)&cmd_global_config,
18927         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18928         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18929         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18930         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18931         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18932         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18933         (cmdline_parse_inst_t *)&cmd_dump,
18934         (cmdline_parse_inst_t *)&cmd_dump_one,
18935         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18936         (cmdline_parse_inst_t *)&cmd_syn_filter,
18937         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18938         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18939         (cmdline_parse_inst_t *)&cmd_flex_filter,
18940         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18941         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18942         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18943         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18944         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18945         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18946         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18947         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18948         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18949         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18950         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18951         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18952         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18953         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18954         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18955         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18956         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18957         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18958         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18959         (cmdline_parse_inst_t *)&cmd_flow,
18960         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18961         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18962         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18963         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18964         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18965         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18966         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18967         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18968         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18969         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18970         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18971         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18972         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18973         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18974         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18975         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18976         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18977         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18978         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18979         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18980         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18981         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18982         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18983         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18984         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18985         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18986         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18987         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18988         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18989         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18990         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18991         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18992         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18993         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18994         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18995         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18996         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18997         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18998         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18999         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19000         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19001         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19002         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19003         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19004         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19005         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19006         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19007         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19008         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19009 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19010         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19011 #endif
19012         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19013         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19014         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19015         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19016         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19017         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19018         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19019         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19020         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19021         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19022         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19023         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19024         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19025         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19026         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19027         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19028         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19029         (cmdline_parse_inst_t *)&cmd_ddp_add,
19030         (cmdline_parse_inst_t *)&cmd_ddp_del,
19031         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19032         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19033         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19034         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19035         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19036         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19037         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19038         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19039         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19040         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19041
19042         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19043         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19044         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19045         (cmdline_parse_inst_t *)&cmd_queue_region,
19046         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19047         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19048         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19049         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19050         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19051         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19052         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19053         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19054         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19055         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19056         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19057         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19058         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19059         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19060         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19061         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19062         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19063         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19064         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19065         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19066         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19067         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19068         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19069         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19070         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19071         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19072         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19073         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19074         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19075         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19076         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19077         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19078         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19079         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19080         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19081 #ifdef RTE_LIBRTE_BPF
19082         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19083         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19084 #endif
19085         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19086         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19087         (cmdline_parse_inst_t *)&cmd_set_raw,
19088         NULL,
19089 };
19090
19091 /* read cmdline commands from file */
19092 void
19093 cmdline_read_from_file(const char *filename)
19094 {
19095         struct cmdline *cl;
19096
19097         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19098         if (cl == NULL) {
19099                 printf("Failed to create file based cmdline context: %s\n",
19100                        filename);
19101                 return;
19102         }
19103
19104         cmdline_interact(cl);
19105         cmdline_quit(cl);
19106
19107         cmdline_free(cl);
19108
19109         printf("Read CLI commands from %s\n", filename);
19110 }
19111
19112 /* prompt function, called from main on MASTER lcore */
19113 void
19114 prompt(void)
19115 {
19116         /* initialize non-constant commands */
19117         cmd_set_fwd_mode_init();
19118         cmd_set_fwd_retry_mode_init();
19119
19120         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19121         if (testpmd_cl == NULL)
19122                 return;
19123         cmdline_interact(testpmd_cl);
19124         cmdline_stdin_exit(testpmd_cl);
19125 }
19126
19127 void
19128 prompt_exit(void)
19129 {
19130         if (testpmd_cl != NULL)
19131                 cmdline_quit(testpmd_cl);
19132 }
19133
19134 static void
19135 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19136 {
19137         if (id == (portid_t)RTE_PORT_ALL) {
19138                 portid_t pid;
19139
19140                 RTE_ETH_FOREACH_DEV(pid) {
19141                         /* check if need_reconfig has been set to 1 */
19142                         if (ports[pid].need_reconfig == 0)
19143                                 ports[pid].need_reconfig = dev;
19144                         /* check if need_reconfig_queues has been set to 1 */
19145                         if (ports[pid].need_reconfig_queues == 0)
19146                                 ports[pid].need_reconfig_queues = queue;
19147                 }
19148         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19149                 /* check if need_reconfig has been set to 1 */
19150                 if (ports[id].need_reconfig == 0)
19151                         ports[id].need_reconfig = dev;
19152                 /* check if need_reconfig_queues has been set to 1 */
19153                 if (ports[id].need_reconfig_queues == 0)
19154                         ports[id].need_reconfig_queues = queue;
19155         }
19156 }