app/testpmd: check code of allmulticast mode switch
[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 attach (ident)\n"
762                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
763
764                         "port detach (port_id)\n"
765                         "    Detach physical or virtual dev by port_id\n\n"
766
767                         "port config (port_id|all)"
768                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
769                         " duplex (half|full|auto)\n"
770                         "    Set speed and duplex for all ports or port_id\n\n"
771
772                         "port config (port_id|all) loopback (mode)\n"
773                         "    Set loopback mode for all ports or port_id\n\n"
774
775                         "port config all (rxq|txq|rxd|txd) (value)\n"
776                         "    Set number for rxq/txq/rxd/txd.\n\n"
777
778                         "port config all max-pkt-len (value)\n"
779                         "    Set the max packet length.\n\n"
780
781                         "port config all drop-en (on|off)\n"
782                         "    Enable or disable packet drop on all RX queues of all ports when no "
783                         "receive buffers available.\n\n"
784
785                         "port config all rss (all|default|ip|tcp|udp|sctp|"
786                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
787                         "    Set the RSS mode.\n\n"
788
789                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
790                         "    Set the RSS redirection table.\n\n"
791
792                         "port config (port_id) dcb vt (on|off) (traffic_class)"
793                         " pfc (on|off)\n"
794                         "    Set the DCB mode.\n\n"
795
796                         "port config all burst (value)\n"
797                         "    Set the number of packets per burst.\n\n"
798
799                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
800                         " (value)\n"
801                         "    Set the ring prefetch/host/writeback threshold"
802                         " for tx/rx queue.\n\n"
803
804                         "port config all (txfreet|txrst|rxfreet) (value)\n"
805                         "    Set free threshold for rx/tx, or set"
806                         " tx rs bit threshold.\n\n"
807                         "port config mtu X value\n"
808                         "    Set the MTU of port X to a given value\n\n"
809
810                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
811                         "    Set a rx/tx queue's ring size configuration, the new"
812                         " value will take effect after command that (re-)start the port"
813                         " or command that setup the specific queue\n\n"
814
815                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
816                         "    Start/stop a rx/tx queue of port X. Only take effect"
817                         " when port X is started\n\n"
818
819                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
820                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
821                         " take effect when port X is stopped.\n\n"
822
823                         "port (port_id) (rxq|txq) (queue_id) setup\n"
824                         "    Setup a rx/tx queue of port X.\n\n"
825
826                         "port config (port_id|all) l2-tunnel E-tag ether-type"
827                         " (value)\n"
828                         "    Set the value of E-tag ether-type.\n\n"
829
830                         "port config (port_id|all) l2-tunnel E-tag"
831                         " (enable|disable)\n"
832                         "    Enable/disable the E-tag support.\n\n"
833
834                         "port config (port_id) pctype mapping reset\n"
835                         "    Reset flow type to pctype mapping on a port\n\n"
836
837                         "port config (port_id) pctype mapping update"
838                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
839                         "    Update a flow type to pctype mapping item on a port\n\n"
840
841                         "port config (port_id) pctype (pctype_id) hash_inset|"
842                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
843                         " (field_idx)\n"
844                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
845
846                         "port config (port_id) pctype (pctype_id) hash_inset|"
847                         "fdir_inset|fdir_flx_inset clear all"
848                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
849
850                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
851                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
852
853                         "port config <port_id> rx_offload vlan_strip|"
854                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
855                         "outer_ipv4_cksum|macsec_strip|header_split|"
856                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
857                         "scatter|timestamp|security|keep_crc on|off\n"
858                         "     Enable or disable a per port Rx offloading"
859                         " on all Rx queues of a port\n\n"
860
861                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
862                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
863                         "outer_ipv4_cksum|macsec_strip|header_split|"
864                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
865                         "scatter|timestamp|security|keep_crc on|off\n"
866                         "    Enable or disable a per queue Rx offloading"
867                         " only on a specific Rx queue\n\n"
868
869                         "port config (port_id) tx_offload vlan_insert|"
870                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
871                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
872                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
873                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
874                         "security|match_metadata on|off\n"
875                         "    Enable or disable a per port Tx offloading"
876                         " on all Tx queues of a port\n\n"
877
878                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
879                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
880                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
881                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
882                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
883                         " on|off\n"
884                         "    Enable or disable a per queue Tx offloading"
885                         " only on a specific Tx queue\n\n"
886
887                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
888                         "    Load an eBPF program as a callback"
889                         " for particular RX/TX queue\n\n"
890
891                         "bpf-unload rx|tx (port) (queue)\n"
892                         "    Unload previously loaded eBPF program"
893                         " for particular RX/TX queue\n\n"
894
895                         "port config (port_id) tx_metadata (value)\n"
896                         "    Set Tx metadata value per port. Testpmd will add this value"
897                         " to any Tx packet sent from this port\n\n"
898                 );
899         }
900
901         if (show_all || !strcmp(res->section, "registers")) {
902
903                 cmdline_printf(
904                         cl,
905                         "\n"
906                         "Registers:\n"
907                         "----------\n\n"
908
909                         "read reg (port_id) (address)\n"
910                         "    Display value of a port register.\n\n"
911
912                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
913                         "    Display a port register bit field.\n\n"
914
915                         "read regbit (port_id) (address) (bit_x)\n"
916                         "    Display a single port register bit.\n\n"
917
918                         "write reg (port_id) (address) (value)\n"
919                         "    Set value of a port register.\n\n"
920
921                         "write regfield (port_id) (address) (bit_x) (bit_y)"
922                         " (value)\n"
923                         "    Set bit field of a port register.\n\n"
924
925                         "write regbit (port_id) (address) (bit_x) (value)\n"
926                         "    Set single bit value of a port register.\n\n"
927                 );
928         }
929         if (show_all || !strcmp(res->section, "filters")) {
930
931                 cmdline_printf(
932                         cl,
933                         "\n"
934                         "filters:\n"
935                         "--------\n\n"
936
937                         "ethertype_filter (port_id) (add|del)"
938                         " (mac_addr|mac_ignr) (mac_address) ethertype"
939                         " (ether_type) (drop|fwd) queue (queue_id)\n"
940                         "    Add/Del an ethertype filter.\n\n"
941
942                         "2tuple_filter (port_id) (add|del)"
943                         " dst_port (dst_port_value) protocol (protocol_value)"
944                         " mask (mask_value) tcp_flags (tcp_flags_value)"
945                         " priority (prio_value) queue (queue_id)\n"
946                         "    Add/Del a 2tuple filter.\n\n"
947
948                         "5tuple_filter (port_id) (add|del)"
949                         " dst_ip (dst_address) src_ip (src_address)"
950                         " dst_port (dst_port_value) src_port (src_port_value)"
951                         " protocol (protocol_value)"
952                         " mask (mask_value) tcp_flags (tcp_flags_value)"
953                         " priority (prio_value) queue (queue_id)\n"
954                         "    Add/Del a 5tuple filter.\n\n"
955
956                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
957                         "    Add/Del syn filter.\n\n"
958
959                         "flex_filter (port_id) (add|del) len (len_value)"
960                         " bytes (bytes_value) mask (mask_value)"
961                         " priority (prio_value) queue (queue_id)\n"
962                         "    Add/Del a flex filter.\n\n"
963
964                         "flow_director_filter (port_id) mode IP (add|del|update)"
965                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
966                         " src (src_ip_address) dst (dst_ip_address)"
967                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
968                         " vlan (vlan_value) flexbytes (flexbytes_value)"
969                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
970                         " fd_id (fd_id_value)\n"
971                         "    Add/Del an IP type flow director filter.\n\n"
972
973                         "flow_director_filter (port_id) mode IP (add|del|update)"
974                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
975                         " src (src_ip_address) (src_port)"
976                         " dst (dst_ip_address) (dst_port)"
977                         " tos (tos_value) ttl (ttl_value)"
978                         " vlan (vlan_value) flexbytes (flexbytes_value)"
979                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
980                         " fd_id (fd_id_value)\n"
981                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
982
983                         "flow_director_filter (port_id) mode IP (add|del|update)"
984                         " flow (ipv4-sctp|ipv6-sctp)"
985                         " src (src_ip_address) (src_port)"
986                         " dst (dst_ip_address) (dst_port)"
987                         " tag (verification_tag) "
988                         " tos (tos_value) ttl (ttl_value)"
989                         " vlan (vlan_value)"
990                         " flexbytes (flexbytes_value) (drop|fwd)"
991                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
992                         "    Add/Del a SCTP type flow director filter.\n\n"
993
994                         "flow_director_filter (port_id) mode IP (add|del|update)"
995                         " flow l2_payload ether (ethertype)"
996                         " flexbytes (flexbytes_value) (drop|fwd)"
997                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
998                         "    Add/Del a l2 payload type flow director filter.\n\n"
999
1000                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1001                         " mac (mac_address) vlan (vlan_value)"
1002                         " flexbytes (flexbytes_value) (drop|fwd)"
1003                         " queue (queue_id) fd_id (fd_id_value)\n"
1004                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1007                         " mac (mac_address) vlan (vlan_value)"
1008                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1009                         " flexbytes (flexbytes_value) (drop|fwd)"
1010                         " queue (queue_id) fd_id (fd_id_value)\n"
1011                         "    Add/Del a Tunnel flow director filter.\n\n"
1012
1013                         "flow_director_filter (port_id) mode raw (add|del|update)"
1014                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1015                         " fd_id (fd_id_value) packet (packet file name)\n"
1016                         "    Add/Del a raw type flow director filter.\n\n"
1017
1018                         "flush_flow_director (port_id)\n"
1019                         "    Flush all flow director entries of a device.\n\n"
1020
1021                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1022                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1023                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1024                         "    Set flow director IP mask.\n\n"
1025
1026                         "flow_director_mask (port_id) mode MAC-VLAN"
1027                         " vlan (vlan_value)\n"
1028                         "    Set flow director MAC-VLAN mask.\n\n"
1029
1030                         "flow_director_mask (port_id) mode Tunnel"
1031                         " vlan (vlan_value) mac (mac_value)"
1032                         " tunnel-type (tunnel_type_value)"
1033                         " tunnel-id (tunnel_id_value)\n"
1034                         "    Set flow director Tunnel mask.\n\n"
1035
1036                         "flow_director_flex_mask (port_id)"
1037                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1038                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1039                         " (mask)\n"
1040                         "    Configure mask of flex payload.\n\n"
1041
1042                         "flow_director_flex_payload (port_id)"
1043                         " (raw|l2|l3|l4) (config)\n"
1044                         "    Configure flex payload selection.\n\n"
1045
1046                         "get_sym_hash_ena_per_port (port_id)\n"
1047                         "    get symmetric hash enable configuration per port.\n\n"
1048
1049                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1050                         "    set symmetric hash enable configuration per port"
1051                         " to enable or disable.\n\n"
1052
1053                         "get_hash_global_config (port_id)\n"
1054                         "    Get the global configurations of hash filters.\n\n"
1055
1056                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1057                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1058                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1059                         " (enable|disable)\n"
1060                         "    Set the global configurations of hash filters.\n\n"
1061
1062                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1063                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1064                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1065                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1066                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1067                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1068                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1069                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1070                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1071                         "fld-8th|none) (select|add)\n"
1072                         "    Set the input set for hash.\n\n"
1073
1074                         "set_fdir_input_set (port_id) "
1075                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1076                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1077                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1078                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1079                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1080                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1081                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1082                         " (select|add)\n"
1083                         "    Set the input set for FDir.\n\n"
1084
1085                         "flow validate {port_id}"
1086                         " [group {group_id}] [priority {level}]"
1087                         " [ingress] [egress]"
1088                         " pattern {item} [/ {item} [...]] / end"
1089                         " actions {action} [/ {action} [...]] / end\n"
1090                         "    Check whether a flow rule can be created.\n\n"
1091
1092                         "flow create {port_id}"
1093                         " [group {group_id}] [priority {level}]"
1094                         " [ingress] [egress]"
1095                         " pattern {item} [/ {item} [...]] / end"
1096                         " actions {action} [/ {action} [...]] / end\n"
1097                         "    Create a flow rule.\n\n"
1098
1099                         "flow destroy {port_id} rule {rule_id} [...]\n"
1100                         "    Destroy specific flow rules.\n\n"
1101
1102                         "flow flush {port_id}\n"
1103                         "    Destroy all flow rules.\n\n"
1104
1105                         "flow query {port_id} {rule_id} {action}\n"
1106                         "    Query an existing flow rule.\n\n"
1107
1108                         "flow list {port_id} [group {group_id}] [...]\n"
1109                         "    List existing flow rules sorted by priority,"
1110                         " filtered by group identifiers.\n\n"
1111
1112                         "flow isolate {port_id} {boolean}\n"
1113                         "    Restrict ingress traffic to the defined"
1114                         " flow rules\n\n"
1115
1116                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1117                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1118                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1119                         "       Configure the VXLAN encapsulation for flows.\n\n"
1120
1121                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1122                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1123                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1124                         " eth-dst (eth-dst)\n"
1125                         "       Configure the VXLAN encapsulation for flows.\n\n"
1126
1127                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1128                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1129                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1130                         " eth-dst (eth-dst)\n"
1131                         "       Configure the VXLAN encapsulation for flows.\n\n"
1132
1133                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1134                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1135                         " (eth-dst)\n"
1136                         "       Configure the NVGRE encapsulation for flows.\n\n"
1137
1138                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1139                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1140                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1141                         "       Configure the NVGRE encapsulation for flows.\n\n"
1142
1143                         "set raw_encap {flow items}\n"
1144                         "       Configure the encapsulation with raw data.\n\n"
1145
1146                         "set raw_decap {flow items}\n"
1147                         "       Configure the decapsulation with raw data.\n\n"
1148
1149                 );
1150         }
1151
1152         if (show_all || !strcmp(res->section, "traffic_management")) {
1153                 cmdline_printf(
1154                         cl,
1155                         "\n"
1156                         "Traffic Management:\n"
1157                         "--------------\n"
1158                         "show port tm cap (port_id)\n"
1159                         "       Display the port TM capability.\n\n"
1160
1161                         "show port tm level cap (port_id) (level_id)\n"
1162                         "       Display the port TM hierarchical level capability.\n\n"
1163
1164                         "show port tm node cap (port_id) (node_id)\n"
1165                         "       Display the port TM node capability.\n\n"
1166
1167                         "show port tm node type (port_id) (node_id)\n"
1168                         "       Display the port TM node type.\n\n"
1169
1170                         "show port tm node stats (port_id) (node_id) (clear)\n"
1171                         "       Display the port TM node stats.\n\n"
1172
1173 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1174                         "set port tm hierarchy default (port_id)\n"
1175                         "       Set default traffic Management hierarchy on a port\n\n"
1176 #endif
1177
1178                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1179                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1180                         " (packet_length_adjust)\n"
1181                         "       Add port tm node private shaper profile.\n\n"
1182
1183                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1184                         "       Delete port tm node private shaper profile.\n\n"
1185
1186                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1187                         " (shaper_profile_id)\n"
1188                         "       Add/update port tm node shared shaper.\n\n"
1189
1190                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1191                         "       Delete port tm node shared shaper.\n\n"
1192
1193                         "set port tm node shaper profile (port_id) (node_id)"
1194                         " (shaper_profile_id)\n"
1195                         "       Set port tm node shaper profile.\n\n"
1196
1197                         "add port tm node wred profile (port_id) (wred_profile_id)"
1198                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1199                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1200                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1201                         "       Add port tm node wred profile.\n\n"
1202
1203                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1204                         "       Delete port tm node wred profile.\n\n"
1205
1206                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1207                         " (priority) (weight) (level_id) (shaper_profile_id)"
1208                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1209                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1210                         "       Add port tm nonleaf node.\n\n"
1211
1212                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1213                         " (priority) (weight) (level_id) (shaper_profile_id)"
1214                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1215                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1216                         "       Add port tm leaf node.\n\n"
1217
1218                         "del port tm node (port_id) (node_id)\n"
1219                         "       Delete port tm node.\n\n"
1220
1221                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1222                         " (priority) (weight)\n"
1223                         "       Set port tm node parent.\n\n"
1224
1225                         "suspend port tm node (port_id) (node_id)"
1226                         "       Suspend tm node.\n\n"
1227
1228                         "resume port tm node (port_id) (node_id)"
1229                         "       Resume tm node.\n\n"
1230
1231                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1232                         "       Commit tm hierarchy.\n\n"
1233
1234                         "set port tm mark ip_ecn (port) (green) (yellow)"
1235                         " (red)\n"
1236                         "    Enables/Disables the traffic management marking"
1237                         " for IP ECN (Explicit Congestion Notification)"
1238                         " packets on a given port\n\n"
1239
1240                         "set port tm mark ip_dscp (port) (green) (yellow)"
1241                         " (red)\n"
1242                         "    Enables/Disables the traffic management marking"
1243                         " on the port for IP dscp packets\n\n"
1244
1245                         "set port tm mark vlan_dei (port) (green) (yellow)"
1246                         " (red)\n"
1247                         "    Enables/Disables the traffic management marking"
1248                         " on the port for VLAN packets with DEI enabled\n\n"
1249                 );
1250         }
1251
1252         if (show_all || !strcmp(res->section, "devices")) {
1253                 cmdline_printf(
1254                         cl,
1255                         "\n"
1256                         "Device Operations:\n"
1257                         "--------------\n"
1258                         "device detach (identifier)\n"
1259                         "       Detach device by identifier.\n\n"
1260                 );
1261         }
1262
1263 }
1264
1265 cmdline_parse_token_string_t cmd_help_long_help =
1266         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1267
1268 cmdline_parse_token_string_t cmd_help_long_section =
1269         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1270                         "all#control#display#config#"
1271                         "ports#registers#filters#traffic_management#devices");
1272
1273 cmdline_parse_inst_t cmd_help_long = {
1274         .f = cmd_help_long_parsed,
1275         .data = NULL,
1276         .help_str = "help all|control|display|config|ports|register|"
1277                 "filters|traffic_management|devices: "
1278                 "Show help",
1279         .tokens = {
1280                 (void *)&cmd_help_long_help,
1281                 (void *)&cmd_help_long_section,
1282                 NULL,
1283         },
1284 };
1285
1286
1287 /* *** start/stop/close all ports *** */
1288 struct cmd_operate_port_result {
1289         cmdline_fixed_string_t keyword;
1290         cmdline_fixed_string_t name;
1291         cmdline_fixed_string_t value;
1292 };
1293
1294 static void cmd_operate_port_parsed(void *parsed_result,
1295                                 __attribute__((unused)) struct cmdline *cl,
1296                                 __attribute__((unused)) void *data)
1297 {
1298         struct cmd_operate_port_result *res = parsed_result;
1299
1300         if (!strcmp(res->name, "start"))
1301                 start_port(RTE_PORT_ALL);
1302         else if (!strcmp(res->name, "stop"))
1303                 stop_port(RTE_PORT_ALL);
1304         else if (!strcmp(res->name, "close"))
1305                 close_port(RTE_PORT_ALL);
1306         else if (!strcmp(res->name, "reset"))
1307                 reset_port(RTE_PORT_ALL);
1308         else
1309                 printf("Unknown parameter\n");
1310 }
1311
1312 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1313         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1314                                                                 "port");
1315 cmdline_parse_token_string_t cmd_operate_port_all_port =
1316         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1317                                                 "start#stop#close#reset");
1318 cmdline_parse_token_string_t cmd_operate_port_all_all =
1319         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1320
1321 cmdline_parse_inst_t cmd_operate_port = {
1322         .f = cmd_operate_port_parsed,
1323         .data = NULL,
1324         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1325         .tokens = {
1326                 (void *)&cmd_operate_port_all_cmd,
1327                 (void *)&cmd_operate_port_all_port,
1328                 (void *)&cmd_operate_port_all_all,
1329                 NULL,
1330         },
1331 };
1332
1333 /* *** start/stop/close specific port *** */
1334 struct cmd_operate_specific_port_result {
1335         cmdline_fixed_string_t keyword;
1336         cmdline_fixed_string_t name;
1337         uint8_t value;
1338 };
1339
1340 static void cmd_operate_specific_port_parsed(void *parsed_result,
1341                         __attribute__((unused)) struct cmdline *cl,
1342                                 __attribute__((unused)) void *data)
1343 {
1344         struct cmd_operate_specific_port_result *res = parsed_result;
1345
1346         if (!strcmp(res->name, "start"))
1347                 start_port(res->value);
1348         else if (!strcmp(res->name, "stop"))
1349                 stop_port(res->value);
1350         else if (!strcmp(res->name, "close"))
1351                 close_port(res->value);
1352         else if (!strcmp(res->name, "reset"))
1353                 reset_port(res->value);
1354         else
1355                 printf("Unknown parameter\n");
1356 }
1357
1358 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1359         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1360                                                         keyword, "port");
1361 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1362         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1363                                                 name, "start#stop#close#reset");
1364 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1365         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1366                                                         value, UINT8);
1367
1368 cmdline_parse_inst_t cmd_operate_specific_port = {
1369         .f = cmd_operate_specific_port_parsed,
1370         .data = NULL,
1371         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1372         .tokens = {
1373                 (void *)&cmd_operate_specific_port_cmd,
1374                 (void *)&cmd_operate_specific_port_port,
1375                 (void *)&cmd_operate_specific_port_id,
1376                 NULL,
1377         },
1378 };
1379
1380 /* *** enable port setup (after attach) via iterator or event *** */
1381 struct cmd_set_port_setup_on_result {
1382         cmdline_fixed_string_t set;
1383         cmdline_fixed_string_t port;
1384         cmdline_fixed_string_t setup;
1385         cmdline_fixed_string_t on;
1386         cmdline_fixed_string_t mode;
1387 };
1388
1389 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1390                                 __attribute__((unused)) struct cmdline *cl,
1391                                 __attribute__((unused)) void *data)
1392 {
1393         struct cmd_set_port_setup_on_result *res = parsed_result;
1394
1395         if (strcmp(res->mode, "event") == 0)
1396                 setup_on_probe_event = true;
1397         else if (strcmp(res->mode, "iterator") == 0)
1398                 setup_on_probe_event = false;
1399         else
1400                 printf("Unknown mode\n");
1401 }
1402
1403 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1404         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1405                         set, "set");
1406 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1407         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1408                         port, "port");
1409 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1410         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1411                         setup, "setup");
1412 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1413         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1414                         on, "on");
1415 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1416         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1417                         mode, "iterator#event");
1418
1419 cmdline_parse_inst_t cmd_set_port_setup_on = {
1420         .f = cmd_set_port_setup_on_parsed,
1421         .data = NULL,
1422         .help_str = "set port setup on iterator|event",
1423         .tokens = {
1424                 (void *)&cmd_set_port_setup_on_set,
1425                 (void *)&cmd_set_port_setup_on_port,
1426                 (void *)&cmd_set_port_setup_on_setup,
1427                 (void *)&cmd_set_port_setup_on_on,
1428                 (void *)&cmd_set_port_setup_on_mode,
1429                 NULL,
1430         },
1431 };
1432
1433 /* *** attach a specified port *** */
1434 struct cmd_operate_attach_port_result {
1435         cmdline_fixed_string_t port;
1436         cmdline_fixed_string_t keyword;
1437         cmdline_fixed_string_t identifier;
1438 };
1439
1440 static void cmd_operate_attach_port_parsed(void *parsed_result,
1441                                 __attribute__((unused)) struct cmdline *cl,
1442                                 __attribute__((unused)) void *data)
1443 {
1444         struct cmd_operate_attach_port_result *res = parsed_result;
1445
1446         if (!strcmp(res->keyword, "attach"))
1447                 attach_port(res->identifier);
1448         else
1449                 printf("Unknown parameter\n");
1450 }
1451
1452 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1453         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1454                         port, "port");
1455 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1456         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1457                         keyword, "attach");
1458 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1459         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1460                         identifier, NULL);
1461
1462 cmdline_parse_inst_t cmd_operate_attach_port = {
1463         .f = cmd_operate_attach_port_parsed,
1464         .data = NULL,
1465         .help_str = "port attach <identifier>: "
1466                 "(identifier: pci address or virtual dev name)",
1467         .tokens = {
1468                 (void *)&cmd_operate_attach_port_port,
1469                 (void *)&cmd_operate_attach_port_keyword,
1470                 (void *)&cmd_operate_attach_port_identifier,
1471                 NULL,
1472         },
1473 };
1474
1475 /* *** detach a specified port *** */
1476 struct cmd_operate_detach_port_result {
1477         cmdline_fixed_string_t port;
1478         cmdline_fixed_string_t keyword;
1479         portid_t port_id;
1480 };
1481
1482 static void cmd_operate_detach_port_parsed(void *parsed_result,
1483                                 __attribute__((unused)) struct cmdline *cl,
1484                                 __attribute__((unused)) void *data)
1485 {
1486         struct cmd_operate_detach_port_result *res = parsed_result;
1487
1488         if (!strcmp(res->keyword, "detach"))
1489                 detach_port_device(res->port_id);
1490         else
1491                 printf("Unknown parameter\n");
1492 }
1493
1494 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1495         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1496                         port, "port");
1497 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1498         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1499                         keyword, "detach");
1500 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1501         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1502                         port_id, UINT16);
1503
1504 cmdline_parse_inst_t cmd_operate_detach_port = {
1505         .f = cmd_operate_detach_port_parsed,
1506         .data = NULL,
1507         .help_str = "port detach <port_id>",
1508         .tokens = {
1509                 (void *)&cmd_operate_detach_port_port,
1510                 (void *)&cmd_operate_detach_port_keyword,
1511                 (void *)&cmd_operate_detach_port_port_id,
1512                 NULL,
1513         },
1514 };
1515
1516 /* *** detach device by identifier *** */
1517 struct cmd_operate_detach_device_result {
1518         cmdline_fixed_string_t device;
1519         cmdline_fixed_string_t keyword;
1520         cmdline_fixed_string_t identifier;
1521 };
1522
1523 static void cmd_operate_detach_device_parsed(void *parsed_result,
1524                                 __attribute__((unused)) struct cmdline *cl,
1525                                 __attribute__((unused)) void *data)
1526 {
1527         struct cmd_operate_detach_device_result *res = parsed_result;
1528
1529         if (!strcmp(res->keyword, "detach"))
1530                 detach_device(res->identifier);
1531         else
1532                 printf("Unknown parameter\n");
1533 }
1534
1535 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1536         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1537                         device, "device");
1538 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1539         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1540                         keyword, "detach");
1541 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1542         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1543                         identifier, NULL);
1544
1545 cmdline_parse_inst_t cmd_operate_detach_device = {
1546         .f = cmd_operate_detach_device_parsed,
1547         .data = NULL,
1548         .help_str = "device detach <identifier>:"
1549                 "(identifier: pci address or virtual dev name)",
1550         .tokens = {
1551                 (void *)&cmd_operate_detach_device_device,
1552                 (void *)&cmd_operate_detach_device_keyword,
1553                 (void *)&cmd_operate_detach_device_identifier,
1554                 NULL,
1555         },
1556 };
1557 /* *** configure speed for all ports *** */
1558 struct cmd_config_speed_all {
1559         cmdline_fixed_string_t port;
1560         cmdline_fixed_string_t keyword;
1561         cmdline_fixed_string_t all;
1562         cmdline_fixed_string_t item1;
1563         cmdline_fixed_string_t item2;
1564         cmdline_fixed_string_t value1;
1565         cmdline_fixed_string_t value2;
1566 };
1567
1568 static int
1569 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1570 {
1571
1572         int duplex;
1573
1574         if (!strcmp(duplexstr, "half")) {
1575                 duplex = ETH_LINK_HALF_DUPLEX;
1576         } else if (!strcmp(duplexstr, "full")) {
1577                 duplex = ETH_LINK_FULL_DUPLEX;
1578         } else if (!strcmp(duplexstr, "auto")) {
1579                 duplex = ETH_LINK_FULL_DUPLEX;
1580         } else {
1581                 printf("Unknown duplex parameter\n");
1582                 return -1;
1583         }
1584
1585         if (!strcmp(speedstr, "10")) {
1586                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1587                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1588         } else if (!strcmp(speedstr, "100")) {
1589                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1590                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1591         } else {
1592                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1593                         printf("Invalid speed/duplex parameters\n");
1594                         return -1;
1595                 }
1596                 if (!strcmp(speedstr, "1000")) {
1597                         *speed = ETH_LINK_SPEED_1G;
1598                 } else if (!strcmp(speedstr, "10000")) {
1599                         *speed = ETH_LINK_SPEED_10G;
1600                 } else if (!strcmp(speedstr, "25000")) {
1601                         *speed = ETH_LINK_SPEED_25G;
1602                 } else if (!strcmp(speedstr, "40000")) {
1603                         *speed = ETH_LINK_SPEED_40G;
1604                 } else if (!strcmp(speedstr, "50000")) {
1605                         *speed = ETH_LINK_SPEED_50G;
1606                 } else if (!strcmp(speedstr, "100000")) {
1607                         *speed = ETH_LINK_SPEED_100G;
1608                 } else if (!strcmp(speedstr, "auto")) {
1609                         *speed = ETH_LINK_SPEED_AUTONEG;
1610                 } else {
1611                         printf("Unknown speed parameter\n");
1612                         return -1;
1613                 }
1614         }
1615
1616         return 0;
1617 }
1618
1619 static void
1620 cmd_config_speed_all_parsed(void *parsed_result,
1621                         __attribute__((unused)) struct cmdline *cl,
1622                         __attribute__((unused)) void *data)
1623 {
1624         struct cmd_config_speed_all *res = parsed_result;
1625         uint32_t link_speed;
1626         portid_t pid;
1627
1628         if (!all_ports_stopped()) {
1629                 printf("Please stop all ports first\n");
1630                 return;
1631         }
1632
1633         if (parse_and_check_speed_duplex(res->value1, res->value2,
1634                         &link_speed) < 0)
1635                 return;
1636
1637         RTE_ETH_FOREACH_DEV(pid) {
1638                 ports[pid].dev_conf.link_speeds = link_speed;
1639         }
1640
1641         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1642 }
1643
1644 cmdline_parse_token_string_t cmd_config_speed_all_port =
1645         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1646 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1647         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1648                                                         "config");
1649 cmdline_parse_token_string_t cmd_config_speed_all_all =
1650         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1651 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1652         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1653 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1654         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1655                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1656 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1657         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1658 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1660                                                 "half#full#auto");
1661
1662 cmdline_parse_inst_t cmd_config_speed_all = {
1663         .f = cmd_config_speed_all_parsed,
1664         .data = NULL,
1665         .help_str = "port config all speed "
1666                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1667                                                         "half|full|auto",
1668         .tokens = {
1669                 (void *)&cmd_config_speed_all_port,
1670                 (void *)&cmd_config_speed_all_keyword,
1671                 (void *)&cmd_config_speed_all_all,
1672                 (void *)&cmd_config_speed_all_item1,
1673                 (void *)&cmd_config_speed_all_value1,
1674                 (void *)&cmd_config_speed_all_item2,
1675                 (void *)&cmd_config_speed_all_value2,
1676                 NULL,
1677         },
1678 };
1679
1680 /* *** configure speed for specific port *** */
1681 struct cmd_config_speed_specific {
1682         cmdline_fixed_string_t port;
1683         cmdline_fixed_string_t keyword;
1684         portid_t id;
1685         cmdline_fixed_string_t item1;
1686         cmdline_fixed_string_t item2;
1687         cmdline_fixed_string_t value1;
1688         cmdline_fixed_string_t value2;
1689 };
1690
1691 static void
1692 cmd_config_speed_specific_parsed(void *parsed_result,
1693                                 __attribute__((unused)) struct cmdline *cl,
1694                                 __attribute__((unused)) void *data)
1695 {
1696         struct cmd_config_speed_specific *res = parsed_result;
1697         uint32_t link_speed;
1698
1699         if (!all_ports_stopped()) {
1700                 printf("Please stop all ports first\n");
1701                 return;
1702         }
1703
1704         if (port_id_is_invalid(res->id, ENABLED_WARN))
1705                 return;
1706
1707         if (parse_and_check_speed_duplex(res->value1, res->value2,
1708                         &link_speed) < 0)
1709                 return;
1710
1711         ports[res->id].dev_conf.link_speeds = link_speed;
1712
1713         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1714 }
1715
1716
1717 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1719                                                                 "port");
1720 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1722                                                                 "config");
1723 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1724         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1725 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1726         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1727                                                                 "speed");
1728 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1729         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1730                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1731 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1733                                                                 "duplex");
1734 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1735         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1736                                                         "half#full#auto");
1737
1738 cmdline_parse_inst_t cmd_config_speed_specific = {
1739         .f = cmd_config_speed_specific_parsed,
1740         .data = NULL,
1741         .help_str = "port config <port_id> speed "
1742                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1743                                                         "half|full|auto",
1744         .tokens = {
1745                 (void *)&cmd_config_speed_specific_port,
1746                 (void *)&cmd_config_speed_specific_keyword,
1747                 (void *)&cmd_config_speed_specific_id,
1748                 (void *)&cmd_config_speed_specific_item1,
1749                 (void *)&cmd_config_speed_specific_value1,
1750                 (void *)&cmd_config_speed_specific_item2,
1751                 (void *)&cmd_config_speed_specific_value2,
1752                 NULL,
1753         },
1754 };
1755
1756 /* *** configure loopback for all ports *** */
1757 struct cmd_config_loopback_all {
1758         cmdline_fixed_string_t port;
1759         cmdline_fixed_string_t keyword;
1760         cmdline_fixed_string_t all;
1761         cmdline_fixed_string_t item;
1762         uint32_t mode;
1763 };
1764
1765 static void
1766 cmd_config_loopback_all_parsed(void *parsed_result,
1767                         __attribute__((unused)) struct cmdline *cl,
1768                         __attribute__((unused)) void *data)
1769 {
1770         struct cmd_config_loopback_all *res = parsed_result;
1771         portid_t pid;
1772
1773         if (!all_ports_stopped()) {
1774                 printf("Please stop all ports first\n");
1775                 return;
1776         }
1777
1778         RTE_ETH_FOREACH_DEV(pid) {
1779                 ports[pid].dev_conf.lpbk_mode = res->mode;
1780         }
1781
1782         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1783 }
1784
1785 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1786         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1787 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1788         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1789                                                         "config");
1790 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1792 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1793         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1794                                                         "loopback");
1795 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1796         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1797
1798 cmdline_parse_inst_t cmd_config_loopback_all = {
1799         .f = cmd_config_loopback_all_parsed,
1800         .data = NULL,
1801         .help_str = "port config all loopback <mode>",
1802         .tokens = {
1803                 (void *)&cmd_config_loopback_all_port,
1804                 (void *)&cmd_config_loopback_all_keyword,
1805                 (void *)&cmd_config_loopback_all_all,
1806                 (void *)&cmd_config_loopback_all_item,
1807                 (void *)&cmd_config_loopback_all_mode,
1808                 NULL,
1809         },
1810 };
1811
1812 /* *** configure loopback for specific port *** */
1813 struct cmd_config_loopback_specific {
1814         cmdline_fixed_string_t port;
1815         cmdline_fixed_string_t keyword;
1816         uint16_t port_id;
1817         cmdline_fixed_string_t item;
1818         uint32_t mode;
1819 };
1820
1821 static void
1822 cmd_config_loopback_specific_parsed(void *parsed_result,
1823                                 __attribute__((unused)) struct cmdline *cl,
1824                                 __attribute__((unused)) void *data)
1825 {
1826         struct cmd_config_loopback_specific *res = parsed_result;
1827
1828         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1829                 return;
1830
1831         if (!port_is_stopped(res->port_id)) {
1832                 printf("Please stop port %u first\n", res->port_id);
1833                 return;
1834         }
1835
1836         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1837
1838         cmd_reconfig_device_queue(res->port_id, 1, 1);
1839 }
1840
1841
1842 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1843         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1844                                                                 "port");
1845 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1847                                                                 "config");
1848 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1849         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1850                                                                 UINT16);
1851 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1853                                                                 "loopback");
1854 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1855         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1856                               UINT32);
1857
1858 cmdline_parse_inst_t cmd_config_loopback_specific = {
1859         .f = cmd_config_loopback_specific_parsed,
1860         .data = NULL,
1861         .help_str = "port config <port_id> loopback <mode>",
1862         .tokens = {
1863                 (void *)&cmd_config_loopback_specific_port,
1864                 (void *)&cmd_config_loopback_specific_keyword,
1865                 (void *)&cmd_config_loopback_specific_id,
1866                 (void *)&cmd_config_loopback_specific_item,
1867                 (void *)&cmd_config_loopback_specific_mode,
1868                 NULL,
1869         },
1870 };
1871
1872 /* *** configure txq/rxq, txd/rxd *** */
1873 struct cmd_config_rx_tx {
1874         cmdline_fixed_string_t port;
1875         cmdline_fixed_string_t keyword;
1876         cmdline_fixed_string_t all;
1877         cmdline_fixed_string_t name;
1878         uint16_t value;
1879 };
1880
1881 static void
1882 cmd_config_rx_tx_parsed(void *parsed_result,
1883                         __attribute__((unused)) struct cmdline *cl,
1884                         __attribute__((unused)) void *data)
1885 {
1886         struct cmd_config_rx_tx *res = parsed_result;
1887
1888         if (!all_ports_stopped()) {
1889                 printf("Please stop all ports first\n");
1890                 return;
1891         }
1892         if (!strcmp(res->name, "rxq")) {
1893                 if (!res->value && !nb_txq) {
1894                         printf("Warning: Either rx or tx queues should be non zero\n");
1895                         return;
1896                 }
1897                 if (check_nb_rxq(res->value) != 0)
1898                         return;
1899                 nb_rxq = res->value;
1900         }
1901         else if (!strcmp(res->name, "txq")) {
1902                 if (!res->value && !nb_rxq) {
1903                         printf("Warning: Either rx or tx queues should be non zero\n");
1904                         return;
1905                 }
1906                 if (check_nb_txq(res->value) != 0)
1907                         return;
1908                 nb_txq = res->value;
1909         }
1910         else if (!strcmp(res->name, "rxd")) {
1911                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1912                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1913                                         res->value, RTE_TEST_RX_DESC_MAX);
1914                         return;
1915                 }
1916                 nb_rxd = res->value;
1917         } else if (!strcmp(res->name, "txd")) {
1918                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1919                         printf("txd %d invalid - must be > 0 && <= %d\n",
1920                                         res->value, RTE_TEST_TX_DESC_MAX);
1921                         return;
1922                 }
1923                 nb_txd = res->value;
1924         } else {
1925                 printf("Unknown parameter\n");
1926                 return;
1927         }
1928
1929         fwd_config_setup();
1930
1931         init_port_config();
1932
1933         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1934 }
1935
1936 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1937         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1938 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1939         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1940 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1941         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1942 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1943         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1944                                                 "rxq#txq#rxd#txd");
1945 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1946         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1947
1948 cmdline_parse_inst_t cmd_config_rx_tx = {
1949         .f = cmd_config_rx_tx_parsed,
1950         .data = NULL,
1951         .help_str = "port config all rxq|txq|rxd|txd <value>",
1952         .tokens = {
1953                 (void *)&cmd_config_rx_tx_port,
1954                 (void *)&cmd_config_rx_tx_keyword,
1955                 (void *)&cmd_config_rx_tx_all,
1956                 (void *)&cmd_config_rx_tx_name,
1957                 (void *)&cmd_config_rx_tx_value,
1958                 NULL,
1959         },
1960 };
1961
1962 /* *** config max packet length *** */
1963 struct cmd_config_max_pkt_len_result {
1964         cmdline_fixed_string_t port;
1965         cmdline_fixed_string_t keyword;
1966         cmdline_fixed_string_t all;
1967         cmdline_fixed_string_t name;
1968         uint32_t value;
1969 };
1970
1971 static void
1972 cmd_config_max_pkt_len_parsed(void *parsed_result,
1973                                 __attribute__((unused)) struct cmdline *cl,
1974                                 __attribute__((unused)) void *data)
1975 {
1976         struct cmd_config_max_pkt_len_result *res = parsed_result;
1977         portid_t pid;
1978
1979         if (!all_ports_stopped()) {
1980                 printf("Please stop all ports first\n");
1981                 return;
1982         }
1983
1984         RTE_ETH_FOREACH_DEV(pid) {
1985                 struct rte_port *port = &ports[pid];
1986                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1987
1988                 if (!strcmp(res->name, "max-pkt-len")) {
1989                         if (res->value < RTE_ETHER_MIN_LEN) {
1990                                 printf("max-pkt-len can not be less than %d\n",
1991                                                 RTE_ETHER_MIN_LEN);
1992                                 return;
1993                         }
1994                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1995                                 return;
1996
1997                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1998                         if (res->value > RTE_ETHER_MAX_LEN)
1999                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2000                         else
2001                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2002                         port->dev_conf.rxmode.offloads = rx_offloads;
2003                 } else {
2004                         printf("Unknown parameter\n");
2005                         return;
2006                 }
2007         }
2008
2009         init_port_config();
2010
2011         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2012 }
2013
2014 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2015         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2016                                                                 "port");
2017 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2018         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2019                                                                 "config");
2020 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2021         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2022                                                                 "all");
2023 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2024         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2025                                                                 "max-pkt-len");
2026 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2027         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2028                                                                 UINT32);
2029
2030 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2031         .f = cmd_config_max_pkt_len_parsed,
2032         .data = NULL,
2033         .help_str = "port config all max-pkt-len <value>",
2034         .tokens = {
2035                 (void *)&cmd_config_max_pkt_len_port,
2036                 (void *)&cmd_config_max_pkt_len_keyword,
2037                 (void *)&cmd_config_max_pkt_len_all,
2038                 (void *)&cmd_config_max_pkt_len_name,
2039                 (void *)&cmd_config_max_pkt_len_value,
2040                 NULL,
2041         },
2042 };
2043
2044 /* *** configure port MTU *** */
2045 struct cmd_config_mtu_result {
2046         cmdline_fixed_string_t port;
2047         cmdline_fixed_string_t keyword;
2048         cmdline_fixed_string_t mtu;
2049         portid_t port_id;
2050         uint16_t value;
2051 };
2052
2053 static void
2054 cmd_config_mtu_parsed(void *parsed_result,
2055                       __attribute__((unused)) struct cmdline *cl,
2056                       __attribute__((unused)) void *data)
2057 {
2058         struct cmd_config_mtu_result *res = parsed_result;
2059
2060         if (res->value < RTE_ETHER_MIN_LEN) {
2061                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2062                 return;
2063         }
2064         port_mtu_set(res->port_id, res->value);
2065 }
2066
2067 cmdline_parse_token_string_t cmd_config_mtu_port =
2068         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2069                                  "port");
2070 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2071         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2072                                  "config");
2073 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2074         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2075                                  "mtu");
2076 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2077         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2078 cmdline_parse_token_num_t cmd_config_mtu_value =
2079         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2080
2081 cmdline_parse_inst_t cmd_config_mtu = {
2082         .f = cmd_config_mtu_parsed,
2083         .data = NULL,
2084         .help_str = "port config mtu <port_id> <value>",
2085         .tokens = {
2086                 (void *)&cmd_config_mtu_port,
2087                 (void *)&cmd_config_mtu_keyword,
2088                 (void *)&cmd_config_mtu_mtu,
2089                 (void *)&cmd_config_mtu_port_id,
2090                 (void *)&cmd_config_mtu_value,
2091                 NULL,
2092         },
2093 };
2094
2095 /* *** configure rx mode *** */
2096 struct cmd_config_rx_mode_flag {
2097         cmdline_fixed_string_t port;
2098         cmdline_fixed_string_t keyword;
2099         cmdline_fixed_string_t all;
2100         cmdline_fixed_string_t name;
2101         cmdline_fixed_string_t value;
2102 };
2103
2104 static void
2105 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2106                                 __attribute__((unused)) struct cmdline *cl,
2107                                 __attribute__((unused)) void *data)
2108 {
2109         struct cmd_config_rx_mode_flag *res = parsed_result;
2110
2111         if (!all_ports_stopped()) {
2112                 printf("Please stop all ports first\n");
2113                 return;
2114         }
2115
2116         if (!strcmp(res->name, "drop-en")) {
2117                 if (!strcmp(res->value, "on"))
2118                         rx_drop_en = 1;
2119                 else if (!strcmp(res->value, "off"))
2120                         rx_drop_en = 0;
2121                 else {
2122                         printf("Unknown parameter\n");
2123                         return;
2124                 }
2125         } else {
2126                 printf("Unknown parameter\n");
2127                 return;
2128         }
2129
2130         init_port_config();
2131
2132         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2133 }
2134
2135 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2136         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2137 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2138         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2139                                                                 "config");
2140 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2141         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2142 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2143         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2144                                         "drop-en");
2145 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2146         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2147                                                         "on#off");
2148
2149 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2150         .f = cmd_config_rx_mode_flag_parsed,
2151         .data = NULL,
2152         .help_str = "port config all drop-en on|off",
2153         .tokens = {
2154                 (void *)&cmd_config_rx_mode_flag_port,
2155                 (void *)&cmd_config_rx_mode_flag_keyword,
2156                 (void *)&cmd_config_rx_mode_flag_all,
2157                 (void *)&cmd_config_rx_mode_flag_name,
2158                 (void *)&cmd_config_rx_mode_flag_value,
2159                 NULL,
2160         },
2161 };
2162
2163 /* *** configure rss *** */
2164 struct cmd_config_rss {
2165         cmdline_fixed_string_t port;
2166         cmdline_fixed_string_t keyword;
2167         cmdline_fixed_string_t all;
2168         cmdline_fixed_string_t name;
2169         cmdline_fixed_string_t value;
2170 };
2171
2172 static void
2173 cmd_config_rss_parsed(void *parsed_result,
2174                         __attribute__((unused)) struct cmdline *cl,
2175                         __attribute__((unused)) void *data)
2176 {
2177         struct cmd_config_rss *res = parsed_result;
2178         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2179         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2180         int use_default = 0;
2181         int all_updated = 1;
2182         int diag;
2183         uint16_t i;
2184         int ret;
2185
2186         if (!strcmp(res->value, "all"))
2187                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2188                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2189                                         ETH_RSS_L2_PAYLOAD;
2190         else if (!strcmp(res->value, "ip"))
2191                 rss_conf.rss_hf = ETH_RSS_IP;
2192         else if (!strcmp(res->value, "udp"))
2193                 rss_conf.rss_hf = ETH_RSS_UDP;
2194         else if (!strcmp(res->value, "tcp"))
2195                 rss_conf.rss_hf = ETH_RSS_TCP;
2196         else if (!strcmp(res->value, "sctp"))
2197                 rss_conf.rss_hf = ETH_RSS_SCTP;
2198         else if (!strcmp(res->value, "ether"))
2199                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2200         else if (!strcmp(res->value, "port"))
2201                 rss_conf.rss_hf = ETH_RSS_PORT;
2202         else if (!strcmp(res->value, "vxlan"))
2203                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2204         else if (!strcmp(res->value, "geneve"))
2205                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2206         else if (!strcmp(res->value, "nvgre"))
2207                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2208         else if (!strcmp(res->value, "none"))
2209                 rss_conf.rss_hf = 0;
2210         else if (!strcmp(res->value, "default"))
2211                 use_default = 1;
2212         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2213                                                 atoi(res->value) < 64)
2214                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2215         else {
2216                 printf("Unknown parameter\n");
2217                 return;
2218         }
2219         rss_conf.rss_key = NULL;
2220         /* Update global configuration for RSS types. */
2221         RTE_ETH_FOREACH_DEV(i) {
2222                 struct rte_eth_rss_conf local_rss_conf;
2223
2224                 ret = eth_dev_info_get_print_err(i, &dev_info);
2225                 if (ret != 0)
2226                         return;
2227
2228                 if (use_default)
2229                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2230
2231                 local_rss_conf = rss_conf;
2232                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2233                         dev_info.flow_type_rss_offloads;
2234                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2235                         printf("Port %u modified RSS hash function based on hardware support,"
2236                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2237                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2238                 }
2239                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2240                 if (diag < 0) {
2241                         all_updated = 0;
2242                         printf("Configuration of RSS hash at ethernet port %d "
2243                                 "failed with error (%d): %s.\n",
2244                                 i, -diag, strerror(-diag));
2245                 }
2246         }
2247         if (all_updated && !use_default)
2248                 rss_hf = rss_conf.rss_hf;
2249 }
2250
2251 cmdline_parse_token_string_t cmd_config_rss_port =
2252         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2253 cmdline_parse_token_string_t cmd_config_rss_keyword =
2254         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2255 cmdline_parse_token_string_t cmd_config_rss_all =
2256         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2257 cmdline_parse_token_string_t cmd_config_rss_name =
2258         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2259 cmdline_parse_token_string_t cmd_config_rss_value =
2260         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2261
2262 cmdline_parse_inst_t cmd_config_rss = {
2263         .f = cmd_config_rss_parsed,
2264         .data = NULL,
2265         .help_str = "port config all rss "
2266                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2267         .tokens = {
2268                 (void *)&cmd_config_rss_port,
2269                 (void *)&cmd_config_rss_keyword,
2270                 (void *)&cmd_config_rss_all,
2271                 (void *)&cmd_config_rss_name,
2272                 (void *)&cmd_config_rss_value,
2273                 NULL,
2274         },
2275 };
2276
2277 /* *** configure rss hash key *** */
2278 struct cmd_config_rss_hash_key {
2279         cmdline_fixed_string_t port;
2280         cmdline_fixed_string_t config;
2281         portid_t port_id;
2282         cmdline_fixed_string_t rss_hash_key;
2283         cmdline_fixed_string_t rss_type;
2284         cmdline_fixed_string_t key;
2285 };
2286
2287 static uint8_t
2288 hexa_digit_to_value(char hexa_digit)
2289 {
2290         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2291                 return (uint8_t) (hexa_digit - '0');
2292         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2293                 return (uint8_t) ((hexa_digit - 'a') + 10);
2294         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2295                 return (uint8_t) ((hexa_digit - 'A') + 10);
2296         /* Invalid hexa digit */
2297         return 0xFF;
2298 }
2299
2300 static uint8_t
2301 parse_and_check_key_hexa_digit(char *key, int idx)
2302 {
2303         uint8_t hexa_v;
2304
2305         hexa_v = hexa_digit_to_value(key[idx]);
2306         if (hexa_v == 0xFF)
2307                 printf("invalid key: character %c at position %d is not a "
2308                        "valid hexa digit\n", key[idx], idx);
2309         return hexa_v;
2310 }
2311
2312 static void
2313 cmd_config_rss_hash_key_parsed(void *parsed_result,
2314                                __attribute__((unused)) struct cmdline *cl,
2315                                __attribute__((unused)) void *data)
2316 {
2317         struct cmd_config_rss_hash_key *res = parsed_result;
2318         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2319         uint8_t xdgt0;
2320         uint8_t xdgt1;
2321         int i;
2322         struct rte_eth_dev_info dev_info;
2323         uint8_t hash_key_size;
2324         uint32_t key_len;
2325         int ret;
2326
2327         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2328         if (ret != 0)
2329                 return;
2330
2331         if (dev_info.hash_key_size > 0 &&
2332                         dev_info.hash_key_size <= sizeof(hash_key))
2333                 hash_key_size = dev_info.hash_key_size;
2334         else {
2335                 printf("dev_info did not provide a valid hash key size\n");
2336                 return;
2337         }
2338         /* Check the length of the RSS hash key */
2339         key_len = strlen(res->key);
2340         if (key_len != (hash_key_size * 2)) {
2341                 printf("key length: %d invalid - key must be a string of %d"
2342                            " hexa-decimal numbers\n",
2343                            (int) key_len, hash_key_size * 2);
2344                 return;
2345         }
2346         /* Translate RSS hash key into binary representation */
2347         for (i = 0; i < hash_key_size; i++) {
2348                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2349                 if (xdgt0 == 0xFF)
2350                         return;
2351                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2352                 if (xdgt1 == 0xFF)
2353                         return;
2354                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2355         }
2356         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2357                         hash_key_size);
2358 }
2359
2360 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2361         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2362 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2363         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2364                                  "config");
2365 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2366         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2367 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2368         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2369                                  rss_hash_key, "rss-hash-key");
2370 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2371         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2372                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2373                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2374                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2375                                  "ipv6-tcp-ex#ipv6-udp-ex");
2376 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2377         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2378
2379 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2380         .f = cmd_config_rss_hash_key_parsed,
2381         .data = NULL,
2382         .help_str = "port config <port_id> rss-hash-key "
2383                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2384                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2385                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2386                 "<string of hex digits (variable length, NIC dependent)>",
2387         .tokens = {
2388                 (void *)&cmd_config_rss_hash_key_port,
2389                 (void *)&cmd_config_rss_hash_key_config,
2390                 (void *)&cmd_config_rss_hash_key_port_id,
2391                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2392                 (void *)&cmd_config_rss_hash_key_rss_type,
2393                 (void *)&cmd_config_rss_hash_key_value,
2394                 NULL,
2395         },
2396 };
2397
2398 /* *** configure port rxq/txq ring size *** */
2399 struct cmd_config_rxtx_ring_size {
2400         cmdline_fixed_string_t port;
2401         cmdline_fixed_string_t config;
2402         portid_t portid;
2403         cmdline_fixed_string_t rxtxq;
2404         uint16_t qid;
2405         cmdline_fixed_string_t rsize;
2406         uint16_t size;
2407 };
2408
2409 static void
2410 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2411                                  __attribute__((unused)) struct cmdline *cl,
2412                                  __attribute__((unused)) void *data)
2413 {
2414         struct cmd_config_rxtx_ring_size *res = parsed_result;
2415         struct rte_port *port;
2416         uint8_t isrx;
2417
2418         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2419                 return;
2420
2421         if (res->portid == (portid_t)RTE_PORT_ALL) {
2422                 printf("Invalid port id\n");
2423                 return;
2424         }
2425
2426         port = &ports[res->portid];
2427
2428         if (!strcmp(res->rxtxq, "rxq"))
2429                 isrx = 1;
2430         else if (!strcmp(res->rxtxq, "txq"))
2431                 isrx = 0;
2432         else {
2433                 printf("Unknown parameter\n");
2434                 return;
2435         }
2436
2437         if (isrx && rx_queue_id_is_invalid(res->qid))
2438                 return;
2439         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2440                 return;
2441
2442         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2443                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2444                        rx_free_thresh);
2445                 return;
2446         }
2447
2448         if (isrx)
2449                 port->nb_rx_desc[res->qid] = res->size;
2450         else
2451                 port->nb_tx_desc[res->qid] = res->size;
2452
2453         cmd_reconfig_device_queue(res->portid, 0, 1);
2454 }
2455
2456 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2457         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2458                                  port, "port");
2459 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2460         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2461                                  config, "config");
2462 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2463         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2464                                  portid, UINT16);
2465 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2466         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2467                                  rxtxq, "rxq#txq");
2468 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2469         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2470                               qid, UINT16);
2471 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2472         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2473                                  rsize, "ring_size");
2474 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2475         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2476                               size, UINT16);
2477
2478 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2479         .f = cmd_config_rxtx_ring_size_parsed,
2480         .data = NULL,
2481         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2482         .tokens = {
2483                 (void *)&cmd_config_rxtx_ring_size_port,
2484                 (void *)&cmd_config_rxtx_ring_size_config,
2485                 (void *)&cmd_config_rxtx_ring_size_portid,
2486                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2487                 (void *)&cmd_config_rxtx_ring_size_qid,
2488                 (void *)&cmd_config_rxtx_ring_size_rsize,
2489                 (void *)&cmd_config_rxtx_ring_size_size,
2490                 NULL,
2491         },
2492 };
2493
2494 /* *** configure port rxq/txq start/stop *** */
2495 struct cmd_config_rxtx_queue {
2496         cmdline_fixed_string_t port;
2497         portid_t portid;
2498         cmdline_fixed_string_t rxtxq;
2499         uint16_t qid;
2500         cmdline_fixed_string_t opname;
2501 };
2502
2503 static void
2504 cmd_config_rxtx_queue_parsed(void *parsed_result,
2505                         __attribute__((unused)) struct cmdline *cl,
2506                         __attribute__((unused)) void *data)
2507 {
2508         struct cmd_config_rxtx_queue *res = parsed_result;
2509         uint8_t isrx;
2510         uint8_t isstart;
2511         int ret = 0;
2512
2513         if (test_done == 0) {
2514                 printf("Please stop forwarding first\n");
2515                 return;
2516         }
2517
2518         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2519                 return;
2520
2521         if (port_is_started(res->portid) != 1) {
2522                 printf("Please start port %u first\n", res->portid);
2523                 return;
2524         }
2525
2526         if (!strcmp(res->rxtxq, "rxq"))
2527                 isrx = 1;
2528         else if (!strcmp(res->rxtxq, "txq"))
2529                 isrx = 0;
2530         else {
2531                 printf("Unknown parameter\n");
2532                 return;
2533         }
2534
2535         if (isrx && rx_queue_id_is_invalid(res->qid))
2536                 return;
2537         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2538                 return;
2539
2540         if (!strcmp(res->opname, "start"))
2541                 isstart = 1;
2542         else if (!strcmp(res->opname, "stop"))
2543                 isstart = 0;
2544         else {
2545                 printf("Unknown parameter\n");
2546                 return;
2547         }
2548
2549         if (isstart && isrx)
2550                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2551         else if (!isstart && isrx)
2552                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2553         else if (isstart && !isrx)
2554                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2555         else
2556                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2557
2558         if (ret == -ENOTSUP)
2559                 printf("Function not supported in PMD driver\n");
2560 }
2561
2562 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2563         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2564 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2565         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2566 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2567         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2568 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2569         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2570 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2571         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2572                                                 "start#stop");
2573
2574 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2575         .f = cmd_config_rxtx_queue_parsed,
2576         .data = NULL,
2577         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2578         .tokens = {
2579                 (void *)&cmd_config_rxtx_queue_port,
2580                 (void *)&cmd_config_rxtx_queue_portid,
2581                 (void *)&cmd_config_rxtx_queue_rxtxq,
2582                 (void *)&cmd_config_rxtx_queue_qid,
2583                 (void *)&cmd_config_rxtx_queue_opname,
2584                 NULL,
2585         },
2586 };
2587
2588 /* *** configure port rxq/txq deferred start on/off *** */
2589 struct cmd_config_deferred_start_rxtx_queue {
2590         cmdline_fixed_string_t port;
2591         portid_t port_id;
2592         cmdline_fixed_string_t rxtxq;
2593         uint16_t qid;
2594         cmdline_fixed_string_t opname;
2595         cmdline_fixed_string_t state;
2596 };
2597
2598 static void
2599 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2600                         __attribute__((unused)) struct cmdline *cl,
2601                         __attribute__((unused)) void *data)
2602 {
2603         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2604         struct rte_port *port;
2605         uint8_t isrx;
2606         uint8_t ison;
2607         uint8_t needreconfig = 0;
2608
2609         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2610                 return;
2611
2612         if (port_is_started(res->port_id) != 0) {
2613                 printf("Please stop port %u first\n", res->port_id);
2614                 return;
2615         }
2616
2617         port = &ports[res->port_id];
2618
2619         isrx = !strcmp(res->rxtxq, "rxq");
2620
2621         if (isrx && rx_queue_id_is_invalid(res->qid))
2622                 return;
2623         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2624                 return;
2625
2626         ison = !strcmp(res->state, "on");
2627
2628         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2629                 port->rx_conf[res->qid].rx_deferred_start = ison;
2630                 needreconfig = 1;
2631         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2632                 port->tx_conf[res->qid].tx_deferred_start = ison;
2633                 needreconfig = 1;
2634         }
2635
2636         if (needreconfig)
2637                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2638 }
2639
2640 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2641         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2642                                                 port, "port");
2643 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2644         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2645                                                 port_id, UINT16);
2646 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2647         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2648                                                 rxtxq, "rxq#txq");
2649 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2650         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2651                                                 qid, UINT16);
2652 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2653         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2654                                                 opname, "deferred_start");
2655 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2656         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2657                                                 state, "on#off");
2658
2659 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2660         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2661         .data = NULL,
2662         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2663         .tokens = {
2664                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2665                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2666                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2667                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2668                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2669                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2670                 NULL,
2671         },
2672 };
2673
2674 /* *** configure port rxq/txq setup *** */
2675 struct cmd_setup_rxtx_queue {
2676         cmdline_fixed_string_t port;
2677         portid_t portid;
2678         cmdline_fixed_string_t rxtxq;
2679         uint16_t qid;
2680         cmdline_fixed_string_t setup;
2681 };
2682
2683 /* Common CLI fields for queue setup */
2684 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2685         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2686 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2687         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2688 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2689         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2690 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2691         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2692 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2693         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2694
2695 static void
2696 cmd_setup_rxtx_queue_parsed(
2697         void *parsed_result,
2698         __attribute__((unused)) struct cmdline *cl,
2699         __attribute__((unused)) void *data)
2700 {
2701         struct cmd_setup_rxtx_queue *res = parsed_result;
2702         struct rte_port *port;
2703         struct rte_mempool *mp;
2704         unsigned int socket_id;
2705         uint8_t isrx = 0;
2706         int ret;
2707
2708         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2709                 return;
2710
2711         if (res->portid == (portid_t)RTE_PORT_ALL) {
2712                 printf("Invalid port id\n");
2713                 return;
2714         }
2715
2716         if (!strcmp(res->rxtxq, "rxq"))
2717                 isrx = 1;
2718         else if (!strcmp(res->rxtxq, "txq"))
2719                 isrx = 0;
2720         else {
2721                 printf("Unknown parameter\n");
2722                 return;
2723         }
2724
2725         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2726                 printf("Invalid rx queue\n");
2727                 return;
2728         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2729                 printf("Invalid tx queue\n");
2730                 return;
2731         }
2732
2733         port = &ports[res->portid];
2734         if (isrx) {
2735                 socket_id = rxring_numa[res->portid];
2736                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2737                         socket_id = port->socket_id;
2738
2739                 mp = mbuf_pool_find(socket_id);
2740                 if (mp == NULL) {
2741                         printf("Failed to setup RX queue: "
2742                                 "No mempool allocation"
2743                                 " on the socket %d\n",
2744                                 rxring_numa[res->portid]);
2745                         return;
2746                 }
2747                 ret = rte_eth_rx_queue_setup(res->portid,
2748                                              res->qid,
2749                                              port->nb_rx_desc[res->qid],
2750                                              socket_id,
2751                                              &port->rx_conf[res->qid],
2752                                              mp);
2753                 if (ret)
2754                         printf("Failed to setup RX queue\n");
2755         } else {
2756                 socket_id = txring_numa[res->portid];
2757                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2758                         socket_id = port->socket_id;
2759
2760                 ret = rte_eth_tx_queue_setup(res->portid,
2761                                              res->qid,
2762                                              port->nb_tx_desc[res->qid],
2763                                              socket_id,
2764                                              &port->tx_conf[res->qid]);
2765                 if (ret)
2766                         printf("Failed to setup TX queue\n");
2767         }
2768 }
2769
2770 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2771         .f = cmd_setup_rxtx_queue_parsed,
2772         .data = NULL,
2773         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2774         .tokens = {
2775                 (void *)&cmd_setup_rxtx_queue_port,
2776                 (void *)&cmd_setup_rxtx_queue_portid,
2777                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2778                 (void *)&cmd_setup_rxtx_queue_qid,
2779                 (void *)&cmd_setup_rxtx_queue_setup,
2780                 NULL,
2781         },
2782 };
2783
2784
2785 /* *** Configure RSS RETA *** */
2786 struct cmd_config_rss_reta {
2787         cmdline_fixed_string_t port;
2788         cmdline_fixed_string_t keyword;
2789         portid_t port_id;
2790         cmdline_fixed_string_t name;
2791         cmdline_fixed_string_t list_name;
2792         cmdline_fixed_string_t list_of_items;
2793 };
2794
2795 static int
2796 parse_reta_config(const char *str,
2797                   struct rte_eth_rss_reta_entry64 *reta_conf,
2798                   uint16_t nb_entries)
2799 {
2800         int i;
2801         unsigned size;
2802         uint16_t hash_index, idx, shift;
2803         uint16_t nb_queue;
2804         char s[256];
2805         const char *p, *p0 = str;
2806         char *end;
2807         enum fieldnames {
2808                 FLD_HASH_INDEX = 0,
2809                 FLD_QUEUE,
2810                 _NUM_FLD
2811         };
2812         unsigned long int_fld[_NUM_FLD];
2813         char *str_fld[_NUM_FLD];
2814
2815         while ((p = strchr(p0,'(')) != NULL) {
2816                 ++p;
2817                 if((p0 = strchr(p,')')) == NULL)
2818                         return -1;
2819
2820                 size = p0 - p;
2821                 if(size >= sizeof(s))
2822                         return -1;
2823
2824                 snprintf(s, sizeof(s), "%.*s", size, p);
2825                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2826                         return -1;
2827                 for (i = 0; i < _NUM_FLD; i++) {
2828                         errno = 0;
2829                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2830                         if (errno != 0 || end == str_fld[i] ||
2831                                         int_fld[i] > 65535)
2832                                 return -1;
2833                 }
2834
2835                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2836                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2837
2838                 if (hash_index >= nb_entries) {
2839                         printf("Invalid RETA hash index=%d\n", hash_index);
2840                         return -1;
2841                 }
2842
2843                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2844                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2845                 reta_conf[idx].mask |= (1ULL << shift);
2846                 reta_conf[idx].reta[shift] = nb_queue;
2847         }
2848
2849         return 0;
2850 }
2851
2852 static void
2853 cmd_set_rss_reta_parsed(void *parsed_result,
2854                         __attribute__((unused)) struct cmdline *cl,
2855                         __attribute__((unused)) void *data)
2856 {
2857         int ret;
2858         struct rte_eth_dev_info dev_info;
2859         struct rte_eth_rss_reta_entry64 reta_conf[8];
2860         struct cmd_config_rss_reta *res = parsed_result;
2861
2862         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2863         if (ret != 0)
2864                 return;
2865
2866         if (dev_info.reta_size == 0) {
2867                 printf("Redirection table size is 0 which is "
2868                                         "invalid for RSS\n");
2869                 return;
2870         } else
2871                 printf("The reta size of port %d is %u\n",
2872                         res->port_id, dev_info.reta_size);
2873         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2874                 printf("Currently do not support more than %u entries of "
2875                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2876                 return;
2877         }
2878
2879         memset(reta_conf, 0, sizeof(reta_conf));
2880         if (!strcmp(res->list_name, "reta")) {
2881                 if (parse_reta_config(res->list_of_items, reta_conf,
2882                                                 dev_info.reta_size)) {
2883                         printf("Invalid RSS Redirection Table "
2884                                         "config entered\n");
2885                         return;
2886                 }
2887                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2888                                 reta_conf, dev_info.reta_size);
2889                 if (ret != 0)
2890                         printf("Bad redirection table parameter, "
2891                                         "return code = %d \n", ret);
2892         }
2893 }
2894
2895 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2896         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2897 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2898         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2899 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2900         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2901 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2902         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2903 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2904         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2905 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2906         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2907                                  NULL);
2908 cmdline_parse_inst_t cmd_config_rss_reta = {
2909         .f = cmd_set_rss_reta_parsed,
2910         .data = NULL,
2911         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2912         .tokens = {
2913                 (void *)&cmd_config_rss_reta_port,
2914                 (void *)&cmd_config_rss_reta_keyword,
2915                 (void *)&cmd_config_rss_reta_port_id,
2916                 (void *)&cmd_config_rss_reta_name,
2917                 (void *)&cmd_config_rss_reta_list_name,
2918                 (void *)&cmd_config_rss_reta_list_of_items,
2919                 NULL,
2920         },
2921 };
2922
2923 /* *** SHOW PORT RETA INFO *** */
2924 struct cmd_showport_reta {
2925         cmdline_fixed_string_t show;
2926         cmdline_fixed_string_t port;
2927         portid_t port_id;
2928         cmdline_fixed_string_t rss;
2929         cmdline_fixed_string_t reta;
2930         uint16_t size;
2931         cmdline_fixed_string_t list_of_items;
2932 };
2933
2934 static int
2935 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2936                            uint16_t nb_entries,
2937                            char *str)
2938 {
2939         uint32_t size;
2940         const char *p, *p0 = str;
2941         char s[256];
2942         char *end;
2943         char *str_fld[8];
2944         uint16_t i;
2945         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2946                         RTE_RETA_GROUP_SIZE;
2947         int ret;
2948
2949         p = strchr(p0, '(');
2950         if (p == NULL)
2951                 return -1;
2952         p++;
2953         p0 = strchr(p, ')');
2954         if (p0 == NULL)
2955                 return -1;
2956         size = p0 - p;
2957         if (size >= sizeof(s)) {
2958                 printf("The string size exceeds the internal buffer size\n");
2959                 return -1;
2960         }
2961         snprintf(s, sizeof(s), "%.*s", size, p);
2962         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2963         if (ret <= 0 || ret != num) {
2964                 printf("The bits of masks do not match the number of "
2965                                         "reta entries: %u\n", num);
2966                 return -1;
2967         }
2968         for (i = 0; i < ret; i++)
2969                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2970
2971         return 0;
2972 }
2973
2974 static void
2975 cmd_showport_reta_parsed(void *parsed_result,
2976                          __attribute__((unused)) struct cmdline *cl,
2977                          __attribute__((unused)) void *data)
2978 {
2979         struct cmd_showport_reta *res = parsed_result;
2980         struct rte_eth_rss_reta_entry64 reta_conf[8];
2981         struct rte_eth_dev_info dev_info;
2982         uint16_t max_reta_size;
2983         int ret;
2984
2985         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2986         if (ret != 0)
2987                 return;
2988
2989         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2990         if (res->size == 0 || res->size > max_reta_size) {
2991                 printf("Invalid redirection table size: %u (1-%u)\n",
2992                         res->size, max_reta_size);
2993                 return;
2994         }
2995
2996         memset(reta_conf, 0, sizeof(reta_conf));
2997         if (showport_parse_reta_config(reta_conf, res->size,
2998                                 res->list_of_items) < 0) {
2999                 printf("Invalid string: %s for reta masks\n",
3000                                         res->list_of_items);
3001                 return;
3002         }
3003         port_rss_reta_info(res->port_id, reta_conf, res->size);
3004 }
3005
3006 cmdline_parse_token_string_t cmd_showport_reta_show =
3007         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3008 cmdline_parse_token_string_t cmd_showport_reta_port =
3009         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3010 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3011         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3012 cmdline_parse_token_string_t cmd_showport_reta_rss =
3013         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3014 cmdline_parse_token_string_t cmd_showport_reta_reta =
3015         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3016 cmdline_parse_token_num_t cmd_showport_reta_size =
3017         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3018 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3019         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3020                                         list_of_items, NULL);
3021
3022 cmdline_parse_inst_t cmd_showport_reta = {
3023         .f = cmd_showport_reta_parsed,
3024         .data = NULL,
3025         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3026         .tokens = {
3027                 (void *)&cmd_showport_reta_show,
3028                 (void *)&cmd_showport_reta_port,
3029                 (void *)&cmd_showport_reta_port_id,
3030                 (void *)&cmd_showport_reta_rss,
3031                 (void *)&cmd_showport_reta_reta,
3032                 (void *)&cmd_showport_reta_size,
3033                 (void *)&cmd_showport_reta_list_of_items,
3034                 NULL,
3035         },
3036 };
3037
3038 /* *** Show RSS hash configuration *** */
3039 struct cmd_showport_rss_hash {
3040         cmdline_fixed_string_t show;
3041         cmdline_fixed_string_t port;
3042         portid_t port_id;
3043         cmdline_fixed_string_t rss_hash;
3044         cmdline_fixed_string_t rss_type;
3045         cmdline_fixed_string_t key; /* optional argument */
3046 };
3047
3048 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3049                                 __attribute__((unused)) struct cmdline *cl,
3050                                 void *show_rss_key)
3051 {
3052         struct cmd_showport_rss_hash *res = parsed_result;
3053
3054         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3055 }
3056
3057 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3058         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3059 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3060         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3061 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3062         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3063 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3064         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3065                                  "rss-hash");
3066 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3067         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3068
3069 cmdline_parse_inst_t cmd_showport_rss_hash = {
3070         .f = cmd_showport_rss_hash_parsed,
3071         .data = NULL,
3072         .help_str = "show port <port_id> rss-hash",
3073         .tokens = {
3074                 (void *)&cmd_showport_rss_hash_show,
3075                 (void *)&cmd_showport_rss_hash_port,
3076                 (void *)&cmd_showport_rss_hash_port_id,
3077                 (void *)&cmd_showport_rss_hash_rss_hash,
3078                 NULL,
3079         },
3080 };
3081
3082 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3083         .f = cmd_showport_rss_hash_parsed,
3084         .data = (void *)1,
3085         .help_str = "show port <port_id> rss-hash key",
3086         .tokens = {
3087                 (void *)&cmd_showport_rss_hash_show,
3088                 (void *)&cmd_showport_rss_hash_port,
3089                 (void *)&cmd_showport_rss_hash_port_id,
3090                 (void *)&cmd_showport_rss_hash_rss_hash,
3091                 (void *)&cmd_showport_rss_hash_rss_key,
3092                 NULL,
3093         },
3094 };
3095
3096 /* *** Configure DCB *** */
3097 struct cmd_config_dcb {
3098         cmdline_fixed_string_t port;
3099         cmdline_fixed_string_t config;
3100         portid_t port_id;
3101         cmdline_fixed_string_t dcb;
3102         cmdline_fixed_string_t vt;
3103         cmdline_fixed_string_t vt_en;
3104         uint8_t num_tcs;
3105         cmdline_fixed_string_t pfc;
3106         cmdline_fixed_string_t pfc_en;
3107 };
3108
3109 static void
3110 cmd_config_dcb_parsed(void *parsed_result,
3111                         __attribute__((unused)) struct cmdline *cl,
3112                         __attribute__((unused)) void *data)
3113 {
3114         struct cmd_config_dcb *res = parsed_result;
3115         portid_t port_id = res->port_id;
3116         struct rte_port *port;
3117         uint8_t pfc_en;
3118         int ret;
3119
3120         port = &ports[port_id];
3121         /** Check if the port is not started **/
3122         if (port->port_status != RTE_PORT_STOPPED) {
3123                 printf("Please stop port %d first\n", port_id);
3124                 return;
3125         }
3126
3127         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3128                 printf("The invalid number of traffic class,"
3129                         " only 4 or 8 allowed.\n");
3130                 return;
3131         }
3132
3133         if (nb_fwd_lcores < res->num_tcs) {
3134                 printf("nb_cores shouldn't be less than number of TCs.\n");
3135                 return;
3136         }
3137         if (!strncmp(res->pfc_en, "on", 2))
3138                 pfc_en = 1;
3139         else
3140                 pfc_en = 0;
3141
3142         /* DCB in VT mode */
3143         if (!strncmp(res->vt_en, "on", 2))
3144                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3145                                 (enum rte_eth_nb_tcs)res->num_tcs,
3146                                 pfc_en);
3147         else
3148                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3149                                 (enum rte_eth_nb_tcs)res->num_tcs,
3150                                 pfc_en);
3151
3152
3153         if (ret != 0) {
3154                 printf("Cannot initialize network ports.\n");
3155                 return;
3156         }
3157
3158         cmd_reconfig_device_queue(port_id, 1, 1);
3159 }
3160
3161 cmdline_parse_token_string_t cmd_config_dcb_port =
3162         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3163 cmdline_parse_token_string_t cmd_config_dcb_config =
3164         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3165 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3166         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3167 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3168         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3169 cmdline_parse_token_string_t cmd_config_dcb_vt =
3170         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3171 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3172         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3173 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3174         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3175 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3176         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3177 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3178         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3179
3180 cmdline_parse_inst_t cmd_config_dcb = {
3181         .f = cmd_config_dcb_parsed,
3182         .data = NULL,
3183         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3184         .tokens = {
3185                 (void *)&cmd_config_dcb_port,
3186                 (void *)&cmd_config_dcb_config,
3187                 (void *)&cmd_config_dcb_port_id,
3188                 (void *)&cmd_config_dcb_dcb,
3189                 (void *)&cmd_config_dcb_vt,
3190                 (void *)&cmd_config_dcb_vt_en,
3191                 (void *)&cmd_config_dcb_num_tcs,
3192                 (void *)&cmd_config_dcb_pfc,
3193                 (void *)&cmd_config_dcb_pfc_en,
3194                 NULL,
3195         },
3196 };
3197
3198 /* *** configure number of packets per burst *** */
3199 struct cmd_config_burst {
3200         cmdline_fixed_string_t port;
3201         cmdline_fixed_string_t keyword;
3202         cmdline_fixed_string_t all;
3203         cmdline_fixed_string_t name;
3204         uint16_t value;
3205 };
3206
3207 static void
3208 cmd_config_burst_parsed(void *parsed_result,
3209                         __attribute__((unused)) struct cmdline *cl,
3210                         __attribute__((unused)) void *data)
3211 {
3212         struct cmd_config_burst *res = parsed_result;
3213         struct rte_eth_dev_info dev_info;
3214         uint16_t rec_nb_pkts;
3215         int ret;
3216
3217         if (!all_ports_stopped()) {
3218                 printf("Please stop all ports first\n");
3219                 return;
3220         }
3221
3222         if (!strcmp(res->name, "burst")) {
3223                 if (res->value == 0) {
3224                         /* If user gives a value of zero, query the PMD for
3225                          * its recommended Rx burst size. Testpmd uses a single
3226                          * size for all ports, so assume all ports are the same
3227                          * NIC model and use the values from Port 0.
3228                          */
3229                         ret = eth_dev_info_get_print_err(0, &dev_info);
3230                         if (ret != 0)
3231                                 return;
3232
3233                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3234
3235                         if (rec_nb_pkts == 0) {
3236                                 printf("PMD does not recommend a burst size.\n"
3237                                         "User provided value must be between"
3238                                         " 1 and %d\n", MAX_PKT_BURST);
3239                                 return;
3240                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3241                                 printf("PMD recommended burst size of %d"
3242                                         " exceeds maximum value of %d\n",
3243                                         rec_nb_pkts, MAX_PKT_BURST);
3244                                 return;
3245                         }
3246                         printf("Using PMD-provided burst value of %d\n",
3247                                 rec_nb_pkts);
3248                         nb_pkt_per_burst = rec_nb_pkts;
3249                 } else if (res->value > MAX_PKT_BURST) {
3250                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3251                         return;
3252                 } else
3253                         nb_pkt_per_burst = res->value;
3254         } else {
3255                 printf("Unknown parameter\n");
3256                 return;
3257         }
3258
3259         init_port_config();
3260
3261         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3262 }
3263
3264 cmdline_parse_token_string_t cmd_config_burst_port =
3265         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3266 cmdline_parse_token_string_t cmd_config_burst_keyword =
3267         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3268 cmdline_parse_token_string_t cmd_config_burst_all =
3269         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3270 cmdline_parse_token_string_t cmd_config_burst_name =
3271         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3272 cmdline_parse_token_num_t cmd_config_burst_value =
3273         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3274
3275 cmdline_parse_inst_t cmd_config_burst = {
3276         .f = cmd_config_burst_parsed,
3277         .data = NULL,
3278         .help_str = "port config all burst <value>",
3279         .tokens = {
3280                 (void *)&cmd_config_burst_port,
3281                 (void *)&cmd_config_burst_keyword,
3282                 (void *)&cmd_config_burst_all,
3283                 (void *)&cmd_config_burst_name,
3284                 (void *)&cmd_config_burst_value,
3285                 NULL,
3286         },
3287 };
3288
3289 /* *** configure rx/tx queues *** */
3290 struct cmd_config_thresh {
3291         cmdline_fixed_string_t port;
3292         cmdline_fixed_string_t keyword;
3293         cmdline_fixed_string_t all;
3294         cmdline_fixed_string_t name;
3295         uint8_t value;
3296 };
3297
3298 static void
3299 cmd_config_thresh_parsed(void *parsed_result,
3300                         __attribute__((unused)) struct cmdline *cl,
3301                         __attribute__((unused)) void *data)
3302 {
3303         struct cmd_config_thresh *res = parsed_result;
3304
3305         if (!all_ports_stopped()) {
3306                 printf("Please stop all ports first\n");
3307                 return;
3308         }
3309
3310         if (!strcmp(res->name, "txpt"))
3311                 tx_pthresh = res->value;
3312         else if(!strcmp(res->name, "txht"))
3313                 tx_hthresh = res->value;
3314         else if(!strcmp(res->name, "txwt"))
3315                 tx_wthresh = res->value;
3316         else if(!strcmp(res->name, "rxpt"))
3317                 rx_pthresh = res->value;
3318         else if(!strcmp(res->name, "rxht"))
3319                 rx_hthresh = res->value;
3320         else if(!strcmp(res->name, "rxwt"))
3321                 rx_wthresh = res->value;
3322         else {
3323                 printf("Unknown parameter\n");
3324                 return;
3325         }
3326
3327         init_port_config();
3328
3329         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3330 }
3331
3332 cmdline_parse_token_string_t cmd_config_thresh_port =
3333         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3334 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3335         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3336 cmdline_parse_token_string_t cmd_config_thresh_all =
3337         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3338 cmdline_parse_token_string_t cmd_config_thresh_name =
3339         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3340                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3341 cmdline_parse_token_num_t cmd_config_thresh_value =
3342         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3343
3344 cmdline_parse_inst_t cmd_config_thresh = {
3345         .f = cmd_config_thresh_parsed,
3346         .data = NULL,
3347         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3348         .tokens = {
3349                 (void *)&cmd_config_thresh_port,
3350                 (void *)&cmd_config_thresh_keyword,
3351                 (void *)&cmd_config_thresh_all,
3352                 (void *)&cmd_config_thresh_name,
3353                 (void *)&cmd_config_thresh_value,
3354                 NULL,
3355         },
3356 };
3357
3358 /* *** configure free/rs threshold *** */
3359 struct cmd_config_threshold {
3360         cmdline_fixed_string_t port;
3361         cmdline_fixed_string_t keyword;
3362         cmdline_fixed_string_t all;
3363         cmdline_fixed_string_t name;
3364         uint16_t value;
3365 };
3366
3367 static void
3368 cmd_config_threshold_parsed(void *parsed_result,
3369                         __attribute__((unused)) struct cmdline *cl,
3370                         __attribute__((unused)) void *data)
3371 {
3372         struct cmd_config_threshold *res = parsed_result;
3373
3374         if (!all_ports_stopped()) {
3375                 printf("Please stop all ports first\n");
3376                 return;
3377         }
3378
3379         if (!strcmp(res->name, "txfreet"))
3380                 tx_free_thresh = res->value;
3381         else if (!strcmp(res->name, "txrst"))
3382                 tx_rs_thresh = res->value;
3383         else if (!strcmp(res->name, "rxfreet"))
3384                 rx_free_thresh = res->value;
3385         else {
3386                 printf("Unknown parameter\n");
3387                 return;
3388         }
3389
3390         init_port_config();
3391
3392         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3393 }
3394
3395 cmdline_parse_token_string_t cmd_config_threshold_port =
3396         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3397 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3398         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3399                                                                 "config");
3400 cmdline_parse_token_string_t cmd_config_threshold_all =
3401         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3402 cmdline_parse_token_string_t cmd_config_threshold_name =
3403         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3404                                                 "txfreet#txrst#rxfreet");
3405 cmdline_parse_token_num_t cmd_config_threshold_value =
3406         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3407
3408 cmdline_parse_inst_t cmd_config_threshold = {
3409         .f = cmd_config_threshold_parsed,
3410         .data = NULL,
3411         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3412         .tokens = {
3413                 (void *)&cmd_config_threshold_port,
3414                 (void *)&cmd_config_threshold_keyword,
3415                 (void *)&cmd_config_threshold_all,
3416                 (void *)&cmd_config_threshold_name,
3417                 (void *)&cmd_config_threshold_value,
3418                 NULL,
3419         },
3420 };
3421
3422 /* *** stop *** */
3423 struct cmd_stop_result {
3424         cmdline_fixed_string_t stop;
3425 };
3426
3427 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3428                             __attribute__((unused)) struct cmdline *cl,
3429                             __attribute__((unused)) void *data)
3430 {
3431         stop_packet_forwarding();
3432 }
3433
3434 cmdline_parse_token_string_t cmd_stop_stop =
3435         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3436
3437 cmdline_parse_inst_t cmd_stop = {
3438         .f = cmd_stop_parsed,
3439         .data = NULL,
3440         .help_str = "stop: Stop packet forwarding",
3441         .tokens = {
3442                 (void *)&cmd_stop_stop,
3443                 NULL,
3444         },
3445 };
3446
3447 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3448
3449 unsigned int
3450 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3451                 unsigned int *parsed_items, int check_unique_values)
3452 {
3453         unsigned int nb_item;
3454         unsigned int value;
3455         unsigned int i;
3456         unsigned int j;
3457         int value_ok;
3458         char c;
3459
3460         /*
3461          * First parse all items in the list and store their value.
3462          */
3463         value = 0;
3464         nb_item = 0;
3465         value_ok = 0;
3466         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3467                 c = str[i];
3468                 if ((c >= '0') && (c <= '9')) {
3469                         value = (unsigned int) (value * 10 + (c - '0'));
3470                         value_ok = 1;
3471                         continue;
3472                 }
3473                 if (c != ',') {
3474                         printf("character %c is not a decimal digit\n", c);
3475                         return 0;
3476                 }
3477                 if (! value_ok) {
3478                         printf("No valid value before comma\n");
3479                         return 0;
3480                 }
3481                 if (nb_item < max_items) {
3482                         parsed_items[nb_item] = value;
3483                         value_ok = 0;
3484                         value = 0;
3485                 }
3486                 nb_item++;
3487         }
3488         if (nb_item >= max_items) {
3489                 printf("Number of %s = %u > %u (maximum items)\n",
3490                        item_name, nb_item + 1, max_items);
3491                 return 0;
3492         }
3493         parsed_items[nb_item++] = value;
3494         if (! check_unique_values)
3495                 return nb_item;
3496
3497         /*
3498          * Then, check that all values in the list are differents.
3499          * No optimization here...
3500          */
3501         for (i = 0; i < nb_item; i++) {
3502                 for (j = i + 1; j < nb_item; j++) {
3503                         if (parsed_items[j] == parsed_items[i]) {
3504                                 printf("duplicated %s %u at index %u and %u\n",
3505                                        item_name, parsed_items[i], i, j);
3506                                 return 0;
3507                         }
3508                 }
3509         }
3510         return nb_item;
3511 }
3512
3513 struct cmd_set_list_result {
3514         cmdline_fixed_string_t cmd_keyword;
3515         cmdline_fixed_string_t list_name;
3516         cmdline_fixed_string_t list_of_items;
3517 };
3518
3519 static void cmd_set_list_parsed(void *parsed_result,
3520                                 __attribute__((unused)) struct cmdline *cl,
3521                                 __attribute__((unused)) void *data)
3522 {
3523         struct cmd_set_list_result *res;
3524         union {
3525                 unsigned int lcorelist[RTE_MAX_LCORE];
3526                 unsigned int portlist[RTE_MAX_ETHPORTS];
3527         } parsed_items;
3528         unsigned int nb_item;
3529
3530         if (test_done == 0) {
3531                 printf("Please stop forwarding first\n");
3532                 return;
3533         }
3534
3535         res = parsed_result;
3536         if (!strcmp(res->list_name, "corelist")) {
3537                 nb_item = parse_item_list(res->list_of_items, "core",
3538                                           RTE_MAX_LCORE,
3539                                           parsed_items.lcorelist, 1);
3540                 if (nb_item > 0) {
3541                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3542                         fwd_config_setup();
3543                 }
3544                 return;
3545         }
3546         if (!strcmp(res->list_name, "portlist")) {
3547                 nb_item = parse_item_list(res->list_of_items, "port",
3548                                           RTE_MAX_ETHPORTS,
3549                                           parsed_items.portlist, 1);
3550                 if (nb_item > 0) {
3551                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3552                         fwd_config_setup();
3553                 }
3554         }
3555 }
3556
3557 cmdline_parse_token_string_t cmd_set_list_keyword =
3558         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3559                                  "set");
3560 cmdline_parse_token_string_t cmd_set_list_name =
3561         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3562                                  "corelist#portlist");
3563 cmdline_parse_token_string_t cmd_set_list_of_items =
3564         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3565                                  NULL);
3566
3567 cmdline_parse_inst_t cmd_set_fwd_list = {
3568         .f = cmd_set_list_parsed,
3569         .data = NULL,
3570         .help_str = "set corelist|portlist <list0[,list1]*>",
3571         .tokens = {
3572                 (void *)&cmd_set_list_keyword,
3573                 (void *)&cmd_set_list_name,
3574                 (void *)&cmd_set_list_of_items,
3575                 NULL,
3576         },
3577 };
3578
3579 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3580
3581 struct cmd_setmask_result {
3582         cmdline_fixed_string_t set;
3583         cmdline_fixed_string_t mask;
3584         uint64_t hexavalue;
3585 };
3586
3587 static void cmd_set_mask_parsed(void *parsed_result,
3588                                 __attribute__((unused)) struct cmdline *cl,
3589                                 __attribute__((unused)) void *data)
3590 {
3591         struct cmd_setmask_result *res = parsed_result;
3592
3593         if (test_done == 0) {
3594                 printf("Please stop forwarding first\n");
3595                 return;
3596         }
3597         if (!strcmp(res->mask, "coremask")) {
3598                 set_fwd_lcores_mask(res->hexavalue);
3599                 fwd_config_setup();
3600         } else if (!strcmp(res->mask, "portmask")) {
3601                 set_fwd_ports_mask(res->hexavalue);
3602                 fwd_config_setup();
3603         }
3604 }
3605
3606 cmdline_parse_token_string_t cmd_setmask_set =
3607         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3608 cmdline_parse_token_string_t cmd_setmask_mask =
3609         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3610                                  "coremask#portmask");
3611 cmdline_parse_token_num_t cmd_setmask_value =
3612         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3613
3614 cmdline_parse_inst_t cmd_set_fwd_mask = {
3615         .f = cmd_set_mask_parsed,
3616         .data = NULL,
3617         .help_str = "set coremask|portmask <hexadecimal value>",
3618         .tokens = {
3619                 (void *)&cmd_setmask_set,
3620                 (void *)&cmd_setmask_mask,
3621                 (void *)&cmd_setmask_value,
3622                 NULL,
3623         },
3624 };
3625
3626 /*
3627  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3628  */
3629 struct cmd_set_result {
3630         cmdline_fixed_string_t set;
3631         cmdline_fixed_string_t what;
3632         uint16_t value;
3633 };
3634
3635 static void cmd_set_parsed(void *parsed_result,
3636                            __attribute__((unused)) struct cmdline *cl,
3637                            __attribute__((unused)) void *data)
3638 {
3639         struct cmd_set_result *res = parsed_result;
3640         if (!strcmp(res->what, "nbport")) {
3641                 set_fwd_ports_number(res->value);
3642                 fwd_config_setup();
3643         } else if (!strcmp(res->what, "nbcore")) {
3644                 set_fwd_lcores_number(res->value);
3645                 fwd_config_setup();
3646         } else if (!strcmp(res->what, "burst"))
3647                 set_nb_pkt_per_burst(res->value);
3648         else if (!strcmp(res->what, "verbose"))
3649                 set_verbose_level(res->value);
3650 }
3651
3652 cmdline_parse_token_string_t cmd_set_set =
3653         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3654 cmdline_parse_token_string_t cmd_set_what =
3655         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3656                                  "nbport#nbcore#burst#verbose");
3657 cmdline_parse_token_num_t cmd_set_value =
3658         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3659
3660 cmdline_parse_inst_t cmd_set_numbers = {
3661         .f = cmd_set_parsed,
3662         .data = NULL,
3663         .help_str = "set nbport|nbcore|burst|verbose <value>",
3664         .tokens = {
3665                 (void *)&cmd_set_set,
3666                 (void *)&cmd_set_what,
3667                 (void *)&cmd_set_value,
3668                 NULL,
3669         },
3670 };
3671
3672 /* *** SET LOG LEVEL CONFIGURATION *** */
3673
3674 struct cmd_set_log_result {
3675         cmdline_fixed_string_t set;
3676         cmdline_fixed_string_t log;
3677         cmdline_fixed_string_t type;
3678         uint32_t level;
3679 };
3680
3681 static void
3682 cmd_set_log_parsed(void *parsed_result,
3683                    __attribute__((unused)) struct cmdline *cl,
3684                    __attribute__((unused)) void *data)
3685 {
3686         struct cmd_set_log_result *res;
3687         int ret;
3688
3689         res = parsed_result;
3690         if (!strcmp(res->type, "global"))
3691                 rte_log_set_global_level(res->level);
3692         else {
3693                 ret = rte_log_set_level_regexp(res->type, res->level);
3694                 if (ret < 0)
3695                         printf("Unable to set log level\n");
3696         }
3697 }
3698
3699 cmdline_parse_token_string_t cmd_set_log_set =
3700         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3701 cmdline_parse_token_string_t cmd_set_log_log =
3702         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3703 cmdline_parse_token_string_t cmd_set_log_type =
3704         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3705 cmdline_parse_token_num_t cmd_set_log_level =
3706         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3707
3708 cmdline_parse_inst_t cmd_set_log = {
3709         .f = cmd_set_log_parsed,
3710         .data = NULL,
3711         .help_str = "set log global|<type> <level>",
3712         .tokens = {
3713                 (void *)&cmd_set_log_set,
3714                 (void *)&cmd_set_log_log,
3715                 (void *)&cmd_set_log_type,
3716                 (void *)&cmd_set_log_level,
3717                 NULL,
3718         },
3719 };
3720
3721 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3722
3723 struct cmd_set_txpkts_result {
3724         cmdline_fixed_string_t cmd_keyword;
3725         cmdline_fixed_string_t txpkts;
3726         cmdline_fixed_string_t seg_lengths;
3727 };
3728
3729 static void
3730 cmd_set_txpkts_parsed(void *parsed_result,
3731                       __attribute__((unused)) struct cmdline *cl,
3732                       __attribute__((unused)) void *data)
3733 {
3734         struct cmd_set_txpkts_result *res;
3735         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3736         unsigned int nb_segs;
3737
3738         res = parsed_result;
3739         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3740                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3741         if (nb_segs > 0)
3742                 set_tx_pkt_segments(seg_lengths, nb_segs);
3743 }
3744
3745 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3746         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3747                                  cmd_keyword, "set");
3748 cmdline_parse_token_string_t cmd_set_txpkts_name =
3749         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3750                                  txpkts, "txpkts");
3751 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3752         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3753                                  seg_lengths, NULL);
3754
3755 cmdline_parse_inst_t cmd_set_txpkts = {
3756         .f = cmd_set_txpkts_parsed,
3757         .data = NULL,
3758         .help_str = "set txpkts <len0[,len1]*>",
3759         .tokens = {
3760                 (void *)&cmd_set_txpkts_keyword,
3761                 (void *)&cmd_set_txpkts_name,
3762                 (void *)&cmd_set_txpkts_lengths,
3763                 NULL,
3764         },
3765 };
3766
3767 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3768
3769 struct cmd_set_txsplit_result {
3770         cmdline_fixed_string_t cmd_keyword;
3771         cmdline_fixed_string_t txsplit;
3772         cmdline_fixed_string_t mode;
3773 };
3774
3775 static void
3776 cmd_set_txsplit_parsed(void *parsed_result,
3777                       __attribute__((unused)) struct cmdline *cl,
3778                       __attribute__((unused)) void *data)
3779 {
3780         struct cmd_set_txsplit_result *res;
3781
3782         res = parsed_result;
3783         set_tx_pkt_split(res->mode);
3784 }
3785
3786 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3787         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3788                                  cmd_keyword, "set");
3789 cmdline_parse_token_string_t cmd_set_txsplit_name =
3790         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3791                                  txsplit, "txsplit");
3792 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3793         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3794                                  mode, NULL);
3795
3796 cmdline_parse_inst_t cmd_set_txsplit = {
3797         .f = cmd_set_txsplit_parsed,
3798         .data = NULL,
3799         .help_str = "set txsplit on|off|rand",
3800         .tokens = {
3801                 (void *)&cmd_set_txsplit_keyword,
3802                 (void *)&cmd_set_txsplit_name,
3803                 (void *)&cmd_set_txsplit_mode,
3804                 NULL,
3805         },
3806 };
3807
3808 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3809 struct cmd_rx_vlan_filter_all_result {
3810         cmdline_fixed_string_t rx_vlan;
3811         cmdline_fixed_string_t what;
3812         cmdline_fixed_string_t all;
3813         portid_t port_id;
3814 };
3815
3816 static void
3817 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3818                               __attribute__((unused)) struct cmdline *cl,
3819                               __attribute__((unused)) void *data)
3820 {
3821         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3822
3823         if (!strcmp(res->what, "add"))
3824                 rx_vlan_all_filter_set(res->port_id, 1);
3825         else
3826                 rx_vlan_all_filter_set(res->port_id, 0);
3827 }
3828
3829 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3830         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3831                                  rx_vlan, "rx_vlan");
3832 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3833         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3834                                  what, "add#rm");
3835 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3836         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3837                                  all, "all");
3838 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3839         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3840                               port_id, UINT16);
3841
3842 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3843         .f = cmd_rx_vlan_filter_all_parsed,
3844         .data = NULL,
3845         .help_str = "rx_vlan add|rm all <port_id>: "
3846                 "Add/Remove all identifiers to/from the set of VLAN "
3847                 "identifiers filtered by a port",
3848         .tokens = {
3849                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3850                 (void *)&cmd_rx_vlan_filter_all_what,
3851                 (void *)&cmd_rx_vlan_filter_all_all,
3852                 (void *)&cmd_rx_vlan_filter_all_portid,
3853                 NULL,
3854         },
3855 };
3856
3857 /* *** VLAN OFFLOAD SET ON A PORT *** */
3858 struct cmd_vlan_offload_result {
3859         cmdline_fixed_string_t vlan;
3860         cmdline_fixed_string_t set;
3861         cmdline_fixed_string_t vlan_type;
3862         cmdline_fixed_string_t what;
3863         cmdline_fixed_string_t on;
3864         cmdline_fixed_string_t port_id;
3865 };
3866
3867 static void
3868 cmd_vlan_offload_parsed(void *parsed_result,
3869                           __attribute__((unused)) struct cmdline *cl,
3870                           __attribute__((unused)) void *data)
3871 {
3872         int on;
3873         struct cmd_vlan_offload_result *res = parsed_result;
3874         char *str;
3875         int i, len = 0;
3876         portid_t port_id = 0;
3877         unsigned int tmp;
3878
3879         str = res->port_id;
3880         len = strnlen(str, STR_TOKEN_SIZE);
3881         i = 0;
3882         /* Get port_id first */
3883         while(i < len){
3884                 if(str[i] == ',')
3885                         break;
3886
3887                 i++;
3888         }
3889         str[i]='\0';
3890         tmp = strtoul(str, NULL, 0);
3891         /* If port_id greater that what portid_t can represent, return */
3892         if(tmp >= RTE_MAX_ETHPORTS)
3893                 return;
3894         port_id = (portid_t)tmp;
3895
3896         if (!strcmp(res->on, "on"))
3897                 on = 1;
3898         else
3899                 on = 0;
3900
3901         if (!strcmp(res->what, "strip"))
3902                 rx_vlan_strip_set(port_id,  on);
3903         else if(!strcmp(res->what, "stripq")){
3904                 uint16_t queue_id = 0;
3905
3906                 /* No queue_id, return */
3907                 if(i + 1 >= len) {
3908                         printf("must specify (port,queue_id)\n");
3909                         return;
3910                 }
3911                 tmp = strtoul(str + i + 1, NULL, 0);
3912                 /* If queue_id greater that what 16-bits can represent, return */
3913                 if(tmp > 0xffff)
3914                         return;
3915
3916                 queue_id = (uint16_t)tmp;
3917                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3918         }
3919         else if (!strcmp(res->what, "filter"))
3920                 rx_vlan_filter_set(port_id, on);
3921         else
3922                 vlan_extend_set(port_id, on);
3923
3924         return;
3925 }
3926
3927 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3928         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3929                                  vlan, "vlan");
3930 cmdline_parse_token_string_t cmd_vlan_offload_set =
3931         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3932                                  set, "set");
3933 cmdline_parse_token_string_t cmd_vlan_offload_what =
3934         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3935                                  what, "strip#filter#qinq#stripq");
3936 cmdline_parse_token_string_t cmd_vlan_offload_on =
3937         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3938                               on, "on#off");
3939 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3940         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3941                               port_id, NULL);
3942
3943 cmdline_parse_inst_t cmd_vlan_offload = {
3944         .f = cmd_vlan_offload_parsed,
3945         .data = NULL,
3946         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3947                 "<port_id[,queue_id]>: "
3948                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3949         .tokens = {
3950                 (void *)&cmd_vlan_offload_vlan,
3951                 (void *)&cmd_vlan_offload_set,
3952                 (void *)&cmd_vlan_offload_what,
3953                 (void *)&cmd_vlan_offload_on,
3954                 (void *)&cmd_vlan_offload_portid,
3955                 NULL,
3956         },
3957 };
3958
3959 /* *** VLAN TPID SET ON A PORT *** */
3960 struct cmd_vlan_tpid_result {
3961         cmdline_fixed_string_t vlan;
3962         cmdline_fixed_string_t set;
3963         cmdline_fixed_string_t vlan_type;
3964         cmdline_fixed_string_t what;
3965         uint16_t tp_id;
3966         portid_t port_id;
3967 };
3968
3969 static void
3970 cmd_vlan_tpid_parsed(void *parsed_result,
3971                           __attribute__((unused)) struct cmdline *cl,
3972                           __attribute__((unused)) void *data)
3973 {
3974         struct cmd_vlan_tpid_result *res = parsed_result;
3975         enum rte_vlan_type vlan_type;
3976
3977         if (!strcmp(res->vlan_type, "inner"))
3978                 vlan_type = ETH_VLAN_TYPE_INNER;
3979         else if (!strcmp(res->vlan_type, "outer"))
3980                 vlan_type = ETH_VLAN_TYPE_OUTER;
3981         else {
3982                 printf("Unknown vlan type\n");
3983                 return;
3984         }
3985         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3986 }
3987
3988 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3989         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3990                                  vlan, "vlan");
3991 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3992         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3993                                  set, "set");
3994 cmdline_parse_token_string_t cmd_vlan_type =
3995         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3996                                  vlan_type, "inner#outer");
3997 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3998         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3999                                  what, "tpid");
4000 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4001         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4002                               tp_id, UINT16);
4003 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4004         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4005                               port_id, UINT16);
4006
4007 cmdline_parse_inst_t cmd_vlan_tpid = {
4008         .f = cmd_vlan_tpid_parsed,
4009         .data = NULL,
4010         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4011                 "Set the VLAN Ether type",
4012         .tokens = {
4013                 (void *)&cmd_vlan_tpid_vlan,
4014                 (void *)&cmd_vlan_tpid_set,
4015                 (void *)&cmd_vlan_type,
4016                 (void *)&cmd_vlan_tpid_what,
4017                 (void *)&cmd_vlan_tpid_tpid,
4018                 (void *)&cmd_vlan_tpid_portid,
4019                 NULL,
4020         },
4021 };
4022
4023 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4024 struct cmd_rx_vlan_filter_result {
4025         cmdline_fixed_string_t rx_vlan;
4026         cmdline_fixed_string_t what;
4027         uint16_t vlan_id;
4028         portid_t port_id;
4029 };
4030
4031 static void
4032 cmd_rx_vlan_filter_parsed(void *parsed_result,
4033                           __attribute__((unused)) struct cmdline *cl,
4034                           __attribute__((unused)) void *data)
4035 {
4036         struct cmd_rx_vlan_filter_result *res = parsed_result;
4037
4038         if (!strcmp(res->what, "add"))
4039                 rx_vft_set(res->port_id, res->vlan_id, 1);
4040         else
4041                 rx_vft_set(res->port_id, res->vlan_id, 0);
4042 }
4043
4044 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4045         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4046                                  rx_vlan, "rx_vlan");
4047 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4048         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4049                                  what, "add#rm");
4050 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4051         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4052                               vlan_id, UINT16);
4053 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4054         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4055                               port_id, UINT16);
4056
4057 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4058         .f = cmd_rx_vlan_filter_parsed,
4059         .data = NULL,
4060         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4061                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4062                 "identifiers filtered by a port",
4063         .tokens = {
4064                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4065                 (void *)&cmd_rx_vlan_filter_what,
4066                 (void *)&cmd_rx_vlan_filter_vlanid,
4067                 (void *)&cmd_rx_vlan_filter_portid,
4068                 NULL,
4069         },
4070 };
4071
4072 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4073 struct cmd_tx_vlan_set_result {
4074         cmdline_fixed_string_t tx_vlan;
4075         cmdline_fixed_string_t set;
4076         portid_t port_id;
4077         uint16_t vlan_id;
4078 };
4079
4080 static void
4081 cmd_tx_vlan_set_parsed(void *parsed_result,
4082                        __attribute__((unused)) struct cmdline *cl,
4083                        __attribute__((unused)) void *data)
4084 {
4085         struct cmd_tx_vlan_set_result *res = parsed_result;
4086
4087         if (!port_is_stopped(res->port_id)) {
4088                 printf("Please stop port %d first\n", res->port_id);
4089                 return;
4090         }
4091
4092         tx_vlan_set(res->port_id, res->vlan_id);
4093
4094         cmd_reconfig_device_queue(res->port_id, 1, 1);
4095 }
4096
4097 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4098         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4099                                  tx_vlan, "tx_vlan");
4100 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4101         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4102                                  set, "set");
4103 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4104         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4105                               port_id, UINT16);
4106 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4107         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4108                               vlan_id, UINT16);
4109
4110 cmdline_parse_inst_t cmd_tx_vlan_set = {
4111         .f = cmd_tx_vlan_set_parsed,
4112         .data = NULL,
4113         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4114                 "Enable hardware insertion of a single VLAN header "
4115                 "with a given TAG Identifier in packets sent on a port",
4116         .tokens = {
4117                 (void *)&cmd_tx_vlan_set_tx_vlan,
4118                 (void *)&cmd_tx_vlan_set_set,
4119                 (void *)&cmd_tx_vlan_set_portid,
4120                 (void *)&cmd_tx_vlan_set_vlanid,
4121                 NULL,
4122         },
4123 };
4124
4125 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4126 struct cmd_tx_vlan_set_qinq_result {
4127         cmdline_fixed_string_t tx_vlan;
4128         cmdline_fixed_string_t set;
4129         portid_t port_id;
4130         uint16_t vlan_id;
4131         uint16_t vlan_id_outer;
4132 };
4133
4134 static void
4135 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4136                             __attribute__((unused)) struct cmdline *cl,
4137                             __attribute__((unused)) void *data)
4138 {
4139         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4140
4141         if (!port_is_stopped(res->port_id)) {
4142                 printf("Please stop port %d first\n", res->port_id);
4143                 return;
4144         }
4145
4146         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4147
4148         cmd_reconfig_device_queue(res->port_id, 1, 1);
4149 }
4150
4151 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4152         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4153                 tx_vlan, "tx_vlan");
4154 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4155         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4156                 set, "set");
4157 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4158         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4159                 port_id, UINT16);
4160 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4161         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4162                 vlan_id, UINT16);
4163 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4164         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4165                 vlan_id_outer, UINT16);
4166
4167 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4168         .f = cmd_tx_vlan_set_qinq_parsed,
4169         .data = NULL,
4170         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4171                 "Enable hardware insertion of double VLAN header "
4172                 "with given TAG Identifiers in packets sent on a port",
4173         .tokens = {
4174                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4175                 (void *)&cmd_tx_vlan_set_qinq_set,
4176                 (void *)&cmd_tx_vlan_set_qinq_portid,
4177                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4178                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4179                 NULL,
4180         },
4181 };
4182
4183 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4184 struct cmd_tx_vlan_set_pvid_result {
4185         cmdline_fixed_string_t tx_vlan;
4186         cmdline_fixed_string_t set;
4187         cmdline_fixed_string_t pvid;
4188         portid_t port_id;
4189         uint16_t vlan_id;
4190         cmdline_fixed_string_t mode;
4191 };
4192
4193 static void
4194 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4195                             __attribute__((unused)) struct cmdline *cl,
4196                             __attribute__((unused)) void *data)
4197 {
4198         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4199
4200         if (strcmp(res->mode, "on") == 0)
4201                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4202         else
4203                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4204 }
4205
4206 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4207         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4208                                  tx_vlan, "tx_vlan");
4209 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4210         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4211                                  set, "set");
4212 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4213         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4214                                  pvid, "pvid");
4215 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4216         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4217                              port_id, UINT16);
4218 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4219         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4220                               vlan_id, UINT16);
4221 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4222         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4223                                  mode, "on#off");
4224
4225 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4226         .f = cmd_tx_vlan_set_pvid_parsed,
4227         .data = NULL,
4228         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4229         .tokens = {
4230                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4231                 (void *)&cmd_tx_vlan_set_pvid_set,
4232                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4233                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4234                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4235                 (void *)&cmd_tx_vlan_set_pvid_mode,
4236                 NULL,
4237         },
4238 };
4239
4240 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4241 struct cmd_tx_vlan_reset_result {
4242         cmdline_fixed_string_t tx_vlan;
4243         cmdline_fixed_string_t reset;
4244         portid_t port_id;
4245 };
4246
4247 static void
4248 cmd_tx_vlan_reset_parsed(void *parsed_result,
4249                          __attribute__((unused)) struct cmdline *cl,
4250                          __attribute__((unused)) void *data)
4251 {
4252         struct cmd_tx_vlan_reset_result *res = parsed_result;
4253
4254         if (!port_is_stopped(res->port_id)) {
4255                 printf("Please stop port %d first\n", res->port_id);
4256                 return;
4257         }
4258
4259         tx_vlan_reset(res->port_id);
4260
4261         cmd_reconfig_device_queue(res->port_id, 1, 1);
4262 }
4263
4264 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4265         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4266                                  tx_vlan, "tx_vlan");
4267 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4268         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4269                                  reset, "reset");
4270 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4271         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4272                               port_id, UINT16);
4273
4274 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4275         .f = cmd_tx_vlan_reset_parsed,
4276         .data = NULL,
4277         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4278                 "VLAN header in packets sent on a port",
4279         .tokens = {
4280                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4281                 (void *)&cmd_tx_vlan_reset_reset,
4282                 (void *)&cmd_tx_vlan_reset_portid,
4283                 NULL,
4284         },
4285 };
4286
4287
4288 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4289 struct cmd_csum_result {
4290         cmdline_fixed_string_t csum;
4291         cmdline_fixed_string_t mode;
4292         cmdline_fixed_string_t proto;
4293         cmdline_fixed_string_t hwsw;
4294         portid_t port_id;
4295 };
4296
4297 static void
4298 csum_show(int port_id)
4299 {
4300         struct rte_eth_dev_info dev_info;
4301         uint64_t tx_offloads;
4302         int ret;
4303
4304         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4305         printf("Parse tunnel is %s\n",
4306                 (ports[port_id].parse_tunnel) ? "on" : "off");
4307         printf("IP checksum offload is %s\n",
4308                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4309         printf("UDP checksum offload is %s\n",
4310                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4311         printf("TCP checksum offload is %s\n",
4312                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4313         printf("SCTP checksum offload is %s\n",
4314                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4315         printf("Outer-Ip checksum offload is %s\n",
4316                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4317         printf("Outer-Udp checksum offload is %s\n",
4318                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4319
4320         /* display warnings if configuration is not supported by the NIC */
4321         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4322         if (ret != 0)
4323                 return;
4324
4325         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4326                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4327                 printf("Warning: hardware IP checksum enabled but not "
4328                         "supported by port %d\n", port_id);
4329         }
4330         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4331                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4332                 printf("Warning: hardware UDP checksum enabled but not "
4333                         "supported by port %d\n", port_id);
4334         }
4335         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4336                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4337                 printf("Warning: hardware TCP checksum enabled but not "
4338                         "supported by port %d\n", port_id);
4339         }
4340         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4341                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4342                 printf("Warning: hardware SCTP checksum enabled but not "
4343                         "supported by port %d\n", port_id);
4344         }
4345         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4346                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4347                 printf("Warning: hardware outer IP checksum enabled but not "
4348                         "supported by port %d\n", port_id);
4349         }
4350         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4351                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4352                         == 0) {
4353                 printf("Warning: hardware outer UDP checksum enabled but not "
4354                         "supported by port %d\n", port_id);
4355         }
4356 }
4357
4358 static void
4359 cmd_config_queue_tx_offloads(struct rte_port *port)
4360 {
4361         int k;
4362
4363         /* Apply queue tx offloads configuration */
4364         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4365                 port->tx_conf[k].offloads =
4366                         port->dev_conf.txmode.offloads;
4367 }
4368
4369 static void
4370 cmd_csum_parsed(void *parsed_result,
4371                        __attribute__((unused)) struct cmdline *cl,
4372                        __attribute__((unused)) void *data)
4373 {
4374         struct cmd_csum_result *res = parsed_result;
4375         int hw = 0;
4376         uint64_t csum_offloads = 0;
4377         struct rte_eth_dev_info dev_info;
4378         int ret;
4379
4380         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4381                 printf("invalid port %d\n", res->port_id);
4382                 return;
4383         }
4384         if (!port_is_stopped(res->port_id)) {
4385                 printf("Please stop port %d first\n", res->port_id);
4386                 return;
4387         }
4388
4389         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4390         if (ret != 0)
4391                 return;
4392
4393         if (!strcmp(res->mode, "set")) {
4394
4395                 if (!strcmp(res->hwsw, "hw"))
4396                         hw = 1;
4397
4398                 if (!strcmp(res->proto, "ip")) {
4399                         if (hw == 0 || (dev_info.tx_offload_capa &
4400                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4401                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4402                         } else {
4403                                 printf("IP checksum offload is not supported "
4404                                        "by port %u\n", res->port_id);
4405                         }
4406                 } else if (!strcmp(res->proto, "udp")) {
4407                         if (hw == 0 || (dev_info.tx_offload_capa &
4408                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4409                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4410                         } else {
4411                                 printf("UDP checksum offload is not supported "
4412                                        "by port %u\n", res->port_id);
4413                         }
4414                 } else if (!strcmp(res->proto, "tcp")) {
4415                         if (hw == 0 || (dev_info.tx_offload_capa &
4416                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4417                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4418                         } else {
4419                                 printf("TCP checksum offload is not supported "
4420                                        "by port %u\n", res->port_id);
4421                         }
4422                 } else if (!strcmp(res->proto, "sctp")) {
4423                         if (hw == 0 || (dev_info.tx_offload_capa &
4424                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4425                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4426                         } else {
4427                                 printf("SCTP checksum offload is not supported "
4428                                        "by port %u\n", res->port_id);
4429                         }
4430                 } else if (!strcmp(res->proto, "outer-ip")) {
4431                         if (hw == 0 || (dev_info.tx_offload_capa &
4432                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4433                                 csum_offloads |=
4434                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4435                         } else {
4436                                 printf("Outer IP checksum offload is not "
4437                                        "supported by port %u\n", res->port_id);
4438                         }
4439                 } else if (!strcmp(res->proto, "outer-udp")) {
4440                         if (hw == 0 || (dev_info.tx_offload_capa &
4441                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4442                                 csum_offloads |=
4443                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4444                         } else {
4445                                 printf("Outer UDP checksum offload is not "
4446                                        "supported by port %u\n", res->port_id);
4447                         }
4448                 }
4449
4450                 if (hw) {
4451                         ports[res->port_id].dev_conf.txmode.offloads |=
4452                                                         csum_offloads;
4453                 } else {
4454                         ports[res->port_id].dev_conf.txmode.offloads &=
4455                                                         (~csum_offloads);
4456                 }
4457                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4458         }
4459         csum_show(res->port_id);
4460
4461         cmd_reconfig_device_queue(res->port_id, 1, 1);
4462 }
4463
4464 cmdline_parse_token_string_t cmd_csum_csum =
4465         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4466                                 csum, "csum");
4467 cmdline_parse_token_string_t cmd_csum_mode =
4468         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4469                                 mode, "set");
4470 cmdline_parse_token_string_t cmd_csum_proto =
4471         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4472                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4473 cmdline_parse_token_string_t cmd_csum_hwsw =
4474         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4475                                 hwsw, "hw#sw");
4476 cmdline_parse_token_num_t cmd_csum_portid =
4477         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4478                                 port_id, UINT16);
4479
4480 cmdline_parse_inst_t cmd_csum_set = {
4481         .f = cmd_csum_parsed,
4482         .data = NULL,
4483         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4484                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4485                 "using csum forward engine",
4486         .tokens = {
4487                 (void *)&cmd_csum_csum,
4488                 (void *)&cmd_csum_mode,
4489                 (void *)&cmd_csum_proto,
4490                 (void *)&cmd_csum_hwsw,
4491                 (void *)&cmd_csum_portid,
4492                 NULL,
4493         },
4494 };
4495
4496 cmdline_parse_token_string_t cmd_csum_mode_show =
4497         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4498                                 mode, "show");
4499
4500 cmdline_parse_inst_t cmd_csum_show = {
4501         .f = cmd_csum_parsed,
4502         .data = NULL,
4503         .help_str = "csum show <port_id>: Show checksum offload configuration",
4504         .tokens = {
4505                 (void *)&cmd_csum_csum,
4506                 (void *)&cmd_csum_mode_show,
4507                 (void *)&cmd_csum_portid,
4508                 NULL,
4509         },
4510 };
4511
4512 /* Enable/disable tunnel parsing */
4513 struct cmd_csum_tunnel_result {
4514         cmdline_fixed_string_t csum;
4515         cmdline_fixed_string_t parse;
4516         cmdline_fixed_string_t onoff;
4517         portid_t port_id;
4518 };
4519
4520 static void
4521 cmd_csum_tunnel_parsed(void *parsed_result,
4522                        __attribute__((unused)) struct cmdline *cl,
4523                        __attribute__((unused)) void *data)
4524 {
4525         struct cmd_csum_tunnel_result *res = parsed_result;
4526
4527         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4528                 return;
4529
4530         if (!strcmp(res->onoff, "on"))
4531                 ports[res->port_id].parse_tunnel = 1;
4532         else
4533                 ports[res->port_id].parse_tunnel = 0;
4534
4535         csum_show(res->port_id);
4536 }
4537
4538 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4539         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4540                                 csum, "csum");
4541 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4542         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4543                                 parse, "parse-tunnel");
4544 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4545         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4546                                 onoff, "on#off");
4547 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4548         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4549                                 port_id, UINT16);
4550
4551 cmdline_parse_inst_t cmd_csum_tunnel = {
4552         .f = cmd_csum_tunnel_parsed,
4553         .data = NULL,
4554         .help_str = "csum parse-tunnel on|off <port_id>: "
4555                 "Enable/Disable parsing of tunnels for csum engine",
4556         .tokens = {
4557                 (void *)&cmd_csum_tunnel_csum,
4558                 (void *)&cmd_csum_tunnel_parse,
4559                 (void *)&cmd_csum_tunnel_onoff,
4560                 (void *)&cmd_csum_tunnel_portid,
4561                 NULL,
4562         },
4563 };
4564
4565 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4566 struct cmd_tso_set_result {
4567         cmdline_fixed_string_t tso;
4568         cmdline_fixed_string_t mode;
4569         uint16_t tso_segsz;
4570         portid_t port_id;
4571 };
4572
4573 static void
4574 cmd_tso_set_parsed(void *parsed_result,
4575                        __attribute__((unused)) struct cmdline *cl,
4576                        __attribute__((unused)) void *data)
4577 {
4578         struct cmd_tso_set_result *res = parsed_result;
4579         struct rte_eth_dev_info dev_info;
4580         int ret;
4581
4582         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4583                 return;
4584         if (!port_is_stopped(res->port_id)) {
4585                 printf("Please stop port %d first\n", res->port_id);
4586                 return;
4587         }
4588
4589         if (!strcmp(res->mode, "set"))
4590                 ports[res->port_id].tso_segsz = res->tso_segsz;
4591
4592         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4593         if (ret != 0)
4594                 return;
4595
4596         if ((ports[res->port_id].tso_segsz != 0) &&
4597                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4598                 printf("Error: TSO is not supported by port %d\n",
4599                        res->port_id);
4600                 return;
4601         }
4602
4603         if (ports[res->port_id].tso_segsz == 0) {
4604                 ports[res->port_id].dev_conf.txmode.offloads &=
4605                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4606                 printf("TSO for non-tunneled packets is disabled\n");
4607         } else {
4608                 ports[res->port_id].dev_conf.txmode.offloads |=
4609                                                 DEV_TX_OFFLOAD_TCP_TSO;
4610                 printf("TSO segment size for non-tunneled packets is %d\n",
4611                         ports[res->port_id].tso_segsz);
4612         }
4613         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4614
4615         /* display warnings if configuration is not supported by the NIC */
4616         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4617         if (ret != 0)
4618                 return;
4619
4620         if ((ports[res->port_id].tso_segsz != 0) &&
4621                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4622                 printf("Warning: TSO enabled but not "
4623                         "supported by port %d\n", res->port_id);
4624         }
4625
4626         cmd_reconfig_device_queue(res->port_id, 1, 1);
4627 }
4628
4629 cmdline_parse_token_string_t cmd_tso_set_tso =
4630         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4631                                 tso, "tso");
4632 cmdline_parse_token_string_t cmd_tso_set_mode =
4633         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4634                                 mode, "set");
4635 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4636         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4637                                 tso_segsz, UINT16);
4638 cmdline_parse_token_num_t cmd_tso_set_portid =
4639         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4640                                 port_id, UINT16);
4641
4642 cmdline_parse_inst_t cmd_tso_set = {
4643         .f = cmd_tso_set_parsed,
4644         .data = NULL,
4645         .help_str = "tso set <tso_segsz> <port_id>: "
4646                 "Set TSO segment size of non-tunneled packets for csum engine "
4647                 "(0 to disable)",
4648         .tokens = {
4649                 (void *)&cmd_tso_set_tso,
4650                 (void *)&cmd_tso_set_mode,
4651                 (void *)&cmd_tso_set_tso_segsz,
4652                 (void *)&cmd_tso_set_portid,
4653                 NULL,
4654         },
4655 };
4656
4657 cmdline_parse_token_string_t cmd_tso_show_mode =
4658         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4659                                 mode, "show");
4660
4661
4662 cmdline_parse_inst_t cmd_tso_show = {
4663         .f = cmd_tso_set_parsed,
4664         .data = NULL,
4665         .help_str = "tso show <port_id>: "
4666                 "Show TSO segment size of non-tunneled packets for csum engine",
4667         .tokens = {
4668                 (void *)&cmd_tso_set_tso,
4669                 (void *)&cmd_tso_show_mode,
4670                 (void *)&cmd_tso_set_portid,
4671                 NULL,
4672         },
4673 };
4674
4675 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4676 struct cmd_tunnel_tso_set_result {
4677         cmdline_fixed_string_t tso;
4678         cmdline_fixed_string_t mode;
4679         uint16_t tso_segsz;
4680         portid_t port_id;
4681 };
4682
4683 static struct rte_eth_dev_info
4684 check_tunnel_tso_nic_support(portid_t port_id)
4685 {
4686         struct rte_eth_dev_info dev_info;
4687
4688         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4689                 return dev_info;
4690
4691         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4692                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4693                        "not enabled for port %d\n", port_id);
4694         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4695                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4696                        "not enabled for port %d\n", port_id);
4697         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4698                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4699                        "not enabled for port %d\n", port_id);
4700         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4701                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4702                        "not enabled for port %d\n", port_id);
4703         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4704                 printf("Warning: IP TUNNEL TSO not supported therefore "
4705                        "not enabled for port %d\n", port_id);
4706         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4707                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4708                        "not enabled for port %d\n", port_id);
4709         return dev_info;
4710 }
4711
4712 static void
4713 cmd_tunnel_tso_set_parsed(void *parsed_result,
4714                           __attribute__((unused)) struct cmdline *cl,
4715                           __attribute__((unused)) void *data)
4716 {
4717         struct cmd_tunnel_tso_set_result *res = parsed_result;
4718         struct rte_eth_dev_info dev_info;
4719
4720         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4721                 return;
4722         if (!port_is_stopped(res->port_id)) {
4723                 printf("Please stop port %d first\n", res->port_id);
4724                 return;
4725         }
4726
4727         if (!strcmp(res->mode, "set"))
4728                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4729
4730         dev_info = check_tunnel_tso_nic_support(res->port_id);
4731         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4732                 ports[res->port_id].dev_conf.txmode.offloads &=
4733                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4734                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4735                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4736                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4737                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4738                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4739                 printf("TSO for tunneled packets is disabled\n");
4740         } else {
4741                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4742                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4743                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4744                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4745                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4746                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4747
4748                 ports[res->port_id].dev_conf.txmode.offloads |=
4749                         (tso_offloads & dev_info.tx_offload_capa);
4750                 printf("TSO segment size for tunneled packets is %d\n",
4751                         ports[res->port_id].tunnel_tso_segsz);
4752
4753                 /* Below conditions are needed to make it work:
4754                  * (1) tunnel TSO is supported by the NIC;
4755                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4756                  * are recognized;
4757                  * (3) for tunneled pkts with outer L3 of IPv4,
4758                  * "csum set outer-ip" must be set to hw, because after tso,
4759                  * total_len of outer IP header is changed, and the checksum
4760                  * of outer IP header calculated by sw should be wrong; that
4761                  * is not necessary for IPv6 tunneled pkts because there's no
4762                  * checksum in IP header anymore.
4763                  */
4764
4765                 if (!ports[res->port_id].parse_tunnel)
4766                         printf("Warning: csum parse_tunnel must be set "
4767                                 "so that tunneled packets are recognized\n");
4768                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4769                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4770                         printf("Warning: csum set outer-ip must be set to hw "
4771                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4772         }
4773
4774         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4775         cmd_reconfig_device_queue(res->port_id, 1, 1);
4776 }
4777
4778 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4779         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4780                                 tso, "tunnel_tso");
4781 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4782         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4783                                 mode, "set");
4784 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4785         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4786                                 tso_segsz, UINT16);
4787 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4788         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4789                                 port_id, UINT16);
4790
4791 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4792         .f = cmd_tunnel_tso_set_parsed,
4793         .data = NULL,
4794         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4795                 "Set TSO segment size of tunneled packets for csum engine "
4796                 "(0 to disable)",
4797         .tokens = {
4798                 (void *)&cmd_tunnel_tso_set_tso,
4799                 (void *)&cmd_tunnel_tso_set_mode,
4800                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4801                 (void *)&cmd_tunnel_tso_set_portid,
4802                 NULL,
4803         },
4804 };
4805
4806 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4807         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4808                                 mode, "show");
4809
4810
4811 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4812         .f = cmd_tunnel_tso_set_parsed,
4813         .data = NULL,
4814         .help_str = "tunnel_tso show <port_id> "
4815                 "Show TSO segment size of tunneled packets for csum engine",
4816         .tokens = {
4817                 (void *)&cmd_tunnel_tso_set_tso,
4818                 (void *)&cmd_tunnel_tso_show_mode,
4819                 (void *)&cmd_tunnel_tso_set_portid,
4820                 NULL,
4821         },
4822 };
4823
4824 /* *** SET GRO FOR A PORT *** */
4825 struct cmd_gro_enable_result {
4826         cmdline_fixed_string_t cmd_set;
4827         cmdline_fixed_string_t cmd_port;
4828         cmdline_fixed_string_t cmd_keyword;
4829         cmdline_fixed_string_t cmd_onoff;
4830         portid_t cmd_pid;
4831 };
4832
4833 static void
4834 cmd_gro_enable_parsed(void *parsed_result,
4835                 __attribute__((unused)) struct cmdline *cl,
4836                 __attribute__((unused)) void *data)
4837 {
4838         struct cmd_gro_enable_result *res;
4839
4840         res = parsed_result;
4841         if (!strcmp(res->cmd_keyword, "gro"))
4842                 setup_gro(res->cmd_onoff, res->cmd_pid);
4843 }
4844
4845 cmdline_parse_token_string_t cmd_gro_enable_set =
4846         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4847                         cmd_set, "set");
4848 cmdline_parse_token_string_t cmd_gro_enable_port =
4849         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4850                         cmd_keyword, "port");
4851 cmdline_parse_token_num_t cmd_gro_enable_pid =
4852         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4853                         cmd_pid, UINT16);
4854 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4855         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4856                         cmd_keyword, "gro");
4857 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4858         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4859                         cmd_onoff, "on#off");
4860
4861 cmdline_parse_inst_t cmd_gro_enable = {
4862         .f = cmd_gro_enable_parsed,
4863         .data = NULL,
4864         .help_str = "set port <port_id> gro on|off",
4865         .tokens = {
4866                 (void *)&cmd_gro_enable_set,
4867                 (void *)&cmd_gro_enable_port,
4868                 (void *)&cmd_gro_enable_pid,
4869                 (void *)&cmd_gro_enable_keyword,
4870                 (void *)&cmd_gro_enable_onoff,
4871                 NULL,
4872         },
4873 };
4874
4875 /* *** DISPLAY GRO CONFIGURATION *** */
4876 struct cmd_gro_show_result {
4877         cmdline_fixed_string_t cmd_show;
4878         cmdline_fixed_string_t cmd_port;
4879         cmdline_fixed_string_t cmd_keyword;
4880         portid_t cmd_pid;
4881 };
4882
4883 static void
4884 cmd_gro_show_parsed(void *parsed_result,
4885                 __attribute__((unused)) struct cmdline *cl,
4886                 __attribute__((unused)) void *data)
4887 {
4888         struct cmd_gro_show_result *res;
4889
4890         res = parsed_result;
4891         if (!strcmp(res->cmd_keyword, "gro"))
4892                 show_gro(res->cmd_pid);
4893 }
4894
4895 cmdline_parse_token_string_t cmd_gro_show_show =
4896         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4897                         cmd_show, "show");
4898 cmdline_parse_token_string_t cmd_gro_show_port =
4899         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4900                         cmd_port, "port");
4901 cmdline_parse_token_num_t cmd_gro_show_pid =
4902         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4903                         cmd_pid, UINT16);
4904 cmdline_parse_token_string_t cmd_gro_show_keyword =
4905         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4906                         cmd_keyword, "gro");
4907
4908 cmdline_parse_inst_t cmd_gro_show = {
4909         .f = cmd_gro_show_parsed,
4910         .data = NULL,
4911         .help_str = "show port <port_id> gro",
4912         .tokens = {
4913                 (void *)&cmd_gro_show_show,
4914                 (void *)&cmd_gro_show_port,
4915                 (void *)&cmd_gro_show_pid,
4916                 (void *)&cmd_gro_show_keyword,
4917                 NULL,
4918         },
4919 };
4920
4921 /* *** SET FLUSH CYCLES FOR GRO *** */
4922 struct cmd_gro_flush_result {
4923         cmdline_fixed_string_t cmd_set;
4924         cmdline_fixed_string_t cmd_keyword;
4925         cmdline_fixed_string_t cmd_flush;
4926         uint8_t cmd_cycles;
4927 };
4928
4929 static void
4930 cmd_gro_flush_parsed(void *parsed_result,
4931                 __attribute__((unused)) struct cmdline *cl,
4932                 __attribute__((unused)) void *data)
4933 {
4934         struct cmd_gro_flush_result *res;
4935
4936         res = parsed_result;
4937         if ((!strcmp(res->cmd_keyword, "gro")) &&
4938                         (!strcmp(res->cmd_flush, "flush")))
4939                 setup_gro_flush_cycles(res->cmd_cycles);
4940 }
4941
4942 cmdline_parse_token_string_t cmd_gro_flush_set =
4943         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4944                         cmd_set, "set");
4945 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4946         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4947                         cmd_keyword, "gro");
4948 cmdline_parse_token_string_t cmd_gro_flush_flush =
4949         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4950                         cmd_flush, "flush");
4951 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4952         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4953                         cmd_cycles, UINT8);
4954
4955 cmdline_parse_inst_t cmd_gro_flush = {
4956         .f = cmd_gro_flush_parsed,
4957         .data = NULL,
4958         .help_str = "set gro flush <cycles>",
4959         .tokens = {
4960                 (void *)&cmd_gro_flush_set,
4961                 (void *)&cmd_gro_flush_keyword,
4962                 (void *)&cmd_gro_flush_flush,
4963                 (void *)&cmd_gro_flush_cycles,
4964                 NULL,
4965         },
4966 };
4967
4968 /* *** ENABLE/DISABLE GSO *** */
4969 struct cmd_gso_enable_result {
4970         cmdline_fixed_string_t cmd_set;
4971         cmdline_fixed_string_t cmd_port;
4972         cmdline_fixed_string_t cmd_keyword;
4973         cmdline_fixed_string_t cmd_mode;
4974         portid_t cmd_pid;
4975 };
4976
4977 static void
4978 cmd_gso_enable_parsed(void *parsed_result,
4979                 __attribute__((unused)) struct cmdline *cl,
4980                 __attribute__((unused)) void *data)
4981 {
4982         struct cmd_gso_enable_result *res;
4983
4984         res = parsed_result;
4985         if (!strcmp(res->cmd_keyword, "gso"))
4986                 setup_gso(res->cmd_mode, res->cmd_pid);
4987 }
4988
4989 cmdline_parse_token_string_t cmd_gso_enable_set =
4990         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4991                         cmd_set, "set");
4992 cmdline_parse_token_string_t cmd_gso_enable_port =
4993         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4994                         cmd_port, "port");
4995 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4996         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4997                         cmd_keyword, "gso");
4998 cmdline_parse_token_string_t cmd_gso_enable_mode =
4999         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5000                         cmd_mode, "on#off");
5001 cmdline_parse_token_num_t cmd_gso_enable_pid =
5002         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5003                         cmd_pid, UINT16);
5004
5005 cmdline_parse_inst_t cmd_gso_enable = {
5006         .f = cmd_gso_enable_parsed,
5007         .data = NULL,
5008         .help_str = "set port <port_id> gso on|off",
5009         .tokens = {
5010                 (void *)&cmd_gso_enable_set,
5011                 (void *)&cmd_gso_enable_port,
5012                 (void *)&cmd_gso_enable_pid,
5013                 (void *)&cmd_gso_enable_keyword,
5014                 (void *)&cmd_gso_enable_mode,
5015                 NULL,
5016         },
5017 };
5018
5019 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5020 struct cmd_gso_size_result {
5021         cmdline_fixed_string_t cmd_set;
5022         cmdline_fixed_string_t cmd_keyword;
5023         cmdline_fixed_string_t cmd_segsz;
5024         uint16_t cmd_size;
5025 };
5026
5027 static void
5028 cmd_gso_size_parsed(void *parsed_result,
5029                        __attribute__((unused)) struct cmdline *cl,
5030                        __attribute__((unused)) void *data)
5031 {
5032         struct cmd_gso_size_result *res = parsed_result;
5033
5034         if (test_done == 0) {
5035                 printf("Before setting GSO segsz, please first"
5036                                 " stop fowarding\n");
5037                 return;
5038         }
5039
5040         if (!strcmp(res->cmd_keyword, "gso") &&
5041                         !strcmp(res->cmd_segsz, "segsz")) {
5042                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5043                         printf("gso_size should be larger than %zu."
5044                                         " Please input a legal value\n",
5045                                         RTE_GSO_SEG_SIZE_MIN);
5046                 else
5047                         gso_max_segment_size = res->cmd_size;
5048         }
5049 }
5050
5051 cmdline_parse_token_string_t cmd_gso_size_set =
5052         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5053                                 cmd_set, "set");
5054 cmdline_parse_token_string_t cmd_gso_size_keyword =
5055         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5056                                 cmd_keyword, "gso");
5057 cmdline_parse_token_string_t cmd_gso_size_segsz =
5058         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5059                                 cmd_segsz, "segsz");
5060 cmdline_parse_token_num_t cmd_gso_size_size =
5061         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5062                                 cmd_size, UINT16);
5063
5064 cmdline_parse_inst_t cmd_gso_size = {
5065         .f = cmd_gso_size_parsed,
5066         .data = NULL,
5067         .help_str = "set gso segsz <length>",
5068         .tokens = {
5069                 (void *)&cmd_gso_size_set,
5070                 (void *)&cmd_gso_size_keyword,
5071                 (void *)&cmd_gso_size_segsz,
5072                 (void *)&cmd_gso_size_size,
5073                 NULL,
5074         },
5075 };
5076
5077 /* *** SHOW GSO CONFIGURATION *** */
5078 struct cmd_gso_show_result {
5079         cmdline_fixed_string_t cmd_show;
5080         cmdline_fixed_string_t cmd_port;
5081         cmdline_fixed_string_t cmd_keyword;
5082         portid_t cmd_pid;
5083 };
5084
5085 static void
5086 cmd_gso_show_parsed(void *parsed_result,
5087                        __attribute__((unused)) struct cmdline *cl,
5088                        __attribute__((unused)) void *data)
5089 {
5090         struct cmd_gso_show_result *res = parsed_result;
5091
5092         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5093                 printf("invalid port id %u\n", res->cmd_pid);
5094                 return;
5095         }
5096         if (!strcmp(res->cmd_keyword, "gso")) {
5097                 if (gso_ports[res->cmd_pid].enable) {
5098                         printf("Max GSO'd packet size: %uB\n"
5099                                         "Supported GSO types: TCP/IPv4, "
5100                                         "UDP/IPv4, VxLAN with inner "
5101                                         "TCP/IPv4 packet, GRE with inner "
5102                                         "TCP/IPv4 packet\n",
5103                                         gso_max_segment_size);
5104                 } else
5105                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5106         }
5107 }
5108
5109 cmdline_parse_token_string_t cmd_gso_show_show =
5110 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5111                 cmd_show, "show");
5112 cmdline_parse_token_string_t cmd_gso_show_port =
5113 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5114                 cmd_port, "port");
5115 cmdline_parse_token_string_t cmd_gso_show_keyword =
5116         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5117                                 cmd_keyword, "gso");
5118 cmdline_parse_token_num_t cmd_gso_show_pid =
5119         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5120                                 cmd_pid, UINT16);
5121
5122 cmdline_parse_inst_t cmd_gso_show = {
5123         .f = cmd_gso_show_parsed,
5124         .data = NULL,
5125         .help_str = "show port <port_id> gso",
5126         .tokens = {
5127                 (void *)&cmd_gso_show_show,
5128                 (void *)&cmd_gso_show_port,
5129                 (void *)&cmd_gso_show_pid,
5130                 (void *)&cmd_gso_show_keyword,
5131                 NULL,
5132         },
5133 };
5134
5135 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5136 struct cmd_set_flush_rx {
5137         cmdline_fixed_string_t set;
5138         cmdline_fixed_string_t flush_rx;
5139         cmdline_fixed_string_t mode;
5140 };
5141
5142 static void
5143 cmd_set_flush_rx_parsed(void *parsed_result,
5144                 __attribute__((unused)) struct cmdline *cl,
5145                 __attribute__((unused)) void *data)
5146 {
5147         struct cmd_set_flush_rx *res = parsed_result;
5148         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5149 }
5150
5151 cmdline_parse_token_string_t cmd_setflushrx_set =
5152         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5153                         set, "set");
5154 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5155         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5156                         flush_rx, "flush_rx");
5157 cmdline_parse_token_string_t cmd_setflushrx_mode =
5158         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5159                         mode, "on#off");
5160
5161
5162 cmdline_parse_inst_t cmd_set_flush_rx = {
5163         .f = cmd_set_flush_rx_parsed,
5164         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5165         .data = NULL,
5166         .tokens = {
5167                 (void *)&cmd_setflushrx_set,
5168                 (void *)&cmd_setflushrx_flush_rx,
5169                 (void *)&cmd_setflushrx_mode,
5170                 NULL,
5171         },
5172 };
5173
5174 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5175 struct cmd_set_link_check {
5176         cmdline_fixed_string_t set;
5177         cmdline_fixed_string_t link_check;
5178         cmdline_fixed_string_t mode;
5179 };
5180
5181 static void
5182 cmd_set_link_check_parsed(void *parsed_result,
5183                 __attribute__((unused)) struct cmdline *cl,
5184                 __attribute__((unused)) void *data)
5185 {
5186         struct cmd_set_link_check *res = parsed_result;
5187         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5188 }
5189
5190 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5191         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5192                         set, "set");
5193 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5194         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5195                         link_check, "link_check");
5196 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5197         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5198                         mode, "on#off");
5199
5200
5201 cmdline_parse_inst_t cmd_set_link_check = {
5202         .f = cmd_set_link_check_parsed,
5203         .help_str = "set link_check on|off: Enable/Disable link status check "
5204                     "when starting/stopping a port",
5205         .data = NULL,
5206         .tokens = {
5207                 (void *)&cmd_setlinkcheck_set,
5208                 (void *)&cmd_setlinkcheck_link_check,
5209                 (void *)&cmd_setlinkcheck_mode,
5210                 NULL,
5211         },
5212 };
5213
5214 /* *** SET NIC BYPASS MODE *** */
5215 struct cmd_set_bypass_mode_result {
5216         cmdline_fixed_string_t set;
5217         cmdline_fixed_string_t bypass;
5218         cmdline_fixed_string_t mode;
5219         cmdline_fixed_string_t value;
5220         portid_t port_id;
5221 };
5222
5223 static void
5224 cmd_set_bypass_mode_parsed(void *parsed_result,
5225                 __attribute__((unused)) struct cmdline *cl,
5226                 __attribute__((unused)) void *data)
5227 {
5228         struct cmd_set_bypass_mode_result *res = parsed_result;
5229         portid_t port_id = res->port_id;
5230         int32_t rc = -EINVAL;
5231
5232 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5233         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5234
5235         if (!strcmp(res->value, "bypass"))
5236                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5237         else if (!strcmp(res->value, "isolate"))
5238                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5239         else
5240                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5241
5242         /* Set the bypass mode for the relevant port. */
5243         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5244 #endif
5245         if (rc != 0)
5246                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5247 }
5248
5249 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5250         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5251                         set, "set");
5252 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5253         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5254                         bypass, "bypass");
5255 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5256         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5257                         mode, "mode");
5258 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5259         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5260                         value, "normal#bypass#isolate");
5261 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5262         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5263                                 port_id, UINT16);
5264
5265 cmdline_parse_inst_t cmd_set_bypass_mode = {
5266         .f = cmd_set_bypass_mode_parsed,
5267         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5268                     "Set the NIC bypass mode for port_id",
5269         .data = NULL,
5270         .tokens = {
5271                 (void *)&cmd_setbypass_mode_set,
5272                 (void *)&cmd_setbypass_mode_bypass,
5273                 (void *)&cmd_setbypass_mode_mode,
5274                 (void *)&cmd_setbypass_mode_value,
5275                 (void *)&cmd_setbypass_mode_port,
5276                 NULL,
5277         },
5278 };
5279
5280 /* *** SET NIC BYPASS EVENT *** */
5281 struct cmd_set_bypass_event_result {
5282         cmdline_fixed_string_t set;
5283         cmdline_fixed_string_t bypass;
5284         cmdline_fixed_string_t event;
5285         cmdline_fixed_string_t event_value;
5286         cmdline_fixed_string_t mode;
5287         cmdline_fixed_string_t mode_value;
5288         portid_t port_id;
5289 };
5290
5291 static void
5292 cmd_set_bypass_event_parsed(void *parsed_result,
5293                 __attribute__((unused)) struct cmdline *cl,
5294                 __attribute__((unused)) void *data)
5295 {
5296         int32_t rc = -EINVAL;
5297         struct cmd_set_bypass_event_result *res = parsed_result;
5298         portid_t port_id = res->port_id;
5299
5300 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5301         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5302         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5303
5304         if (!strcmp(res->event_value, "timeout"))
5305                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5306         else if (!strcmp(res->event_value, "os_on"))
5307                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5308         else if (!strcmp(res->event_value, "os_off"))
5309                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5310         else if (!strcmp(res->event_value, "power_on"))
5311                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5312         else if (!strcmp(res->event_value, "power_off"))
5313                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5314         else
5315                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5316
5317         if (!strcmp(res->mode_value, "bypass"))
5318                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5319         else if (!strcmp(res->mode_value, "isolate"))
5320                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5321         else
5322                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5323
5324         /* Set the watchdog timeout. */
5325         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5326
5327                 rc = -EINVAL;
5328                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5329                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5330                                                            bypass_timeout);
5331                 }
5332                 if (rc != 0) {
5333                         printf("Failed to set timeout value %u "
5334                         "for port %d, errto code: %d.\n",
5335                         bypass_timeout, port_id, rc);
5336                 }
5337         }
5338
5339         /* Set the bypass event to transition to bypass mode. */
5340         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5341                                               bypass_mode);
5342 #endif
5343
5344         if (rc != 0)
5345                 printf("\t Failed to set bypass event for port = %d.\n",
5346                        port_id);
5347 }
5348
5349 cmdline_parse_token_string_t cmd_setbypass_event_set =
5350         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5351                         set, "set");
5352 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5353         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5354                         bypass, "bypass");
5355 cmdline_parse_token_string_t cmd_setbypass_event_event =
5356         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5357                         event, "event");
5358 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5359         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5360                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5361 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5362         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5363                         mode, "mode");
5364 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5365         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5366                         mode_value, "normal#bypass#isolate");
5367 cmdline_parse_token_num_t cmd_setbypass_event_port =
5368         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5369                                 port_id, UINT16);
5370
5371 cmdline_parse_inst_t cmd_set_bypass_event = {
5372         .f = cmd_set_bypass_event_parsed,
5373         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5374                 "power_off mode normal|bypass|isolate <port_id>: "
5375                 "Set the NIC bypass event mode for port_id",
5376         .data = NULL,
5377         .tokens = {
5378                 (void *)&cmd_setbypass_event_set,
5379                 (void *)&cmd_setbypass_event_bypass,
5380                 (void *)&cmd_setbypass_event_event,
5381                 (void *)&cmd_setbypass_event_event_value,
5382                 (void *)&cmd_setbypass_event_mode,
5383                 (void *)&cmd_setbypass_event_mode_value,
5384                 (void *)&cmd_setbypass_event_port,
5385                 NULL,
5386         },
5387 };
5388
5389
5390 /* *** SET NIC BYPASS TIMEOUT *** */
5391 struct cmd_set_bypass_timeout_result {
5392         cmdline_fixed_string_t set;
5393         cmdline_fixed_string_t bypass;
5394         cmdline_fixed_string_t timeout;
5395         cmdline_fixed_string_t value;
5396 };
5397
5398 static void
5399 cmd_set_bypass_timeout_parsed(void *parsed_result,
5400                 __attribute__((unused)) struct cmdline *cl,
5401                 __attribute__((unused)) void *data)
5402 {
5403         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5404
5405 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5406         if (!strcmp(res->value, "1.5"))
5407                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5408         else if (!strcmp(res->value, "2"))
5409                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5410         else if (!strcmp(res->value, "3"))
5411                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5412         else if (!strcmp(res->value, "4"))
5413                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5414         else if (!strcmp(res->value, "8"))
5415                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5416         else if (!strcmp(res->value, "16"))
5417                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5418         else if (!strcmp(res->value, "32"))
5419                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5420         else
5421                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5422 #endif
5423 }
5424
5425 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5426         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5427                         set, "set");
5428 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5429         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5430                         bypass, "bypass");
5431 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5432         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5433                         timeout, "timeout");
5434 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5435         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5436                         value, "0#1.5#2#3#4#8#16#32");
5437
5438 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5439         .f = cmd_set_bypass_timeout_parsed,
5440         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5441                 "Set the NIC bypass watchdog timeout in seconds",
5442         .data = NULL,
5443         .tokens = {
5444                 (void *)&cmd_setbypass_timeout_set,
5445                 (void *)&cmd_setbypass_timeout_bypass,
5446                 (void *)&cmd_setbypass_timeout_timeout,
5447                 (void *)&cmd_setbypass_timeout_value,
5448                 NULL,
5449         },
5450 };
5451
5452 /* *** SHOW NIC BYPASS MODE *** */
5453 struct cmd_show_bypass_config_result {
5454         cmdline_fixed_string_t show;
5455         cmdline_fixed_string_t bypass;
5456         cmdline_fixed_string_t config;
5457         portid_t port_id;
5458 };
5459
5460 static void
5461 cmd_show_bypass_config_parsed(void *parsed_result,
5462                 __attribute__((unused)) struct cmdline *cl,
5463                 __attribute__((unused)) void *data)
5464 {
5465         struct cmd_show_bypass_config_result *res = parsed_result;
5466         portid_t port_id = res->port_id;
5467         int rc = -EINVAL;
5468 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5469         uint32_t event_mode;
5470         uint32_t bypass_mode;
5471         uint32_t timeout = bypass_timeout;
5472         int i;
5473
5474         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5475                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5476         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5477                 {"UNKNOWN", "normal", "bypass", "isolate"};
5478         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5479                 "NONE",
5480                 "OS/board on",
5481                 "power supply on",
5482                 "OS/board off",
5483                 "power supply off",
5484                 "timeout"};
5485         int num_events = (sizeof events) / (sizeof events[0]);
5486
5487         /* Display the bypass mode.*/
5488         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5489                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5490                 return;
5491         }
5492         else {
5493                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5494                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5495
5496                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5497         }
5498
5499         /* Display the bypass timeout.*/
5500         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5501                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5502
5503         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5504
5505         /* Display the bypass events and associated modes. */
5506         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5507
5508                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5509                         printf("\tFailed to get bypass mode for event = %s\n",
5510                                 events[i]);
5511                 } else {
5512                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5513                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5514
5515                         printf("\tbypass event: %-16s = %s\n", events[i],
5516                                 modes[event_mode]);
5517                 }
5518         }
5519 #endif
5520         if (rc != 0)
5521                 printf("\tFailed to get bypass configuration for port = %d\n",
5522                        port_id);
5523 }
5524
5525 cmdline_parse_token_string_t cmd_showbypass_config_show =
5526         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5527                         show, "show");
5528 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5529         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5530                         bypass, "bypass");
5531 cmdline_parse_token_string_t cmd_showbypass_config_config =
5532         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5533                         config, "config");
5534 cmdline_parse_token_num_t cmd_showbypass_config_port =
5535         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5536                                 port_id, UINT16);
5537
5538 cmdline_parse_inst_t cmd_show_bypass_config = {
5539         .f = cmd_show_bypass_config_parsed,
5540         .help_str = "show bypass config <port_id>: "
5541                     "Show the NIC bypass config for port_id",
5542         .data = NULL,
5543         .tokens = {
5544                 (void *)&cmd_showbypass_config_show,
5545                 (void *)&cmd_showbypass_config_bypass,
5546                 (void *)&cmd_showbypass_config_config,
5547                 (void *)&cmd_showbypass_config_port,
5548                 NULL,
5549         },
5550 };
5551
5552 #ifdef RTE_LIBRTE_PMD_BOND
5553 /* *** SET BONDING MODE *** */
5554 struct cmd_set_bonding_mode_result {
5555         cmdline_fixed_string_t set;
5556         cmdline_fixed_string_t bonding;
5557         cmdline_fixed_string_t mode;
5558         uint8_t value;
5559         portid_t port_id;
5560 };
5561
5562 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5563                 __attribute__((unused))  struct cmdline *cl,
5564                 __attribute__((unused)) void *data)
5565 {
5566         struct cmd_set_bonding_mode_result *res = parsed_result;
5567         portid_t port_id = res->port_id;
5568
5569         /* Set the bonding mode for the relevant port. */
5570         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5571                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5572 }
5573
5574 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5575 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5576                 set, "set");
5577 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5578 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5579                 bonding, "bonding");
5580 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5581 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5582                 mode, "mode");
5583 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5584 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5585                 value, UINT8);
5586 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5587 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5588                 port_id, UINT16);
5589
5590 cmdline_parse_inst_t cmd_set_bonding_mode = {
5591                 .f = cmd_set_bonding_mode_parsed,
5592                 .help_str = "set bonding mode <mode_value> <port_id>: "
5593                         "Set the bonding mode for port_id",
5594                 .data = NULL,
5595                 .tokens = {
5596                                 (void *) &cmd_setbonding_mode_set,
5597                                 (void *) &cmd_setbonding_mode_bonding,
5598                                 (void *) &cmd_setbonding_mode_mode,
5599                                 (void *) &cmd_setbonding_mode_value,
5600                                 (void *) &cmd_setbonding_mode_port,
5601                                 NULL
5602                 }
5603 };
5604
5605 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5606 struct cmd_set_bonding_lacp_dedicated_queues_result {
5607         cmdline_fixed_string_t set;
5608         cmdline_fixed_string_t bonding;
5609         cmdline_fixed_string_t lacp;
5610         cmdline_fixed_string_t dedicated_queues;
5611         portid_t port_id;
5612         cmdline_fixed_string_t mode;
5613 };
5614
5615 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5616                 __attribute__((unused))  struct cmdline *cl,
5617                 __attribute__((unused)) void *data)
5618 {
5619         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5620         portid_t port_id = res->port_id;
5621         struct rte_port *port;
5622
5623         port = &ports[port_id];
5624
5625         /** Check if the port is not started **/
5626         if (port->port_status != RTE_PORT_STOPPED) {
5627                 printf("Please stop port %d first\n", port_id);
5628                 return;
5629         }
5630
5631         if (!strcmp(res->mode, "enable")) {
5632                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5633                         printf("Dedicate queues for LACP control packets"
5634                                         " enabled\n");
5635                 else
5636                         printf("Enabling dedicate queues for LACP control "
5637                                         "packets on port %d failed\n", port_id);
5638         } else if (!strcmp(res->mode, "disable")) {
5639                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5640                         printf("Dedicated queues for LACP control packets "
5641                                         "disabled\n");
5642                 else
5643                         printf("Disabling dedicated queues for LACP control "
5644                                         "traffic on port %d failed\n", port_id);
5645         }
5646 }
5647
5648 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5649 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5650                 set, "set");
5651 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5652 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5653                 bonding, "bonding");
5654 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5655 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5656                 lacp, "lacp");
5657 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5658 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5659                 dedicated_queues, "dedicated_queues");
5660 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5661 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5662                 port_id, UINT16);
5663 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5664 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5665                 mode, "enable#disable");
5666
5667 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5668                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5669                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5670                         "enable|disable: "
5671                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5672                 .data = NULL,
5673                 .tokens = {
5674                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5675                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5676                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5677                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5678                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5679                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5680                         NULL
5681                 }
5682 };
5683
5684 /* *** SET BALANCE XMIT POLICY *** */
5685 struct cmd_set_bonding_balance_xmit_policy_result {
5686         cmdline_fixed_string_t set;
5687         cmdline_fixed_string_t bonding;
5688         cmdline_fixed_string_t balance_xmit_policy;
5689         portid_t port_id;
5690         cmdline_fixed_string_t policy;
5691 };
5692
5693 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5694                 __attribute__((unused))  struct cmdline *cl,
5695                 __attribute__((unused)) void *data)
5696 {
5697         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5698         portid_t port_id = res->port_id;
5699         uint8_t policy;
5700
5701         if (!strcmp(res->policy, "l2")) {
5702                 policy = BALANCE_XMIT_POLICY_LAYER2;
5703         } else if (!strcmp(res->policy, "l23")) {
5704                 policy = BALANCE_XMIT_POLICY_LAYER23;
5705         } else if (!strcmp(res->policy, "l34")) {
5706                 policy = BALANCE_XMIT_POLICY_LAYER34;
5707         } else {
5708                 printf("\t Invalid xmit policy selection");
5709                 return;
5710         }
5711
5712         /* Set the bonding mode for the relevant port. */
5713         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5714                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5715                                 port_id);
5716         }
5717 }
5718
5719 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5720 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5721                 set, "set");
5722 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5723 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5724                 bonding, "bonding");
5725 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5726 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5727                 balance_xmit_policy, "balance_xmit_policy");
5728 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5729 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5730                 port_id, UINT16);
5731 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5732 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5733                 policy, "l2#l23#l34");
5734
5735 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5736                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5737                 .help_str = "set bonding balance_xmit_policy <port_id> "
5738                         "l2|l23|l34: "
5739                         "Set the bonding balance_xmit_policy for port_id",
5740                 .data = NULL,
5741                 .tokens = {
5742                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5743                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5744                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5745                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5746                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5747                                 NULL
5748                 }
5749 };
5750
5751 /* *** SHOW NIC BONDING CONFIGURATION *** */
5752 struct cmd_show_bonding_config_result {
5753         cmdline_fixed_string_t show;
5754         cmdline_fixed_string_t bonding;
5755         cmdline_fixed_string_t config;
5756         portid_t port_id;
5757 };
5758
5759 static void cmd_show_bonding_config_parsed(void *parsed_result,
5760                 __attribute__((unused))  struct cmdline *cl,
5761                 __attribute__((unused)) void *data)
5762 {
5763         struct cmd_show_bonding_config_result *res = parsed_result;
5764         int bonding_mode, agg_mode;
5765         portid_t slaves[RTE_MAX_ETHPORTS];
5766         int num_slaves, num_active_slaves;
5767         int primary_id;
5768         int i;
5769         portid_t port_id = res->port_id;
5770
5771         /* Display the bonding mode.*/
5772         bonding_mode = rte_eth_bond_mode_get(port_id);
5773         if (bonding_mode < 0) {
5774                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5775                 return;
5776         } else
5777                 printf("\tBonding mode: %d\n", bonding_mode);
5778
5779         if (bonding_mode == BONDING_MODE_BALANCE) {
5780                 int balance_xmit_policy;
5781
5782                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5783                 if (balance_xmit_policy < 0) {
5784                         printf("\tFailed to get balance xmit policy for port = %d\n",
5785                                         port_id);
5786                         return;
5787                 } else {
5788                         printf("\tBalance Xmit Policy: ");
5789
5790                         switch (balance_xmit_policy) {
5791                         case BALANCE_XMIT_POLICY_LAYER2:
5792                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5793                                 break;
5794                         case BALANCE_XMIT_POLICY_LAYER23:
5795                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5796                                 break;
5797                         case BALANCE_XMIT_POLICY_LAYER34:
5798                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5799                                 break;
5800                         }
5801                         printf("\n");
5802                 }
5803         }
5804
5805         if (bonding_mode == BONDING_MODE_8023AD) {
5806                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5807                 printf("\tIEEE802.3AD Aggregator Mode: ");
5808                 switch (agg_mode) {
5809                 case AGG_BANDWIDTH:
5810                         printf("bandwidth");
5811                         break;
5812                 case AGG_STABLE:
5813                         printf("stable");
5814                         break;
5815                 case AGG_COUNT:
5816                         printf("count");
5817                         break;
5818                 }
5819                 printf("\n");
5820         }
5821
5822         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5823
5824         if (num_slaves < 0) {
5825                 printf("\tFailed to get slave list for port = %d\n", port_id);
5826                 return;
5827         }
5828         if (num_slaves > 0) {
5829                 printf("\tSlaves (%d): [", num_slaves);
5830                 for (i = 0; i < num_slaves - 1; i++)
5831                         printf("%d ", slaves[i]);
5832
5833                 printf("%d]\n", slaves[num_slaves - 1]);
5834         } else {
5835                 printf("\tSlaves: []\n");
5836
5837         }
5838
5839         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5840                         RTE_MAX_ETHPORTS);
5841
5842         if (num_active_slaves < 0) {
5843                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5844                 return;
5845         }
5846         if (num_active_slaves > 0) {
5847                 printf("\tActive Slaves (%d): [", num_active_slaves);
5848                 for (i = 0; i < num_active_slaves - 1; i++)
5849                         printf("%d ", slaves[i]);
5850
5851                 printf("%d]\n", slaves[num_active_slaves - 1]);
5852
5853         } else {
5854                 printf("\tActive Slaves: []\n");
5855
5856         }
5857
5858         primary_id = rte_eth_bond_primary_get(port_id);
5859         if (primary_id < 0) {
5860                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5861                 return;
5862         } else
5863                 printf("\tPrimary: [%d]\n", primary_id);
5864
5865 }
5866
5867 cmdline_parse_token_string_t cmd_showbonding_config_show =
5868 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5869                 show, "show");
5870 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5871 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5872                 bonding, "bonding");
5873 cmdline_parse_token_string_t cmd_showbonding_config_config =
5874 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5875                 config, "config");
5876 cmdline_parse_token_num_t cmd_showbonding_config_port =
5877 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5878                 port_id, UINT16);
5879
5880 cmdline_parse_inst_t cmd_show_bonding_config = {
5881                 .f = cmd_show_bonding_config_parsed,
5882                 .help_str = "show bonding config <port_id>: "
5883                         "Show the bonding config for port_id",
5884                 .data = NULL,
5885                 .tokens = {
5886                                 (void *)&cmd_showbonding_config_show,
5887                                 (void *)&cmd_showbonding_config_bonding,
5888                                 (void *)&cmd_showbonding_config_config,
5889                                 (void *)&cmd_showbonding_config_port,
5890                                 NULL
5891                 }
5892 };
5893
5894 /* *** SET BONDING PRIMARY *** */
5895 struct cmd_set_bonding_primary_result {
5896         cmdline_fixed_string_t set;
5897         cmdline_fixed_string_t bonding;
5898         cmdline_fixed_string_t primary;
5899         portid_t slave_id;
5900         portid_t port_id;
5901 };
5902
5903 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5904                 __attribute__((unused))  struct cmdline *cl,
5905                 __attribute__((unused)) void *data)
5906 {
5907         struct cmd_set_bonding_primary_result *res = parsed_result;
5908         portid_t master_port_id = res->port_id;
5909         portid_t slave_port_id = res->slave_id;
5910
5911         /* Set the primary slave for a bonded device. */
5912         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5913                 printf("\t Failed to set primary slave for port = %d.\n",
5914                                 master_port_id);
5915                 return;
5916         }
5917         init_port_config();
5918 }
5919
5920 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5921 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5922                 set, "set");
5923 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5924 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5925                 bonding, "bonding");
5926 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5928                 primary, "primary");
5929 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5930 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5931                 slave_id, UINT16);
5932 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5933 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5934                 port_id, UINT16);
5935
5936 cmdline_parse_inst_t cmd_set_bonding_primary = {
5937                 .f = cmd_set_bonding_primary_parsed,
5938                 .help_str = "set bonding primary <slave_id> <port_id>: "
5939                         "Set the primary slave for port_id",
5940                 .data = NULL,
5941                 .tokens = {
5942                                 (void *)&cmd_setbonding_primary_set,
5943                                 (void *)&cmd_setbonding_primary_bonding,
5944                                 (void *)&cmd_setbonding_primary_primary,
5945                                 (void *)&cmd_setbonding_primary_slave,
5946                                 (void *)&cmd_setbonding_primary_port,
5947                                 NULL
5948                 }
5949 };
5950
5951 /* *** ADD SLAVE *** */
5952 struct cmd_add_bonding_slave_result {
5953         cmdline_fixed_string_t add;
5954         cmdline_fixed_string_t bonding;
5955         cmdline_fixed_string_t slave;
5956         portid_t slave_id;
5957         portid_t port_id;
5958 };
5959
5960 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5961                 __attribute__((unused))  struct cmdline *cl,
5962                 __attribute__((unused)) void *data)
5963 {
5964         struct cmd_add_bonding_slave_result *res = parsed_result;
5965         portid_t master_port_id = res->port_id;
5966         portid_t slave_port_id = res->slave_id;
5967
5968         /* add the slave for a bonded device. */
5969         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5970                 printf("\t Failed to add slave %d to master port = %d.\n",
5971                                 slave_port_id, master_port_id);
5972                 return;
5973         }
5974         init_port_config();
5975         set_port_slave_flag(slave_port_id);
5976 }
5977
5978 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5979 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5980                 add, "add");
5981 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5982 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5983                 bonding, "bonding");
5984 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5985 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5986                 slave, "slave");
5987 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5988 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5989                 slave_id, UINT16);
5990 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5991 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5992                 port_id, UINT16);
5993
5994 cmdline_parse_inst_t cmd_add_bonding_slave = {
5995                 .f = cmd_add_bonding_slave_parsed,
5996                 .help_str = "add bonding slave <slave_id> <port_id>: "
5997                         "Add a slave device to a bonded device",
5998                 .data = NULL,
5999                 .tokens = {
6000                                 (void *)&cmd_addbonding_slave_add,
6001                                 (void *)&cmd_addbonding_slave_bonding,
6002                                 (void *)&cmd_addbonding_slave_slave,
6003                                 (void *)&cmd_addbonding_slave_slaveid,
6004                                 (void *)&cmd_addbonding_slave_port,
6005                                 NULL
6006                 }
6007 };
6008
6009 /* *** REMOVE SLAVE *** */
6010 struct cmd_remove_bonding_slave_result {
6011         cmdline_fixed_string_t remove;
6012         cmdline_fixed_string_t bonding;
6013         cmdline_fixed_string_t slave;
6014         portid_t slave_id;
6015         portid_t port_id;
6016 };
6017
6018 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6019                 __attribute__((unused))  struct cmdline *cl,
6020                 __attribute__((unused)) void *data)
6021 {
6022         struct cmd_remove_bonding_slave_result *res = parsed_result;
6023         portid_t master_port_id = res->port_id;
6024         portid_t slave_port_id = res->slave_id;
6025
6026         /* remove the slave from a bonded device. */
6027         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6028                 printf("\t Failed to remove slave %d from master port = %d.\n",
6029                                 slave_port_id, master_port_id);
6030                 return;
6031         }
6032         init_port_config();
6033         clear_port_slave_flag(slave_port_id);
6034 }
6035
6036 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6037                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6038                                 remove, "remove");
6039 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6040                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6041                                 bonding, "bonding");
6042 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6043                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6044                                 slave, "slave");
6045 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6046                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6047                                 slave_id, UINT16);
6048 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6049                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6050                                 port_id, UINT16);
6051
6052 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6053                 .f = cmd_remove_bonding_slave_parsed,
6054                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6055                         "Remove a slave device from a bonded device",
6056                 .data = NULL,
6057                 .tokens = {
6058                                 (void *)&cmd_removebonding_slave_remove,
6059                                 (void *)&cmd_removebonding_slave_bonding,
6060                                 (void *)&cmd_removebonding_slave_slave,
6061                                 (void *)&cmd_removebonding_slave_slaveid,
6062                                 (void *)&cmd_removebonding_slave_port,
6063                                 NULL
6064                 }
6065 };
6066
6067 /* *** CREATE BONDED DEVICE *** */
6068 struct cmd_create_bonded_device_result {
6069         cmdline_fixed_string_t create;
6070         cmdline_fixed_string_t bonded;
6071         cmdline_fixed_string_t device;
6072         uint8_t mode;
6073         uint8_t socket;
6074 };
6075
6076 static int bond_dev_num = 0;
6077
6078 static void cmd_create_bonded_device_parsed(void *parsed_result,
6079                 __attribute__((unused))  struct cmdline *cl,
6080                 __attribute__((unused)) void *data)
6081 {
6082         struct cmd_create_bonded_device_result *res = parsed_result;
6083         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6084         int port_id;
6085         int ret;
6086
6087         if (test_done == 0) {
6088                 printf("Please stop forwarding first\n");
6089                 return;
6090         }
6091
6092         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6093                         bond_dev_num++);
6094
6095         /* Create a new bonded device. */
6096         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6097         if (port_id < 0) {
6098                 printf("\t Failed to create bonded device.\n");
6099                 return;
6100         } else {
6101                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6102                                 port_id);
6103
6104                 /* Update number of ports */
6105                 nb_ports = rte_eth_dev_count_avail();
6106                 reconfig(port_id, res->socket);
6107                 ret = rte_eth_promiscuous_enable(port_id);
6108                 if (ret != 0)
6109                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6110                                 port_id, rte_strerror(-ret));
6111
6112                 ports[port_id].need_setup = 0;
6113                 ports[port_id].port_status = RTE_PORT_STOPPED;
6114         }
6115
6116 }
6117
6118 cmdline_parse_token_string_t cmd_createbonded_device_create =
6119                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6120                                 create, "create");
6121 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6122                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6123                                 bonded, "bonded");
6124 cmdline_parse_token_string_t cmd_createbonded_device_device =
6125                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6126                                 device, "device");
6127 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6128                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6129                                 mode, UINT8);
6130 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6131                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6132                                 socket, UINT8);
6133
6134 cmdline_parse_inst_t cmd_create_bonded_device = {
6135                 .f = cmd_create_bonded_device_parsed,
6136                 .help_str = "create bonded device <mode> <socket>: "
6137                         "Create a new bonded device with specific bonding mode and socket",
6138                 .data = NULL,
6139                 .tokens = {
6140                                 (void *)&cmd_createbonded_device_create,
6141                                 (void *)&cmd_createbonded_device_bonded,
6142                                 (void *)&cmd_createbonded_device_device,
6143                                 (void *)&cmd_createbonded_device_mode,
6144                                 (void *)&cmd_createbonded_device_socket,
6145                                 NULL
6146                 }
6147 };
6148
6149 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6150 struct cmd_set_bond_mac_addr_result {
6151         cmdline_fixed_string_t set;
6152         cmdline_fixed_string_t bonding;
6153         cmdline_fixed_string_t mac_addr;
6154         uint16_t port_num;
6155         struct rte_ether_addr address;
6156 };
6157
6158 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6159                 __attribute__((unused))  struct cmdline *cl,
6160                 __attribute__((unused)) void *data)
6161 {
6162         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6163         int ret;
6164
6165         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6166                 return;
6167
6168         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6169
6170         /* check the return value and print it if is < 0 */
6171         if (ret < 0)
6172                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6173 }
6174
6175 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6176                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6177 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6178                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6179                                 "bonding");
6180 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6181                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6182                                 "mac_addr");
6183 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6184                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6185                                 port_num, UINT16);
6186 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6187                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6188
6189 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6190                 .f = cmd_set_bond_mac_addr_parsed,
6191                 .data = (void *) 0,
6192                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6193                 .tokens = {
6194                                 (void *)&cmd_set_bond_mac_addr_set,
6195                                 (void *)&cmd_set_bond_mac_addr_bonding,
6196                                 (void *)&cmd_set_bond_mac_addr_mac,
6197                                 (void *)&cmd_set_bond_mac_addr_portnum,
6198                                 (void *)&cmd_set_bond_mac_addr_addr,
6199                                 NULL
6200                 }
6201 };
6202
6203
6204 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6205 struct cmd_set_bond_mon_period_result {
6206         cmdline_fixed_string_t set;
6207         cmdline_fixed_string_t bonding;
6208         cmdline_fixed_string_t mon_period;
6209         uint16_t port_num;
6210         uint32_t period_ms;
6211 };
6212
6213 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6214                 __attribute__((unused))  struct cmdline *cl,
6215                 __attribute__((unused)) void *data)
6216 {
6217         struct cmd_set_bond_mon_period_result *res = parsed_result;
6218         int ret;
6219
6220         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6221
6222         /* check the return value and print it if is < 0 */
6223         if (ret < 0)
6224                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6225 }
6226
6227 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6228                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6229                                 set, "set");
6230 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6231                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6232                                 bonding, "bonding");
6233 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6234                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6235                                 mon_period,     "mon_period");
6236 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6237                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6238                                 port_num, UINT16);
6239 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6240                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6241                                 period_ms, UINT32);
6242
6243 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6244                 .f = cmd_set_bond_mon_period_parsed,
6245                 .data = (void *) 0,
6246                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6247                 .tokens = {
6248                                 (void *)&cmd_set_bond_mon_period_set,
6249                                 (void *)&cmd_set_bond_mon_period_bonding,
6250                                 (void *)&cmd_set_bond_mon_period_mon_period,
6251                                 (void *)&cmd_set_bond_mon_period_portnum,
6252                                 (void *)&cmd_set_bond_mon_period_period_ms,
6253                                 NULL
6254                 }
6255 };
6256
6257
6258
6259 struct cmd_set_bonding_agg_mode_policy_result {
6260         cmdline_fixed_string_t set;
6261         cmdline_fixed_string_t bonding;
6262         cmdline_fixed_string_t agg_mode;
6263         uint16_t port_num;
6264         cmdline_fixed_string_t policy;
6265 };
6266
6267
6268 static void
6269 cmd_set_bonding_agg_mode(void *parsed_result,
6270                 __attribute__((unused)) struct cmdline *cl,
6271                 __attribute__((unused)) void *data)
6272 {
6273         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6274         uint8_t policy = AGG_BANDWIDTH;
6275
6276         if (!strcmp(res->policy, "bandwidth"))
6277                 policy = AGG_BANDWIDTH;
6278         else if (!strcmp(res->policy, "stable"))
6279                 policy = AGG_STABLE;
6280         else if (!strcmp(res->policy, "count"))
6281                 policy = AGG_COUNT;
6282
6283         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6284 }
6285
6286
6287 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6288         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6289                                 set, "set");
6290 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6291         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6292                                 bonding, "bonding");
6293
6294 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6295         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6296                                 agg_mode, "agg_mode");
6297
6298 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6299         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6300                                 port_num, UINT16);
6301
6302 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6303         TOKEN_STRING_INITIALIZER(
6304                         struct cmd_set_bonding_balance_xmit_policy_result,
6305                 policy, "stable#bandwidth#count");
6306
6307 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6308         .f = cmd_set_bonding_agg_mode,
6309         .data = (void *) 0,
6310         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6311         .tokens = {
6312                         (void *)&cmd_set_bonding_agg_mode_set,
6313                         (void *)&cmd_set_bonding_agg_mode_bonding,
6314                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6315                         (void *)&cmd_set_bonding_agg_mode_portnum,
6316                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6317                         NULL
6318                 }
6319 };
6320
6321
6322 #endif /* RTE_LIBRTE_PMD_BOND */
6323
6324 /* *** SET FORWARDING MODE *** */
6325 struct cmd_set_fwd_mode_result {
6326         cmdline_fixed_string_t set;
6327         cmdline_fixed_string_t fwd;
6328         cmdline_fixed_string_t mode;
6329 };
6330
6331 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6332                                     __attribute__((unused)) struct cmdline *cl,
6333                                     __attribute__((unused)) void *data)
6334 {
6335         struct cmd_set_fwd_mode_result *res = parsed_result;
6336
6337         retry_enabled = 0;
6338         set_pkt_forwarding_mode(res->mode);
6339 }
6340
6341 cmdline_parse_token_string_t cmd_setfwd_set =
6342         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6343 cmdline_parse_token_string_t cmd_setfwd_fwd =
6344         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6345 cmdline_parse_token_string_t cmd_setfwd_mode =
6346         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6347                 "" /* defined at init */);
6348
6349 cmdline_parse_inst_t cmd_set_fwd_mode = {
6350         .f = cmd_set_fwd_mode_parsed,
6351         .data = NULL,
6352         .help_str = NULL, /* defined at init */
6353         .tokens = {
6354                 (void *)&cmd_setfwd_set,
6355                 (void *)&cmd_setfwd_fwd,
6356                 (void *)&cmd_setfwd_mode,
6357                 NULL,
6358         },
6359 };
6360
6361 static void cmd_set_fwd_mode_init(void)
6362 {
6363         char *modes, *c;
6364         static char token[128];
6365         static char help[256];
6366         cmdline_parse_token_string_t *token_struct;
6367
6368         modes = list_pkt_forwarding_modes();
6369         snprintf(help, sizeof(help), "set fwd %s: "
6370                 "Set packet forwarding mode", modes);
6371         cmd_set_fwd_mode.help_str = help;
6372
6373         /* string token separator is # */
6374         for (c = token; *modes != '\0'; modes++)
6375                 if (*modes == '|')
6376                         *c++ = '#';
6377                 else
6378                         *c++ = *modes;
6379         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6380         token_struct->string_data.str = token;
6381 }
6382
6383 /* *** SET RETRY FORWARDING MODE *** */
6384 struct cmd_set_fwd_retry_mode_result {
6385         cmdline_fixed_string_t set;
6386         cmdline_fixed_string_t fwd;
6387         cmdline_fixed_string_t mode;
6388         cmdline_fixed_string_t retry;
6389 };
6390
6391 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6392                             __attribute__((unused)) struct cmdline *cl,
6393                             __attribute__((unused)) void *data)
6394 {
6395         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6396
6397         retry_enabled = 1;
6398         set_pkt_forwarding_mode(res->mode);
6399 }
6400
6401 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6402         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6403                         set, "set");
6404 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6405         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6406                         fwd, "fwd");
6407 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6408         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6409                         mode,
6410                 "" /* defined at init */);
6411 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6412         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6413                         retry, "retry");
6414
6415 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6416         .f = cmd_set_fwd_retry_mode_parsed,
6417         .data = NULL,
6418         .help_str = NULL, /* defined at init */
6419         .tokens = {
6420                 (void *)&cmd_setfwd_retry_set,
6421                 (void *)&cmd_setfwd_retry_fwd,
6422                 (void *)&cmd_setfwd_retry_mode,
6423                 (void *)&cmd_setfwd_retry_retry,
6424                 NULL,
6425         },
6426 };
6427
6428 static void cmd_set_fwd_retry_mode_init(void)
6429 {
6430         char *modes, *c;
6431         static char token[128];
6432         static char help[256];
6433         cmdline_parse_token_string_t *token_struct;
6434
6435         modes = list_pkt_forwarding_retry_modes();
6436         snprintf(help, sizeof(help), "set fwd %s retry: "
6437                 "Set packet forwarding mode with retry", modes);
6438         cmd_set_fwd_retry_mode.help_str = help;
6439
6440         /* string token separator is # */
6441         for (c = token; *modes != '\0'; modes++)
6442                 if (*modes == '|')
6443                         *c++ = '#';
6444                 else
6445                         *c++ = *modes;
6446         token_struct = (cmdline_parse_token_string_t *)
6447                 cmd_set_fwd_retry_mode.tokens[2];
6448         token_struct->string_data.str = token;
6449 }
6450
6451 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6452 struct cmd_set_burst_tx_retry_result {
6453         cmdline_fixed_string_t set;
6454         cmdline_fixed_string_t burst;
6455         cmdline_fixed_string_t tx;
6456         cmdline_fixed_string_t delay;
6457         uint32_t time;
6458         cmdline_fixed_string_t retry;
6459         uint32_t retry_num;
6460 };
6461
6462 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6463                                         __attribute__((unused)) struct cmdline *cl,
6464                                         __attribute__((unused)) void *data)
6465 {
6466         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6467
6468         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6469                 && !strcmp(res->tx, "tx")) {
6470                 if (!strcmp(res->delay, "delay"))
6471                         burst_tx_delay_time = res->time;
6472                 if (!strcmp(res->retry, "retry"))
6473                         burst_tx_retry_num = res->retry_num;
6474         }
6475
6476 }
6477
6478 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6479         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6480 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6481         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6482                                  "burst");
6483 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6484         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6485 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6486         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6487 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6488         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6489 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6490         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6491 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6492         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6493
6494 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6495         .f = cmd_set_burst_tx_retry_parsed,
6496         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6497         .tokens = {
6498                 (void *)&cmd_set_burst_tx_retry_set,
6499                 (void *)&cmd_set_burst_tx_retry_burst,
6500                 (void *)&cmd_set_burst_tx_retry_tx,
6501                 (void *)&cmd_set_burst_tx_retry_delay,
6502                 (void *)&cmd_set_burst_tx_retry_time,
6503                 (void *)&cmd_set_burst_tx_retry_retry,
6504                 (void *)&cmd_set_burst_tx_retry_retry_num,
6505                 NULL,
6506         },
6507 };
6508
6509 /* *** SET PROMISC MODE *** */
6510 struct cmd_set_promisc_mode_result {
6511         cmdline_fixed_string_t set;
6512         cmdline_fixed_string_t promisc;
6513         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6514         uint16_t port_num;               /* valid if "allports" argument == 0 */
6515         cmdline_fixed_string_t mode;
6516 };
6517
6518 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6519                                         __attribute__((unused)) struct cmdline *cl,
6520                                         void *allports)
6521 {
6522         struct cmd_set_promisc_mode_result *res = parsed_result;
6523         int enable;
6524         portid_t i;
6525
6526         if (!strcmp(res->mode, "on"))
6527                 enable = 1;
6528         else
6529                 enable = 0;
6530
6531         /* all ports */
6532         if (allports) {
6533                 RTE_ETH_FOREACH_DEV(i)
6534                         eth_set_promisc_mode(i, enable);
6535         } else {
6536                 eth_set_promisc_mode(res->port_num, enable);
6537         }
6538 }
6539
6540 cmdline_parse_token_string_t cmd_setpromisc_set =
6541         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6542 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6543         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6544                                  "promisc");
6545 cmdline_parse_token_string_t cmd_setpromisc_portall =
6546         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6547                                  "all");
6548 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6549         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6550                               UINT16);
6551 cmdline_parse_token_string_t cmd_setpromisc_mode =
6552         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6553                                  "on#off");
6554
6555 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6556         .f = cmd_set_promisc_mode_parsed,
6557         .data = (void *)1,
6558         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6559         .tokens = {
6560                 (void *)&cmd_setpromisc_set,
6561                 (void *)&cmd_setpromisc_promisc,
6562                 (void *)&cmd_setpromisc_portall,
6563                 (void *)&cmd_setpromisc_mode,
6564                 NULL,
6565         },
6566 };
6567
6568 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6569         .f = cmd_set_promisc_mode_parsed,
6570         .data = (void *)0,
6571         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6572         .tokens = {
6573                 (void *)&cmd_setpromisc_set,
6574                 (void *)&cmd_setpromisc_promisc,
6575                 (void *)&cmd_setpromisc_portnum,
6576                 (void *)&cmd_setpromisc_mode,
6577                 NULL,
6578         },
6579 };
6580
6581 /* *** SET ALLMULTI MODE *** */
6582 struct cmd_set_allmulti_mode_result {
6583         cmdline_fixed_string_t set;
6584         cmdline_fixed_string_t allmulti;
6585         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6586         uint16_t port_num;               /* valid if "allports" argument == 0 */
6587         cmdline_fixed_string_t mode;
6588 };
6589
6590 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6591                                         __attribute__((unused)) struct cmdline *cl,
6592                                         void *allports)
6593 {
6594         struct cmd_set_allmulti_mode_result *res = parsed_result;
6595         int enable;
6596         portid_t i;
6597
6598         if (!strcmp(res->mode, "on"))
6599                 enable = 1;
6600         else
6601                 enable = 0;
6602
6603         /* all ports */
6604         if (allports) {
6605                 RTE_ETH_FOREACH_DEV(i) {
6606                         eth_set_allmulticast_mode(i, enable);
6607                 }
6608         }
6609         else {
6610                 eth_set_allmulticast_mode(res->port_num, enable);
6611         }
6612 }
6613
6614 cmdline_parse_token_string_t cmd_setallmulti_set =
6615         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6616 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6617         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6618                                  "allmulti");
6619 cmdline_parse_token_string_t cmd_setallmulti_portall =
6620         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6621                                  "all");
6622 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6623         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6624                               UINT16);
6625 cmdline_parse_token_string_t cmd_setallmulti_mode =
6626         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6627                                  "on#off");
6628
6629 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6630         .f = cmd_set_allmulti_mode_parsed,
6631         .data = (void *)1,
6632         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6633         .tokens = {
6634                 (void *)&cmd_setallmulti_set,
6635                 (void *)&cmd_setallmulti_allmulti,
6636                 (void *)&cmd_setallmulti_portall,
6637                 (void *)&cmd_setallmulti_mode,
6638                 NULL,
6639         },
6640 };
6641
6642 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6643         .f = cmd_set_allmulti_mode_parsed,
6644         .data = (void *)0,
6645         .help_str = "set allmulti <port_id> on|off: "
6646                 "Set allmulti mode on port_id",
6647         .tokens = {
6648                 (void *)&cmd_setallmulti_set,
6649                 (void *)&cmd_setallmulti_allmulti,
6650                 (void *)&cmd_setallmulti_portnum,
6651                 (void *)&cmd_setallmulti_mode,
6652                 NULL,
6653         },
6654 };
6655
6656 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6657 struct cmd_link_flow_ctrl_set_result {
6658         cmdline_fixed_string_t set;
6659         cmdline_fixed_string_t flow_ctrl;
6660         cmdline_fixed_string_t rx;
6661         cmdline_fixed_string_t rx_lfc_mode;
6662         cmdline_fixed_string_t tx;
6663         cmdline_fixed_string_t tx_lfc_mode;
6664         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6665         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6666         cmdline_fixed_string_t autoneg_str;
6667         cmdline_fixed_string_t autoneg;
6668         cmdline_fixed_string_t hw_str;
6669         uint32_t high_water;
6670         cmdline_fixed_string_t lw_str;
6671         uint32_t low_water;
6672         cmdline_fixed_string_t pt_str;
6673         uint16_t pause_time;
6674         cmdline_fixed_string_t xon_str;
6675         uint16_t send_xon;
6676         portid_t port_id;
6677 };
6678
6679 cmdline_parse_token_string_t cmd_lfc_set_set =
6680         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6681                                 set, "set");
6682 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6683         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6684                                 flow_ctrl, "flow_ctrl");
6685 cmdline_parse_token_string_t cmd_lfc_set_rx =
6686         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6687                                 rx, "rx");
6688 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6689         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6690                                 rx_lfc_mode, "on#off");
6691 cmdline_parse_token_string_t cmd_lfc_set_tx =
6692         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6693                                 tx, "tx");
6694 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6695         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6696                                 tx_lfc_mode, "on#off");
6697 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6698         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6699                                 hw_str, "high_water");
6700 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6701         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6702                                 high_water, UINT32);
6703 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6704         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6705                                 lw_str, "low_water");
6706 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6707         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6708                                 low_water, UINT32);
6709 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6710         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6711                                 pt_str, "pause_time");
6712 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6713         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6714                                 pause_time, UINT16);
6715 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6716         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6717                                 xon_str, "send_xon");
6718 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6719         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6720                                 send_xon, UINT16);
6721 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6722         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6723                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6724 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6725         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6726                                 mac_ctrl_frame_fwd_mode, "on#off");
6727 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6728         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6729                                 autoneg_str, "autoneg");
6730 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6731         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6732                                 autoneg, "on#off");
6733 cmdline_parse_token_num_t cmd_lfc_set_portid =
6734         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6735                                 port_id, UINT16);
6736
6737 /* forward declaration */
6738 static void
6739 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6740                               void *data);
6741
6742 cmdline_parse_inst_t cmd_link_flow_control_set = {
6743         .f = cmd_link_flow_ctrl_set_parsed,
6744         .data = NULL,
6745         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6746                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6747                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6748         .tokens = {
6749                 (void *)&cmd_lfc_set_set,
6750                 (void *)&cmd_lfc_set_flow_ctrl,
6751                 (void *)&cmd_lfc_set_rx,
6752                 (void *)&cmd_lfc_set_rx_mode,
6753                 (void *)&cmd_lfc_set_tx,
6754                 (void *)&cmd_lfc_set_tx_mode,
6755                 (void *)&cmd_lfc_set_high_water,
6756                 (void *)&cmd_lfc_set_low_water,
6757                 (void *)&cmd_lfc_set_pause_time,
6758                 (void *)&cmd_lfc_set_send_xon,
6759                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6760                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6761                 (void *)&cmd_lfc_set_autoneg_str,
6762                 (void *)&cmd_lfc_set_autoneg,
6763                 (void *)&cmd_lfc_set_portid,
6764                 NULL,
6765         },
6766 };
6767
6768 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6769         .f = cmd_link_flow_ctrl_set_parsed,
6770         .data = (void *)&cmd_link_flow_control_set_rx,
6771         .help_str = "set flow_ctrl rx on|off <port_id>: "
6772                 "Change rx flow control parameter",
6773         .tokens = {
6774                 (void *)&cmd_lfc_set_set,
6775                 (void *)&cmd_lfc_set_flow_ctrl,
6776                 (void *)&cmd_lfc_set_rx,
6777                 (void *)&cmd_lfc_set_rx_mode,
6778                 (void *)&cmd_lfc_set_portid,
6779                 NULL,
6780         },
6781 };
6782
6783 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6784         .f = cmd_link_flow_ctrl_set_parsed,
6785         .data = (void *)&cmd_link_flow_control_set_tx,
6786         .help_str = "set flow_ctrl tx on|off <port_id>: "
6787                 "Change tx flow control parameter",
6788         .tokens = {
6789                 (void *)&cmd_lfc_set_set,
6790                 (void *)&cmd_lfc_set_flow_ctrl,
6791                 (void *)&cmd_lfc_set_tx,
6792                 (void *)&cmd_lfc_set_tx_mode,
6793                 (void *)&cmd_lfc_set_portid,
6794                 NULL,
6795         },
6796 };
6797
6798 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6799         .f = cmd_link_flow_ctrl_set_parsed,
6800         .data = (void *)&cmd_link_flow_control_set_hw,
6801         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6802                 "Change high water flow control parameter",
6803         .tokens = {
6804                 (void *)&cmd_lfc_set_set,
6805                 (void *)&cmd_lfc_set_flow_ctrl,
6806                 (void *)&cmd_lfc_set_high_water_str,
6807                 (void *)&cmd_lfc_set_high_water,
6808                 (void *)&cmd_lfc_set_portid,
6809                 NULL,
6810         },
6811 };
6812
6813 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6814         .f = cmd_link_flow_ctrl_set_parsed,
6815         .data = (void *)&cmd_link_flow_control_set_lw,
6816         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6817                 "Change low water flow control parameter",
6818         .tokens = {
6819                 (void *)&cmd_lfc_set_set,
6820                 (void *)&cmd_lfc_set_flow_ctrl,
6821                 (void *)&cmd_lfc_set_low_water_str,
6822                 (void *)&cmd_lfc_set_low_water,
6823                 (void *)&cmd_lfc_set_portid,
6824                 NULL,
6825         },
6826 };
6827
6828 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6829         .f = cmd_link_flow_ctrl_set_parsed,
6830         .data = (void *)&cmd_link_flow_control_set_pt,
6831         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6832                 "Change pause time flow control parameter",
6833         .tokens = {
6834                 (void *)&cmd_lfc_set_set,
6835                 (void *)&cmd_lfc_set_flow_ctrl,
6836                 (void *)&cmd_lfc_set_pause_time_str,
6837                 (void *)&cmd_lfc_set_pause_time,
6838                 (void *)&cmd_lfc_set_portid,
6839                 NULL,
6840         },
6841 };
6842
6843 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6844         .f = cmd_link_flow_ctrl_set_parsed,
6845         .data = (void *)&cmd_link_flow_control_set_xon,
6846         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6847                 "Change send_xon flow control parameter",
6848         .tokens = {
6849                 (void *)&cmd_lfc_set_set,
6850                 (void *)&cmd_lfc_set_flow_ctrl,
6851                 (void *)&cmd_lfc_set_send_xon_str,
6852                 (void *)&cmd_lfc_set_send_xon,
6853                 (void *)&cmd_lfc_set_portid,
6854                 NULL,
6855         },
6856 };
6857
6858 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6859         .f = cmd_link_flow_ctrl_set_parsed,
6860         .data = (void *)&cmd_link_flow_control_set_macfwd,
6861         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6862                 "Change mac ctrl fwd flow control parameter",
6863         .tokens = {
6864                 (void *)&cmd_lfc_set_set,
6865                 (void *)&cmd_lfc_set_flow_ctrl,
6866                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6867                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6868                 (void *)&cmd_lfc_set_portid,
6869                 NULL,
6870         },
6871 };
6872
6873 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6874         .f = cmd_link_flow_ctrl_set_parsed,
6875         .data = (void *)&cmd_link_flow_control_set_autoneg,
6876         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6877                 "Change autoneg flow control parameter",
6878         .tokens = {
6879                 (void *)&cmd_lfc_set_set,
6880                 (void *)&cmd_lfc_set_flow_ctrl,
6881                 (void *)&cmd_lfc_set_autoneg_str,
6882                 (void *)&cmd_lfc_set_autoneg,
6883                 (void *)&cmd_lfc_set_portid,
6884                 NULL,
6885         },
6886 };
6887
6888 static void
6889 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6890                               __attribute__((unused)) struct cmdline *cl,
6891                               void *data)
6892 {
6893         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6894         cmdline_parse_inst_t *cmd = data;
6895         struct rte_eth_fc_conf fc_conf;
6896         int rx_fc_en = 0;
6897         int tx_fc_en = 0;
6898         int ret;
6899
6900         /*
6901          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6902          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6903          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6904          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6905          */
6906         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6907                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6908         };
6909
6910         /* Partial command line, retrieve current configuration */
6911         if (cmd) {
6912                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6913                 if (ret != 0) {
6914                         printf("cannot get current flow ctrl parameters, return"
6915                                "code = %d\n", ret);
6916                         return;
6917                 }
6918
6919                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6920                     (fc_conf.mode == RTE_FC_FULL))
6921                         rx_fc_en = 1;
6922                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6923                     (fc_conf.mode == RTE_FC_FULL))
6924                         tx_fc_en = 1;
6925         }
6926
6927         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6928                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6929
6930         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6931                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6932
6933         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6934
6935         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6936                 fc_conf.high_water = res->high_water;
6937
6938         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6939                 fc_conf.low_water = res->low_water;
6940
6941         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6942                 fc_conf.pause_time = res->pause_time;
6943
6944         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6945                 fc_conf.send_xon = res->send_xon;
6946
6947         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6948                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6949                         fc_conf.mac_ctrl_frame_fwd = 1;
6950                 else
6951                         fc_conf.mac_ctrl_frame_fwd = 0;
6952         }
6953
6954         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6955                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6956
6957         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6958         if (ret != 0)
6959                 printf("bad flow contrl parameter, return code = %d \n", ret);
6960 }
6961
6962 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6963 struct cmd_priority_flow_ctrl_set_result {
6964         cmdline_fixed_string_t set;
6965         cmdline_fixed_string_t pfc_ctrl;
6966         cmdline_fixed_string_t rx;
6967         cmdline_fixed_string_t rx_pfc_mode;
6968         cmdline_fixed_string_t tx;
6969         cmdline_fixed_string_t tx_pfc_mode;
6970         uint32_t high_water;
6971         uint32_t low_water;
6972         uint16_t pause_time;
6973         uint8_t  priority;
6974         portid_t port_id;
6975 };
6976
6977 static void
6978 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6979                        __attribute__((unused)) struct cmdline *cl,
6980                        __attribute__((unused)) void *data)
6981 {
6982         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6983         struct rte_eth_pfc_conf pfc_conf;
6984         int rx_fc_enable, tx_fc_enable;
6985         int ret;
6986
6987         /*
6988          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6989          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6990          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6991          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6992          */
6993         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6994                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6995         };
6996
6997         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6998         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6999         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7000         pfc_conf.fc.high_water = res->high_water;
7001         pfc_conf.fc.low_water  = res->low_water;
7002         pfc_conf.fc.pause_time = res->pause_time;
7003         pfc_conf.priority      = res->priority;
7004
7005         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7006         if (ret != 0)
7007                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7008 }
7009
7010 cmdline_parse_token_string_t cmd_pfc_set_set =
7011         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7012                                 set, "set");
7013 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7014         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7015                                 pfc_ctrl, "pfc_ctrl");
7016 cmdline_parse_token_string_t cmd_pfc_set_rx =
7017         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7018                                 rx, "rx");
7019 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7020         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7021                                 rx_pfc_mode, "on#off");
7022 cmdline_parse_token_string_t cmd_pfc_set_tx =
7023         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7024                                 tx, "tx");
7025 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7026         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7027                                 tx_pfc_mode, "on#off");
7028 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7029         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7030                                 high_water, UINT32);
7031 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7032         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7033                                 low_water, UINT32);
7034 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7035         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7036                                 pause_time, UINT16);
7037 cmdline_parse_token_num_t cmd_pfc_set_priority =
7038         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7039                                 priority, UINT8);
7040 cmdline_parse_token_num_t cmd_pfc_set_portid =
7041         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7042                                 port_id, UINT16);
7043
7044 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7045         .f = cmd_priority_flow_ctrl_set_parsed,
7046         .data = NULL,
7047         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7048                 "<pause_time> <priority> <port_id>: "
7049                 "Configure the Ethernet priority flow control",
7050         .tokens = {
7051                 (void *)&cmd_pfc_set_set,
7052                 (void *)&cmd_pfc_set_flow_ctrl,
7053                 (void *)&cmd_pfc_set_rx,
7054                 (void *)&cmd_pfc_set_rx_mode,
7055                 (void *)&cmd_pfc_set_tx,
7056                 (void *)&cmd_pfc_set_tx_mode,
7057                 (void *)&cmd_pfc_set_high_water,
7058                 (void *)&cmd_pfc_set_low_water,
7059                 (void *)&cmd_pfc_set_pause_time,
7060                 (void *)&cmd_pfc_set_priority,
7061                 (void *)&cmd_pfc_set_portid,
7062                 NULL,
7063         },
7064 };
7065
7066 /* *** RESET CONFIGURATION *** */
7067 struct cmd_reset_result {
7068         cmdline_fixed_string_t reset;
7069         cmdline_fixed_string_t def;
7070 };
7071
7072 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7073                              struct cmdline *cl,
7074                              __attribute__((unused)) void *data)
7075 {
7076         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7077         set_def_fwd_config();
7078 }
7079
7080 cmdline_parse_token_string_t cmd_reset_set =
7081         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7082 cmdline_parse_token_string_t cmd_reset_def =
7083         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7084                                  "default");
7085
7086 cmdline_parse_inst_t cmd_reset = {
7087         .f = cmd_reset_parsed,
7088         .data = NULL,
7089         .help_str = "set default: Reset default forwarding configuration",
7090         .tokens = {
7091                 (void *)&cmd_reset_set,
7092                 (void *)&cmd_reset_def,
7093                 NULL,
7094         },
7095 };
7096
7097 /* *** START FORWARDING *** */
7098 struct cmd_start_result {
7099         cmdline_fixed_string_t start;
7100 };
7101
7102 cmdline_parse_token_string_t cmd_start_start =
7103         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7104
7105 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7106                              __attribute__((unused)) struct cmdline *cl,
7107                              __attribute__((unused)) void *data)
7108 {
7109         start_packet_forwarding(0);
7110 }
7111
7112 cmdline_parse_inst_t cmd_start = {
7113         .f = cmd_start_parsed,
7114         .data = NULL,
7115         .help_str = "start: Start packet forwarding",
7116         .tokens = {
7117                 (void *)&cmd_start_start,
7118                 NULL,
7119         },
7120 };
7121
7122 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7123 struct cmd_start_tx_first_result {
7124         cmdline_fixed_string_t start;
7125         cmdline_fixed_string_t tx_first;
7126 };
7127
7128 static void
7129 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7130                           __attribute__((unused)) struct cmdline *cl,
7131                           __attribute__((unused)) void *data)
7132 {
7133         start_packet_forwarding(1);
7134 }
7135
7136 cmdline_parse_token_string_t cmd_start_tx_first_start =
7137         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7138                                  "start");
7139 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7140         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7141                                  tx_first, "tx_first");
7142
7143 cmdline_parse_inst_t cmd_start_tx_first = {
7144         .f = cmd_start_tx_first_parsed,
7145         .data = NULL,
7146         .help_str = "start tx_first: Start packet forwarding, "
7147                 "after sending 1 burst of packets",
7148         .tokens = {
7149                 (void *)&cmd_start_tx_first_start,
7150                 (void *)&cmd_start_tx_first_tx_first,
7151                 NULL,
7152         },
7153 };
7154
7155 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7156 struct cmd_start_tx_first_n_result {
7157         cmdline_fixed_string_t start;
7158         cmdline_fixed_string_t tx_first;
7159         uint32_t tx_num;
7160 };
7161
7162 static void
7163 cmd_start_tx_first_n_parsed(void *parsed_result,
7164                           __attribute__((unused)) struct cmdline *cl,
7165                           __attribute__((unused)) void *data)
7166 {
7167         struct cmd_start_tx_first_n_result *res = parsed_result;
7168
7169         start_packet_forwarding(res->tx_num);
7170 }
7171
7172 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7173         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7174                         start, "start");
7175 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7176         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7177                         tx_first, "tx_first");
7178 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7179         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7180                         tx_num, UINT32);
7181
7182 cmdline_parse_inst_t cmd_start_tx_first_n = {
7183         .f = cmd_start_tx_first_n_parsed,
7184         .data = NULL,
7185         .help_str = "start tx_first <num>: "
7186                 "packet forwarding, after sending <num> bursts of packets",
7187         .tokens = {
7188                 (void *)&cmd_start_tx_first_n_start,
7189                 (void *)&cmd_start_tx_first_n_tx_first,
7190                 (void *)&cmd_start_tx_first_n_tx_num,
7191                 NULL,
7192         },
7193 };
7194
7195 /* *** SET LINK UP *** */
7196 struct cmd_set_link_up_result {
7197         cmdline_fixed_string_t set;
7198         cmdline_fixed_string_t link_up;
7199         cmdline_fixed_string_t port;
7200         portid_t port_id;
7201 };
7202
7203 cmdline_parse_token_string_t cmd_set_link_up_set =
7204         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7205 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7206         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7207                                 "link-up");
7208 cmdline_parse_token_string_t cmd_set_link_up_port =
7209         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7210 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7211         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7212
7213 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7214                              __attribute__((unused)) struct cmdline *cl,
7215                              __attribute__((unused)) void *data)
7216 {
7217         struct cmd_set_link_up_result *res = parsed_result;
7218         dev_set_link_up(res->port_id);
7219 }
7220
7221 cmdline_parse_inst_t cmd_set_link_up = {
7222         .f = cmd_set_link_up_parsed,
7223         .data = NULL,
7224         .help_str = "set link-up port <port id>",
7225         .tokens = {
7226                 (void *)&cmd_set_link_up_set,
7227                 (void *)&cmd_set_link_up_link_up,
7228                 (void *)&cmd_set_link_up_port,
7229                 (void *)&cmd_set_link_up_port_id,
7230                 NULL,
7231         },
7232 };
7233
7234 /* *** SET LINK DOWN *** */
7235 struct cmd_set_link_down_result {
7236         cmdline_fixed_string_t set;
7237         cmdline_fixed_string_t link_down;
7238         cmdline_fixed_string_t port;
7239         portid_t port_id;
7240 };
7241
7242 cmdline_parse_token_string_t cmd_set_link_down_set =
7243         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7244 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7245         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7246                                 "link-down");
7247 cmdline_parse_token_string_t cmd_set_link_down_port =
7248         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7249 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7250         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7251
7252 static void cmd_set_link_down_parsed(
7253                                 __attribute__((unused)) void *parsed_result,
7254                                 __attribute__((unused)) struct cmdline *cl,
7255                                 __attribute__((unused)) void *data)
7256 {
7257         struct cmd_set_link_down_result *res = parsed_result;
7258         dev_set_link_down(res->port_id);
7259 }
7260
7261 cmdline_parse_inst_t cmd_set_link_down = {
7262         .f = cmd_set_link_down_parsed,
7263         .data = NULL,
7264         .help_str = "set link-down port <port id>",
7265         .tokens = {
7266                 (void *)&cmd_set_link_down_set,
7267                 (void *)&cmd_set_link_down_link_down,
7268                 (void *)&cmd_set_link_down_port,
7269                 (void *)&cmd_set_link_down_port_id,
7270                 NULL,
7271         },
7272 };
7273
7274 /* *** SHOW CFG *** */
7275 struct cmd_showcfg_result {
7276         cmdline_fixed_string_t show;
7277         cmdline_fixed_string_t cfg;
7278         cmdline_fixed_string_t what;
7279 };
7280
7281 static void cmd_showcfg_parsed(void *parsed_result,
7282                                __attribute__((unused)) struct cmdline *cl,
7283                                __attribute__((unused)) void *data)
7284 {
7285         struct cmd_showcfg_result *res = parsed_result;
7286         if (!strcmp(res->what, "rxtx"))
7287                 rxtx_config_display();
7288         else if (!strcmp(res->what, "cores"))
7289                 fwd_lcores_config_display();
7290         else if (!strcmp(res->what, "fwd"))
7291                 pkt_fwd_config_display(&cur_fwd_config);
7292         else if (!strcmp(res->what, "txpkts"))
7293                 show_tx_pkt_segments();
7294 }
7295
7296 cmdline_parse_token_string_t cmd_showcfg_show =
7297         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7298 cmdline_parse_token_string_t cmd_showcfg_port =
7299         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7300 cmdline_parse_token_string_t cmd_showcfg_what =
7301         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7302                                  "rxtx#cores#fwd#txpkts");
7303
7304 cmdline_parse_inst_t cmd_showcfg = {
7305         .f = cmd_showcfg_parsed,
7306         .data = NULL,
7307         .help_str = "show config rxtx|cores|fwd|txpkts",
7308         .tokens = {
7309                 (void *)&cmd_showcfg_show,
7310                 (void *)&cmd_showcfg_port,
7311                 (void *)&cmd_showcfg_what,
7312                 NULL,
7313         },
7314 };
7315
7316 /* *** SHOW ALL PORT INFO *** */
7317 struct cmd_showportall_result {
7318         cmdline_fixed_string_t show;
7319         cmdline_fixed_string_t port;
7320         cmdline_fixed_string_t what;
7321         cmdline_fixed_string_t all;
7322 };
7323
7324 static void cmd_showportall_parsed(void *parsed_result,
7325                                 __attribute__((unused)) struct cmdline *cl,
7326                                 __attribute__((unused)) void *data)
7327 {
7328         portid_t i;
7329
7330         struct cmd_showportall_result *res = parsed_result;
7331         if (!strcmp(res->show, "clear")) {
7332                 if (!strcmp(res->what, "stats"))
7333                         RTE_ETH_FOREACH_DEV(i)
7334                                 nic_stats_clear(i);
7335                 else if (!strcmp(res->what, "xstats"))
7336                         RTE_ETH_FOREACH_DEV(i)
7337                                 nic_xstats_clear(i);
7338         } else if (!strcmp(res->what, "info"))
7339                 RTE_ETH_FOREACH_DEV(i)
7340                         port_infos_display(i);
7341         else if (!strcmp(res->what, "summary")) {
7342                 port_summary_header_display();
7343                 RTE_ETH_FOREACH_DEV(i)
7344                         port_summary_display(i);
7345         }
7346         else if (!strcmp(res->what, "stats"))
7347                 RTE_ETH_FOREACH_DEV(i)
7348                         nic_stats_display(i);
7349         else if (!strcmp(res->what, "xstats"))
7350                 RTE_ETH_FOREACH_DEV(i)
7351                         nic_xstats_display(i);
7352         else if (!strcmp(res->what, "fdir"))
7353                 RTE_ETH_FOREACH_DEV(i)
7354                         fdir_get_infos(i);
7355         else if (!strcmp(res->what, "stat_qmap"))
7356                 RTE_ETH_FOREACH_DEV(i)
7357                         nic_stats_mapping_display(i);
7358         else if (!strcmp(res->what, "dcb_tc"))
7359                 RTE_ETH_FOREACH_DEV(i)
7360                         port_dcb_info_display(i);
7361         else if (!strcmp(res->what, "cap"))
7362                 RTE_ETH_FOREACH_DEV(i)
7363                         port_offload_cap_display(i);
7364 }
7365
7366 cmdline_parse_token_string_t cmd_showportall_show =
7367         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7368                                  "show#clear");
7369 cmdline_parse_token_string_t cmd_showportall_port =
7370         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7371 cmdline_parse_token_string_t cmd_showportall_what =
7372         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7373                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7374 cmdline_parse_token_string_t cmd_showportall_all =
7375         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7376 cmdline_parse_inst_t cmd_showportall = {
7377         .f = cmd_showportall_parsed,
7378         .data = NULL,
7379         .help_str = "show|clear port "
7380                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7381         .tokens = {
7382                 (void *)&cmd_showportall_show,
7383                 (void *)&cmd_showportall_port,
7384                 (void *)&cmd_showportall_what,
7385                 (void *)&cmd_showportall_all,
7386                 NULL,
7387         },
7388 };
7389
7390 /* *** SHOW PORT INFO *** */
7391 struct cmd_showport_result {
7392         cmdline_fixed_string_t show;
7393         cmdline_fixed_string_t port;
7394         cmdline_fixed_string_t what;
7395         uint16_t portnum;
7396 };
7397
7398 static void cmd_showport_parsed(void *parsed_result,
7399                                 __attribute__((unused)) struct cmdline *cl,
7400                                 __attribute__((unused)) void *data)
7401 {
7402         struct cmd_showport_result *res = parsed_result;
7403         if (!strcmp(res->show, "clear")) {
7404                 if (!strcmp(res->what, "stats"))
7405                         nic_stats_clear(res->portnum);
7406                 else if (!strcmp(res->what, "xstats"))
7407                         nic_xstats_clear(res->portnum);
7408         } else if (!strcmp(res->what, "info"))
7409                 port_infos_display(res->portnum);
7410         else if (!strcmp(res->what, "summary")) {
7411                 port_summary_header_display();
7412                 port_summary_display(res->portnum);
7413         }
7414         else if (!strcmp(res->what, "stats"))
7415                 nic_stats_display(res->portnum);
7416         else if (!strcmp(res->what, "xstats"))
7417                 nic_xstats_display(res->portnum);
7418         else if (!strcmp(res->what, "fdir"))
7419                  fdir_get_infos(res->portnum);
7420         else if (!strcmp(res->what, "stat_qmap"))
7421                 nic_stats_mapping_display(res->portnum);
7422         else if (!strcmp(res->what, "dcb_tc"))
7423                 port_dcb_info_display(res->portnum);
7424         else if (!strcmp(res->what, "cap"))
7425                 port_offload_cap_display(res->portnum);
7426 }
7427
7428 cmdline_parse_token_string_t cmd_showport_show =
7429         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7430                                  "show#clear");
7431 cmdline_parse_token_string_t cmd_showport_port =
7432         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7433 cmdline_parse_token_string_t cmd_showport_what =
7434         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7435                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7436 cmdline_parse_token_num_t cmd_showport_portnum =
7437         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7438
7439 cmdline_parse_inst_t cmd_showport = {
7440         .f = cmd_showport_parsed,
7441         .data = NULL,
7442         .help_str = "show|clear port "
7443                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7444                 "<port_id>",
7445         .tokens = {
7446                 (void *)&cmd_showport_show,
7447                 (void *)&cmd_showport_port,
7448                 (void *)&cmd_showport_what,
7449                 (void *)&cmd_showport_portnum,
7450                 NULL,
7451         },
7452 };
7453
7454 /* *** SHOW DEVICE INFO *** */
7455 struct cmd_showdevice_result {
7456         cmdline_fixed_string_t show;
7457         cmdline_fixed_string_t device;
7458         cmdline_fixed_string_t what;
7459         cmdline_fixed_string_t identifier;
7460 };
7461
7462 static void cmd_showdevice_parsed(void *parsed_result,
7463                                 __attribute__((unused)) struct cmdline *cl,
7464                                 __attribute__((unused)) void *data)
7465 {
7466         struct cmd_showdevice_result *res = parsed_result;
7467         if (!strcmp(res->what, "info")) {
7468                 if (!strcmp(res->identifier, "all"))
7469                         device_infos_display(NULL);
7470                 else
7471                         device_infos_display(res->identifier);
7472         }
7473 }
7474
7475 cmdline_parse_token_string_t cmd_showdevice_show =
7476         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7477                                  "show");
7478 cmdline_parse_token_string_t cmd_showdevice_device =
7479         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7480 cmdline_parse_token_string_t cmd_showdevice_what =
7481         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7482                                  "info");
7483 cmdline_parse_token_string_t cmd_showdevice_identifier =
7484         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7485                         identifier, NULL);
7486
7487 cmdline_parse_inst_t cmd_showdevice = {
7488         .f = cmd_showdevice_parsed,
7489         .data = NULL,
7490         .help_str = "show device info <identifier>|all",
7491         .tokens = {
7492                 (void *)&cmd_showdevice_show,
7493                 (void *)&cmd_showdevice_device,
7494                 (void *)&cmd_showdevice_what,
7495                 (void *)&cmd_showdevice_identifier,
7496                 NULL,
7497         },
7498 };
7499 /* *** SHOW QUEUE INFO *** */
7500 struct cmd_showqueue_result {
7501         cmdline_fixed_string_t show;
7502         cmdline_fixed_string_t type;
7503         cmdline_fixed_string_t what;
7504         uint16_t portnum;
7505         uint16_t queuenum;
7506 };
7507
7508 static void
7509 cmd_showqueue_parsed(void *parsed_result,
7510         __attribute__((unused)) struct cmdline *cl,
7511         __attribute__((unused)) void *data)
7512 {
7513         struct cmd_showqueue_result *res = parsed_result;
7514
7515         if (!strcmp(res->type, "rxq"))
7516                 rx_queue_infos_display(res->portnum, res->queuenum);
7517         else if (!strcmp(res->type, "txq"))
7518                 tx_queue_infos_display(res->portnum, res->queuenum);
7519 }
7520
7521 cmdline_parse_token_string_t cmd_showqueue_show =
7522         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7523 cmdline_parse_token_string_t cmd_showqueue_type =
7524         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7525 cmdline_parse_token_string_t cmd_showqueue_what =
7526         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7527 cmdline_parse_token_num_t cmd_showqueue_portnum =
7528         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7529 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7530         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7531
7532 cmdline_parse_inst_t cmd_showqueue = {
7533         .f = cmd_showqueue_parsed,
7534         .data = NULL,
7535         .help_str = "show rxq|txq info <port_id> <queue_id>",
7536         .tokens = {
7537                 (void *)&cmd_showqueue_show,
7538                 (void *)&cmd_showqueue_type,
7539                 (void *)&cmd_showqueue_what,
7540                 (void *)&cmd_showqueue_portnum,
7541                 (void *)&cmd_showqueue_queuenum,
7542                 NULL,
7543         },
7544 };
7545
7546 /* show/clear fwd engine statistics */
7547 struct fwd_result {
7548         cmdline_fixed_string_t action;
7549         cmdline_fixed_string_t fwd;
7550         cmdline_fixed_string_t stats;
7551         cmdline_fixed_string_t all;
7552 };
7553
7554 cmdline_parse_token_string_t cmd_fwd_action =
7555         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7556 cmdline_parse_token_string_t cmd_fwd_fwd =
7557         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7558 cmdline_parse_token_string_t cmd_fwd_stats =
7559         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7560 cmdline_parse_token_string_t cmd_fwd_all =
7561         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7562
7563 static void
7564 cmd_showfwdall_parsed(void *parsed_result,
7565                       __rte_unused struct cmdline *cl,
7566                       __rte_unused void *data)
7567 {
7568         struct fwd_result *res = parsed_result;
7569
7570         if (!strcmp(res->action, "show"))
7571                 fwd_stats_display();
7572         else
7573                 fwd_stats_reset();
7574 }
7575
7576 static cmdline_parse_inst_t cmd_showfwdall = {
7577         .f = cmd_showfwdall_parsed,
7578         .data = NULL,
7579         .help_str = "show|clear fwd stats all",
7580         .tokens = {
7581                 (void *)&cmd_fwd_action,
7582                 (void *)&cmd_fwd_fwd,
7583                 (void *)&cmd_fwd_stats,
7584                 (void *)&cmd_fwd_all,
7585                 NULL,
7586         },
7587 };
7588
7589 /* *** READ PORT REGISTER *** */
7590 struct cmd_read_reg_result {
7591         cmdline_fixed_string_t read;
7592         cmdline_fixed_string_t reg;
7593         portid_t port_id;
7594         uint32_t reg_off;
7595 };
7596
7597 static void
7598 cmd_read_reg_parsed(void *parsed_result,
7599                     __attribute__((unused)) struct cmdline *cl,
7600                     __attribute__((unused)) void *data)
7601 {
7602         struct cmd_read_reg_result *res = parsed_result;
7603         port_reg_display(res->port_id, res->reg_off);
7604 }
7605
7606 cmdline_parse_token_string_t cmd_read_reg_read =
7607         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7608 cmdline_parse_token_string_t cmd_read_reg_reg =
7609         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7610 cmdline_parse_token_num_t cmd_read_reg_port_id =
7611         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7612 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7613         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7614
7615 cmdline_parse_inst_t cmd_read_reg = {
7616         .f = cmd_read_reg_parsed,
7617         .data = NULL,
7618         .help_str = "read reg <port_id> <reg_off>",
7619         .tokens = {
7620                 (void *)&cmd_read_reg_read,
7621                 (void *)&cmd_read_reg_reg,
7622                 (void *)&cmd_read_reg_port_id,
7623                 (void *)&cmd_read_reg_reg_off,
7624                 NULL,
7625         },
7626 };
7627
7628 /* *** READ PORT REGISTER BIT FIELD *** */
7629 struct cmd_read_reg_bit_field_result {
7630         cmdline_fixed_string_t read;
7631         cmdline_fixed_string_t regfield;
7632         portid_t port_id;
7633         uint32_t reg_off;
7634         uint8_t bit1_pos;
7635         uint8_t bit2_pos;
7636 };
7637
7638 static void
7639 cmd_read_reg_bit_field_parsed(void *parsed_result,
7640                               __attribute__((unused)) struct cmdline *cl,
7641                               __attribute__((unused)) void *data)
7642 {
7643         struct cmd_read_reg_bit_field_result *res = parsed_result;
7644         port_reg_bit_field_display(res->port_id, res->reg_off,
7645                                    res->bit1_pos, res->bit2_pos);
7646 }
7647
7648 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7649         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7650                                  "read");
7651 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7652         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7653                                  regfield, "regfield");
7654 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7655         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7656                               UINT16);
7657 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7658         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7659                               UINT32);
7660 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7661         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7662                               UINT8);
7663 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7664         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7665                               UINT8);
7666
7667 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7668         .f = cmd_read_reg_bit_field_parsed,
7669         .data = NULL,
7670         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7671         "Read register bit field between bit_x and bit_y included",
7672         .tokens = {
7673                 (void *)&cmd_read_reg_bit_field_read,
7674                 (void *)&cmd_read_reg_bit_field_regfield,
7675                 (void *)&cmd_read_reg_bit_field_port_id,
7676                 (void *)&cmd_read_reg_bit_field_reg_off,
7677                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7678                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7679                 NULL,
7680         },
7681 };
7682
7683 /* *** READ PORT REGISTER BIT *** */
7684 struct cmd_read_reg_bit_result {
7685         cmdline_fixed_string_t read;
7686         cmdline_fixed_string_t regbit;
7687         portid_t port_id;
7688         uint32_t reg_off;
7689         uint8_t bit_pos;
7690 };
7691
7692 static void
7693 cmd_read_reg_bit_parsed(void *parsed_result,
7694                         __attribute__((unused)) struct cmdline *cl,
7695                         __attribute__((unused)) void *data)
7696 {
7697         struct cmd_read_reg_bit_result *res = parsed_result;
7698         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7699 }
7700
7701 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7702         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7703 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7704         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7705                                  regbit, "regbit");
7706 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7707         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7708 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7709         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7710 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7711         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7712
7713 cmdline_parse_inst_t cmd_read_reg_bit = {
7714         .f = cmd_read_reg_bit_parsed,
7715         .data = NULL,
7716         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7717         .tokens = {
7718                 (void *)&cmd_read_reg_bit_read,
7719                 (void *)&cmd_read_reg_bit_regbit,
7720                 (void *)&cmd_read_reg_bit_port_id,
7721                 (void *)&cmd_read_reg_bit_reg_off,
7722                 (void *)&cmd_read_reg_bit_bit_pos,
7723                 NULL,
7724         },
7725 };
7726
7727 /* *** WRITE PORT REGISTER *** */
7728 struct cmd_write_reg_result {
7729         cmdline_fixed_string_t write;
7730         cmdline_fixed_string_t reg;
7731         portid_t port_id;
7732         uint32_t reg_off;
7733         uint32_t value;
7734 };
7735
7736 static void
7737 cmd_write_reg_parsed(void *parsed_result,
7738                      __attribute__((unused)) struct cmdline *cl,
7739                      __attribute__((unused)) void *data)
7740 {
7741         struct cmd_write_reg_result *res = parsed_result;
7742         port_reg_set(res->port_id, res->reg_off, res->value);
7743 }
7744
7745 cmdline_parse_token_string_t cmd_write_reg_write =
7746         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7747 cmdline_parse_token_string_t cmd_write_reg_reg =
7748         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7749 cmdline_parse_token_num_t cmd_write_reg_port_id =
7750         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7751 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7752         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7753 cmdline_parse_token_num_t cmd_write_reg_value =
7754         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7755
7756 cmdline_parse_inst_t cmd_write_reg = {
7757         .f = cmd_write_reg_parsed,
7758         .data = NULL,
7759         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7760         .tokens = {
7761                 (void *)&cmd_write_reg_write,
7762                 (void *)&cmd_write_reg_reg,
7763                 (void *)&cmd_write_reg_port_id,
7764                 (void *)&cmd_write_reg_reg_off,
7765                 (void *)&cmd_write_reg_value,
7766                 NULL,
7767         },
7768 };
7769
7770 /* *** WRITE PORT REGISTER BIT FIELD *** */
7771 struct cmd_write_reg_bit_field_result {
7772         cmdline_fixed_string_t write;
7773         cmdline_fixed_string_t regfield;
7774         portid_t port_id;
7775         uint32_t reg_off;
7776         uint8_t bit1_pos;
7777         uint8_t bit2_pos;
7778         uint32_t value;
7779 };
7780
7781 static void
7782 cmd_write_reg_bit_field_parsed(void *parsed_result,
7783                                __attribute__((unused)) struct cmdline *cl,
7784                                __attribute__((unused)) void *data)
7785 {
7786         struct cmd_write_reg_bit_field_result *res = parsed_result;
7787         port_reg_bit_field_set(res->port_id, res->reg_off,
7788                           res->bit1_pos, res->bit2_pos, res->value);
7789 }
7790
7791 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7792         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7793                                  "write");
7794 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7795         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7796                                  regfield, "regfield");
7797 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7798         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7799                               UINT16);
7800 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7801         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7802                               UINT32);
7803 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7804         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7805                               UINT8);
7806 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7807         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7808                               UINT8);
7809 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7810         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7811                               UINT32);
7812
7813 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7814         .f = cmd_write_reg_bit_field_parsed,
7815         .data = NULL,
7816         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7817                 "<reg_value>: "
7818                 "Set register bit field between bit_x and bit_y included",
7819         .tokens = {
7820                 (void *)&cmd_write_reg_bit_field_write,
7821                 (void *)&cmd_write_reg_bit_field_regfield,
7822                 (void *)&cmd_write_reg_bit_field_port_id,
7823                 (void *)&cmd_write_reg_bit_field_reg_off,
7824                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7825                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7826                 (void *)&cmd_write_reg_bit_field_value,
7827                 NULL,
7828         },
7829 };
7830
7831 /* *** WRITE PORT REGISTER BIT *** */
7832 struct cmd_write_reg_bit_result {
7833         cmdline_fixed_string_t write;
7834         cmdline_fixed_string_t regbit;
7835         portid_t port_id;
7836         uint32_t reg_off;
7837         uint8_t bit_pos;
7838         uint8_t value;
7839 };
7840
7841 static void
7842 cmd_write_reg_bit_parsed(void *parsed_result,
7843                          __attribute__((unused)) struct cmdline *cl,
7844                          __attribute__((unused)) void *data)
7845 {
7846         struct cmd_write_reg_bit_result *res = parsed_result;
7847         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7848 }
7849
7850 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7851         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7852                                  "write");
7853 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7854         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7855                                  regbit, "regbit");
7856 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7857         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7858 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7859         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7860 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7861         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7862 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7863         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7864
7865 cmdline_parse_inst_t cmd_write_reg_bit = {
7866         .f = cmd_write_reg_bit_parsed,
7867         .data = NULL,
7868         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7869                 "0 <= bit_x <= 31",
7870         .tokens = {
7871                 (void *)&cmd_write_reg_bit_write,
7872                 (void *)&cmd_write_reg_bit_regbit,
7873                 (void *)&cmd_write_reg_bit_port_id,
7874                 (void *)&cmd_write_reg_bit_reg_off,
7875                 (void *)&cmd_write_reg_bit_bit_pos,
7876                 (void *)&cmd_write_reg_bit_value,
7877                 NULL,
7878         },
7879 };
7880
7881 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7882 struct cmd_read_rxd_txd_result {
7883         cmdline_fixed_string_t read;
7884         cmdline_fixed_string_t rxd_txd;
7885         portid_t port_id;
7886         uint16_t queue_id;
7887         uint16_t desc_id;
7888 };
7889
7890 static void
7891 cmd_read_rxd_txd_parsed(void *parsed_result,
7892                         __attribute__((unused)) struct cmdline *cl,
7893                         __attribute__((unused)) void *data)
7894 {
7895         struct cmd_read_rxd_txd_result *res = parsed_result;
7896
7897         if (!strcmp(res->rxd_txd, "rxd"))
7898                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7899         else if (!strcmp(res->rxd_txd, "txd"))
7900                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7901 }
7902
7903 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7904         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7905 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7906         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7907                                  "rxd#txd");
7908 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7909         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7910 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7911         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7912 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7913         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7914
7915 cmdline_parse_inst_t cmd_read_rxd_txd = {
7916         .f = cmd_read_rxd_txd_parsed,
7917         .data = NULL,
7918         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7919         .tokens = {
7920                 (void *)&cmd_read_rxd_txd_read,
7921                 (void *)&cmd_read_rxd_txd_rxd_txd,
7922                 (void *)&cmd_read_rxd_txd_port_id,
7923                 (void *)&cmd_read_rxd_txd_queue_id,
7924                 (void *)&cmd_read_rxd_txd_desc_id,
7925                 NULL,
7926         },
7927 };
7928
7929 /* *** QUIT *** */
7930 struct cmd_quit_result {
7931         cmdline_fixed_string_t quit;
7932 };
7933
7934 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7935                             struct cmdline *cl,
7936                             __attribute__((unused)) void *data)
7937 {
7938         cmdline_quit(cl);
7939 }
7940
7941 cmdline_parse_token_string_t cmd_quit_quit =
7942         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7943
7944 cmdline_parse_inst_t cmd_quit = {
7945         .f = cmd_quit_parsed,
7946         .data = NULL,
7947         .help_str = "quit: Exit application",
7948         .tokens = {
7949                 (void *)&cmd_quit_quit,
7950                 NULL,
7951         },
7952 };
7953
7954 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7955 struct cmd_mac_addr_result {
7956         cmdline_fixed_string_t mac_addr_cmd;
7957         cmdline_fixed_string_t what;
7958         uint16_t port_num;
7959         struct rte_ether_addr address;
7960 };
7961
7962 static void cmd_mac_addr_parsed(void *parsed_result,
7963                 __attribute__((unused)) struct cmdline *cl,
7964                 __attribute__((unused)) void *data)
7965 {
7966         struct cmd_mac_addr_result *res = parsed_result;
7967         int ret;
7968
7969         if (strcmp(res->what, "add") == 0)
7970                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7971         else if (strcmp(res->what, "set") == 0)
7972                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7973                                                        &res->address);
7974         else
7975                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7976
7977         /* check the return value and print it if is < 0 */
7978         if(ret < 0)
7979                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7980
7981 }
7982
7983 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7984         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7985                                 "mac_addr");
7986 cmdline_parse_token_string_t cmd_mac_addr_what =
7987         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7988                                 "add#remove#set");
7989 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7990                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7991                                         UINT16);
7992 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7993                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7994
7995 cmdline_parse_inst_t cmd_mac_addr = {
7996         .f = cmd_mac_addr_parsed,
7997         .data = (void *)0,
7998         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7999                         "Add/Remove/Set MAC address on port_id",
8000         .tokens = {
8001                 (void *)&cmd_mac_addr_cmd,
8002                 (void *)&cmd_mac_addr_what,
8003                 (void *)&cmd_mac_addr_portnum,
8004                 (void *)&cmd_mac_addr_addr,
8005                 NULL,
8006         },
8007 };
8008
8009 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8010 struct cmd_eth_peer_result {
8011         cmdline_fixed_string_t set;
8012         cmdline_fixed_string_t eth_peer;
8013         portid_t port_id;
8014         cmdline_fixed_string_t peer_addr;
8015 };
8016
8017 static void cmd_set_eth_peer_parsed(void *parsed_result,
8018                         __attribute__((unused)) struct cmdline *cl,
8019                         __attribute__((unused)) void *data)
8020 {
8021                 struct cmd_eth_peer_result *res = parsed_result;
8022
8023                 if (test_done == 0) {
8024                         printf("Please stop forwarding first\n");
8025                         return;
8026                 }
8027                 if (!strcmp(res->eth_peer, "eth-peer")) {
8028                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8029                         fwd_config_setup();
8030                 }
8031 }
8032 cmdline_parse_token_string_t cmd_eth_peer_set =
8033         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8034 cmdline_parse_token_string_t cmd_eth_peer =
8035         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8036 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8037         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8038 cmdline_parse_token_string_t cmd_eth_peer_addr =
8039         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8040
8041 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8042         .f = cmd_set_eth_peer_parsed,
8043         .data = NULL,
8044         .help_str = "set eth-peer <port_id> <peer_mac>",
8045         .tokens = {
8046                 (void *)&cmd_eth_peer_set,
8047                 (void *)&cmd_eth_peer,
8048                 (void *)&cmd_eth_peer_port_id,
8049                 (void *)&cmd_eth_peer_addr,
8050                 NULL,
8051         },
8052 };
8053
8054 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8055 struct cmd_set_qmap_result {
8056         cmdline_fixed_string_t set;
8057         cmdline_fixed_string_t qmap;
8058         cmdline_fixed_string_t what;
8059         portid_t port_id;
8060         uint16_t queue_id;
8061         uint8_t map_value;
8062 };
8063
8064 static void
8065 cmd_set_qmap_parsed(void *parsed_result,
8066                        __attribute__((unused)) struct cmdline *cl,
8067                        __attribute__((unused)) void *data)
8068 {
8069         struct cmd_set_qmap_result *res = parsed_result;
8070         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8071
8072         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8073 }
8074
8075 cmdline_parse_token_string_t cmd_setqmap_set =
8076         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8077                                  set, "set");
8078 cmdline_parse_token_string_t cmd_setqmap_qmap =
8079         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8080                                  qmap, "stat_qmap");
8081 cmdline_parse_token_string_t cmd_setqmap_what =
8082         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8083                                  what, "tx#rx");
8084 cmdline_parse_token_num_t cmd_setqmap_portid =
8085         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8086                               port_id, UINT16);
8087 cmdline_parse_token_num_t cmd_setqmap_queueid =
8088         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8089                               queue_id, UINT16);
8090 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8091         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8092                               map_value, UINT8);
8093
8094 cmdline_parse_inst_t cmd_set_qmap = {
8095         .f = cmd_set_qmap_parsed,
8096         .data = NULL,
8097         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8098                 "Set statistics mapping value on tx|rx queue_id of port_id",
8099         .tokens = {
8100                 (void *)&cmd_setqmap_set,
8101                 (void *)&cmd_setqmap_qmap,
8102                 (void *)&cmd_setqmap_what,
8103                 (void *)&cmd_setqmap_portid,
8104                 (void *)&cmd_setqmap_queueid,
8105                 (void *)&cmd_setqmap_mapvalue,
8106                 NULL,
8107         },
8108 };
8109
8110 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8111 struct cmd_set_xstats_hide_zero_result {
8112         cmdline_fixed_string_t keyword;
8113         cmdline_fixed_string_t name;
8114         cmdline_fixed_string_t on_off;
8115 };
8116
8117 static void
8118 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8119                         __attribute__((unused)) struct cmdline *cl,
8120                         __attribute__((unused)) void *data)
8121 {
8122         struct cmd_set_xstats_hide_zero_result *res;
8123         uint16_t on_off = 0;
8124
8125         res = parsed_result;
8126         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8127         set_xstats_hide_zero(on_off);
8128 }
8129
8130 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8131         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8132                                  keyword, "set");
8133 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8134         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8135                                  name, "xstats-hide-zero");
8136 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8137         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8138                                  on_off, "on#off");
8139
8140 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8141         .f = cmd_set_xstats_hide_zero_parsed,
8142         .data = NULL,
8143         .help_str = "set xstats-hide-zero on|off",
8144         .tokens = {
8145                 (void *)&cmd_set_xstats_hide_zero_keyword,
8146                 (void *)&cmd_set_xstats_hide_zero_name,
8147                 (void *)&cmd_set_xstats_hide_zero_on_off,
8148                 NULL,
8149         },
8150 };
8151
8152 /* *** CONFIGURE UNICAST HASH TABLE *** */
8153 struct cmd_set_uc_hash_table {
8154         cmdline_fixed_string_t set;
8155         cmdline_fixed_string_t port;
8156         portid_t port_id;
8157         cmdline_fixed_string_t what;
8158         struct rte_ether_addr address;
8159         cmdline_fixed_string_t mode;
8160 };
8161
8162 static void
8163 cmd_set_uc_hash_parsed(void *parsed_result,
8164                        __attribute__((unused)) struct cmdline *cl,
8165                        __attribute__((unused)) void *data)
8166 {
8167         int ret=0;
8168         struct cmd_set_uc_hash_table *res = parsed_result;
8169
8170         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8171
8172         if (strcmp(res->what, "uta") == 0)
8173                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8174                                                 &res->address,(uint8_t)is_on);
8175         if (ret < 0)
8176                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8177
8178 }
8179
8180 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8181         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8182                                  set, "set");
8183 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8184         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8185                                  port, "port");
8186 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8187         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8188                               port_id, UINT16);
8189 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8190         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8191                                  what, "uta");
8192 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8193         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8194                                 address);
8195 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8196         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8197                                  mode, "on#off");
8198
8199 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8200         .f = cmd_set_uc_hash_parsed,
8201         .data = NULL,
8202         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8203         .tokens = {
8204                 (void *)&cmd_set_uc_hash_set,
8205                 (void *)&cmd_set_uc_hash_port,
8206                 (void *)&cmd_set_uc_hash_portid,
8207                 (void *)&cmd_set_uc_hash_what,
8208                 (void *)&cmd_set_uc_hash_mac,
8209                 (void *)&cmd_set_uc_hash_mode,
8210                 NULL,
8211         },
8212 };
8213
8214 struct cmd_set_uc_all_hash_table {
8215         cmdline_fixed_string_t set;
8216         cmdline_fixed_string_t port;
8217         portid_t port_id;
8218         cmdline_fixed_string_t what;
8219         cmdline_fixed_string_t value;
8220         cmdline_fixed_string_t mode;
8221 };
8222
8223 static void
8224 cmd_set_uc_all_hash_parsed(void *parsed_result,
8225                        __attribute__((unused)) struct cmdline *cl,
8226                        __attribute__((unused)) void *data)
8227 {
8228         int ret=0;
8229         struct cmd_set_uc_all_hash_table *res = parsed_result;
8230
8231         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8232
8233         if ((strcmp(res->what, "uta") == 0) &&
8234                 (strcmp(res->value, "all") == 0))
8235                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8236         if (ret < 0)
8237                 printf("bad unicast hash table parameter,"
8238                         "return code = %d \n", ret);
8239 }
8240
8241 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8242         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8243                                  set, "set");
8244 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8245         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8246                                  port, "port");
8247 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8248         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8249                               port_id, UINT16);
8250 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8251         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8252                                  what, "uta");
8253 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8254         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8255                                 value,"all");
8256 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8257         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8258                                  mode, "on#off");
8259
8260 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8261         .f = cmd_set_uc_all_hash_parsed,
8262         .data = NULL,
8263         .help_str = "set port <port_id> uta all on|off",
8264         .tokens = {
8265                 (void *)&cmd_set_uc_all_hash_set,
8266                 (void *)&cmd_set_uc_all_hash_port,
8267                 (void *)&cmd_set_uc_all_hash_portid,
8268                 (void *)&cmd_set_uc_all_hash_what,
8269                 (void *)&cmd_set_uc_all_hash_value,
8270                 (void *)&cmd_set_uc_all_hash_mode,
8271                 NULL,
8272         },
8273 };
8274
8275 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8276 struct cmd_set_vf_macvlan_filter {
8277         cmdline_fixed_string_t set;
8278         cmdline_fixed_string_t port;
8279         portid_t port_id;
8280         cmdline_fixed_string_t vf;
8281         uint8_t vf_id;
8282         struct rte_ether_addr address;
8283         cmdline_fixed_string_t filter_type;
8284         cmdline_fixed_string_t mode;
8285 };
8286
8287 static void
8288 cmd_set_vf_macvlan_parsed(void *parsed_result,
8289                        __attribute__((unused)) struct cmdline *cl,
8290                        __attribute__((unused)) void *data)
8291 {
8292         int is_on, ret = 0;
8293         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8294         struct rte_eth_mac_filter filter;
8295
8296         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8297
8298         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8299
8300         /* set VF MAC filter */
8301         filter.is_vf = 1;
8302
8303         /* set VF ID */
8304         filter.dst_id = res->vf_id;
8305
8306         if (!strcmp(res->filter_type, "exact-mac"))
8307                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8308         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8309                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8310         else if (!strcmp(res->filter_type, "hashmac"))
8311                 filter.filter_type = RTE_MAC_HASH_MATCH;
8312         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8313                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8314
8315         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8316
8317         if (is_on)
8318                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8319                                         RTE_ETH_FILTER_MACVLAN,
8320                                         RTE_ETH_FILTER_ADD,
8321                                          &filter);
8322         else
8323                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8324                                         RTE_ETH_FILTER_MACVLAN,
8325                                         RTE_ETH_FILTER_DELETE,
8326                                         &filter);
8327
8328         if (ret < 0)
8329                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8330
8331 }
8332
8333 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8334         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8335                                  set, "set");
8336 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8337         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8338                                  port, "port");
8339 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8340         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8341                               port_id, UINT16);
8342 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8343         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8344                                  vf, "vf");
8345 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8346         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8347                                 vf_id, UINT8);
8348 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8349         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8350                                 address);
8351 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8352         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8353                                 filter_type, "exact-mac#exact-mac-vlan"
8354                                 "#hashmac#hashmac-vlan");
8355 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8356         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8357                                  mode, "on#off");
8358
8359 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8360         .f = cmd_set_vf_macvlan_parsed,
8361         .data = NULL,
8362         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8363                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8364                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8365                 "hash match rule: hash match of MAC and exact match of VLAN",
8366         .tokens = {
8367                 (void *)&cmd_set_vf_macvlan_set,
8368                 (void *)&cmd_set_vf_macvlan_port,
8369                 (void *)&cmd_set_vf_macvlan_portid,
8370                 (void *)&cmd_set_vf_macvlan_vf,
8371                 (void *)&cmd_set_vf_macvlan_vf_id,
8372                 (void *)&cmd_set_vf_macvlan_mac,
8373                 (void *)&cmd_set_vf_macvlan_filter_type,
8374                 (void *)&cmd_set_vf_macvlan_mode,
8375                 NULL,
8376         },
8377 };
8378
8379 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8380 struct cmd_set_vf_traffic {
8381         cmdline_fixed_string_t set;
8382         cmdline_fixed_string_t port;
8383         portid_t port_id;
8384         cmdline_fixed_string_t vf;
8385         uint8_t vf_id;
8386         cmdline_fixed_string_t what;
8387         cmdline_fixed_string_t mode;
8388 };
8389
8390 static void
8391 cmd_set_vf_traffic_parsed(void *parsed_result,
8392                        __attribute__((unused)) struct cmdline *cl,
8393                        __attribute__((unused)) void *data)
8394 {
8395         struct cmd_set_vf_traffic *res = parsed_result;
8396         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8397         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8398
8399         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8400 }
8401
8402 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8403         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8404                                  set, "set");
8405 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8406         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8407                                  port, "port");
8408 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8409         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8410                               port_id, UINT16);
8411 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8412         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8413                                  vf, "vf");
8414 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8415         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8416                               vf_id, UINT8);
8417 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8418         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8419                                  what, "tx#rx");
8420 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8421         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8422                                  mode, "on#off");
8423
8424 cmdline_parse_inst_t cmd_set_vf_traffic = {
8425         .f = cmd_set_vf_traffic_parsed,
8426         .data = NULL,
8427         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8428         .tokens = {
8429                 (void *)&cmd_setvf_traffic_set,
8430                 (void *)&cmd_setvf_traffic_port,
8431                 (void *)&cmd_setvf_traffic_portid,
8432                 (void *)&cmd_setvf_traffic_vf,
8433                 (void *)&cmd_setvf_traffic_vfid,
8434                 (void *)&cmd_setvf_traffic_what,
8435                 (void *)&cmd_setvf_traffic_mode,
8436                 NULL,
8437         },
8438 };
8439
8440 /* *** CONFIGURE VF RECEIVE MODE *** */
8441 struct cmd_set_vf_rxmode {
8442         cmdline_fixed_string_t set;
8443         cmdline_fixed_string_t port;
8444         portid_t port_id;
8445         cmdline_fixed_string_t vf;
8446         uint8_t vf_id;
8447         cmdline_fixed_string_t what;
8448         cmdline_fixed_string_t mode;
8449         cmdline_fixed_string_t on;
8450 };
8451
8452 static void
8453 cmd_set_vf_rxmode_parsed(void *parsed_result,
8454                        __attribute__((unused)) struct cmdline *cl,
8455                        __attribute__((unused)) void *data)
8456 {
8457         int ret = -ENOTSUP;
8458         uint16_t vf_rxmode = 0;
8459         struct cmd_set_vf_rxmode *res = parsed_result;
8460
8461         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8462         if (!strcmp(res->what,"rxmode")) {
8463                 if (!strcmp(res->mode, "AUPE"))
8464                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8465                 else if (!strcmp(res->mode, "ROPE"))
8466                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8467                 else if (!strcmp(res->mode, "BAM"))
8468                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8469                 else if (!strncmp(res->mode, "MPE",3))
8470                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8471         }
8472
8473         RTE_SET_USED(is_on);
8474
8475 #ifdef RTE_LIBRTE_IXGBE_PMD
8476         if (ret == -ENOTSUP)
8477                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8478                                                   vf_rxmode, (uint8_t)is_on);
8479 #endif
8480 #ifdef RTE_LIBRTE_BNXT_PMD
8481         if (ret == -ENOTSUP)
8482                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8483                                                  vf_rxmode, (uint8_t)is_on);
8484 #endif
8485         if (ret < 0)
8486                 printf("bad VF receive mode parameter, return code = %d \n",
8487                 ret);
8488 }
8489
8490 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8491         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8492                                  set, "set");
8493 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8494         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8495                                  port, "port");
8496 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8497         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8498                               port_id, UINT16);
8499 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8500         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8501                                  vf, "vf");
8502 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8503         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8504                               vf_id, UINT8);
8505 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8506         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8507                                  what, "rxmode");
8508 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8509         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8510                                  mode, "AUPE#ROPE#BAM#MPE");
8511 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8512         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8513                                  on, "on#off");
8514
8515 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8516         .f = cmd_set_vf_rxmode_parsed,
8517         .data = NULL,
8518         .help_str = "set port <port_id> vf <vf_id> rxmode "
8519                 "AUPE|ROPE|BAM|MPE on|off",
8520         .tokens = {
8521                 (void *)&cmd_set_vf_rxmode_set,
8522                 (void *)&cmd_set_vf_rxmode_port,
8523                 (void *)&cmd_set_vf_rxmode_portid,
8524                 (void *)&cmd_set_vf_rxmode_vf,
8525                 (void *)&cmd_set_vf_rxmode_vfid,
8526                 (void *)&cmd_set_vf_rxmode_what,
8527                 (void *)&cmd_set_vf_rxmode_mode,
8528                 (void *)&cmd_set_vf_rxmode_on,
8529                 NULL,
8530         },
8531 };
8532
8533 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8534 struct cmd_vf_mac_addr_result {
8535         cmdline_fixed_string_t mac_addr_cmd;
8536         cmdline_fixed_string_t what;
8537         cmdline_fixed_string_t port;
8538         uint16_t port_num;
8539         cmdline_fixed_string_t vf;
8540         uint8_t vf_num;
8541         struct rte_ether_addr address;
8542 };
8543
8544 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8545                 __attribute__((unused)) struct cmdline *cl,
8546                 __attribute__((unused)) void *data)
8547 {
8548         struct cmd_vf_mac_addr_result *res = parsed_result;
8549         int ret = -ENOTSUP;
8550
8551         if (strcmp(res->what, "add") != 0)
8552                 return;
8553
8554 #ifdef RTE_LIBRTE_I40E_PMD
8555         if (ret == -ENOTSUP)
8556                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8557                                                    &res->address);
8558 #endif
8559 #ifdef RTE_LIBRTE_BNXT_PMD
8560         if (ret == -ENOTSUP)
8561                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8562                                                 res->vf_num);
8563 #endif
8564
8565         if(ret < 0)
8566                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8567
8568 }
8569
8570 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8571         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8572                                 mac_addr_cmd,"mac_addr");
8573 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8574         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8575                                 what,"add");
8576 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8577         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8578                                 port,"port");
8579 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8580         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8581                                 port_num, UINT16);
8582 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8583         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8584                                 vf,"vf");
8585 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8586         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8587                                 vf_num, UINT8);
8588 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8589         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8590                                 address);
8591
8592 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8593         .f = cmd_vf_mac_addr_parsed,
8594         .data = (void *)0,
8595         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8596                 "Add MAC address filtering for a VF on port_id",
8597         .tokens = {
8598                 (void *)&cmd_vf_mac_addr_cmd,
8599                 (void *)&cmd_vf_mac_addr_what,
8600                 (void *)&cmd_vf_mac_addr_port,
8601                 (void *)&cmd_vf_mac_addr_portnum,
8602                 (void *)&cmd_vf_mac_addr_vf,
8603                 (void *)&cmd_vf_mac_addr_vfnum,
8604                 (void *)&cmd_vf_mac_addr_addr,
8605                 NULL,
8606         },
8607 };
8608
8609 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8610 struct cmd_vf_rx_vlan_filter {
8611         cmdline_fixed_string_t rx_vlan;
8612         cmdline_fixed_string_t what;
8613         uint16_t vlan_id;
8614         cmdline_fixed_string_t port;
8615         portid_t port_id;
8616         cmdline_fixed_string_t vf;
8617         uint64_t vf_mask;
8618 };
8619
8620 static void
8621 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8622                           __attribute__((unused)) struct cmdline *cl,
8623                           __attribute__((unused)) void *data)
8624 {
8625         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8626         int ret = -ENOTSUP;
8627
8628         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8629
8630 #ifdef RTE_LIBRTE_IXGBE_PMD
8631         if (ret == -ENOTSUP)
8632                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8633                                 res->vlan_id, res->vf_mask, is_add);
8634 #endif
8635 #ifdef RTE_LIBRTE_I40E_PMD
8636         if (ret == -ENOTSUP)
8637                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8638                                 res->vlan_id, res->vf_mask, is_add);
8639 #endif
8640 #ifdef RTE_LIBRTE_BNXT_PMD
8641         if (ret == -ENOTSUP)
8642                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8643                                 res->vlan_id, res->vf_mask, is_add);
8644 #endif
8645
8646         switch (ret) {
8647         case 0:
8648                 break;
8649         case -EINVAL:
8650                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8651                                 res->vlan_id, res->vf_mask);
8652                 break;
8653         case -ENODEV:
8654                 printf("invalid port_id %d\n", res->port_id);
8655                 break;
8656         case -ENOTSUP:
8657                 printf("function not implemented or supported\n");
8658                 break;
8659         default:
8660                 printf("programming error: (%s)\n", strerror(-ret));
8661         }
8662 }
8663
8664 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8665         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8666                                  rx_vlan, "rx_vlan");
8667 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8668         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8669                                  what, "add#rm");
8670 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8671         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8672                               vlan_id, UINT16);
8673 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8674         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8675                                  port, "port");
8676 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8677         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8678                               port_id, UINT16);
8679 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8680         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8681                                  vf, "vf");
8682 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8683         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8684                               vf_mask, UINT64);
8685
8686 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8687         .f = cmd_vf_rx_vlan_filter_parsed,
8688         .data = NULL,
8689         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8690                 "(vf_mask = hexadecimal VF mask)",
8691         .tokens = {
8692                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8693                 (void *)&cmd_vf_rx_vlan_filter_what,
8694                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8695                 (void *)&cmd_vf_rx_vlan_filter_port,
8696                 (void *)&cmd_vf_rx_vlan_filter_portid,
8697                 (void *)&cmd_vf_rx_vlan_filter_vf,
8698                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8699                 NULL,
8700         },
8701 };
8702
8703 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8704 struct cmd_queue_rate_limit_result {
8705         cmdline_fixed_string_t set;
8706         cmdline_fixed_string_t port;
8707         uint16_t port_num;
8708         cmdline_fixed_string_t queue;
8709         uint8_t queue_num;
8710         cmdline_fixed_string_t rate;
8711         uint16_t rate_num;
8712 };
8713
8714 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8715                 __attribute__((unused)) struct cmdline *cl,
8716                 __attribute__((unused)) void *data)
8717 {
8718         struct cmd_queue_rate_limit_result *res = parsed_result;
8719         int ret = 0;
8720
8721         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8722                 && (strcmp(res->queue, "queue") == 0)
8723                 && (strcmp(res->rate, "rate") == 0))
8724                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8725                                         res->rate_num);
8726         if (ret < 0)
8727                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8728
8729 }
8730
8731 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8732         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8733                                 set, "set");
8734 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8735         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8736                                 port, "port");
8737 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8738         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8739                                 port_num, UINT16);
8740 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8741         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8742                                 queue, "queue");
8743 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8744         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8745                                 queue_num, UINT8);
8746 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8747         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8748                                 rate, "rate");
8749 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8750         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8751                                 rate_num, UINT16);
8752
8753 cmdline_parse_inst_t cmd_queue_rate_limit = {
8754         .f = cmd_queue_rate_limit_parsed,
8755         .data = (void *)0,
8756         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8757                 "Set rate limit for a queue on port_id",
8758         .tokens = {
8759                 (void *)&cmd_queue_rate_limit_set,
8760                 (void *)&cmd_queue_rate_limit_port,
8761                 (void *)&cmd_queue_rate_limit_portnum,
8762                 (void *)&cmd_queue_rate_limit_queue,
8763                 (void *)&cmd_queue_rate_limit_queuenum,
8764                 (void *)&cmd_queue_rate_limit_rate,
8765                 (void *)&cmd_queue_rate_limit_ratenum,
8766                 NULL,
8767         },
8768 };
8769
8770 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8771 struct cmd_vf_rate_limit_result {
8772         cmdline_fixed_string_t set;
8773         cmdline_fixed_string_t port;
8774         uint16_t port_num;
8775         cmdline_fixed_string_t vf;
8776         uint8_t vf_num;
8777         cmdline_fixed_string_t rate;
8778         uint16_t rate_num;
8779         cmdline_fixed_string_t q_msk;
8780         uint64_t q_msk_val;
8781 };
8782
8783 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8784                 __attribute__((unused)) struct cmdline *cl,
8785                 __attribute__((unused)) void *data)
8786 {
8787         struct cmd_vf_rate_limit_result *res = parsed_result;
8788         int ret = 0;
8789
8790         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8791                 && (strcmp(res->vf, "vf") == 0)
8792                 && (strcmp(res->rate, "rate") == 0)
8793                 && (strcmp(res->q_msk, "queue_mask") == 0))
8794                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8795                                         res->rate_num, res->q_msk_val);
8796         if (ret < 0)
8797                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8798
8799 }
8800
8801 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8802         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8803                                 set, "set");
8804 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8805         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8806                                 port, "port");
8807 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8808         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8809                                 port_num, UINT16);
8810 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8811         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8812                                 vf, "vf");
8813 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8814         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8815                                 vf_num, UINT8);
8816 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8817         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8818                                 rate, "rate");
8819 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8820         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8821                                 rate_num, UINT16);
8822 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8823         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8824                                 q_msk, "queue_mask");
8825 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8826         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8827                                 q_msk_val, UINT64);
8828
8829 cmdline_parse_inst_t cmd_vf_rate_limit = {
8830         .f = cmd_vf_rate_limit_parsed,
8831         .data = (void *)0,
8832         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8833                 "queue_mask <queue_mask_value>: "
8834                 "Set rate limit for queues of VF on port_id",
8835         .tokens = {
8836                 (void *)&cmd_vf_rate_limit_set,
8837                 (void *)&cmd_vf_rate_limit_port,
8838                 (void *)&cmd_vf_rate_limit_portnum,
8839                 (void *)&cmd_vf_rate_limit_vf,
8840                 (void *)&cmd_vf_rate_limit_vfnum,
8841                 (void *)&cmd_vf_rate_limit_rate,
8842                 (void *)&cmd_vf_rate_limit_ratenum,
8843                 (void *)&cmd_vf_rate_limit_q_msk,
8844                 (void *)&cmd_vf_rate_limit_q_msk_val,
8845                 NULL,
8846         },
8847 };
8848
8849 /* *** ADD TUNNEL FILTER OF A PORT *** */
8850 struct cmd_tunnel_filter_result {
8851         cmdline_fixed_string_t cmd;
8852         cmdline_fixed_string_t what;
8853         portid_t port_id;
8854         struct rte_ether_addr outer_mac;
8855         struct rte_ether_addr inner_mac;
8856         cmdline_ipaddr_t ip_value;
8857         uint16_t inner_vlan;
8858         cmdline_fixed_string_t tunnel_type;
8859         cmdline_fixed_string_t filter_type;
8860         uint32_t tenant_id;
8861         uint16_t queue_num;
8862 };
8863
8864 static void
8865 cmd_tunnel_filter_parsed(void *parsed_result,
8866                           __attribute__((unused)) struct cmdline *cl,
8867                           __attribute__((unused)) void *data)
8868 {
8869         struct cmd_tunnel_filter_result *res = parsed_result;
8870         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8871         int ret = 0;
8872
8873         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8874
8875         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8876         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8877         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8878
8879         if (res->ip_value.family == AF_INET) {
8880                 tunnel_filter_conf.ip_addr.ipv4_addr =
8881                         res->ip_value.addr.ipv4.s_addr;
8882                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8883         } else {
8884                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8885                         &(res->ip_value.addr.ipv6),
8886                         sizeof(struct in6_addr));
8887                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8888         }
8889
8890         if (!strcmp(res->filter_type, "imac-ivlan"))
8891                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8892         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8893                 tunnel_filter_conf.filter_type =
8894                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8895         else if (!strcmp(res->filter_type, "imac-tenid"))
8896                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8897         else if (!strcmp(res->filter_type, "imac"))
8898                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8899         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8900                 tunnel_filter_conf.filter_type =
8901                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8902         else if (!strcmp(res->filter_type, "oip"))
8903                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8904         else if (!strcmp(res->filter_type, "iip"))
8905                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8906         else {
8907                 printf("The filter type is not supported");
8908                 return;
8909         }
8910
8911         if (!strcmp(res->tunnel_type, "vxlan"))
8912                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8913         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8914                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8915         else if (!strcmp(res->tunnel_type, "nvgre"))
8916                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8917         else if (!strcmp(res->tunnel_type, "ipingre"))
8918                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8919         else {
8920                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8921                 return;
8922         }
8923
8924         tunnel_filter_conf.tenant_id = res->tenant_id;
8925         tunnel_filter_conf.queue_id = res->queue_num;
8926         if (!strcmp(res->what, "add"))
8927                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8928                                         RTE_ETH_FILTER_TUNNEL,
8929                                         RTE_ETH_FILTER_ADD,
8930                                         &tunnel_filter_conf);
8931         else
8932                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8933                                         RTE_ETH_FILTER_TUNNEL,
8934                                         RTE_ETH_FILTER_DELETE,
8935                                         &tunnel_filter_conf);
8936         if (ret < 0)
8937                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8938                                 strerror(-ret));
8939
8940 }
8941 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8942         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8943         cmd, "tunnel_filter");
8944 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8945         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8946         what, "add#rm");
8947 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8948         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8949         port_id, UINT16);
8950 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8951         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8952         outer_mac);
8953 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8954         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8955         inner_mac);
8956 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8957         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8958         inner_vlan, UINT16);
8959 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8960         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8961         ip_value);
8962 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8963         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8964         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8965
8966 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8967         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8968         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8969                 "imac#omac-imac-tenid");
8970 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8971         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8972         tenant_id, UINT32);
8973 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8974         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8975         queue_num, UINT16);
8976
8977 cmdline_parse_inst_t cmd_tunnel_filter = {
8978         .f = cmd_tunnel_filter_parsed,
8979         .data = (void *)0,
8980         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8981                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8982                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8983                 "<queue_id>: Add/Rm tunnel filter of a port",
8984         .tokens = {
8985                 (void *)&cmd_tunnel_filter_cmd,
8986                 (void *)&cmd_tunnel_filter_what,
8987                 (void *)&cmd_tunnel_filter_port_id,
8988                 (void *)&cmd_tunnel_filter_outer_mac,
8989                 (void *)&cmd_tunnel_filter_inner_mac,
8990                 (void *)&cmd_tunnel_filter_ip_value,
8991                 (void *)&cmd_tunnel_filter_innner_vlan,
8992                 (void *)&cmd_tunnel_filter_tunnel_type,
8993                 (void *)&cmd_tunnel_filter_filter_type,
8994                 (void *)&cmd_tunnel_filter_tenant_id,
8995                 (void *)&cmd_tunnel_filter_queue_num,
8996                 NULL,
8997         },
8998 };
8999
9000 /* *** CONFIGURE TUNNEL UDP PORT *** */
9001 struct cmd_tunnel_udp_config {
9002         cmdline_fixed_string_t cmd;
9003         cmdline_fixed_string_t what;
9004         uint16_t udp_port;
9005         portid_t port_id;
9006 };
9007
9008 static void
9009 cmd_tunnel_udp_config_parsed(void *parsed_result,
9010                           __attribute__((unused)) struct cmdline *cl,
9011                           __attribute__((unused)) void *data)
9012 {
9013         struct cmd_tunnel_udp_config *res = parsed_result;
9014         struct rte_eth_udp_tunnel tunnel_udp;
9015         int ret;
9016
9017         tunnel_udp.udp_port = res->udp_port;
9018
9019         if (!strcmp(res->cmd, "rx_vxlan_port"))
9020                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9021
9022         if (!strcmp(res->what, "add"))
9023                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9024                                                       &tunnel_udp);
9025         else
9026                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9027                                                          &tunnel_udp);
9028
9029         if (ret < 0)
9030                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9031 }
9032
9033 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9034         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9035                                 cmd, "rx_vxlan_port");
9036 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9037         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9038                                 what, "add#rm");
9039 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9040         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9041                                 udp_port, UINT16);
9042 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9043         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9044                                 port_id, UINT16);
9045
9046 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9047         .f = cmd_tunnel_udp_config_parsed,
9048         .data = (void *)0,
9049         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9050                 "Add/Remove a tunneling UDP port filter",
9051         .tokens = {
9052                 (void *)&cmd_tunnel_udp_config_cmd,
9053                 (void *)&cmd_tunnel_udp_config_what,
9054                 (void *)&cmd_tunnel_udp_config_udp_port,
9055                 (void *)&cmd_tunnel_udp_config_port_id,
9056                 NULL,
9057         },
9058 };
9059
9060 struct cmd_config_tunnel_udp_port {
9061         cmdline_fixed_string_t port;
9062         cmdline_fixed_string_t config;
9063         portid_t port_id;
9064         cmdline_fixed_string_t udp_tunnel_port;
9065         cmdline_fixed_string_t action;
9066         cmdline_fixed_string_t tunnel_type;
9067         uint16_t udp_port;
9068 };
9069
9070 static void
9071 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9072                                __attribute__((unused)) struct cmdline *cl,
9073                                __attribute__((unused)) void *data)
9074 {
9075         struct cmd_config_tunnel_udp_port *res = parsed_result;
9076         struct rte_eth_udp_tunnel tunnel_udp;
9077         int ret = 0;
9078
9079         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9080                 return;
9081
9082         tunnel_udp.udp_port = res->udp_port;
9083
9084         if (!strcmp(res->tunnel_type, "vxlan")) {
9085                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9086         } else if (!strcmp(res->tunnel_type, "geneve")) {
9087                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9088         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9089                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9090         } else {
9091                 printf("Invalid tunnel type\n");
9092                 return;
9093         }
9094
9095         if (!strcmp(res->action, "add"))
9096                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9097                                                       &tunnel_udp);
9098         else
9099                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9100                                                          &tunnel_udp);
9101
9102         if (ret < 0)
9103                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9104 }
9105
9106 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9107         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9108                                  "port");
9109 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9110         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9111                                  "config");
9112 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9113         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9114                               UINT16);
9115 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9116         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9117                                  udp_tunnel_port,
9118                                  "udp_tunnel_port");
9119 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9120         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9121                                  "add#rm");
9122 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9123         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9124                                  "vxlan#geneve#vxlan-gpe");
9125 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9126         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9127                               UINT16);
9128
9129 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9130         .f = cmd_cfg_tunnel_udp_port_parsed,
9131         .data = NULL,
9132         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9133         .tokens = {
9134                 (void *)&cmd_config_tunnel_udp_port_port,
9135                 (void *)&cmd_config_tunnel_udp_port_config,
9136                 (void *)&cmd_config_tunnel_udp_port_port_id,
9137                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9138                 (void *)&cmd_config_tunnel_udp_port_action,
9139                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9140                 (void *)&cmd_config_tunnel_udp_port_value,
9141                 NULL,
9142         },
9143 };
9144
9145 /* *** GLOBAL CONFIG *** */
9146 struct cmd_global_config_result {
9147         cmdline_fixed_string_t cmd;
9148         portid_t port_id;
9149         cmdline_fixed_string_t cfg_type;
9150         uint8_t len;
9151 };
9152
9153 static void
9154 cmd_global_config_parsed(void *parsed_result,
9155                          __attribute__((unused)) struct cmdline *cl,
9156                          __attribute__((unused)) void *data)
9157 {
9158         struct cmd_global_config_result *res = parsed_result;
9159         struct rte_eth_global_cfg conf;
9160         int ret;
9161
9162         memset(&conf, 0, sizeof(conf));
9163         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9164         conf.cfg.gre_key_len = res->len;
9165         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9166                                       RTE_ETH_FILTER_SET, &conf);
9167         if (ret != 0)
9168                 printf("Global config error\n");
9169 }
9170
9171 cmdline_parse_token_string_t cmd_global_config_cmd =
9172         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9173                 "global_config");
9174 cmdline_parse_token_num_t cmd_global_config_port_id =
9175         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9176                                UINT16);
9177 cmdline_parse_token_string_t cmd_global_config_type =
9178         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9179                 cfg_type, "gre-key-len");
9180 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9181         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9182                 len, UINT8);
9183
9184 cmdline_parse_inst_t cmd_global_config = {
9185         .f = cmd_global_config_parsed,
9186         .data = (void *)NULL,
9187         .help_str = "global_config <port_id> gre-key-len <key_len>",
9188         .tokens = {
9189                 (void *)&cmd_global_config_cmd,
9190                 (void *)&cmd_global_config_port_id,
9191                 (void *)&cmd_global_config_type,
9192                 (void *)&cmd_global_config_gre_key_len,
9193                 NULL,
9194         },
9195 };
9196
9197 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9198 struct cmd_set_mirror_mask_result {
9199         cmdline_fixed_string_t set;
9200         cmdline_fixed_string_t port;
9201         portid_t port_id;
9202         cmdline_fixed_string_t mirror;
9203         uint8_t rule_id;
9204         cmdline_fixed_string_t what;
9205         cmdline_fixed_string_t value;
9206         cmdline_fixed_string_t dstpool;
9207         uint8_t dstpool_id;
9208         cmdline_fixed_string_t on;
9209 };
9210
9211 cmdline_parse_token_string_t cmd_mirror_mask_set =
9212         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9213                                 set, "set");
9214 cmdline_parse_token_string_t cmd_mirror_mask_port =
9215         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9216                                 port, "port");
9217 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9218         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9219                                 port_id, UINT16);
9220 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9221         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9222                                 mirror, "mirror-rule");
9223 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9224         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9225                                 rule_id, UINT8);
9226 cmdline_parse_token_string_t cmd_mirror_mask_what =
9227         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9228                                 what, "pool-mirror-up#pool-mirror-down"
9229                                       "#vlan-mirror");
9230 cmdline_parse_token_string_t cmd_mirror_mask_value =
9231         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9232                                 value, NULL);
9233 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9234         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9235                                 dstpool, "dst-pool");
9236 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9237         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9238                                 dstpool_id, UINT8);
9239 cmdline_parse_token_string_t cmd_mirror_mask_on =
9240         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9241                                 on, "on#off");
9242
9243 static void
9244 cmd_set_mirror_mask_parsed(void *parsed_result,
9245                        __attribute__((unused)) struct cmdline *cl,
9246                        __attribute__((unused)) void *data)
9247 {
9248         int ret,nb_item,i;
9249         struct cmd_set_mirror_mask_result *res = parsed_result;
9250         struct rte_eth_mirror_conf mr_conf;
9251
9252         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9253
9254         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9255
9256         mr_conf.dst_pool = res->dstpool_id;
9257
9258         if (!strcmp(res->what, "pool-mirror-up")) {
9259                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9260                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9261         } else if (!strcmp(res->what, "pool-mirror-down")) {
9262                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9263                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9264         } else if (!strcmp(res->what, "vlan-mirror")) {
9265                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9266                 nb_item = parse_item_list(res->value, "vlan",
9267                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9268                 if (nb_item <= 0)
9269                         return;
9270
9271                 for (i = 0; i < nb_item; i++) {
9272                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9273                                 printf("Invalid vlan_id: must be < 4096\n");
9274                                 return;
9275                         }
9276
9277                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9278                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9279                 }
9280         }
9281
9282         if (!strcmp(res->on, "on"))
9283                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9284                                                 res->rule_id, 1);
9285         else
9286                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9287                                                 res->rule_id, 0);
9288         if (ret < 0)
9289                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9290 }
9291
9292 cmdline_parse_inst_t cmd_set_mirror_mask = {
9293                 .f = cmd_set_mirror_mask_parsed,
9294                 .data = NULL,
9295                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9296                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9297                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9298                 .tokens = {
9299                         (void *)&cmd_mirror_mask_set,
9300                         (void *)&cmd_mirror_mask_port,
9301                         (void *)&cmd_mirror_mask_portid,
9302                         (void *)&cmd_mirror_mask_mirror,
9303                         (void *)&cmd_mirror_mask_ruleid,
9304                         (void *)&cmd_mirror_mask_what,
9305                         (void *)&cmd_mirror_mask_value,
9306                         (void *)&cmd_mirror_mask_dstpool,
9307                         (void *)&cmd_mirror_mask_poolid,
9308                         (void *)&cmd_mirror_mask_on,
9309                         NULL,
9310                 },
9311 };
9312
9313 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9314 struct cmd_set_mirror_link_result {
9315         cmdline_fixed_string_t set;
9316         cmdline_fixed_string_t port;
9317         portid_t port_id;
9318         cmdline_fixed_string_t mirror;
9319         uint8_t rule_id;
9320         cmdline_fixed_string_t what;
9321         cmdline_fixed_string_t dstpool;
9322         uint8_t dstpool_id;
9323         cmdline_fixed_string_t on;
9324 };
9325
9326 cmdline_parse_token_string_t cmd_mirror_link_set =
9327         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9328                                  set, "set");
9329 cmdline_parse_token_string_t cmd_mirror_link_port =
9330         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9331                                 port, "port");
9332 cmdline_parse_token_num_t cmd_mirror_link_portid =
9333         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9334                                 port_id, UINT16);
9335 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9336         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9337                                 mirror, "mirror-rule");
9338 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9339         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9340                             rule_id, UINT8);
9341 cmdline_parse_token_string_t cmd_mirror_link_what =
9342         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9343                                 what, "uplink-mirror#downlink-mirror");
9344 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9345         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9346                                 dstpool, "dst-pool");
9347 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9348         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9349                                 dstpool_id, UINT8);
9350 cmdline_parse_token_string_t cmd_mirror_link_on =
9351         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9352                                 on, "on#off");
9353
9354 static void
9355 cmd_set_mirror_link_parsed(void *parsed_result,
9356                        __attribute__((unused)) struct cmdline *cl,
9357                        __attribute__((unused)) void *data)
9358 {
9359         int ret;
9360         struct cmd_set_mirror_link_result *res = parsed_result;
9361         struct rte_eth_mirror_conf mr_conf;
9362
9363         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9364         if (!strcmp(res->what, "uplink-mirror"))
9365                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9366         else
9367                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9368
9369         mr_conf.dst_pool = res->dstpool_id;
9370
9371         if (!strcmp(res->on, "on"))
9372                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9373                                                 res->rule_id, 1);
9374         else
9375                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9376                                                 res->rule_id, 0);
9377
9378         /* check the return value and print it if is < 0 */
9379         if (ret < 0)
9380                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9381
9382 }
9383
9384 cmdline_parse_inst_t cmd_set_mirror_link = {
9385                 .f = cmd_set_mirror_link_parsed,
9386                 .data = NULL,
9387                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9388                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9389                 .tokens = {
9390                         (void *)&cmd_mirror_link_set,
9391                         (void *)&cmd_mirror_link_port,
9392                         (void *)&cmd_mirror_link_portid,
9393                         (void *)&cmd_mirror_link_mirror,
9394                         (void *)&cmd_mirror_link_ruleid,
9395                         (void *)&cmd_mirror_link_what,
9396                         (void *)&cmd_mirror_link_dstpool,
9397                         (void *)&cmd_mirror_link_poolid,
9398                         (void *)&cmd_mirror_link_on,
9399                         NULL,
9400                 },
9401 };
9402
9403 /* *** RESET VM MIRROR RULE *** */
9404 struct cmd_rm_mirror_rule_result {
9405         cmdline_fixed_string_t reset;
9406         cmdline_fixed_string_t port;
9407         portid_t port_id;
9408         cmdline_fixed_string_t mirror;
9409         uint8_t rule_id;
9410 };
9411
9412 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9413         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9414                                  reset, "reset");
9415 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9416         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9417                                 port, "port");
9418 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9419         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9420                                 port_id, UINT16);
9421 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9422         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9423                                 mirror, "mirror-rule");
9424 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9425         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9426                                 rule_id, UINT8);
9427
9428 static void
9429 cmd_reset_mirror_rule_parsed(void *parsed_result,
9430                        __attribute__((unused)) struct cmdline *cl,
9431                        __attribute__((unused)) void *data)
9432 {
9433         int ret;
9434         struct cmd_set_mirror_link_result *res = parsed_result;
9435         /* check rule_id */
9436         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9437         if(ret < 0)
9438                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9439 }
9440
9441 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9442                 .f = cmd_reset_mirror_rule_parsed,
9443                 .data = NULL,
9444                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9445                 .tokens = {
9446                         (void *)&cmd_rm_mirror_rule_reset,
9447                         (void *)&cmd_rm_mirror_rule_port,
9448                         (void *)&cmd_rm_mirror_rule_portid,
9449                         (void *)&cmd_rm_mirror_rule_mirror,
9450                         (void *)&cmd_rm_mirror_rule_ruleid,
9451                         NULL,
9452                 },
9453 };
9454
9455 /* ******************************************************************************** */
9456
9457 struct cmd_dump_result {
9458         cmdline_fixed_string_t dump;
9459 };
9460
9461 static void
9462 dump_struct_sizes(void)
9463 {
9464 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9465         DUMP_SIZE(struct rte_mbuf);
9466         DUMP_SIZE(struct rte_mempool);
9467         DUMP_SIZE(struct rte_ring);
9468 #undef DUMP_SIZE
9469 }
9470
9471 static void cmd_dump_parsed(void *parsed_result,
9472                             __attribute__((unused)) struct cmdline *cl,
9473                             __attribute__((unused)) void *data)
9474 {
9475         struct cmd_dump_result *res = parsed_result;
9476
9477         if (!strcmp(res->dump, "dump_physmem"))
9478                 rte_dump_physmem_layout(stdout);
9479         else if (!strcmp(res->dump, "dump_memzone"))
9480                 rte_memzone_dump(stdout);
9481         else if (!strcmp(res->dump, "dump_struct_sizes"))
9482                 dump_struct_sizes();
9483         else if (!strcmp(res->dump, "dump_ring"))
9484                 rte_ring_list_dump(stdout);
9485         else if (!strcmp(res->dump, "dump_mempool"))
9486                 rte_mempool_list_dump(stdout);
9487         else if (!strcmp(res->dump, "dump_devargs"))
9488                 rte_devargs_dump(stdout);
9489         else if (!strcmp(res->dump, "dump_log_types"))
9490                 rte_log_dump(stdout);
9491 }
9492
9493 cmdline_parse_token_string_t cmd_dump_dump =
9494         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9495                 "dump_physmem#"
9496                 "dump_memzone#"
9497                 "dump_struct_sizes#"
9498                 "dump_ring#"
9499                 "dump_mempool#"
9500                 "dump_devargs#"
9501                 "dump_log_types");
9502
9503 cmdline_parse_inst_t cmd_dump = {
9504         .f = cmd_dump_parsed,  /* function to call */
9505         .data = NULL,      /* 2nd arg of func */
9506         .help_str = "Dump status",
9507         .tokens = {        /* token list, NULL terminated */
9508                 (void *)&cmd_dump_dump,
9509                 NULL,
9510         },
9511 };
9512
9513 /* ******************************************************************************** */
9514
9515 struct cmd_dump_one_result {
9516         cmdline_fixed_string_t dump;
9517         cmdline_fixed_string_t name;
9518 };
9519
9520 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9521                                 __attribute__((unused)) void *data)
9522 {
9523         struct cmd_dump_one_result *res = parsed_result;
9524
9525         if (!strcmp(res->dump, "dump_ring")) {
9526                 struct rte_ring *r;
9527                 r = rte_ring_lookup(res->name);
9528                 if (r == NULL) {
9529                         cmdline_printf(cl, "Cannot find ring\n");
9530                         return;
9531                 }
9532                 rte_ring_dump(stdout, r);
9533         } else if (!strcmp(res->dump, "dump_mempool")) {
9534                 struct rte_mempool *mp;
9535                 mp = rte_mempool_lookup(res->name);
9536                 if (mp == NULL) {
9537                         cmdline_printf(cl, "Cannot find mempool\n");
9538                         return;
9539                 }
9540                 rte_mempool_dump(stdout, mp);
9541         }
9542 }
9543
9544 cmdline_parse_token_string_t cmd_dump_one_dump =
9545         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9546                                  "dump_ring#dump_mempool");
9547
9548 cmdline_parse_token_string_t cmd_dump_one_name =
9549         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9550
9551 cmdline_parse_inst_t cmd_dump_one = {
9552         .f = cmd_dump_one_parsed,  /* function to call */
9553         .data = NULL,      /* 2nd arg of func */
9554         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9555         .tokens = {        /* token list, NULL terminated */
9556                 (void *)&cmd_dump_one_dump,
9557                 (void *)&cmd_dump_one_name,
9558                 NULL,
9559         },
9560 };
9561
9562 /* *** Add/Del syn filter *** */
9563 struct cmd_syn_filter_result {
9564         cmdline_fixed_string_t filter;
9565         portid_t port_id;
9566         cmdline_fixed_string_t ops;
9567         cmdline_fixed_string_t priority;
9568         cmdline_fixed_string_t high;
9569         cmdline_fixed_string_t queue;
9570         uint16_t queue_id;
9571 };
9572
9573 static void
9574 cmd_syn_filter_parsed(void *parsed_result,
9575                         __attribute__((unused)) struct cmdline *cl,
9576                         __attribute__((unused)) void *data)
9577 {
9578         struct cmd_syn_filter_result *res = parsed_result;
9579         struct rte_eth_syn_filter syn_filter;
9580         int ret = 0;
9581
9582         ret = rte_eth_dev_filter_supported(res->port_id,
9583                                         RTE_ETH_FILTER_SYN);
9584         if (ret < 0) {
9585                 printf("syn filter is not supported on port %u.\n",
9586                                 res->port_id);
9587                 return;
9588         }
9589
9590         memset(&syn_filter, 0, sizeof(syn_filter));
9591
9592         if (!strcmp(res->ops, "add")) {
9593                 if (!strcmp(res->high, "high"))
9594                         syn_filter.hig_pri = 1;
9595                 else
9596                         syn_filter.hig_pri = 0;
9597
9598                 syn_filter.queue = res->queue_id;
9599                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9600                                                 RTE_ETH_FILTER_SYN,
9601                                                 RTE_ETH_FILTER_ADD,
9602                                                 &syn_filter);
9603         } else
9604                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9605                                                 RTE_ETH_FILTER_SYN,
9606                                                 RTE_ETH_FILTER_DELETE,
9607                                                 &syn_filter);
9608
9609         if (ret < 0)
9610                 printf("syn filter programming error: (%s)\n",
9611                                 strerror(-ret));
9612 }
9613
9614 cmdline_parse_token_string_t cmd_syn_filter_filter =
9615         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9616         filter, "syn_filter");
9617 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9618         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9619         port_id, UINT16);
9620 cmdline_parse_token_string_t cmd_syn_filter_ops =
9621         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9622         ops, "add#del");
9623 cmdline_parse_token_string_t cmd_syn_filter_priority =
9624         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9625                                 priority, "priority");
9626 cmdline_parse_token_string_t cmd_syn_filter_high =
9627         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9628                                 high, "high#low");
9629 cmdline_parse_token_string_t cmd_syn_filter_queue =
9630         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9631                                 queue, "queue");
9632 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9633         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9634                                 queue_id, UINT16);
9635
9636 cmdline_parse_inst_t cmd_syn_filter = {
9637         .f = cmd_syn_filter_parsed,
9638         .data = NULL,
9639         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9640                 "<queue_id>: Add/Delete syn filter",
9641         .tokens = {
9642                 (void *)&cmd_syn_filter_filter,
9643                 (void *)&cmd_syn_filter_port_id,
9644                 (void *)&cmd_syn_filter_ops,
9645                 (void *)&cmd_syn_filter_priority,
9646                 (void *)&cmd_syn_filter_high,
9647                 (void *)&cmd_syn_filter_queue,
9648                 (void *)&cmd_syn_filter_queue_id,
9649                 NULL,
9650         },
9651 };
9652
9653 /* *** queue region set *** */
9654 struct cmd_queue_region_result {
9655         cmdline_fixed_string_t set;
9656         cmdline_fixed_string_t port;
9657         portid_t port_id;
9658         cmdline_fixed_string_t cmd;
9659         cmdline_fixed_string_t region;
9660         uint8_t  region_id;
9661         cmdline_fixed_string_t queue_start_index;
9662         uint8_t  queue_id;
9663         cmdline_fixed_string_t queue_num;
9664         uint8_t  queue_num_value;
9665 };
9666
9667 static void
9668 cmd_queue_region_parsed(void *parsed_result,
9669                         __attribute__((unused)) struct cmdline *cl,
9670                         __attribute__((unused)) void *data)
9671 {
9672         struct cmd_queue_region_result *res = parsed_result;
9673         int ret = -ENOTSUP;
9674 #ifdef RTE_LIBRTE_I40E_PMD
9675         struct rte_pmd_i40e_queue_region_conf region_conf;
9676         enum rte_pmd_i40e_queue_region_op op_type;
9677 #endif
9678
9679         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9680                 return;
9681
9682 #ifdef RTE_LIBRTE_I40E_PMD
9683         memset(&region_conf, 0, sizeof(region_conf));
9684         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9685         region_conf.region_id = res->region_id;
9686         region_conf.queue_num = res->queue_num_value;
9687         region_conf.queue_start_index = res->queue_id;
9688
9689         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9690                                 op_type, &region_conf);
9691 #endif
9692
9693         switch (ret) {
9694         case 0:
9695                 break;
9696         case -ENOTSUP:
9697                 printf("function not implemented or supported\n");
9698                 break;
9699         default:
9700                 printf("queue region config error: (%s)\n", strerror(-ret));
9701         }
9702 }
9703
9704 cmdline_parse_token_string_t cmd_queue_region_set =
9705 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9706                 set, "set");
9707 cmdline_parse_token_string_t cmd_queue_region_port =
9708         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9709 cmdline_parse_token_num_t cmd_queue_region_port_id =
9710         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9711                                 port_id, UINT16);
9712 cmdline_parse_token_string_t cmd_queue_region_cmd =
9713         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9714                                  cmd, "queue-region");
9715 cmdline_parse_token_string_t cmd_queue_region_id =
9716         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9717                                 region, "region_id");
9718 cmdline_parse_token_num_t cmd_queue_region_index =
9719         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9720                                 region_id, UINT8);
9721 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9722         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9723                                 queue_start_index, "queue_start_index");
9724 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9725         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9726                                 queue_id, UINT8);
9727 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9728         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9729                                 queue_num, "queue_num");
9730 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9731         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9732                                 queue_num_value, UINT8);
9733
9734 cmdline_parse_inst_t cmd_queue_region = {
9735         .f = cmd_queue_region_parsed,
9736         .data = NULL,
9737         .help_str = "set port <port_id> queue-region region_id <value> "
9738                 "queue_start_index <value> queue_num <value>: Set a queue region",
9739         .tokens = {
9740                 (void *)&cmd_queue_region_set,
9741                 (void *)&cmd_queue_region_port,
9742                 (void *)&cmd_queue_region_port_id,
9743                 (void *)&cmd_queue_region_cmd,
9744                 (void *)&cmd_queue_region_id,
9745                 (void *)&cmd_queue_region_index,
9746                 (void *)&cmd_queue_region_queue_start_index,
9747                 (void *)&cmd_queue_region_queue_id,
9748                 (void *)&cmd_queue_region_queue_num,
9749                 (void *)&cmd_queue_region_queue_num_value,
9750                 NULL,
9751         },
9752 };
9753
9754 /* *** queue region and flowtype set *** */
9755 struct cmd_region_flowtype_result {
9756         cmdline_fixed_string_t set;
9757         cmdline_fixed_string_t port;
9758         portid_t port_id;
9759         cmdline_fixed_string_t cmd;
9760         cmdline_fixed_string_t region;
9761         uint8_t  region_id;
9762         cmdline_fixed_string_t flowtype;
9763         uint8_t  flowtype_id;
9764 };
9765
9766 static void
9767 cmd_region_flowtype_parsed(void *parsed_result,
9768                         __attribute__((unused)) struct cmdline *cl,
9769                         __attribute__((unused)) void *data)
9770 {
9771         struct cmd_region_flowtype_result *res = parsed_result;
9772         int ret = -ENOTSUP;
9773 #ifdef RTE_LIBRTE_I40E_PMD
9774         struct rte_pmd_i40e_queue_region_conf region_conf;
9775         enum rte_pmd_i40e_queue_region_op op_type;
9776 #endif
9777
9778         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9779                 return;
9780
9781 #ifdef RTE_LIBRTE_I40E_PMD
9782         memset(&region_conf, 0, sizeof(region_conf));
9783
9784         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9785         region_conf.region_id = res->region_id;
9786         region_conf.hw_flowtype = res->flowtype_id;
9787
9788         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9789                         op_type, &region_conf);
9790 #endif
9791
9792         switch (ret) {
9793         case 0:
9794                 break;
9795         case -ENOTSUP:
9796                 printf("function not implemented or supported\n");
9797                 break;
9798         default:
9799                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9800         }
9801 }
9802
9803 cmdline_parse_token_string_t cmd_region_flowtype_set =
9804 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9805                                 set, "set");
9806 cmdline_parse_token_string_t cmd_region_flowtype_port =
9807         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9808                                 port, "port");
9809 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9810         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9811                                 port_id, UINT16);
9812 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9813         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9814                                 cmd, "queue-region");
9815 cmdline_parse_token_string_t cmd_region_flowtype_index =
9816         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9817                                 region, "region_id");
9818 cmdline_parse_token_num_t cmd_region_flowtype_id =
9819         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9820                                 region_id, UINT8);
9821 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9822         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9823                                 flowtype, "flowtype");
9824 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9825         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9826                                 flowtype_id, UINT8);
9827 cmdline_parse_inst_t cmd_region_flowtype = {
9828         .f = cmd_region_flowtype_parsed,
9829         .data = NULL,
9830         .help_str = "set port <port_id> queue-region region_id <value> "
9831                 "flowtype <value>: Set a flowtype region index",
9832         .tokens = {
9833                 (void *)&cmd_region_flowtype_set,
9834                 (void *)&cmd_region_flowtype_port,
9835                 (void *)&cmd_region_flowtype_port_index,
9836                 (void *)&cmd_region_flowtype_cmd,
9837                 (void *)&cmd_region_flowtype_index,
9838                 (void *)&cmd_region_flowtype_id,
9839                 (void *)&cmd_region_flowtype_flow_index,
9840                 (void *)&cmd_region_flowtype_flow_id,
9841                 NULL,
9842         },
9843 };
9844
9845 /* *** User Priority (UP) to queue region (region_id) set *** */
9846 struct cmd_user_priority_region_result {
9847         cmdline_fixed_string_t set;
9848         cmdline_fixed_string_t port;
9849         portid_t port_id;
9850         cmdline_fixed_string_t cmd;
9851         cmdline_fixed_string_t user_priority;
9852         uint8_t  user_priority_id;
9853         cmdline_fixed_string_t region;
9854         uint8_t  region_id;
9855 };
9856
9857 static void
9858 cmd_user_priority_region_parsed(void *parsed_result,
9859                         __attribute__((unused)) struct cmdline *cl,
9860                         __attribute__((unused)) void *data)
9861 {
9862         struct cmd_user_priority_region_result *res = parsed_result;
9863         int ret = -ENOTSUP;
9864 #ifdef RTE_LIBRTE_I40E_PMD
9865         struct rte_pmd_i40e_queue_region_conf region_conf;
9866         enum rte_pmd_i40e_queue_region_op op_type;
9867 #endif
9868
9869         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9870                 return;
9871
9872 #ifdef RTE_LIBRTE_I40E_PMD
9873         memset(&region_conf, 0, sizeof(region_conf));
9874         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9875         region_conf.user_priority = res->user_priority_id;
9876         region_conf.region_id = res->region_id;
9877
9878         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9879                                 op_type, &region_conf);
9880 #endif
9881
9882         switch (ret) {
9883         case 0:
9884                 break;
9885         case -ENOTSUP:
9886                 printf("function not implemented or supported\n");
9887                 break;
9888         default:
9889                 printf("user_priority region config error: (%s)\n",
9890                                 strerror(-ret));
9891         }
9892 }
9893
9894 cmdline_parse_token_string_t cmd_user_priority_region_set =
9895         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9896                                 set, "set");
9897 cmdline_parse_token_string_t cmd_user_priority_region_port =
9898         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9899                                 port, "port");
9900 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9901         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9902                                 port_id, UINT16);
9903 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9904         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9905                                 cmd, "queue-region");
9906 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9907         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9908                                 user_priority, "UP");
9909 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9910         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9911                                 user_priority_id, UINT8);
9912 cmdline_parse_token_string_t cmd_user_priority_region_region =
9913         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9914                                 region, "region_id");
9915 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9916         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9917                                 region_id, UINT8);
9918
9919 cmdline_parse_inst_t cmd_user_priority_region = {
9920         .f = cmd_user_priority_region_parsed,
9921         .data = NULL,
9922         .help_str = "set port <port_id> queue-region UP <value> "
9923                 "region_id <value>: Set the mapping of User Priority (UP) "
9924                 "to queue region (region_id) ",
9925         .tokens = {
9926                 (void *)&cmd_user_priority_region_set,
9927                 (void *)&cmd_user_priority_region_port,
9928                 (void *)&cmd_user_priority_region_port_index,
9929                 (void *)&cmd_user_priority_region_cmd,
9930                 (void *)&cmd_user_priority_region_UP,
9931                 (void *)&cmd_user_priority_region_UP_id,
9932                 (void *)&cmd_user_priority_region_region,
9933                 (void *)&cmd_user_priority_region_region_id,
9934                 NULL,
9935         },
9936 };
9937
9938 /* *** flush all queue region related configuration *** */
9939 struct cmd_flush_queue_region_result {
9940         cmdline_fixed_string_t set;
9941         cmdline_fixed_string_t port;
9942         portid_t port_id;
9943         cmdline_fixed_string_t cmd;
9944         cmdline_fixed_string_t flush;
9945         cmdline_fixed_string_t what;
9946 };
9947
9948 static void
9949 cmd_flush_queue_region_parsed(void *parsed_result,
9950                         __attribute__((unused)) struct cmdline *cl,
9951                         __attribute__((unused)) void *data)
9952 {
9953         struct cmd_flush_queue_region_result *res = parsed_result;
9954         int ret = -ENOTSUP;
9955 #ifdef RTE_LIBRTE_I40E_PMD
9956         struct rte_pmd_i40e_queue_region_conf region_conf;
9957         enum rte_pmd_i40e_queue_region_op op_type;
9958 #endif
9959
9960         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9961                 return;
9962
9963 #ifdef RTE_LIBRTE_I40E_PMD
9964         memset(&region_conf, 0, sizeof(region_conf));
9965
9966         if (strcmp(res->what, "on") == 0)
9967                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9968         else
9969                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9970
9971         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9972                                 op_type, &region_conf);
9973 #endif
9974
9975         switch (ret) {
9976         case 0:
9977                 break;
9978         case -ENOTSUP:
9979                 printf("function not implemented or supported\n");
9980                 break;
9981         default:
9982                 printf("queue region config flush error: (%s)\n",
9983                                 strerror(-ret));
9984         }
9985 }
9986
9987 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9988         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9989                                 set, "set");
9990 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9991         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9992                                 port, "port");
9993 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9994         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9995                                 port_id, UINT16);
9996 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9997         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9998                                 cmd, "queue-region");
9999 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10000         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10001                                 flush, "flush");
10002 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10003         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10004                                 what, "on#off");
10005
10006 cmdline_parse_inst_t cmd_flush_queue_region = {
10007         .f = cmd_flush_queue_region_parsed,
10008         .data = NULL,
10009         .help_str = "set port <port_id> queue-region flush on|off"
10010                 ": flush all queue region related configuration",
10011         .tokens = {
10012                 (void *)&cmd_flush_queue_region_set,
10013                 (void *)&cmd_flush_queue_region_port,
10014                 (void *)&cmd_flush_queue_region_port_index,
10015                 (void *)&cmd_flush_queue_region_cmd,
10016                 (void *)&cmd_flush_queue_region_flush,
10017                 (void *)&cmd_flush_queue_region_what,
10018                 NULL,
10019         },
10020 };
10021
10022 /* *** get all queue region related configuration info *** */
10023 struct cmd_show_queue_region_info {
10024         cmdline_fixed_string_t show;
10025         cmdline_fixed_string_t port;
10026         portid_t port_id;
10027         cmdline_fixed_string_t cmd;
10028 };
10029
10030 static void
10031 cmd_show_queue_region_info_parsed(void *parsed_result,
10032                         __attribute__((unused)) struct cmdline *cl,
10033                         __attribute__((unused)) void *data)
10034 {
10035         struct cmd_show_queue_region_info *res = parsed_result;
10036         int ret = -ENOTSUP;
10037 #ifdef RTE_LIBRTE_I40E_PMD
10038         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10039         enum rte_pmd_i40e_queue_region_op op_type;
10040 #endif
10041
10042         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10043                 return;
10044
10045 #ifdef RTE_LIBRTE_I40E_PMD
10046         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10047
10048         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10049
10050         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10051                                         op_type, &rte_pmd_regions);
10052
10053         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10054 #endif
10055
10056         switch (ret) {
10057         case 0:
10058                 break;
10059         case -ENOTSUP:
10060                 printf("function not implemented or supported\n");
10061                 break;
10062         default:
10063                 printf("queue region config info show error: (%s)\n",
10064                                 strerror(-ret));
10065         }
10066 }
10067
10068 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10069 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10070                                 show, "show");
10071 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10072         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10073                                 port, "port");
10074 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10075         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10076                                 port_id, UINT16);
10077 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10078         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10079                                 cmd, "queue-region");
10080
10081 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10082         .f = cmd_show_queue_region_info_parsed,
10083         .data = NULL,
10084         .help_str = "show port <port_id> queue-region"
10085                 ": show all queue region related configuration info",
10086         .tokens = {
10087                 (void *)&cmd_show_queue_region_info_get,
10088                 (void *)&cmd_show_queue_region_info_port,
10089                 (void *)&cmd_show_queue_region_info_port_index,
10090                 (void *)&cmd_show_queue_region_info_cmd,
10091                 NULL,
10092         },
10093 };
10094
10095 /* *** ADD/REMOVE A 2tuple FILTER *** */
10096 struct cmd_2tuple_filter_result {
10097         cmdline_fixed_string_t filter;
10098         portid_t port_id;
10099         cmdline_fixed_string_t ops;
10100         cmdline_fixed_string_t dst_port;
10101         uint16_t dst_port_value;
10102         cmdline_fixed_string_t protocol;
10103         uint8_t protocol_value;
10104         cmdline_fixed_string_t mask;
10105         uint8_t  mask_value;
10106         cmdline_fixed_string_t tcp_flags;
10107         uint8_t tcp_flags_value;
10108         cmdline_fixed_string_t priority;
10109         uint8_t  priority_value;
10110         cmdline_fixed_string_t queue;
10111         uint16_t  queue_id;
10112 };
10113
10114 static void
10115 cmd_2tuple_filter_parsed(void *parsed_result,
10116                         __attribute__((unused)) struct cmdline *cl,
10117                         __attribute__((unused)) void *data)
10118 {
10119         struct rte_eth_ntuple_filter filter;
10120         struct cmd_2tuple_filter_result *res = parsed_result;
10121         int ret = 0;
10122
10123         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10124         if (ret < 0) {
10125                 printf("ntuple filter is not supported on port %u.\n",
10126                         res->port_id);
10127                 return;
10128         }
10129
10130         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10131
10132         filter.flags = RTE_2TUPLE_FLAGS;
10133         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10134         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10135         filter.proto = res->protocol_value;
10136         filter.priority = res->priority_value;
10137         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10138                 printf("nonzero tcp_flags is only meaningful"
10139                         " when protocol is TCP.\n");
10140                 return;
10141         }
10142         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10143                 printf("invalid TCP flags.\n");
10144                 return;
10145         }
10146
10147         if (res->tcp_flags_value != 0) {
10148                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10149                 filter.tcp_flags = res->tcp_flags_value;
10150         }
10151
10152         /* need convert to big endian. */
10153         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10154         filter.queue = res->queue_id;
10155
10156         if (!strcmp(res->ops, "add"))
10157                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10158                                 RTE_ETH_FILTER_NTUPLE,
10159                                 RTE_ETH_FILTER_ADD,
10160                                 &filter);
10161         else
10162                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10163                                 RTE_ETH_FILTER_NTUPLE,
10164                                 RTE_ETH_FILTER_DELETE,
10165                                 &filter);
10166         if (ret < 0)
10167                 printf("2tuple filter programming error: (%s)\n",
10168                         strerror(-ret));
10169
10170 }
10171
10172 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10173         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10174                                  filter, "2tuple_filter");
10175 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10176         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10177                                 port_id, UINT16);
10178 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10179         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10180                                  ops, "add#del");
10181 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10182         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10183                                 dst_port, "dst_port");
10184 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10185         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10186                                 dst_port_value, UINT16);
10187 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10188         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10189                                 protocol, "protocol");
10190 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10191         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10192                                 protocol_value, UINT8);
10193 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10194         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10195                                 mask, "mask");
10196 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10197         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10198                                 mask_value, INT8);
10199 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10200         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10201                                 tcp_flags, "tcp_flags");
10202 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10203         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10204                                 tcp_flags_value, UINT8);
10205 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10206         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10207                                 priority, "priority");
10208 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10209         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10210                                 priority_value, UINT8);
10211 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10212         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10213                                 queue, "queue");
10214 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10215         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10216                                 queue_id, UINT16);
10217
10218 cmdline_parse_inst_t cmd_2tuple_filter = {
10219         .f = cmd_2tuple_filter_parsed,
10220         .data = NULL,
10221         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10222                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10223                 "<queue_id>: Add a 2tuple filter",
10224         .tokens = {
10225                 (void *)&cmd_2tuple_filter_filter,
10226                 (void *)&cmd_2tuple_filter_port_id,
10227                 (void *)&cmd_2tuple_filter_ops,
10228                 (void *)&cmd_2tuple_filter_dst_port,
10229                 (void *)&cmd_2tuple_filter_dst_port_value,
10230                 (void *)&cmd_2tuple_filter_protocol,
10231                 (void *)&cmd_2tuple_filter_protocol_value,
10232                 (void *)&cmd_2tuple_filter_mask,
10233                 (void *)&cmd_2tuple_filter_mask_value,
10234                 (void *)&cmd_2tuple_filter_tcp_flags,
10235                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10236                 (void *)&cmd_2tuple_filter_priority,
10237                 (void *)&cmd_2tuple_filter_priority_value,
10238                 (void *)&cmd_2tuple_filter_queue,
10239                 (void *)&cmd_2tuple_filter_queue_id,
10240                 NULL,
10241         },
10242 };
10243
10244 /* *** ADD/REMOVE A 5tuple FILTER *** */
10245 struct cmd_5tuple_filter_result {
10246         cmdline_fixed_string_t filter;
10247         portid_t port_id;
10248         cmdline_fixed_string_t ops;
10249         cmdline_fixed_string_t dst_ip;
10250         cmdline_ipaddr_t dst_ip_value;
10251         cmdline_fixed_string_t src_ip;
10252         cmdline_ipaddr_t src_ip_value;
10253         cmdline_fixed_string_t dst_port;
10254         uint16_t dst_port_value;
10255         cmdline_fixed_string_t src_port;
10256         uint16_t src_port_value;
10257         cmdline_fixed_string_t protocol;
10258         uint8_t protocol_value;
10259         cmdline_fixed_string_t mask;
10260         uint8_t  mask_value;
10261         cmdline_fixed_string_t tcp_flags;
10262         uint8_t tcp_flags_value;
10263         cmdline_fixed_string_t priority;
10264         uint8_t  priority_value;
10265         cmdline_fixed_string_t queue;
10266         uint16_t  queue_id;
10267 };
10268
10269 static void
10270 cmd_5tuple_filter_parsed(void *parsed_result,
10271                         __attribute__((unused)) struct cmdline *cl,
10272                         __attribute__((unused)) void *data)
10273 {
10274         struct rte_eth_ntuple_filter filter;
10275         struct cmd_5tuple_filter_result *res = parsed_result;
10276         int ret = 0;
10277
10278         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10279         if (ret < 0) {
10280                 printf("ntuple filter is not supported on port %u.\n",
10281                         res->port_id);
10282                 return;
10283         }
10284
10285         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10286
10287         filter.flags = RTE_5TUPLE_FLAGS;
10288         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10289         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10290         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10291         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10292         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10293         filter.proto = res->protocol_value;
10294         filter.priority = res->priority_value;
10295         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10296                 printf("nonzero tcp_flags is only meaningful"
10297                         " when protocol is TCP.\n");
10298                 return;
10299         }
10300         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10301                 printf("invalid TCP flags.\n");
10302                 return;
10303         }
10304
10305         if (res->tcp_flags_value != 0) {
10306                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10307                 filter.tcp_flags = res->tcp_flags_value;
10308         }
10309
10310         if (res->dst_ip_value.family == AF_INET)
10311                 /* no need to convert, already big endian. */
10312                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10313         else {
10314                 if (filter.dst_ip_mask == 0) {
10315                         printf("can not support ipv6 involved compare.\n");
10316                         return;
10317                 }
10318                 filter.dst_ip = 0;
10319         }
10320
10321         if (res->src_ip_value.family == AF_INET)
10322                 /* no need to convert, already big endian. */
10323                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10324         else {
10325                 if (filter.src_ip_mask == 0) {
10326                         printf("can not support ipv6 involved compare.\n");
10327                         return;
10328                 }
10329                 filter.src_ip = 0;
10330         }
10331         /* need convert to big endian. */
10332         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10333         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10334         filter.queue = res->queue_id;
10335
10336         if (!strcmp(res->ops, "add"))
10337                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10338                                 RTE_ETH_FILTER_NTUPLE,
10339                                 RTE_ETH_FILTER_ADD,
10340                                 &filter);
10341         else
10342                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10343                                 RTE_ETH_FILTER_NTUPLE,
10344                                 RTE_ETH_FILTER_DELETE,
10345                                 &filter);
10346         if (ret < 0)
10347                 printf("5tuple filter programming error: (%s)\n",
10348                         strerror(-ret));
10349 }
10350
10351 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10352         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10353                                  filter, "5tuple_filter");
10354 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10355         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10356                                 port_id, UINT16);
10357 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10358         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10359                                  ops, "add#del");
10360 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10361         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10362                                 dst_ip, "dst_ip");
10363 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10364         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10365                                 dst_ip_value);
10366 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10367         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10368                                 src_ip, "src_ip");
10369 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10370         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10371                                 src_ip_value);
10372 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10373         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10374                                 dst_port, "dst_port");
10375 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10376         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10377                                 dst_port_value, UINT16);
10378 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10379         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10380                                 src_port, "src_port");
10381 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10382         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10383                                 src_port_value, UINT16);
10384 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10385         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10386                                 protocol, "protocol");
10387 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10388         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10389                                 protocol_value, UINT8);
10390 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10391         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10392                                 mask, "mask");
10393 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10394         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10395                                 mask_value, INT8);
10396 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10397         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10398                                 tcp_flags, "tcp_flags");
10399 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10400         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10401                                 tcp_flags_value, UINT8);
10402 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10403         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10404                                 priority, "priority");
10405 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10406         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10407                                 priority_value, UINT8);
10408 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10409         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10410                                 queue, "queue");
10411 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10412         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10413                                 queue_id, UINT16);
10414
10415 cmdline_parse_inst_t cmd_5tuple_filter = {
10416         .f = cmd_5tuple_filter_parsed,
10417         .data = NULL,
10418         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10419                 "src_ip <value> dst_port <value> src_port <value> "
10420                 "protocol <value>  mask <value> tcp_flags <value> "
10421                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10422         .tokens = {
10423                 (void *)&cmd_5tuple_filter_filter,
10424                 (void *)&cmd_5tuple_filter_port_id,
10425                 (void *)&cmd_5tuple_filter_ops,
10426                 (void *)&cmd_5tuple_filter_dst_ip,
10427                 (void *)&cmd_5tuple_filter_dst_ip_value,
10428                 (void *)&cmd_5tuple_filter_src_ip,
10429                 (void *)&cmd_5tuple_filter_src_ip_value,
10430                 (void *)&cmd_5tuple_filter_dst_port,
10431                 (void *)&cmd_5tuple_filter_dst_port_value,
10432                 (void *)&cmd_5tuple_filter_src_port,
10433                 (void *)&cmd_5tuple_filter_src_port_value,
10434                 (void *)&cmd_5tuple_filter_protocol,
10435                 (void *)&cmd_5tuple_filter_protocol_value,
10436                 (void *)&cmd_5tuple_filter_mask,
10437                 (void *)&cmd_5tuple_filter_mask_value,
10438                 (void *)&cmd_5tuple_filter_tcp_flags,
10439                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10440                 (void *)&cmd_5tuple_filter_priority,
10441                 (void *)&cmd_5tuple_filter_priority_value,
10442                 (void *)&cmd_5tuple_filter_queue,
10443                 (void *)&cmd_5tuple_filter_queue_id,
10444                 NULL,
10445         },
10446 };
10447
10448 /* *** ADD/REMOVE A flex FILTER *** */
10449 struct cmd_flex_filter_result {
10450         cmdline_fixed_string_t filter;
10451         cmdline_fixed_string_t ops;
10452         portid_t port_id;
10453         cmdline_fixed_string_t len;
10454         uint8_t len_value;
10455         cmdline_fixed_string_t bytes;
10456         cmdline_fixed_string_t bytes_value;
10457         cmdline_fixed_string_t mask;
10458         cmdline_fixed_string_t mask_value;
10459         cmdline_fixed_string_t priority;
10460         uint8_t priority_value;
10461         cmdline_fixed_string_t queue;
10462         uint16_t queue_id;
10463 };
10464
10465 static int xdigit2val(unsigned char c)
10466 {
10467         int val;
10468         if (isdigit(c))
10469                 val = c - '0';
10470         else if (isupper(c))
10471                 val = c - 'A' + 10;
10472         else
10473                 val = c - 'a' + 10;
10474         return val;
10475 }
10476
10477 static void
10478 cmd_flex_filter_parsed(void *parsed_result,
10479                           __attribute__((unused)) struct cmdline *cl,
10480                           __attribute__((unused)) void *data)
10481 {
10482         int ret = 0;
10483         struct rte_eth_flex_filter filter;
10484         struct cmd_flex_filter_result *res = parsed_result;
10485         char *bytes_ptr, *mask_ptr;
10486         uint16_t len, i, j = 0;
10487         char c;
10488         int val;
10489         uint8_t byte = 0;
10490
10491         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10492                 printf("the len exceed the max length 128\n");
10493                 return;
10494         }
10495         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10496         filter.len = res->len_value;
10497         filter.priority = res->priority_value;
10498         filter.queue = res->queue_id;
10499         bytes_ptr = res->bytes_value;
10500         mask_ptr = res->mask_value;
10501
10502          /* translate bytes string to array. */
10503         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10504                 (bytes_ptr[1] == 'X')))
10505                 bytes_ptr += 2;
10506         len = strnlen(bytes_ptr, res->len_value * 2);
10507         if (len == 0 || (len % 8 != 0)) {
10508                 printf("please check len and bytes input\n");
10509                 return;
10510         }
10511         for (i = 0; i < len; i++) {
10512                 c = bytes_ptr[i];
10513                 if (isxdigit(c) == 0) {
10514                         /* invalid characters. */
10515                         printf("invalid input\n");
10516                         return;
10517                 }
10518                 val = xdigit2val(c);
10519                 if (i % 2) {
10520                         byte |= val;
10521                         filter.bytes[j] = byte;
10522                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10523                         j++;
10524                         byte = 0;
10525                 } else
10526                         byte |= val << 4;
10527         }
10528         printf("\n");
10529          /* translate mask string to uint8_t array. */
10530         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10531                 (mask_ptr[1] == 'X')))
10532                 mask_ptr += 2;
10533         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10534         if (len == 0) {
10535                 printf("invalid input\n");
10536                 return;
10537         }
10538         j = 0;
10539         byte = 0;
10540         for (i = 0; i < len; i++) {
10541                 c = mask_ptr[i];
10542                 if (isxdigit(c) == 0) {
10543                         /* invalid characters. */
10544                         printf("invalid input\n");
10545                         return;
10546                 }
10547                 val = xdigit2val(c);
10548                 if (i % 2) {
10549                         byte |= val;
10550                         filter.mask[j] = byte;
10551                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10552                         j++;
10553                         byte = 0;
10554                 } else
10555                         byte |= val << 4;
10556         }
10557         printf("\n");
10558
10559         if (!strcmp(res->ops, "add"))
10560                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10561                                 RTE_ETH_FILTER_FLEXIBLE,
10562                                 RTE_ETH_FILTER_ADD,
10563                                 &filter);
10564         else
10565                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10566                                 RTE_ETH_FILTER_FLEXIBLE,
10567                                 RTE_ETH_FILTER_DELETE,
10568                                 &filter);
10569
10570         if (ret < 0)
10571                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10572 }
10573
10574 cmdline_parse_token_string_t cmd_flex_filter_filter =
10575         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10576                                 filter, "flex_filter");
10577 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10578         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10579                                 port_id, UINT16);
10580 cmdline_parse_token_string_t cmd_flex_filter_ops =
10581         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10582                                 ops, "add#del");
10583 cmdline_parse_token_string_t cmd_flex_filter_len =
10584         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10585                                 len, "len");
10586 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10587         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10588                                 len_value, UINT8);
10589 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10590         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10591                                 bytes, "bytes");
10592 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10593         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10594                                 bytes_value, NULL);
10595 cmdline_parse_token_string_t cmd_flex_filter_mask =
10596         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10597                                 mask, "mask");
10598 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10599         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10600                                 mask_value, NULL);
10601 cmdline_parse_token_string_t cmd_flex_filter_priority =
10602         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10603                                 priority, "priority");
10604 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10605         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10606                                 priority_value, UINT8);
10607 cmdline_parse_token_string_t cmd_flex_filter_queue =
10608         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10609                                 queue, "queue");
10610 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10611         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10612                                 queue_id, UINT16);
10613 cmdline_parse_inst_t cmd_flex_filter = {
10614         .f = cmd_flex_filter_parsed,
10615         .data = NULL,
10616         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10617                 "<value> mask <value> priority <value> queue <queue_id>: "
10618                 "Add/Del a flex filter",
10619         .tokens = {
10620                 (void *)&cmd_flex_filter_filter,
10621                 (void *)&cmd_flex_filter_port_id,
10622                 (void *)&cmd_flex_filter_ops,
10623                 (void *)&cmd_flex_filter_len,
10624                 (void *)&cmd_flex_filter_len_value,
10625                 (void *)&cmd_flex_filter_bytes,
10626                 (void *)&cmd_flex_filter_bytes_value,
10627                 (void *)&cmd_flex_filter_mask,
10628                 (void *)&cmd_flex_filter_mask_value,
10629                 (void *)&cmd_flex_filter_priority,
10630                 (void *)&cmd_flex_filter_priority_value,
10631                 (void *)&cmd_flex_filter_queue,
10632                 (void *)&cmd_flex_filter_queue_id,
10633                 NULL,
10634         },
10635 };
10636
10637 /* *** Filters Control *** */
10638
10639 /* *** deal with ethertype filter *** */
10640 struct cmd_ethertype_filter_result {
10641         cmdline_fixed_string_t filter;
10642         portid_t port_id;
10643         cmdline_fixed_string_t ops;
10644         cmdline_fixed_string_t mac;
10645         struct rte_ether_addr mac_addr;
10646         cmdline_fixed_string_t ethertype;
10647         uint16_t ethertype_value;
10648         cmdline_fixed_string_t drop;
10649         cmdline_fixed_string_t queue;
10650         uint16_t  queue_id;
10651 };
10652
10653 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10654         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10655                                  filter, "ethertype_filter");
10656 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10657         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10658                               port_id, UINT16);
10659 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10660         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10661                                  ops, "add#del");
10662 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10663         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10664                                  mac, "mac_addr#mac_ignr");
10665 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10666         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10667                                      mac_addr);
10668 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10669         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10670                                  ethertype, "ethertype");
10671 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10672         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10673                               ethertype_value, UINT16);
10674 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10675         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10676                                  drop, "drop#fwd");
10677 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10678         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10679                                  queue, "queue");
10680 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10681         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10682                               queue_id, UINT16);
10683
10684 static void
10685 cmd_ethertype_filter_parsed(void *parsed_result,
10686                           __attribute__((unused)) struct cmdline *cl,
10687                           __attribute__((unused)) void *data)
10688 {
10689         struct cmd_ethertype_filter_result *res = parsed_result;
10690         struct rte_eth_ethertype_filter filter;
10691         int ret = 0;
10692
10693         ret = rte_eth_dev_filter_supported(res->port_id,
10694                         RTE_ETH_FILTER_ETHERTYPE);
10695         if (ret < 0) {
10696                 printf("ethertype filter is not supported on port %u.\n",
10697                         res->port_id);
10698                 return;
10699         }
10700
10701         memset(&filter, 0, sizeof(filter));
10702         if (!strcmp(res->mac, "mac_addr")) {
10703                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10704                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10705                         sizeof(struct rte_ether_addr));
10706         }
10707         if (!strcmp(res->drop, "drop"))
10708                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10709         filter.ether_type = res->ethertype_value;
10710         filter.queue = res->queue_id;
10711
10712         if (!strcmp(res->ops, "add"))
10713                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10714                                 RTE_ETH_FILTER_ETHERTYPE,
10715                                 RTE_ETH_FILTER_ADD,
10716                                 &filter);
10717         else
10718                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10719                                 RTE_ETH_FILTER_ETHERTYPE,
10720                                 RTE_ETH_FILTER_DELETE,
10721                                 &filter);
10722         if (ret < 0)
10723                 printf("ethertype filter programming error: (%s)\n",
10724                         strerror(-ret));
10725 }
10726
10727 cmdline_parse_inst_t cmd_ethertype_filter = {
10728         .f = cmd_ethertype_filter_parsed,
10729         .data = NULL,
10730         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10731                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10732                 "Add or delete an ethertype filter entry",
10733         .tokens = {
10734                 (void *)&cmd_ethertype_filter_filter,
10735                 (void *)&cmd_ethertype_filter_port_id,
10736                 (void *)&cmd_ethertype_filter_ops,
10737                 (void *)&cmd_ethertype_filter_mac,
10738                 (void *)&cmd_ethertype_filter_mac_addr,
10739                 (void *)&cmd_ethertype_filter_ethertype,
10740                 (void *)&cmd_ethertype_filter_ethertype_value,
10741                 (void *)&cmd_ethertype_filter_drop,
10742                 (void *)&cmd_ethertype_filter_queue,
10743                 (void *)&cmd_ethertype_filter_queue_id,
10744                 NULL,
10745         },
10746 };
10747
10748 /* *** deal with flow director filter *** */
10749 struct cmd_flow_director_result {
10750         cmdline_fixed_string_t flow_director_filter;
10751         portid_t port_id;
10752         cmdline_fixed_string_t mode;
10753         cmdline_fixed_string_t mode_value;
10754         cmdline_fixed_string_t ops;
10755         cmdline_fixed_string_t flow;
10756         cmdline_fixed_string_t flow_type;
10757         cmdline_fixed_string_t ether;
10758         uint16_t ether_type;
10759         cmdline_fixed_string_t src;
10760         cmdline_ipaddr_t ip_src;
10761         uint16_t port_src;
10762         cmdline_fixed_string_t dst;
10763         cmdline_ipaddr_t ip_dst;
10764         uint16_t port_dst;
10765         cmdline_fixed_string_t verify_tag;
10766         uint32_t verify_tag_value;
10767         cmdline_fixed_string_t tos;
10768         uint8_t tos_value;
10769         cmdline_fixed_string_t proto;
10770         uint8_t proto_value;
10771         cmdline_fixed_string_t ttl;
10772         uint8_t ttl_value;
10773         cmdline_fixed_string_t vlan;
10774         uint16_t vlan_value;
10775         cmdline_fixed_string_t flexbytes;
10776         cmdline_fixed_string_t flexbytes_value;
10777         cmdline_fixed_string_t pf_vf;
10778         cmdline_fixed_string_t drop;
10779         cmdline_fixed_string_t queue;
10780         uint16_t  queue_id;
10781         cmdline_fixed_string_t fd_id;
10782         uint32_t  fd_id_value;
10783         cmdline_fixed_string_t mac;
10784         struct rte_ether_addr mac_addr;
10785         cmdline_fixed_string_t tunnel;
10786         cmdline_fixed_string_t tunnel_type;
10787         cmdline_fixed_string_t tunnel_id;
10788         uint32_t tunnel_id_value;
10789         cmdline_fixed_string_t packet;
10790         char filepath[];
10791 };
10792
10793 static inline int
10794 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10795 {
10796         char s[256];
10797         const char *p, *p0 = q_arg;
10798         char *end;
10799         unsigned long int_fld;
10800         char *str_fld[max_num];
10801         int i;
10802         unsigned size;
10803         int ret = -1;
10804
10805         p = strchr(p0, '(');
10806         if (p == NULL)
10807                 return -1;
10808         ++p;
10809         p0 = strchr(p, ')');
10810         if (p0 == NULL)
10811                 return -1;
10812
10813         size = p0 - p;
10814         if (size >= sizeof(s))
10815                 return -1;
10816
10817         snprintf(s, sizeof(s), "%.*s", size, p);
10818         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10819         if (ret < 0 || ret > max_num)
10820                 return -1;
10821         for (i = 0; i < ret; i++) {
10822                 errno = 0;
10823                 int_fld = strtoul(str_fld[i], &end, 0);
10824                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10825                         return -1;
10826                 flexbytes[i] = (uint8_t)int_fld;
10827         }
10828         return ret;
10829 }
10830
10831 static uint16_t
10832 str2flowtype(char *string)
10833 {
10834         uint8_t i = 0;
10835         static const struct {
10836                 char str[32];
10837                 uint16_t type;
10838         } flowtype_str[] = {
10839                 {"raw", RTE_ETH_FLOW_RAW},
10840                 {"ipv4", RTE_ETH_FLOW_IPV4},
10841                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10842                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10843                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10844                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10845                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10846                 {"ipv6", RTE_ETH_FLOW_IPV6},
10847                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10848                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10849                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10850                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10851                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10852                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10853         };
10854
10855         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10856                 if (!strcmp(flowtype_str[i].str, string))
10857                         return flowtype_str[i].type;
10858         }
10859
10860         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10861                 return (uint16_t)atoi(string);
10862
10863         return RTE_ETH_FLOW_UNKNOWN;
10864 }
10865
10866 static enum rte_eth_fdir_tunnel_type
10867 str2fdir_tunneltype(char *string)
10868 {
10869         uint8_t i = 0;
10870
10871         static const struct {
10872                 char str[32];
10873                 enum rte_eth_fdir_tunnel_type type;
10874         } tunneltype_str[] = {
10875                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10876                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10877         };
10878
10879         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10880                 if (!strcmp(tunneltype_str[i].str, string))
10881                         return tunneltype_str[i].type;
10882         }
10883         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10884 }
10885
10886 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10887 do { \
10888         if ((ip_addr).family == AF_INET) \
10889                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10890         else { \
10891                 printf("invalid parameter.\n"); \
10892                 return; \
10893         } \
10894 } while (0)
10895
10896 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10897 do { \
10898         if ((ip_addr).family == AF_INET6) \
10899                 rte_memcpy(&(ip), \
10900                                  &((ip_addr).addr.ipv6), \
10901                                  sizeof(struct in6_addr)); \
10902         else { \
10903                 printf("invalid parameter.\n"); \
10904                 return; \
10905         } \
10906 } while (0)
10907
10908 static void
10909 cmd_flow_director_filter_parsed(void *parsed_result,
10910                           __attribute__((unused)) struct cmdline *cl,
10911                           __attribute__((unused)) void *data)
10912 {
10913         struct cmd_flow_director_result *res = parsed_result;
10914         struct rte_eth_fdir_filter entry;
10915         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10916         char *end;
10917         unsigned long vf_id;
10918         int ret = 0;
10919
10920         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10921         if (ret < 0) {
10922                 printf("flow director is not supported on port %u.\n",
10923                         res->port_id);
10924                 return;
10925         }
10926         memset(flexbytes, 0, sizeof(flexbytes));
10927         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10928
10929         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10930                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10931                         printf("Please set mode to MAC-VLAN.\n");
10932                         return;
10933                 }
10934         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10935                 if (strcmp(res->mode_value, "Tunnel")) {
10936                         printf("Please set mode to Tunnel.\n");
10937                         return;
10938                 }
10939         } else {
10940                 if (!strcmp(res->mode_value, "raw")) {
10941 #ifdef RTE_LIBRTE_I40E_PMD
10942                         struct rte_pmd_i40e_flow_type_mapping
10943                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10944                         struct rte_pmd_i40e_pkt_template_conf conf;
10945                         uint16_t flow_type = str2flowtype(res->flow_type);
10946                         uint16_t i, port = res->port_id;
10947                         uint8_t add;
10948
10949                         memset(&conf, 0, sizeof(conf));
10950
10951                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10952                                 printf("Invalid flow type specified.\n");
10953                                 return;
10954                         }
10955                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10956                                                                  mapping);
10957                         if (ret)
10958                                 return;
10959                         if (mapping[flow_type].pctype == 0ULL) {
10960                                 printf("Invalid flow type specified.\n");
10961                                 return;
10962                         }
10963                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10964                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10965                                         conf.input.pctype = i;
10966                                         break;
10967                                 }
10968                         }
10969
10970                         conf.input.packet = open_file(res->filepath,
10971                                                 &conf.input.length);
10972                         if (!conf.input.packet)
10973                                 return;
10974                         if (!strcmp(res->drop, "drop"))
10975                                 conf.action.behavior =
10976                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10977                         else
10978                                 conf.action.behavior =
10979                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10980                         conf.action.report_status =
10981                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10982                         conf.action.rx_queue = res->queue_id;
10983                         conf.soft_id = res->fd_id_value;
10984                         add  = strcmp(res->ops, "del") ? 1 : 0;
10985                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10986                                                                         &conf,
10987                                                                         add);
10988                         if (ret < 0)
10989                                 printf("flow director config error: (%s)\n",
10990                                        strerror(-ret));
10991                         close_file(conf.input.packet);
10992 #endif
10993                         return;
10994                 } else if (strcmp(res->mode_value, "IP")) {
10995                         printf("Please set mode to IP or raw.\n");
10996                         return;
10997                 }
10998                 entry.input.flow_type = str2flowtype(res->flow_type);
10999         }
11000
11001         ret = parse_flexbytes(res->flexbytes_value,
11002                                         flexbytes,
11003                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11004         if (ret < 0) {
11005                 printf("error: Cannot parse flexbytes input.\n");
11006                 return;
11007         }
11008
11009         switch (entry.input.flow_type) {
11010         case RTE_ETH_FLOW_FRAG_IPV4:
11011         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11012                 entry.input.flow.ip4_flow.proto = res->proto_value;
11013                 /* fall-through */
11014         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11015         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11016                 IPV4_ADDR_TO_UINT(res->ip_dst,
11017                         entry.input.flow.ip4_flow.dst_ip);
11018                 IPV4_ADDR_TO_UINT(res->ip_src,
11019                         entry.input.flow.ip4_flow.src_ip);
11020                 entry.input.flow.ip4_flow.tos = res->tos_value;
11021                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11022                 /* need convert to big endian. */
11023                 entry.input.flow.udp4_flow.dst_port =
11024                                 rte_cpu_to_be_16(res->port_dst);
11025                 entry.input.flow.udp4_flow.src_port =
11026                                 rte_cpu_to_be_16(res->port_src);
11027                 break;
11028         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11029                 IPV4_ADDR_TO_UINT(res->ip_dst,
11030                         entry.input.flow.sctp4_flow.ip.dst_ip);
11031                 IPV4_ADDR_TO_UINT(res->ip_src,
11032                         entry.input.flow.sctp4_flow.ip.src_ip);
11033                 entry.input.flow.ip4_flow.tos = res->tos_value;
11034                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11035                 /* need convert to big endian. */
11036                 entry.input.flow.sctp4_flow.dst_port =
11037                                 rte_cpu_to_be_16(res->port_dst);
11038                 entry.input.flow.sctp4_flow.src_port =
11039                                 rte_cpu_to_be_16(res->port_src);
11040                 entry.input.flow.sctp4_flow.verify_tag =
11041                                 rte_cpu_to_be_32(res->verify_tag_value);
11042                 break;
11043         case RTE_ETH_FLOW_FRAG_IPV6:
11044         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11045                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11046                 /* fall-through */
11047         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11048         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11049                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11050                         entry.input.flow.ipv6_flow.dst_ip);
11051                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11052                         entry.input.flow.ipv6_flow.src_ip);
11053                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11054                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11055                 /* need convert to big endian. */
11056                 entry.input.flow.udp6_flow.dst_port =
11057                                 rte_cpu_to_be_16(res->port_dst);
11058                 entry.input.flow.udp6_flow.src_port =
11059                                 rte_cpu_to_be_16(res->port_src);
11060                 break;
11061         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11062                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11063                         entry.input.flow.sctp6_flow.ip.dst_ip);
11064                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11065                         entry.input.flow.sctp6_flow.ip.src_ip);
11066                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11067                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11068                 /* need convert to big endian. */
11069                 entry.input.flow.sctp6_flow.dst_port =
11070                                 rte_cpu_to_be_16(res->port_dst);
11071                 entry.input.flow.sctp6_flow.src_port =
11072                                 rte_cpu_to_be_16(res->port_src);
11073                 entry.input.flow.sctp6_flow.verify_tag =
11074                                 rte_cpu_to_be_32(res->verify_tag_value);
11075                 break;
11076         case RTE_ETH_FLOW_L2_PAYLOAD:
11077                 entry.input.flow.l2_flow.ether_type =
11078                         rte_cpu_to_be_16(res->ether_type);
11079                 break;
11080         default:
11081                 break;
11082         }
11083
11084         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11085                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11086                                  &res->mac_addr,
11087                                  sizeof(struct rte_ether_addr));
11088
11089         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11090                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11091                                  &res->mac_addr,
11092                                  sizeof(struct rte_ether_addr));
11093                 entry.input.flow.tunnel_flow.tunnel_type =
11094                         str2fdir_tunneltype(res->tunnel_type);
11095                 entry.input.flow.tunnel_flow.tunnel_id =
11096                         rte_cpu_to_be_32(res->tunnel_id_value);
11097         }
11098
11099         rte_memcpy(entry.input.flow_ext.flexbytes,
11100                    flexbytes,
11101                    RTE_ETH_FDIR_MAX_FLEXLEN);
11102
11103         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11104
11105         entry.action.flex_off = 0;  /*use 0 by default */
11106         if (!strcmp(res->drop, "drop"))
11107                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11108         else
11109                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11110
11111         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11112             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11113                 if (!strcmp(res->pf_vf, "pf"))
11114                         entry.input.flow_ext.is_vf = 0;
11115                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11116                         struct rte_eth_dev_info dev_info;
11117
11118                         ret = eth_dev_info_get_print_err(res->port_id,
11119                                                 &dev_info);
11120                         if (ret != 0)
11121                                 return;
11122
11123                         errno = 0;
11124                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11125                         if (errno != 0 || *end != '\0' ||
11126                             vf_id >= dev_info.max_vfs) {
11127                                 printf("invalid parameter %s.\n", res->pf_vf);
11128                                 return;
11129                         }
11130                         entry.input.flow_ext.is_vf = 1;
11131                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11132                 } else {
11133                         printf("invalid parameter %s.\n", res->pf_vf);
11134                         return;
11135                 }
11136         }
11137
11138         /* set to report FD ID by default */
11139         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11140         entry.action.rx_queue = res->queue_id;
11141         entry.soft_id = res->fd_id_value;
11142         if (!strcmp(res->ops, "add"))
11143                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11144                                              RTE_ETH_FILTER_ADD, &entry);
11145         else if (!strcmp(res->ops, "del"))
11146                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11147                                              RTE_ETH_FILTER_DELETE, &entry);
11148         else
11149                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11150                                              RTE_ETH_FILTER_UPDATE, &entry);
11151         if (ret < 0)
11152                 printf("flow director programming error: (%s)\n",
11153                         strerror(-ret));
11154 }
11155
11156 cmdline_parse_token_string_t cmd_flow_director_filter =
11157         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11158                                  flow_director_filter, "flow_director_filter");
11159 cmdline_parse_token_num_t cmd_flow_director_port_id =
11160         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11161                               port_id, UINT16);
11162 cmdline_parse_token_string_t cmd_flow_director_ops =
11163         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11164                                  ops, "add#del#update");
11165 cmdline_parse_token_string_t cmd_flow_director_flow =
11166         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11167                                  flow, "flow");
11168 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11169         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11170                 flow_type, NULL);
11171 cmdline_parse_token_string_t cmd_flow_director_ether =
11172         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11173                                  ether, "ether");
11174 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11175         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11176                               ether_type, UINT16);
11177 cmdline_parse_token_string_t cmd_flow_director_src =
11178         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11179                                  src, "src");
11180 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11181         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11182                                  ip_src);
11183 cmdline_parse_token_num_t cmd_flow_director_port_src =
11184         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11185                               port_src, UINT16);
11186 cmdline_parse_token_string_t cmd_flow_director_dst =
11187         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11188                                  dst, "dst");
11189 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11190         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11191                                  ip_dst);
11192 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11193         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11194                               port_dst, UINT16);
11195 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11196         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11197                                   verify_tag, "verify_tag");
11198 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11199         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11200                               verify_tag_value, UINT32);
11201 cmdline_parse_token_string_t cmd_flow_director_tos =
11202         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11203                                  tos, "tos");
11204 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11205         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11206                               tos_value, UINT8);
11207 cmdline_parse_token_string_t cmd_flow_director_proto =
11208         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11209                                  proto, "proto");
11210 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11211         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11212                               proto_value, UINT8);
11213 cmdline_parse_token_string_t cmd_flow_director_ttl =
11214         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11215                                  ttl, "ttl");
11216 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11217         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11218                               ttl_value, UINT8);
11219 cmdline_parse_token_string_t cmd_flow_director_vlan =
11220         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11221                                  vlan, "vlan");
11222 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11223         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11224                               vlan_value, UINT16);
11225 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11226         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11227                                  flexbytes, "flexbytes");
11228 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11229         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11230                               flexbytes_value, NULL);
11231 cmdline_parse_token_string_t cmd_flow_director_drop =
11232         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11233                                  drop, "drop#fwd");
11234 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11235         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11236                               pf_vf, NULL);
11237 cmdline_parse_token_string_t cmd_flow_director_queue =
11238         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11239                                  queue, "queue");
11240 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11241         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11242                               queue_id, UINT16);
11243 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11244         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11245                                  fd_id, "fd_id");
11246 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11247         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11248                               fd_id_value, UINT32);
11249
11250 cmdline_parse_token_string_t cmd_flow_director_mode =
11251         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11252                                  mode, "mode");
11253 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11254         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11255                                  mode_value, "IP");
11256 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11257         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11258                                  mode_value, "MAC-VLAN");
11259 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11260         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11261                                  mode_value, "Tunnel");
11262 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11263         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11264                                  mode_value, "raw");
11265 cmdline_parse_token_string_t cmd_flow_director_mac =
11266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11267                                  mac, "mac");
11268 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11269         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11270                                     mac_addr);
11271 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11272         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11273                                  tunnel, "tunnel");
11274 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11276                                  tunnel_type, "NVGRE#VxLAN");
11277 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11278         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11279                                  tunnel_id, "tunnel-id");
11280 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11281         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11282                               tunnel_id_value, UINT32);
11283 cmdline_parse_token_string_t cmd_flow_director_packet =
11284         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11285                                  packet, "packet");
11286 cmdline_parse_token_string_t cmd_flow_director_filepath =
11287         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11288                                  filepath, NULL);
11289
11290 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11291         .f = cmd_flow_director_filter_parsed,
11292         .data = NULL,
11293         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11294                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11295                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11296                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11297                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11298                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11299                 "fd_id <fd_id_value>: "
11300                 "Add or delete an ip flow director entry on NIC",
11301         .tokens = {
11302                 (void *)&cmd_flow_director_filter,
11303                 (void *)&cmd_flow_director_port_id,
11304                 (void *)&cmd_flow_director_mode,
11305                 (void *)&cmd_flow_director_mode_ip,
11306                 (void *)&cmd_flow_director_ops,
11307                 (void *)&cmd_flow_director_flow,
11308                 (void *)&cmd_flow_director_flow_type,
11309                 (void *)&cmd_flow_director_src,
11310                 (void *)&cmd_flow_director_ip_src,
11311                 (void *)&cmd_flow_director_dst,
11312                 (void *)&cmd_flow_director_ip_dst,
11313                 (void *)&cmd_flow_director_tos,
11314                 (void *)&cmd_flow_director_tos_value,
11315                 (void *)&cmd_flow_director_proto,
11316                 (void *)&cmd_flow_director_proto_value,
11317                 (void *)&cmd_flow_director_ttl,
11318                 (void *)&cmd_flow_director_ttl_value,
11319                 (void *)&cmd_flow_director_vlan,
11320                 (void *)&cmd_flow_director_vlan_value,
11321                 (void *)&cmd_flow_director_flexbytes,
11322                 (void *)&cmd_flow_director_flexbytes_value,
11323                 (void *)&cmd_flow_director_drop,
11324                 (void *)&cmd_flow_director_pf_vf,
11325                 (void *)&cmd_flow_director_queue,
11326                 (void *)&cmd_flow_director_queue_id,
11327                 (void *)&cmd_flow_director_fd_id,
11328                 (void *)&cmd_flow_director_fd_id_value,
11329                 NULL,
11330         },
11331 };
11332
11333 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11334         .f = cmd_flow_director_filter_parsed,
11335         .data = NULL,
11336         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11337                 "director entry on NIC",
11338         .tokens = {
11339                 (void *)&cmd_flow_director_filter,
11340                 (void *)&cmd_flow_director_port_id,
11341                 (void *)&cmd_flow_director_mode,
11342                 (void *)&cmd_flow_director_mode_ip,
11343                 (void *)&cmd_flow_director_ops,
11344                 (void *)&cmd_flow_director_flow,
11345                 (void *)&cmd_flow_director_flow_type,
11346                 (void *)&cmd_flow_director_src,
11347                 (void *)&cmd_flow_director_ip_src,
11348                 (void *)&cmd_flow_director_port_src,
11349                 (void *)&cmd_flow_director_dst,
11350                 (void *)&cmd_flow_director_ip_dst,
11351                 (void *)&cmd_flow_director_port_dst,
11352                 (void *)&cmd_flow_director_tos,
11353                 (void *)&cmd_flow_director_tos_value,
11354                 (void *)&cmd_flow_director_ttl,
11355                 (void *)&cmd_flow_director_ttl_value,
11356                 (void *)&cmd_flow_director_vlan,
11357                 (void *)&cmd_flow_director_vlan_value,
11358                 (void *)&cmd_flow_director_flexbytes,
11359                 (void *)&cmd_flow_director_flexbytes_value,
11360                 (void *)&cmd_flow_director_drop,
11361                 (void *)&cmd_flow_director_pf_vf,
11362                 (void *)&cmd_flow_director_queue,
11363                 (void *)&cmd_flow_director_queue_id,
11364                 (void *)&cmd_flow_director_fd_id,
11365                 (void *)&cmd_flow_director_fd_id_value,
11366                 NULL,
11367         },
11368 };
11369
11370 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11371         .f = cmd_flow_director_filter_parsed,
11372         .data = NULL,
11373         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11374                 "director entry on NIC",
11375         .tokens = {
11376                 (void *)&cmd_flow_director_filter,
11377                 (void *)&cmd_flow_director_port_id,
11378                 (void *)&cmd_flow_director_mode,
11379                 (void *)&cmd_flow_director_mode_ip,
11380                 (void *)&cmd_flow_director_ops,
11381                 (void *)&cmd_flow_director_flow,
11382                 (void *)&cmd_flow_director_flow_type,
11383                 (void *)&cmd_flow_director_src,
11384                 (void *)&cmd_flow_director_ip_src,
11385                 (void *)&cmd_flow_director_port_src,
11386                 (void *)&cmd_flow_director_dst,
11387                 (void *)&cmd_flow_director_ip_dst,
11388                 (void *)&cmd_flow_director_port_dst,
11389                 (void *)&cmd_flow_director_verify_tag,
11390                 (void *)&cmd_flow_director_verify_tag_value,
11391                 (void *)&cmd_flow_director_tos,
11392                 (void *)&cmd_flow_director_tos_value,
11393                 (void *)&cmd_flow_director_ttl,
11394                 (void *)&cmd_flow_director_ttl_value,
11395                 (void *)&cmd_flow_director_vlan,
11396                 (void *)&cmd_flow_director_vlan_value,
11397                 (void *)&cmd_flow_director_flexbytes,
11398                 (void *)&cmd_flow_director_flexbytes_value,
11399                 (void *)&cmd_flow_director_drop,
11400                 (void *)&cmd_flow_director_pf_vf,
11401                 (void *)&cmd_flow_director_queue,
11402                 (void *)&cmd_flow_director_queue_id,
11403                 (void *)&cmd_flow_director_fd_id,
11404                 (void *)&cmd_flow_director_fd_id_value,
11405                 NULL,
11406         },
11407 };
11408
11409 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11410         .f = cmd_flow_director_filter_parsed,
11411         .data = NULL,
11412         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11413                 "director entry on NIC",
11414         .tokens = {
11415                 (void *)&cmd_flow_director_filter,
11416                 (void *)&cmd_flow_director_port_id,
11417                 (void *)&cmd_flow_director_mode,
11418                 (void *)&cmd_flow_director_mode_ip,
11419                 (void *)&cmd_flow_director_ops,
11420                 (void *)&cmd_flow_director_flow,
11421                 (void *)&cmd_flow_director_flow_type,
11422                 (void *)&cmd_flow_director_ether,
11423                 (void *)&cmd_flow_director_ether_type,
11424                 (void *)&cmd_flow_director_flexbytes,
11425                 (void *)&cmd_flow_director_flexbytes_value,
11426                 (void *)&cmd_flow_director_drop,
11427                 (void *)&cmd_flow_director_pf_vf,
11428                 (void *)&cmd_flow_director_queue,
11429                 (void *)&cmd_flow_director_queue_id,
11430                 (void *)&cmd_flow_director_fd_id,
11431                 (void *)&cmd_flow_director_fd_id_value,
11432                 NULL,
11433         },
11434 };
11435
11436 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11437         .f = cmd_flow_director_filter_parsed,
11438         .data = NULL,
11439         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11440                 "director entry on NIC",
11441         .tokens = {
11442                 (void *)&cmd_flow_director_filter,
11443                 (void *)&cmd_flow_director_port_id,
11444                 (void *)&cmd_flow_director_mode,
11445                 (void *)&cmd_flow_director_mode_mac_vlan,
11446                 (void *)&cmd_flow_director_ops,
11447                 (void *)&cmd_flow_director_mac,
11448                 (void *)&cmd_flow_director_mac_addr,
11449                 (void *)&cmd_flow_director_vlan,
11450                 (void *)&cmd_flow_director_vlan_value,
11451                 (void *)&cmd_flow_director_flexbytes,
11452                 (void *)&cmd_flow_director_flexbytes_value,
11453                 (void *)&cmd_flow_director_drop,
11454                 (void *)&cmd_flow_director_queue,
11455                 (void *)&cmd_flow_director_queue_id,
11456                 (void *)&cmd_flow_director_fd_id,
11457                 (void *)&cmd_flow_director_fd_id_value,
11458                 NULL,
11459         },
11460 };
11461
11462 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11463         .f = cmd_flow_director_filter_parsed,
11464         .data = NULL,
11465         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11466                 "director entry on NIC",
11467         .tokens = {
11468                 (void *)&cmd_flow_director_filter,
11469                 (void *)&cmd_flow_director_port_id,
11470                 (void *)&cmd_flow_director_mode,
11471                 (void *)&cmd_flow_director_mode_tunnel,
11472                 (void *)&cmd_flow_director_ops,
11473                 (void *)&cmd_flow_director_mac,
11474                 (void *)&cmd_flow_director_mac_addr,
11475                 (void *)&cmd_flow_director_vlan,
11476                 (void *)&cmd_flow_director_vlan_value,
11477                 (void *)&cmd_flow_director_tunnel,
11478                 (void *)&cmd_flow_director_tunnel_type,
11479                 (void *)&cmd_flow_director_tunnel_id,
11480                 (void *)&cmd_flow_director_tunnel_id_value,
11481                 (void *)&cmd_flow_director_flexbytes,
11482                 (void *)&cmd_flow_director_flexbytes_value,
11483                 (void *)&cmd_flow_director_drop,
11484                 (void *)&cmd_flow_director_queue,
11485                 (void *)&cmd_flow_director_queue_id,
11486                 (void *)&cmd_flow_director_fd_id,
11487                 (void *)&cmd_flow_director_fd_id_value,
11488                 NULL,
11489         },
11490 };
11491
11492 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11493         .f = cmd_flow_director_filter_parsed,
11494         .data = NULL,
11495         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11496                 "director entry on NIC",
11497         .tokens = {
11498                 (void *)&cmd_flow_director_filter,
11499                 (void *)&cmd_flow_director_port_id,
11500                 (void *)&cmd_flow_director_mode,
11501                 (void *)&cmd_flow_director_mode_raw,
11502                 (void *)&cmd_flow_director_ops,
11503                 (void *)&cmd_flow_director_flow,
11504                 (void *)&cmd_flow_director_flow_type,
11505                 (void *)&cmd_flow_director_drop,
11506                 (void *)&cmd_flow_director_queue,
11507                 (void *)&cmd_flow_director_queue_id,
11508                 (void *)&cmd_flow_director_fd_id,
11509                 (void *)&cmd_flow_director_fd_id_value,
11510                 (void *)&cmd_flow_director_packet,
11511                 (void *)&cmd_flow_director_filepath,
11512                 NULL,
11513         },
11514 };
11515
11516 struct cmd_flush_flow_director_result {
11517         cmdline_fixed_string_t flush_flow_director;
11518         portid_t port_id;
11519 };
11520
11521 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11522         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11523                                  flush_flow_director, "flush_flow_director");
11524 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11525         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11526                               port_id, UINT16);
11527
11528 static void
11529 cmd_flush_flow_director_parsed(void *parsed_result,
11530                           __attribute__((unused)) struct cmdline *cl,
11531                           __attribute__((unused)) void *data)
11532 {
11533         struct cmd_flow_director_result *res = parsed_result;
11534         int ret = 0;
11535
11536         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11537         if (ret < 0) {
11538                 printf("flow director is not supported on port %u.\n",
11539                         res->port_id);
11540                 return;
11541         }
11542
11543         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11544                         RTE_ETH_FILTER_FLUSH, NULL);
11545         if (ret < 0)
11546                 printf("flow director table flushing error: (%s)\n",
11547                         strerror(-ret));
11548 }
11549
11550 cmdline_parse_inst_t cmd_flush_flow_director = {
11551         .f = cmd_flush_flow_director_parsed,
11552         .data = NULL,
11553         .help_str = "flush_flow_director <port_id>: "
11554                 "Flush all flow director entries of a device on NIC",
11555         .tokens = {
11556                 (void *)&cmd_flush_flow_director_flush,
11557                 (void *)&cmd_flush_flow_director_port_id,
11558                 NULL,
11559         },
11560 };
11561
11562 /* *** deal with flow director mask *** */
11563 struct cmd_flow_director_mask_result {
11564         cmdline_fixed_string_t flow_director_mask;
11565         portid_t port_id;
11566         cmdline_fixed_string_t mode;
11567         cmdline_fixed_string_t mode_value;
11568         cmdline_fixed_string_t vlan;
11569         uint16_t vlan_mask;
11570         cmdline_fixed_string_t src_mask;
11571         cmdline_ipaddr_t ipv4_src;
11572         cmdline_ipaddr_t ipv6_src;
11573         uint16_t port_src;
11574         cmdline_fixed_string_t dst_mask;
11575         cmdline_ipaddr_t ipv4_dst;
11576         cmdline_ipaddr_t ipv6_dst;
11577         uint16_t port_dst;
11578         cmdline_fixed_string_t mac;
11579         uint8_t mac_addr_byte_mask;
11580         cmdline_fixed_string_t tunnel_id;
11581         uint32_t tunnel_id_mask;
11582         cmdline_fixed_string_t tunnel_type;
11583         uint8_t tunnel_type_mask;
11584 };
11585
11586 static void
11587 cmd_flow_director_mask_parsed(void *parsed_result,
11588                           __attribute__((unused)) struct cmdline *cl,
11589                           __attribute__((unused)) void *data)
11590 {
11591         struct cmd_flow_director_mask_result *res = parsed_result;
11592         struct rte_eth_fdir_masks *mask;
11593         struct rte_port *port;
11594
11595         port = &ports[res->port_id];
11596         /** Check if the port is not started **/
11597         if (port->port_status != RTE_PORT_STOPPED) {
11598                 printf("Please stop port %d first\n", res->port_id);
11599                 return;
11600         }
11601
11602         mask = &port->dev_conf.fdir_conf.mask;
11603
11604         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11605                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11606                         printf("Please set mode to MAC-VLAN.\n");
11607                         return;
11608                 }
11609
11610                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11611         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11612                 if (strcmp(res->mode_value, "Tunnel")) {
11613                         printf("Please set mode to Tunnel.\n");
11614                         return;
11615                 }
11616
11617                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11618                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11619                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11620                 mask->tunnel_type_mask = res->tunnel_type_mask;
11621         } else {
11622                 if (strcmp(res->mode_value, "IP")) {
11623                         printf("Please set mode to IP.\n");
11624                         return;
11625                 }
11626
11627                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11628                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11629                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11630                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11631                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11632                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11633                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11634         }
11635
11636         cmd_reconfig_device_queue(res->port_id, 1, 1);
11637 }
11638
11639 cmdline_parse_token_string_t cmd_flow_director_mask =
11640         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11641                                  flow_director_mask, "flow_director_mask");
11642 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11643         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11644                               port_id, UINT16);
11645 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11646         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11647                                  vlan, "vlan");
11648 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11649         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11650                               vlan_mask, UINT16);
11651 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11652         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11653                                  src_mask, "src_mask");
11654 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11655         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11656                                  ipv4_src);
11657 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11658         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11659                                  ipv6_src);
11660 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11661         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11662                               port_src, UINT16);
11663 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11664         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11665                                  dst_mask, "dst_mask");
11666 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11667         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11668                                  ipv4_dst);
11669 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11670         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11671                                  ipv6_dst);
11672 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11673         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11674                               port_dst, UINT16);
11675
11676 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11677         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11678                                  mode, "mode");
11679 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11680         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11681                                  mode_value, "IP");
11682 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11683         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11684                                  mode_value, "MAC-VLAN");
11685 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11686         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11687                                  mode_value, "Tunnel");
11688 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11689         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11690                                  mac, "mac");
11691 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11692         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11693                               mac_addr_byte_mask, UINT8);
11694 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11695         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11696                                  tunnel_type, "tunnel-type");
11697 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11698         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11699                               tunnel_type_mask, UINT8);
11700 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11701         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11702                                  tunnel_id, "tunnel-id");
11703 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11704         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11705                               tunnel_id_mask, UINT32);
11706
11707 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11708         .f = cmd_flow_director_mask_parsed,
11709         .data = NULL,
11710         .help_str = "flow_director_mask ... : "
11711                 "Set IP mode flow director's mask on NIC",
11712         .tokens = {
11713                 (void *)&cmd_flow_director_mask,
11714                 (void *)&cmd_flow_director_mask_port_id,
11715                 (void *)&cmd_flow_director_mask_mode,
11716                 (void *)&cmd_flow_director_mask_mode_ip,
11717                 (void *)&cmd_flow_director_mask_vlan,
11718                 (void *)&cmd_flow_director_mask_vlan_value,
11719                 (void *)&cmd_flow_director_mask_src,
11720                 (void *)&cmd_flow_director_mask_ipv4_src,
11721                 (void *)&cmd_flow_director_mask_ipv6_src,
11722                 (void *)&cmd_flow_director_mask_port_src,
11723                 (void *)&cmd_flow_director_mask_dst,
11724                 (void *)&cmd_flow_director_mask_ipv4_dst,
11725                 (void *)&cmd_flow_director_mask_ipv6_dst,
11726                 (void *)&cmd_flow_director_mask_port_dst,
11727                 NULL,
11728         },
11729 };
11730
11731 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11732         .f = cmd_flow_director_mask_parsed,
11733         .data = NULL,
11734         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11735                 "flow director's mask on NIC",
11736         .tokens = {
11737                 (void *)&cmd_flow_director_mask,
11738                 (void *)&cmd_flow_director_mask_port_id,
11739                 (void *)&cmd_flow_director_mask_mode,
11740                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11741                 (void *)&cmd_flow_director_mask_vlan,
11742                 (void *)&cmd_flow_director_mask_vlan_value,
11743                 NULL,
11744         },
11745 };
11746
11747 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11748         .f = cmd_flow_director_mask_parsed,
11749         .data = NULL,
11750         .help_str = "flow_director_mask ... : Set tunnel mode "
11751                 "flow director's mask on NIC",
11752         .tokens = {
11753                 (void *)&cmd_flow_director_mask,
11754                 (void *)&cmd_flow_director_mask_port_id,
11755                 (void *)&cmd_flow_director_mask_mode,
11756                 (void *)&cmd_flow_director_mask_mode_tunnel,
11757                 (void *)&cmd_flow_director_mask_vlan,
11758                 (void *)&cmd_flow_director_mask_vlan_value,
11759                 (void *)&cmd_flow_director_mask_mac,
11760                 (void *)&cmd_flow_director_mask_mac_value,
11761                 (void *)&cmd_flow_director_mask_tunnel_type,
11762                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11763                 (void *)&cmd_flow_director_mask_tunnel_id,
11764                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11765                 NULL,
11766         },
11767 };
11768
11769 /* *** deal with flow director mask on flexible payload *** */
11770 struct cmd_flow_director_flex_mask_result {
11771         cmdline_fixed_string_t flow_director_flexmask;
11772         portid_t port_id;
11773         cmdline_fixed_string_t flow;
11774         cmdline_fixed_string_t flow_type;
11775         cmdline_fixed_string_t mask;
11776 };
11777
11778 static void
11779 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11780                           __attribute__((unused)) struct cmdline *cl,
11781                           __attribute__((unused)) void *data)
11782 {
11783         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11784         struct rte_eth_fdir_info fdir_info;
11785         struct rte_eth_fdir_flex_mask flex_mask;
11786         struct rte_port *port;
11787         uint64_t flow_type_mask;
11788         uint16_t i;
11789         int ret;
11790
11791         port = &ports[res->port_id];
11792         /** Check if the port is not started **/
11793         if (port->port_status != RTE_PORT_STOPPED) {
11794                 printf("Please stop port %d first\n", res->port_id);
11795                 return;
11796         }
11797
11798         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11799         ret = parse_flexbytes(res->mask,
11800                         flex_mask.mask,
11801                         RTE_ETH_FDIR_MAX_FLEXLEN);
11802         if (ret < 0) {
11803                 printf("error: Cannot parse mask input.\n");
11804                 return;
11805         }
11806
11807         memset(&fdir_info, 0, sizeof(fdir_info));
11808         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11809                                 RTE_ETH_FILTER_INFO, &fdir_info);
11810         if (ret < 0) {
11811                 printf("Cannot get FDir filter info\n");
11812                 return;
11813         }
11814
11815         if (!strcmp(res->flow_type, "none")) {
11816                 /* means don't specify the flow type */
11817                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11818                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11819                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11820                                0, sizeof(struct rte_eth_fdir_flex_mask));
11821                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11822                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11823                                  &flex_mask,
11824                                  sizeof(struct rte_eth_fdir_flex_mask));
11825                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11826                 return;
11827         }
11828         flow_type_mask = fdir_info.flow_types_mask[0];
11829         if (!strcmp(res->flow_type, "all")) {
11830                 if (!flow_type_mask) {
11831                         printf("No flow type supported\n");
11832                         return;
11833                 }
11834                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11835                         if (flow_type_mask & (1ULL << i)) {
11836                                 flex_mask.flow_type = i;
11837                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11838                         }
11839                 }
11840                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11841                 return;
11842         }
11843         flex_mask.flow_type = str2flowtype(res->flow_type);
11844         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11845                 printf("Flow type %s not supported on port %d\n",
11846                                 res->flow_type, res->port_id);
11847                 return;
11848         }
11849         fdir_set_flex_mask(res->port_id, &flex_mask);
11850         cmd_reconfig_device_queue(res->port_id, 1, 1);
11851 }
11852
11853 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11854         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11855                                  flow_director_flexmask,
11856                                  "flow_director_flex_mask");
11857 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11858         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11859                               port_id, UINT16);
11860 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11861         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11862                                  flow, "flow");
11863 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11864         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11865                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11866                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11867 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11868         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11869                                  mask, NULL);
11870
11871 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11872         .f = cmd_flow_director_flex_mask_parsed,
11873         .data = NULL,
11874         .help_str = "flow_director_flex_mask ... : "
11875                 "Set flow director's flex mask on NIC",
11876         .tokens = {
11877                 (void *)&cmd_flow_director_flexmask,
11878                 (void *)&cmd_flow_director_flexmask_port_id,
11879                 (void *)&cmd_flow_director_flexmask_flow,
11880                 (void *)&cmd_flow_director_flexmask_flow_type,
11881                 (void *)&cmd_flow_director_flexmask_mask,
11882                 NULL,
11883         },
11884 };
11885
11886 /* *** deal with flow director flexible payload configuration *** */
11887 struct cmd_flow_director_flexpayload_result {
11888         cmdline_fixed_string_t flow_director_flexpayload;
11889         portid_t port_id;
11890         cmdline_fixed_string_t payload_layer;
11891         cmdline_fixed_string_t payload_cfg;
11892 };
11893
11894 static inline int
11895 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11896 {
11897         char s[256];
11898         const char *p, *p0 = q_arg;
11899         char *end;
11900         unsigned long int_fld;
11901         char *str_fld[max_num];
11902         int i;
11903         unsigned size;
11904         int ret = -1;
11905
11906         p = strchr(p0, '(');
11907         if (p == NULL)
11908                 return -1;
11909         ++p;
11910         p0 = strchr(p, ')');
11911         if (p0 == NULL)
11912                 return -1;
11913
11914         size = p0 - p;
11915         if (size >= sizeof(s))
11916                 return -1;
11917
11918         snprintf(s, sizeof(s), "%.*s", size, p);
11919         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11920         if (ret < 0 || ret > max_num)
11921                 return -1;
11922         for (i = 0; i < ret; i++) {
11923                 errno = 0;
11924                 int_fld = strtoul(str_fld[i], &end, 0);
11925                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11926                         return -1;
11927                 offsets[i] = (uint16_t)int_fld;
11928         }
11929         return ret;
11930 }
11931
11932 static void
11933 cmd_flow_director_flxpld_parsed(void *parsed_result,
11934                           __attribute__((unused)) struct cmdline *cl,
11935                           __attribute__((unused)) void *data)
11936 {
11937         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11938         struct rte_eth_flex_payload_cfg flex_cfg;
11939         struct rte_port *port;
11940         int ret = 0;
11941
11942         port = &ports[res->port_id];
11943         /** Check if the port is not started **/
11944         if (port->port_status != RTE_PORT_STOPPED) {
11945                 printf("Please stop port %d first\n", res->port_id);
11946                 return;
11947         }
11948
11949         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11950
11951         if (!strcmp(res->payload_layer, "raw"))
11952                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11953         else if (!strcmp(res->payload_layer, "l2"))
11954                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11955         else if (!strcmp(res->payload_layer, "l3"))
11956                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11957         else if (!strcmp(res->payload_layer, "l4"))
11958                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11959
11960         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11961                             RTE_ETH_FDIR_MAX_FLEXLEN);
11962         if (ret < 0) {
11963                 printf("error: Cannot parse flex payload input.\n");
11964                 return;
11965         }
11966
11967         fdir_set_flex_payload(res->port_id, &flex_cfg);
11968         cmd_reconfig_device_queue(res->port_id, 1, 1);
11969 }
11970
11971 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11972         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11973                                  flow_director_flexpayload,
11974                                  "flow_director_flex_payload");
11975 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11976         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11977                               port_id, UINT16);
11978 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11979         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11980                                  payload_layer, "raw#l2#l3#l4");
11981 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11982         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11983                                  payload_cfg, NULL);
11984
11985 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11986         .f = cmd_flow_director_flxpld_parsed,
11987         .data = NULL,
11988         .help_str = "flow_director_flexpayload ... : "
11989                 "Set flow director's flex payload on NIC",
11990         .tokens = {
11991                 (void *)&cmd_flow_director_flexpayload,
11992                 (void *)&cmd_flow_director_flexpayload_port_id,
11993                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11994                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11995                 NULL,
11996         },
11997 };
11998
11999 /* Generic flow interface command. */
12000 extern cmdline_parse_inst_t cmd_flow;
12001
12002 /* *** Classification Filters Control *** */
12003 /* *** Get symmetric hash enable per port *** */
12004 struct cmd_get_sym_hash_ena_per_port_result {
12005         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12006         portid_t port_id;
12007 };
12008
12009 static void
12010 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12011                                  __rte_unused struct cmdline *cl,
12012                                  __rte_unused void *data)
12013 {
12014         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12015         struct rte_eth_hash_filter_info info;
12016         int ret;
12017
12018         if (rte_eth_dev_filter_supported(res->port_id,
12019                                 RTE_ETH_FILTER_HASH) < 0) {
12020                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12021                                                         res->port_id);
12022                 return;
12023         }
12024
12025         memset(&info, 0, sizeof(info));
12026         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12027         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12028                                                 RTE_ETH_FILTER_GET, &info);
12029
12030         if (ret < 0) {
12031                 printf("Cannot get symmetric hash enable per port "
12032                                         "on port %u\n", res->port_id);
12033                 return;
12034         }
12035
12036         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12037                                 "enabled" : "disabled", res->port_id);
12038 }
12039
12040 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12041         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12042                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12043 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12044         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12045                 port_id, UINT16);
12046
12047 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12048         .f = cmd_get_sym_hash_per_port_parsed,
12049         .data = NULL,
12050         .help_str = "get_sym_hash_ena_per_port <port_id>",
12051         .tokens = {
12052                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12053                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12054                 NULL,
12055         },
12056 };
12057
12058 /* *** Set symmetric hash enable per port *** */
12059 struct cmd_set_sym_hash_ena_per_port_result {
12060         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12061         cmdline_fixed_string_t enable;
12062         portid_t port_id;
12063 };
12064
12065 static void
12066 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12067                                  __rte_unused struct cmdline *cl,
12068                                  __rte_unused void *data)
12069 {
12070         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12071         struct rte_eth_hash_filter_info info;
12072         int ret;
12073
12074         if (rte_eth_dev_filter_supported(res->port_id,
12075                                 RTE_ETH_FILTER_HASH) < 0) {
12076                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12077                                                         res->port_id);
12078                 return;
12079         }
12080
12081         memset(&info, 0, sizeof(info));
12082         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12083         if (!strcmp(res->enable, "enable"))
12084                 info.info.enable = 1;
12085         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12086                                         RTE_ETH_FILTER_SET, &info);
12087         if (ret < 0) {
12088                 printf("Cannot set symmetric hash enable per port on "
12089                                         "port %u\n", res->port_id);
12090                 return;
12091         }
12092         printf("Symmetric hash has been set to %s on port %u\n",
12093                                         res->enable, res->port_id);
12094 }
12095
12096 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12097         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12098                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12099 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12100         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12101                 port_id, UINT16);
12102 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12103         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12104                 enable, "enable#disable");
12105
12106 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12107         .f = cmd_set_sym_hash_per_port_parsed,
12108         .data = NULL,
12109         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12110         .tokens = {
12111                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12112                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12113                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12114                 NULL,
12115         },
12116 };
12117
12118 /* Get global config of hash function */
12119 struct cmd_get_hash_global_config_result {
12120         cmdline_fixed_string_t get_hash_global_config;
12121         portid_t port_id;
12122 };
12123
12124 static char *
12125 flowtype_to_str(uint16_t ftype)
12126 {
12127         uint16_t i;
12128         static struct {
12129                 char str[16];
12130                 uint16_t ftype;
12131         } ftype_table[] = {
12132                 {"ipv4", RTE_ETH_FLOW_IPV4},
12133                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12134                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12135                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12136                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12137                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12138                 {"ipv6", RTE_ETH_FLOW_IPV6},
12139                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12140                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12141                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12142                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12143                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12144                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12145                 {"port", RTE_ETH_FLOW_PORT},
12146                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12147                 {"geneve", RTE_ETH_FLOW_GENEVE},
12148                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12149                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12150         };
12151
12152         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12153                 if (ftype_table[i].ftype == ftype)
12154                         return ftype_table[i].str;
12155         }
12156
12157         return NULL;
12158 }
12159
12160 static void
12161 cmd_get_hash_global_config_parsed(void *parsed_result,
12162                                   __rte_unused struct cmdline *cl,
12163                                   __rte_unused void *data)
12164 {
12165         struct cmd_get_hash_global_config_result *res = parsed_result;
12166         struct rte_eth_hash_filter_info info;
12167         uint32_t idx, offset;
12168         uint16_t i;
12169         char *str;
12170         int ret;
12171
12172         if (rte_eth_dev_filter_supported(res->port_id,
12173                         RTE_ETH_FILTER_HASH) < 0) {
12174                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12175                                                         res->port_id);
12176                 return;
12177         }
12178
12179         memset(&info, 0, sizeof(info));
12180         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12181         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12182                                         RTE_ETH_FILTER_GET, &info);
12183         if (ret < 0) {
12184                 printf("Cannot get hash global configurations by port %d\n",
12185                                                         res->port_id);
12186                 return;
12187         }
12188
12189         switch (info.info.global_conf.hash_func) {
12190         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12191                 printf("Hash function is Toeplitz\n");
12192                 break;
12193         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12194                 printf("Hash function is Simple XOR\n");
12195                 break;
12196         default:
12197                 printf("Unknown hash function\n");
12198                 break;
12199         }
12200
12201         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12202                 idx = i / UINT64_BIT;
12203                 offset = i % UINT64_BIT;
12204                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12205                                                 (1ULL << offset)))
12206                         continue;
12207                 str = flowtype_to_str(i);
12208                 if (!str)
12209                         continue;
12210                 printf("Symmetric hash is %s globally for flow type %s "
12211                                                         "by port %d\n",
12212                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12213                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12214                                                         res->port_id);
12215         }
12216 }
12217
12218 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12219         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12220                 get_hash_global_config, "get_hash_global_config");
12221 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12222         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12223                 port_id, UINT16);
12224
12225 cmdline_parse_inst_t cmd_get_hash_global_config = {
12226         .f = cmd_get_hash_global_config_parsed,
12227         .data = NULL,
12228         .help_str = "get_hash_global_config <port_id>",
12229         .tokens = {
12230                 (void *)&cmd_get_hash_global_config_all,
12231                 (void *)&cmd_get_hash_global_config_port_id,
12232                 NULL,
12233         },
12234 };
12235
12236 /* Set global config of hash function */
12237 struct cmd_set_hash_global_config_result {
12238         cmdline_fixed_string_t set_hash_global_config;
12239         portid_t port_id;
12240         cmdline_fixed_string_t hash_func;
12241         cmdline_fixed_string_t flow_type;
12242         cmdline_fixed_string_t enable;
12243 };
12244
12245 static void
12246 cmd_set_hash_global_config_parsed(void *parsed_result,
12247                                   __rte_unused struct cmdline *cl,
12248                                   __rte_unused void *data)
12249 {
12250         struct cmd_set_hash_global_config_result *res = parsed_result;
12251         struct rte_eth_hash_filter_info info;
12252         uint32_t ftype, idx, offset;
12253         int ret;
12254
12255         if (rte_eth_dev_filter_supported(res->port_id,
12256                                 RTE_ETH_FILTER_HASH) < 0) {
12257                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12258                                                         res->port_id);
12259                 return;
12260         }
12261         memset(&info, 0, sizeof(info));
12262         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12263         if (!strcmp(res->hash_func, "toeplitz"))
12264                 info.info.global_conf.hash_func =
12265                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12266         else if (!strcmp(res->hash_func, "simple_xor"))
12267                 info.info.global_conf.hash_func =
12268                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12269         else if (!strcmp(res->hash_func, "default"))
12270                 info.info.global_conf.hash_func =
12271                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12272
12273         ftype = str2flowtype(res->flow_type);
12274         idx = ftype / UINT64_BIT;
12275         offset = ftype % UINT64_BIT;
12276         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12277         if (!strcmp(res->enable, "enable"))
12278                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12279                                                 (1ULL << offset);
12280         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12281                                         RTE_ETH_FILTER_SET, &info);
12282         if (ret < 0)
12283                 printf("Cannot set global hash configurations by port %d\n",
12284                                                         res->port_id);
12285         else
12286                 printf("Global hash configurations have been set "
12287                         "successfully by port %d\n", res->port_id);
12288 }
12289
12290 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12291         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12292                 set_hash_global_config, "set_hash_global_config");
12293 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12294         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12295                 port_id, UINT16);
12296 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12297         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12298                 hash_func, "toeplitz#simple_xor#default");
12299 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12300         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12301                 flow_type,
12302                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12303                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12304 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12305         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12306                 enable, "enable#disable");
12307
12308 cmdline_parse_inst_t cmd_set_hash_global_config = {
12309         .f = cmd_set_hash_global_config_parsed,
12310         .data = NULL,
12311         .help_str = "set_hash_global_config <port_id> "
12312                 "toeplitz|simple_xor|default "
12313                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12314                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12315                 "l2_payload enable|disable",
12316         .tokens = {
12317                 (void *)&cmd_set_hash_global_config_all,
12318                 (void *)&cmd_set_hash_global_config_port_id,
12319                 (void *)&cmd_set_hash_global_config_hash_func,
12320                 (void *)&cmd_set_hash_global_config_flow_type,
12321                 (void *)&cmd_set_hash_global_config_enable,
12322                 NULL,
12323         },
12324 };
12325
12326 /* Set hash input set */
12327 struct cmd_set_hash_input_set_result {
12328         cmdline_fixed_string_t set_hash_input_set;
12329         portid_t port_id;
12330         cmdline_fixed_string_t flow_type;
12331         cmdline_fixed_string_t inset_field;
12332         cmdline_fixed_string_t select;
12333 };
12334
12335 static enum rte_eth_input_set_field
12336 str2inset(char *string)
12337 {
12338         uint16_t i;
12339
12340         static const struct {
12341                 char str[32];
12342                 enum rte_eth_input_set_field inset;
12343         } inset_table[] = {
12344                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12345                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12346                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12347                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12348                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12349                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12350                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12351                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12352                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12353                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12354                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12355                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12356                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12357                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12358                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12359                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12360                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12361                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12362                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12363                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12364                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12365                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12366                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12367                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12368                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12369                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12370                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12371                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12372                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12373                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12374                 {"none", RTE_ETH_INPUT_SET_NONE},
12375         };
12376
12377         for (i = 0; i < RTE_DIM(inset_table); i++) {
12378                 if (!strcmp(string, inset_table[i].str))
12379                         return inset_table[i].inset;
12380         }
12381
12382         return RTE_ETH_INPUT_SET_UNKNOWN;
12383 }
12384
12385 static void
12386 cmd_set_hash_input_set_parsed(void *parsed_result,
12387                               __rte_unused struct cmdline *cl,
12388                               __rte_unused void *data)
12389 {
12390         struct cmd_set_hash_input_set_result *res = parsed_result;
12391         struct rte_eth_hash_filter_info info;
12392
12393         memset(&info, 0, sizeof(info));
12394         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12395         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12396         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12397         info.info.input_set_conf.inset_size = 1;
12398         if (!strcmp(res->select, "select"))
12399                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12400         else if (!strcmp(res->select, "add"))
12401                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12402         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12403                                 RTE_ETH_FILTER_SET, &info);
12404 }
12405
12406 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12407         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12408                 set_hash_input_set, "set_hash_input_set");
12409 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12410         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12411                 port_id, UINT16);
12412 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12413         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12414                 flow_type, NULL);
12415 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12416         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12417                 inset_field,
12418                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12419                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12420                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12421                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12422                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12423                 "fld-8th#none");
12424 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12425         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12426                 select, "select#add");
12427
12428 cmdline_parse_inst_t cmd_set_hash_input_set = {
12429         .f = cmd_set_hash_input_set_parsed,
12430         .data = NULL,
12431         .help_str = "set_hash_input_set <port_id> "
12432         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12433         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12434         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12435         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12436         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12437         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12438         "fld-7th|fld-8th|none select|add",
12439         .tokens = {
12440                 (void *)&cmd_set_hash_input_set_cmd,
12441                 (void *)&cmd_set_hash_input_set_port_id,
12442                 (void *)&cmd_set_hash_input_set_flow_type,
12443                 (void *)&cmd_set_hash_input_set_field,
12444                 (void *)&cmd_set_hash_input_set_select,
12445                 NULL,
12446         },
12447 };
12448
12449 /* Set flow director input set */
12450 struct cmd_set_fdir_input_set_result {
12451         cmdline_fixed_string_t set_fdir_input_set;
12452         portid_t port_id;
12453         cmdline_fixed_string_t flow_type;
12454         cmdline_fixed_string_t inset_field;
12455         cmdline_fixed_string_t select;
12456 };
12457
12458 static void
12459 cmd_set_fdir_input_set_parsed(void *parsed_result,
12460         __rte_unused struct cmdline *cl,
12461         __rte_unused void *data)
12462 {
12463         struct cmd_set_fdir_input_set_result *res = parsed_result;
12464         struct rte_eth_fdir_filter_info info;
12465
12466         memset(&info, 0, sizeof(info));
12467         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12468         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12469         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12470         info.info.input_set_conf.inset_size = 1;
12471         if (!strcmp(res->select, "select"))
12472                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12473         else if (!strcmp(res->select, "add"))
12474                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12475         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12476                 RTE_ETH_FILTER_SET, &info);
12477 }
12478
12479 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12480         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12481         set_fdir_input_set, "set_fdir_input_set");
12482 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12483         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12484         port_id, UINT16);
12485 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12486         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12487         flow_type,
12488         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12489         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12490 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12491         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12492         inset_field,
12493         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12494         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12495         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12496         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12497         "sctp-veri-tag#none");
12498 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12499         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12500         select, "select#add");
12501
12502 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12503         .f = cmd_set_fdir_input_set_parsed,
12504         .data = NULL,
12505         .help_str = "set_fdir_input_set <port_id> "
12506         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12507         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12508         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12509         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12510         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12511         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12512         "sctp-veri-tag|none select|add",
12513         .tokens = {
12514                 (void *)&cmd_set_fdir_input_set_cmd,
12515                 (void *)&cmd_set_fdir_input_set_port_id,
12516                 (void *)&cmd_set_fdir_input_set_flow_type,
12517                 (void *)&cmd_set_fdir_input_set_field,
12518                 (void *)&cmd_set_fdir_input_set_select,
12519                 NULL,
12520         },
12521 };
12522
12523 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12524 struct cmd_mcast_addr_result {
12525         cmdline_fixed_string_t mcast_addr_cmd;
12526         cmdline_fixed_string_t what;
12527         uint16_t port_num;
12528         struct rte_ether_addr mc_addr;
12529 };
12530
12531 static void cmd_mcast_addr_parsed(void *parsed_result,
12532                 __attribute__((unused)) struct cmdline *cl,
12533                 __attribute__((unused)) void *data)
12534 {
12535         struct cmd_mcast_addr_result *res = parsed_result;
12536
12537         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12538                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12539                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12540                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12541                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12542                 return;
12543         }
12544         if (strcmp(res->what, "add") == 0)
12545                 mcast_addr_add(res->port_num, &res->mc_addr);
12546         else
12547                 mcast_addr_remove(res->port_num, &res->mc_addr);
12548 }
12549
12550 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12551         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12552                                  mcast_addr_cmd, "mcast_addr");
12553 cmdline_parse_token_string_t cmd_mcast_addr_what =
12554         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12555                                  "add#remove");
12556 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12557         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12558 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12559         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12560
12561 cmdline_parse_inst_t cmd_mcast_addr = {
12562         .f = cmd_mcast_addr_parsed,
12563         .data = (void *)0,
12564         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12565                 "Add/Remove multicast MAC address on port_id",
12566         .tokens = {
12567                 (void *)&cmd_mcast_addr_cmd,
12568                 (void *)&cmd_mcast_addr_what,
12569                 (void *)&cmd_mcast_addr_portnum,
12570                 (void *)&cmd_mcast_addr_addr,
12571                 NULL,
12572         },
12573 };
12574
12575 /* l2 tunnel config
12576  * only support E-tag now.
12577  */
12578
12579 /* Ether type config */
12580 struct cmd_config_l2_tunnel_eth_type_result {
12581         cmdline_fixed_string_t port;
12582         cmdline_fixed_string_t config;
12583         cmdline_fixed_string_t all;
12584         portid_t id;
12585         cmdline_fixed_string_t l2_tunnel;
12586         cmdline_fixed_string_t l2_tunnel_type;
12587         cmdline_fixed_string_t eth_type;
12588         uint16_t eth_type_val;
12589 };
12590
12591 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12592         TOKEN_STRING_INITIALIZER
12593                 (struct cmd_config_l2_tunnel_eth_type_result,
12594                  port, "port");
12595 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12596         TOKEN_STRING_INITIALIZER
12597                 (struct cmd_config_l2_tunnel_eth_type_result,
12598                  config, "config");
12599 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12600         TOKEN_STRING_INITIALIZER
12601                 (struct cmd_config_l2_tunnel_eth_type_result,
12602                  all, "all");
12603 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12604         TOKEN_NUM_INITIALIZER
12605                 (struct cmd_config_l2_tunnel_eth_type_result,
12606                  id, UINT16);
12607 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12608         TOKEN_STRING_INITIALIZER
12609                 (struct cmd_config_l2_tunnel_eth_type_result,
12610                  l2_tunnel, "l2-tunnel");
12611 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12612         TOKEN_STRING_INITIALIZER
12613                 (struct cmd_config_l2_tunnel_eth_type_result,
12614                  l2_tunnel_type, "E-tag");
12615 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12616         TOKEN_STRING_INITIALIZER
12617                 (struct cmd_config_l2_tunnel_eth_type_result,
12618                  eth_type, "ether-type");
12619 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12620         TOKEN_NUM_INITIALIZER
12621                 (struct cmd_config_l2_tunnel_eth_type_result,
12622                  eth_type_val, UINT16);
12623
12624 static enum rte_eth_tunnel_type
12625 str2fdir_l2_tunnel_type(char *string)
12626 {
12627         uint32_t i = 0;
12628
12629         static const struct {
12630                 char str[32];
12631                 enum rte_eth_tunnel_type type;
12632         } l2_tunnel_type_str[] = {
12633                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12634         };
12635
12636         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12637                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12638                         return l2_tunnel_type_str[i].type;
12639         }
12640         return RTE_TUNNEL_TYPE_NONE;
12641 }
12642
12643 /* ether type config for all ports */
12644 static void
12645 cmd_config_l2_tunnel_eth_type_all_parsed
12646         (void *parsed_result,
12647          __attribute__((unused)) struct cmdline *cl,
12648          __attribute__((unused)) void *data)
12649 {
12650         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12651         struct rte_eth_l2_tunnel_conf entry;
12652         portid_t pid;
12653
12654         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12655         entry.ether_type = res->eth_type_val;
12656
12657         RTE_ETH_FOREACH_DEV(pid) {
12658                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12659         }
12660 }
12661
12662 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12663         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12664         .data = NULL,
12665         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12666         .tokens = {
12667                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12668                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12669                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12670                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12671                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12672                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12673                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12674                 NULL,
12675         },
12676 };
12677
12678 /* ether type config for a specific port */
12679 static void
12680 cmd_config_l2_tunnel_eth_type_specific_parsed(
12681         void *parsed_result,
12682         __attribute__((unused)) struct cmdline *cl,
12683         __attribute__((unused)) void *data)
12684 {
12685         struct cmd_config_l2_tunnel_eth_type_result *res =
12686                  parsed_result;
12687         struct rte_eth_l2_tunnel_conf entry;
12688
12689         if (port_id_is_invalid(res->id, ENABLED_WARN))
12690                 return;
12691
12692         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12693         entry.ether_type = res->eth_type_val;
12694
12695         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12696 }
12697
12698 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12699         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12700         .data = NULL,
12701         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12702         .tokens = {
12703                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12704                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12705                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12706                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12707                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12708                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12709                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12710                 NULL,
12711         },
12712 };
12713
12714 /* Enable/disable l2 tunnel */
12715 struct cmd_config_l2_tunnel_en_dis_result {
12716         cmdline_fixed_string_t port;
12717         cmdline_fixed_string_t config;
12718         cmdline_fixed_string_t all;
12719         portid_t id;
12720         cmdline_fixed_string_t l2_tunnel;
12721         cmdline_fixed_string_t l2_tunnel_type;
12722         cmdline_fixed_string_t en_dis;
12723 };
12724
12725 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12726         TOKEN_STRING_INITIALIZER
12727                 (struct cmd_config_l2_tunnel_en_dis_result,
12728                  port, "port");
12729 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12730         TOKEN_STRING_INITIALIZER
12731                 (struct cmd_config_l2_tunnel_en_dis_result,
12732                  config, "config");
12733 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12734         TOKEN_STRING_INITIALIZER
12735                 (struct cmd_config_l2_tunnel_en_dis_result,
12736                  all, "all");
12737 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12738         TOKEN_NUM_INITIALIZER
12739                 (struct cmd_config_l2_tunnel_en_dis_result,
12740                  id, UINT16);
12741 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12742         TOKEN_STRING_INITIALIZER
12743                 (struct cmd_config_l2_tunnel_en_dis_result,
12744                  l2_tunnel, "l2-tunnel");
12745 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12746         TOKEN_STRING_INITIALIZER
12747                 (struct cmd_config_l2_tunnel_en_dis_result,
12748                  l2_tunnel_type, "E-tag");
12749 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12750         TOKEN_STRING_INITIALIZER
12751                 (struct cmd_config_l2_tunnel_en_dis_result,
12752                  en_dis, "enable#disable");
12753
12754 /* enable/disable l2 tunnel for all ports */
12755 static void
12756 cmd_config_l2_tunnel_en_dis_all_parsed(
12757         void *parsed_result,
12758         __attribute__((unused)) struct cmdline *cl,
12759         __attribute__((unused)) void *data)
12760 {
12761         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12762         struct rte_eth_l2_tunnel_conf entry;
12763         portid_t pid;
12764         uint8_t en;
12765
12766         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12767
12768         if (!strcmp("enable", res->en_dis))
12769                 en = 1;
12770         else
12771                 en = 0;
12772
12773         RTE_ETH_FOREACH_DEV(pid) {
12774                 rte_eth_dev_l2_tunnel_offload_set(pid,
12775                                                   &entry,
12776                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12777                                                   en);
12778         }
12779 }
12780
12781 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12782         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12783         .data = NULL,
12784         .help_str = "port config all l2-tunnel E-tag enable|disable",
12785         .tokens = {
12786                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12787                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12788                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12789                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12790                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12791                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12792                 NULL,
12793         },
12794 };
12795
12796 /* enable/disable l2 tunnel for a port */
12797 static void
12798 cmd_config_l2_tunnel_en_dis_specific_parsed(
12799         void *parsed_result,
12800         __attribute__((unused)) struct cmdline *cl,
12801         __attribute__((unused)) void *data)
12802 {
12803         struct cmd_config_l2_tunnel_en_dis_result *res =
12804                 parsed_result;
12805         struct rte_eth_l2_tunnel_conf entry;
12806
12807         if (port_id_is_invalid(res->id, ENABLED_WARN))
12808                 return;
12809
12810         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12811
12812         if (!strcmp("enable", res->en_dis))
12813                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12814                                                   &entry,
12815                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12816                                                   1);
12817         else
12818                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12819                                                   &entry,
12820                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12821                                                   0);
12822 }
12823
12824 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12825         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12826         .data = NULL,
12827         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12828         .tokens = {
12829                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12830                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12831                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12832                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12833                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12834                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12835                 NULL,
12836         },
12837 };
12838
12839 /* E-tag configuration */
12840
12841 /* Common result structure for all E-tag configuration */
12842 struct cmd_config_e_tag_result {
12843         cmdline_fixed_string_t e_tag;
12844         cmdline_fixed_string_t set;
12845         cmdline_fixed_string_t insertion;
12846         cmdline_fixed_string_t stripping;
12847         cmdline_fixed_string_t forwarding;
12848         cmdline_fixed_string_t filter;
12849         cmdline_fixed_string_t add;
12850         cmdline_fixed_string_t del;
12851         cmdline_fixed_string_t on;
12852         cmdline_fixed_string_t off;
12853         cmdline_fixed_string_t on_off;
12854         cmdline_fixed_string_t port_tag_id;
12855         uint32_t port_tag_id_val;
12856         cmdline_fixed_string_t e_tag_id;
12857         uint16_t e_tag_id_val;
12858         cmdline_fixed_string_t dst_pool;
12859         uint8_t dst_pool_val;
12860         cmdline_fixed_string_t port;
12861         portid_t port_id;
12862         cmdline_fixed_string_t vf;
12863         uint8_t vf_id;
12864 };
12865
12866 /* Common CLI fields for all E-tag configuration */
12867 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12868         TOKEN_STRING_INITIALIZER
12869                 (struct cmd_config_e_tag_result,
12870                  e_tag, "E-tag");
12871 cmdline_parse_token_string_t cmd_config_e_tag_set =
12872         TOKEN_STRING_INITIALIZER
12873                 (struct cmd_config_e_tag_result,
12874                  set, "set");
12875 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12876         TOKEN_STRING_INITIALIZER
12877                 (struct cmd_config_e_tag_result,
12878                  insertion, "insertion");
12879 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12880         TOKEN_STRING_INITIALIZER
12881                 (struct cmd_config_e_tag_result,
12882                  stripping, "stripping");
12883 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12884         TOKEN_STRING_INITIALIZER
12885                 (struct cmd_config_e_tag_result,
12886                  forwarding, "forwarding");
12887 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12888         TOKEN_STRING_INITIALIZER
12889                 (struct cmd_config_e_tag_result,
12890                  filter, "filter");
12891 cmdline_parse_token_string_t cmd_config_e_tag_add =
12892         TOKEN_STRING_INITIALIZER
12893                 (struct cmd_config_e_tag_result,
12894                  add, "add");
12895 cmdline_parse_token_string_t cmd_config_e_tag_del =
12896         TOKEN_STRING_INITIALIZER
12897                 (struct cmd_config_e_tag_result,
12898                  del, "del");
12899 cmdline_parse_token_string_t cmd_config_e_tag_on =
12900         TOKEN_STRING_INITIALIZER
12901                 (struct cmd_config_e_tag_result,
12902                  on, "on");
12903 cmdline_parse_token_string_t cmd_config_e_tag_off =
12904         TOKEN_STRING_INITIALIZER
12905                 (struct cmd_config_e_tag_result,
12906                  off, "off");
12907 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12908         TOKEN_STRING_INITIALIZER
12909                 (struct cmd_config_e_tag_result,
12910                  on_off, "on#off");
12911 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12912         TOKEN_STRING_INITIALIZER
12913                 (struct cmd_config_e_tag_result,
12914                  port_tag_id, "port-tag-id");
12915 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12916         TOKEN_NUM_INITIALIZER
12917                 (struct cmd_config_e_tag_result,
12918                  port_tag_id_val, UINT32);
12919 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12920         TOKEN_STRING_INITIALIZER
12921                 (struct cmd_config_e_tag_result,
12922                  e_tag_id, "e-tag-id");
12923 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12924         TOKEN_NUM_INITIALIZER
12925                 (struct cmd_config_e_tag_result,
12926                  e_tag_id_val, UINT16);
12927 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12928         TOKEN_STRING_INITIALIZER
12929                 (struct cmd_config_e_tag_result,
12930                  dst_pool, "dst-pool");
12931 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12932         TOKEN_NUM_INITIALIZER
12933                 (struct cmd_config_e_tag_result,
12934                  dst_pool_val, UINT8);
12935 cmdline_parse_token_string_t cmd_config_e_tag_port =
12936         TOKEN_STRING_INITIALIZER
12937                 (struct cmd_config_e_tag_result,
12938                  port, "port");
12939 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12940         TOKEN_NUM_INITIALIZER
12941                 (struct cmd_config_e_tag_result,
12942                  port_id, UINT16);
12943 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12944         TOKEN_STRING_INITIALIZER
12945                 (struct cmd_config_e_tag_result,
12946                  vf, "vf");
12947 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12948         TOKEN_NUM_INITIALIZER
12949                 (struct cmd_config_e_tag_result,
12950                  vf_id, UINT8);
12951
12952 /* E-tag insertion configuration */
12953 static void
12954 cmd_config_e_tag_insertion_en_parsed(
12955         void *parsed_result,
12956         __attribute__((unused)) struct cmdline *cl,
12957         __attribute__((unused)) void *data)
12958 {
12959         struct cmd_config_e_tag_result *res =
12960                 parsed_result;
12961         struct rte_eth_l2_tunnel_conf entry;
12962
12963         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12964                 return;
12965
12966         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12967         entry.tunnel_id = res->port_tag_id_val;
12968         entry.vf_id = res->vf_id;
12969         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12970                                           &entry,
12971                                           ETH_L2_TUNNEL_INSERTION_MASK,
12972                                           1);
12973 }
12974
12975 static void
12976 cmd_config_e_tag_insertion_dis_parsed(
12977         void *parsed_result,
12978         __attribute__((unused)) struct cmdline *cl,
12979         __attribute__((unused)) void *data)
12980 {
12981         struct cmd_config_e_tag_result *res =
12982                 parsed_result;
12983         struct rte_eth_l2_tunnel_conf entry;
12984
12985         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12986                 return;
12987
12988         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12989         entry.vf_id = res->vf_id;
12990
12991         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12992                                           &entry,
12993                                           ETH_L2_TUNNEL_INSERTION_MASK,
12994                                           0);
12995 }
12996
12997 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12998         .f = cmd_config_e_tag_insertion_en_parsed,
12999         .data = NULL,
13000         .help_str = "E-tag ... : E-tag insertion enable",
13001         .tokens = {
13002                 (void *)&cmd_config_e_tag_e_tag,
13003                 (void *)&cmd_config_e_tag_set,
13004                 (void *)&cmd_config_e_tag_insertion,
13005                 (void *)&cmd_config_e_tag_on,
13006                 (void *)&cmd_config_e_tag_port_tag_id,
13007                 (void *)&cmd_config_e_tag_port_tag_id_val,
13008                 (void *)&cmd_config_e_tag_port,
13009                 (void *)&cmd_config_e_tag_port_id,
13010                 (void *)&cmd_config_e_tag_vf,
13011                 (void *)&cmd_config_e_tag_vf_id,
13012                 NULL,
13013         },
13014 };
13015
13016 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13017         .f = cmd_config_e_tag_insertion_dis_parsed,
13018         .data = NULL,
13019         .help_str = "E-tag ... : E-tag insertion disable",
13020         .tokens = {
13021                 (void *)&cmd_config_e_tag_e_tag,
13022                 (void *)&cmd_config_e_tag_set,
13023                 (void *)&cmd_config_e_tag_insertion,
13024                 (void *)&cmd_config_e_tag_off,
13025                 (void *)&cmd_config_e_tag_port,
13026                 (void *)&cmd_config_e_tag_port_id,
13027                 (void *)&cmd_config_e_tag_vf,
13028                 (void *)&cmd_config_e_tag_vf_id,
13029                 NULL,
13030         },
13031 };
13032
13033 /* E-tag stripping configuration */
13034 static void
13035 cmd_config_e_tag_stripping_parsed(
13036         void *parsed_result,
13037         __attribute__((unused)) struct cmdline *cl,
13038         __attribute__((unused)) void *data)
13039 {
13040         struct cmd_config_e_tag_result *res =
13041                 parsed_result;
13042         struct rte_eth_l2_tunnel_conf entry;
13043
13044         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13045                 return;
13046
13047         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13048
13049         if (!strcmp(res->on_off, "on"))
13050                 rte_eth_dev_l2_tunnel_offload_set
13051                         (res->port_id,
13052                          &entry,
13053                          ETH_L2_TUNNEL_STRIPPING_MASK,
13054                          1);
13055         else
13056                 rte_eth_dev_l2_tunnel_offload_set
13057                         (res->port_id,
13058                          &entry,
13059                          ETH_L2_TUNNEL_STRIPPING_MASK,
13060                          0);
13061 }
13062
13063 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13064         .f = cmd_config_e_tag_stripping_parsed,
13065         .data = NULL,
13066         .help_str = "E-tag ... : E-tag stripping enable/disable",
13067         .tokens = {
13068                 (void *)&cmd_config_e_tag_e_tag,
13069                 (void *)&cmd_config_e_tag_set,
13070                 (void *)&cmd_config_e_tag_stripping,
13071                 (void *)&cmd_config_e_tag_on_off,
13072                 (void *)&cmd_config_e_tag_port,
13073                 (void *)&cmd_config_e_tag_port_id,
13074                 NULL,
13075         },
13076 };
13077
13078 /* E-tag forwarding configuration */
13079 static void
13080 cmd_config_e_tag_forwarding_parsed(
13081         void *parsed_result,
13082         __attribute__((unused)) struct cmdline *cl,
13083         __attribute__((unused)) void *data)
13084 {
13085         struct cmd_config_e_tag_result *res = parsed_result;
13086         struct rte_eth_l2_tunnel_conf entry;
13087
13088         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13089                 return;
13090
13091         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13092
13093         if (!strcmp(res->on_off, "on"))
13094                 rte_eth_dev_l2_tunnel_offload_set
13095                         (res->port_id,
13096                          &entry,
13097                          ETH_L2_TUNNEL_FORWARDING_MASK,
13098                          1);
13099         else
13100                 rte_eth_dev_l2_tunnel_offload_set
13101                         (res->port_id,
13102                          &entry,
13103                          ETH_L2_TUNNEL_FORWARDING_MASK,
13104                          0);
13105 }
13106
13107 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13108         .f = cmd_config_e_tag_forwarding_parsed,
13109         .data = NULL,
13110         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13111         .tokens = {
13112                 (void *)&cmd_config_e_tag_e_tag,
13113                 (void *)&cmd_config_e_tag_set,
13114                 (void *)&cmd_config_e_tag_forwarding,
13115                 (void *)&cmd_config_e_tag_on_off,
13116                 (void *)&cmd_config_e_tag_port,
13117                 (void *)&cmd_config_e_tag_port_id,
13118                 NULL,
13119         },
13120 };
13121
13122 /* E-tag filter configuration */
13123 static void
13124 cmd_config_e_tag_filter_add_parsed(
13125         void *parsed_result,
13126         __attribute__((unused)) struct cmdline *cl,
13127         __attribute__((unused)) void *data)
13128 {
13129         struct cmd_config_e_tag_result *res = parsed_result;
13130         struct rte_eth_l2_tunnel_conf entry;
13131         int ret = 0;
13132
13133         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13134                 return;
13135
13136         if (res->e_tag_id_val > 0x3fff) {
13137                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13138                 return;
13139         }
13140
13141         ret = rte_eth_dev_filter_supported(res->port_id,
13142                                            RTE_ETH_FILTER_L2_TUNNEL);
13143         if (ret < 0) {
13144                 printf("E-tag filter is not supported on port %u.\n",
13145                        res->port_id);
13146                 return;
13147         }
13148
13149         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13150         entry.tunnel_id = res->e_tag_id_val;
13151         entry.pool = res->dst_pool_val;
13152
13153         ret = rte_eth_dev_filter_ctrl(res->port_id,
13154                                       RTE_ETH_FILTER_L2_TUNNEL,
13155                                       RTE_ETH_FILTER_ADD,
13156                                       &entry);
13157         if (ret < 0)
13158                 printf("E-tag filter programming error: (%s)\n",
13159                        strerror(-ret));
13160 }
13161
13162 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13163         .f = cmd_config_e_tag_filter_add_parsed,
13164         .data = NULL,
13165         .help_str = "E-tag ... : E-tag filter add",
13166         .tokens = {
13167                 (void *)&cmd_config_e_tag_e_tag,
13168                 (void *)&cmd_config_e_tag_set,
13169                 (void *)&cmd_config_e_tag_filter,
13170                 (void *)&cmd_config_e_tag_add,
13171                 (void *)&cmd_config_e_tag_e_tag_id,
13172                 (void *)&cmd_config_e_tag_e_tag_id_val,
13173                 (void *)&cmd_config_e_tag_dst_pool,
13174                 (void *)&cmd_config_e_tag_dst_pool_val,
13175                 (void *)&cmd_config_e_tag_port,
13176                 (void *)&cmd_config_e_tag_port_id,
13177                 NULL,
13178         },
13179 };
13180
13181 static void
13182 cmd_config_e_tag_filter_del_parsed(
13183         void *parsed_result,
13184         __attribute__((unused)) struct cmdline *cl,
13185         __attribute__((unused)) void *data)
13186 {
13187         struct cmd_config_e_tag_result *res = parsed_result;
13188         struct rte_eth_l2_tunnel_conf entry;
13189         int ret = 0;
13190
13191         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13192                 return;
13193
13194         if (res->e_tag_id_val > 0x3fff) {
13195                 printf("e-tag-id must be less than 0x3fff.\n");
13196                 return;
13197         }
13198
13199         ret = rte_eth_dev_filter_supported(res->port_id,
13200                                            RTE_ETH_FILTER_L2_TUNNEL);
13201         if (ret < 0) {
13202                 printf("E-tag filter is not supported on port %u.\n",
13203                        res->port_id);
13204                 return;
13205         }
13206
13207         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13208         entry.tunnel_id = res->e_tag_id_val;
13209
13210         ret = rte_eth_dev_filter_ctrl(res->port_id,
13211                                       RTE_ETH_FILTER_L2_TUNNEL,
13212                                       RTE_ETH_FILTER_DELETE,
13213                                       &entry);
13214         if (ret < 0)
13215                 printf("E-tag filter programming error: (%s)\n",
13216                        strerror(-ret));
13217 }
13218
13219 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13220         .f = cmd_config_e_tag_filter_del_parsed,
13221         .data = NULL,
13222         .help_str = "E-tag ... : E-tag filter delete",
13223         .tokens = {
13224                 (void *)&cmd_config_e_tag_e_tag,
13225                 (void *)&cmd_config_e_tag_set,
13226                 (void *)&cmd_config_e_tag_filter,
13227                 (void *)&cmd_config_e_tag_del,
13228                 (void *)&cmd_config_e_tag_e_tag_id,
13229                 (void *)&cmd_config_e_tag_e_tag_id_val,
13230                 (void *)&cmd_config_e_tag_port,
13231                 (void *)&cmd_config_e_tag_port_id,
13232                 NULL,
13233         },
13234 };
13235
13236 /* vf vlan anti spoof configuration */
13237
13238 /* Common result structure for vf vlan anti spoof */
13239 struct cmd_vf_vlan_anti_spoof_result {
13240         cmdline_fixed_string_t set;
13241         cmdline_fixed_string_t vf;
13242         cmdline_fixed_string_t vlan;
13243         cmdline_fixed_string_t antispoof;
13244         portid_t port_id;
13245         uint32_t vf_id;
13246         cmdline_fixed_string_t on_off;
13247 };
13248
13249 /* Common CLI fields for vf vlan anti spoof enable disable */
13250 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13251         TOKEN_STRING_INITIALIZER
13252                 (struct cmd_vf_vlan_anti_spoof_result,
13253                  set, "set");
13254 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13255         TOKEN_STRING_INITIALIZER
13256                 (struct cmd_vf_vlan_anti_spoof_result,
13257                  vf, "vf");
13258 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13259         TOKEN_STRING_INITIALIZER
13260                 (struct cmd_vf_vlan_anti_spoof_result,
13261                  vlan, "vlan");
13262 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13263         TOKEN_STRING_INITIALIZER
13264                 (struct cmd_vf_vlan_anti_spoof_result,
13265                  antispoof, "antispoof");
13266 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13267         TOKEN_NUM_INITIALIZER
13268                 (struct cmd_vf_vlan_anti_spoof_result,
13269                  port_id, UINT16);
13270 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13271         TOKEN_NUM_INITIALIZER
13272                 (struct cmd_vf_vlan_anti_spoof_result,
13273                  vf_id, UINT32);
13274 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13275         TOKEN_STRING_INITIALIZER
13276                 (struct cmd_vf_vlan_anti_spoof_result,
13277                  on_off, "on#off");
13278
13279 static void
13280 cmd_set_vf_vlan_anti_spoof_parsed(
13281         void *parsed_result,
13282         __attribute__((unused)) struct cmdline *cl,
13283         __attribute__((unused)) void *data)
13284 {
13285         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13286         int ret = -ENOTSUP;
13287
13288         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13289
13290         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13291                 return;
13292
13293 #ifdef RTE_LIBRTE_IXGBE_PMD
13294         if (ret == -ENOTSUP)
13295                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13296                                 res->vf_id, is_on);
13297 #endif
13298 #ifdef RTE_LIBRTE_I40E_PMD
13299         if (ret == -ENOTSUP)
13300                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13301                                 res->vf_id, is_on);
13302 #endif
13303 #ifdef RTE_LIBRTE_BNXT_PMD
13304         if (ret == -ENOTSUP)
13305                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13306                                 res->vf_id, is_on);
13307 #endif
13308
13309         switch (ret) {
13310         case 0:
13311                 break;
13312         case -EINVAL:
13313                 printf("invalid vf_id %d\n", res->vf_id);
13314                 break;
13315         case -ENODEV:
13316                 printf("invalid port_id %d\n", res->port_id);
13317                 break;
13318         case -ENOTSUP:
13319                 printf("function not implemented\n");
13320                 break;
13321         default:
13322                 printf("programming error: (%s)\n", strerror(-ret));
13323         }
13324 }
13325
13326 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13327         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13328         .data = NULL,
13329         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13330         .tokens = {
13331                 (void *)&cmd_vf_vlan_anti_spoof_set,
13332                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13333                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13334                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13335                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13336                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13337                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13338                 NULL,
13339         },
13340 };
13341
13342 /* vf mac anti spoof configuration */
13343
13344 /* Common result structure for vf mac anti spoof */
13345 struct cmd_vf_mac_anti_spoof_result {
13346         cmdline_fixed_string_t set;
13347         cmdline_fixed_string_t vf;
13348         cmdline_fixed_string_t mac;
13349         cmdline_fixed_string_t antispoof;
13350         portid_t port_id;
13351         uint32_t vf_id;
13352         cmdline_fixed_string_t on_off;
13353 };
13354
13355 /* Common CLI fields for vf mac anti spoof enable disable */
13356 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13357         TOKEN_STRING_INITIALIZER
13358                 (struct cmd_vf_mac_anti_spoof_result,
13359                  set, "set");
13360 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13361         TOKEN_STRING_INITIALIZER
13362                 (struct cmd_vf_mac_anti_spoof_result,
13363                  vf, "vf");
13364 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13365         TOKEN_STRING_INITIALIZER
13366                 (struct cmd_vf_mac_anti_spoof_result,
13367                  mac, "mac");
13368 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13369         TOKEN_STRING_INITIALIZER
13370                 (struct cmd_vf_mac_anti_spoof_result,
13371                  antispoof, "antispoof");
13372 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13373         TOKEN_NUM_INITIALIZER
13374                 (struct cmd_vf_mac_anti_spoof_result,
13375                  port_id, UINT16);
13376 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13377         TOKEN_NUM_INITIALIZER
13378                 (struct cmd_vf_mac_anti_spoof_result,
13379                  vf_id, UINT32);
13380 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13381         TOKEN_STRING_INITIALIZER
13382                 (struct cmd_vf_mac_anti_spoof_result,
13383                  on_off, "on#off");
13384
13385 static void
13386 cmd_set_vf_mac_anti_spoof_parsed(
13387         void *parsed_result,
13388         __attribute__((unused)) struct cmdline *cl,
13389         __attribute__((unused)) void *data)
13390 {
13391         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13392         int ret = -ENOTSUP;
13393
13394         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13395
13396         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13397                 return;
13398
13399 #ifdef RTE_LIBRTE_IXGBE_PMD
13400         if (ret == -ENOTSUP)
13401                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13402                         res->vf_id, is_on);
13403 #endif
13404 #ifdef RTE_LIBRTE_I40E_PMD
13405         if (ret == -ENOTSUP)
13406                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13407                         res->vf_id, is_on);
13408 #endif
13409 #ifdef RTE_LIBRTE_BNXT_PMD
13410         if (ret == -ENOTSUP)
13411                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13412                         res->vf_id, is_on);
13413 #endif
13414
13415         switch (ret) {
13416         case 0:
13417                 break;
13418         case -EINVAL:
13419                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13420                 break;
13421         case -ENODEV:
13422                 printf("invalid port_id %d\n", res->port_id);
13423                 break;
13424         case -ENOTSUP:
13425                 printf("function not implemented\n");
13426                 break;
13427         default:
13428                 printf("programming error: (%s)\n", strerror(-ret));
13429         }
13430 }
13431
13432 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13433         .f = cmd_set_vf_mac_anti_spoof_parsed,
13434         .data = NULL,
13435         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13436         .tokens = {
13437                 (void *)&cmd_vf_mac_anti_spoof_set,
13438                 (void *)&cmd_vf_mac_anti_spoof_vf,
13439                 (void *)&cmd_vf_mac_anti_spoof_mac,
13440                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13441                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13442                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13443                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13444                 NULL,
13445         },
13446 };
13447
13448 /* vf vlan strip queue configuration */
13449
13450 /* Common result structure for vf mac anti spoof */
13451 struct cmd_vf_vlan_stripq_result {
13452         cmdline_fixed_string_t set;
13453         cmdline_fixed_string_t vf;
13454         cmdline_fixed_string_t vlan;
13455         cmdline_fixed_string_t stripq;
13456         portid_t port_id;
13457         uint16_t vf_id;
13458         cmdline_fixed_string_t on_off;
13459 };
13460
13461 /* Common CLI fields for vf vlan strip enable disable */
13462 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13463         TOKEN_STRING_INITIALIZER
13464                 (struct cmd_vf_vlan_stripq_result,
13465                  set, "set");
13466 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13467         TOKEN_STRING_INITIALIZER
13468                 (struct cmd_vf_vlan_stripq_result,
13469                  vf, "vf");
13470 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13471         TOKEN_STRING_INITIALIZER
13472                 (struct cmd_vf_vlan_stripq_result,
13473                  vlan, "vlan");
13474 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13475         TOKEN_STRING_INITIALIZER
13476                 (struct cmd_vf_vlan_stripq_result,
13477                  stripq, "stripq");
13478 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13479         TOKEN_NUM_INITIALIZER
13480                 (struct cmd_vf_vlan_stripq_result,
13481                  port_id, UINT16);
13482 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13483         TOKEN_NUM_INITIALIZER
13484                 (struct cmd_vf_vlan_stripq_result,
13485                  vf_id, UINT16);
13486 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13487         TOKEN_STRING_INITIALIZER
13488                 (struct cmd_vf_vlan_stripq_result,
13489                  on_off, "on#off");
13490
13491 static void
13492 cmd_set_vf_vlan_stripq_parsed(
13493         void *parsed_result,
13494         __attribute__((unused)) struct cmdline *cl,
13495         __attribute__((unused)) void *data)
13496 {
13497         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13498         int ret = -ENOTSUP;
13499
13500         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13501
13502         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13503                 return;
13504
13505 #ifdef RTE_LIBRTE_IXGBE_PMD
13506         if (ret == -ENOTSUP)
13507                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13508                         res->vf_id, is_on);
13509 #endif
13510 #ifdef RTE_LIBRTE_I40E_PMD
13511         if (ret == -ENOTSUP)
13512                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13513                         res->vf_id, is_on);
13514 #endif
13515 #ifdef RTE_LIBRTE_BNXT_PMD
13516         if (ret == -ENOTSUP)
13517                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13518                         res->vf_id, is_on);
13519 #endif
13520
13521         switch (ret) {
13522         case 0:
13523                 break;
13524         case -EINVAL:
13525                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13526                 break;
13527         case -ENODEV:
13528                 printf("invalid port_id %d\n", res->port_id);
13529                 break;
13530         case -ENOTSUP:
13531                 printf("function not implemented\n");
13532                 break;
13533         default:
13534                 printf("programming error: (%s)\n", strerror(-ret));
13535         }
13536 }
13537
13538 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13539         .f = cmd_set_vf_vlan_stripq_parsed,
13540         .data = NULL,
13541         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13542         .tokens = {
13543                 (void *)&cmd_vf_vlan_stripq_set,
13544                 (void *)&cmd_vf_vlan_stripq_vf,
13545                 (void *)&cmd_vf_vlan_stripq_vlan,
13546                 (void *)&cmd_vf_vlan_stripq_stripq,
13547                 (void *)&cmd_vf_vlan_stripq_port_id,
13548                 (void *)&cmd_vf_vlan_stripq_vf_id,
13549                 (void *)&cmd_vf_vlan_stripq_on_off,
13550                 NULL,
13551         },
13552 };
13553
13554 /* vf vlan insert configuration */
13555
13556 /* Common result structure for vf vlan insert */
13557 struct cmd_vf_vlan_insert_result {
13558         cmdline_fixed_string_t set;
13559         cmdline_fixed_string_t vf;
13560         cmdline_fixed_string_t vlan;
13561         cmdline_fixed_string_t insert;
13562         portid_t port_id;
13563         uint16_t vf_id;
13564         uint16_t vlan_id;
13565 };
13566
13567 /* Common CLI fields for vf vlan insert enable disable */
13568 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13569         TOKEN_STRING_INITIALIZER
13570                 (struct cmd_vf_vlan_insert_result,
13571                  set, "set");
13572 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13573         TOKEN_STRING_INITIALIZER
13574                 (struct cmd_vf_vlan_insert_result,
13575                  vf, "vf");
13576 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13577         TOKEN_STRING_INITIALIZER
13578                 (struct cmd_vf_vlan_insert_result,
13579                  vlan, "vlan");
13580 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13581         TOKEN_STRING_INITIALIZER
13582                 (struct cmd_vf_vlan_insert_result,
13583                  insert, "insert");
13584 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13585         TOKEN_NUM_INITIALIZER
13586                 (struct cmd_vf_vlan_insert_result,
13587                  port_id, UINT16);
13588 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13589         TOKEN_NUM_INITIALIZER
13590                 (struct cmd_vf_vlan_insert_result,
13591                  vf_id, UINT16);
13592 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13593         TOKEN_NUM_INITIALIZER
13594                 (struct cmd_vf_vlan_insert_result,
13595                  vlan_id, UINT16);
13596
13597 static void
13598 cmd_set_vf_vlan_insert_parsed(
13599         void *parsed_result,
13600         __attribute__((unused)) struct cmdline *cl,
13601         __attribute__((unused)) void *data)
13602 {
13603         struct cmd_vf_vlan_insert_result *res = parsed_result;
13604         int ret = -ENOTSUP;
13605
13606         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13607                 return;
13608
13609 #ifdef RTE_LIBRTE_IXGBE_PMD
13610         if (ret == -ENOTSUP)
13611                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13612                         res->vlan_id);
13613 #endif
13614 #ifdef RTE_LIBRTE_I40E_PMD
13615         if (ret == -ENOTSUP)
13616                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13617                         res->vlan_id);
13618 #endif
13619 #ifdef RTE_LIBRTE_BNXT_PMD
13620         if (ret == -ENOTSUP)
13621                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13622                         res->vlan_id);
13623 #endif
13624
13625         switch (ret) {
13626         case 0:
13627                 break;
13628         case -EINVAL:
13629                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13630                 break;
13631         case -ENODEV:
13632                 printf("invalid port_id %d\n", res->port_id);
13633                 break;
13634         case -ENOTSUP:
13635                 printf("function not implemented\n");
13636                 break;
13637         default:
13638                 printf("programming error: (%s)\n", strerror(-ret));
13639         }
13640 }
13641
13642 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13643         .f = cmd_set_vf_vlan_insert_parsed,
13644         .data = NULL,
13645         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13646         .tokens = {
13647                 (void *)&cmd_vf_vlan_insert_set,
13648                 (void *)&cmd_vf_vlan_insert_vf,
13649                 (void *)&cmd_vf_vlan_insert_vlan,
13650                 (void *)&cmd_vf_vlan_insert_insert,
13651                 (void *)&cmd_vf_vlan_insert_port_id,
13652                 (void *)&cmd_vf_vlan_insert_vf_id,
13653                 (void *)&cmd_vf_vlan_insert_vlan_id,
13654                 NULL,
13655         },
13656 };
13657
13658 /* tx loopback configuration */
13659
13660 /* Common result structure for tx loopback */
13661 struct cmd_tx_loopback_result {
13662         cmdline_fixed_string_t set;
13663         cmdline_fixed_string_t tx;
13664         cmdline_fixed_string_t loopback;
13665         portid_t port_id;
13666         cmdline_fixed_string_t on_off;
13667 };
13668
13669 /* Common CLI fields for tx loopback enable disable */
13670 cmdline_parse_token_string_t cmd_tx_loopback_set =
13671         TOKEN_STRING_INITIALIZER
13672                 (struct cmd_tx_loopback_result,
13673                  set, "set");
13674 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13675         TOKEN_STRING_INITIALIZER
13676                 (struct cmd_tx_loopback_result,
13677                  tx, "tx");
13678 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13679         TOKEN_STRING_INITIALIZER
13680                 (struct cmd_tx_loopback_result,
13681                  loopback, "loopback");
13682 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13683         TOKEN_NUM_INITIALIZER
13684                 (struct cmd_tx_loopback_result,
13685                  port_id, UINT16);
13686 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13687         TOKEN_STRING_INITIALIZER
13688                 (struct cmd_tx_loopback_result,
13689                  on_off, "on#off");
13690
13691 static void
13692 cmd_set_tx_loopback_parsed(
13693         void *parsed_result,
13694         __attribute__((unused)) struct cmdline *cl,
13695         __attribute__((unused)) void *data)
13696 {
13697         struct cmd_tx_loopback_result *res = parsed_result;
13698         int ret = -ENOTSUP;
13699
13700         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13701
13702         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13703                 return;
13704
13705 #ifdef RTE_LIBRTE_IXGBE_PMD
13706         if (ret == -ENOTSUP)
13707                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13708 #endif
13709 #ifdef RTE_LIBRTE_I40E_PMD
13710         if (ret == -ENOTSUP)
13711                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13712 #endif
13713 #ifdef RTE_LIBRTE_BNXT_PMD
13714         if (ret == -ENOTSUP)
13715                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13716 #endif
13717 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13718         if (ret == -ENOTSUP)
13719                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13720 #endif
13721
13722         switch (ret) {
13723         case 0:
13724                 break;
13725         case -EINVAL:
13726                 printf("invalid is_on %d\n", is_on);
13727                 break;
13728         case -ENODEV:
13729                 printf("invalid port_id %d\n", res->port_id);
13730                 break;
13731         case -ENOTSUP:
13732                 printf("function not implemented\n");
13733                 break;
13734         default:
13735                 printf("programming error: (%s)\n", strerror(-ret));
13736         }
13737 }
13738
13739 cmdline_parse_inst_t cmd_set_tx_loopback = {
13740         .f = cmd_set_tx_loopback_parsed,
13741         .data = NULL,
13742         .help_str = "set tx loopback <port_id> on|off",
13743         .tokens = {
13744                 (void *)&cmd_tx_loopback_set,
13745                 (void *)&cmd_tx_loopback_tx,
13746                 (void *)&cmd_tx_loopback_loopback,
13747                 (void *)&cmd_tx_loopback_port_id,
13748                 (void *)&cmd_tx_loopback_on_off,
13749                 NULL,
13750         },
13751 };
13752
13753 /* all queues drop enable configuration */
13754
13755 /* Common result structure for all queues drop enable */
13756 struct cmd_all_queues_drop_en_result {
13757         cmdline_fixed_string_t set;
13758         cmdline_fixed_string_t all;
13759         cmdline_fixed_string_t queues;
13760         cmdline_fixed_string_t drop;
13761         portid_t port_id;
13762         cmdline_fixed_string_t on_off;
13763 };
13764
13765 /* Common CLI fields for tx loopback enable disable */
13766 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13767         TOKEN_STRING_INITIALIZER
13768                 (struct cmd_all_queues_drop_en_result,
13769                  set, "set");
13770 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13771         TOKEN_STRING_INITIALIZER
13772                 (struct cmd_all_queues_drop_en_result,
13773                  all, "all");
13774 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13775         TOKEN_STRING_INITIALIZER
13776                 (struct cmd_all_queues_drop_en_result,
13777                  queues, "queues");
13778 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13779         TOKEN_STRING_INITIALIZER
13780                 (struct cmd_all_queues_drop_en_result,
13781                  drop, "drop");
13782 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13783         TOKEN_NUM_INITIALIZER
13784                 (struct cmd_all_queues_drop_en_result,
13785                  port_id, UINT16);
13786 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13787         TOKEN_STRING_INITIALIZER
13788                 (struct cmd_all_queues_drop_en_result,
13789                  on_off, "on#off");
13790
13791 static void
13792 cmd_set_all_queues_drop_en_parsed(
13793         void *parsed_result,
13794         __attribute__((unused)) struct cmdline *cl,
13795         __attribute__((unused)) void *data)
13796 {
13797         struct cmd_all_queues_drop_en_result *res = parsed_result;
13798         int ret = -ENOTSUP;
13799         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13800
13801         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13802                 return;
13803
13804 #ifdef RTE_LIBRTE_IXGBE_PMD
13805         if (ret == -ENOTSUP)
13806                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13807 #endif
13808 #ifdef RTE_LIBRTE_BNXT_PMD
13809         if (ret == -ENOTSUP)
13810                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13811 #endif
13812         switch (ret) {
13813         case 0:
13814                 break;
13815         case -EINVAL:
13816                 printf("invalid is_on %d\n", is_on);
13817                 break;
13818         case -ENODEV:
13819                 printf("invalid port_id %d\n", res->port_id);
13820                 break;
13821         case -ENOTSUP:
13822                 printf("function not implemented\n");
13823                 break;
13824         default:
13825                 printf("programming error: (%s)\n", strerror(-ret));
13826         }
13827 }
13828
13829 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13830         .f = cmd_set_all_queues_drop_en_parsed,
13831         .data = NULL,
13832         .help_str = "set all queues drop <port_id> on|off",
13833         .tokens = {
13834                 (void *)&cmd_all_queues_drop_en_set,
13835                 (void *)&cmd_all_queues_drop_en_all,
13836                 (void *)&cmd_all_queues_drop_en_queues,
13837                 (void *)&cmd_all_queues_drop_en_drop,
13838                 (void *)&cmd_all_queues_drop_en_port_id,
13839                 (void *)&cmd_all_queues_drop_en_on_off,
13840                 NULL,
13841         },
13842 };
13843
13844 /* vf split drop enable configuration */
13845
13846 /* Common result structure for vf split drop enable */
13847 struct cmd_vf_split_drop_en_result {
13848         cmdline_fixed_string_t set;
13849         cmdline_fixed_string_t vf;
13850         cmdline_fixed_string_t split;
13851         cmdline_fixed_string_t drop;
13852         portid_t port_id;
13853         uint16_t vf_id;
13854         cmdline_fixed_string_t on_off;
13855 };
13856
13857 /* Common CLI fields for vf split drop enable disable */
13858 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13859         TOKEN_STRING_INITIALIZER
13860                 (struct cmd_vf_split_drop_en_result,
13861                  set, "set");
13862 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13863         TOKEN_STRING_INITIALIZER
13864                 (struct cmd_vf_split_drop_en_result,
13865                  vf, "vf");
13866 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13867         TOKEN_STRING_INITIALIZER
13868                 (struct cmd_vf_split_drop_en_result,
13869                  split, "split");
13870 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13871         TOKEN_STRING_INITIALIZER
13872                 (struct cmd_vf_split_drop_en_result,
13873                  drop, "drop");
13874 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13875         TOKEN_NUM_INITIALIZER
13876                 (struct cmd_vf_split_drop_en_result,
13877                  port_id, UINT16);
13878 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13879         TOKEN_NUM_INITIALIZER
13880                 (struct cmd_vf_split_drop_en_result,
13881                  vf_id, UINT16);
13882 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13883         TOKEN_STRING_INITIALIZER
13884                 (struct cmd_vf_split_drop_en_result,
13885                  on_off, "on#off");
13886
13887 static void
13888 cmd_set_vf_split_drop_en_parsed(
13889         void *parsed_result,
13890         __attribute__((unused)) struct cmdline *cl,
13891         __attribute__((unused)) void *data)
13892 {
13893         struct cmd_vf_split_drop_en_result *res = parsed_result;
13894         int ret = -ENOTSUP;
13895         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13896
13897         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13898                 return;
13899
13900 #ifdef RTE_LIBRTE_IXGBE_PMD
13901         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13902                         is_on);
13903 #endif
13904         switch (ret) {
13905         case 0:
13906                 break;
13907         case -EINVAL:
13908                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13909                 break;
13910         case -ENODEV:
13911                 printf("invalid port_id %d\n", res->port_id);
13912                 break;
13913         case -ENOTSUP:
13914                 printf("not supported on port %d\n", res->port_id);
13915                 break;
13916         default:
13917                 printf("programming error: (%s)\n", strerror(-ret));
13918         }
13919 }
13920
13921 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13922         .f = cmd_set_vf_split_drop_en_parsed,
13923         .data = NULL,
13924         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13925         .tokens = {
13926                 (void *)&cmd_vf_split_drop_en_set,
13927                 (void *)&cmd_vf_split_drop_en_vf,
13928                 (void *)&cmd_vf_split_drop_en_split,
13929                 (void *)&cmd_vf_split_drop_en_drop,
13930                 (void *)&cmd_vf_split_drop_en_port_id,
13931                 (void *)&cmd_vf_split_drop_en_vf_id,
13932                 (void *)&cmd_vf_split_drop_en_on_off,
13933                 NULL,
13934         },
13935 };
13936
13937 /* vf mac address configuration */
13938
13939 /* Common result structure for vf mac address */
13940 struct cmd_set_vf_mac_addr_result {
13941         cmdline_fixed_string_t set;
13942         cmdline_fixed_string_t vf;
13943         cmdline_fixed_string_t mac;
13944         cmdline_fixed_string_t addr;
13945         portid_t port_id;
13946         uint16_t vf_id;
13947         struct rte_ether_addr mac_addr;
13948
13949 };
13950
13951 /* Common CLI fields for vf split drop enable disable */
13952 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13953         TOKEN_STRING_INITIALIZER
13954                 (struct cmd_set_vf_mac_addr_result,
13955                  set, "set");
13956 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13957         TOKEN_STRING_INITIALIZER
13958                 (struct cmd_set_vf_mac_addr_result,
13959                  vf, "vf");
13960 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13961         TOKEN_STRING_INITIALIZER
13962                 (struct cmd_set_vf_mac_addr_result,
13963                  mac, "mac");
13964 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13965         TOKEN_STRING_INITIALIZER
13966                 (struct cmd_set_vf_mac_addr_result,
13967                  addr, "addr");
13968 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13969         TOKEN_NUM_INITIALIZER
13970                 (struct cmd_set_vf_mac_addr_result,
13971                  port_id, UINT16);
13972 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13973         TOKEN_NUM_INITIALIZER
13974                 (struct cmd_set_vf_mac_addr_result,
13975                  vf_id, UINT16);
13976 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13977         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13978                  mac_addr);
13979
13980 static void
13981 cmd_set_vf_mac_addr_parsed(
13982         void *parsed_result,
13983         __attribute__((unused)) struct cmdline *cl,
13984         __attribute__((unused)) void *data)
13985 {
13986         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13987         int ret = -ENOTSUP;
13988
13989         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13990                 return;
13991
13992 #ifdef RTE_LIBRTE_IXGBE_PMD
13993         if (ret == -ENOTSUP)
13994                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13995                                 &res->mac_addr);
13996 #endif
13997 #ifdef RTE_LIBRTE_I40E_PMD
13998         if (ret == -ENOTSUP)
13999                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14000                                 &res->mac_addr);
14001 #endif
14002 #ifdef RTE_LIBRTE_BNXT_PMD
14003         if (ret == -ENOTSUP)
14004                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14005                                 &res->mac_addr);
14006 #endif
14007
14008         switch (ret) {
14009         case 0:
14010                 break;
14011         case -EINVAL:
14012                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14013                 break;
14014         case -ENODEV:
14015                 printf("invalid port_id %d\n", res->port_id);
14016                 break;
14017         case -ENOTSUP:
14018                 printf("function not implemented\n");
14019                 break;
14020         default:
14021                 printf("programming error: (%s)\n", strerror(-ret));
14022         }
14023 }
14024
14025 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14026         .f = cmd_set_vf_mac_addr_parsed,
14027         .data = NULL,
14028         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14029         .tokens = {
14030                 (void *)&cmd_set_vf_mac_addr_set,
14031                 (void *)&cmd_set_vf_mac_addr_vf,
14032                 (void *)&cmd_set_vf_mac_addr_mac,
14033                 (void *)&cmd_set_vf_mac_addr_addr,
14034                 (void *)&cmd_set_vf_mac_addr_port_id,
14035                 (void *)&cmd_set_vf_mac_addr_vf_id,
14036                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14037                 NULL,
14038         },
14039 };
14040
14041 /* MACsec configuration */
14042
14043 /* Common result structure for MACsec offload enable */
14044 struct cmd_macsec_offload_on_result {
14045         cmdline_fixed_string_t set;
14046         cmdline_fixed_string_t macsec;
14047         cmdline_fixed_string_t offload;
14048         portid_t port_id;
14049         cmdline_fixed_string_t on;
14050         cmdline_fixed_string_t encrypt;
14051         cmdline_fixed_string_t en_on_off;
14052         cmdline_fixed_string_t replay_protect;
14053         cmdline_fixed_string_t rp_on_off;
14054 };
14055
14056 /* Common CLI fields for MACsec offload disable */
14057 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14058         TOKEN_STRING_INITIALIZER
14059                 (struct cmd_macsec_offload_on_result,
14060                  set, "set");
14061 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14062         TOKEN_STRING_INITIALIZER
14063                 (struct cmd_macsec_offload_on_result,
14064                  macsec, "macsec");
14065 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14066         TOKEN_STRING_INITIALIZER
14067                 (struct cmd_macsec_offload_on_result,
14068                  offload, "offload");
14069 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14070         TOKEN_NUM_INITIALIZER
14071                 (struct cmd_macsec_offload_on_result,
14072                  port_id, UINT16);
14073 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14074         TOKEN_STRING_INITIALIZER
14075                 (struct cmd_macsec_offload_on_result,
14076                  on, "on");
14077 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14078         TOKEN_STRING_INITIALIZER
14079                 (struct cmd_macsec_offload_on_result,
14080                  encrypt, "encrypt");
14081 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14082         TOKEN_STRING_INITIALIZER
14083                 (struct cmd_macsec_offload_on_result,
14084                  en_on_off, "on#off");
14085 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14086         TOKEN_STRING_INITIALIZER
14087                 (struct cmd_macsec_offload_on_result,
14088                  replay_protect, "replay-protect");
14089 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14090         TOKEN_STRING_INITIALIZER
14091                 (struct cmd_macsec_offload_on_result,
14092                  rp_on_off, "on#off");
14093
14094 static void
14095 cmd_set_macsec_offload_on_parsed(
14096         void *parsed_result,
14097         __attribute__((unused)) struct cmdline *cl,
14098         __attribute__((unused)) void *data)
14099 {
14100         struct cmd_macsec_offload_on_result *res = parsed_result;
14101         int ret = -ENOTSUP;
14102         portid_t port_id = res->port_id;
14103         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14104         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14105         struct rte_eth_dev_info dev_info;
14106
14107         if (port_id_is_invalid(port_id, ENABLED_WARN))
14108                 return;
14109         if (!port_is_stopped(port_id)) {
14110                 printf("Please stop port %d first\n", port_id);
14111                 return;
14112         }
14113
14114         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14115         if (ret != 0)
14116                 return;
14117
14118         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14119 #ifdef RTE_LIBRTE_IXGBE_PMD
14120                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14121 #endif
14122         }
14123         RTE_SET_USED(en);
14124         RTE_SET_USED(rp);
14125
14126         switch (ret) {
14127         case 0:
14128                 ports[port_id].dev_conf.txmode.offloads |=
14129                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14130                 cmd_reconfig_device_queue(port_id, 1, 1);
14131                 break;
14132         case -ENODEV:
14133                 printf("invalid port_id %d\n", port_id);
14134                 break;
14135         case -ENOTSUP:
14136                 printf("not supported on port %d\n", port_id);
14137                 break;
14138         default:
14139                 printf("programming error: (%s)\n", strerror(-ret));
14140         }
14141 }
14142
14143 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14144         .f = cmd_set_macsec_offload_on_parsed,
14145         .data = NULL,
14146         .help_str = "set macsec offload <port_id> on "
14147                 "encrypt on|off replay-protect on|off",
14148         .tokens = {
14149                 (void *)&cmd_macsec_offload_on_set,
14150                 (void *)&cmd_macsec_offload_on_macsec,
14151                 (void *)&cmd_macsec_offload_on_offload,
14152                 (void *)&cmd_macsec_offload_on_port_id,
14153                 (void *)&cmd_macsec_offload_on_on,
14154                 (void *)&cmd_macsec_offload_on_encrypt,
14155                 (void *)&cmd_macsec_offload_on_en_on_off,
14156                 (void *)&cmd_macsec_offload_on_replay_protect,
14157                 (void *)&cmd_macsec_offload_on_rp_on_off,
14158                 NULL,
14159         },
14160 };
14161
14162 /* Common result structure for MACsec offload disable */
14163 struct cmd_macsec_offload_off_result {
14164         cmdline_fixed_string_t set;
14165         cmdline_fixed_string_t macsec;
14166         cmdline_fixed_string_t offload;
14167         portid_t port_id;
14168         cmdline_fixed_string_t off;
14169 };
14170
14171 /* Common CLI fields for MACsec offload disable */
14172 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14173         TOKEN_STRING_INITIALIZER
14174                 (struct cmd_macsec_offload_off_result,
14175                  set, "set");
14176 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14177         TOKEN_STRING_INITIALIZER
14178                 (struct cmd_macsec_offload_off_result,
14179                  macsec, "macsec");
14180 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14181         TOKEN_STRING_INITIALIZER
14182                 (struct cmd_macsec_offload_off_result,
14183                  offload, "offload");
14184 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14185         TOKEN_NUM_INITIALIZER
14186                 (struct cmd_macsec_offload_off_result,
14187                  port_id, UINT16);
14188 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14189         TOKEN_STRING_INITIALIZER
14190                 (struct cmd_macsec_offload_off_result,
14191                  off, "off");
14192
14193 static void
14194 cmd_set_macsec_offload_off_parsed(
14195         void *parsed_result,
14196         __attribute__((unused)) struct cmdline *cl,
14197         __attribute__((unused)) void *data)
14198 {
14199         struct cmd_macsec_offload_off_result *res = parsed_result;
14200         int ret = -ENOTSUP;
14201         struct rte_eth_dev_info dev_info;
14202         portid_t port_id = res->port_id;
14203
14204         if (port_id_is_invalid(port_id, ENABLED_WARN))
14205                 return;
14206         if (!port_is_stopped(port_id)) {
14207                 printf("Please stop port %d first\n", port_id);
14208                 return;
14209         }
14210
14211         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14212         if (ret != 0)
14213                 return;
14214
14215         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14216 #ifdef RTE_LIBRTE_IXGBE_PMD
14217                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14218 #endif
14219         }
14220         switch (ret) {
14221         case 0:
14222                 ports[port_id].dev_conf.txmode.offloads &=
14223                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14224                 cmd_reconfig_device_queue(port_id, 1, 1);
14225                 break;
14226         case -ENODEV:
14227                 printf("invalid port_id %d\n", port_id);
14228                 break;
14229         case -ENOTSUP:
14230                 printf("not supported on port %d\n", port_id);
14231                 break;
14232         default:
14233                 printf("programming error: (%s)\n", strerror(-ret));
14234         }
14235 }
14236
14237 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14238         .f = cmd_set_macsec_offload_off_parsed,
14239         .data = NULL,
14240         .help_str = "set macsec offload <port_id> off",
14241         .tokens = {
14242                 (void *)&cmd_macsec_offload_off_set,
14243                 (void *)&cmd_macsec_offload_off_macsec,
14244                 (void *)&cmd_macsec_offload_off_offload,
14245                 (void *)&cmd_macsec_offload_off_port_id,
14246                 (void *)&cmd_macsec_offload_off_off,
14247                 NULL,
14248         },
14249 };
14250
14251 /* Common result structure for MACsec secure connection configure */
14252 struct cmd_macsec_sc_result {
14253         cmdline_fixed_string_t set;
14254         cmdline_fixed_string_t macsec;
14255         cmdline_fixed_string_t sc;
14256         cmdline_fixed_string_t tx_rx;
14257         portid_t port_id;
14258         struct rte_ether_addr mac;
14259         uint16_t pi;
14260 };
14261
14262 /* Common CLI fields for MACsec secure connection configure */
14263 cmdline_parse_token_string_t cmd_macsec_sc_set =
14264         TOKEN_STRING_INITIALIZER
14265                 (struct cmd_macsec_sc_result,
14266                  set, "set");
14267 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14268         TOKEN_STRING_INITIALIZER
14269                 (struct cmd_macsec_sc_result,
14270                  macsec, "macsec");
14271 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14272         TOKEN_STRING_INITIALIZER
14273                 (struct cmd_macsec_sc_result,
14274                  sc, "sc");
14275 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14276         TOKEN_STRING_INITIALIZER
14277                 (struct cmd_macsec_sc_result,
14278                  tx_rx, "tx#rx");
14279 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14280         TOKEN_NUM_INITIALIZER
14281                 (struct cmd_macsec_sc_result,
14282                  port_id, UINT16);
14283 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14284         TOKEN_ETHERADDR_INITIALIZER
14285                 (struct cmd_macsec_sc_result,
14286                  mac);
14287 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14288         TOKEN_NUM_INITIALIZER
14289                 (struct cmd_macsec_sc_result,
14290                  pi, UINT16);
14291
14292 static void
14293 cmd_set_macsec_sc_parsed(
14294         void *parsed_result,
14295         __attribute__((unused)) struct cmdline *cl,
14296         __attribute__((unused)) void *data)
14297 {
14298         struct cmd_macsec_sc_result *res = parsed_result;
14299         int ret = -ENOTSUP;
14300         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14301
14302 #ifdef RTE_LIBRTE_IXGBE_PMD
14303         ret = is_tx ?
14304                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14305                                 res->mac.addr_bytes) :
14306                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14307                                 res->mac.addr_bytes, res->pi);
14308 #endif
14309         RTE_SET_USED(is_tx);
14310
14311         switch (ret) {
14312         case 0:
14313                 break;
14314         case -ENODEV:
14315                 printf("invalid port_id %d\n", res->port_id);
14316                 break;
14317         case -ENOTSUP:
14318                 printf("not supported on port %d\n", res->port_id);
14319                 break;
14320         default:
14321                 printf("programming error: (%s)\n", strerror(-ret));
14322         }
14323 }
14324
14325 cmdline_parse_inst_t cmd_set_macsec_sc = {
14326         .f = cmd_set_macsec_sc_parsed,
14327         .data = NULL,
14328         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14329         .tokens = {
14330                 (void *)&cmd_macsec_sc_set,
14331                 (void *)&cmd_macsec_sc_macsec,
14332                 (void *)&cmd_macsec_sc_sc,
14333                 (void *)&cmd_macsec_sc_tx_rx,
14334                 (void *)&cmd_macsec_sc_port_id,
14335                 (void *)&cmd_macsec_sc_mac,
14336                 (void *)&cmd_macsec_sc_pi,
14337                 NULL,
14338         },
14339 };
14340
14341 /* Common result structure for MACsec secure connection configure */
14342 struct cmd_macsec_sa_result {
14343         cmdline_fixed_string_t set;
14344         cmdline_fixed_string_t macsec;
14345         cmdline_fixed_string_t sa;
14346         cmdline_fixed_string_t tx_rx;
14347         portid_t port_id;
14348         uint8_t idx;
14349         uint8_t an;
14350         uint32_t pn;
14351         cmdline_fixed_string_t key;
14352 };
14353
14354 /* Common CLI fields for MACsec secure connection configure */
14355 cmdline_parse_token_string_t cmd_macsec_sa_set =
14356         TOKEN_STRING_INITIALIZER
14357                 (struct cmd_macsec_sa_result,
14358                  set, "set");
14359 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14360         TOKEN_STRING_INITIALIZER
14361                 (struct cmd_macsec_sa_result,
14362                  macsec, "macsec");
14363 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14364         TOKEN_STRING_INITIALIZER
14365                 (struct cmd_macsec_sa_result,
14366                  sa, "sa");
14367 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14368         TOKEN_STRING_INITIALIZER
14369                 (struct cmd_macsec_sa_result,
14370                  tx_rx, "tx#rx");
14371 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14372         TOKEN_NUM_INITIALIZER
14373                 (struct cmd_macsec_sa_result,
14374                  port_id, UINT16);
14375 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14376         TOKEN_NUM_INITIALIZER
14377                 (struct cmd_macsec_sa_result,
14378                  idx, UINT8);
14379 cmdline_parse_token_num_t cmd_macsec_sa_an =
14380         TOKEN_NUM_INITIALIZER
14381                 (struct cmd_macsec_sa_result,
14382                  an, UINT8);
14383 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14384         TOKEN_NUM_INITIALIZER
14385                 (struct cmd_macsec_sa_result,
14386                  pn, UINT32);
14387 cmdline_parse_token_string_t cmd_macsec_sa_key =
14388         TOKEN_STRING_INITIALIZER
14389                 (struct cmd_macsec_sa_result,
14390                  key, NULL);
14391
14392 static void
14393 cmd_set_macsec_sa_parsed(
14394         void *parsed_result,
14395         __attribute__((unused)) struct cmdline *cl,
14396         __attribute__((unused)) void *data)
14397 {
14398         struct cmd_macsec_sa_result *res = parsed_result;
14399         int ret = -ENOTSUP;
14400         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14401         uint8_t key[16] = { 0 };
14402         uint8_t xdgt0;
14403         uint8_t xdgt1;
14404         int key_len;
14405         int i;
14406
14407         key_len = strlen(res->key) / 2;
14408         if (key_len > 16)
14409                 key_len = 16;
14410
14411         for (i = 0; i < key_len; i++) {
14412                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14413                 if (xdgt0 == 0xFF)
14414                         return;
14415                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14416                 if (xdgt1 == 0xFF)
14417                         return;
14418                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14419         }
14420
14421 #ifdef RTE_LIBRTE_IXGBE_PMD
14422         ret = is_tx ?
14423                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14424                         res->idx, res->an, res->pn, key) :
14425                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14426                         res->idx, res->an, res->pn, key);
14427 #endif
14428         RTE_SET_USED(is_tx);
14429         RTE_SET_USED(key);
14430
14431         switch (ret) {
14432         case 0:
14433                 break;
14434         case -EINVAL:
14435                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14436                 break;
14437         case -ENODEV:
14438                 printf("invalid port_id %d\n", res->port_id);
14439                 break;
14440         case -ENOTSUP:
14441                 printf("not supported on port %d\n", res->port_id);
14442                 break;
14443         default:
14444                 printf("programming error: (%s)\n", strerror(-ret));
14445         }
14446 }
14447
14448 cmdline_parse_inst_t cmd_set_macsec_sa = {
14449         .f = cmd_set_macsec_sa_parsed,
14450         .data = NULL,
14451         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14452         .tokens = {
14453                 (void *)&cmd_macsec_sa_set,
14454                 (void *)&cmd_macsec_sa_macsec,
14455                 (void *)&cmd_macsec_sa_sa,
14456                 (void *)&cmd_macsec_sa_tx_rx,
14457                 (void *)&cmd_macsec_sa_port_id,
14458                 (void *)&cmd_macsec_sa_idx,
14459                 (void *)&cmd_macsec_sa_an,
14460                 (void *)&cmd_macsec_sa_pn,
14461                 (void *)&cmd_macsec_sa_key,
14462                 NULL,
14463         },
14464 };
14465
14466 /* VF unicast promiscuous mode configuration */
14467
14468 /* Common result structure for VF unicast promiscuous mode */
14469 struct cmd_vf_promisc_result {
14470         cmdline_fixed_string_t set;
14471         cmdline_fixed_string_t vf;
14472         cmdline_fixed_string_t promisc;
14473         portid_t port_id;
14474         uint32_t vf_id;
14475         cmdline_fixed_string_t on_off;
14476 };
14477
14478 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14479 cmdline_parse_token_string_t cmd_vf_promisc_set =
14480         TOKEN_STRING_INITIALIZER
14481                 (struct cmd_vf_promisc_result,
14482                  set, "set");
14483 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14484         TOKEN_STRING_INITIALIZER
14485                 (struct cmd_vf_promisc_result,
14486                  vf, "vf");
14487 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14488         TOKEN_STRING_INITIALIZER
14489                 (struct cmd_vf_promisc_result,
14490                  promisc, "promisc");
14491 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14492         TOKEN_NUM_INITIALIZER
14493                 (struct cmd_vf_promisc_result,
14494                  port_id, UINT16);
14495 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14496         TOKEN_NUM_INITIALIZER
14497                 (struct cmd_vf_promisc_result,
14498                  vf_id, UINT32);
14499 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14500         TOKEN_STRING_INITIALIZER
14501                 (struct cmd_vf_promisc_result,
14502                  on_off, "on#off");
14503
14504 static void
14505 cmd_set_vf_promisc_parsed(
14506         void *parsed_result,
14507         __attribute__((unused)) struct cmdline *cl,
14508         __attribute__((unused)) void *data)
14509 {
14510         struct cmd_vf_promisc_result *res = parsed_result;
14511         int ret = -ENOTSUP;
14512
14513         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14514
14515         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14516                 return;
14517
14518 #ifdef RTE_LIBRTE_I40E_PMD
14519         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14520                                                   res->vf_id, is_on);
14521 #endif
14522
14523         switch (ret) {
14524         case 0:
14525                 break;
14526         case -EINVAL:
14527                 printf("invalid vf_id %d\n", res->vf_id);
14528                 break;
14529         case -ENODEV:
14530                 printf("invalid port_id %d\n", res->port_id);
14531                 break;
14532         case -ENOTSUP:
14533                 printf("function not implemented\n");
14534                 break;
14535         default:
14536                 printf("programming error: (%s)\n", strerror(-ret));
14537         }
14538 }
14539
14540 cmdline_parse_inst_t cmd_set_vf_promisc = {
14541         .f = cmd_set_vf_promisc_parsed,
14542         .data = NULL,
14543         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14544                 "Set unicast promiscuous mode for a VF from the PF",
14545         .tokens = {
14546                 (void *)&cmd_vf_promisc_set,
14547                 (void *)&cmd_vf_promisc_vf,
14548                 (void *)&cmd_vf_promisc_promisc,
14549                 (void *)&cmd_vf_promisc_port_id,
14550                 (void *)&cmd_vf_promisc_vf_id,
14551                 (void *)&cmd_vf_promisc_on_off,
14552                 NULL,
14553         },
14554 };
14555
14556 /* VF multicast promiscuous mode configuration */
14557
14558 /* Common result structure for VF multicast promiscuous mode */
14559 struct cmd_vf_allmulti_result {
14560         cmdline_fixed_string_t set;
14561         cmdline_fixed_string_t vf;
14562         cmdline_fixed_string_t allmulti;
14563         portid_t port_id;
14564         uint32_t vf_id;
14565         cmdline_fixed_string_t on_off;
14566 };
14567
14568 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14569 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14570         TOKEN_STRING_INITIALIZER
14571                 (struct cmd_vf_allmulti_result,
14572                  set, "set");
14573 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14574         TOKEN_STRING_INITIALIZER
14575                 (struct cmd_vf_allmulti_result,
14576                  vf, "vf");
14577 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14578         TOKEN_STRING_INITIALIZER
14579                 (struct cmd_vf_allmulti_result,
14580                  allmulti, "allmulti");
14581 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14582         TOKEN_NUM_INITIALIZER
14583                 (struct cmd_vf_allmulti_result,
14584                  port_id, UINT16);
14585 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14586         TOKEN_NUM_INITIALIZER
14587                 (struct cmd_vf_allmulti_result,
14588                  vf_id, UINT32);
14589 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14590         TOKEN_STRING_INITIALIZER
14591                 (struct cmd_vf_allmulti_result,
14592                  on_off, "on#off");
14593
14594 static void
14595 cmd_set_vf_allmulti_parsed(
14596         void *parsed_result,
14597         __attribute__((unused)) struct cmdline *cl,
14598         __attribute__((unused)) void *data)
14599 {
14600         struct cmd_vf_allmulti_result *res = parsed_result;
14601         int ret = -ENOTSUP;
14602
14603         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14604
14605         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14606                 return;
14607
14608 #ifdef RTE_LIBRTE_I40E_PMD
14609         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14610                                                     res->vf_id, is_on);
14611 #endif
14612
14613         switch (ret) {
14614         case 0:
14615                 break;
14616         case -EINVAL:
14617                 printf("invalid vf_id %d\n", res->vf_id);
14618                 break;
14619         case -ENODEV:
14620                 printf("invalid port_id %d\n", res->port_id);
14621                 break;
14622         case -ENOTSUP:
14623                 printf("function not implemented\n");
14624                 break;
14625         default:
14626                 printf("programming error: (%s)\n", strerror(-ret));
14627         }
14628 }
14629
14630 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14631         .f = cmd_set_vf_allmulti_parsed,
14632         .data = NULL,
14633         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14634                 "Set multicast promiscuous mode for a VF from the PF",
14635         .tokens = {
14636                 (void *)&cmd_vf_allmulti_set,
14637                 (void *)&cmd_vf_allmulti_vf,
14638                 (void *)&cmd_vf_allmulti_allmulti,
14639                 (void *)&cmd_vf_allmulti_port_id,
14640                 (void *)&cmd_vf_allmulti_vf_id,
14641                 (void *)&cmd_vf_allmulti_on_off,
14642                 NULL,
14643         },
14644 };
14645
14646 /* vf broadcast mode configuration */
14647
14648 /* Common result structure for vf broadcast */
14649 struct cmd_set_vf_broadcast_result {
14650         cmdline_fixed_string_t set;
14651         cmdline_fixed_string_t vf;
14652         cmdline_fixed_string_t broadcast;
14653         portid_t port_id;
14654         uint16_t vf_id;
14655         cmdline_fixed_string_t on_off;
14656 };
14657
14658 /* Common CLI fields for vf broadcast enable disable */
14659 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14660         TOKEN_STRING_INITIALIZER
14661                 (struct cmd_set_vf_broadcast_result,
14662                  set, "set");
14663 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14664         TOKEN_STRING_INITIALIZER
14665                 (struct cmd_set_vf_broadcast_result,
14666                  vf, "vf");
14667 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14668         TOKEN_STRING_INITIALIZER
14669                 (struct cmd_set_vf_broadcast_result,
14670                  broadcast, "broadcast");
14671 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14672         TOKEN_NUM_INITIALIZER
14673                 (struct cmd_set_vf_broadcast_result,
14674                  port_id, UINT16);
14675 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14676         TOKEN_NUM_INITIALIZER
14677                 (struct cmd_set_vf_broadcast_result,
14678                  vf_id, UINT16);
14679 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14680         TOKEN_STRING_INITIALIZER
14681                 (struct cmd_set_vf_broadcast_result,
14682                  on_off, "on#off");
14683
14684 static void
14685 cmd_set_vf_broadcast_parsed(
14686         void *parsed_result,
14687         __attribute__((unused)) struct cmdline *cl,
14688         __attribute__((unused)) void *data)
14689 {
14690         struct cmd_set_vf_broadcast_result *res = parsed_result;
14691         int ret = -ENOTSUP;
14692
14693         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14694
14695         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14696                 return;
14697
14698 #ifdef RTE_LIBRTE_I40E_PMD
14699         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14700                                             res->vf_id, is_on);
14701 #endif
14702
14703         switch (ret) {
14704         case 0:
14705                 break;
14706         case -EINVAL:
14707                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14708                 break;
14709         case -ENODEV:
14710                 printf("invalid port_id %d\n", res->port_id);
14711                 break;
14712         case -ENOTSUP:
14713                 printf("function not implemented\n");
14714                 break;
14715         default:
14716                 printf("programming error: (%s)\n", strerror(-ret));
14717         }
14718 }
14719
14720 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14721         .f = cmd_set_vf_broadcast_parsed,
14722         .data = NULL,
14723         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14724         .tokens = {
14725                 (void *)&cmd_set_vf_broadcast_set,
14726                 (void *)&cmd_set_vf_broadcast_vf,
14727                 (void *)&cmd_set_vf_broadcast_broadcast,
14728                 (void *)&cmd_set_vf_broadcast_port_id,
14729                 (void *)&cmd_set_vf_broadcast_vf_id,
14730                 (void *)&cmd_set_vf_broadcast_on_off,
14731                 NULL,
14732         },
14733 };
14734
14735 /* vf vlan tag configuration */
14736
14737 /* Common result structure for vf vlan tag */
14738 struct cmd_set_vf_vlan_tag_result {
14739         cmdline_fixed_string_t set;
14740         cmdline_fixed_string_t vf;
14741         cmdline_fixed_string_t vlan;
14742         cmdline_fixed_string_t tag;
14743         portid_t port_id;
14744         uint16_t vf_id;
14745         cmdline_fixed_string_t on_off;
14746 };
14747
14748 /* Common CLI fields for vf vlan tag enable disable */
14749 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14750         TOKEN_STRING_INITIALIZER
14751                 (struct cmd_set_vf_vlan_tag_result,
14752                  set, "set");
14753 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14754         TOKEN_STRING_INITIALIZER
14755                 (struct cmd_set_vf_vlan_tag_result,
14756                  vf, "vf");
14757 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14758         TOKEN_STRING_INITIALIZER
14759                 (struct cmd_set_vf_vlan_tag_result,
14760                  vlan, "vlan");
14761 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14762         TOKEN_STRING_INITIALIZER
14763                 (struct cmd_set_vf_vlan_tag_result,
14764                  tag, "tag");
14765 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14766         TOKEN_NUM_INITIALIZER
14767                 (struct cmd_set_vf_vlan_tag_result,
14768                  port_id, UINT16);
14769 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14770         TOKEN_NUM_INITIALIZER
14771                 (struct cmd_set_vf_vlan_tag_result,
14772                  vf_id, UINT16);
14773 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14774         TOKEN_STRING_INITIALIZER
14775                 (struct cmd_set_vf_vlan_tag_result,
14776                  on_off, "on#off");
14777
14778 static void
14779 cmd_set_vf_vlan_tag_parsed(
14780         void *parsed_result,
14781         __attribute__((unused)) struct cmdline *cl,
14782         __attribute__((unused)) void *data)
14783 {
14784         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14785         int ret = -ENOTSUP;
14786
14787         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14788
14789         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14790                 return;
14791
14792 #ifdef RTE_LIBRTE_I40E_PMD
14793         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14794                                            res->vf_id, is_on);
14795 #endif
14796
14797         switch (ret) {
14798         case 0:
14799                 break;
14800         case -EINVAL:
14801                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14802                 break;
14803         case -ENODEV:
14804                 printf("invalid port_id %d\n", res->port_id);
14805                 break;
14806         case -ENOTSUP:
14807                 printf("function not implemented\n");
14808                 break;
14809         default:
14810                 printf("programming error: (%s)\n", strerror(-ret));
14811         }
14812 }
14813
14814 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14815         .f = cmd_set_vf_vlan_tag_parsed,
14816         .data = NULL,
14817         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14818         .tokens = {
14819                 (void *)&cmd_set_vf_vlan_tag_set,
14820                 (void *)&cmd_set_vf_vlan_tag_vf,
14821                 (void *)&cmd_set_vf_vlan_tag_vlan,
14822                 (void *)&cmd_set_vf_vlan_tag_tag,
14823                 (void *)&cmd_set_vf_vlan_tag_port_id,
14824                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14825                 (void *)&cmd_set_vf_vlan_tag_on_off,
14826                 NULL,
14827         },
14828 };
14829
14830 /* Common definition of VF and TC TX bandwidth configuration */
14831 struct cmd_vf_tc_bw_result {
14832         cmdline_fixed_string_t set;
14833         cmdline_fixed_string_t vf;
14834         cmdline_fixed_string_t tc;
14835         cmdline_fixed_string_t tx;
14836         cmdline_fixed_string_t min_bw;
14837         cmdline_fixed_string_t max_bw;
14838         cmdline_fixed_string_t strict_link_prio;
14839         portid_t port_id;
14840         uint16_t vf_id;
14841         uint8_t tc_no;
14842         uint32_t bw;
14843         cmdline_fixed_string_t bw_list;
14844         uint8_t tc_map;
14845 };
14846
14847 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14848         TOKEN_STRING_INITIALIZER
14849                 (struct cmd_vf_tc_bw_result,
14850                  set, "set");
14851 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14852         TOKEN_STRING_INITIALIZER
14853                 (struct cmd_vf_tc_bw_result,
14854                  vf, "vf");
14855 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14856         TOKEN_STRING_INITIALIZER
14857                 (struct cmd_vf_tc_bw_result,
14858                  tc, "tc");
14859 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14860         TOKEN_STRING_INITIALIZER
14861                 (struct cmd_vf_tc_bw_result,
14862                  tx, "tx");
14863 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14864         TOKEN_STRING_INITIALIZER
14865                 (struct cmd_vf_tc_bw_result,
14866                  strict_link_prio, "strict-link-priority");
14867 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14868         TOKEN_STRING_INITIALIZER
14869                 (struct cmd_vf_tc_bw_result,
14870                  min_bw, "min-bandwidth");
14871 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14872         TOKEN_STRING_INITIALIZER
14873                 (struct cmd_vf_tc_bw_result,
14874                  max_bw, "max-bandwidth");
14875 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14876         TOKEN_NUM_INITIALIZER
14877                 (struct cmd_vf_tc_bw_result,
14878                  port_id, UINT16);
14879 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14880         TOKEN_NUM_INITIALIZER
14881                 (struct cmd_vf_tc_bw_result,
14882                  vf_id, UINT16);
14883 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14884         TOKEN_NUM_INITIALIZER
14885                 (struct cmd_vf_tc_bw_result,
14886                  tc_no, UINT8);
14887 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14888         TOKEN_NUM_INITIALIZER
14889                 (struct cmd_vf_tc_bw_result,
14890                  bw, UINT32);
14891 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14892         TOKEN_STRING_INITIALIZER
14893                 (struct cmd_vf_tc_bw_result,
14894                  bw_list, NULL);
14895 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14896         TOKEN_NUM_INITIALIZER
14897                 (struct cmd_vf_tc_bw_result,
14898                  tc_map, UINT8);
14899
14900 /* VF max bandwidth setting */
14901 static void
14902 cmd_vf_max_bw_parsed(
14903         void *parsed_result,
14904         __attribute__((unused)) struct cmdline *cl,
14905         __attribute__((unused)) void *data)
14906 {
14907         struct cmd_vf_tc_bw_result *res = parsed_result;
14908         int ret = -ENOTSUP;
14909
14910         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14911                 return;
14912
14913 #ifdef RTE_LIBRTE_I40E_PMD
14914         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14915                                          res->vf_id, res->bw);
14916 #endif
14917
14918         switch (ret) {
14919         case 0:
14920                 break;
14921         case -EINVAL:
14922                 printf("invalid vf_id %d or bandwidth %d\n",
14923                        res->vf_id, res->bw);
14924                 break;
14925         case -ENODEV:
14926                 printf("invalid port_id %d\n", res->port_id);
14927                 break;
14928         case -ENOTSUP:
14929                 printf("function not implemented\n");
14930                 break;
14931         default:
14932                 printf("programming error: (%s)\n", strerror(-ret));
14933         }
14934 }
14935
14936 cmdline_parse_inst_t cmd_vf_max_bw = {
14937         .f = cmd_vf_max_bw_parsed,
14938         .data = NULL,
14939         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14940         .tokens = {
14941                 (void *)&cmd_vf_tc_bw_set,
14942                 (void *)&cmd_vf_tc_bw_vf,
14943                 (void *)&cmd_vf_tc_bw_tx,
14944                 (void *)&cmd_vf_tc_bw_max_bw,
14945                 (void *)&cmd_vf_tc_bw_port_id,
14946                 (void *)&cmd_vf_tc_bw_vf_id,
14947                 (void *)&cmd_vf_tc_bw_bw,
14948                 NULL,
14949         },
14950 };
14951
14952 static int
14953 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14954                            uint8_t *tc_num,
14955                            char *str)
14956 {
14957         uint32_t size;
14958         const char *p, *p0 = str;
14959         char s[256];
14960         char *end;
14961         char *str_fld[16];
14962         uint16_t i;
14963         int ret;
14964
14965         p = strchr(p0, '(');
14966         if (p == NULL) {
14967                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14968                 return -1;
14969         }
14970         p++;
14971         p0 = strchr(p, ')');
14972         if (p0 == NULL) {
14973                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14974                 return -1;
14975         }
14976         size = p0 - p;
14977         if (size >= sizeof(s)) {
14978                 printf("The string size exceeds the internal buffer size\n");
14979                 return -1;
14980         }
14981         snprintf(s, sizeof(s), "%.*s", size, p);
14982         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14983         if (ret <= 0) {
14984                 printf("Failed to get the bandwidth list. ");
14985                 return -1;
14986         }
14987         *tc_num = ret;
14988         for (i = 0; i < ret; i++)
14989                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14990
14991         return 0;
14992 }
14993
14994 /* TC min bandwidth setting */
14995 static void
14996 cmd_vf_tc_min_bw_parsed(
14997         void *parsed_result,
14998         __attribute__((unused)) struct cmdline *cl,
14999         __attribute__((unused)) void *data)
15000 {
15001         struct cmd_vf_tc_bw_result *res = parsed_result;
15002         uint8_t tc_num;
15003         uint8_t bw[16];
15004         int ret = -ENOTSUP;
15005
15006         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15007                 return;
15008
15009         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15010         if (ret)
15011                 return;
15012
15013 #ifdef RTE_LIBRTE_I40E_PMD
15014         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15015                                               tc_num, bw);
15016 #endif
15017
15018         switch (ret) {
15019         case 0:
15020                 break;
15021         case -EINVAL:
15022                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15023                 break;
15024         case -ENODEV:
15025                 printf("invalid port_id %d\n", res->port_id);
15026                 break;
15027         case -ENOTSUP:
15028                 printf("function not implemented\n");
15029                 break;
15030         default:
15031                 printf("programming error: (%s)\n", strerror(-ret));
15032         }
15033 }
15034
15035 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15036         .f = cmd_vf_tc_min_bw_parsed,
15037         .data = NULL,
15038         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15039                     " <bw1, bw2, ...>",
15040         .tokens = {
15041                 (void *)&cmd_vf_tc_bw_set,
15042                 (void *)&cmd_vf_tc_bw_vf,
15043                 (void *)&cmd_vf_tc_bw_tc,
15044                 (void *)&cmd_vf_tc_bw_tx,
15045                 (void *)&cmd_vf_tc_bw_min_bw,
15046                 (void *)&cmd_vf_tc_bw_port_id,
15047                 (void *)&cmd_vf_tc_bw_vf_id,
15048                 (void *)&cmd_vf_tc_bw_bw_list,
15049                 NULL,
15050         },
15051 };
15052
15053 static void
15054 cmd_tc_min_bw_parsed(
15055         void *parsed_result,
15056         __attribute__((unused)) struct cmdline *cl,
15057         __attribute__((unused)) void *data)
15058 {
15059         struct cmd_vf_tc_bw_result *res = parsed_result;
15060         struct rte_port *port;
15061         uint8_t tc_num;
15062         uint8_t bw[16];
15063         int ret = -ENOTSUP;
15064
15065         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15066                 return;
15067
15068         port = &ports[res->port_id];
15069         /** Check if the port is not started **/
15070         if (port->port_status != RTE_PORT_STOPPED) {
15071                 printf("Please stop port %d first\n", res->port_id);
15072                 return;
15073         }
15074
15075         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15076         if (ret)
15077                 return;
15078
15079 #ifdef RTE_LIBRTE_IXGBE_PMD
15080         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15081 #endif
15082
15083         switch (ret) {
15084         case 0:
15085                 break;
15086         case -EINVAL:
15087                 printf("invalid bandwidth\n");
15088                 break;
15089         case -ENODEV:
15090                 printf("invalid port_id %d\n", res->port_id);
15091                 break;
15092         case -ENOTSUP:
15093                 printf("function not implemented\n");
15094                 break;
15095         default:
15096                 printf("programming error: (%s)\n", strerror(-ret));
15097         }
15098 }
15099
15100 cmdline_parse_inst_t cmd_tc_min_bw = {
15101         .f = cmd_tc_min_bw_parsed,
15102         .data = NULL,
15103         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15104         .tokens = {
15105                 (void *)&cmd_vf_tc_bw_set,
15106                 (void *)&cmd_vf_tc_bw_tc,
15107                 (void *)&cmd_vf_tc_bw_tx,
15108                 (void *)&cmd_vf_tc_bw_min_bw,
15109                 (void *)&cmd_vf_tc_bw_port_id,
15110                 (void *)&cmd_vf_tc_bw_bw_list,
15111                 NULL,
15112         },
15113 };
15114
15115 /* TC max bandwidth setting */
15116 static void
15117 cmd_vf_tc_max_bw_parsed(
15118         void *parsed_result,
15119         __attribute__((unused)) struct cmdline *cl,
15120         __attribute__((unused)) void *data)
15121 {
15122         struct cmd_vf_tc_bw_result *res = parsed_result;
15123         int ret = -ENOTSUP;
15124
15125         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15126                 return;
15127
15128 #ifdef RTE_LIBRTE_I40E_PMD
15129         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15130                                             res->tc_no, res->bw);
15131 #endif
15132
15133         switch (ret) {
15134         case 0:
15135                 break;
15136         case -EINVAL:
15137                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15138                        res->vf_id, res->tc_no, res->bw);
15139                 break;
15140         case -ENODEV:
15141                 printf("invalid port_id %d\n", res->port_id);
15142                 break;
15143         case -ENOTSUP:
15144                 printf("function not implemented\n");
15145                 break;
15146         default:
15147                 printf("programming error: (%s)\n", strerror(-ret));
15148         }
15149 }
15150
15151 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15152         .f = cmd_vf_tc_max_bw_parsed,
15153         .data = NULL,
15154         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15155                     " <bandwidth>",
15156         .tokens = {
15157                 (void *)&cmd_vf_tc_bw_set,
15158                 (void *)&cmd_vf_tc_bw_vf,
15159                 (void *)&cmd_vf_tc_bw_tc,
15160                 (void *)&cmd_vf_tc_bw_tx,
15161                 (void *)&cmd_vf_tc_bw_max_bw,
15162                 (void *)&cmd_vf_tc_bw_port_id,
15163                 (void *)&cmd_vf_tc_bw_vf_id,
15164                 (void *)&cmd_vf_tc_bw_tc_no,
15165                 (void *)&cmd_vf_tc_bw_bw,
15166                 NULL,
15167         },
15168 };
15169
15170
15171 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15172
15173 /* *** Set Port default Traffic Management Hierarchy *** */
15174 struct cmd_set_port_tm_hierarchy_default_result {
15175         cmdline_fixed_string_t set;
15176         cmdline_fixed_string_t port;
15177         cmdline_fixed_string_t tm;
15178         cmdline_fixed_string_t hierarchy;
15179         cmdline_fixed_string_t def;
15180         portid_t port_id;
15181 };
15182
15183 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15184         TOKEN_STRING_INITIALIZER(
15185                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15186 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15187         TOKEN_STRING_INITIALIZER(
15188                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15189 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15190         TOKEN_STRING_INITIALIZER(
15191                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15192 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15193         TOKEN_STRING_INITIALIZER(
15194                 struct cmd_set_port_tm_hierarchy_default_result,
15195                         hierarchy, "hierarchy");
15196 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15197         TOKEN_STRING_INITIALIZER(
15198                 struct cmd_set_port_tm_hierarchy_default_result,
15199                         def, "default");
15200 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15201         TOKEN_NUM_INITIALIZER(
15202                 struct cmd_set_port_tm_hierarchy_default_result,
15203                         port_id, UINT16);
15204
15205 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15206         __attribute__((unused)) struct cmdline *cl,
15207         __attribute__((unused)) void *data)
15208 {
15209         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15210         struct rte_port *p;
15211         portid_t port_id = res->port_id;
15212
15213         if (port_id_is_invalid(port_id, ENABLED_WARN))
15214                 return;
15215
15216         p = &ports[port_id];
15217
15218         /* Forward mode: tm */
15219         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15220                 printf("  softnicfwd mode not enabled(error)\n");
15221                 return;
15222         }
15223
15224         /* Set the default tm hierarchy */
15225         p->softport.default_tm_hierarchy_enable = 1;
15226 }
15227
15228 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15229         .f = cmd_set_port_tm_hierarchy_default_parsed,
15230         .data = NULL,
15231         .help_str = "set port tm hierarchy default <port_id>",
15232         .tokens = {
15233                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15234                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15235                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15236                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15237                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15238                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15239                 NULL,
15240         },
15241 };
15242 #endif
15243
15244 /** Set VXLAN encapsulation details */
15245 struct cmd_set_vxlan_result {
15246         cmdline_fixed_string_t set;
15247         cmdline_fixed_string_t vxlan;
15248         cmdline_fixed_string_t pos_token;
15249         cmdline_fixed_string_t ip_version;
15250         uint32_t vlan_present:1;
15251         uint32_t vni;
15252         uint16_t udp_src;
15253         uint16_t udp_dst;
15254         cmdline_ipaddr_t ip_src;
15255         cmdline_ipaddr_t ip_dst;
15256         uint16_t tci;
15257         uint8_t tos;
15258         uint8_t ttl;
15259         struct rte_ether_addr eth_src;
15260         struct rte_ether_addr eth_dst;
15261 };
15262
15263 cmdline_parse_token_string_t cmd_set_vxlan_set =
15264         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15265 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15266         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15267 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15268         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15269                                  "vxlan-tos-ttl");
15270 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15271         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15272                                  "vxlan-with-vlan");
15273 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15274         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15275                                  "ip-version");
15276 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15277         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15278                                  "ipv4#ipv6");
15279 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15280         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15281                                  "vni");
15282 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15283         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15284 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15285         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15286                                  "udp-src");
15287 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15288         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15289 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15290         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15291                                  "udp-dst");
15292 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15293         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15294 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15295         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15296                                  "ip-tos");
15297 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15298         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15299 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15300         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15301                                  "ip-ttl");
15302 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15303         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15304 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15305         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15306                                  "ip-src");
15307 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15308         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15309 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15310         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15311                                  "ip-dst");
15312 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15313         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15314 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15315         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15316                                  "vlan-tci");
15317 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15318         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15319 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15320         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15321                                  "eth-src");
15322 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15323         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15324 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15325         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15326                                  "eth-dst");
15327 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15328         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15329
15330 static void cmd_set_vxlan_parsed(void *parsed_result,
15331         __attribute__((unused)) struct cmdline *cl,
15332         __attribute__((unused)) void *data)
15333 {
15334         struct cmd_set_vxlan_result *res = parsed_result;
15335         union {
15336                 uint32_t vxlan_id;
15337                 uint8_t vni[4];
15338         } id = {
15339                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15340         };
15341
15342         vxlan_encap_conf.select_tos_ttl = 0;
15343         if (strcmp(res->vxlan, "vxlan") == 0)
15344                 vxlan_encap_conf.select_vlan = 0;
15345         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15346                 vxlan_encap_conf.select_vlan = 1;
15347         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15348                 vxlan_encap_conf.select_vlan = 0;
15349                 vxlan_encap_conf.select_tos_ttl = 1;
15350         }
15351         if (strcmp(res->ip_version, "ipv4") == 0)
15352                 vxlan_encap_conf.select_ipv4 = 1;
15353         else if (strcmp(res->ip_version, "ipv6") == 0)
15354                 vxlan_encap_conf.select_ipv4 = 0;
15355         else
15356                 return;
15357         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15358         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15359         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15360         vxlan_encap_conf.ip_tos = res->tos;
15361         vxlan_encap_conf.ip_ttl = res->ttl;
15362         if (vxlan_encap_conf.select_ipv4) {
15363                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15364                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15365         } else {
15366                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15367                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15368         }
15369         if (vxlan_encap_conf.select_vlan)
15370                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15371         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15372                    RTE_ETHER_ADDR_LEN);
15373         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15374                    RTE_ETHER_ADDR_LEN);
15375 }
15376
15377 cmdline_parse_inst_t cmd_set_vxlan = {
15378         .f = cmd_set_vxlan_parsed,
15379         .data = NULL,
15380         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15381                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15382                 " eth-src <eth-src> eth-dst <eth-dst>",
15383         .tokens = {
15384                 (void *)&cmd_set_vxlan_set,
15385                 (void *)&cmd_set_vxlan_vxlan,
15386                 (void *)&cmd_set_vxlan_ip_version,
15387                 (void *)&cmd_set_vxlan_ip_version_value,
15388                 (void *)&cmd_set_vxlan_vni,
15389                 (void *)&cmd_set_vxlan_vni_value,
15390                 (void *)&cmd_set_vxlan_udp_src,
15391                 (void *)&cmd_set_vxlan_udp_src_value,
15392                 (void *)&cmd_set_vxlan_udp_dst,
15393                 (void *)&cmd_set_vxlan_udp_dst_value,
15394                 (void *)&cmd_set_vxlan_ip_src,
15395                 (void *)&cmd_set_vxlan_ip_src_value,
15396                 (void *)&cmd_set_vxlan_ip_dst,
15397                 (void *)&cmd_set_vxlan_ip_dst_value,
15398                 (void *)&cmd_set_vxlan_eth_src,
15399                 (void *)&cmd_set_vxlan_eth_src_value,
15400                 (void *)&cmd_set_vxlan_eth_dst,
15401                 (void *)&cmd_set_vxlan_eth_dst_value,
15402                 NULL,
15403         },
15404 };
15405
15406 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15407         .f = cmd_set_vxlan_parsed,
15408         .data = NULL,
15409         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15410                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15411                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15412                 " eth-dst <eth-dst>",
15413         .tokens = {
15414                 (void *)&cmd_set_vxlan_set,
15415                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15416                 (void *)&cmd_set_vxlan_ip_version,
15417                 (void *)&cmd_set_vxlan_ip_version_value,
15418                 (void *)&cmd_set_vxlan_vni,
15419                 (void *)&cmd_set_vxlan_vni_value,
15420                 (void *)&cmd_set_vxlan_udp_src,
15421                 (void *)&cmd_set_vxlan_udp_src_value,
15422                 (void *)&cmd_set_vxlan_udp_dst,
15423                 (void *)&cmd_set_vxlan_udp_dst_value,
15424                 (void *)&cmd_set_vxlan_ip_tos,
15425                 (void *)&cmd_set_vxlan_ip_tos_value,
15426                 (void *)&cmd_set_vxlan_ip_ttl,
15427                 (void *)&cmd_set_vxlan_ip_ttl_value,
15428                 (void *)&cmd_set_vxlan_ip_src,
15429                 (void *)&cmd_set_vxlan_ip_src_value,
15430                 (void *)&cmd_set_vxlan_ip_dst,
15431                 (void *)&cmd_set_vxlan_ip_dst_value,
15432                 (void *)&cmd_set_vxlan_eth_src,
15433                 (void *)&cmd_set_vxlan_eth_src_value,
15434                 (void *)&cmd_set_vxlan_eth_dst,
15435                 (void *)&cmd_set_vxlan_eth_dst_value,
15436                 NULL,
15437         },
15438 };
15439
15440 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15441         .f = cmd_set_vxlan_parsed,
15442         .data = NULL,
15443         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15444                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15445                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15446                 " <eth-dst>",
15447         .tokens = {
15448                 (void *)&cmd_set_vxlan_set,
15449                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15450                 (void *)&cmd_set_vxlan_ip_version,
15451                 (void *)&cmd_set_vxlan_ip_version_value,
15452                 (void *)&cmd_set_vxlan_vni,
15453                 (void *)&cmd_set_vxlan_vni_value,
15454                 (void *)&cmd_set_vxlan_udp_src,
15455                 (void *)&cmd_set_vxlan_udp_src_value,
15456                 (void *)&cmd_set_vxlan_udp_dst,
15457                 (void *)&cmd_set_vxlan_udp_dst_value,
15458                 (void *)&cmd_set_vxlan_ip_src,
15459                 (void *)&cmd_set_vxlan_ip_src_value,
15460                 (void *)&cmd_set_vxlan_ip_dst,
15461                 (void *)&cmd_set_vxlan_ip_dst_value,
15462                 (void *)&cmd_set_vxlan_vlan,
15463                 (void *)&cmd_set_vxlan_vlan_value,
15464                 (void *)&cmd_set_vxlan_eth_src,
15465                 (void *)&cmd_set_vxlan_eth_src_value,
15466                 (void *)&cmd_set_vxlan_eth_dst,
15467                 (void *)&cmd_set_vxlan_eth_dst_value,
15468                 NULL,
15469         },
15470 };
15471
15472 /** Set NVGRE encapsulation details */
15473 struct cmd_set_nvgre_result {
15474         cmdline_fixed_string_t set;
15475         cmdline_fixed_string_t nvgre;
15476         cmdline_fixed_string_t pos_token;
15477         cmdline_fixed_string_t ip_version;
15478         uint32_t tni;
15479         cmdline_ipaddr_t ip_src;
15480         cmdline_ipaddr_t ip_dst;
15481         uint16_t tci;
15482         struct rte_ether_addr eth_src;
15483         struct rte_ether_addr eth_dst;
15484 };
15485
15486 cmdline_parse_token_string_t cmd_set_nvgre_set =
15487         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15488 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15489         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15490 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15491         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15492                                  "nvgre-with-vlan");
15493 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15494         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15495                                  "ip-version");
15496 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15497         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15498                                  "ipv4#ipv6");
15499 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15500         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15501                                  "tni");
15502 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15503         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15504 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15505         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15506                                  "ip-src");
15507 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15508         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15509 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15510         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15511                                  "ip-dst");
15512 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15513         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15514 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15515         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15516                                  "vlan-tci");
15517 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15518         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15519 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15520         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15521                                  "eth-src");
15522 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15523         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15524 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15525         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15526                                  "eth-dst");
15527 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15528         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15529
15530 static void cmd_set_nvgre_parsed(void *parsed_result,
15531         __attribute__((unused)) struct cmdline *cl,
15532         __attribute__((unused)) void *data)
15533 {
15534         struct cmd_set_nvgre_result *res = parsed_result;
15535         union {
15536                 uint32_t nvgre_tni;
15537                 uint8_t tni[4];
15538         } id = {
15539                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15540         };
15541
15542         if (strcmp(res->nvgre, "nvgre") == 0)
15543                 nvgre_encap_conf.select_vlan = 0;
15544         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15545                 nvgre_encap_conf.select_vlan = 1;
15546         if (strcmp(res->ip_version, "ipv4") == 0)
15547                 nvgre_encap_conf.select_ipv4 = 1;
15548         else if (strcmp(res->ip_version, "ipv6") == 0)
15549                 nvgre_encap_conf.select_ipv4 = 0;
15550         else
15551                 return;
15552         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15553         if (nvgre_encap_conf.select_ipv4) {
15554                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15555                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15556         } else {
15557                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15558                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15559         }
15560         if (nvgre_encap_conf.select_vlan)
15561                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15562         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15563                    RTE_ETHER_ADDR_LEN);
15564         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15565                    RTE_ETHER_ADDR_LEN);
15566 }
15567
15568 cmdline_parse_inst_t cmd_set_nvgre = {
15569         .f = cmd_set_nvgre_parsed,
15570         .data = NULL,
15571         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15572                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15573                 " eth-dst <eth-dst>",
15574         .tokens = {
15575                 (void *)&cmd_set_nvgre_set,
15576                 (void *)&cmd_set_nvgre_nvgre,
15577                 (void *)&cmd_set_nvgre_ip_version,
15578                 (void *)&cmd_set_nvgre_ip_version_value,
15579                 (void *)&cmd_set_nvgre_tni,
15580                 (void *)&cmd_set_nvgre_tni_value,
15581                 (void *)&cmd_set_nvgre_ip_src,
15582                 (void *)&cmd_set_nvgre_ip_src_value,
15583                 (void *)&cmd_set_nvgre_ip_dst,
15584                 (void *)&cmd_set_nvgre_ip_dst_value,
15585                 (void *)&cmd_set_nvgre_eth_src,
15586                 (void *)&cmd_set_nvgre_eth_src_value,
15587                 (void *)&cmd_set_nvgre_eth_dst,
15588                 (void *)&cmd_set_nvgre_eth_dst_value,
15589                 NULL,
15590         },
15591 };
15592
15593 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15594         .f = cmd_set_nvgre_parsed,
15595         .data = NULL,
15596         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15597                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15598                 " eth-src <eth-src> eth-dst <eth-dst>",
15599         .tokens = {
15600                 (void *)&cmd_set_nvgre_set,
15601                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15602                 (void *)&cmd_set_nvgre_ip_version,
15603                 (void *)&cmd_set_nvgre_ip_version_value,
15604                 (void *)&cmd_set_nvgre_tni,
15605                 (void *)&cmd_set_nvgre_tni_value,
15606                 (void *)&cmd_set_nvgre_ip_src,
15607                 (void *)&cmd_set_nvgre_ip_src_value,
15608                 (void *)&cmd_set_nvgre_ip_dst,
15609                 (void *)&cmd_set_nvgre_ip_dst_value,
15610                 (void *)&cmd_set_nvgre_vlan,
15611                 (void *)&cmd_set_nvgre_vlan_value,
15612                 (void *)&cmd_set_nvgre_eth_src,
15613                 (void *)&cmd_set_nvgre_eth_src_value,
15614                 (void *)&cmd_set_nvgre_eth_dst,
15615                 (void *)&cmd_set_nvgre_eth_dst_value,
15616                 NULL,
15617         },
15618 };
15619
15620 /** Set L2 encapsulation details */
15621 struct cmd_set_l2_encap_result {
15622         cmdline_fixed_string_t set;
15623         cmdline_fixed_string_t l2_encap;
15624         cmdline_fixed_string_t pos_token;
15625         cmdline_fixed_string_t ip_version;
15626         uint32_t vlan_present:1;
15627         uint16_t tci;
15628         struct rte_ether_addr eth_src;
15629         struct rte_ether_addr eth_dst;
15630 };
15631
15632 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15633         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15634 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15635         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15636 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15637         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15638                                  "l2_encap-with-vlan");
15639 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15640         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15641                                  "ip-version");
15642 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15643         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15644                                  "ipv4#ipv6");
15645 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15646         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15647                                  "vlan-tci");
15648 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15649         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15650 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15651         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15652                                  "eth-src");
15653 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15654         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15655 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15656         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15657                                  "eth-dst");
15658 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15659         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15660
15661 static void cmd_set_l2_encap_parsed(void *parsed_result,
15662         __attribute__((unused)) struct cmdline *cl,
15663         __attribute__((unused)) void *data)
15664 {
15665         struct cmd_set_l2_encap_result *res = parsed_result;
15666
15667         if (strcmp(res->l2_encap, "l2_encap") == 0)
15668                 l2_encap_conf.select_vlan = 0;
15669         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15670                 l2_encap_conf.select_vlan = 1;
15671         if (strcmp(res->ip_version, "ipv4") == 0)
15672                 l2_encap_conf.select_ipv4 = 1;
15673         else if (strcmp(res->ip_version, "ipv6") == 0)
15674                 l2_encap_conf.select_ipv4 = 0;
15675         else
15676                 return;
15677         if (l2_encap_conf.select_vlan)
15678                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15679         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15680                    RTE_ETHER_ADDR_LEN);
15681         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15682                    RTE_ETHER_ADDR_LEN);
15683 }
15684
15685 cmdline_parse_inst_t cmd_set_l2_encap = {
15686         .f = cmd_set_l2_encap_parsed,
15687         .data = NULL,
15688         .help_str = "set l2_encap ip-version ipv4|ipv6"
15689                 " eth-src <eth-src> eth-dst <eth-dst>",
15690         .tokens = {
15691                 (void *)&cmd_set_l2_encap_set,
15692                 (void *)&cmd_set_l2_encap_l2_encap,
15693                 (void *)&cmd_set_l2_encap_ip_version,
15694                 (void *)&cmd_set_l2_encap_ip_version_value,
15695                 (void *)&cmd_set_l2_encap_eth_src,
15696                 (void *)&cmd_set_l2_encap_eth_src_value,
15697                 (void *)&cmd_set_l2_encap_eth_dst,
15698                 (void *)&cmd_set_l2_encap_eth_dst_value,
15699                 NULL,
15700         },
15701 };
15702
15703 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15704         .f = cmd_set_l2_encap_parsed,
15705         .data = NULL,
15706         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15707                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15708         .tokens = {
15709                 (void *)&cmd_set_l2_encap_set,
15710                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15711                 (void *)&cmd_set_l2_encap_ip_version,
15712                 (void *)&cmd_set_l2_encap_ip_version_value,
15713                 (void *)&cmd_set_l2_encap_vlan,
15714                 (void *)&cmd_set_l2_encap_vlan_value,
15715                 (void *)&cmd_set_l2_encap_eth_src,
15716                 (void *)&cmd_set_l2_encap_eth_src_value,
15717                 (void *)&cmd_set_l2_encap_eth_dst,
15718                 (void *)&cmd_set_l2_encap_eth_dst_value,
15719                 NULL,
15720         },
15721 };
15722
15723 /** Set L2 decapsulation details */
15724 struct cmd_set_l2_decap_result {
15725         cmdline_fixed_string_t set;
15726         cmdline_fixed_string_t l2_decap;
15727         cmdline_fixed_string_t pos_token;
15728         uint32_t vlan_present:1;
15729 };
15730
15731 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15732         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15733 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15734         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15735                                  "l2_decap");
15736 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15737         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15738                                  "l2_decap-with-vlan");
15739
15740 static void cmd_set_l2_decap_parsed(void *parsed_result,
15741         __attribute__((unused)) struct cmdline *cl,
15742         __attribute__((unused)) void *data)
15743 {
15744         struct cmd_set_l2_decap_result *res = parsed_result;
15745
15746         if (strcmp(res->l2_decap, "l2_decap") == 0)
15747                 l2_decap_conf.select_vlan = 0;
15748         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15749                 l2_decap_conf.select_vlan = 1;
15750 }
15751
15752 cmdline_parse_inst_t cmd_set_l2_decap = {
15753         .f = cmd_set_l2_decap_parsed,
15754         .data = NULL,
15755         .help_str = "set l2_decap",
15756         .tokens = {
15757                 (void *)&cmd_set_l2_decap_set,
15758                 (void *)&cmd_set_l2_decap_l2_decap,
15759                 NULL,
15760         },
15761 };
15762
15763 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15764         .f = cmd_set_l2_decap_parsed,
15765         .data = NULL,
15766         .help_str = "set l2_decap-with-vlan",
15767         .tokens = {
15768                 (void *)&cmd_set_l2_decap_set,
15769                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15770                 NULL,
15771         },
15772 };
15773
15774 /** Set MPLSoGRE encapsulation details */
15775 struct cmd_set_mplsogre_encap_result {
15776         cmdline_fixed_string_t set;
15777         cmdline_fixed_string_t mplsogre;
15778         cmdline_fixed_string_t pos_token;
15779         cmdline_fixed_string_t ip_version;
15780         uint32_t vlan_present:1;
15781         uint32_t label;
15782         cmdline_ipaddr_t ip_src;
15783         cmdline_ipaddr_t ip_dst;
15784         uint16_t tci;
15785         struct rte_ether_addr eth_src;
15786         struct rte_ether_addr eth_dst;
15787 };
15788
15789 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15790         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15791                                  "set");
15792 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15793         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15794                                  "mplsogre_encap");
15795 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15796         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15797                                  mplsogre, "mplsogre_encap-with-vlan");
15798 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15799         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15800                                  pos_token, "ip-version");
15801 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15802         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15803                                  ip_version, "ipv4#ipv6");
15804 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15805         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15806                                  pos_token, "label");
15807 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15808         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15809                               UINT32);
15810 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15811         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15812                                  pos_token, "ip-src");
15813 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15814         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15815 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15816         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15817                                  pos_token, "ip-dst");
15818 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15819         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15820 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15821         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15822                                  pos_token, "vlan-tci");
15823 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15824         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15825                               UINT16);
15826 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15827         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15828                                  pos_token, "eth-src");
15829 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15830         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15831                                     eth_src);
15832 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15833         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15834                                  pos_token, "eth-dst");
15835 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15836         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15837                                     eth_dst);
15838
15839 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15840         __attribute__((unused)) struct cmdline *cl,
15841         __attribute__((unused)) void *data)
15842 {
15843         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15844         union {
15845                 uint32_t mplsogre_label;
15846                 uint8_t label[4];
15847         } id = {
15848                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15849         };
15850
15851         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15852                 mplsogre_encap_conf.select_vlan = 0;
15853         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15854                 mplsogre_encap_conf.select_vlan = 1;
15855         if (strcmp(res->ip_version, "ipv4") == 0)
15856                 mplsogre_encap_conf.select_ipv4 = 1;
15857         else if (strcmp(res->ip_version, "ipv6") == 0)
15858                 mplsogre_encap_conf.select_ipv4 = 0;
15859         else
15860                 return;
15861         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15862         if (mplsogre_encap_conf.select_ipv4) {
15863                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15864                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15865         } else {
15866                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15867                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15868         }
15869         if (mplsogre_encap_conf.select_vlan)
15870                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15871         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15872                    RTE_ETHER_ADDR_LEN);
15873         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15874                    RTE_ETHER_ADDR_LEN);
15875 }
15876
15877 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15878         .f = cmd_set_mplsogre_encap_parsed,
15879         .data = NULL,
15880         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15881                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15882                 " eth-dst <eth-dst>",
15883         .tokens = {
15884                 (void *)&cmd_set_mplsogre_encap_set,
15885                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15886                 (void *)&cmd_set_mplsogre_encap_ip_version,
15887                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15888                 (void *)&cmd_set_mplsogre_encap_label,
15889                 (void *)&cmd_set_mplsogre_encap_label_value,
15890                 (void *)&cmd_set_mplsogre_encap_ip_src,
15891                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15892                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15893                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15894                 (void *)&cmd_set_mplsogre_encap_eth_src,
15895                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15896                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15897                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15898                 NULL,
15899         },
15900 };
15901
15902 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15903         .f = cmd_set_mplsogre_encap_parsed,
15904         .data = NULL,
15905         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15906                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15907                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15908         .tokens = {
15909                 (void *)&cmd_set_mplsogre_encap_set,
15910                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15911                 (void *)&cmd_set_mplsogre_encap_ip_version,
15912                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15913                 (void *)&cmd_set_mplsogre_encap_label,
15914                 (void *)&cmd_set_mplsogre_encap_label_value,
15915                 (void *)&cmd_set_mplsogre_encap_ip_src,
15916                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15917                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15918                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15919                 (void *)&cmd_set_mplsogre_encap_vlan,
15920                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15921                 (void *)&cmd_set_mplsogre_encap_eth_src,
15922                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15923                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15924                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15925                 NULL,
15926         },
15927 };
15928
15929 /** Set MPLSoGRE decapsulation details */
15930 struct cmd_set_mplsogre_decap_result {
15931         cmdline_fixed_string_t set;
15932         cmdline_fixed_string_t mplsogre;
15933         cmdline_fixed_string_t pos_token;
15934         cmdline_fixed_string_t ip_version;
15935         uint32_t vlan_present:1;
15936 };
15937
15938 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15939         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15940                                  "set");
15941 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15942         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15943                                  "mplsogre_decap");
15944 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15945         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15946                                  mplsogre, "mplsogre_decap-with-vlan");
15947 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15948         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15949                                  pos_token, "ip-version");
15950 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15951         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15952                                  ip_version, "ipv4#ipv6");
15953
15954 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15955         __attribute__((unused)) struct cmdline *cl,
15956         __attribute__((unused)) void *data)
15957 {
15958         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15959
15960         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15961                 mplsogre_decap_conf.select_vlan = 0;
15962         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15963                 mplsogre_decap_conf.select_vlan = 1;
15964         if (strcmp(res->ip_version, "ipv4") == 0)
15965                 mplsogre_decap_conf.select_ipv4 = 1;
15966         else if (strcmp(res->ip_version, "ipv6") == 0)
15967                 mplsogre_decap_conf.select_ipv4 = 0;
15968 }
15969
15970 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15971         .f = cmd_set_mplsogre_decap_parsed,
15972         .data = NULL,
15973         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15974         .tokens = {
15975                 (void *)&cmd_set_mplsogre_decap_set,
15976                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15977                 (void *)&cmd_set_mplsogre_decap_ip_version,
15978                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15979                 NULL,
15980         },
15981 };
15982
15983 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15984         .f = cmd_set_mplsogre_decap_parsed,
15985         .data = NULL,
15986         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15987         .tokens = {
15988                 (void *)&cmd_set_mplsogre_decap_set,
15989                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15990                 (void *)&cmd_set_mplsogre_decap_ip_version,
15991                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15992                 NULL,
15993         },
15994 };
15995
15996 /** Set MPLSoUDP encapsulation details */
15997 struct cmd_set_mplsoudp_encap_result {
15998         cmdline_fixed_string_t set;
15999         cmdline_fixed_string_t mplsoudp;
16000         cmdline_fixed_string_t pos_token;
16001         cmdline_fixed_string_t ip_version;
16002         uint32_t vlan_present:1;
16003         uint32_t label;
16004         uint16_t udp_src;
16005         uint16_t udp_dst;
16006         cmdline_ipaddr_t ip_src;
16007         cmdline_ipaddr_t ip_dst;
16008         uint16_t tci;
16009         struct rte_ether_addr eth_src;
16010         struct rte_ether_addr eth_dst;
16011 };
16012
16013 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16014         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16015                                  "set");
16016 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16017         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16018                                  "mplsoudp_encap");
16019 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16020         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16021                                  mplsoudp, "mplsoudp_encap-with-vlan");
16022 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16023         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16024                                  pos_token, "ip-version");
16025 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16026         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16027                                  ip_version, "ipv4#ipv6");
16028 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16029         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16030                                  pos_token, "label");
16031 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16032         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16033                               UINT32);
16034 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16035         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16036                                  pos_token, "udp-src");
16037 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16038         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16039                               UINT16);
16040 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16041         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16042                                  pos_token, "udp-dst");
16043 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16044         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16045                               UINT16);
16046 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16047         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16048                                  pos_token, "ip-src");
16049 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16050         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16051 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16052         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16053                                  pos_token, "ip-dst");
16054 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16055         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16056 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16057         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16058                                  pos_token, "vlan-tci");
16059 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16060         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16061                               UINT16);
16062 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16063         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16064                                  pos_token, "eth-src");
16065 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16066         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16067                                     eth_src);
16068 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16069         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16070                                  pos_token, "eth-dst");
16071 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16072         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16073                                     eth_dst);
16074
16075 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16076         __attribute__((unused)) struct cmdline *cl,
16077         __attribute__((unused)) void *data)
16078 {
16079         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16080         union {
16081                 uint32_t mplsoudp_label;
16082                 uint8_t label[4];
16083         } id = {
16084                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16085         };
16086
16087         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16088                 mplsoudp_encap_conf.select_vlan = 0;
16089         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16090                 mplsoudp_encap_conf.select_vlan = 1;
16091         if (strcmp(res->ip_version, "ipv4") == 0)
16092                 mplsoudp_encap_conf.select_ipv4 = 1;
16093         else if (strcmp(res->ip_version, "ipv6") == 0)
16094                 mplsoudp_encap_conf.select_ipv4 = 0;
16095         else
16096                 return;
16097         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16098         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16099         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16100         if (mplsoudp_encap_conf.select_ipv4) {
16101                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16102                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16103         } else {
16104                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16105                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16106         }
16107         if (mplsoudp_encap_conf.select_vlan)
16108                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16109         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16110                    RTE_ETHER_ADDR_LEN);
16111         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16112                    RTE_ETHER_ADDR_LEN);
16113 }
16114
16115 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16116         .f = cmd_set_mplsoudp_encap_parsed,
16117         .data = NULL,
16118         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16119                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16120                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16121         .tokens = {
16122                 (void *)&cmd_set_mplsoudp_encap_set,
16123                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16124                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16125                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16126                 (void *)&cmd_set_mplsoudp_encap_label,
16127                 (void *)&cmd_set_mplsoudp_encap_label_value,
16128                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16129                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16130                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16131                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16132                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16133                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16134                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16135                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16136                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16137                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16138                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16139                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16140                 NULL,
16141         },
16142 };
16143
16144 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16145         .f = cmd_set_mplsoudp_encap_parsed,
16146         .data = NULL,
16147         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16148                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16149                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16150                 " eth-src <eth-src> eth-dst <eth-dst>",
16151         .tokens = {
16152                 (void *)&cmd_set_mplsoudp_encap_set,
16153                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16154                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16155                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16156                 (void *)&cmd_set_mplsoudp_encap_label,
16157                 (void *)&cmd_set_mplsoudp_encap_label_value,
16158                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16159                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16160                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16161                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16162                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16163                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16164                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16165                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16166                 (void *)&cmd_set_mplsoudp_encap_vlan,
16167                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16168                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16169                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16170                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16171                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16172                 NULL,
16173         },
16174 };
16175
16176 /** Set MPLSoUDP decapsulation details */
16177 struct cmd_set_mplsoudp_decap_result {
16178         cmdline_fixed_string_t set;
16179         cmdline_fixed_string_t mplsoudp;
16180         cmdline_fixed_string_t pos_token;
16181         cmdline_fixed_string_t ip_version;
16182         uint32_t vlan_present:1;
16183 };
16184
16185 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16186         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16187                                  "set");
16188 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16189         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16190                                  "mplsoudp_decap");
16191 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16192         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16193                                  mplsoudp, "mplsoudp_decap-with-vlan");
16194 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16195         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16196                                  pos_token, "ip-version");
16197 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16198         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16199                                  ip_version, "ipv4#ipv6");
16200
16201 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16202         __attribute__((unused)) struct cmdline *cl,
16203         __attribute__((unused)) void *data)
16204 {
16205         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16206
16207         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16208                 mplsoudp_decap_conf.select_vlan = 0;
16209         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16210                 mplsoudp_decap_conf.select_vlan = 1;
16211         if (strcmp(res->ip_version, "ipv4") == 0)
16212                 mplsoudp_decap_conf.select_ipv4 = 1;
16213         else if (strcmp(res->ip_version, "ipv6") == 0)
16214                 mplsoudp_decap_conf.select_ipv4 = 0;
16215 }
16216
16217 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16218         .f = cmd_set_mplsoudp_decap_parsed,
16219         .data = NULL,
16220         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16221         .tokens = {
16222                 (void *)&cmd_set_mplsoudp_decap_set,
16223                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16224                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16225                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16226                 NULL,
16227         },
16228 };
16229
16230 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16231         .f = cmd_set_mplsoudp_decap_parsed,
16232         .data = NULL,
16233         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16234         .tokens = {
16235                 (void *)&cmd_set_mplsoudp_decap_set,
16236                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16237                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16238                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16239                 NULL,
16240         },
16241 };
16242
16243 /* Strict link priority scheduling mode setting */
16244 static void
16245 cmd_strict_link_prio_parsed(
16246         void *parsed_result,
16247         __attribute__((unused)) struct cmdline *cl,
16248         __attribute__((unused)) void *data)
16249 {
16250         struct cmd_vf_tc_bw_result *res = parsed_result;
16251         int ret = -ENOTSUP;
16252
16253         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16254                 return;
16255
16256 #ifdef RTE_LIBRTE_I40E_PMD
16257         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16258 #endif
16259
16260         switch (ret) {
16261         case 0:
16262                 break;
16263         case -EINVAL:
16264                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16265                 break;
16266         case -ENODEV:
16267                 printf("invalid port_id %d\n", res->port_id);
16268                 break;
16269         case -ENOTSUP:
16270                 printf("function not implemented\n");
16271                 break;
16272         default:
16273                 printf("programming error: (%s)\n", strerror(-ret));
16274         }
16275 }
16276
16277 cmdline_parse_inst_t cmd_strict_link_prio = {
16278         .f = cmd_strict_link_prio_parsed,
16279         .data = NULL,
16280         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16281         .tokens = {
16282                 (void *)&cmd_vf_tc_bw_set,
16283                 (void *)&cmd_vf_tc_bw_tx,
16284                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16285                 (void *)&cmd_vf_tc_bw_port_id,
16286                 (void *)&cmd_vf_tc_bw_tc_map,
16287                 NULL,
16288         },
16289 };
16290
16291 /* Load dynamic device personalization*/
16292 struct cmd_ddp_add_result {
16293         cmdline_fixed_string_t ddp;
16294         cmdline_fixed_string_t add;
16295         portid_t port_id;
16296         char filepath[];
16297 };
16298
16299 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16300         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16301 cmdline_parse_token_string_t cmd_ddp_add_add =
16302         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16303 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16304         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16305 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16306         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16307
16308 static void
16309 cmd_ddp_add_parsed(
16310         void *parsed_result,
16311         __attribute__((unused)) struct cmdline *cl,
16312         __attribute__((unused)) void *data)
16313 {
16314         struct cmd_ddp_add_result *res = parsed_result;
16315         uint8_t *buff;
16316         uint32_t size;
16317         char *filepath;
16318         char *file_fld[2];
16319         int file_num;
16320         int ret = -ENOTSUP;
16321
16322         if (!all_ports_stopped()) {
16323                 printf("Please stop all ports first\n");
16324                 return;
16325         }
16326
16327         filepath = strdup(res->filepath);
16328         if (filepath == NULL) {
16329                 printf("Failed to allocate memory\n");
16330                 return;
16331         }
16332         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16333
16334         buff = open_file(file_fld[0], &size);
16335         if (!buff) {
16336                 free((void *)filepath);
16337                 return;
16338         }
16339
16340 #ifdef RTE_LIBRTE_I40E_PMD
16341         if (ret == -ENOTSUP)
16342                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16343                                                buff, size,
16344                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16345 #endif
16346
16347         if (ret == -EEXIST)
16348                 printf("Profile has already existed.\n");
16349         else if (ret < 0)
16350                 printf("Failed to load profile.\n");
16351         else if (file_num == 2)
16352                 save_file(file_fld[1], buff, size);
16353
16354         close_file(buff);
16355         free((void *)filepath);
16356 }
16357
16358 cmdline_parse_inst_t cmd_ddp_add = {
16359         .f = cmd_ddp_add_parsed,
16360         .data = NULL,
16361         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16362         .tokens = {
16363                 (void *)&cmd_ddp_add_ddp,
16364                 (void *)&cmd_ddp_add_add,
16365                 (void *)&cmd_ddp_add_port_id,
16366                 (void *)&cmd_ddp_add_filepath,
16367                 NULL,
16368         },
16369 };
16370
16371 /* Delete dynamic device personalization*/
16372 struct cmd_ddp_del_result {
16373         cmdline_fixed_string_t ddp;
16374         cmdline_fixed_string_t del;
16375         portid_t port_id;
16376         char filepath[];
16377 };
16378
16379 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16380         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16381 cmdline_parse_token_string_t cmd_ddp_del_del =
16382         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16383 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16384         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16385 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16386         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16387
16388 static void
16389 cmd_ddp_del_parsed(
16390         void *parsed_result,
16391         __attribute__((unused)) struct cmdline *cl,
16392         __attribute__((unused)) void *data)
16393 {
16394         struct cmd_ddp_del_result *res = parsed_result;
16395         uint8_t *buff;
16396         uint32_t size;
16397         int ret = -ENOTSUP;
16398
16399         if (!all_ports_stopped()) {
16400                 printf("Please stop all ports first\n");
16401                 return;
16402         }
16403
16404         buff = open_file(res->filepath, &size);
16405         if (!buff)
16406                 return;
16407
16408 #ifdef RTE_LIBRTE_I40E_PMD
16409         if (ret == -ENOTSUP)
16410                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16411                                                buff, size,
16412                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16413 #endif
16414
16415         if (ret == -EACCES)
16416                 printf("Profile does not exist.\n");
16417         else if (ret < 0)
16418                 printf("Failed to delete profile.\n");
16419
16420         close_file(buff);
16421 }
16422
16423 cmdline_parse_inst_t cmd_ddp_del = {
16424         .f = cmd_ddp_del_parsed,
16425         .data = NULL,
16426         .help_str = "ddp del <port_id> <backup_profile_path>",
16427         .tokens = {
16428                 (void *)&cmd_ddp_del_ddp,
16429                 (void *)&cmd_ddp_del_del,
16430                 (void *)&cmd_ddp_del_port_id,
16431                 (void *)&cmd_ddp_del_filepath,
16432                 NULL,
16433         },
16434 };
16435
16436 /* Get dynamic device personalization profile info */
16437 struct cmd_ddp_info_result {
16438         cmdline_fixed_string_t ddp;
16439         cmdline_fixed_string_t get;
16440         cmdline_fixed_string_t info;
16441         char filepath[];
16442 };
16443
16444 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16445         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16446 cmdline_parse_token_string_t cmd_ddp_info_get =
16447         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16448 cmdline_parse_token_string_t cmd_ddp_info_info =
16449         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16450 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16451         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16452
16453 static void
16454 cmd_ddp_info_parsed(
16455         void *parsed_result,
16456         __attribute__((unused)) struct cmdline *cl,
16457         __attribute__((unused)) void *data)
16458 {
16459         struct cmd_ddp_info_result *res = parsed_result;
16460         uint8_t *pkg;
16461         uint32_t pkg_size;
16462         int ret = -ENOTSUP;
16463 #ifdef RTE_LIBRTE_I40E_PMD
16464         uint32_t i, j, n;
16465         uint8_t *buff;
16466         uint32_t buff_size = 0;
16467         struct rte_pmd_i40e_profile_info info;
16468         uint32_t dev_num = 0;
16469         struct rte_pmd_i40e_ddp_device_id *devs;
16470         uint32_t proto_num = 0;
16471         struct rte_pmd_i40e_proto_info *proto = NULL;
16472         uint32_t pctype_num = 0;
16473         struct rte_pmd_i40e_ptype_info *pctype;
16474         uint32_t ptype_num = 0;
16475         struct rte_pmd_i40e_ptype_info *ptype;
16476         uint8_t proto_id;
16477
16478 #endif
16479
16480         pkg = open_file(res->filepath, &pkg_size);
16481         if (!pkg)
16482                 return;
16483
16484 #ifdef RTE_LIBRTE_I40E_PMD
16485         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16486                                 (uint8_t *)&info, sizeof(info),
16487                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16488         if (!ret) {
16489                 printf("Global Track id:       0x%x\n", info.track_id);
16490                 printf("Global Version:        %d.%d.%d.%d\n",
16491                         info.version.major,
16492                         info.version.minor,
16493                         info.version.update,
16494                         info.version.draft);
16495                 printf("Global Package name:   %s\n\n", info.name);
16496         }
16497
16498         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16499                                 (uint8_t *)&info, sizeof(info),
16500                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16501         if (!ret) {
16502                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16503                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16504                         info.version.major,
16505                         info.version.minor,
16506                         info.version.update,
16507                         info.version.draft);
16508                 printf("i40e Profile name:     %s\n\n", info.name);
16509         }
16510
16511         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16512                                 (uint8_t *)&buff_size, sizeof(buff_size),
16513                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16514         if (!ret && buff_size) {
16515                 buff = (uint8_t *)malloc(buff_size);
16516                 if (buff) {
16517                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16518                                                 buff, buff_size,
16519                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16520                         if (!ret)
16521                                 printf("Package Notes:\n%s\n\n", buff);
16522                         free(buff);
16523                 }
16524         }
16525
16526         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16527                                 (uint8_t *)&dev_num, sizeof(dev_num),
16528                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16529         if (!ret && dev_num) {
16530                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16531                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16532                 if (devs) {
16533                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16534                                                 (uint8_t *)devs, buff_size,
16535                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16536                         if (!ret) {
16537                                 printf("List of supported devices:\n");
16538                                 for (i = 0; i < dev_num; i++) {
16539                                         printf("  %04X:%04X %04X:%04X\n",
16540                                                 devs[i].vendor_dev_id >> 16,
16541                                                 devs[i].vendor_dev_id & 0xFFFF,
16542                                                 devs[i].sub_vendor_dev_id >> 16,
16543                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16544                                 }
16545                                 printf("\n");
16546                         }
16547                         free(devs);
16548                 }
16549         }
16550
16551         /* get information about protocols and packet types */
16552         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16553                 (uint8_t *)&proto_num, sizeof(proto_num),
16554                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16555         if (ret || !proto_num)
16556                 goto no_print_return;
16557
16558         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16559         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16560         if (!proto)
16561                 goto no_print_return;
16562
16563         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16564                                         buff_size,
16565                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16566         if (!ret) {
16567                 printf("List of used protocols:\n");
16568                 for (i = 0; i < proto_num; i++)
16569                         printf("  %2u: %s\n", proto[i].proto_id,
16570                                proto[i].name);
16571                 printf("\n");
16572         }
16573         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16574                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16575                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16576         if (ret || !pctype_num)
16577                 goto no_print_pctypes;
16578
16579         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16580         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16581         if (!pctype)
16582                 goto no_print_pctypes;
16583
16584         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16585                                         buff_size,
16586                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16587         if (ret) {
16588                 free(pctype);
16589                 goto no_print_pctypes;
16590         }
16591
16592         printf("List of defined packet classification types:\n");
16593         for (i = 0; i < pctype_num; i++) {
16594                 printf("  %2u:", pctype[i].ptype_id);
16595                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16596                         proto_id = pctype[i].protocols[j];
16597                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16598                                 for (n = 0; n < proto_num; n++) {
16599                                         if (proto[n].proto_id == proto_id) {
16600                                                 printf(" %s", proto[n].name);
16601                                                 break;
16602                                         }
16603                                 }
16604                         }
16605                 }
16606                 printf("\n");
16607         }
16608         printf("\n");
16609         free(pctype);
16610
16611 no_print_pctypes:
16612
16613         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16614                                         sizeof(ptype_num),
16615                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16616         if (ret || !ptype_num)
16617                 goto no_print_return;
16618
16619         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16620         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16621         if (!ptype)
16622                 goto no_print_return;
16623
16624         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16625                                         buff_size,
16626                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16627         if (ret) {
16628                 free(ptype);
16629                 goto no_print_return;
16630         }
16631         printf("List of defined packet types:\n");
16632         for (i = 0; i < ptype_num; i++) {
16633                 printf("  %2u:", ptype[i].ptype_id);
16634                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16635                         proto_id = ptype[i].protocols[j];
16636                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16637                                 for (n = 0; n < proto_num; n++) {
16638                                         if (proto[n].proto_id == proto_id) {
16639                                                 printf(" %s", proto[n].name);
16640                                                 break;
16641                                         }
16642                                 }
16643                         }
16644                 }
16645                 printf("\n");
16646         }
16647         free(ptype);
16648         printf("\n");
16649
16650         ret = 0;
16651 no_print_return:
16652         if (proto)
16653                 free(proto);
16654 #endif
16655         if (ret == -ENOTSUP)
16656                 printf("Function not supported in PMD driver\n");
16657         close_file(pkg);
16658 }
16659
16660 cmdline_parse_inst_t cmd_ddp_get_info = {
16661         .f = cmd_ddp_info_parsed,
16662         .data = NULL,
16663         .help_str = "ddp get info <profile_path>",
16664         .tokens = {
16665                 (void *)&cmd_ddp_info_ddp,
16666                 (void *)&cmd_ddp_info_get,
16667                 (void *)&cmd_ddp_info_info,
16668                 (void *)&cmd_ddp_info_filepath,
16669                 NULL,
16670         },
16671 };
16672
16673 /* Get dynamic device personalization profile info list*/
16674 #define PROFILE_INFO_SIZE 48
16675 #define MAX_PROFILE_NUM 16
16676
16677 struct cmd_ddp_get_list_result {
16678         cmdline_fixed_string_t ddp;
16679         cmdline_fixed_string_t get;
16680         cmdline_fixed_string_t list;
16681         portid_t port_id;
16682 };
16683
16684 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16685         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16686 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16687         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16688 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16689         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16690 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16691         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16692
16693 static void
16694 cmd_ddp_get_list_parsed(
16695         __attribute__((unused)) void *parsed_result,
16696         __attribute__((unused)) struct cmdline *cl,
16697         __attribute__((unused)) void *data)
16698 {
16699 #ifdef RTE_LIBRTE_I40E_PMD
16700         struct cmd_ddp_get_list_result *res = parsed_result;
16701         struct rte_pmd_i40e_profile_list *p_list;
16702         struct rte_pmd_i40e_profile_info *p_info;
16703         uint32_t p_num;
16704         uint32_t size;
16705         uint32_t i;
16706 #endif
16707         int ret = -ENOTSUP;
16708
16709 #ifdef RTE_LIBRTE_I40E_PMD
16710         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16711         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16712         if (!p_list)
16713                 printf("%s: Failed to malloc buffer\n", __func__);
16714
16715         if (ret == -ENOTSUP)
16716                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16717                                                 (uint8_t *)p_list, size);
16718
16719         if (!ret) {
16720                 p_num = p_list->p_count;
16721                 printf("Profile number is: %d\n\n", p_num);
16722
16723                 for (i = 0; i < p_num; i++) {
16724                         p_info = &p_list->p_info[i];
16725                         printf("Profile %d:\n", i);
16726                         printf("Track id:     0x%x\n", p_info->track_id);
16727                         printf("Version:      %d.%d.%d.%d\n",
16728                                p_info->version.major,
16729                                p_info->version.minor,
16730                                p_info->version.update,
16731                                p_info->version.draft);
16732                         printf("Profile name: %s\n\n", p_info->name);
16733                 }
16734         }
16735
16736         free(p_list);
16737 #endif
16738
16739         if (ret < 0)
16740                 printf("Failed to get ddp list\n");
16741 }
16742
16743 cmdline_parse_inst_t cmd_ddp_get_list = {
16744         .f = cmd_ddp_get_list_parsed,
16745         .data = NULL,
16746         .help_str = "ddp get list <port_id>",
16747         .tokens = {
16748                 (void *)&cmd_ddp_get_list_ddp,
16749                 (void *)&cmd_ddp_get_list_get,
16750                 (void *)&cmd_ddp_get_list_list,
16751                 (void *)&cmd_ddp_get_list_port_id,
16752                 NULL,
16753         },
16754 };
16755
16756 /* Configure input set */
16757 struct cmd_cfg_input_set_result {
16758         cmdline_fixed_string_t port;
16759         cmdline_fixed_string_t cfg;
16760         portid_t port_id;
16761         cmdline_fixed_string_t pctype;
16762         uint8_t pctype_id;
16763         cmdline_fixed_string_t inset_type;
16764         cmdline_fixed_string_t opt;
16765         cmdline_fixed_string_t field;
16766         uint8_t field_idx;
16767 };
16768
16769 static void
16770 cmd_cfg_input_set_parsed(
16771         __attribute__((unused)) void *parsed_result,
16772         __attribute__((unused)) struct cmdline *cl,
16773         __attribute__((unused)) void *data)
16774 {
16775 #ifdef RTE_LIBRTE_I40E_PMD
16776         struct cmd_cfg_input_set_result *res = parsed_result;
16777         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16778         struct rte_pmd_i40e_inset inset;
16779 #endif
16780         int ret = -ENOTSUP;
16781
16782         if (!all_ports_stopped()) {
16783                 printf("Please stop all ports first\n");
16784                 return;
16785         }
16786
16787 #ifdef RTE_LIBRTE_I40E_PMD
16788         if (!strcmp(res->inset_type, "hash_inset"))
16789                 inset_type = INSET_HASH;
16790         else if (!strcmp(res->inset_type, "fdir_inset"))
16791                 inset_type = INSET_FDIR;
16792         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16793                 inset_type = INSET_FDIR_FLX;
16794         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16795                                      &inset, inset_type);
16796         if (ret) {
16797                 printf("Failed to get input set.\n");
16798                 return;
16799         }
16800
16801         if (!strcmp(res->opt, "get")) {
16802                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16803                                                    res->field_idx);
16804                 if (ret)
16805                         printf("Field index %d is enabled.\n", res->field_idx);
16806                 else
16807                         printf("Field index %d is disabled.\n", res->field_idx);
16808                 return;
16809         } else if (!strcmp(res->opt, "set"))
16810                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16811                                                    res->field_idx);
16812         else if (!strcmp(res->opt, "clear"))
16813                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16814                                                      res->field_idx);
16815         if (ret) {
16816                 printf("Failed to configure input set field.\n");
16817                 return;
16818         }
16819
16820         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16821                                      &inset, inset_type);
16822         if (ret) {
16823                 printf("Failed to set input set.\n");
16824                 return;
16825         }
16826 #endif
16827
16828         if (ret == -ENOTSUP)
16829                 printf("Function not supported\n");
16830 }
16831
16832 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16833         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16834                                  port, "port");
16835 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16836         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16837                                  cfg, "config");
16838 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16839         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16840                               port_id, UINT16);
16841 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16842         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16843                                  pctype, "pctype");
16844 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16845         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16846                               pctype_id, UINT8);
16847 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16848         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16849                                  inset_type,
16850                                  "hash_inset#fdir_inset#fdir_flx_inset");
16851 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16852         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16853                                  opt, "get#set#clear");
16854 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16855         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16856                                  field, "field");
16857 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16858         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16859                               field_idx, UINT8);
16860
16861 cmdline_parse_inst_t cmd_cfg_input_set = {
16862         .f = cmd_cfg_input_set_parsed,
16863         .data = NULL,
16864         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16865                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16866         .tokens = {
16867                 (void *)&cmd_cfg_input_set_port,
16868                 (void *)&cmd_cfg_input_set_cfg,
16869                 (void *)&cmd_cfg_input_set_port_id,
16870                 (void *)&cmd_cfg_input_set_pctype,
16871                 (void *)&cmd_cfg_input_set_pctype_id,
16872                 (void *)&cmd_cfg_input_set_inset_type,
16873                 (void *)&cmd_cfg_input_set_opt,
16874                 (void *)&cmd_cfg_input_set_field,
16875                 (void *)&cmd_cfg_input_set_field_idx,
16876                 NULL,
16877         },
16878 };
16879
16880 /* Clear input set */
16881 struct cmd_clear_input_set_result {
16882         cmdline_fixed_string_t port;
16883         cmdline_fixed_string_t cfg;
16884         portid_t port_id;
16885         cmdline_fixed_string_t pctype;
16886         uint8_t pctype_id;
16887         cmdline_fixed_string_t inset_type;
16888         cmdline_fixed_string_t clear;
16889         cmdline_fixed_string_t all;
16890 };
16891
16892 static void
16893 cmd_clear_input_set_parsed(
16894         __attribute__((unused)) void *parsed_result,
16895         __attribute__((unused)) struct cmdline *cl,
16896         __attribute__((unused)) void *data)
16897 {
16898 #ifdef RTE_LIBRTE_I40E_PMD
16899         struct cmd_clear_input_set_result *res = parsed_result;
16900         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16901         struct rte_pmd_i40e_inset inset;
16902 #endif
16903         int ret = -ENOTSUP;
16904
16905         if (!all_ports_stopped()) {
16906                 printf("Please stop all ports first\n");
16907                 return;
16908         }
16909
16910 #ifdef RTE_LIBRTE_I40E_PMD
16911         if (!strcmp(res->inset_type, "hash_inset"))
16912                 inset_type = INSET_HASH;
16913         else if (!strcmp(res->inset_type, "fdir_inset"))
16914                 inset_type = INSET_FDIR;
16915         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16916                 inset_type = INSET_FDIR_FLX;
16917
16918         memset(&inset, 0, sizeof(inset));
16919
16920         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16921                                      &inset, inset_type);
16922         if (ret) {
16923                 printf("Failed to clear input set.\n");
16924                 return;
16925         }
16926
16927 #endif
16928
16929         if (ret == -ENOTSUP)
16930                 printf("Function not supported\n");
16931 }
16932
16933 cmdline_parse_token_string_t cmd_clear_input_set_port =
16934         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16935                                  port, "port");
16936 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16937         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16938                                  cfg, "config");
16939 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16940         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16941                               port_id, UINT16);
16942 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16943         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16944                                  pctype, "pctype");
16945 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16946         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16947                               pctype_id, UINT8);
16948 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16949         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16950                                  inset_type,
16951                                  "hash_inset#fdir_inset#fdir_flx_inset");
16952 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16953         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16954                                  clear, "clear");
16955 cmdline_parse_token_string_t cmd_clear_input_set_all =
16956         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16957                                  all, "all");
16958
16959 cmdline_parse_inst_t cmd_clear_input_set = {
16960         .f = cmd_clear_input_set_parsed,
16961         .data = NULL,
16962         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16963                     "fdir_inset|fdir_flx_inset clear all",
16964         .tokens = {
16965                 (void *)&cmd_clear_input_set_port,
16966                 (void *)&cmd_clear_input_set_cfg,
16967                 (void *)&cmd_clear_input_set_port_id,
16968                 (void *)&cmd_clear_input_set_pctype,
16969                 (void *)&cmd_clear_input_set_pctype_id,
16970                 (void *)&cmd_clear_input_set_inset_type,
16971                 (void *)&cmd_clear_input_set_clear,
16972                 (void *)&cmd_clear_input_set_all,
16973                 NULL,
16974         },
16975 };
16976
16977 /* show vf stats */
16978
16979 /* Common result structure for show vf stats */
16980 struct cmd_show_vf_stats_result {
16981         cmdline_fixed_string_t show;
16982         cmdline_fixed_string_t vf;
16983         cmdline_fixed_string_t stats;
16984         portid_t port_id;
16985         uint16_t vf_id;
16986 };
16987
16988 /* Common CLI fields show vf stats*/
16989 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16990         TOKEN_STRING_INITIALIZER
16991                 (struct cmd_show_vf_stats_result,
16992                  show, "show");
16993 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16994         TOKEN_STRING_INITIALIZER
16995                 (struct cmd_show_vf_stats_result,
16996                  vf, "vf");
16997 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16998         TOKEN_STRING_INITIALIZER
16999                 (struct cmd_show_vf_stats_result,
17000                  stats, "stats");
17001 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17002         TOKEN_NUM_INITIALIZER
17003                 (struct cmd_show_vf_stats_result,
17004                  port_id, UINT16);
17005 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17006         TOKEN_NUM_INITIALIZER
17007                 (struct cmd_show_vf_stats_result,
17008                  vf_id, UINT16);
17009
17010 static void
17011 cmd_show_vf_stats_parsed(
17012         void *parsed_result,
17013         __attribute__((unused)) struct cmdline *cl,
17014         __attribute__((unused)) void *data)
17015 {
17016         struct cmd_show_vf_stats_result *res = parsed_result;
17017         struct rte_eth_stats stats;
17018         int ret = -ENOTSUP;
17019         static const char *nic_stats_border = "########################";
17020
17021         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17022                 return;
17023
17024         memset(&stats, 0, sizeof(stats));
17025
17026 #ifdef RTE_LIBRTE_I40E_PMD
17027         if (ret == -ENOTSUP)
17028                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17029                                                 res->vf_id,
17030                                                 &stats);
17031 #endif
17032 #ifdef RTE_LIBRTE_BNXT_PMD
17033         if (ret == -ENOTSUP)
17034                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17035                                                 res->vf_id,
17036                                                 &stats);
17037 #endif
17038
17039         switch (ret) {
17040         case 0:
17041                 break;
17042         case -EINVAL:
17043                 printf("invalid vf_id %d\n", res->vf_id);
17044                 break;
17045         case -ENODEV:
17046                 printf("invalid port_id %d\n", res->port_id);
17047                 break;
17048         case -ENOTSUP:
17049                 printf("function not implemented\n");
17050                 break;
17051         default:
17052                 printf("programming error: (%s)\n", strerror(-ret));
17053         }
17054
17055         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17056                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17057
17058         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17059                "%-"PRIu64"\n",
17060                stats.ipackets, stats.imissed, stats.ibytes);
17061         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17062         printf("  RX-nombuf:  %-10"PRIu64"\n",
17063                stats.rx_nombuf);
17064         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17065                "%-"PRIu64"\n",
17066                stats.opackets, stats.oerrors, stats.obytes);
17067
17068         printf("  %s############################%s\n",
17069                                nic_stats_border, nic_stats_border);
17070 }
17071
17072 cmdline_parse_inst_t cmd_show_vf_stats = {
17073         .f = cmd_show_vf_stats_parsed,
17074         .data = NULL,
17075         .help_str = "show vf stats <port_id> <vf_id>",
17076         .tokens = {
17077                 (void *)&cmd_show_vf_stats_show,
17078                 (void *)&cmd_show_vf_stats_vf,
17079                 (void *)&cmd_show_vf_stats_stats,
17080                 (void *)&cmd_show_vf_stats_port_id,
17081                 (void *)&cmd_show_vf_stats_vf_id,
17082                 NULL,
17083         },
17084 };
17085
17086 /* clear vf stats */
17087
17088 /* Common result structure for clear vf stats */
17089 struct cmd_clear_vf_stats_result {
17090         cmdline_fixed_string_t clear;
17091         cmdline_fixed_string_t vf;
17092         cmdline_fixed_string_t stats;
17093         portid_t port_id;
17094         uint16_t vf_id;
17095 };
17096
17097 /* Common CLI fields clear vf stats*/
17098 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17099         TOKEN_STRING_INITIALIZER
17100                 (struct cmd_clear_vf_stats_result,
17101                  clear, "clear");
17102 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17103         TOKEN_STRING_INITIALIZER
17104                 (struct cmd_clear_vf_stats_result,
17105                  vf, "vf");
17106 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17107         TOKEN_STRING_INITIALIZER
17108                 (struct cmd_clear_vf_stats_result,
17109                  stats, "stats");
17110 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17111         TOKEN_NUM_INITIALIZER
17112                 (struct cmd_clear_vf_stats_result,
17113                  port_id, UINT16);
17114 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17115         TOKEN_NUM_INITIALIZER
17116                 (struct cmd_clear_vf_stats_result,
17117                  vf_id, UINT16);
17118
17119 static void
17120 cmd_clear_vf_stats_parsed(
17121         void *parsed_result,
17122         __attribute__((unused)) struct cmdline *cl,
17123         __attribute__((unused)) void *data)
17124 {
17125         struct cmd_clear_vf_stats_result *res = parsed_result;
17126         int ret = -ENOTSUP;
17127
17128         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17129                 return;
17130
17131 #ifdef RTE_LIBRTE_I40E_PMD
17132         if (ret == -ENOTSUP)
17133                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17134                                                   res->vf_id);
17135 #endif
17136 #ifdef RTE_LIBRTE_BNXT_PMD
17137         if (ret == -ENOTSUP)
17138                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17139                                                   res->vf_id);
17140 #endif
17141
17142         switch (ret) {
17143         case 0:
17144                 break;
17145         case -EINVAL:
17146                 printf("invalid vf_id %d\n", res->vf_id);
17147                 break;
17148         case -ENODEV:
17149                 printf("invalid port_id %d\n", res->port_id);
17150                 break;
17151         case -ENOTSUP:
17152                 printf("function not implemented\n");
17153                 break;
17154         default:
17155                 printf("programming error: (%s)\n", strerror(-ret));
17156         }
17157 }
17158
17159 cmdline_parse_inst_t cmd_clear_vf_stats = {
17160         .f = cmd_clear_vf_stats_parsed,
17161         .data = NULL,
17162         .help_str = "clear vf stats <port_id> <vf_id>",
17163         .tokens = {
17164                 (void *)&cmd_clear_vf_stats_clear,
17165                 (void *)&cmd_clear_vf_stats_vf,
17166                 (void *)&cmd_clear_vf_stats_stats,
17167                 (void *)&cmd_clear_vf_stats_port_id,
17168                 (void *)&cmd_clear_vf_stats_vf_id,
17169                 NULL,
17170         },
17171 };
17172
17173 /* port config pctype mapping reset */
17174
17175 /* Common result structure for port config pctype mapping reset */
17176 struct cmd_pctype_mapping_reset_result {
17177         cmdline_fixed_string_t port;
17178         cmdline_fixed_string_t config;
17179         portid_t port_id;
17180         cmdline_fixed_string_t pctype;
17181         cmdline_fixed_string_t mapping;
17182         cmdline_fixed_string_t reset;
17183 };
17184
17185 /* Common CLI fields for port config pctype mapping reset*/
17186 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17187         TOKEN_STRING_INITIALIZER
17188                 (struct cmd_pctype_mapping_reset_result,
17189                  port, "port");
17190 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17191         TOKEN_STRING_INITIALIZER
17192                 (struct cmd_pctype_mapping_reset_result,
17193                  config, "config");
17194 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17195         TOKEN_NUM_INITIALIZER
17196                 (struct cmd_pctype_mapping_reset_result,
17197                  port_id, UINT16);
17198 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17199         TOKEN_STRING_INITIALIZER
17200                 (struct cmd_pctype_mapping_reset_result,
17201                  pctype, "pctype");
17202 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17203         TOKEN_STRING_INITIALIZER
17204                 (struct cmd_pctype_mapping_reset_result,
17205                  mapping, "mapping");
17206 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17207         TOKEN_STRING_INITIALIZER
17208                 (struct cmd_pctype_mapping_reset_result,
17209                  reset, "reset");
17210
17211 static void
17212 cmd_pctype_mapping_reset_parsed(
17213         void *parsed_result,
17214         __attribute__((unused)) struct cmdline *cl,
17215         __attribute__((unused)) void *data)
17216 {
17217         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17218         int ret = -ENOTSUP;
17219
17220         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17221                 return;
17222
17223 #ifdef RTE_LIBRTE_I40E_PMD
17224         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17225 #endif
17226
17227         switch (ret) {
17228         case 0:
17229                 break;
17230         case -ENODEV:
17231                 printf("invalid port_id %d\n", res->port_id);
17232                 break;
17233         case -ENOTSUP:
17234                 printf("function not implemented\n");
17235                 break;
17236         default:
17237                 printf("programming error: (%s)\n", strerror(-ret));
17238         }
17239 }
17240
17241 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17242         .f = cmd_pctype_mapping_reset_parsed,
17243         .data = NULL,
17244         .help_str = "port config <port_id> pctype mapping reset",
17245         .tokens = {
17246                 (void *)&cmd_pctype_mapping_reset_port,
17247                 (void *)&cmd_pctype_mapping_reset_config,
17248                 (void *)&cmd_pctype_mapping_reset_port_id,
17249                 (void *)&cmd_pctype_mapping_reset_pctype,
17250                 (void *)&cmd_pctype_mapping_reset_mapping,
17251                 (void *)&cmd_pctype_mapping_reset_reset,
17252                 NULL,
17253         },
17254 };
17255
17256 /* show port pctype mapping */
17257
17258 /* Common result structure for show port pctype mapping */
17259 struct cmd_pctype_mapping_get_result {
17260         cmdline_fixed_string_t show;
17261         cmdline_fixed_string_t port;
17262         portid_t port_id;
17263         cmdline_fixed_string_t pctype;
17264         cmdline_fixed_string_t mapping;
17265 };
17266
17267 /* Common CLI fields for pctype mapping get */
17268 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17269         TOKEN_STRING_INITIALIZER
17270                 (struct cmd_pctype_mapping_get_result,
17271                  show, "show");
17272 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17273         TOKEN_STRING_INITIALIZER
17274                 (struct cmd_pctype_mapping_get_result,
17275                  port, "port");
17276 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17277         TOKEN_NUM_INITIALIZER
17278                 (struct cmd_pctype_mapping_get_result,
17279                  port_id, UINT16);
17280 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17281         TOKEN_STRING_INITIALIZER
17282                 (struct cmd_pctype_mapping_get_result,
17283                  pctype, "pctype");
17284 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17285         TOKEN_STRING_INITIALIZER
17286                 (struct cmd_pctype_mapping_get_result,
17287                  mapping, "mapping");
17288
17289 static void
17290 cmd_pctype_mapping_get_parsed(
17291         void *parsed_result,
17292         __attribute__((unused)) struct cmdline *cl,
17293         __attribute__((unused)) void *data)
17294 {
17295         struct cmd_pctype_mapping_get_result *res = parsed_result;
17296         int ret = -ENOTSUP;
17297 #ifdef RTE_LIBRTE_I40E_PMD
17298         struct rte_pmd_i40e_flow_type_mapping
17299                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17300         int i, j, first_pctype;
17301 #endif
17302
17303         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17304                 return;
17305
17306 #ifdef RTE_LIBRTE_I40E_PMD
17307         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17308 #endif
17309
17310         switch (ret) {
17311         case 0:
17312                 break;
17313         case -ENODEV:
17314                 printf("invalid port_id %d\n", res->port_id);
17315                 return;
17316         case -ENOTSUP:
17317                 printf("function not implemented\n");
17318                 return;
17319         default:
17320                 printf("programming error: (%s)\n", strerror(-ret));
17321                 return;
17322         }
17323
17324 #ifdef RTE_LIBRTE_I40E_PMD
17325         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17326                 if (mapping[i].pctype != 0ULL) {
17327                         first_pctype = 1;
17328
17329                         printf("pctype: ");
17330                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17331                                 if (mapping[i].pctype & (1ULL << j)) {
17332                                         printf(first_pctype ?
17333                                                "%02d" : ",%02d", j);
17334                                         first_pctype = 0;
17335                                 }
17336                         }
17337                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17338                 }
17339         }
17340 #endif
17341 }
17342
17343 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17344         .f = cmd_pctype_mapping_get_parsed,
17345         .data = NULL,
17346         .help_str = "show port <port_id> pctype mapping",
17347         .tokens = {
17348                 (void *)&cmd_pctype_mapping_get_show,
17349                 (void *)&cmd_pctype_mapping_get_port,
17350                 (void *)&cmd_pctype_mapping_get_port_id,
17351                 (void *)&cmd_pctype_mapping_get_pctype,
17352                 (void *)&cmd_pctype_mapping_get_mapping,
17353                 NULL,
17354         },
17355 };
17356
17357 /* port config pctype mapping update */
17358
17359 /* Common result structure for port config pctype mapping update */
17360 struct cmd_pctype_mapping_update_result {
17361         cmdline_fixed_string_t port;
17362         cmdline_fixed_string_t config;
17363         portid_t port_id;
17364         cmdline_fixed_string_t pctype;
17365         cmdline_fixed_string_t mapping;
17366         cmdline_fixed_string_t update;
17367         cmdline_fixed_string_t pctype_list;
17368         uint16_t flow_type;
17369 };
17370
17371 /* Common CLI fields for pctype mapping update*/
17372 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17373         TOKEN_STRING_INITIALIZER
17374                 (struct cmd_pctype_mapping_update_result,
17375                  port, "port");
17376 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17377         TOKEN_STRING_INITIALIZER
17378                 (struct cmd_pctype_mapping_update_result,
17379                  config, "config");
17380 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17381         TOKEN_NUM_INITIALIZER
17382                 (struct cmd_pctype_mapping_update_result,
17383                  port_id, UINT16);
17384 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17385         TOKEN_STRING_INITIALIZER
17386                 (struct cmd_pctype_mapping_update_result,
17387                  pctype, "pctype");
17388 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17389         TOKEN_STRING_INITIALIZER
17390                 (struct cmd_pctype_mapping_update_result,
17391                  mapping, "mapping");
17392 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17393         TOKEN_STRING_INITIALIZER
17394                 (struct cmd_pctype_mapping_update_result,
17395                  update, "update");
17396 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17397         TOKEN_STRING_INITIALIZER
17398                 (struct cmd_pctype_mapping_update_result,
17399                  pctype_list, NULL);
17400 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17401         TOKEN_NUM_INITIALIZER
17402                 (struct cmd_pctype_mapping_update_result,
17403                  flow_type, UINT16);
17404
17405 static void
17406 cmd_pctype_mapping_update_parsed(
17407         void *parsed_result,
17408         __attribute__((unused)) struct cmdline *cl,
17409         __attribute__((unused)) void *data)
17410 {
17411         struct cmd_pctype_mapping_update_result *res = parsed_result;
17412         int ret = -ENOTSUP;
17413 #ifdef RTE_LIBRTE_I40E_PMD
17414         struct rte_pmd_i40e_flow_type_mapping mapping;
17415         unsigned int i;
17416         unsigned int nb_item;
17417         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17418 #endif
17419
17420         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17421                 return;
17422
17423 #ifdef RTE_LIBRTE_I40E_PMD
17424         nb_item = parse_item_list(res->pctype_list, "pctypes",
17425                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17426         mapping.flow_type = res->flow_type;
17427         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17428                 mapping.pctype |= (1ULL << pctype_list[i]);
17429         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17430                                                 &mapping,
17431                                                 1,
17432                                                 0);
17433 #endif
17434
17435         switch (ret) {
17436         case 0:
17437                 break;
17438         case -EINVAL:
17439                 printf("invalid pctype or flow type\n");
17440                 break;
17441         case -ENODEV:
17442                 printf("invalid port_id %d\n", res->port_id);
17443                 break;
17444         case -ENOTSUP:
17445                 printf("function not implemented\n");
17446                 break;
17447         default:
17448                 printf("programming error: (%s)\n", strerror(-ret));
17449         }
17450 }
17451
17452 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17453         .f = cmd_pctype_mapping_update_parsed,
17454         .data = NULL,
17455         .help_str = "port config <port_id> pctype mapping update"
17456         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17457         .tokens = {
17458                 (void *)&cmd_pctype_mapping_update_port,
17459                 (void *)&cmd_pctype_mapping_update_config,
17460                 (void *)&cmd_pctype_mapping_update_port_id,
17461                 (void *)&cmd_pctype_mapping_update_pctype,
17462                 (void *)&cmd_pctype_mapping_update_mapping,
17463                 (void *)&cmd_pctype_mapping_update_update,
17464                 (void *)&cmd_pctype_mapping_update_pc_type,
17465                 (void *)&cmd_pctype_mapping_update_flow_type,
17466                 NULL,
17467         },
17468 };
17469
17470 /* ptype mapping get */
17471
17472 /* Common result structure for ptype mapping get */
17473 struct cmd_ptype_mapping_get_result {
17474         cmdline_fixed_string_t ptype;
17475         cmdline_fixed_string_t mapping;
17476         cmdline_fixed_string_t get;
17477         portid_t port_id;
17478         uint8_t valid_only;
17479 };
17480
17481 /* Common CLI fields for ptype mapping get */
17482 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17483         TOKEN_STRING_INITIALIZER
17484                 (struct cmd_ptype_mapping_get_result,
17485                  ptype, "ptype");
17486 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17487         TOKEN_STRING_INITIALIZER
17488                 (struct cmd_ptype_mapping_get_result,
17489                  mapping, "mapping");
17490 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17491         TOKEN_STRING_INITIALIZER
17492                 (struct cmd_ptype_mapping_get_result,
17493                  get, "get");
17494 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17495         TOKEN_NUM_INITIALIZER
17496                 (struct cmd_ptype_mapping_get_result,
17497                  port_id, UINT16);
17498 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17499         TOKEN_NUM_INITIALIZER
17500                 (struct cmd_ptype_mapping_get_result,
17501                  valid_only, UINT8);
17502
17503 static void
17504 cmd_ptype_mapping_get_parsed(
17505         void *parsed_result,
17506         __attribute__((unused)) struct cmdline *cl,
17507         __attribute__((unused)) void *data)
17508 {
17509         struct cmd_ptype_mapping_get_result *res = parsed_result;
17510         int ret = -ENOTSUP;
17511 #ifdef RTE_LIBRTE_I40E_PMD
17512         int max_ptype_num = 256;
17513         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17514         uint16_t count;
17515         int i;
17516 #endif
17517
17518         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17519                 return;
17520
17521 #ifdef RTE_LIBRTE_I40E_PMD
17522         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17523                                         mapping,
17524                                         max_ptype_num,
17525                                         &count,
17526                                         res->valid_only);
17527 #endif
17528
17529         switch (ret) {
17530         case 0:
17531                 break;
17532         case -ENODEV:
17533                 printf("invalid port_id %d\n", res->port_id);
17534                 break;
17535         case -ENOTSUP:
17536                 printf("function not implemented\n");
17537                 break;
17538         default:
17539                 printf("programming error: (%s)\n", strerror(-ret));
17540         }
17541
17542 #ifdef RTE_LIBRTE_I40E_PMD
17543         if (!ret) {
17544                 for (i = 0; i < count; i++)
17545                         printf("%3d\t0x%08x\n",
17546                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17547         }
17548 #endif
17549 }
17550
17551 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17552         .f = cmd_ptype_mapping_get_parsed,
17553         .data = NULL,
17554         .help_str = "ptype mapping get <port_id> <valid_only>",
17555         .tokens = {
17556                 (void *)&cmd_ptype_mapping_get_ptype,
17557                 (void *)&cmd_ptype_mapping_get_mapping,
17558                 (void *)&cmd_ptype_mapping_get_get,
17559                 (void *)&cmd_ptype_mapping_get_port_id,
17560                 (void *)&cmd_ptype_mapping_get_valid_only,
17561                 NULL,
17562         },
17563 };
17564
17565 /* ptype mapping replace */
17566
17567 /* Common result structure for ptype mapping replace */
17568 struct cmd_ptype_mapping_replace_result {
17569         cmdline_fixed_string_t ptype;
17570         cmdline_fixed_string_t mapping;
17571         cmdline_fixed_string_t replace;
17572         portid_t port_id;
17573         uint32_t target;
17574         uint8_t mask;
17575         uint32_t pkt_type;
17576 };
17577
17578 /* Common CLI fields for ptype mapping replace */
17579 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17580         TOKEN_STRING_INITIALIZER
17581                 (struct cmd_ptype_mapping_replace_result,
17582                  ptype, "ptype");
17583 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17584         TOKEN_STRING_INITIALIZER
17585                 (struct cmd_ptype_mapping_replace_result,
17586                  mapping, "mapping");
17587 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17588         TOKEN_STRING_INITIALIZER
17589                 (struct cmd_ptype_mapping_replace_result,
17590                  replace, "replace");
17591 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17592         TOKEN_NUM_INITIALIZER
17593                 (struct cmd_ptype_mapping_replace_result,
17594                  port_id, UINT16);
17595 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17596         TOKEN_NUM_INITIALIZER
17597                 (struct cmd_ptype_mapping_replace_result,
17598                  target, UINT32);
17599 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17600         TOKEN_NUM_INITIALIZER
17601                 (struct cmd_ptype_mapping_replace_result,
17602                  mask, UINT8);
17603 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17604         TOKEN_NUM_INITIALIZER
17605                 (struct cmd_ptype_mapping_replace_result,
17606                  pkt_type, UINT32);
17607
17608 static void
17609 cmd_ptype_mapping_replace_parsed(
17610         void *parsed_result,
17611         __attribute__((unused)) struct cmdline *cl,
17612         __attribute__((unused)) void *data)
17613 {
17614         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17615         int ret = -ENOTSUP;
17616
17617         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17618                 return;
17619
17620 #ifdef RTE_LIBRTE_I40E_PMD
17621         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17622                                         res->target,
17623                                         res->mask,
17624                                         res->pkt_type);
17625 #endif
17626
17627         switch (ret) {
17628         case 0:
17629                 break;
17630         case -EINVAL:
17631                 printf("invalid ptype 0x%8x or 0x%8x\n",
17632                                 res->target, res->pkt_type);
17633                 break;
17634         case -ENODEV:
17635                 printf("invalid port_id %d\n", res->port_id);
17636                 break;
17637         case -ENOTSUP:
17638                 printf("function not implemented\n");
17639                 break;
17640         default:
17641                 printf("programming error: (%s)\n", strerror(-ret));
17642         }
17643 }
17644
17645 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17646         .f = cmd_ptype_mapping_replace_parsed,
17647         .data = NULL,
17648         .help_str =
17649                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17650         .tokens = {
17651                 (void *)&cmd_ptype_mapping_replace_ptype,
17652                 (void *)&cmd_ptype_mapping_replace_mapping,
17653                 (void *)&cmd_ptype_mapping_replace_replace,
17654                 (void *)&cmd_ptype_mapping_replace_port_id,
17655                 (void *)&cmd_ptype_mapping_replace_target,
17656                 (void *)&cmd_ptype_mapping_replace_mask,
17657                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17658                 NULL,
17659         },
17660 };
17661
17662 /* ptype mapping reset */
17663
17664 /* Common result structure for ptype mapping reset */
17665 struct cmd_ptype_mapping_reset_result {
17666         cmdline_fixed_string_t ptype;
17667         cmdline_fixed_string_t mapping;
17668         cmdline_fixed_string_t reset;
17669         portid_t port_id;
17670 };
17671
17672 /* Common CLI fields for ptype mapping reset*/
17673 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17674         TOKEN_STRING_INITIALIZER
17675                 (struct cmd_ptype_mapping_reset_result,
17676                  ptype, "ptype");
17677 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17678         TOKEN_STRING_INITIALIZER
17679                 (struct cmd_ptype_mapping_reset_result,
17680                  mapping, "mapping");
17681 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17682         TOKEN_STRING_INITIALIZER
17683                 (struct cmd_ptype_mapping_reset_result,
17684                  reset, "reset");
17685 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17686         TOKEN_NUM_INITIALIZER
17687                 (struct cmd_ptype_mapping_reset_result,
17688                  port_id, UINT16);
17689
17690 static void
17691 cmd_ptype_mapping_reset_parsed(
17692         void *parsed_result,
17693         __attribute__((unused)) struct cmdline *cl,
17694         __attribute__((unused)) void *data)
17695 {
17696         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17697         int ret = -ENOTSUP;
17698
17699         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17700                 return;
17701
17702 #ifdef RTE_LIBRTE_I40E_PMD
17703         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17704 #endif
17705
17706         switch (ret) {
17707         case 0:
17708                 break;
17709         case -ENODEV:
17710                 printf("invalid port_id %d\n", res->port_id);
17711                 break;
17712         case -ENOTSUP:
17713                 printf("function not implemented\n");
17714                 break;
17715         default:
17716                 printf("programming error: (%s)\n", strerror(-ret));
17717         }
17718 }
17719
17720 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17721         .f = cmd_ptype_mapping_reset_parsed,
17722         .data = NULL,
17723         .help_str = "ptype mapping reset <port_id>",
17724         .tokens = {
17725                 (void *)&cmd_ptype_mapping_reset_ptype,
17726                 (void *)&cmd_ptype_mapping_reset_mapping,
17727                 (void *)&cmd_ptype_mapping_reset_reset,
17728                 (void *)&cmd_ptype_mapping_reset_port_id,
17729                 NULL,
17730         },
17731 };
17732
17733 /* ptype mapping update */
17734
17735 /* Common result structure for ptype mapping update */
17736 struct cmd_ptype_mapping_update_result {
17737         cmdline_fixed_string_t ptype;
17738         cmdline_fixed_string_t mapping;
17739         cmdline_fixed_string_t reset;
17740         portid_t port_id;
17741         uint8_t hw_ptype;
17742         uint32_t sw_ptype;
17743 };
17744
17745 /* Common CLI fields for ptype mapping update*/
17746 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17747         TOKEN_STRING_INITIALIZER
17748                 (struct cmd_ptype_mapping_update_result,
17749                  ptype, "ptype");
17750 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17751         TOKEN_STRING_INITIALIZER
17752                 (struct cmd_ptype_mapping_update_result,
17753                  mapping, "mapping");
17754 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17755         TOKEN_STRING_INITIALIZER
17756                 (struct cmd_ptype_mapping_update_result,
17757                  reset, "update");
17758 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17759         TOKEN_NUM_INITIALIZER
17760                 (struct cmd_ptype_mapping_update_result,
17761                  port_id, UINT16);
17762 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17763         TOKEN_NUM_INITIALIZER
17764                 (struct cmd_ptype_mapping_update_result,
17765                  hw_ptype, UINT8);
17766 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17767         TOKEN_NUM_INITIALIZER
17768                 (struct cmd_ptype_mapping_update_result,
17769                  sw_ptype, UINT32);
17770
17771 static void
17772 cmd_ptype_mapping_update_parsed(
17773         void *parsed_result,
17774         __attribute__((unused)) struct cmdline *cl,
17775         __attribute__((unused)) void *data)
17776 {
17777         struct cmd_ptype_mapping_update_result *res = parsed_result;
17778         int ret = -ENOTSUP;
17779 #ifdef RTE_LIBRTE_I40E_PMD
17780         struct rte_pmd_i40e_ptype_mapping mapping;
17781 #endif
17782         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17783                 return;
17784
17785 #ifdef RTE_LIBRTE_I40E_PMD
17786         mapping.hw_ptype = res->hw_ptype;
17787         mapping.sw_ptype = res->sw_ptype;
17788         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17789                                                 &mapping,
17790                                                 1,
17791                                                 0);
17792 #endif
17793
17794         switch (ret) {
17795         case 0:
17796                 break;
17797         case -EINVAL:
17798                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17799                 break;
17800         case -ENODEV:
17801                 printf("invalid port_id %d\n", res->port_id);
17802                 break;
17803         case -ENOTSUP:
17804                 printf("function not implemented\n");
17805                 break;
17806         default:
17807                 printf("programming error: (%s)\n", strerror(-ret));
17808         }
17809 }
17810
17811 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17812         .f = cmd_ptype_mapping_update_parsed,
17813         .data = NULL,
17814         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17815         .tokens = {
17816                 (void *)&cmd_ptype_mapping_update_ptype,
17817                 (void *)&cmd_ptype_mapping_update_mapping,
17818                 (void *)&cmd_ptype_mapping_update_update,
17819                 (void *)&cmd_ptype_mapping_update_port_id,
17820                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17821                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17822                 NULL,
17823         },
17824 };
17825
17826 /* Common result structure for file commands */
17827 struct cmd_cmdfile_result {
17828         cmdline_fixed_string_t load;
17829         cmdline_fixed_string_t filename;
17830 };
17831
17832 /* Common CLI fields for file commands */
17833 cmdline_parse_token_string_t cmd_load_cmdfile =
17834         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17835 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17836         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17837
17838 static void
17839 cmd_load_from_file_parsed(
17840         void *parsed_result,
17841         __attribute__((unused)) struct cmdline *cl,
17842         __attribute__((unused)) void *data)
17843 {
17844         struct cmd_cmdfile_result *res = parsed_result;
17845
17846         cmdline_read_from_file(res->filename);
17847 }
17848
17849 cmdline_parse_inst_t cmd_load_from_file = {
17850         .f = cmd_load_from_file_parsed,
17851         .data = NULL,
17852         .help_str = "load <filename>",
17853         .tokens = {
17854                 (void *)&cmd_load_cmdfile,
17855                 (void *)&cmd_load_cmdfile_filename,
17856                 NULL,
17857         },
17858 };
17859
17860 /* Get Rx offloads capabilities */
17861 struct cmd_rx_offload_get_capa_result {
17862         cmdline_fixed_string_t show;
17863         cmdline_fixed_string_t port;
17864         portid_t port_id;
17865         cmdline_fixed_string_t rx_offload;
17866         cmdline_fixed_string_t capabilities;
17867 };
17868
17869 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17870         TOKEN_STRING_INITIALIZER
17871                 (struct cmd_rx_offload_get_capa_result,
17872                  show, "show");
17873 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17874         TOKEN_STRING_INITIALIZER
17875                 (struct cmd_rx_offload_get_capa_result,
17876                  port, "port");
17877 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17878         TOKEN_NUM_INITIALIZER
17879                 (struct cmd_rx_offload_get_capa_result,
17880                  port_id, UINT16);
17881 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17882         TOKEN_STRING_INITIALIZER
17883                 (struct cmd_rx_offload_get_capa_result,
17884                  rx_offload, "rx_offload");
17885 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17886         TOKEN_STRING_INITIALIZER
17887                 (struct cmd_rx_offload_get_capa_result,
17888                  capabilities, "capabilities");
17889
17890 static void
17891 print_rx_offloads(uint64_t offloads)
17892 {
17893         uint64_t single_offload;
17894         int begin;
17895         int end;
17896         int bit;
17897
17898         if (offloads == 0)
17899                 return;
17900
17901         begin = __builtin_ctzll(offloads);
17902         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17903
17904         single_offload = 1ULL << begin;
17905         for (bit = begin; bit < end; bit++) {
17906                 if (offloads & single_offload)
17907                         printf(" %s",
17908                                rte_eth_dev_rx_offload_name(single_offload));
17909                 single_offload <<= 1;
17910         }
17911 }
17912
17913 static void
17914 cmd_rx_offload_get_capa_parsed(
17915         void *parsed_result,
17916         __attribute__((unused)) struct cmdline *cl,
17917         __attribute__((unused)) void *data)
17918 {
17919         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17920         struct rte_eth_dev_info dev_info;
17921         portid_t port_id = res->port_id;
17922         uint64_t queue_offloads;
17923         uint64_t port_offloads;
17924         int ret;
17925
17926         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17927         if (ret != 0)
17928                 return;
17929
17930         queue_offloads = dev_info.rx_queue_offload_capa;
17931         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17932
17933         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17934         printf("  Per Queue :");
17935         print_rx_offloads(queue_offloads);
17936
17937         printf("\n");
17938         printf("  Per Port  :");
17939         print_rx_offloads(port_offloads);
17940         printf("\n\n");
17941 }
17942
17943 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17944         .f = cmd_rx_offload_get_capa_parsed,
17945         .data = NULL,
17946         .help_str = "show port <port_id> rx_offload capabilities",
17947         .tokens = {
17948                 (void *)&cmd_rx_offload_get_capa_show,
17949                 (void *)&cmd_rx_offload_get_capa_port,
17950                 (void *)&cmd_rx_offload_get_capa_port_id,
17951                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17952                 (void *)&cmd_rx_offload_get_capa_capabilities,
17953                 NULL,
17954         }
17955 };
17956
17957 /* Get Rx offloads configuration */
17958 struct cmd_rx_offload_get_configuration_result {
17959         cmdline_fixed_string_t show;
17960         cmdline_fixed_string_t port;
17961         portid_t port_id;
17962         cmdline_fixed_string_t rx_offload;
17963         cmdline_fixed_string_t configuration;
17964 };
17965
17966 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17967         TOKEN_STRING_INITIALIZER
17968                 (struct cmd_rx_offload_get_configuration_result,
17969                  show, "show");
17970 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17971         TOKEN_STRING_INITIALIZER
17972                 (struct cmd_rx_offload_get_configuration_result,
17973                  port, "port");
17974 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17975         TOKEN_NUM_INITIALIZER
17976                 (struct cmd_rx_offload_get_configuration_result,
17977                  port_id, UINT16);
17978 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17979         TOKEN_STRING_INITIALIZER
17980                 (struct cmd_rx_offload_get_configuration_result,
17981                  rx_offload, "rx_offload");
17982 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17983         TOKEN_STRING_INITIALIZER
17984                 (struct cmd_rx_offload_get_configuration_result,
17985                  configuration, "configuration");
17986
17987 static void
17988 cmd_rx_offload_get_configuration_parsed(
17989         void *parsed_result,
17990         __attribute__((unused)) struct cmdline *cl,
17991         __attribute__((unused)) void *data)
17992 {
17993         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17994         struct rte_eth_dev_info dev_info;
17995         portid_t port_id = res->port_id;
17996         struct rte_port *port = &ports[port_id];
17997         uint64_t port_offloads;
17998         uint64_t queue_offloads;
17999         uint16_t nb_rx_queues;
18000         int q;
18001         int ret;
18002
18003         printf("Rx Offloading Configuration of port %d :\n", port_id);
18004
18005         port_offloads = port->dev_conf.rxmode.offloads;
18006         printf("  Port :");
18007         print_rx_offloads(port_offloads);
18008         printf("\n");
18009
18010         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18011         if (ret != 0)
18012                 return;
18013
18014         nb_rx_queues = dev_info.nb_rx_queues;
18015         for (q = 0; q < nb_rx_queues; q++) {
18016                 queue_offloads = port->rx_conf[q].offloads;
18017                 printf("  Queue[%2d] :", q);
18018                 print_rx_offloads(queue_offloads);
18019                 printf("\n");
18020         }
18021         printf("\n");
18022 }
18023
18024 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18025         .f = cmd_rx_offload_get_configuration_parsed,
18026         .data = NULL,
18027         .help_str = "show port <port_id> rx_offload configuration",
18028         .tokens = {
18029                 (void *)&cmd_rx_offload_get_configuration_show,
18030                 (void *)&cmd_rx_offload_get_configuration_port,
18031                 (void *)&cmd_rx_offload_get_configuration_port_id,
18032                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18033                 (void *)&cmd_rx_offload_get_configuration_configuration,
18034                 NULL,
18035         }
18036 };
18037
18038 /* Enable/Disable a per port offloading */
18039 struct cmd_config_per_port_rx_offload_result {
18040         cmdline_fixed_string_t port;
18041         cmdline_fixed_string_t config;
18042         portid_t port_id;
18043         cmdline_fixed_string_t rx_offload;
18044         cmdline_fixed_string_t offload;
18045         cmdline_fixed_string_t on_off;
18046 };
18047
18048 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18049         TOKEN_STRING_INITIALIZER
18050                 (struct cmd_config_per_port_rx_offload_result,
18051                  port, "port");
18052 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18053         TOKEN_STRING_INITIALIZER
18054                 (struct cmd_config_per_port_rx_offload_result,
18055                  config, "config");
18056 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18057         TOKEN_NUM_INITIALIZER
18058                 (struct cmd_config_per_port_rx_offload_result,
18059                  port_id, UINT16);
18060 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18061         TOKEN_STRING_INITIALIZER
18062                 (struct cmd_config_per_port_rx_offload_result,
18063                  rx_offload, "rx_offload");
18064 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18065         TOKEN_STRING_INITIALIZER
18066                 (struct cmd_config_per_port_rx_offload_result,
18067                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18068                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18069                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18070                            "crc_strip#scatter#timestamp#security#keep_crc");
18071 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18072         TOKEN_STRING_INITIALIZER
18073                 (struct cmd_config_per_port_rx_offload_result,
18074                  on_off, "on#off");
18075
18076 static uint64_t
18077 search_rx_offload(const char *name)
18078 {
18079         uint64_t single_offload;
18080         const char *single_name;
18081         int found = 0;
18082         unsigned int bit;
18083
18084         single_offload = 1;
18085         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18086                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18087                 if (!strcasecmp(single_name, name)) {
18088                         found = 1;
18089                         break;
18090                 }
18091                 single_offload <<= 1;
18092         }
18093
18094         if (found)
18095                 return single_offload;
18096
18097         return 0;
18098 }
18099
18100 static void
18101 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18102                                 __attribute__((unused)) struct cmdline *cl,
18103                                 __attribute__((unused)) void *data)
18104 {
18105         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18106         portid_t port_id = res->port_id;
18107         struct rte_eth_dev_info dev_info;
18108         struct rte_port *port = &ports[port_id];
18109         uint64_t single_offload;
18110         uint16_t nb_rx_queues;
18111         int q;
18112         int ret;
18113
18114         if (port->port_status != RTE_PORT_STOPPED) {
18115                 printf("Error: Can't config offload when Port %d "
18116                        "is not stopped\n", port_id);
18117                 return;
18118         }
18119
18120         single_offload = search_rx_offload(res->offload);
18121         if (single_offload == 0) {
18122                 printf("Unknown offload name: %s\n", res->offload);
18123                 return;
18124         }
18125
18126         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18127         if (ret != 0)
18128                 return;
18129
18130         nb_rx_queues = dev_info.nb_rx_queues;
18131         if (!strcmp(res->on_off, "on")) {
18132                 port->dev_conf.rxmode.offloads |= single_offload;
18133                 for (q = 0; q < nb_rx_queues; q++)
18134                         port->rx_conf[q].offloads |= single_offload;
18135         } else {
18136                 port->dev_conf.rxmode.offloads &= ~single_offload;
18137                 for (q = 0; q < nb_rx_queues; q++)
18138                         port->rx_conf[q].offloads &= ~single_offload;
18139         }
18140
18141         cmd_reconfig_device_queue(port_id, 1, 1);
18142 }
18143
18144 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18145         .f = cmd_config_per_port_rx_offload_parsed,
18146         .data = NULL,
18147         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18148                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18149                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18150                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18151                     "on|off",
18152         .tokens = {
18153                 (void *)&cmd_config_per_port_rx_offload_result_port,
18154                 (void *)&cmd_config_per_port_rx_offload_result_config,
18155                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18156                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18157                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18158                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18159                 NULL,
18160         }
18161 };
18162
18163 /* Enable/Disable a per queue offloading */
18164 struct cmd_config_per_queue_rx_offload_result {
18165         cmdline_fixed_string_t port;
18166         portid_t port_id;
18167         cmdline_fixed_string_t rxq;
18168         uint16_t queue_id;
18169         cmdline_fixed_string_t rx_offload;
18170         cmdline_fixed_string_t offload;
18171         cmdline_fixed_string_t on_off;
18172 };
18173
18174 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18175         TOKEN_STRING_INITIALIZER
18176                 (struct cmd_config_per_queue_rx_offload_result,
18177                  port, "port");
18178 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18179         TOKEN_NUM_INITIALIZER
18180                 (struct cmd_config_per_queue_rx_offload_result,
18181                  port_id, UINT16);
18182 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18183         TOKEN_STRING_INITIALIZER
18184                 (struct cmd_config_per_queue_rx_offload_result,
18185                  rxq, "rxq");
18186 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18187         TOKEN_NUM_INITIALIZER
18188                 (struct cmd_config_per_queue_rx_offload_result,
18189                  queue_id, UINT16);
18190 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18191         TOKEN_STRING_INITIALIZER
18192                 (struct cmd_config_per_queue_rx_offload_result,
18193                  rx_offload, "rx_offload");
18194 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18195         TOKEN_STRING_INITIALIZER
18196                 (struct cmd_config_per_queue_rx_offload_result,
18197                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18198                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18199                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18200                            "crc_strip#scatter#timestamp#security#keep_crc");
18201 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18202         TOKEN_STRING_INITIALIZER
18203                 (struct cmd_config_per_queue_rx_offload_result,
18204                  on_off, "on#off");
18205
18206 static void
18207 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18208                                 __attribute__((unused)) struct cmdline *cl,
18209                                 __attribute__((unused)) void *data)
18210 {
18211         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18212         struct rte_eth_dev_info dev_info;
18213         portid_t port_id = res->port_id;
18214         uint16_t queue_id = res->queue_id;
18215         struct rte_port *port = &ports[port_id];
18216         uint64_t single_offload;
18217         int ret;
18218
18219         if (port->port_status != RTE_PORT_STOPPED) {
18220                 printf("Error: Can't config offload when Port %d "
18221                        "is not stopped\n", port_id);
18222                 return;
18223         }
18224
18225         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18226         if (ret != 0)
18227                 return;
18228
18229         if (queue_id >= dev_info.nb_rx_queues) {
18230                 printf("Error: input queue_id should be 0 ... "
18231                        "%d\n", dev_info.nb_rx_queues - 1);
18232                 return;
18233         }
18234
18235         single_offload = search_rx_offload(res->offload);
18236         if (single_offload == 0) {
18237                 printf("Unknown offload name: %s\n", res->offload);
18238                 return;
18239         }
18240
18241         if (!strcmp(res->on_off, "on"))
18242                 port->rx_conf[queue_id].offloads |= single_offload;
18243         else
18244                 port->rx_conf[queue_id].offloads &= ~single_offload;
18245
18246         cmd_reconfig_device_queue(port_id, 1, 1);
18247 }
18248
18249 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18250         .f = cmd_config_per_queue_rx_offload_parsed,
18251         .data = NULL,
18252         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18253                     "vlan_strip|ipv4_cksum|"
18254                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18255                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18256                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18257                     "on|off",
18258         .tokens = {
18259                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18260                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18261                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18262                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18263                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18264                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18265                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18266                 NULL,
18267         }
18268 };
18269
18270 /* Get Tx offloads capabilities */
18271 struct cmd_tx_offload_get_capa_result {
18272         cmdline_fixed_string_t show;
18273         cmdline_fixed_string_t port;
18274         portid_t port_id;
18275         cmdline_fixed_string_t tx_offload;
18276         cmdline_fixed_string_t capabilities;
18277 };
18278
18279 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18280         TOKEN_STRING_INITIALIZER
18281                 (struct cmd_tx_offload_get_capa_result,
18282                  show, "show");
18283 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18284         TOKEN_STRING_INITIALIZER
18285                 (struct cmd_tx_offload_get_capa_result,
18286                  port, "port");
18287 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18288         TOKEN_NUM_INITIALIZER
18289                 (struct cmd_tx_offload_get_capa_result,
18290                  port_id, UINT16);
18291 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18292         TOKEN_STRING_INITIALIZER
18293                 (struct cmd_tx_offload_get_capa_result,
18294                  tx_offload, "tx_offload");
18295 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18296         TOKEN_STRING_INITIALIZER
18297                 (struct cmd_tx_offload_get_capa_result,
18298                  capabilities, "capabilities");
18299
18300 static void
18301 print_tx_offloads(uint64_t offloads)
18302 {
18303         uint64_t single_offload;
18304         int begin;
18305         int end;
18306         int bit;
18307
18308         if (offloads == 0)
18309                 return;
18310
18311         begin = __builtin_ctzll(offloads);
18312         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18313
18314         single_offload = 1ULL << begin;
18315         for (bit = begin; bit < end; bit++) {
18316                 if (offloads & single_offload)
18317                         printf(" %s",
18318                                rte_eth_dev_tx_offload_name(single_offload));
18319                 single_offload <<= 1;
18320         }
18321 }
18322
18323 static void
18324 cmd_tx_offload_get_capa_parsed(
18325         void *parsed_result,
18326         __attribute__((unused)) struct cmdline *cl,
18327         __attribute__((unused)) void *data)
18328 {
18329         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18330         struct rte_eth_dev_info dev_info;
18331         portid_t port_id = res->port_id;
18332         uint64_t queue_offloads;
18333         uint64_t port_offloads;
18334         int ret;
18335
18336         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18337         if (ret != 0)
18338                 return;
18339
18340         queue_offloads = dev_info.tx_queue_offload_capa;
18341         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18342
18343         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18344         printf("  Per Queue :");
18345         print_tx_offloads(queue_offloads);
18346
18347         printf("\n");
18348         printf("  Per Port  :");
18349         print_tx_offloads(port_offloads);
18350         printf("\n\n");
18351 }
18352
18353 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18354         .f = cmd_tx_offload_get_capa_parsed,
18355         .data = NULL,
18356         .help_str = "show port <port_id> tx_offload capabilities",
18357         .tokens = {
18358                 (void *)&cmd_tx_offload_get_capa_show,
18359                 (void *)&cmd_tx_offload_get_capa_port,
18360                 (void *)&cmd_tx_offload_get_capa_port_id,
18361                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18362                 (void *)&cmd_tx_offload_get_capa_capabilities,
18363                 NULL,
18364         }
18365 };
18366
18367 /* Get Tx offloads configuration */
18368 struct cmd_tx_offload_get_configuration_result {
18369         cmdline_fixed_string_t show;
18370         cmdline_fixed_string_t port;
18371         portid_t port_id;
18372         cmdline_fixed_string_t tx_offload;
18373         cmdline_fixed_string_t configuration;
18374 };
18375
18376 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18377         TOKEN_STRING_INITIALIZER
18378                 (struct cmd_tx_offload_get_configuration_result,
18379                  show, "show");
18380 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18381         TOKEN_STRING_INITIALIZER
18382                 (struct cmd_tx_offload_get_configuration_result,
18383                  port, "port");
18384 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18385         TOKEN_NUM_INITIALIZER
18386                 (struct cmd_tx_offload_get_configuration_result,
18387                  port_id, UINT16);
18388 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18389         TOKEN_STRING_INITIALIZER
18390                 (struct cmd_tx_offload_get_configuration_result,
18391                  tx_offload, "tx_offload");
18392 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18393         TOKEN_STRING_INITIALIZER
18394                 (struct cmd_tx_offload_get_configuration_result,
18395                  configuration, "configuration");
18396
18397 static void
18398 cmd_tx_offload_get_configuration_parsed(
18399         void *parsed_result,
18400         __attribute__((unused)) struct cmdline *cl,
18401         __attribute__((unused)) void *data)
18402 {
18403         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18404         struct rte_eth_dev_info dev_info;
18405         portid_t port_id = res->port_id;
18406         struct rte_port *port = &ports[port_id];
18407         uint64_t port_offloads;
18408         uint64_t queue_offloads;
18409         uint16_t nb_tx_queues;
18410         int q;
18411         int ret;
18412
18413         printf("Tx Offloading Configuration of port %d :\n", port_id);
18414
18415         port_offloads = port->dev_conf.txmode.offloads;
18416         printf("  Port :");
18417         print_tx_offloads(port_offloads);
18418         printf("\n");
18419
18420         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18421         if (ret != 0)
18422                 return;
18423
18424         nb_tx_queues = dev_info.nb_tx_queues;
18425         for (q = 0; q < nb_tx_queues; q++) {
18426                 queue_offloads = port->tx_conf[q].offloads;
18427                 printf("  Queue[%2d] :", q);
18428                 print_tx_offloads(queue_offloads);
18429                 printf("\n");
18430         }
18431         printf("\n");
18432 }
18433
18434 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18435         .f = cmd_tx_offload_get_configuration_parsed,
18436         .data = NULL,
18437         .help_str = "show port <port_id> tx_offload configuration",
18438         .tokens = {
18439                 (void *)&cmd_tx_offload_get_configuration_show,
18440                 (void *)&cmd_tx_offload_get_configuration_port,
18441                 (void *)&cmd_tx_offload_get_configuration_port_id,
18442                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18443                 (void *)&cmd_tx_offload_get_configuration_configuration,
18444                 NULL,
18445         }
18446 };
18447
18448 /* Enable/Disable a per port offloading */
18449 struct cmd_config_per_port_tx_offload_result {
18450         cmdline_fixed_string_t port;
18451         cmdline_fixed_string_t config;
18452         portid_t port_id;
18453         cmdline_fixed_string_t tx_offload;
18454         cmdline_fixed_string_t offload;
18455         cmdline_fixed_string_t on_off;
18456 };
18457
18458 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18459         TOKEN_STRING_INITIALIZER
18460                 (struct cmd_config_per_port_tx_offload_result,
18461                  port, "port");
18462 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18463         TOKEN_STRING_INITIALIZER
18464                 (struct cmd_config_per_port_tx_offload_result,
18465                  config, "config");
18466 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18467         TOKEN_NUM_INITIALIZER
18468                 (struct cmd_config_per_port_tx_offload_result,
18469                  port_id, UINT16);
18470 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18471         TOKEN_STRING_INITIALIZER
18472                 (struct cmd_config_per_port_tx_offload_result,
18473                  tx_offload, "tx_offload");
18474 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18475         TOKEN_STRING_INITIALIZER
18476                 (struct cmd_config_per_port_tx_offload_result,
18477                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18478                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18479                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18480                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18481                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18482                           "match_metadata");
18483 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18484         TOKEN_STRING_INITIALIZER
18485                 (struct cmd_config_per_port_tx_offload_result,
18486                  on_off, "on#off");
18487
18488 static uint64_t
18489 search_tx_offload(const char *name)
18490 {
18491         uint64_t single_offload;
18492         const char *single_name;
18493         int found = 0;
18494         unsigned int bit;
18495
18496         single_offload = 1;
18497         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18498                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18499                 if (single_name == NULL)
18500                         break;
18501                 if (!strcasecmp(single_name, name)) {
18502                         found = 1;
18503                         break;
18504                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18505                         break;
18506                 single_offload <<= 1;
18507         }
18508
18509         if (found)
18510                 return single_offload;
18511
18512         return 0;
18513 }
18514
18515 static void
18516 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18517                                 __attribute__((unused)) struct cmdline *cl,
18518                                 __attribute__((unused)) void *data)
18519 {
18520         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18521         portid_t port_id = res->port_id;
18522         struct rte_eth_dev_info dev_info;
18523         struct rte_port *port = &ports[port_id];
18524         uint64_t single_offload;
18525         uint16_t nb_tx_queues;
18526         int q;
18527         int ret;
18528
18529         if (port->port_status != RTE_PORT_STOPPED) {
18530                 printf("Error: Can't config offload when Port %d "
18531                        "is not stopped\n", port_id);
18532                 return;
18533         }
18534
18535         single_offload = search_tx_offload(res->offload);
18536         if (single_offload == 0) {
18537                 printf("Unknown offload name: %s\n", res->offload);
18538                 return;
18539         }
18540
18541         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18542         if (ret != 0)
18543                 return;
18544
18545         nb_tx_queues = dev_info.nb_tx_queues;
18546         if (!strcmp(res->on_off, "on")) {
18547                 port->dev_conf.txmode.offloads |= single_offload;
18548                 for (q = 0; q < nb_tx_queues; q++)
18549                         port->tx_conf[q].offloads |= single_offload;
18550         } else {
18551                 port->dev_conf.txmode.offloads &= ~single_offload;
18552                 for (q = 0; q < nb_tx_queues; q++)
18553                         port->tx_conf[q].offloads &= ~single_offload;
18554         }
18555
18556         cmd_reconfig_device_queue(port_id, 1, 1);
18557 }
18558
18559 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18560         .f = cmd_config_per_port_tx_offload_parsed,
18561         .data = NULL,
18562         .help_str = "port config <port_id> tx_offload "
18563                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18564                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18565                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18566                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18567                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18568                     "match_metadata on|off",
18569         .tokens = {
18570                 (void *)&cmd_config_per_port_tx_offload_result_port,
18571                 (void *)&cmd_config_per_port_tx_offload_result_config,
18572                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18573                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18574                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18575                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18576                 NULL,
18577         }
18578 };
18579
18580 /* Enable/Disable a per queue offloading */
18581 struct cmd_config_per_queue_tx_offload_result {
18582         cmdline_fixed_string_t port;
18583         portid_t port_id;
18584         cmdline_fixed_string_t txq;
18585         uint16_t queue_id;
18586         cmdline_fixed_string_t tx_offload;
18587         cmdline_fixed_string_t offload;
18588         cmdline_fixed_string_t on_off;
18589 };
18590
18591 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18592         TOKEN_STRING_INITIALIZER
18593                 (struct cmd_config_per_queue_tx_offload_result,
18594                  port, "port");
18595 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18596         TOKEN_NUM_INITIALIZER
18597                 (struct cmd_config_per_queue_tx_offload_result,
18598                  port_id, UINT16);
18599 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18600         TOKEN_STRING_INITIALIZER
18601                 (struct cmd_config_per_queue_tx_offload_result,
18602                  txq, "txq");
18603 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18604         TOKEN_NUM_INITIALIZER
18605                 (struct cmd_config_per_queue_tx_offload_result,
18606                  queue_id, UINT16);
18607 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18608         TOKEN_STRING_INITIALIZER
18609                 (struct cmd_config_per_queue_tx_offload_result,
18610                  tx_offload, "tx_offload");
18611 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18612         TOKEN_STRING_INITIALIZER
18613                 (struct cmd_config_per_queue_tx_offload_result,
18614                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18615                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18616                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18617                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18618                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18619 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18620         TOKEN_STRING_INITIALIZER
18621                 (struct cmd_config_per_queue_tx_offload_result,
18622                  on_off, "on#off");
18623
18624 static void
18625 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18626                                 __attribute__((unused)) struct cmdline *cl,
18627                                 __attribute__((unused)) void *data)
18628 {
18629         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18630         struct rte_eth_dev_info dev_info;
18631         portid_t port_id = res->port_id;
18632         uint16_t queue_id = res->queue_id;
18633         struct rte_port *port = &ports[port_id];
18634         uint64_t single_offload;
18635         int ret;
18636
18637         if (port->port_status != RTE_PORT_STOPPED) {
18638                 printf("Error: Can't config offload when Port %d "
18639                        "is not stopped\n", port_id);
18640                 return;
18641         }
18642
18643         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18644         if (ret != 0)
18645                 return;
18646
18647         if (queue_id >= dev_info.nb_tx_queues) {
18648                 printf("Error: input queue_id should be 0 ... "
18649                        "%d\n", dev_info.nb_tx_queues - 1);
18650                 return;
18651         }
18652
18653         single_offload = search_tx_offload(res->offload);
18654         if (single_offload == 0) {
18655                 printf("Unknown offload name: %s\n", res->offload);
18656                 return;
18657         }
18658
18659         if (!strcmp(res->on_off, "on"))
18660                 port->tx_conf[queue_id].offloads |= single_offload;
18661         else
18662                 port->tx_conf[queue_id].offloads &= ~single_offload;
18663
18664         cmd_reconfig_device_queue(port_id, 1, 1);
18665 }
18666
18667 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18668         .f = cmd_config_per_queue_tx_offload_parsed,
18669         .data = NULL,
18670         .help_str = "port <port_id> txq <queue_id> tx_offload "
18671                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18672                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18673                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18674                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18675                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18676                     "on|off",
18677         .tokens = {
18678                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18679                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18680                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18681                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18682                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18683                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18684                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18685                 NULL,
18686         }
18687 };
18688
18689 /* *** configure tx_metadata for specific port *** */
18690 struct cmd_config_tx_metadata_specific_result {
18691         cmdline_fixed_string_t port;
18692         cmdline_fixed_string_t keyword;
18693         uint16_t port_id;
18694         cmdline_fixed_string_t item;
18695         uint32_t value;
18696 };
18697
18698 static void
18699 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18700                                 __attribute__((unused)) struct cmdline *cl,
18701                                 __attribute__((unused)) void *data)
18702 {
18703         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18704
18705         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18706                 return;
18707         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18708         /* Add/remove callback to insert valid metadata in every Tx packet. */
18709         if (ports[res->port_id].tx_metadata)
18710                 add_tx_md_callback(res->port_id);
18711         else
18712                 remove_tx_md_callback(res->port_id);
18713 }
18714
18715 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18716         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18717                         port, "port");
18718 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18719         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18720                         keyword, "config");
18721 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18722         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18723                         port_id, UINT16);
18724 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18725         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18726                         item, "tx_metadata");
18727 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18728         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18729                         value, UINT32);
18730
18731 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18732         .f = cmd_config_tx_metadata_specific_parsed,
18733         .data = NULL,
18734         .help_str = "port config <port_id> tx_metadata <value>",
18735         .tokens = {
18736                 (void *)&cmd_config_tx_metadata_specific_port,
18737                 (void *)&cmd_config_tx_metadata_specific_keyword,
18738                 (void *)&cmd_config_tx_metadata_specific_id,
18739                 (void *)&cmd_config_tx_metadata_specific_item,
18740                 (void *)&cmd_config_tx_metadata_specific_value,
18741                 NULL,
18742         },
18743 };
18744
18745 /* *** display tx_metadata per port configuration *** */
18746 struct cmd_show_tx_metadata_result {
18747         cmdline_fixed_string_t cmd_show;
18748         cmdline_fixed_string_t cmd_port;
18749         cmdline_fixed_string_t cmd_keyword;
18750         portid_t cmd_pid;
18751 };
18752
18753 static void
18754 cmd_show_tx_metadata_parsed(void *parsed_result,
18755                 __attribute__((unused)) struct cmdline *cl,
18756                 __attribute__((unused)) void *data)
18757 {
18758         struct cmd_show_tx_metadata_result *res = parsed_result;
18759
18760         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18761                 printf("invalid port id %u\n", res->cmd_pid);
18762                 return;
18763         }
18764         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18765                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18766                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18767         }
18768 }
18769
18770 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18771         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18772                         cmd_show, "show");
18773 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18774         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18775                         cmd_port, "port");
18776 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18777         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18778                         cmd_pid, UINT16);
18779 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18780         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18781                         cmd_keyword, "tx_metadata");
18782
18783 cmdline_parse_inst_t cmd_show_tx_metadata = {
18784         .f = cmd_show_tx_metadata_parsed,
18785         .data = NULL,
18786         .help_str = "show port <port_id> tx_metadata",
18787         .tokens = {
18788                 (void *)&cmd_show_tx_metadata_show,
18789                 (void *)&cmd_show_tx_metadata_port,
18790                 (void *)&cmd_show_tx_metadata_pid,
18791                 (void *)&cmd_show_tx_metadata_keyword,
18792                 NULL,
18793         },
18794 };
18795
18796 /* ******************************************************************************** */
18797
18798 /* list of instructions */
18799 cmdline_parse_ctx_t main_ctx[] = {
18800         (cmdline_parse_inst_t *)&cmd_help_brief,
18801         (cmdline_parse_inst_t *)&cmd_help_long,
18802         (cmdline_parse_inst_t *)&cmd_quit,
18803         (cmdline_parse_inst_t *)&cmd_load_from_file,
18804         (cmdline_parse_inst_t *)&cmd_showport,
18805         (cmdline_parse_inst_t *)&cmd_showqueue,
18806         (cmdline_parse_inst_t *)&cmd_showportall,
18807         (cmdline_parse_inst_t *)&cmd_showdevice,
18808         (cmdline_parse_inst_t *)&cmd_showcfg,
18809         (cmdline_parse_inst_t *)&cmd_showfwdall,
18810         (cmdline_parse_inst_t *)&cmd_start,
18811         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18812         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18813         (cmdline_parse_inst_t *)&cmd_set_link_up,
18814         (cmdline_parse_inst_t *)&cmd_set_link_down,
18815         (cmdline_parse_inst_t *)&cmd_reset,
18816         (cmdline_parse_inst_t *)&cmd_set_numbers,
18817         (cmdline_parse_inst_t *)&cmd_set_log,
18818         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18819         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18820         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18821         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18822         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18823         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18824         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18825         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18826         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18827         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18828         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18829         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18830         (cmdline_parse_inst_t *)&cmd_set_link_check,
18831         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18832         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18833         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18834         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18835 #ifdef RTE_LIBRTE_PMD_BOND
18836         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18837         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18838         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18839         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18840         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18841         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18842         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18843         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18844         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18845         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18846         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18847 #endif
18848         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18849         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18850         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18851         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18852         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18853         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18854         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18855         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18856         (cmdline_parse_inst_t *)&cmd_csum_set,
18857         (cmdline_parse_inst_t *)&cmd_csum_show,
18858         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18859         (cmdline_parse_inst_t *)&cmd_tso_set,
18860         (cmdline_parse_inst_t *)&cmd_tso_show,
18861         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18862         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18863         (cmdline_parse_inst_t *)&cmd_gro_enable,
18864         (cmdline_parse_inst_t *)&cmd_gro_flush,
18865         (cmdline_parse_inst_t *)&cmd_gro_show,
18866         (cmdline_parse_inst_t *)&cmd_gso_enable,
18867         (cmdline_parse_inst_t *)&cmd_gso_size,
18868         (cmdline_parse_inst_t *)&cmd_gso_show,
18869         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18870         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18871         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18872         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18873         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18874         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18875         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18876         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18877         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18878         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18879         (cmdline_parse_inst_t *)&cmd_config_dcb,
18880         (cmdline_parse_inst_t *)&cmd_read_reg,
18881         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18882         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18883         (cmdline_parse_inst_t *)&cmd_write_reg,
18884         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18885         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18886         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18887         (cmdline_parse_inst_t *)&cmd_stop,
18888         (cmdline_parse_inst_t *)&cmd_mac_addr,
18889         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18890         (cmdline_parse_inst_t *)&cmd_set_qmap,
18891         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18892         (cmdline_parse_inst_t *)&cmd_operate_port,
18893         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18894         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18895         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18896         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
18897         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18898         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18899         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18900         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18901         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18902         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18903         (cmdline_parse_inst_t *)&cmd_config_mtu,
18904         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18905         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18906         (cmdline_parse_inst_t *)&cmd_config_rss,
18907         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18908         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18909         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18910         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18911         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18912         (cmdline_parse_inst_t *)&cmd_showport_reta,
18913         (cmdline_parse_inst_t *)&cmd_config_burst,
18914         (cmdline_parse_inst_t *)&cmd_config_thresh,
18915         (cmdline_parse_inst_t *)&cmd_config_threshold,
18916         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18917         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18918         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18919         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18920         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18921         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18922         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18923         (cmdline_parse_inst_t *)&cmd_global_config,
18924         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18925         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18926         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18927         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18928         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18929         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18930         (cmdline_parse_inst_t *)&cmd_dump,
18931         (cmdline_parse_inst_t *)&cmd_dump_one,
18932         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18933         (cmdline_parse_inst_t *)&cmd_syn_filter,
18934         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18935         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18936         (cmdline_parse_inst_t *)&cmd_flex_filter,
18937         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18938         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18939         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18940         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18941         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18942         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18943         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18944         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18945         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18946         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18947         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18948         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18949         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18950         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18951         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18952         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18953         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18954         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18955         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18956         (cmdline_parse_inst_t *)&cmd_flow,
18957         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18958         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18959         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18960         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18961         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18962         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18963         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18964         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18965         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18966         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18967         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18968         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18969         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18970         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18971         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18972         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18973         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18974         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18975         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18976         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18977         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18978         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18979         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18980         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18981         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18982         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18983         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18984         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18985         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18986         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18987         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18988         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18989         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18990         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18991         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18992         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18993         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18994         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18995         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18996         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18997         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18998         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18999         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19000         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19001         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19002         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19003         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19004         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19005         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19006 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19007         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19008 #endif
19009         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19010         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19011         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19012         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19013         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19014         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19015         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19016         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19017         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19018         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19019         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19020         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19021         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19022         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19023         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19024         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19025         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19026         (cmdline_parse_inst_t *)&cmd_ddp_add,
19027         (cmdline_parse_inst_t *)&cmd_ddp_del,
19028         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19029         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19030         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19031         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19032         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19033         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19034         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19035         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19036         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19037         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19038
19039         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19040         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19041         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19042         (cmdline_parse_inst_t *)&cmd_queue_region,
19043         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19044         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19045         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19046         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19047         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19048         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19049         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19050         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19051         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19052         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19053         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19054         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19055         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19056         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19057         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19058         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19059         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19060         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19061         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19062         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19063         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19064         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19065         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19066         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19067         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19068         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19069         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19070         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19071         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19072         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19073         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19074         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19075         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19076         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19077         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19078 #ifdef RTE_LIBRTE_BPF
19079         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19080         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19081 #endif
19082         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19083         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19084         (cmdline_parse_inst_t *)&cmd_set_raw,
19085         NULL,
19086 };
19087
19088 /* read cmdline commands from file */
19089 void
19090 cmdline_read_from_file(const char *filename)
19091 {
19092         struct cmdline *cl;
19093
19094         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19095         if (cl == NULL) {
19096                 printf("Failed to create file based cmdline context: %s\n",
19097                        filename);
19098                 return;
19099         }
19100
19101         cmdline_interact(cl);
19102         cmdline_quit(cl);
19103
19104         cmdline_free(cl);
19105
19106         printf("Read CLI commands from %s\n", filename);
19107 }
19108
19109 /* prompt function, called from main on MASTER lcore */
19110 void
19111 prompt(void)
19112 {
19113         /* initialize non-constant commands */
19114         cmd_set_fwd_mode_init();
19115         cmd_set_fwd_retry_mode_init();
19116
19117         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19118         if (testpmd_cl == NULL)
19119                 return;
19120         cmdline_interact(testpmd_cl);
19121         cmdline_stdin_exit(testpmd_cl);
19122 }
19123
19124 void
19125 prompt_exit(void)
19126 {
19127         if (testpmd_cl != NULL)
19128                 cmdline_quit(testpmd_cl);
19129 }
19130
19131 static void
19132 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19133 {
19134         if (id == (portid_t)RTE_PORT_ALL) {
19135                 portid_t pid;
19136
19137                 RTE_ETH_FOREACH_DEV(pid) {
19138                         /* check if need_reconfig has been set to 1 */
19139                         if (ports[pid].need_reconfig == 0)
19140                                 ports[pid].need_reconfig = dev;
19141                         /* check if need_reconfig_queues has been set to 1 */
19142                         if (ports[pid].need_reconfig_queues == 0)
19143                                 ports[pid].need_reconfig_queues = queue;
19144                 }
19145         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19146                 /* check if need_reconfig has been set to 1 */
19147                 if (ports[id].need_reconfig == 0)
19148                         ports[id].need_reconfig = dev;
19149                 /* check if need_reconfig_queues has been set to 1 */
19150                 if (ports[id].need_reconfig_queues == 0)
19151                         ports[id].need_reconfig_queues = queue;
19152         }
19153 }