app/testpmd: fix GENEVE flow item
[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 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43
44 #include <cmdline_rdline.h>
45 #include <cmdline_parse.h>
46 #include <cmdline_parse_num.h>
47 #include <cmdline_parse_string.h>
48 #include <cmdline_parse_ipaddr.h>
49 #include <cmdline_parse_etheraddr.h>
50 #include <cmdline_socket.h>
51 #include <cmdline.h>
52 #ifdef RTE_LIBRTE_PMD_BOND
53 #include <rte_eth_bond.h>
54 #include <rte_eth_bond_8023ad.h>
55 #endif
56 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
57 #include <rte_pmd_dpaa.h>
58 #endif
59 #ifdef RTE_LIBRTE_IXGBE_PMD
60 #include <rte_pmd_ixgbe.h>
61 #endif
62 #ifdef RTE_LIBRTE_I40E_PMD
63 #include <rte_pmd_i40e.h>
64 #endif
65 #ifdef RTE_LIBRTE_BNXT_PMD
66 #include <rte_pmd_bnxt.h>
67 #endif
68 #include "testpmd.h"
69 #include "cmdline_mtr.h"
70 #include "cmdline_tm.h"
71 #include "bpf_cmd.h"
72
73 static struct cmdline *testpmd_cl;
74
75 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
76
77 /* *** Help command with introduction. *** */
78 struct cmd_help_brief_result {
79         cmdline_fixed_string_t help;
80 };
81
82 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
83                                   struct cmdline *cl,
84                                   __attribute__((unused)) void *data)
85 {
86         cmdline_printf(
87                 cl,
88                 "\n"
89                 "Help is available for the following sections:\n\n"
90                 "    help control                    : Start and stop forwarding.\n"
91                 "    help display                    : Displaying port, stats and config "
92                 "information.\n"
93                 "    help config                     : Configuration information.\n"
94                 "    help ports                      : Configuring ports.\n"
95                 "    help registers                  : Reading and setting port registers.\n"
96                 "    help filters                    : Filters configuration help.\n"
97                 "    help traffic_management         : Traffic Management commmands.\n"
98                 "    help devices                    : Device related cmds.\n"
99                 "    help all                        : All of the above sections.\n\n"
100         );
101
102 }
103
104 cmdline_parse_token_string_t cmd_help_brief_help =
105         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
106
107 cmdline_parse_inst_t cmd_help_brief = {
108         .f = cmd_help_brief_parsed,
109         .data = NULL,
110         .help_str = "help: Show help",
111         .tokens = {
112                 (void *)&cmd_help_brief_help,
113                 NULL,
114         },
115 };
116
117 /* *** Help command with help sections. *** */
118 struct cmd_help_long_result {
119         cmdline_fixed_string_t help;
120         cmdline_fixed_string_t section;
121 };
122
123 static void cmd_help_long_parsed(void *parsed_result,
124                                  struct cmdline *cl,
125                                  __attribute__((unused)) void *data)
126 {
127         int show_all = 0;
128         struct cmd_help_long_result *res = parsed_result;
129
130         if (!strcmp(res->section, "all"))
131                 show_all = 1;
132
133         if (show_all || !strcmp(res->section, "control")) {
134
135                 cmdline_printf(
136                         cl,
137                         "\n"
138                         "Control forwarding:\n"
139                         "-------------------\n\n"
140
141                         "start\n"
142                         "    Start packet forwarding with current configuration.\n\n"
143
144                         "start tx_first\n"
145                         "    Start packet forwarding with current config"
146                         " after sending one burst of packets.\n\n"
147
148                         "stop\n"
149                         "    Stop packet forwarding, and display accumulated"
150                         " statistics.\n\n"
151
152                         "quit\n"
153                         "    Quit to prompt.\n\n"
154                 );
155         }
156
157         if (show_all || !strcmp(res->section, "display")) {
158
159                 cmdline_printf(
160                         cl,
161                         "\n"
162                         "Display:\n"
163                         "--------\n\n"
164
165                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
166                         "    Display information for port_id, or all.\n\n"
167
168                         "show port X rss reta (size) (mask0,mask1,...)\n"
169                         "    Display the rss redirection table entry indicated"
170                         " by masks on port X. size is used to indicate the"
171                         " hardware supported reta size\n\n"
172
173                         "show port (port_id) rss-hash [key]\n"
174                         "    Display the RSS hash functions and RSS hash key of port\n\n"
175
176                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
177                         "    Clear information for port_id, or all.\n\n"
178
179                         "show (rxq|txq) info (port_id) (queue_id)\n"
180                         "    Display information for configured RX/TX queue.\n\n"
181
182                         "show config (rxtx|cores|fwd|txpkts)\n"
183                         "    Display the given configuration.\n\n"
184
185                         "read rxd (port_id) (queue_id) (rxd_id)\n"
186                         "    Display an RX descriptor of a port RX queue.\n\n"
187
188                         "read txd (port_id) (queue_id) (txd_id)\n"
189                         "    Display a TX descriptor of a port TX queue.\n\n"
190
191                         "ddp get list (port_id)\n"
192                         "    Get ddp profile info list\n\n"
193
194                         "ddp get info (profile_path)\n"
195                         "    Get ddp profile information.\n\n"
196
197                         "show vf stats (port_id) (vf_id)\n"
198                         "    Display a VF's statistics.\n\n"
199
200                         "clear vf stats (port_id) (vf_id)\n"
201                         "    Reset a VF's statistics.\n\n"
202
203                         "show port (port_id) pctype mapping\n"
204                         "    Get flow ptype to pctype mapping on a port\n\n"
205
206                         "show port meter stats (port_id) (meter_id) (clear)\n"
207                         "    Get meter stats on a port\n\n"
208
209                         "show fwd stats all\n"
210                         "    Display statistics for all fwd engines.\n\n"
211
212                         "clear fwd stats all\n"
213                         "    Clear statistics for all fwd engines.\n\n"
214
215                         "show port (port_id) rx_offload capabilities\n"
216                         "    List all per queue and per port Rx offloading"
217                         " capabilities of a port\n\n"
218
219                         "show port (port_id) rx_offload configuration\n"
220                         "    List port level and all queue level"
221                         " Rx offloading configuration\n\n"
222
223                         "show port (port_id) tx_offload capabilities\n"
224                         "    List all per queue and per port"
225                         " Tx offloading capabilities of a port\n\n"
226
227                         "show port (port_id) tx_offload configuration\n"
228                         "    List port level and all queue level"
229                         " Tx offloading configuration\n\n"
230
231                         "show port (port_id) tx_metadata\n"
232                         "    Show Tx metadata value set"
233                         " for a specific port\n\n"
234
235                         "show port (port_id) ptypes\n"
236                         "    Show port supported ptypes"
237                         " for a specific port\n\n"
238
239                         "show device info (<identifier>|all)"
240                         "       Show general information about devices probed.\n\n"
241
242                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
243                         "       Show status of rx|tx descriptor.\n\n"
244
245                         "show port (port_id) macs|mcast_macs"
246                         "       Display list of mac addresses added to port.\n\n"
247                 );
248         }
249
250         if (show_all || !strcmp(res->section, "config")) {
251                 cmdline_printf(
252                         cl,
253                         "\n"
254                         "Configuration:\n"
255                         "--------------\n"
256                         "Configuration changes only become active when"
257                         " forwarding is started/restarted.\n\n"
258
259                         "set default\n"
260                         "    Reset forwarding to the default configuration.\n\n"
261
262                         "set verbose (level)\n"
263                         "    Set the debug verbosity level X.\n\n"
264
265                         "set log global|(type) (level)\n"
266                         "    Set the log level.\n\n"
267
268                         "set nbport (num)\n"
269                         "    Set number of ports.\n\n"
270
271                         "set nbcore (num)\n"
272                         "    Set number of cores.\n\n"
273
274                         "set coremask (mask)\n"
275                         "    Set the forwarding cores hexadecimal mask.\n\n"
276
277                         "set portmask (mask)\n"
278                         "    Set the forwarding ports hexadecimal mask.\n\n"
279
280                         "set burst (num)\n"
281                         "    Set number of packets per burst.\n\n"
282
283                         "set burst tx delay (microseconds) retry (num)\n"
284                         "    Set the transmit delay time and number of retries,"
285                         " effective when retry is enabled.\n\n"
286
287                         "set txpkts (x[,y]*)\n"
288                         "    Set the length of each segment of TXONLY"
289                         " and optionally CSUM packets.\n\n"
290
291                         "set txsplit (off|on|rand)\n"
292                         "    Set the split policy for the TX packets."
293                         " Right now only applicable for CSUM and TXONLY"
294                         " modes\n\n"
295
296                         "set corelist (x[,y]*)\n"
297                         "    Set the list of forwarding cores.\n\n"
298
299                         "set portlist (x[,y]*)\n"
300                         "    Set the list of forwarding ports.\n\n"
301
302                         "set port setup on (iterator|event)\n"
303                         "    Select how attached port is retrieved for setup.\n\n"
304
305                         "set tx loopback (port_id) (on|off)\n"
306                         "    Enable or disable tx loopback.\n\n"
307
308                         "set all queues drop (port_id) (on|off)\n"
309                         "    Set drop enable bit for all queues.\n\n"
310
311                         "set vf split drop (port_id) (vf_id) (on|off)\n"
312                         "    Set split drop enable bit for a VF from the PF.\n\n"
313
314                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
315                         "    Set MAC antispoof for a VF from the PF.\n\n"
316
317                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
318                         "    Enable MACsec offload.\n\n"
319
320                         "set macsec offload (port_id) off\n"
321                         "    Disable MACsec offload.\n\n"
322
323                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
324                         "    Configure MACsec secure connection (SC).\n\n"
325
326                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
327                         "    Configure MACsec secure association (SA).\n\n"
328
329                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
330                         "    Set VF broadcast for a VF from the PF.\n\n"
331
332                         "vlan set stripq (on|off) (port_id,queue_id)\n"
333                         "    Set the VLAN strip for a queue on a port.\n\n"
334
335                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
336                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
337
338                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
339                         "    Set VLAN insert for a VF from the PF.\n\n"
340
341                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
342                         "    Set VLAN antispoof for a VF from the PF.\n\n"
343
344                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
345                         "    Set VLAN tag for a VF from the PF.\n\n"
346
347                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
348                         "    Set a VF's max bandwidth(Mbps).\n\n"
349
350                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
351                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
352
353                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
354                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
355
356                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
357                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
358
359                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
360                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
361
362                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
363                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
364
365                         "vlan set (inner|outer) tpid (value) (port_id)\n"
366                         "    Set the VLAN TPID for Packet Filtering on"
367                         " a port\n\n"
368
369                         "rx_vlan add (vlan_id|all) (port_id)\n"
370                         "    Add a vlan_id, or all identifiers, to the set"
371                         " of VLAN identifiers filtered by port_id.\n\n"
372
373                         "rx_vlan rm (vlan_id|all) (port_id)\n"
374                         "    Remove a vlan_id, or all identifiers, from the set"
375                         " of VLAN identifiers filtered by port_id.\n\n"
376
377                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
378                         "    Add a vlan_id, to the set of VLAN identifiers"
379                         "filtered for VF(s) from port_id.\n\n"
380
381                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
382                         "    Remove a vlan_id, to the set of VLAN identifiers"
383                         "filtered for VF(s) from port_id.\n\n"
384
385                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
386                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
387                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
388                         "   add a tunnel filter of a port.\n\n"
389
390                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
391                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
392                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
393                         "   remove a tunnel filter of a port.\n\n"
394
395                         "rx_vxlan_port add (udp_port) (port_id)\n"
396                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
397
398                         "rx_vxlan_port rm (udp_port) (port_id)\n"
399                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
400
401                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
402                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
403                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
404
405                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
406                         "    Set port based TX VLAN insertion.\n\n"
407
408                         "tx_vlan reset (port_id)\n"
409                         "    Disable hardware insertion of a VLAN header in"
410                         " packets sent on a port.\n\n"
411
412                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
413                         "    Select hardware or software calculation of the"
414                         " checksum when transmitting a packet using the"
415                         " csum forward engine.\n"
416                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
417                         "    outer-ip concerns the outer IP layer in"
418                         "    outer-udp concerns the outer UDP layer in"
419                         " case the packet is recognized as a tunnel packet by"
420                         " the forward engine (vxlan, gre and ipip are supported)\n"
421                         "    Please check the NIC datasheet for HW limits.\n\n"
422
423                         "csum parse-tunnel (on|off) (tx_port_id)\n"
424                         "    If disabled, treat tunnel packets as non-tunneled"
425                         " packets (treat inner headers as payload). The port\n"
426                         "    argument is the port used for TX in csum forward"
427                         " engine.\n\n"
428
429                         "csum show (port_id)\n"
430                         "    Display tx checksum offload configuration\n\n"
431
432                         "tso set (segsize) (portid)\n"
433                         "    Enable TCP Segmentation Offload in csum forward"
434                         " engine.\n"
435                         "    Please check the NIC datasheet for HW limits.\n\n"
436
437                         "tso show (portid)"
438                         "    Display the status of TCP Segmentation Offload.\n\n"
439
440                         "set port (port_id) gro on|off\n"
441                         "    Enable or disable Generic Receive Offload in"
442                         " csum forwarding engine.\n\n"
443
444                         "show port (port_id) gro\n"
445                         "    Display GRO configuration.\n\n"
446
447                         "set gro flush (cycles)\n"
448                         "    Set the cycle to flush GROed packets from"
449                         " reassembly tables.\n\n"
450
451                         "set port (port_id) gso (on|off)"
452                         "    Enable or disable Generic Segmentation Offload in"
453                         " csum forwarding engine.\n\n"
454
455                         "set gso segsz (length)\n"
456                         "    Set max packet length for output GSO segments,"
457                         " including packet header and payload.\n\n"
458
459                         "show port (port_id) gso\n"
460                         "    Show GSO configuration.\n\n"
461
462                         "set fwd (%s)\n"
463                         "    Set packet forwarding mode.\n\n"
464
465                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
466                         "    Add a MAC address on port_id.\n\n"
467
468                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
469                         "    Remove a MAC address from port_id.\n\n"
470
471                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
472                         "    Set the default MAC address for port_id.\n\n"
473
474                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
475                         "    Add a MAC address for a VF on the port.\n\n"
476
477                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Set the MAC address for a VF from the PF.\n\n"
479
480                         "set eth-peer (port_id) (peer_addr)\n"
481                         "    set the peer address for certain port.\n\n"
482
483                         "set port (port_id) uta (mac_address|all) (on|off)\n"
484                         "    Add/Remove a or all unicast hash filter(s)"
485                         "from port X.\n\n"
486
487                         "set promisc (port_id|all) (on|off)\n"
488                         "    Set the promiscuous mode on port_id, or all.\n\n"
489
490                         "set allmulti (port_id|all) (on|off)\n"
491                         "    Set the allmulti mode on port_id, or all.\n\n"
492
493                         "set vf promisc (port_id) (vf_id) (on|off)\n"
494                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
495
496                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
497                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
498
499                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
500                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
501                         " (on|off) autoneg (on|off) (port_id)\n"
502                         "set flow_ctrl rx (on|off) (portid)\n"
503                         "set flow_ctrl tx (on|off) (portid)\n"
504                         "set flow_ctrl high_water (high_water) (portid)\n"
505                         "set flow_ctrl low_water (low_water) (portid)\n"
506                         "set flow_ctrl pause_time (pause_time) (portid)\n"
507                         "set flow_ctrl send_xon (send_xon) (portid)\n"
508                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
509                         "set flow_ctrl autoneg (on|off) (port_id)\n"
510                         "    Set the link flow control parameter on a port.\n\n"
511
512                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
513                         " (low_water) (pause_time) (priority) (port_id)\n"
514                         "    Set the priority flow control parameter on a"
515                         " port.\n\n"
516
517                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
518                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
519                         " queue on port.\n"
520                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
521                         " on port 0 to mapping 5.\n\n"
522
523                         "set xstats-hide-zero on|off\n"
524                         "    Set the option to hide the zero values"
525                         " for xstats display.\n"
526
527                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
528                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
529
530                         "set port (port_id) vf (vf_id) (mac_addr)"
531                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
532                         "   Add/Remove unicast or multicast MAC addr filter"
533                         " for a VF.\n\n"
534
535                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
536                         "|MPE) (on|off)\n"
537                         "    AUPE:accepts untagged VLAN;"
538                         "ROPE:accept unicast hash\n\n"
539                         "    BAM:accepts broadcast packets;"
540                         "MPE:accepts all multicast packets\n\n"
541                         "    Enable/Disable a VF receive mode of a port\n\n"
542
543                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
544                         "    Set rate limit for a queue of a port\n\n"
545
546                         "set port (port_id) vf (vf_id) rate (rate_num) "
547                         "queue_mask (queue_mask_value)\n"
548                         "    Set rate limit for queues in VF of a port\n\n"
549
550                         "set port (port_id) mirror-rule (rule_id)"
551                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
552                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
553                         "   Set pool or vlan type mirror rule on a port.\n"
554                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
555                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
556                         " to pool 0.\n\n"
557
558                         "set port (port_id) mirror-rule (rule_id)"
559                         " (uplink-mirror|downlink-mirror) dst-pool"
560                         " (pool_id) (on|off)\n"
561                         "   Set uplink or downlink type mirror rule on a port.\n"
562                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
563                         " 0 on' enable mirror income traffic to pool 0.\n\n"
564
565                         "reset port (port_id) mirror-rule (rule_id)\n"
566                         "   Reset a mirror rule.\n\n"
567
568                         "set flush_rx (on|off)\n"
569                         "   Flush (default) or don't flush RX streams before"
570                         " forwarding. Mainly used with PCAP drivers.\n\n"
571
572                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
573                         "   Set the bypass mode for the lowest port on bypass enabled"
574                         " NIC.\n\n"
575
576                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
577                         "mode (normal|bypass|isolate) (port_id)\n"
578                         "   Set the event required to initiate specified bypass mode for"
579                         " the lowest port on a bypass enabled NIC where:\n"
580                         "       timeout   = enable bypass after watchdog timeout.\n"
581                         "       os_on     = enable bypass when OS/board is powered on.\n"
582                         "       os_off    = enable bypass when OS/board is powered off.\n"
583                         "       power_on  = enable bypass when power supply is turned on.\n"
584                         "       power_off = enable bypass when power supply is turned off."
585                         "\n\n"
586
587                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
588                         "   Set the bypass watchdog timeout to 'n' seconds"
589                         " where 0 = instant.\n\n"
590
591                         "show bypass config (port_id)\n"
592                         "   Show the bypass configuration for a bypass enabled NIC"
593                         " using the lowest port on the NIC.\n\n"
594
595 #ifdef RTE_LIBRTE_PMD_BOND
596                         "create bonded device (mode) (socket)\n"
597                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
598
599                         "add bonding slave (slave_id) (port_id)\n"
600                         "       Add a slave device to a bonded device.\n\n"
601
602                         "remove bonding slave (slave_id) (port_id)\n"
603                         "       Remove a slave device from a bonded device.\n\n"
604
605                         "set bonding mode (value) (port_id)\n"
606                         "       Set the bonding mode on a bonded device.\n\n"
607
608                         "set bonding primary (slave_id) (port_id)\n"
609                         "       Set the primary slave for a bonded device.\n\n"
610
611                         "show bonding config (port_id)\n"
612                         "       Show the bonding config for port_id.\n\n"
613
614                         "set bonding mac_addr (port_id) (address)\n"
615                         "       Set the MAC address of a bonded device.\n\n"
616
617                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
618                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
619
620                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
621                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
622
623                         "set bonding mon_period (port_id) (value)\n"
624                         "       Set the bonding link status monitoring polling period in ms.\n\n"
625
626                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
627                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
628
629 #endif
630                         "set link-up port (port_id)\n"
631                         "       Set link up for a port.\n\n"
632
633                         "set link-down port (port_id)\n"
634                         "       Set link down for a port.\n\n"
635
636                         "E-tag set insertion on port-tag-id (value)"
637                         " port (port_id) vf (vf_id)\n"
638                         "    Enable E-tag insertion for a VF on a port\n\n"
639
640                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
641                         "    Disable E-tag insertion for a VF on a port\n\n"
642
643                         "E-tag set stripping (on|off) port (port_id)\n"
644                         "    Enable/disable E-tag stripping on a port\n\n"
645
646                         "E-tag set forwarding (on|off) port (port_id)\n"
647                         "    Enable/disable E-tag based forwarding"
648                         " on a port\n\n"
649
650                         "E-tag set filter add e-tag-id (value) dst-pool"
651                         " (pool_id) port (port_id)\n"
652                         "    Add an E-tag forwarding filter on a port\n\n"
653
654                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
655                         "    Delete an E-tag forwarding filter on a port\n\n"
656
657                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
658                         "    Load a profile package on a port\n\n"
659
660                         "ddp del (port_id) (backup_profile_path)\n"
661                         "    Delete a profile package from a port\n\n"
662
663                         "ptype mapping get (port_id) (valid_only)\n"
664                         "    Get ptype mapping on a port\n\n"
665
666                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
667                         "    Replace target with the pkt_type in ptype mapping\n\n"
668
669                         "ptype mapping reset (port_id)\n"
670                         "    Reset ptype mapping on a port\n\n"
671
672                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
673                         "    Update a ptype mapping item on a port\n\n"
674
675                         "set port (port_id) ptype_mask (ptype_mask)\n"
676                         "    set packet types classification for a specific port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "queue_start_index (value) queue_num (value)\n"
680                         "    Set a queue region on a port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "flowtype (value)\n"
684                         "    Set a flowtype region index on a port\n\n"
685
686                         "set port (port_id) queue-region UP (value) region_id (value)\n"
687                         "    Set the mapping of User Priority to "
688                         "queue region on a port\n\n"
689
690                         "set port (port_id) queue-region flush (on|off)\n"
691                         "    flush all queue region related configuration\n\n"
692
693                         "show port meter cap (port_id)\n"
694                         "    Show port meter capability information\n\n"
695
696                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
697                         "    meter profile add - srtcm rfc 2697\n\n"
698
699                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
700                         "    meter profile add - trtcm rfc 2698\n\n"
701
702                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
703                         "    meter profile add - trtcm rfc 4115\n\n"
704
705                         "del port meter profile (port_id) (profile_id)\n"
706                         "    meter profile delete\n\n"
707
708                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
709                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
710                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
711                         "(dscp_tbl_entry63)]\n"
712                         "    meter create\n\n"
713
714                         "enable port meter (port_id) (mtr_id)\n"
715                         "    meter enable\n\n"
716
717                         "disable port meter (port_id) (mtr_id)\n"
718                         "    meter disable\n\n"
719
720                         "del port meter (port_id) (mtr_id)\n"
721                         "    meter delete\n\n"
722
723                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
724                         "    meter update meter profile\n\n"
725
726                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
727                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
728                         "    update meter dscp table entries\n\n"
729
730                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
731                         "(action0) [(action1) (action2)]\n"
732                         "    meter update policer action\n\n"
733
734                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
735                         "    meter update stats\n\n"
736
737                         "show port (port_id) queue-region\n"
738                         "    show all queue region related configuration info\n\n"
739
740                         , list_pkt_forwarding_modes()
741                 );
742         }
743
744         if (show_all || !strcmp(res->section, "ports")) {
745
746                 cmdline_printf(
747                         cl,
748                         "\n"
749                         "Port Operations:\n"
750                         "----------------\n\n"
751
752                         "port start (port_id|all)\n"
753                         "    Start all ports or port_id.\n\n"
754
755                         "port stop (port_id|all)\n"
756                         "    Stop all ports or port_id.\n\n"
757
758                         "port close (port_id|all)\n"
759                         "    Close all ports or port_id.\n\n"
760
761                         "port reset (port_id|all)\n"
762                         "    Reset all ports or port_id.\n\n"
763
764                         "port attach (ident)\n"
765                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
766
767                         "port detach (port_id)\n"
768                         "    Detach physical or virtual dev by port_id\n\n"
769
770                         "port config (port_id|all)"
771                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
772                         " duplex (half|full|auto)\n"
773                         "    Set speed and duplex for all ports or port_id\n\n"
774
775                         "port config (port_id|all) loopback (mode)\n"
776                         "    Set loopback mode for all ports or port_id\n\n"
777
778                         "port config all (rxq|txq|rxd|txd) (value)\n"
779                         "    Set number for rxq/txq/rxd/txd.\n\n"
780
781                         "port config all max-pkt-len (value)\n"
782                         "    Set the max packet length.\n\n"
783
784                         "port config all max-lro-pkt-size (value)\n"
785                         "    Set the max LRO aggregated packet size.\n\n"
786
787                         "port config all drop-en (on|off)\n"
788                         "    Enable or disable packet drop on all RX queues of all ports when no "
789                         "receive buffers available.\n\n"
790
791                         "port config all rss (all|default|ip|tcp|udp|sctp|"
792                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
793                         "    Set the RSS mode.\n\n"
794
795                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
796                         "    Set the RSS redirection table.\n\n"
797
798                         "port config (port_id) dcb vt (on|off) (traffic_class)"
799                         " pfc (on|off)\n"
800                         "    Set the DCB mode.\n\n"
801
802                         "port config all burst (value)\n"
803                         "    Set the number of packets per burst.\n\n"
804
805                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
806                         " (value)\n"
807                         "    Set the ring prefetch/host/writeback threshold"
808                         " for tx/rx queue.\n\n"
809
810                         "port config all (txfreet|txrst|rxfreet) (value)\n"
811                         "    Set free threshold for rx/tx, or set"
812                         " tx rs bit threshold.\n\n"
813                         "port config mtu X value\n"
814                         "    Set the MTU of port X to a given value\n\n"
815
816                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
817                         "    Set a rx/tx queue's ring size configuration, the new"
818                         " value will take effect after command that (re-)start the port"
819                         " or command that setup the specific queue\n\n"
820
821                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
822                         "    Start/stop a rx/tx queue of port X. Only take effect"
823                         " when port X is started\n\n"
824
825                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
826                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
827                         " take effect when port X is stopped.\n\n"
828
829                         "port (port_id) (rxq|txq) (queue_id) setup\n"
830                         "    Setup a rx/tx queue of port X.\n\n"
831
832                         "port config (port_id|all) l2-tunnel E-tag ether-type"
833                         " (value)\n"
834                         "    Set the value of E-tag ether-type.\n\n"
835
836                         "port config (port_id|all) l2-tunnel E-tag"
837                         " (enable|disable)\n"
838                         "    Enable/disable the E-tag support.\n\n"
839
840                         "port config (port_id) pctype mapping reset\n"
841                         "    Reset flow type to pctype mapping on a port\n\n"
842
843                         "port config (port_id) pctype mapping update"
844                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
845                         "    Update a flow type to pctype mapping item on a port\n\n"
846
847                         "port config (port_id) pctype (pctype_id) hash_inset|"
848                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
849                         " (field_idx)\n"
850                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
851
852                         "port config (port_id) pctype (pctype_id) hash_inset|"
853                         "fdir_inset|fdir_flx_inset clear all"
854                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
855
856                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
857                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
858
859                         "port config <port_id> rx_offload vlan_strip|"
860                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
861                         "outer_ipv4_cksum|macsec_strip|header_split|"
862                         "vlan_filter|vlan_extend|jumbo_frame|"
863                         "scatter|timestamp|security|keep_crc on|off\n"
864                         "     Enable or disable a per port Rx offloading"
865                         " on all Rx queues of a port\n\n"
866
867                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
868                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
869                         "outer_ipv4_cksum|macsec_strip|header_split|"
870                         "vlan_filter|vlan_extend|jumbo_frame|"
871                         "scatter|timestamp|security|keep_crc on|off\n"
872                         "    Enable or disable a per queue Rx offloading"
873                         " only on a specific Rx queue\n\n"
874
875                         "port config (port_id) tx_offload vlan_insert|"
876                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
877                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
878                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
879                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
880                         "security on|off\n"
881                         "    Enable or disable a per port Tx offloading"
882                         " on all Tx queues of a port\n\n"
883
884                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
885                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
886                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
887                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
888                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
889                         " on|off\n"
890                         "    Enable or disable a per queue Tx offloading"
891                         " only on a specific Tx queue\n\n"
892
893                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
894                         "    Load an eBPF program as a callback"
895                         " for particular RX/TX queue\n\n"
896
897                         "bpf-unload rx|tx (port) (queue)\n"
898                         "    Unload previously loaded eBPF program"
899                         " for particular RX/TX queue\n\n"
900
901                         "port config (port_id) tx_metadata (value)\n"
902                         "    Set Tx metadata value per port. Testpmd will add this value"
903                         " to any Tx packet sent from this port\n\n"
904                 );
905         }
906
907         if (show_all || !strcmp(res->section, "registers")) {
908
909                 cmdline_printf(
910                         cl,
911                         "\n"
912                         "Registers:\n"
913                         "----------\n\n"
914
915                         "read reg (port_id) (address)\n"
916                         "    Display value of a port register.\n\n"
917
918                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
919                         "    Display a port register bit field.\n\n"
920
921                         "read regbit (port_id) (address) (bit_x)\n"
922                         "    Display a single port register bit.\n\n"
923
924                         "write reg (port_id) (address) (value)\n"
925                         "    Set value of a port register.\n\n"
926
927                         "write regfield (port_id) (address) (bit_x) (bit_y)"
928                         " (value)\n"
929                         "    Set bit field of a port register.\n\n"
930
931                         "write regbit (port_id) (address) (bit_x) (value)\n"
932                         "    Set single bit value of a port register.\n\n"
933                 );
934         }
935         if (show_all || !strcmp(res->section, "filters")) {
936
937                 cmdline_printf(
938                         cl,
939                         "\n"
940                         "filters:\n"
941                         "--------\n\n"
942
943                         "ethertype_filter (port_id) (add|del)"
944                         " (mac_addr|mac_ignr) (mac_address) ethertype"
945                         " (ether_type) (drop|fwd) queue (queue_id)\n"
946                         "    Add/Del an ethertype filter.\n\n"
947
948                         "2tuple_filter (port_id) (add|del)"
949                         " dst_port (dst_port_value) protocol (protocol_value)"
950                         " mask (mask_value) tcp_flags (tcp_flags_value)"
951                         " priority (prio_value) queue (queue_id)\n"
952                         "    Add/Del a 2tuple filter.\n\n"
953
954                         "5tuple_filter (port_id) (add|del)"
955                         " dst_ip (dst_address) src_ip (src_address)"
956                         " dst_port (dst_port_value) src_port (src_port_value)"
957                         " protocol (protocol_value)"
958                         " mask (mask_value) tcp_flags (tcp_flags_value)"
959                         " priority (prio_value) queue (queue_id)\n"
960                         "    Add/Del a 5tuple filter.\n\n"
961
962                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
963                         "    Add/Del syn filter.\n\n"
964
965                         "flex_filter (port_id) (add|del) len (len_value)"
966                         " bytes (bytes_value) mask (mask_value)"
967                         " priority (prio_value) queue (queue_id)\n"
968                         "    Add/Del a flex filter.\n\n"
969
970                         "flow_director_filter (port_id) mode IP (add|del|update)"
971                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
972                         " src (src_ip_address) dst (dst_ip_address)"
973                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
974                         " vlan (vlan_value) flexbytes (flexbytes_value)"
975                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
976                         " fd_id (fd_id_value)\n"
977                         "    Add/Del an IP type flow director filter.\n\n"
978
979                         "flow_director_filter (port_id) mode IP (add|del|update)"
980                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
981                         " src (src_ip_address) (src_port)"
982                         " dst (dst_ip_address) (dst_port)"
983                         " tos (tos_value) ttl (ttl_value)"
984                         " vlan (vlan_value) flexbytes (flexbytes_value)"
985                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
986                         " fd_id (fd_id_value)\n"
987                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
988
989                         "flow_director_filter (port_id) mode IP (add|del|update)"
990                         " flow (ipv4-sctp|ipv6-sctp)"
991                         " src (src_ip_address) (src_port)"
992                         " dst (dst_ip_address) (dst_port)"
993                         " tag (verification_tag) "
994                         " tos (tos_value) ttl (ttl_value)"
995                         " vlan (vlan_value)"
996                         " flexbytes (flexbytes_value) (drop|fwd)"
997                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
998                         "    Add/Del a SCTP type flow director filter.\n\n"
999
1000                         "flow_director_filter (port_id) mode IP (add|del|update)"
1001                         " flow l2_payload ether (ethertype)"
1002                         " flexbytes (flexbytes_value) (drop|fwd)"
1003                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1004                         "    Add/Del a l2 payload type flow director filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1007                         " mac (mac_address) vlan (vlan_value)"
1008                         " flexbytes (flexbytes_value) (drop|fwd)"
1009                         " queue (queue_id) fd_id (fd_id_value)\n"
1010                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1011
1012                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1013                         " mac (mac_address) vlan (vlan_value)"
1014                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1015                         " flexbytes (flexbytes_value) (drop|fwd)"
1016                         " queue (queue_id) fd_id (fd_id_value)\n"
1017                         "    Add/Del a Tunnel flow director filter.\n\n"
1018
1019                         "flow_director_filter (port_id) mode raw (add|del|update)"
1020                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1021                         " fd_id (fd_id_value) packet (packet file name)\n"
1022                         "    Add/Del a raw type flow director filter.\n\n"
1023
1024                         "flush_flow_director (port_id)\n"
1025                         "    Flush all flow director entries of a device.\n\n"
1026
1027                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1028                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1029                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1030                         "    Set flow director IP mask.\n\n"
1031
1032                         "flow_director_mask (port_id) mode MAC-VLAN"
1033                         " vlan (vlan_value)\n"
1034                         "    Set flow director MAC-VLAN mask.\n\n"
1035
1036                         "flow_director_mask (port_id) mode Tunnel"
1037                         " vlan (vlan_value) mac (mac_value)"
1038                         " tunnel-type (tunnel_type_value)"
1039                         " tunnel-id (tunnel_id_value)\n"
1040                         "    Set flow director Tunnel mask.\n\n"
1041
1042                         "flow_director_flex_mask (port_id)"
1043                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1044                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1045                         " (mask)\n"
1046                         "    Configure mask of flex payload.\n\n"
1047
1048                         "flow_director_flex_payload (port_id)"
1049                         " (raw|l2|l3|l4) (config)\n"
1050                         "    Configure flex payload selection.\n\n"
1051
1052                         "get_sym_hash_ena_per_port (port_id)\n"
1053                         "    get symmetric hash enable configuration per port.\n\n"
1054
1055                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1056                         "    set symmetric hash enable configuration per port"
1057                         " to enable or disable.\n\n"
1058
1059                         "get_hash_global_config (port_id)\n"
1060                         "    Get the global configurations of hash filters.\n\n"
1061
1062                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1063                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1064                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1065                         " (enable|disable)\n"
1066                         "    Set the global configurations of hash filters.\n\n"
1067
1068                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1069                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1070                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1071                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1072                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1073                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1074                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1075                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1076                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1077                         "fld-8th|none) (select|add)\n"
1078                         "    Set the input set for hash.\n\n"
1079
1080                         "set_fdir_input_set (port_id) "
1081                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1082                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1083                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1084                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1085                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1086                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1087                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1088                         " (select|add)\n"
1089                         "    Set the input set for FDir.\n\n"
1090
1091                         "flow validate {port_id}"
1092                         " [group {group_id}] [priority {level}]"
1093                         " [ingress] [egress]"
1094                         " pattern {item} [/ {item} [...]] / end"
1095                         " actions {action} [/ {action} [...]] / end\n"
1096                         "    Check whether a flow rule can be created.\n\n"
1097
1098                         "flow create {port_id}"
1099                         " [group {group_id}] [priority {level}]"
1100                         " [ingress] [egress]"
1101                         " pattern {item} [/ {item} [...]] / end"
1102                         " actions {action} [/ {action} [...]] / end\n"
1103                         "    Create a flow rule.\n\n"
1104
1105                         "flow destroy {port_id} rule {rule_id} [...]\n"
1106                         "    Destroy specific flow rules.\n\n"
1107
1108                         "flow flush {port_id}\n"
1109                         "    Destroy all flow rules.\n\n"
1110
1111                         "flow query {port_id} {rule_id} {action}\n"
1112                         "    Query an existing flow rule.\n\n"
1113
1114                         "flow list {port_id} [group {group_id}] [...]\n"
1115                         "    List existing flow rules sorted by priority,"
1116                         " filtered by group identifiers.\n\n"
1117
1118                         "flow isolate {port_id} {boolean}\n"
1119                         "    Restrict ingress traffic to the defined"
1120                         " flow rules\n\n"
1121
1122                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1123                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1124                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1125                         "       Configure the VXLAN encapsulation for flows.\n\n"
1126
1127                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1128                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1129                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1130                         " eth-dst (eth-dst)\n"
1131                         "       Configure the VXLAN encapsulation for flows.\n\n"
1132
1133                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1134                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1135                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1136                         " eth-dst (eth-dst)\n"
1137                         "       Configure the VXLAN encapsulation for flows.\n\n"
1138
1139                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1140                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1141                         " (eth-dst)\n"
1142                         "       Configure the NVGRE encapsulation for flows.\n\n"
1143
1144                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1145                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1146                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1147                         "       Configure the NVGRE encapsulation for flows.\n\n"
1148
1149                         "set raw_encap {flow items}\n"
1150                         "       Configure the encapsulation with raw data.\n\n"
1151
1152                         "set raw_decap {flow items}\n"
1153                         "       Configure the decapsulation with raw data.\n\n"
1154
1155                 );
1156         }
1157
1158         if (show_all || !strcmp(res->section, "traffic_management")) {
1159                 cmdline_printf(
1160                         cl,
1161                         "\n"
1162                         "Traffic Management:\n"
1163                         "--------------\n"
1164                         "show port tm cap (port_id)\n"
1165                         "       Display the port TM capability.\n\n"
1166
1167                         "show port tm level cap (port_id) (level_id)\n"
1168                         "       Display the port TM hierarchical level capability.\n\n"
1169
1170                         "show port tm node cap (port_id) (node_id)\n"
1171                         "       Display the port TM node capability.\n\n"
1172
1173                         "show port tm node type (port_id) (node_id)\n"
1174                         "       Display the port TM node type.\n\n"
1175
1176                         "show port tm node stats (port_id) (node_id) (clear)\n"
1177                         "       Display the port TM node stats.\n\n"
1178
1179 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1180                         "set port tm hierarchy default (port_id)\n"
1181                         "       Set default traffic Management hierarchy on a port\n\n"
1182 #endif
1183
1184                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1185                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1186                         " (packet_length_adjust)\n"
1187                         "       Add port tm node private shaper profile.\n\n"
1188
1189                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1190                         "       Delete port tm node private shaper profile.\n\n"
1191
1192                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1193                         " (shaper_profile_id)\n"
1194                         "       Add/update port tm node shared shaper.\n\n"
1195
1196                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1197                         "       Delete port tm node shared shaper.\n\n"
1198
1199                         "set port tm node shaper profile (port_id) (node_id)"
1200                         " (shaper_profile_id)\n"
1201                         "       Set port tm node shaper profile.\n\n"
1202
1203                         "add port tm node wred profile (port_id) (wred_profile_id)"
1204                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1205                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1206                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1207                         "       Add port tm node wred profile.\n\n"
1208
1209                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1210                         "       Delete port tm node wred profile.\n\n"
1211
1212                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1213                         " (priority) (weight) (level_id) (shaper_profile_id)"
1214                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1215                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1216                         "       Add port tm nonleaf node.\n\n"
1217
1218                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1219                         " (priority) (weight) (level_id) (shaper_profile_id)"
1220                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1221                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1222                         "       Add port tm leaf node.\n\n"
1223
1224                         "del port tm node (port_id) (node_id)\n"
1225                         "       Delete port tm node.\n\n"
1226
1227                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1228                         " (priority) (weight)\n"
1229                         "       Set port tm node parent.\n\n"
1230
1231                         "suspend port tm node (port_id) (node_id)"
1232                         "       Suspend tm node.\n\n"
1233
1234                         "resume port tm node (port_id) (node_id)"
1235                         "       Resume tm node.\n\n"
1236
1237                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1238                         "       Commit tm hierarchy.\n\n"
1239
1240                         "set port tm mark ip_ecn (port) (green) (yellow)"
1241                         " (red)\n"
1242                         "    Enables/Disables the traffic management marking"
1243                         " for IP ECN (Explicit Congestion Notification)"
1244                         " packets on a given port\n\n"
1245
1246                         "set port tm mark ip_dscp (port) (green) (yellow)"
1247                         " (red)\n"
1248                         "    Enables/Disables the traffic management marking"
1249                         " on the port for IP dscp packets\n\n"
1250
1251                         "set port tm mark vlan_dei (port) (green) (yellow)"
1252                         " (red)\n"
1253                         "    Enables/Disables the traffic management marking"
1254                         " on the port for VLAN packets with DEI enabled\n\n"
1255                 );
1256         }
1257
1258         if (show_all || !strcmp(res->section, "devices")) {
1259                 cmdline_printf(
1260                         cl,
1261                         "\n"
1262                         "Device Operations:\n"
1263                         "--------------\n"
1264                         "device detach (identifier)\n"
1265                         "       Detach device by identifier.\n\n"
1266                 );
1267         }
1268
1269 }
1270
1271 cmdline_parse_token_string_t cmd_help_long_help =
1272         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1273
1274 cmdline_parse_token_string_t cmd_help_long_section =
1275         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1276                         "all#control#display#config#"
1277                         "ports#registers#filters#traffic_management#devices");
1278
1279 cmdline_parse_inst_t cmd_help_long = {
1280         .f = cmd_help_long_parsed,
1281         .data = NULL,
1282         .help_str = "help all|control|display|config|ports|register|"
1283                 "filters|traffic_management|devices: "
1284                 "Show help",
1285         .tokens = {
1286                 (void *)&cmd_help_long_help,
1287                 (void *)&cmd_help_long_section,
1288                 NULL,
1289         },
1290 };
1291
1292
1293 /* *** start/stop/close all ports *** */
1294 struct cmd_operate_port_result {
1295         cmdline_fixed_string_t keyword;
1296         cmdline_fixed_string_t name;
1297         cmdline_fixed_string_t value;
1298 };
1299
1300 static void cmd_operate_port_parsed(void *parsed_result,
1301                                 __attribute__((unused)) struct cmdline *cl,
1302                                 __attribute__((unused)) void *data)
1303 {
1304         struct cmd_operate_port_result *res = parsed_result;
1305
1306         if (!strcmp(res->name, "start"))
1307                 start_port(RTE_PORT_ALL);
1308         else if (!strcmp(res->name, "stop"))
1309                 stop_port(RTE_PORT_ALL);
1310         else if (!strcmp(res->name, "close"))
1311                 close_port(RTE_PORT_ALL);
1312         else if (!strcmp(res->name, "reset"))
1313                 reset_port(RTE_PORT_ALL);
1314         else
1315                 printf("Unknown parameter\n");
1316 }
1317
1318 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1319         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1320                                                                 "port");
1321 cmdline_parse_token_string_t cmd_operate_port_all_port =
1322         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1323                                                 "start#stop#close#reset");
1324 cmdline_parse_token_string_t cmd_operate_port_all_all =
1325         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1326
1327 cmdline_parse_inst_t cmd_operate_port = {
1328         .f = cmd_operate_port_parsed,
1329         .data = NULL,
1330         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1331         .tokens = {
1332                 (void *)&cmd_operate_port_all_cmd,
1333                 (void *)&cmd_operate_port_all_port,
1334                 (void *)&cmd_operate_port_all_all,
1335                 NULL,
1336         },
1337 };
1338
1339 /* *** start/stop/close specific port *** */
1340 struct cmd_operate_specific_port_result {
1341         cmdline_fixed_string_t keyword;
1342         cmdline_fixed_string_t name;
1343         uint8_t value;
1344 };
1345
1346 static void cmd_operate_specific_port_parsed(void *parsed_result,
1347                         __attribute__((unused)) struct cmdline *cl,
1348                                 __attribute__((unused)) void *data)
1349 {
1350         struct cmd_operate_specific_port_result *res = parsed_result;
1351
1352         if (!strcmp(res->name, "start"))
1353                 start_port(res->value);
1354         else if (!strcmp(res->name, "stop"))
1355                 stop_port(res->value);
1356         else if (!strcmp(res->name, "close"))
1357                 close_port(res->value);
1358         else if (!strcmp(res->name, "reset"))
1359                 reset_port(res->value);
1360         else
1361                 printf("Unknown parameter\n");
1362 }
1363
1364 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1365         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1366                                                         keyword, "port");
1367 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1368         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1369                                                 name, "start#stop#close#reset");
1370 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1371         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1372                                                         value, UINT8);
1373
1374 cmdline_parse_inst_t cmd_operate_specific_port = {
1375         .f = cmd_operate_specific_port_parsed,
1376         .data = NULL,
1377         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1378         .tokens = {
1379                 (void *)&cmd_operate_specific_port_cmd,
1380                 (void *)&cmd_operate_specific_port_port,
1381                 (void *)&cmd_operate_specific_port_id,
1382                 NULL,
1383         },
1384 };
1385
1386 /* *** enable port setup (after attach) via iterator or event *** */
1387 struct cmd_set_port_setup_on_result {
1388         cmdline_fixed_string_t set;
1389         cmdline_fixed_string_t port;
1390         cmdline_fixed_string_t setup;
1391         cmdline_fixed_string_t on;
1392         cmdline_fixed_string_t mode;
1393 };
1394
1395 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1396                                 __attribute__((unused)) struct cmdline *cl,
1397                                 __attribute__((unused)) void *data)
1398 {
1399         struct cmd_set_port_setup_on_result *res = parsed_result;
1400
1401         if (strcmp(res->mode, "event") == 0)
1402                 setup_on_probe_event = true;
1403         else if (strcmp(res->mode, "iterator") == 0)
1404                 setup_on_probe_event = false;
1405         else
1406                 printf("Unknown mode\n");
1407 }
1408
1409 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1410         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1411                         set, "set");
1412 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1413         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1414                         port, "port");
1415 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1416         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1417                         setup, "setup");
1418 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1419         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1420                         on, "on");
1421 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1422         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1423                         mode, "iterator#event");
1424
1425 cmdline_parse_inst_t cmd_set_port_setup_on = {
1426         .f = cmd_set_port_setup_on_parsed,
1427         .data = NULL,
1428         .help_str = "set port setup on iterator|event",
1429         .tokens = {
1430                 (void *)&cmd_set_port_setup_on_set,
1431                 (void *)&cmd_set_port_setup_on_port,
1432                 (void *)&cmd_set_port_setup_on_setup,
1433                 (void *)&cmd_set_port_setup_on_on,
1434                 (void *)&cmd_set_port_setup_on_mode,
1435                 NULL,
1436         },
1437 };
1438
1439 /* *** attach a specified port *** */
1440 struct cmd_operate_attach_port_result {
1441         cmdline_fixed_string_t port;
1442         cmdline_fixed_string_t keyword;
1443         cmdline_fixed_string_t identifier;
1444 };
1445
1446 static void cmd_operate_attach_port_parsed(void *parsed_result,
1447                                 __attribute__((unused)) struct cmdline *cl,
1448                                 __attribute__((unused)) void *data)
1449 {
1450         struct cmd_operate_attach_port_result *res = parsed_result;
1451
1452         if (!strcmp(res->keyword, "attach"))
1453                 attach_port(res->identifier);
1454         else
1455                 printf("Unknown parameter\n");
1456 }
1457
1458 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1459         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1460                         port, "port");
1461 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1462         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1463                         keyword, "attach");
1464 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1465         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1466                         identifier, NULL);
1467
1468 cmdline_parse_inst_t cmd_operate_attach_port = {
1469         .f = cmd_operate_attach_port_parsed,
1470         .data = NULL,
1471         .help_str = "port attach <identifier>: "
1472                 "(identifier: pci address or virtual dev name)",
1473         .tokens = {
1474                 (void *)&cmd_operate_attach_port_port,
1475                 (void *)&cmd_operate_attach_port_keyword,
1476                 (void *)&cmd_operate_attach_port_identifier,
1477                 NULL,
1478         },
1479 };
1480
1481 /* *** detach a specified port *** */
1482 struct cmd_operate_detach_port_result {
1483         cmdline_fixed_string_t port;
1484         cmdline_fixed_string_t keyword;
1485         portid_t port_id;
1486 };
1487
1488 static void cmd_operate_detach_port_parsed(void *parsed_result,
1489                                 __attribute__((unused)) struct cmdline *cl,
1490                                 __attribute__((unused)) void *data)
1491 {
1492         struct cmd_operate_detach_port_result *res = parsed_result;
1493
1494         if (!strcmp(res->keyword, "detach"))
1495                 detach_port_device(res->port_id);
1496         else
1497                 printf("Unknown parameter\n");
1498 }
1499
1500 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1501         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1502                         port, "port");
1503 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1504         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1505                         keyword, "detach");
1506 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1507         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1508                         port_id, UINT16);
1509
1510 cmdline_parse_inst_t cmd_operate_detach_port = {
1511         .f = cmd_operate_detach_port_parsed,
1512         .data = NULL,
1513         .help_str = "port detach <port_id>",
1514         .tokens = {
1515                 (void *)&cmd_operate_detach_port_port,
1516                 (void *)&cmd_operate_detach_port_keyword,
1517                 (void *)&cmd_operate_detach_port_port_id,
1518                 NULL,
1519         },
1520 };
1521
1522 /* *** detach device by identifier *** */
1523 struct cmd_operate_detach_device_result {
1524         cmdline_fixed_string_t device;
1525         cmdline_fixed_string_t keyword;
1526         cmdline_fixed_string_t identifier;
1527 };
1528
1529 static void cmd_operate_detach_device_parsed(void *parsed_result,
1530                                 __attribute__((unused)) struct cmdline *cl,
1531                                 __attribute__((unused)) void *data)
1532 {
1533         struct cmd_operate_detach_device_result *res = parsed_result;
1534
1535         if (!strcmp(res->keyword, "detach"))
1536                 detach_device(res->identifier);
1537         else
1538                 printf("Unknown parameter\n");
1539 }
1540
1541 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1542         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1543                         device, "device");
1544 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1545         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1546                         keyword, "detach");
1547 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1548         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1549                         identifier, NULL);
1550
1551 cmdline_parse_inst_t cmd_operate_detach_device = {
1552         .f = cmd_operate_detach_device_parsed,
1553         .data = NULL,
1554         .help_str = "device detach <identifier>:"
1555                 "(identifier: pci address or virtual dev name)",
1556         .tokens = {
1557                 (void *)&cmd_operate_detach_device_device,
1558                 (void *)&cmd_operate_detach_device_keyword,
1559                 (void *)&cmd_operate_detach_device_identifier,
1560                 NULL,
1561         },
1562 };
1563 /* *** configure speed for all ports *** */
1564 struct cmd_config_speed_all {
1565         cmdline_fixed_string_t port;
1566         cmdline_fixed_string_t keyword;
1567         cmdline_fixed_string_t all;
1568         cmdline_fixed_string_t item1;
1569         cmdline_fixed_string_t item2;
1570         cmdline_fixed_string_t value1;
1571         cmdline_fixed_string_t value2;
1572 };
1573
1574 static int
1575 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1576 {
1577
1578         int duplex;
1579
1580         if (!strcmp(duplexstr, "half")) {
1581                 duplex = ETH_LINK_HALF_DUPLEX;
1582         } else if (!strcmp(duplexstr, "full")) {
1583                 duplex = ETH_LINK_FULL_DUPLEX;
1584         } else if (!strcmp(duplexstr, "auto")) {
1585                 duplex = ETH_LINK_FULL_DUPLEX;
1586         } else {
1587                 printf("Unknown duplex parameter\n");
1588                 return -1;
1589         }
1590
1591         if (!strcmp(speedstr, "10")) {
1592                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1593                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1594         } else if (!strcmp(speedstr, "100")) {
1595                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1596                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1597         } else {
1598                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1599                         printf("Invalid speed/duplex parameters\n");
1600                         return -1;
1601                 }
1602                 if (!strcmp(speedstr, "1000")) {
1603                         *speed = ETH_LINK_SPEED_1G;
1604                 } else if (!strcmp(speedstr, "10000")) {
1605                         *speed = ETH_LINK_SPEED_10G;
1606                 } else if (!strcmp(speedstr, "25000")) {
1607                         *speed = ETH_LINK_SPEED_25G;
1608                 } else if (!strcmp(speedstr, "40000")) {
1609                         *speed = ETH_LINK_SPEED_40G;
1610                 } else if (!strcmp(speedstr, "50000")) {
1611                         *speed = ETH_LINK_SPEED_50G;
1612                 } else if (!strcmp(speedstr, "100000")) {
1613                         *speed = ETH_LINK_SPEED_100G;
1614                 } else if (!strcmp(speedstr, "auto")) {
1615                         *speed = ETH_LINK_SPEED_AUTONEG;
1616                 } else {
1617                         printf("Unknown speed parameter\n");
1618                         return -1;
1619                 }
1620         }
1621
1622         return 0;
1623 }
1624
1625 static void
1626 cmd_config_speed_all_parsed(void *parsed_result,
1627                         __attribute__((unused)) struct cmdline *cl,
1628                         __attribute__((unused)) void *data)
1629 {
1630         struct cmd_config_speed_all *res = parsed_result;
1631         uint32_t link_speed;
1632         portid_t pid;
1633
1634         if (!all_ports_stopped()) {
1635                 printf("Please stop all ports first\n");
1636                 return;
1637         }
1638
1639         if (parse_and_check_speed_duplex(res->value1, res->value2,
1640                         &link_speed) < 0)
1641                 return;
1642
1643         RTE_ETH_FOREACH_DEV(pid) {
1644                 ports[pid].dev_conf.link_speeds = link_speed;
1645         }
1646
1647         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1648 }
1649
1650 cmdline_parse_token_string_t cmd_config_speed_all_port =
1651         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1652 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1653         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1654                                                         "config");
1655 cmdline_parse_token_string_t cmd_config_speed_all_all =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1657 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1658         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1659 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1660         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1661                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1662 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1663         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1664 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1666                                                 "half#full#auto");
1667
1668 cmdline_parse_inst_t cmd_config_speed_all = {
1669         .f = cmd_config_speed_all_parsed,
1670         .data = NULL,
1671         .help_str = "port config all speed "
1672                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1673                                                         "half|full|auto",
1674         .tokens = {
1675                 (void *)&cmd_config_speed_all_port,
1676                 (void *)&cmd_config_speed_all_keyword,
1677                 (void *)&cmd_config_speed_all_all,
1678                 (void *)&cmd_config_speed_all_item1,
1679                 (void *)&cmd_config_speed_all_value1,
1680                 (void *)&cmd_config_speed_all_item2,
1681                 (void *)&cmd_config_speed_all_value2,
1682                 NULL,
1683         },
1684 };
1685
1686 /* *** configure speed for specific port *** */
1687 struct cmd_config_speed_specific {
1688         cmdline_fixed_string_t port;
1689         cmdline_fixed_string_t keyword;
1690         portid_t id;
1691         cmdline_fixed_string_t item1;
1692         cmdline_fixed_string_t item2;
1693         cmdline_fixed_string_t value1;
1694         cmdline_fixed_string_t value2;
1695 };
1696
1697 static void
1698 cmd_config_speed_specific_parsed(void *parsed_result,
1699                                 __attribute__((unused)) struct cmdline *cl,
1700                                 __attribute__((unused)) void *data)
1701 {
1702         struct cmd_config_speed_specific *res = parsed_result;
1703         uint32_t link_speed;
1704
1705         if (!all_ports_stopped()) {
1706                 printf("Please stop all ports first\n");
1707                 return;
1708         }
1709
1710         if (port_id_is_invalid(res->id, ENABLED_WARN))
1711                 return;
1712
1713         if (parse_and_check_speed_duplex(res->value1, res->value2,
1714                         &link_speed) < 0)
1715                 return;
1716
1717         ports[res->id].dev_conf.link_speeds = link_speed;
1718
1719         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1720 }
1721
1722
1723 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1724         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1725                                                                 "port");
1726 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1727         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1728                                                                 "config");
1729 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1730         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1731 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1733                                                                 "speed");
1734 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1735         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1736                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1737 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1738         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1739                                                                 "duplex");
1740 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1741         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1742                                                         "half#full#auto");
1743
1744 cmdline_parse_inst_t cmd_config_speed_specific = {
1745         .f = cmd_config_speed_specific_parsed,
1746         .data = NULL,
1747         .help_str = "port config <port_id> speed "
1748                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1749                                                         "half|full|auto",
1750         .tokens = {
1751                 (void *)&cmd_config_speed_specific_port,
1752                 (void *)&cmd_config_speed_specific_keyword,
1753                 (void *)&cmd_config_speed_specific_id,
1754                 (void *)&cmd_config_speed_specific_item1,
1755                 (void *)&cmd_config_speed_specific_value1,
1756                 (void *)&cmd_config_speed_specific_item2,
1757                 (void *)&cmd_config_speed_specific_value2,
1758                 NULL,
1759         },
1760 };
1761
1762 /* *** configure loopback for all ports *** */
1763 struct cmd_config_loopback_all {
1764         cmdline_fixed_string_t port;
1765         cmdline_fixed_string_t keyword;
1766         cmdline_fixed_string_t all;
1767         cmdline_fixed_string_t item;
1768         uint32_t mode;
1769 };
1770
1771 static void
1772 cmd_config_loopback_all_parsed(void *parsed_result,
1773                         __attribute__((unused)) struct cmdline *cl,
1774                         __attribute__((unused)) void *data)
1775 {
1776         struct cmd_config_loopback_all *res = parsed_result;
1777         portid_t pid;
1778
1779         if (!all_ports_stopped()) {
1780                 printf("Please stop all ports first\n");
1781                 return;
1782         }
1783
1784         RTE_ETH_FOREACH_DEV(pid) {
1785                 ports[pid].dev_conf.lpbk_mode = res->mode;
1786         }
1787
1788         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1789 }
1790
1791 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1792         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1793 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1794         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1795                                                         "config");
1796 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1797         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1798 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1799         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1800                                                         "loopback");
1801 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1802         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1803
1804 cmdline_parse_inst_t cmd_config_loopback_all = {
1805         .f = cmd_config_loopback_all_parsed,
1806         .data = NULL,
1807         .help_str = "port config all loopback <mode>",
1808         .tokens = {
1809                 (void *)&cmd_config_loopback_all_port,
1810                 (void *)&cmd_config_loopback_all_keyword,
1811                 (void *)&cmd_config_loopback_all_all,
1812                 (void *)&cmd_config_loopback_all_item,
1813                 (void *)&cmd_config_loopback_all_mode,
1814                 NULL,
1815         },
1816 };
1817
1818 /* *** configure loopback for specific port *** */
1819 struct cmd_config_loopback_specific {
1820         cmdline_fixed_string_t port;
1821         cmdline_fixed_string_t keyword;
1822         uint16_t port_id;
1823         cmdline_fixed_string_t item;
1824         uint32_t mode;
1825 };
1826
1827 static void
1828 cmd_config_loopback_specific_parsed(void *parsed_result,
1829                                 __attribute__((unused)) struct cmdline *cl,
1830                                 __attribute__((unused)) void *data)
1831 {
1832         struct cmd_config_loopback_specific *res = parsed_result;
1833
1834         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1835                 return;
1836
1837         if (!port_is_stopped(res->port_id)) {
1838                 printf("Please stop port %u first\n", res->port_id);
1839                 return;
1840         }
1841
1842         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1843
1844         cmd_reconfig_device_queue(res->port_id, 1, 1);
1845 }
1846
1847
1848 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1850                                                                 "port");
1851 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1853                                                                 "config");
1854 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1855         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1856                                                                 UINT16);
1857 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1858         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1859                                                                 "loopback");
1860 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1861         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1862                               UINT32);
1863
1864 cmdline_parse_inst_t cmd_config_loopback_specific = {
1865         .f = cmd_config_loopback_specific_parsed,
1866         .data = NULL,
1867         .help_str = "port config <port_id> loopback <mode>",
1868         .tokens = {
1869                 (void *)&cmd_config_loopback_specific_port,
1870                 (void *)&cmd_config_loopback_specific_keyword,
1871                 (void *)&cmd_config_loopback_specific_id,
1872                 (void *)&cmd_config_loopback_specific_item,
1873                 (void *)&cmd_config_loopback_specific_mode,
1874                 NULL,
1875         },
1876 };
1877
1878 /* *** configure txq/rxq, txd/rxd *** */
1879 struct cmd_config_rx_tx {
1880         cmdline_fixed_string_t port;
1881         cmdline_fixed_string_t keyword;
1882         cmdline_fixed_string_t all;
1883         cmdline_fixed_string_t name;
1884         uint16_t value;
1885 };
1886
1887 static void
1888 cmd_config_rx_tx_parsed(void *parsed_result,
1889                         __attribute__((unused)) struct cmdline *cl,
1890                         __attribute__((unused)) void *data)
1891 {
1892         struct cmd_config_rx_tx *res = parsed_result;
1893
1894         if (!all_ports_stopped()) {
1895                 printf("Please stop all ports first\n");
1896                 return;
1897         }
1898         if (!strcmp(res->name, "rxq")) {
1899                 if (!res->value && !nb_txq) {
1900                         printf("Warning: Either rx or tx queues should be non zero\n");
1901                         return;
1902                 }
1903                 if (check_nb_rxq(res->value) != 0)
1904                         return;
1905                 nb_rxq = res->value;
1906         }
1907         else if (!strcmp(res->name, "txq")) {
1908                 if (!res->value && !nb_rxq) {
1909                         printf("Warning: Either rx or tx queues should be non zero\n");
1910                         return;
1911                 }
1912                 if (check_nb_txq(res->value) != 0)
1913                         return;
1914                 nb_txq = res->value;
1915         }
1916         else if (!strcmp(res->name, "rxd")) {
1917                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1918                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1919                                         res->value, RTE_TEST_RX_DESC_MAX);
1920                         return;
1921                 }
1922                 nb_rxd = res->value;
1923         } else if (!strcmp(res->name, "txd")) {
1924                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1925                         printf("txd %d invalid - must be > 0 && <= %d\n",
1926                                         res->value, RTE_TEST_TX_DESC_MAX);
1927                         return;
1928                 }
1929                 nb_txd = res->value;
1930         } else {
1931                 printf("Unknown parameter\n");
1932                 return;
1933         }
1934
1935         fwd_config_setup();
1936
1937         init_port_config();
1938
1939         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1940 }
1941
1942 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1943         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1944 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1945         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1946 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1947         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1948 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1949         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1950                                                 "rxq#txq#rxd#txd");
1951 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1952         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1953
1954 cmdline_parse_inst_t cmd_config_rx_tx = {
1955         .f = cmd_config_rx_tx_parsed,
1956         .data = NULL,
1957         .help_str = "port config all rxq|txq|rxd|txd <value>",
1958         .tokens = {
1959                 (void *)&cmd_config_rx_tx_port,
1960                 (void *)&cmd_config_rx_tx_keyword,
1961                 (void *)&cmd_config_rx_tx_all,
1962                 (void *)&cmd_config_rx_tx_name,
1963                 (void *)&cmd_config_rx_tx_value,
1964                 NULL,
1965         },
1966 };
1967
1968 /* *** config max packet length *** */
1969 struct cmd_config_max_pkt_len_result {
1970         cmdline_fixed_string_t port;
1971         cmdline_fixed_string_t keyword;
1972         cmdline_fixed_string_t all;
1973         cmdline_fixed_string_t name;
1974         uint32_t value;
1975 };
1976
1977 static void
1978 cmd_config_max_pkt_len_parsed(void *parsed_result,
1979                                 __attribute__((unused)) struct cmdline *cl,
1980                                 __attribute__((unused)) void *data)
1981 {
1982         struct cmd_config_max_pkt_len_result *res = parsed_result;
1983         portid_t pid;
1984
1985         if (!all_ports_stopped()) {
1986                 printf("Please stop all ports first\n");
1987                 return;
1988         }
1989
1990         RTE_ETH_FOREACH_DEV(pid) {
1991                 struct rte_port *port = &ports[pid];
1992                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1993
1994                 if (!strcmp(res->name, "max-pkt-len")) {
1995                         if (res->value < RTE_ETHER_MIN_LEN) {
1996                                 printf("max-pkt-len can not be less than %d\n",
1997                                                 RTE_ETHER_MIN_LEN);
1998                                 return;
1999                         }
2000                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2001                                 return;
2002
2003                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2004                         if (res->value > RTE_ETHER_MAX_LEN)
2005                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2006                         else
2007                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2008                         port->dev_conf.rxmode.offloads = rx_offloads;
2009                 } else {
2010                         printf("Unknown parameter\n");
2011                         return;
2012                 }
2013         }
2014
2015         init_port_config();
2016
2017         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2018 }
2019
2020 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2021         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2022                                                                 "port");
2023 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2024         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2025                                                                 "config");
2026 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2027         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2028                                                                 "all");
2029 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2030         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2031                                                                 "max-pkt-len");
2032 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2033         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2034                                                                 UINT32);
2035
2036 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2037         .f = cmd_config_max_pkt_len_parsed,
2038         .data = NULL,
2039         .help_str = "port config all max-pkt-len <value>",
2040         .tokens = {
2041                 (void *)&cmd_config_max_pkt_len_port,
2042                 (void *)&cmd_config_max_pkt_len_keyword,
2043                 (void *)&cmd_config_max_pkt_len_all,
2044                 (void *)&cmd_config_max_pkt_len_name,
2045                 (void *)&cmd_config_max_pkt_len_value,
2046                 NULL,
2047         },
2048 };
2049
2050 /* *** config max LRO aggregated packet size *** */
2051 struct cmd_config_max_lro_pkt_size_result {
2052         cmdline_fixed_string_t port;
2053         cmdline_fixed_string_t keyword;
2054         cmdline_fixed_string_t all;
2055         cmdline_fixed_string_t name;
2056         uint32_t value;
2057 };
2058
2059 static void
2060 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2061                                 __attribute__((unused)) struct cmdline *cl,
2062                                 __attribute__((unused)) void *data)
2063 {
2064         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2065         portid_t pid;
2066
2067         if (!all_ports_stopped()) {
2068                 printf("Please stop all ports first\n");
2069                 return;
2070         }
2071
2072         RTE_ETH_FOREACH_DEV(pid) {
2073                 struct rte_port *port = &ports[pid];
2074
2075                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2076                         if (res->value ==
2077                                         port->dev_conf.rxmode.max_lro_pkt_size)
2078                                 return;
2079
2080                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2081                 } else {
2082                         printf("Unknown parameter\n");
2083                         return;
2084                 }
2085         }
2086
2087         init_port_config();
2088
2089         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2090 }
2091
2092 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2093         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2094                                  port, "port");
2095 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2096         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2097                                  keyword, "config");
2098 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2099         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2100                                  all, "all");
2101 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2102         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2103                                  name, "max-lro-pkt-size");
2104 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2105         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2106                               value, UINT32);
2107
2108 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2109         .f = cmd_config_max_lro_pkt_size_parsed,
2110         .data = NULL,
2111         .help_str = "port config all max-lro-pkt-size <value>",
2112         .tokens = {
2113                 (void *)&cmd_config_max_lro_pkt_size_port,
2114                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2115                 (void *)&cmd_config_max_lro_pkt_size_all,
2116                 (void *)&cmd_config_max_lro_pkt_size_name,
2117                 (void *)&cmd_config_max_lro_pkt_size_value,
2118                 NULL,
2119         },
2120 };
2121
2122 /* *** configure port MTU *** */
2123 struct cmd_config_mtu_result {
2124         cmdline_fixed_string_t port;
2125         cmdline_fixed_string_t keyword;
2126         cmdline_fixed_string_t mtu;
2127         portid_t port_id;
2128         uint16_t value;
2129 };
2130
2131 static void
2132 cmd_config_mtu_parsed(void *parsed_result,
2133                       __attribute__((unused)) struct cmdline *cl,
2134                       __attribute__((unused)) void *data)
2135 {
2136         struct cmd_config_mtu_result *res = parsed_result;
2137
2138         if (res->value < RTE_ETHER_MIN_LEN) {
2139                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2140                 return;
2141         }
2142         port_mtu_set(res->port_id, res->value);
2143 }
2144
2145 cmdline_parse_token_string_t cmd_config_mtu_port =
2146         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2147                                  "port");
2148 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2149         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2150                                  "config");
2151 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2152         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2153                                  "mtu");
2154 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2155         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2156 cmdline_parse_token_num_t cmd_config_mtu_value =
2157         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2158
2159 cmdline_parse_inst_t cmd_config_mtu = {
2160         .f = cmd_config_mtu_parsed,
2161         .data = NULL,
2162         .help_str = "port config mtu <port_id> <value>",
2163         .tokens = {
2164                 (void *)&cmd_config_mtu_port,
2165                 (void *)&cmd_config_mtu_keyword,
2166                 (void *)&cmd_config_mtu_mtu,
2167                 (void *)&cmd_config_mtu_port_id,
2168                 (void *)&cmd_config_mtu_value,
2169                 NULL,
2170         },
2171 };
2172
2173 /* *** configure rx mode *** */
2174 struct cmd_config_rx_mode_flag {
2175         cmdline_fixed_string_t port;
2176         cmdline_fixed_string_t keyword;
2177         cmdline_fixed_string_t all;
2178         cmdline_fixed_string_t name;
2179         cmdline_fixed_string_t value;
2180 };
2181
2182 static void
2183 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2184                                 __attribute__((unused)) struct cmdline *cl,
2185                                 __attribute__((unused)) void *data)
2186 {
2187         struct cmd_config_rx_mode_flag *res = parsed_result;
2188
2189         if (!all_ports_stopped()) {
2190                 printf("Please stop all ports first\n");
2191                 return;
2192         }
2193
2194         if (!strcmp(res->name, "drop-en")) {
2195                 if (!strcmp(res->value, "on"))
2196                         rx_drop_en = 1;
2197                 else if (!strcmp(res->value, "off"))
2198                         rx_drop_en = 0;
2199                 else {
2200                         printf("Unknown parameter\n");
2201                         return;
2202                 }
2203         } else {
2204                 printf("Unknown parameter\n");
2205                 return;
2206         }
2207
2208         init_port_config();
2209
2210         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2211 }
2212
2213 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2214         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2215 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2216         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2217                                                                 "config");
2218 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2219         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2220 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2221         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2222                                         "drop-en");
2223 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2224         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2225                                                         "on#off");
2226
2227 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2228         .f = cmd_config_rx_mode_flag_parsed,
2229         .data = NULL,
2230         .help_str = "port config all drop-en on|off",
2231         .tokens = {
2232                 (void *)&cmd_config_rx_mode_flag_port,
2233                 (void *)&cmd_config_rx_mode_flag_keyword,
2234                 (void *)&cmd_config_rx_mode_flag_all,
2235                 (void *)&cmd_config_rx_mode_flag_name,
2236                 (void *)&cmd_config_rx_mode_flag_value,
2237                 NULL,
2238         },
2239 };
2240
2241 /* *** configure rss *** */
2242 struct cmd_config_rss {
2243         cmdline_fixed_string_t port;
2244         cmdline_fixed_string_t keyword;
2245         cmdline_fixed_string_t all;
2246         cmdline_fixed_string_t name;
2247         cmdline_fixed_string_t value;
2248 };
2249
2250 static void
2251 cmd_config_rss_parsed(void *parsed_result,
2252                         __attribute__((unused)) struct cmdline *cl,
2253                         __attribute__((unused)) void *data)
2254 {
2255         struct cmd_config_rss *res = parsed_result;
2256         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2257         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2258         int use_default = 0;
2259         int all_updated = 1;
2260         int diag;
2261         uint16_t i;
2262         int ret;
2263
2264         if (!strcmp(res->value, "all"))
2265                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2266                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2267                                         ETH_RSS_L2_PAYLOAD;
2268         else if (!strcmp(res->value, "ip"))
2269                 rss_conf.rss_hf = ETH_RSS_IP;
2270         else if (!strcmp(res->value, "udp"))
2271                 rss_conf.rss_hf = ETH_RSS_UDP;
2272         else if (!strcmp(res->value, "tcp"))
2273                 rss_conf.rss_hf = ETH_RSS_TCP;
2274         else if (!strcmp(res->value, "sctp"))
2275                 rss_conf.rss_hf = ETH_RSS_SCTP;
2276         else if (!strcmp(res->value, "ether"))
2277                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2278         else if (!strcmp(res->value, "port"))
2279                 rss_conf.rss_hf = ETH_RSS_PORT;
2280         else if (!strcmp(res->value, "vxlan"))
2281                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2282         else if (!strcmp(res->value, "geneve"))
2283                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2284         else if (!strcmp(res->value, "nvgre"))
2285                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2286         else if (!strcmp(res->value, "l3-src-only"))
2287                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2288         else if (!strcmp(res->value, "l3-dst-only"))
2289                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2290         else if (!strcmp(res->value, "l4-src-only"))
2291                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2292         else if (!strcmp(res->value, "l4-dst-only"))
2293                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2294         else if (!strcmp(res->value, "none"))
2295                 rss_conf.rss_hf = 0;
2296         else if (!strcmp(res->value, "default"))
2297                 use_default = 1;
2298         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2299                                                 atoi(res->value) < 64)
2300                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2301         else {
2302                 printf("Unknown parameter\n");
2303                 return;
2304         }
2305         rss_conf.rss_key = NULL;
2306         /* Update global configuration for RSS types. */
2307         RTE_ETH_FOREACH_DEV(i) {
2308                 struct rte_eth_rss_conf local_rss_conf;
2309
2310                 ret = eth_dev_info_get_print_err(i, &dev_info);
2311                 if (ret != 0)
2312                         return;
2313
2314                 if (use_default)
2315                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2316
2317                 local_rss_conf = rss_conf;
2318                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2319                         dev_info.flow_type_rss_offloads;
2320                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2321                         printf("Port %u modified RSS hash function based on hardware support,"
2322                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2323                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2324                 }
2325                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2326                 if (diag < 0) {
2327                         all_updated = 0;
2328                         printf("Configuration of RSS hash at ethernet port %d "
2329                                 "failed with error (%d): %s.\n",
2330                                 i, -diag, strerror(-diag));
2331                 }
2332         }
2333         if (all_updated && !use_default)
2334                 rss_hf = rss_conf.rss_hf;
2335 }
2336
2337 cmdline_parse_token_string_t cmd_config_rss_port =
2338         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2339 cmdline_parse_token_string_t cmd_config_rss_keyword =
2340         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2341 cmdline_parse_token_string_t cmd_config_rss_all =
2342         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2343 cmdline_parse_token_string_t cmd_config_rss_name =
2344         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2345 cmdline_parse_token_string_t cmd_config_rss_value =
2346         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2347
2348 cmdline_parse_inst_t cmd_config_rss = {
2349         .f = cmd_config_rss_parsed,
2350         .data = NULL,
2351         .help_str = "port config all rss "
2352                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2353         .tokens = {
2354                 (void *)&cmd_config_rss_port,
2355                 (void *)&cmd_config_rss_keyword,
2356                 (void *)&cmd_config_rss_all,
2357                 (void *)&cmd_config_rss_name,
2358                 (void *)&cmd_config_rss_value,
2359                 NULL,
2360         },
2361 };
2362
2363 /* *** configure rss hash key *** */
2364 struct cmd_config_rss_hash_key {
2365         cmdline_fixed_string_t port;
2366         cmdline_fixed_string_t config;
2367         portid_t port_id;
2368         cmdline_fixed_string_t rss_hash_key;
2369         cmdline_fixed_string_t rss_type;
2370         cmdline_fixed_string_t key;
2371 };
2372
2373 static uint8_t
2374 hexa_digit_to_value(char hexa_digit)
2375 {
2376         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2377                 return (uint8_t) (hexa_digit - '0');
2378         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2379                 return (uint8_t) ((hexa_digit - 'a') + 10);
2380         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2381                 return (uint8_t) ((hexa_digit - 'A') + 10);
2382         /* Invalid hexa digit */
2383         return 0xFF;
2384 }
2385
2386 static uint8_t
2387 parse_and_check_key_hexa_digit(char *key, int idx)
2388 {
2389         uint8_t hexa_v;
2390
2391         hexa_v = hexa_digit_to_value(key[idx]);
2392         if (hexa_v == 0xFF)
2393                 printf("invalid key: character %c at position %d is not a "
2394                        "valid hexa digit\n", key[idx], idx);
2395         return hexa_v;
2396 }
2397
2398 static void
2399 cmd_config_rss_hash_key_parsed(void *parsed_result,
2400                                __attribute__((unused)) struct cmdline *cl,
2401                                __attribute__((unused)) void *data)
2402 {
2403         struct cmd_config_rss_hash_key *res = parsed_result;
2404         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2405         uint8_t xdgt0;
2406         uint8_t xdgt1;
2407         int i;
2408         struct rte_eth_dev_info dev_info;
2409         uint8_t hash_key_size;
2410         uint32_t key_len;
2411         int ret;
2412
2413         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2414         if (ret != 0)
2415                 return;
2416
2417         if (dev_info.hash_key_size > 0 &&
2418                         dev_info.hash_key_size <= sizeof(hash_key))
2419                 hash_key_size = dev_info.hash_key_size;
2420         else {
2421                 printf("dev_info did not provide a valid hash key size\n");
2422                 return;
2423         }
2424         /* Check the length of the RSS hash key */
2425         key_len = strlen(res->key);
2426         if (key_len != (hash_key_size * 2)) {
2427                 printf("key length: %d invalid - key must be a string of %d"
2428                            " hexa-decimal numbers\n",
2429                            (int) key_len, hash_key_size * 2);
2430                 return;
2431         }
2432         /* Translate RSS hash key into binary representation */
2433         for (i = 0; i < hash_key_size; i++) {
2434                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2435                 if (xdgt0 == 0xFF)
2436                         return;
2437                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2438                 if (xdgt1 == 0xFF)
2439                         return;
2440                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2441         }
2442         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2443                         hash_key_size);
2444 }
2445
2446 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2447         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2448 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2449         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2450                                  "config");
2451 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2452         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2453 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2454         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2455                                  rss_hash_key, "rss-hash-key");
2456 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2457         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2458                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2459                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2460                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2461                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2462                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only");
2463 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2464         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2465
2466 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2467         .f = cmd_config_rss_hash_key_parsed,
2468         .data = NULL,
2469         .help_str = "port config <port_id> rss-hash-key "
2470                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2471                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2472                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2473                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only "
2474                 "<string of hex digits (variable length, NIC dependent)>",
2475         .tokens = {
2476                 (void *)&cmd_config_rss_hash_key_port,
2477                 (void *)&cmd_config_rss_hash_key_config,
2478                 (void *)&cmd_config_rss_hash_key_port_id,
2479                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2480                 (void *)&cmd_config_rss_hash_key_rss_type,
2481                 (void *)&cmd_config_rss_hash_key_value,
2482                 NULL,
2483         },
2484 };
2485
2486 /* *** configure port rxq/txq ring size *** */
2487 struct cmd_config_rxtx_ring_size {
2488         cmdline_fixed_string_t port;
2489         cmdline_fixed_string_t config;
2490         portid_t portid;
2491         cmdline_fixed_string_t rxtxq;
2492         uint16_t qid;
2493         cmdline_fixed_string_t rsize;
2494         uint16_t size;
2495 };
2496
2497 static void
2498 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2499                                  __attribute__((unused)) struct cmdline *cl,
2500                                  __attribute__((unused)) void *data)
2501 {
2502         struct cmd_config_rxtx_ring_size *res = parsed_result;
2503         struct rte_port *port;
2504         uint8_t isrx;
2505
2506         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2507                 return;
2508
2509         if (res->portid == (portid_t)RTE_PORT_ALL) {
2510                 printf("Invalid port id\n");
2511                 return;
2512         }
2513
2514         port = &ports[res->portid];
2515
2516         if (!strcmp(res->rxtxq, "rxq"))
2517                 isrx = 1;
2518         else if (!strcmp(res->rxtxq, "txq"))
2519                 isrx = 0;
2520         else {
2521                 printf("Unknown parameter\n");
2522                 return;
2523         }
2524
2525         if (isrx && rx_queue_id_is_invalid(res->qid))
2526                 return;
2527         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2528                 return;
2529
2530         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2531                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2532                        rx_free_thresh);
2533                 return;
2534         }
2535
2536         if (isrx)
2537                 port->nb_rx_desc[res->qid] = res->size;
2538         else
2539                 port->nb_tx_desc[res->qid] = res->size;
2540
2541         cmd_reconfig_device_queue(res->portid, 0, 1);
2542 }
2543
2544 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2545         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2546                                  port, "port");
2547 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2548         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2549                                  config, "config");
2550 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2551         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2552                                  portid, UINT16);
2553 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2554         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2555                                  rxtxq, "rxq#txq");
2556 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2557         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2558                               qid, UINT16);
2559 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2560         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2561                                  rsize, "ring_size");
2562 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2563         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2564                               size, UINT16);
2565
2566 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2567         .f = cmd_config_rxtx_ring_size_parsed,
2568         .data = NULL,
2569         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2570         .tokens = {
2571                 (void *)&cmd_config_rxtx_ring_size_port,
2572                 (void *)&cmd_config_rxtx_ring_size_config,
2573                 (void *)&cmd_config_rxtx_ring_size_portid,
2574                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2575                 (void *)&cmd_config_rxtx_ring_size_qid,
2576                 (void *)&cmd_config_rxtx_ring_size_rsize,
2577                 (void *)&cmd_config_rxtx_ring_size_size,
2578                 NULL,
2579         },
2580 };
2581
2582 /* *** configure port rxq/txq start/stop *** */
2583 struct cmd_config_rxtx_queue {
2584         cmdline_fixed_string_t port;
2585         portid_t portid;
2586         cmdline_fixed_string_t rxtxq;
2587         uint16_t qid;
2588         cmdline_fixed_string_t opname;
2589 };
2590
2591 static void
2592 cmd_config_rxtx_queue_parsed(void *parsed_result,
2593                         __attribute__((unused)) struct cmdline *cl,
2594                         __attribute__((unused)) void *data)
2595 {
2596         struct cmd_config_rxtx_queue *res = parsed_result;
2597         uint8_t isrx;
2598         uint8_t isstart;
2599         int ret = 0;
2600
2601         if (test_done == 0) {
2602                 printf("Please stop forwarding first\n");
2603                 return;
2604         }
2605
2606         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2607                 return;
2608
2609         if (port_is_started(res->portid) != 1) {
2610                 printf("Please start port %u first\n", res->portid);
2611                 return;
2612         }
2613
2614         if (!strcmp(res->rxtxq, "rxq"))
2615                 isrx = 1;
2616         else if (!strcmp(res->rxtxq, "txq"))
2617                 isrx = 0;
2618         else {
2619                 printf("Unknown parameter\n");
2620                 return;
2621         }
2622
2623         if (isrx && rx_queue_id_is_invalid(res->qid))
2624                 return;
2625         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2626                 return;
2627
2628         if (!strcmp(res->opname, "start"))
2629                 isstart = 1;
2630         else if (!strcmp(res->opname, "stop"))
2631                 isstart = 0;
2632         else {
2633                 printf("Unknown parameter\n");
2634                 return;
2635         }
2636
2637         if (isstart && isrx)
2638                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2639         else if (!isstart && isrx)
2640                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2641         else if (isstart && !isrx)
2642                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2643         else
2644                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2645
2646         if (ret == -ENOTSUP)
2647                 printf("Function not supported in PMD driver\n");
2648 }
2649
2650 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2651         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2652 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2653         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2654 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2655         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2656 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2657         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2658 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2659         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2660                                                 "start#stop");
2661
2662 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2663         .f = cmd_config_rxtx_queue_parsed,
2664         .data = NULL,
2665         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2666         .tokens = {
2667                 (void *)&cmd_config_rxtx_queue_port,
2668                 (void *)&cmd_config_rxtx_queue_portid,
2669                 (void *)&cmd_config_rxtx_queue_rxtxq,
2670                 (void *)&cmd_config_rxtx_queue_qid,
2671                 (void *)&cmd_config_rxtx_queue_opname,
2672                 NULL,
2673         },
2674 };
2675
2676 /* *** configure port rxq/txq deferred start on/off *** */
2677 struct cmd_config_deferred_start_rxtx_queue {
2678         cmdline_fixed_string_t port;
2679         portid_t port_id;
2680         cmdline_fixed_string_t rxtxq;
2681         uint16_t qid;
2682         cmdline_fixed_string_t opname;
2683         cmdline_fixed_string_t state;
2684 };
2685
2686 static void
2687 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2688                         __attribute__((unused)) struct cmdline *cl,
2689                         __attribute__((unused)) void *data)
2690 {
2691         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2692         struct rte_port *port;
2693         uint8_t isrx;
2694         uint8_t ison;
2695         uint8_t needreconfig = 0;
2696
2697         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2698                 return;
2699
2700         if (port_is_started(res->port_id) != 0) {
2701                 printf("Please stop port %u first\n", res->port_id);
2702                 return;
2703         }
2704
2705         port = &ports[res->port_id];
2706
2707         isrx = !strcmp(res->rxtxq, "rxq");
2708
2709         if (isrx && rx_queue_id_is_invalid(res->qid))
2710                 return;
2711         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2712                 return;
2713
2714         ison = !strcmp(res->state, "on");
2715
2716         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2717                 port->rx_conf[res->qid].rx_deferred_start = ison;
2718                 needreconfig = 1;
2719         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2720                 port->tx_conf[res->qid].tx_deferred_start = ison;
2721                 needreconfig = 1;
2722         }
2723
2724         if (needreconfig)
2725                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2726 }
2727
2728 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2729         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2730                                                 port, "port");
2731 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2732         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2733                                                 port_id, UINT16);
2734 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2735         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2736                                                 rxtxq, "rxq#txq");
2737 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2738         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2739                                                 qid, UINT16);
2740 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2741         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2742                                                 opname, "deferred_start");
2743 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2744         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2745                                                 state, "on#off");
2746
2747 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2748         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2749         .data = NULL,
2750         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2751         .tokens = {
2752                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2753                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2754                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2755                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2756                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2757                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2758                 NULL,
2759         },
2760 };
2761
2762 /* *** configure port rxq/txq setup *** */
2763 struct cmd_setup_rxtx_queue {
2764         cmdline_fixed_string_t port;
2765         portid_t portid;
2766         cmdline_fixed_string_t rxtxq;
2767         uint16_t qid;
2768         cmdline_fixed_string_t setup;
2769 };
2770
2771 /* Common CLI fields for queue setup */
2772 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2773         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2774 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2775         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2776 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2777         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2778 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2779         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2780 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2781         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2782
2783 static void
2784 cmd_setup_rxtx_queue_parsed(
2785         void *parsed_result,
2786         __attribute__((unused)) struct cmdline *cl,
2787         __attribute__((unused)) void *data)
2788 {
2789         struct cmd_setup_rxtx_queue *res = parsed_result;
2790         struct rte_port *port;
2791         struct rte_mempool *mp;
2792         unsigned int socket_id;
2793         uint8_t isrx = 0;
2794         int ret;
2795
2796         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2797                 return;
2798
2799         if (res->portid == (portid_t)RTE_PORT_ALL) {
2800                 printf("Invalid port id\n");
2801                 return;
2802         }
2803
2804         if (!strcmp(res->rxtxq, "rxq"))
2805                 isrx = 1;
2806         else if (!strcmp(res->rxtxq, "txq"))
2807                 isrx = 0;
2808         else {
2809                 printf("Unknown parameter\n");
2810                 return;
2811         }
2812
2813         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2814                 printf("Invalid rx queue\n");
2815                 return;
2816         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2817                 printf("Invalid tx queue\n");
2818                 return;
2819         }
2820
2821         port = &ports[res->portid];
2822         if (isrx) {
2823                 socket_id = rxring_numa[res->portid];
2824                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2825                         socket_id = port->socket_id;
2826
2827                 mp = mbuf_pool_find(socket_id);
2828                 if (mp == NULL) {
2829                         printf("Failed to setup RX queue: "
2830                                 "No mempool allocation"
2831                                 " on the socket %d\n",
2832                                 rxring_numa[res->portid]);
2833                         return;
2834                 }
2835                 ret = rte_eth_rx_queue_setup(res->portid,
2836                                              res->qid,
2837                                              port->nb_rx_desc[res->qid],
2838                                              socket_id,
2839                                              &port->rx_conf[res->qid],
2840                                              mp);
2841                 if (ret)
2842                         printf("Failed to setup RX queue\n");
2843         } else {
2844                 socket_id = txring_numa[res->portid];
2845                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2846                         socket_id = port->socket_id;
2847
2848                 ret = rte_eth_tx_queue_setup(res->portid,
2849                                              res->qid,
2850                                              port->nb_tx_desc[res->qid],
2851                                              socket_id,
2852                                              &port->tx_conf[res->qid]);
2853                 if (ret)
2854                         printf("Failed to setup TX queue\n");
2855         }
2856 }
2857
2858 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2859         .f = cmd_setup_rxtx_queue_parsed,
2860         .data = NULL,
2861         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2862         .tokens = {
2863                 (void *)&cmd_setup_rxtx_queue_port,
2864                 (void *)&cmd_setup_rxtx_queue_portid,
2865                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2866                 (void *)&cmd_setup_rxtx_queue_qid,
2867                 (void *)&cmd_setup_rxtx_queue_setup,
2868                 NULL,
2869         },
2870 };
2871
2872
2873 /* *** Configure RSS RETA *** */
2874 struct cmd_config_rss_reta {
2875         cmdline_fixed_string_t port;
2876         cmdline_fixed_string_t keyword;
2877         portid_t port_id;
2878         cmdline_fixed_string_t name;
2879         cmdline_fixed_string_t list_name;
2880         cmdline_fixed_string_t list_of_items;
2881 };
2882
2883 static int
2884 parse_reta_config(const char *str,
2885                   struct rte_eth_rss_reta_entry64 *reta_conf,
2886                   uint16_t nb_entries)
2887 {
2888         int i;
2889         unsigned size;
2890         uint16_t hash_index, idx, shift;
2891         uint16_t nb_queue;
2892         char s[256];
2893         const char *p, *p0 = str;
2894         char *end;
2895         enum fieldnames {
2896                 FLD_HASH_INDEX = 0,
2897                 FLD_QUEUE,
2898                 _NUM_FLD
2899         };
2900         unsigned long int_fld[_NUM_FLD];
2901         char *str_fld[_NUM_FLD];
2902
2903         while ((p = strchr(p0,'(')) != NULL) {
2904                 ++p;
2905                 if((p0 = strchr(p,')')) == NULL)
2906                         return -1;
2907
2908                 size = p0 - p;
2909                 if(size >= sizeof(s))
2910                         return -1;
2911
2912                 snprintf(s, sizeof(s), "%.*s", size, p);
2913                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2914                         return -1;
2915                 for (i = 0; i < _NUM_FLD; i++) {
2916                         errno = 0;
2917                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2918                         if (errno != 0 || end == str_fld[i] ||
2919                                         int_fld[i] > 65535)
2920                                 return -1;
2921                 }
2922
2923                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2924                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2925
2926                 if (hash_index >= nb_entries) {
2927                         printf("Invalid RETA hash index=%d\n", hash_index);
2928                         return -1;
2929                 }
2930
2931                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2932                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2933                 reta_conf[idx].mask |= (1ULL << shift);
2934                 reta_conf[idx].reta[shift] = nb_queue;
2935         }
2936
2937         return 0;
2938 }
2939
2940 static void
2941 cmd_set_rss_reta_parsed(void *parsed_result,
2942                         __attribute__((unused)) struct cmdline *cl,
2943                         __attribute__((unused)) void *data)
2944 {
2945         int ret;
2946         struct rte_eth_dev_info dev_info;
2947         struct rte_eth_rss_reta_entry64 reta_conf[8];
2948         struct cmd_config_rss_reta *res = parsed_result;
2949
2950         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2951         if (ret != 0)
2952                 return;
2953
2954         if (dev_info.reta_size == 0) {
2955                 printf("Redirection table size is 0 which is "
2956                                         "invalid for RSS\n");
2957                 return;
2958         } else
2959                 printf("The reta size of port %d is %u\n",
2960                         res->port_id, dev_info.reta_size);
2961         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2962                 printf("Currently do not support more than %u entries of "
2963                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2964                 return;
2965         }
2966
2967         memset(reta_conf, 0, sizeof(reta_conf));
2968         if (!strcmp(res->list_name, "reta")) {
2969                 if (parse_reta_config(res->list_of_items, reta_conf,
2970                                                 dev_info.reta_size)) {
2971                         printf("Invalid RSS Redirection Table "
2972                                         "config entered\n");
2973                         return;
2974                 }
2975                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2976                                 reta_conf, dev_info.reta_size);
2977                 if (ret != 0)
2978                         printf("Bad redirection table parameter, "
2979                                         "return code = %d \n", ret);
2980         }
2981 }
2982
2983 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2984         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2985 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2986         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2987 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2988         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2989 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2990         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2991 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2992         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2993 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2994         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2995                                  NULL);
2996 cmdline_parse_inst_t cmd_config_rss_reta = {
2997         .f = cmd_set_rss_reta_parsed,
2998         .data = NULL,
2999         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3000         .tokens = {
3001                 (void *)&cmd_config_rss_reta_port,
3002                 (void *)&cmd_config_rss_reta_keyword,
3003                 (void *)&cmd_config_rss_reta_port_id,
3004                 (void *)&cmd_config_rss_reta_name,
3005                 (void *)&cmd_config_rss_reta_list_name,
3006                 (void *)&cmd_config_rss_reta_list_of_items,
3007                 NULL,
3008         },
3009 };
3010
3011 /* *** SHOW PORT RETA INFO *** */
3012 struct cmd_showport_reta {
3013         cmdline_fixed_string_t show;
3014         cmdline_fixed_string_t port;
3015         portid_t port_id;
3016         cmdline_fixed_string_t rss;
3017         cmdline_fixed_string_t reta;
3018         uint16_t size;
3019         cmdline_fixed_string_t list_of_items;
3020 };
3021
3022 static int
3023 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3024                            uint16_t nb_entries,
3025                            char *str)
3026 {
3027         uint32_t size;
3028         const char *p, *p0 = str;
3029         char s[256];
3030         char *end;
3031         char *str_fld[8];
3032         uint16_t i;
3033         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3034                         RTE_RETA_GROUP_SIZE;
3035         int ret;
3036
3037         p = strchr(p0, '(');
3038         if (p == NULL)
3039                 return -1;
3040         p++;
3041         p0 = strchr(p, ')');
3042         if (p0 == NULL)
3043                 return -1;
3044         size = p0 - p;
3045         if (size >= sizeof(s)) {
3046                 printf("The string size exceeds the internal buffer size\n");
3047                 return -1;
3048         }
3049         snprintf(s, sizeof(s), "%.*s", size, p);
3050         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3051         if (ret <= 0 || ret != num) {
3052                 printf("The bits of masks do not match the number of "
3053                                         "reta entries: %u\n", num);
3054                 return -1;
3055         }
3056         for (i = 0; i < ret; i++)
3057                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3058
3059         return 0;
3060 }
3061
3062 static void
3063 cmd_showport_reta_parsed(void *parsed_result,
3064                          __attribute__((unused)) struct cmdline *cl,
3065                          __attribute__((unused)) void *data)
3066 {
3067         struct cmd_showport_reta *res = parsed_result;
3068         struct rte_eth_rss_reta_entry64 reta_conf[8];
3069         struct rte_eth_dev_info dev_info;
3070         uint16_t max_reta_size;
3071         int ret;
3072
3073         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3074         if (ret != 0)
3075                 return;
3076
3077         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3078         if (res->size == 0 || res->size > max_reta_size) {
3079                 printf("Invalid redirection table size: %u (1-%u)\n",
3080                         res->size, max_reta_size);
3081                 return;
3082         }
3083
3084         memset(reta_conf, 0, sizeof(reta_conf));
3085         if (showport_parse_reta_config(reta_conf, res->size,
3086                                 res->list_of_items) < 0) {
3087                 printf("Invalid string: %s for reta masks\n",
3088                                         res->list_of_items);
3089                 return;
3090         }
3091         port_rss_reta_info(res->port_id, reta_conf, res->size);
3092 }
3093
3094 cmdline_parse_token_string_t cmd_showport_reta_show =
3095         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3096 cmdline_parse_token_string_t cmd_showport_reta_port =
3097         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3098 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3099         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3100 cmdline_parse_token_string_t cmd_showport_reta_rss =
3101         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3102 cmdline_parse_token_string_t cmd_showport_reta_reta =
3103         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3104 cmdline_parse_token_num_t cmd_showport_reta_size =
3105         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3106 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3107         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3108                                         list_of_items, NULL);
3109
3110 cmdline_parse_inst_t cmd_showport_reta = {
3111         .f = cmd_showport_reta_parsed,
3112         .data = NULL,
3113         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3114         .tokens = {
3115                 (void *)&cmd_showport_reta_show,
3116                 (void *)&cmd_showport_reta_port,
3117                 (void *)&cmd_showport_reta_port_id,
3118                 (void *)&cmd_showport_reta_rss,
3119                 (void *)&cmd_showport_reta_reta,
3120                 (void *)&cmd_showport_reta_size,
3121                 (void *)&cmd_showport_reta_list_of_items,
3122                 NULL,
3123         },
3124 };
3125
3126 /* *** Show RSS hash configuration *** */
3127 struct cmd_showport_rss_hash {
3128         cmdline_fixed_string_t show;
3129         cmdline_fixed_string_t port;
3130         portid_t port_id;
3131         cmdline_fixed_string_t rss_hash;
3132         cmdline_fixed_string_t rss_type;
3133         cmdline_fixed_string_t key; /* optional argument */
3134 };
3135
3136 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3137                                 __attribute__((unused)) struct cmdline *cl,
3138                                 void *show_rss_key)
3139 {
3140         struct cmd_showport_rss_hash *res = parsed_result;
3141
3142         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3143 }
3144
3145 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3146         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3147 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3148         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3149 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3150         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3151 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3152         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3153                                  "rss-hash");
3154 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3155         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3156
3157 cmdline_parse_inst_t cmd_showport_rss_hash = {
3158         .f = cmd_showport_rss_hash_parsed,
3159         .data = NULL,
3160         .help_str = "show port <port_id> rss-hash",
3161         .tokens = {
3162                 (void *)&cmd_showport_rss_hash_show,
3163                 (void *)&cmd_showport_rss_hash_port,
3164                 (void *)&cmd_showport_rss_hash_port_id,
3165                 (void *)&cmd_showport_rss_hash_rss_hash,
3166                 NULL,
3167         },
3168 };
3169
3170 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3171         .f = cmd_showport_rss_hash_parsed,
3172         .data = (void *)1,
3173         .help_str = "show port <port_id> rss-hash key",
3174         .tokens = {
3175                 (void *)&cmd_showport_rss_hash_show,
3176                 (void *)&cmd_showport_rss_hash_port,
3177                 (void *)&cmd_showport_rss_hash_port_id,
3178                 (void *)&cmd_showport_rss_hash_rss_hash,
3179                 (void *)&cmd_showport_rss_hash_rss_key,
3180                 NULL,
3181         },
3182 };
3183
3184 /* *** Configure DCB *** */
3185 struct cmd_config_dcb {
3186         cmdline_fixed_string_t port;
3187         cmdline_fixed_string_t config;
3188         portid_t port_id;
3189         cmdline_fixed_string_t dcb;
3190         cmdline_fixed_string_t vt;
3191         cmdline_fixed_string_t vt_en;
3192         uint8_t num_tcs;
3193         cmdline_fixed_string_t pfc;
3194         cmdline_fixed_string_t pfc_en;
3195 };
3196
3197 static void
3198 cmd_config_dcb_parsed(void *parsed_result,
3199                         __attribute__((unused)) struct cmdline *cl,
3200                         __attribute__((unused)) void *data)
3201 {
3202         struct cmd_config_dcb *res = parsed_result;
3203         portid_t port_id = res->port_id;
3204         struct rte_port *port;
3205         uint8_t pfc_en;
3206         int ret;
3207
3208         port = &ports[port_id];
3209         /** Check if the port is not started **/
3210         if (port->port_status != RTE_PORT_STOPPED) {
3211                 printf("Please stop port %d first\n", port_id);
3212                 return;
3213         }
3214
3215         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3216                 printf("The invalid number of traffic class,"
3217                         " only 4 or 8 allowed.\n");
3218                 return;
3219         }
3220
3221         if (nb_fwd_lcores < res->num_tcs) {
3222                 printf("nb_cores shouldn't be less than number of TCs.\n");
3223                 return;
3224         }
3225         if (!strncmp(res->pfc_en, "on", 2))
3226                 pfc_en = 1;
3227         else
3228                 pfc_en = 0;
3229
3230         /* DCB in VT mode */
3231         if (!strncmp(res->vt_en, "on", 2))
3232                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3233                                 (enum rte_eth_nb_tcs)res->num_tcs,
3234                                 pfc_en);
3235         else
3236                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3237                                 (enum rte_eth_nb_tcs)res->num_tcs,
3238                                 pfc_en);
3239
3240
3241         if (ret != 0) {
3242                 printf("Cannot initialize network ports.\n");
3243                 return;
3244         }
3245
3246         cmd_reconfig_device_queue(port_id, 1, 1);
3247 }
3248
3249 cmdline_parse_token_string_t cmd_config_dcb_port =
3250         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3251 cmdline_parse_token_string_t cmd_config_dcb_config =
3252         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3253 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3254         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3255 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3256         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3257 cmdline_parse_token_string_t cmd_config_dcb_vt =
3258         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3259 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3260         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3261 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3262         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3263 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3264         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3265 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3266         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3267
3268 cmdline_parse_inst_t cmd_config_dcb = {
3269         .f = cmd_config_dcb_parsed,
3270         .data = NULL,
3271         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3272         .tokens = {
3273                 (void *)&cmd_config_dcb_port,
3274                 (void *)&cmd_config_dcb_config,
3275                 (void *)&cmd_config_dcb_port_id,
3276                 (void *)&cmd_config_dcb_dcb,
3277                 (void *)&cmd_config_dcb_vt,
3278                 (void *)&cmd_config_dcb_vt_en,
3279                 (void *)&cmd_config_dcb_num_tcs,
3280                 (void *)&cmd_config_dcb_pfc,
3281                 (void *)&cmd_config_dcb_pfc_en,
3282                 NULL,
3283         },
3284 };
3285
3286 /* *** configure number of packets per burst *** */
3287 struct cmd_config_burst {
3288         cmdline_fixed_string_t port;
3289         cmdline_fixed_string_t keyword;
3290         cmdline_fixed_string_t all;
3291         cmdline_fixed_string_t name;
3292         uint16_t value;
3293 };
3294
3295 static void
3296 cmd_config_burst_parsed(void *parsed_result,
3297                         __attribute__((unused)) struct cmdline *cl,
3298                         __attribute__((unused)) void *data)
3299 {
3300         struct cmd_config_burst *res = parsed_result;
3301         struct rte_eth_dev_info dev_info;
3302         uint16_t rec_nb_pkts;
3303         int ret;
3304
3305         if (!all_ports_stopped()) {
3306                 printf("Please stop all ports first\n");
3307                 return;
3308         }
3309
3310         if (!strcmp(res->name, "burst")) {
3311                 if (res->value == 0) {
3312                         /* If user gives a value of zero, query the PMD for
3313                          * its recommended Rx burst size. Testpmd uses a single
3314                          * size for all ports, so assume all ports are the same
3315                          * NIC model and use the values from Port 0.
3316                          */
3317                         ret = eth_dev_info_get_print_err(0, &dev_info);
3318                         if (ret != 0)
3319                                 return;
3320
3321                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3322
3323                         if (rec_nb_pkts == 0) {
3324                                 printf("PMD does not recommend a burst size.\n"
3325                                         "User provided value must be between"
3326                                         " 1 and %d\n", MAX_PKT_BURST);
3327                                 return;
3328                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3329                                 printf("PMD recommended burst size of %d"
3330                                         " exceeds maximum value of %d\n",
3331                                         rec_nb_pkts, MAX_PKT_BURST);
3332                                 return;
3333                         }
3334                         printf("Using PMD-provided burst value of %d\n",
3335                                 rec_nb_pkts);
3336                         nb_pkt_per_burst = rec_nb_pkts;
3337                 } else if (res->value > MAX_PKT_BURST) {
3338                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3339                         return;
3340                 } else
3341                         nb_pkt_per_burst = res->value;
3342         } else {
3343                 printf("Unknown parameter\n");
3344                 return;
3345         }
3346
3347         init_port_config();
3348
3349         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3350 }
3351
3352 cmdline_parse_token_string_t cmd_config_burst_port =
3353         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3354 cmdline_parse_token_string_t cmd_config_burst_keyword =
3355         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3356 cmdline_parse_token_string_t cmd_config_burst_all =
3357         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3358 cmdline_parse_token_string_t cmd_config_burst_name =
3359         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3360 cmdline_parse_token_num_t cmd_config_burst_value =
3361         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3362
3363 cmdline_parse_inst_t cmd_config_burst = {
3364         .f = cmd_config_burst_parsed,
3365         .data = NULL,
3366         .help_str = "port config all burst <value>",
3367         .tokens = {
3368                 (void *)&cmd_config_burst_port,
3369                 (void *)&cmd_config_burst_keyword,
3370                 (void *)&cmd_config_burst_all,
3371                 (void *)&cmd_config_burst_name,
3372                 (void *)&cmd_config_burst_value,
3373                 NULL,
3374         },
3375 };
3376
3377 /* *** configure rx/tx queues *** */
3378 struct cmd_config_thresh {
3379         cmdline_fixed_string_t port;
3380         cmdline_fixed_string_t keyword;
3381         cmdline_fixed_string_t all;
3382         cmdline_fixed_string_t name;
3383         uint8_t value;
3384 };
3385
3386 static void
3387 cmd_config_thresh_parsed(void *parsed_result,
3388                         __attribute__((unused)) struct cmdline *cl,
3389                         __attribute__((unused)) void *data)
3390 {
3391         struct cmd_config_thresh *res = parsed_result;
3392
3393         if (!all_ports_stopped()) {
3394                 printf("Please stop all ports first\n");
3395                 return;
3396         }
3397
3398         if (!strcmp(res->name, "txpt"))
3399                 tx_pthresh = res->value;
3400         else if(!strcmp(res->name, "txht"))
3401                 tx_hthresh = res->value;
3402         else if(!strcmp(res->name, "txwt"))
3403                 tx_wthresh = res->value;
3404         else if(!strcmp(res->name, "rxpt"))
3405                 rx_pthresh = res->value;
3406         else if(!strcmp(res->name, "rxht"))
3407                 rx_hthresh = res->value;
3408         else if(!strcmp(res->name, "rxwt"))
3409                 rx_wthresh = res->value;
3410         else {
3411                 printf("Unknown parameter\n");
3412                 return;
3413         }
3414
3415         init_port_config();
3416
3417         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3418 }
3419
3420 cmdline_parse_token_string_t cmd_config_thresh_port =
3421         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3422 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3423         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3424 cmdline_parse_token_string_t cmd_config_thresh_all =
3425         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3426 cmdline_parse_token_string_t cmd_config_thresh_name =
3427         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3428                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3429 cmdline_parse_token_num_t cmd_config_thresh_value =
3430         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3431
3432 cmdline_parse_inst_t cmd_config_thresh = {
3433         .f = cmd_config_thresh_parsed,
3434         .data = NULL,
3435         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3436         .tokens = {
3437                 (void *)&cmd_config_thresh_port,
3438                 (void *)&cmd_config_thresh_keyword,
3439                 (void *)&cmd_config_thresh_all,
3440                 (void *)&cmd_config_thresh_name,
3441                 (void *)&cmd_config_thresh_value,
3442                 NULL,
3443         },
3444 };
3445
3446 /* *** configure free/rs threshold *** */
3447 struct cmd_config_threshold {
3448         cmdline_fixed_string_t port;
3449         cmdline_fixed_string_t keyword;
3450         cmdline_fixed_string_t all;
3451         cmdline_fixed_string_t name;
3452         uint16_t value;
3453 };
3454
3455 static void
3456 cmd_config_threshold_parsed(void *parsed_result,
3457                         __attribute__((unused)) struct cmdline *cl,
3458                         __attribute__((unused)) void *data)
3459 {
3460         struct cmd_config_threshold *res = parsed_result;
3461
3462         if (!all_ports_stopped()) {
3463                 printf("Please stop all ports first\n");
3464                 return;
3465         }
3466
3467         if (!strcmp(res->name, "txfreet"))
3468                 tx_free_thresh = res->value;
3469         else if (!strcmp(res->name, "txrst"))
3470                 tx_rs_thresh = res->value;
3471         else if (!strcmp(res->name, "rxfreet"))
3472                 rx_free_thresh = res->value;
3473         else {
3474                 printf("Unknown parameter\n");
3475                 return;
3476         }
3477
3478         init_port_config();
3479
3480         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3481 }
3482
3483 cmdline_parse_token_string_t cmd_config_threshold_port =
3484         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3485 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3486         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3487                                                                 "config");
3488 cmdline_parse_token_string_t cmd_config_threshold_all =
3489         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3490 cmdline_parse_token_string_t cmd_config_threshold_name =
3491         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3492                                                 "txfreet#txrst#rxfreet");
3493 cmdline_parse_token_num_t cmd_config_threshold_value =
3494         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3495
3496 cmdline_parse_inst_t cmd_config_threshold = {
3497         .f = cmd_config_threshold_parsed,
3498         .data = NULL,
3499         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3500         .tokens = {
3501                 (void *)&cmd_config_threshold_port,
3502                 (void *)&cmd_config_threshold_keyword,
3503                 (void *)&cmd_config_threshold_all,
3504                 (void *)&cmd_config_threshold_name,
3505                 (void *)&cmd_config_threshold_value,
3506                 NULL,
3507         },
3508 };
3509
3510 /* *** stop *** */
3511 struct cmd_stop_result {
3512         cmdline_fixed_string_t stop;
3513 };
3514
3515 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3516                             __attribute__((unused)) struct cmdline *cl,
3517                             __attribute__((unused)) void *data)
3518 {
3519         stop_packet_forwarding();
3520 }
3521
3522 cmdline_parse_token_string_t cmd_stop_stop =
3523         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3524
3525 cmdline_parse_inst_t cmd_stop = {
3526         .f = cmd_stop_parsed,
3527         .data = NULL,
3528         .help_str = "stop: Stop packet forwarding",
3529         .tokens = {
3530                 (void *)&cmd_stop_stop,
3531                 NULL,
3532         },
3533 };
3534
3535 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3536
3537 unsigned int
3538 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3539                 unsigned int *parsed_items, int check_unique_values)
3540 {
3541         unsigned int nb_item;
3542         unsigned int value;
3543         unsigned int i;
3544         unsigned int j;
3545         int value_ok;
3546         char c;
3547
3548         /*
3549          * First parse all items in the list and store their value.
3550          */
3551         value = 0;
3552         nb_item = 0;
3553         value_ok = 0;
3554         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3555                 c = str[i];
3556                 if ((c >= '0') && (c <= '9')) {
3557                         value = (unsigned int) (value * 10 + (c - '0'));
3558                         value_ok = 1;
3559                         continue;
3560                 }
3561                 if (c != ',') {
3562                         printf("character %c is not a decimal digit\n", c);
3563                         return 0;
3564                 }
3565                 if (! value_ok) {
3566                         printf("No valid value before comma\n");
3567                         return 0;
3568                 }
3569                 if (nb_item < max_items) {
3570                         parsed_items[nb_item] = value;
3571                         value_ok = 0;
3572                         value = 0;
3573                 }
3574                 nb_item++;
3575         }
3576         if (nb_item >= max_items) {
3577                 printf("Number of %s = %u > %u (maximum items)\n",
3578                        item_name, nb_item + 1, max_items);
3579                 return 0;
3580         }
3581         parsed_items[nb_item++] = value;
3582         if (! check_unique_values)
3583                 return nb_item;
3584
3585         /*
3586          * Then, check that all values in the list are differents.
3587          * No optimization here...
3588          */
3589         for (i = 0; i < nb_item; i++) {
3590                 for (j = i + 1; j < nb_item; j++) {
3591                         if (parsed_items[j] == parsed_items[i]) {
3592                                 printf("duplicated %s %u at index %u and %u\n",
3593                                        item_name, parsed_items[i], i, j);
3594                                 return 0;
3595                         }
3596                 }
3597         }
3598         return nb_item;
3599 }
3600
3601 struct cmd_set_list_result {
3602         cmdline_fixed_string_t cmd_keyword;
3603         cmdline_fixed_string_t list_name;
3604         cmdline_fixed_string_t list_of_items;
3605 };
3606
3607 static void cmd_set_list_parsed(void *parsed_result,
3608                                 __attribute__((unused)) struct cmdline *cl,
3609                                 __attribute__((unused)) void *data)
3610 {
3611         struct cmd_set_list_result *res;
3612         union {
3613                 unsigned int lcorelist[RTE_MAX_LCORE];
3614                 unsigned int portlist[RTE_MAX_ETHPORTS];
3615         } parsed_items;
3616         unsigned int nb_item;
3617
3618         if (test_done == 0) {
3619                 printf("Please stop forwarding first\n");
3620                 return;
3621         }
3622
3623         res = parsed_result;
3624         if (!strcmp(res->list_name, "corelist")) {
3625                 nb_item = parse_item_list(res->list_of_items, "core",
3626                                           RTE_MAX_LCORE,
3627                                           parsed_items.lcorelist, 1);
3628                 if (nb_item > 0) {
3629                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3630                         fwd_config_setup();
3631                 }
3632                 return;
3633         }
3634         if (!strcmp(res->list_name, "portlist")) {
3635                 nb_item = parse_item_list(res->list_of_items, "port",
3636                                           RTE_MAX_ETHPORTS,
3637                                           parsed_items.portlist, 1);
3638                 if (nb_item > 0) {
3639                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3640                         fwd_config_setup();
3641                 }
3642         }
3643 }
3644
3645 cmdline_parse_token_string_t cmd_set_list_keyword =
3646         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3647                                  "set");
3648 cmdline_parse_token_string_t cmd_set_list_name =
3649         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3650                                  "corelist#portlist");
3651 cmdline_parse_token_string_t cmd_set_list_of_items =
3652         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3653                                  NULL);
3654
3655 cmdline_parse_inst_t cmd_set_fwd_list = {
3656         .f = cmd_set_list_parsed,
3657         .data = NULL,
3658         .help_str = "set corelist|portlist <list0[,list1]*>",
3659         .tokens = {
3660                 (void *)&cmd_set_list_keyword,
3661                 (void *)&cmd_set_list_name,
3662                 (void *)&cmd_set_list_of_items,
3663                 NULL,
3664         },
3665 };
3666
3667 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3668
3669 struct cmd_setmask_result {
3670         cmdline_fixed_string_t set;
3671         cmdline_fixed_string_t mask;
3672         uint64_t hexavalue;
3673 };
3674
3675 static void cmd_set_mask_parsed(void *parsed_result,
3676                                 __attribute__((unused)) struct cmdline *cl,
3677                                 __attribute__((unused)) void *data)
3678 {
3679         struct cmd_setmask_result *res = parsed_result;
3680
3681         if (test_done == 0) {
3682                 printf("Please stop forwarding first\n");
3683                 return;
3684         }
3685         if (!strcmp(res->mask, "coremask")) {
3686                 set_fwd_lcores_mask(res->hexavalue);
3687                 fwd_config_setup();
3688         } else if (!strcmp(res->mask, "portmask")) {
3689                 set_fwd_ports_mask(res->hexavalue);
3690                 fwd_config_setup();
3691         }
3692 }
3693
3694 cmdline_parse_token_string_t cmd_setmask_set =
3695         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3696 cmdline_parse_token_string_t cmd_setmask_mask =
3697         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3698                                  "coremask#portmask");
3699 cmdline_parse_token_num_t cmd_setmask_value =
3700         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3701
3702 cmdline_parse_inst_t cmd_set_fwd_mask = {
3703         .f = cmd_set_mask_parsed,
3704         .data = NULL,
3705         .help_str = "set coremask|portmask <hexadecimal value>",
3706         .tokens = {
3707                 (void *)&cmd_setmask_set,
3708                 (void *)&cmd_setmask_mask,
3709                 (void *)&cmd_setmask_value,
3710                 NULL,
3711         },
3712 };
3713
3714 /*
3715  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3716  */
3717 struct cmd_set_result {
3718         cmdline_fixed_string_t set;
3719         cmdline_fixed_string_t what;
3720         uint16_t value;
3721 };
3722
3723 static void cmd_set_parsed(void *parsed_result,
3724                            __attribute__((unused)) struct cmdline *cl,
3725                            __attribute__((unused)) void *data)
3726 {
3727         struct cmd_set_result *res = parsed_result;
3728         if (!strcmp(res->what, "nbport")) {
3729                 set_fwd_ports_number(res->value);
3730                 fwd_config_setup();
3731         } else if (!strcmp(res->what, "nbcore")) {
3732                 set_fwd_lcores_number(res->value);
3733                 fwd_config_setup();
3734         } else if (!strcmp(res->what, "burst"))
3735                 set_nb_pkt_per_burst(res->value);
3736         else if (!strcmp(res->what, "verbose"))
3737                 set_verbose_level(res->value);
3738 }
3739
3740 cmdline_parse_token_string_t cmd_set_set =
3741         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3742 cmdline_parse_token_string_t cmd_set_what =
3743         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3744                                  "nbport#nbcore#burst#verbose");
3745 cmdline_parse_token_num_t cmd_set_value =
3746         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3747
3748 cmdline_parse_inst_t cmd_set_numbers = {
3749         .f = cmd_set_parsed,
3750         .data = NULL,
3751         .help_str = "set nbport|nbcore|burst|verbose <value>",
3752         .tokens = {
3753                 (void *)&cmd_set_set,
3754                 (void *)&cmd_set_what,
3755                 (void *)&cmd_set_value,
3756                 NULL,
3757         },
3758 };
3759
3760 /* *** SET LOG LEVEL CONFIGURATION *** */
3761
3762 struct cmd_set_log_result {
3763         cmdline_fixed_string_t set;
3764         cmdline_fixed_string_t log;
3765         cmdline_fixed_string_t type;
3766         uint32_t level;
3767 };
3768
3769 static void
3770 cmd_set_log_parsed(void *parsed_result,
3771                    __attribute__((unused)) struct cmdline *cl,
3772                    __attribute__((unused)) void *data)
3773 {
3774         struct cmd_set_log_result *res;
3775         int ret;
3776
3777         res = parsed_result;
3778         if (!strcmp(res->type, "global"))
3779                 rte_log_set_global_level(res->level);
3780         else {
3781                 ret = rte_log_set_level_regexp(res->type, res->level);
3782                 if (ret < 0)
3783                         printf("Unable to set log level\n");
3784         }
3785 }
3786
3787 cmdline_parse_token_string_t cmd_set_log_set =
3788         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3789 cmdline_parse_token_string_t cmd_set_log_log =
3790         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3791 cmdline_parse_token_string_t cmd_set_log_type =
3792         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3793 cmdline_parse_token_num_t cmd_set_log_level =
3794         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3795
3796 cmdline_parse_inst_t cmd_set_log = {
3797         .f = cmd_set_log_parsed,
3798         .data = NULL,
3799         .help_str = "set log global|<type> <level>",
3800         .tokens = {
3801                 (void *)&cmd_set_log_set,
3802                 (void *)&cmd_set_log_log,
3803                 (void *)&cmd_set_log_type,
3804                 (void *)&cmd_set_log_level,
3805                 NULL,
3806         },
3807 };
3808
3809 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3810
3811 struct cmd_set_txpkts_result {
3812         cmdline_fixed_string_t cmd_keyword;
3813         cmdline_fixed_string_t txpkts;
3814         cmdline_fixed_string_t seg_lengths;
3815 };
3816
3817 static void
3818 cmd_set_txpkts_parsed(void *parsed_result,
3819                       __attribute__((unused)) struct cmdline *cl,
3820                       __attribute__((unused)) void *data)
3821 {
3822         struct cmd_set_txpkts_result *res;
3823         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3824         unsigned int nb_segs;
3825
3826         res = parsed_result;
3827         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3828                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3829         if (nb_segs > 0)
3830                 set_tx_pkt_segments(seg_lengths, nb_segs);
3831 }
3832
3833 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3834         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3835                                  cmd_keyword, "set");
3836 cmdline_parse_token_string_t cmd_set_txpkts_name =
3837         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3838                                  txpkts, "txpkts");
3839 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3840         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3841                                  seg_lengths, NULL);
3842
3843 cmdline_parse_inst_t cmd_set_txpkts = {
3844         .f = cmd_set_txpkts_parsed,
3845         .data = NULL,
3846         .help_str = "set txpkts <len0[,len1]*>",
3847         .tokens = {
3848                 (void *)&cmd_set_txpkts_keyword,
3849                 (void *)&cmd_set_txpkts_name,
3850                 (void *)&cmd_set_txpkts_lengths,
3851                 NULL,
3852         },
3853 };
3854
3855 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3856
3857 struct cmd_set_txsplit_result {
3858         cmdline_fixed_string_t cmd_keyword;
3859         cmdline_fixed_string_t txsplit;
3860         cmdline_fixed_string_t mode;
3861 };
3862
3863 static void
3864 cmd_set_txsplit_parsed(void *parsed_result,
3865                       __attribute__((unused)) struct cmdline *cl,
3866                       __attribute__((unused)) void *data)
3867 {
3868         struct cmd_set_txsplit_result *res;
3869
3870         res = parsed_result;
3871         set_tx_pkt_split(res->mode);
3872 }
3873
3874 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3875         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3876                                  cmd_keyword, "set");
3877 cmdline_parse_token_string_t cmd_set_txsplit_name =
3878         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3879                                  txsplit, "txsplit");
3880 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3881         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3882                                  mode, NULL);
3883
3884 cmdline_parse_inst_t cmd_set_txsplit = {
3885         .f = cmd_set_txsplit_parsed,
3886         .data = NULL,
3887         .help_str = "set txsplit on|off|rand",
3888         .tokens = {
3889                 (void *)&cmd_set_txsplit_keyword,
3890                 (void *)&cmd_set_txsplit_name,
3891                 (void *)&cmd_set_txsplit_mode,
3892                 NULL,
3893         },
3894 };
3895
3896 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3897 struct cmd_rx_vlan_filter_all_result {
3898         cmdline_fixed_string_t rx_vlan;
3899         cmdline_fixed_string_t what;
3900         cmdline_fixed_string_t all;
3901         portid_t port_id;
3902 };
3903
3904 static void
3905 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3906                               __attribute__((unused)) struct cmdline *cl,
3907                               __attribute__((unused)) void *data)
3908 {
3909         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3910
3911         if (!strcmp(res->what, "add"))
3912                 rx_vlan_all_filter_set(res->port_id, 1);
3913         else
3914                 rx_vlan_all_filter_set(res->port_id, 0);
3915 }
3916
3917 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3918         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3919                                  rx_vlan, "rx_vlan");
3920 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3921         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3922                                  what, "add#rm");
3923 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3924         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3925                                  all, "all");
3926 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3927         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3928                               port_id, UINT16);
3929
3930 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3931         .f = cmd_rx_vlan_filter_all_parsed,
3932         .data = NULL,
3933         .help_str = "rx_vlan add|rm all <port_id>: "
3934                 "Add/Remove all identifiers to/from the set of VLAN "
3935                 "identifiers filtered by a port",
3936         .tokens = {
3937                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3938                 (void *)&cmd_rx_vlan_filter_all_what,
3939                 (void *)&cmd_rx_vlan_filter_all_all,
3940                 (void *)&cmd_rx_vlan_filter_all_portid,
3941                 NULL,
3942         },
3943 };
3944
3945 /* *** VLAN OFFLOAD SET ON A PORT *** */
3946 struct cmd_vlan_offload_result {
3947         cmdline_fixed_string_t vlan;
3948         cmdline_fixed_string_t set;
3949         cmdline_fixed_string_t vlan_type;
3950         cmdline_fixed_string_t what;
3951         cmdline_fixed_string_t on;
3952         cmdline_fixed_string_t port_id;
3953 };
3954
3955 static void
3956 cmd_vlan_offload_parsed(void *parsed_result,
3957                           __attribute__((unused)) struct cmdline *cl,
3958                           __attribute__((unused)) void *data)
3959 {
3960         int on;
3961         struct cmd_vlan_offload_result *res = parsed_result;
3962         char *str;
3963         int i, len = 0;
3964         portid_t port_id = 0;
3965         unsigned int tmp;
3966
3967         str = res->port_id;
3968         len = strnlen(str, STR_TOKEN_SIZE);
3969         i = 0;
3970         /* Get port_id first */
3971         while(i < len){
3972                 if(str[i] == ',')
3973                         break;
3974
3975                 i++;
3976         }
3977         str[i]='\0';
3978         tmp = strtoul(str, NULL, 0);
3979         /* If port_id greater that what portid_t can represent, return */
3980         if(tmp >= RTE_MAX_ETHPORTS)
3981                 return;
3982         port_id = (portid_t)tmp;
3983
3984         if (!strcmp(res->on, "on"))
3985                 on = 1;
3986         else
3987                 on = 0;
3988
3989         if (!strcmp(res->what, "strip"))
3990                 rx_vlan_strip_set(port_id,  on);
3991         else if(!strcmp(res->what, "stripq")){
3992                 uint16_t queue_id = 0;
3993
3994                 /* No queue_id, return */
3995                 if(i + 1 >= len) {
3996                         printf("must specify (port,queue_id)\n");
3997                         return;
3998                 }
3999                 tmp = strtoul(str + i + 1, NULL, 0);
4000                 /* If queue_id greater that what 16-bits can represent, return */
4001                 if(tmp > 0xffff)
4002                         return;
4003
4004                 queue_id = (uint16_t)tmp;
4005                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4006         }
4007         else if (!strcmp(res->what, "filter"))
4008                 rx_vlan_filter_set(port_id, on);
4009         else if (!strcmp(res->what, "qinq_strip"))
4010                 rx_vlan_qinq_strip_set(port_id, on);
4011         else
4012                 vlan_extend_set(port_id, on);
4013
4014         return;
4015 }
4016
4017 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4018         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4019                                  vlan, "vlan");
4020 cmdline_parse_token_string_t cmd_vlan_offload_set =
4021         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4022                                  set, "set");
4023 cmdline_parse_token_string_t cmd_vlan_offload_what =
4024         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4025                                 what, "strip#filter#qinq_strip#extend#stripq");
4026 cmdline_parse_token_string_t cmd_vlan_offload_on =
4027         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4028                               on, "on#off");
4029 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4030         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4031                               port_id, NULL);
4032
4033 cmdline_parse_inst_t cmd_vlan_offload = {
4034         .f = cmd_vlan_offload_parsed,
4035         .data = NULL,
4036         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4037                 "<port_id[,queue_id]>: "
4038                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4039         .tokens = {
4040                 (void *)&cmd_vlan_offload_vlan,
4041                 (void *)&cmd_vlan_offload_set,
4042                 (void *)&cmd_vlan_offload_what,
4043                 (void *)&cmd_vlan_offload_on,
4044                 (void *)&cmd_vlan_offload_portid,
4045                 NULL,
4046         },
4047 };
4048
4049 /* *** VLAN TPID SET ON A PORT *** */
4050 struct cmd_vlan_tpid_result {
4051         cmdline_fixed_string_t vlan;
4052         cmdline_fixed_string_t set;
4053         cmdline_fixed_string_t vlan_type;
4054         cmdline_fixed_string_t what;
4055         uint16_t tp_id;
4056         portid_t port_id;
4057 };
4058
4059 static void
4060 cmd_vlan_tpid_parsed(void *parsed_result,
4061                           __attribute__((unused)) struct cmdline *cl,
4062                           __attribute__((unused)) void *data)
4063 {
4064         struct cmd_vlan_tpid_result *res = parsed_result;
4065         enum rte_vlan_type vlan_type;
4066
4067         if (!strcmp(res->vlan_type, "inner"))
4068                 vlan_type = ETH_VLAN_TYPE_INNER;
4069         else if (!strcmp(res->vlan_type, "outer"))
4070                 vlan_type = ETH_VLAN_TYPE_OUTER;
4071         else {
4072                 printf("Unknown vlan type\n");
4073                 return;
4074         }
4075         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4076 }
4077
4078 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4079         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4080                                  vlan, "vlan");
4081 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4082         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4083                                  set, "set");
4084 cmdline_parse_token_string_t cmd_vlan_type =
4085         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4086                                  vlan_type, "inner#outer");
4087 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4088         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4089                                  what, "tpid");
4090 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4091         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4092                               tp_id, UINT16);
4093 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4094         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4095                               port_id, UINT16);
4096
4097 cmdline_parse_inst_t cmd_vlan_tpid = {
4098         .f = cmd_vlan_tpid_parsed,
4099         .data = NULL,
4100         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4101                 "Set the VLAN Ether type",
4102         .tokens = {
4103                 (void *)&cmd_vlan_tpid_vlan,
4104                 (void *)&cmd_vlan_tpid_set,
4105                 (void *)&cmd_vlan_type,
4106                 (void *)&cmd_vlan_tpid_what,
4107                 (void *)&cmd_vlan_tpid_tpid,
4108                 (void *)&cmd_vlan_tpid_portid,
4109                 NULL,
4110         },
4111 };
4112
4113 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4114 struct cmd_rx_vlan_filter_result {
4115         cmdline_fixed_string_t rx_vlan;
4116         cmdline_fixed_string_t what;
4117         uint16_t vlan_id;
4118         portid_t port_id;
4119 };
4120
4121 static void
4122 cmd_rx_vlan_filter_parsed(void *parsed_result,
4123                           __attribute__((unused)) struct cmdline *cl,
4124                           __attribute__((unused)) void *data)
4125 {
4126         struct cmd_rx_vlan_filter_result *res = parsed_result;
4127
4128         if (!strcmp(res->what, "add"))
4129                 rx_vft_set(res->port_id, res->vlan_id, 1);
4130         else
4131                 rx_vft_set(res->port_id, res->vlan_id, 0);
4132 }
4133
4134 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4135         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4136                                  rx_vlan, "rx_vlan");
4137 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4138         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4139                                  what, "add#rm");
4140 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4141         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4142                               vlan_id, UINT16);
4143 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4144         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4145                               port_id, UINT16);
4146
4147 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4148         .f = cmd_rx_vlan_filter_parsed,
4149         .data = NULL,
4150         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4151                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4152                 "identifiers filtered by a port",
4153         .tokens = {
4154                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4155                 (void *)&cmd_rx_vlan_filter_what,
4156                 (void *)&cmd_rx_vlan_filter_vlanid,
4157                 (void *)&cmd_rx_vlan_filter_portid,
4158                 NULL,
4159         },
4160 };
4161
4162 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4163 struct cmd_tx_vlan_set_result {
4164         cmdline_fixed_string_t tx_vlan;
4165         cmdline_fixed_string_t set;
4166         portid_t port_id;
4167         uint16_t vlan_id;
4168 };
4169
4170 static void
4171 cmd_tx_vlan_set_parsed(void *parsed_result,
4172                        __attribute__((unused)) struct cmdline *cl,
4173                        __attribute__((unused)) void *data)
4174 {
4175         struct cmd_tx_vlan_set_result *res = parsed_result;
4176
4177         if (!port_is_stopped(res->port_id)) {
4178                 printf("Please stop port %d first\n", res->port_id);
4179                 return;
4180         }
4181
4182         tx_vlan_set(res->port_id, res->vlan_id);
4183
4184         cmd_reconfig_device_queue(res->port_id, 1, 1);
4185 }
4186
4187 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4188         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4189                                  tx_vlan, "tx_vlan");
4190 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4191         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4192                                  set, "set");
4193 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4194         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4195                               port_id, UINT16);
4196 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4197         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4198                               vlan_id, UINT16);
4199
4200 cmdline_parse_inst_t cmd_tx_vlan_set = {
4201         .f = cmd_tx_vlan_set_parsed,
4202         .data = NULL,
4203         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4204                 "Enable hardware insertion of a single VLAN header "
4205                 "with a given TAG Identifier in packets sent on a port",
4206         .tokens = {
4207                 (void *)&cmd_tx_vlan_set_tx_vlan,
4208                 (void *)&cmd_tx_vlan_set_set,
4209                 (void *)&cmd_tx_vlan_set_portid,
4210                 (void *)&cmd_tx_vlan_set_vlanid,
4211                 NULL,
4212         },
4213 };
4214
4215 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4216 struct cmd_tx_vlan_set_qinq_result {
4217         cmdline_fixed_string_t tx_vlan;
4218         cmdline_fixed_string_t set;
4219         portid_t port_id;
4220         uint16_t vlan_id;
4221         uint16_t vlan_id_outer;
4222 };
4223
4224 static void
4225 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4226                             __attribute__((unused)) struct cmdline *cl,
4227                             __attribute__((unused)) void *data)
4228 {
4229         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4230
4231         if (!port_is_stopped(res->port_id)) {
4232                 printf("Please stop port %d first\n", res->port_id);
4233                 return;
4234         }
4235
4236         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4237
4238         cmd_reconfig_device_queue(res->port_id, 1, 1);
4239 }
4240
4241 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4242         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4243                 tx_vlan, "tx_vlan");
4244 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4245         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4246                 set, "set");
4247 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4248         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4249                 port_id, UINT16);
4250 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4251         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4252                 vlan_id, UINT16);
4253 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4254         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4255                 vlan_id_outer, UINT16);
4256
4257 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4258         .f = cmd_tx_vlan_set_qinq_parsed,
4259         .data = NULL,
4260         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4261                 "Enable hardware insertion of double VLAN header "
4262                 "with given TAG Identifiers in packets sent on a port",
4263         .tokens = {
4264                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4265                 (void *)&cmd_tx_vlan_set_qinq_set,
4266                 (void *)&cmd_tx_vlan_set_qinq_portid,
4267                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4268                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4269                 NULL,
4270         },
4271 };
4272
4273 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4274 struct cmd_tx_vlan_set_pvid_result {
4275         cmdline_fixed_string_t tx_vlan;
4276         cmdline_fixed_string_t set;
4277         cmdline_fixed_string_t pvid;
4278         portid_t port_id;
4279         uint16_t vlan_id;
4280         cmdline_fixed_string_t mode;
4281 };
4282
4283 static void
4284 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4285                             __attribute__((unused)) struct cmdline *cl,
4286                             __attribute__((unused)) void *data)
4287 {
4288         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4289
4290         if (strcmp(res->mode, "on") == 0)
4291                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4292         else
4293                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4294 }
4295
4296 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4297         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4298                                  tx_vlan, "tx_vlan");
4299 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4300         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4301                                  set, "set");
4302 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4303         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4304                                  pvid, "pvid");
4305 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4306         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4307                              port_id, UINT16);
4308 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4309         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4310                               vlan_id, UINT16);
4311 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4312         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4313                                  mode, "on#off");
4314
4315 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4316         .f = cmd_tx_vlan_set_pvid_parsed,
4317         .data = NULL,
4318         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4319         .tokens = {
4320                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4321                 (void *)&cmd_tx_vlan_set_pvid_set,
4322                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4323                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4324                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4325                 (void *)&cmd_tx_vlan_set_pvid_mode,
4326                 NULL,
4327         },
4328 };
4329
4330 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4331 struct cmd_tx_vlan_reset_result {
4332         cmdline_fixed_string_t tx_vlan;
4333         cmdline_fixed_string_t reset;
4334         portid_t port_id;
4335 };
4336
4337 static void
4338 cmd_tx_vlan_reset_parsed(void *parsed_result,
4339                          __attribute__((unused)) struct cmdline *cl,
4340                          __attribute__((unused)) void *data)
4341 {
4342         struct cmd_tx_vlan_reset_result *res = parsed_result;
4343
4344         if (!port_is_stopped(res->port_id)) {
4345                 printf("Please stop port %d first\n", res->port_id);
4346                 return;
4347         }
4348
4349         tx_vlan_reset(res->port_id);
4350
4351         cmd_reconfig_device_queue(res->port_id, 1, 1);
4352 }
4353
4354 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4355         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4356                                  tx_vlan, "tx_vlan");
4357 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4358         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4359                                  reset, "reset");
4360 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4361         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4362                               port_id, UINT16);
4363
4364 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4365         .f = cmd_tx_vlan_reset_parsed,
4366         .data = NULL,
4367         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4368                 "VLAN header in packets sent on a port",
4369         .tokens = {
4370                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4371                 (void *)&cmd_tx_vlan_reset_reset,
4372                 (void *)&cmd_tx_vlan_reset_portid,
4373                 NULL,
4374         },
4375 };
4376
4377
4378 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4379 struct cmd_csum_result {
4380         cmdline_fixed_string_t csum;
4381         cmdline_fixed_string_t mode;
4382         cmdline_fixed_string_t proto;
4383         cmdline_fixed_string_t hwsw;
4384         portid_t port_id;
4385 };
4386
4387 static void
4388 csum_show(int port_id)
4389 {
4390         struct rte_eth_dev_info dev_info;
4391         uint64_t tx_offloads;
4392         int ret;
4393
4394         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4395         printf("Parse tunnel is %s\n",
4396                 (ports[port_id].parse_tunnel) ? "on" : "off");
4397         printf("IP checksum offload is %s\n",
4398                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4399         printf("UDP checksum offload is %s\n",
4400                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4401         printf("TCP checksum offload is %s\n",
4402                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4403         printf("SCTP checksum offload is %s\n",
4404                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4405         printf("Outer-Ip checksum offload is %s\n",
4406                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4407         printf("Outer-Udp checksum offload is %s\n",
4408                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4409
4410         /* display warnings if configuration is not supported by the NIC */
4411         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4412         if (ret != 0)
4413                 return;
4414
4415         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4416                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4417                 printf("Warning: hardware IP checksum enabled but not "
4418                         "supported by port %d\n", port_id);
4419         }
4420         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4421                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4422                 printf("Warning: hardware UDP checksum enabled but not "
4423                         "supported by port %d\n", port_id);
4424         }
4425         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4426                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4427                 printf("Warning: hardware TCP checksum enabled but not "
4428                         "supported by port %d\n", port_id);
4429         }
4430         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4431                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4432                 printf("Warning: hardware SCTP checksum enabled but not "
4433                         "supported by port %d\n", port_id);
4434         }
4435         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4436                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4437                 printf("Warning: hardware outer IP checksum enabled but not "
4438                         "supported by port %d\n", port_id);
4439         }
4440         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4441                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4442                         == 0) {
4443                 printf("Warning: hardware outer UDP checksum enabled but not "
4444                         "supported by port %d\n", port_id);
4445         }
4446 }
4447
4448 static void
4449 cmd_config_queue_tx_offloads(struct rte_port *port)
4450 {
4451         int k;
4452
4453         /* Apply queue tx offloads configuration */
4454         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4455                 port->tx_conf[k].offloads =
4456                         port->dev_conf.txmode.offloads;
4457 }
4458
4459 static void
4460 cmd_csum_parsed(void *parsed_result,
4461                        __attribute__((unused)) struct cmdline *cl,
4462                        __attribute__((unused)) void *data)
4463 {
4464         struct cmd_csum_result *res = parsed_result;
4465         int hw = 0;
4466         uint64_t csum_offloads = 0;
4467         struct rte_eth_dev_info dev_info;
4468         int ret;
4469
4470         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4471                 printf("invalid port %d\n", res->port_id);
4472                 return;
4473         }
4474         if (!port_is_stopped(res->port_id)) {
4475                 printf("Please stop port %d first\n", res->port_id);
4476                 return;
4477         }
4478
4479         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4480         if (ret != 0)
4481                 return;
4482
4483         if (!strcmp(res->mode, "set")) {
4484
4485                 if (!strcmp(res->hwsw, "hw"))
4486                         hw = 1;
4487
4488                 if (!strcmp(res->proto, "ip")) {
4489                         if (hw == 0 || (dev_info.tx_offload_capa &
4490                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4491                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4492                         } else {
4493                                 printf("IP checksum offload is not supported "
4494                                        "by port %u\n", res->port_id);
4495                         }
4496                 } else if (!strcmp(res->proto, "udp")) {
4497                         if (hw == 0 || (dev_info.tx_offload_capa &
4498                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4499                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4500                         } else {
4501                                 printf("UDP checksum offload is not supported "
4502                                        "by port %u\n", res->port_id);
4503                         }
4504                 } else if (!strcmp(res->proto, "tcp")) {
4505                         if (hw == 0 || (dev_info.tx_offload_capa &
4506                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4507                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4508                         } else {
4509                                 printf("TCP checksum offload is not supported "
4510                                        "by port %u\n", res->port_id);
4511                         }
4512                 } else if (!strcmp(res->proto, "sctp")) {
4513                         if (hw == 0 || (dev_info.tx_offload_capa &
4514                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4515                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4516                         } else {
4517                                 printf("SCTP checksum offload is not supported "
4518                                        "by port %u\n", res->port_id);
4519                         }
4520                 } else if (!strcmp(res->proto, "outer-ip")) {
4521                         if (hw == 0 || (dev_info.tx_offload_capa &
4522                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4523                                 csum_offloads |=
4524                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4525                         } else {
4526                                 printf("Outer IP checksum offload is not "
4527                                        "supported by port %u\n", res->port_id);
4528                         }
4529                 } else if (!strcmp(res->proto, "outer-udp")) {
4530                         if (hw == 0 || (dev_info.tx_offload_capa &
4531                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4532                                 csum_offloads |=
4533                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4534                         } else {
4535                                 printf("Outer UDP checksum offload is not "
4536                                        "supported by port %u\n", res->port_id);
4537                         }
4538                 }
4539
4540                 if (hw) {
4541                         ports[res->port_id].dev_conf.txmode.offloads |=
4542                                                         csum_offloads;
4543                 } else {
4544                         ports[res->port_id].dev_conf.txmode.offloads &=
4545                                                         (~csum_offloads);
4546                 }
4547                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4548         }
4549         csum_show(res->port_id);
4550
4551         cmd_reconfig_device_queue(res->port_id, 1, 1);
4552 }
4553
4554 cmdline_parse_token_string_t cmd_csum_csum =
4555         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4556                                 csum, "csum");
4557 cmdline_parse_token_string_t cmd_csum_mode =
4558         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4559                                 mode, "set");
4560 cmdline_parse_token_string_t cmd_csum_proto =
4561         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4562                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4563 cmdline_parse_token_string_t cmd_csum_hwsw =
4564         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4565                                 hwsw, "hw#sw");
4566 cmdline_parse_token_num_t cmd_csum_portid =
4567         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4568                                 port_id, UINT16);
4569
4570 cmdline_parse_inst_t cmd_csum_set = {
4571         .f = cmd_csum_parsed,
4572         .data = NULL,
4573         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4574                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4575                 "using csum forward engine",
4576         .tokens = {
4577                 (void *)&cmd_csum_csum,
4578                 (void *)&cmd_csum_mode,
4579                 (void *)&cmd_csum_proto,
4580                 (void *)&cmd_csum_hwsw,
4581                 (void *)&cmd_csum_portid,
4582                 NULL,
4583         },
4584 };
4585
4586 cmdline_parse_token_string_t cmd_csum_mode_show =
4587         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4588                                 mode, "show");
4589
4590 cmdline_parse_inst_t cmd_csum_show = {
4591         .f = cmd_csum_parsed,
4592         .data = NULL,
4593         .help_str = "csum show <port_id>: Show checksum offload configuration",
4594         .tokens = {
4595                 (void *)&cmd_csum_csum,
4596                 (void *)&cmd_csum_mode_show,
4597                 (void *)&cmd_csum_portid,
4598                 NULL,
4599         },
4600 };
4601
4602 /* Enable/disable tunnel parsing */
4603 struct cmd_csum_tunnel_result {
4604         cmdline_fixed_string_t csum;
4605         cmdline_fixed_string_t parse;
4606         cmdline_fixed_string_t onoff;
4607         portid_t port_id;
4608 };
4609
4610 static void
4611 cmd_csum_tunnel_parsed(void *parsed_result,
4612                        __attribute__((unused)) struct cmdline *cl,
4613                        __attribute__((unused)) void *data)
4614 {
4615         struct cmd_csum_tunnel_result *res = parsed_result;
4616
4617         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4618                 return;
4619
4620         if (!strcmp(res->onoff, "on"))
4621                 ports[res->port_id].parse_tunnel = 1;
4622         else
4623                 ports[res->port_id].parse_tunnel = 0;
4624
4625         csum_show(res->port_id);
4626 }
4627
4628 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4629         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4630                                 csum, "csum");
4631 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4632         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4633                                 parse, "parse-tunnel");
4634 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4635         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4636                                 onoff, "on#off");
4637 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4638         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4639                                 port_id, UINT16);
4640
4641 cmdline_parse_inst_t cmd_csum_tunnel = {
4642         .f = cmd_csum_tunnel_parsed,
4643         .data = NULL,
4644         .help_str = "csum parse-tunnel on|off <port_id>: "
4645                 "Enable/Disable parsing of tunnels for csum engine",
4646         .tokens = {
4647                 (void *)&cmd_csum_tunnel_csum,
4648                 (void *)&cmd_csum_tunnel_parse,
4649                 (void *)&cmd_csum_tunnel_onoff,
4650                 (void *)&cmd_csum_tunnel_portid,
4651                 NULL,
4652         },
4653 };
4654
4655 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4656 struct cmd_tso_set_result {
4657         cmdline_fixed_string_t tso;
4658         cmdline_fixed_string_t mode;
4659         uint16_t tso_segsz;
4660         portid_t port_id;
4661 };
4662
4663 static void
4664 cmd_tso_set_parsed(void *parsed_result,
4665                        __attribute__((unused)) struct cmdline *cl,
4666                        __attribute__((unused)) void *data)
4667 {
4668         struct cmd_tso_set_result *res = parsed_result;
4669         struct rte_eth_dev_info dev_info;
4670         int ret;
4671
4672         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4673                 return;
4674         if (!port_is_stopped(res->port_id)) {
4675                 printf("Please stop port %d first\n", res->port_id);
4676                 return;
4677         }
4678
4679         if (!strcmp(res->mode, "set"))
4680                 ports[res->port_id].tso_segsz = res->tso_segsz;
4681
4682         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4683         if (ret != 0)
4684                 return;
4685
4686         if ((ports[res->port_id].tso_segsz != 0) &&
4687                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4688                 printf("Error: TSO is not supported by port %d\n",
4689                        res->port_id);
4690                 return;
4691         }
4692
4693         if (ports[res->port_id].tso_segsz == 0) {
4694                 ports[res->port_id].dev_conf.txmode.offloads &=
4695                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4696                 printf("TSO for non-tunneled packets is disabled\n");
4697         } else {
4698                 ports[res->port_id].dev_conf.txmode.offloads |=
4699                                                 DEV_TX_OFFLOAD_TCP_TSO;
4700                 printf("TSO segment size for non-tunneled packets is %d\n",
4701                         ports[res->port_id].tso_segsz);
4702         }
4703         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4704
4705         /* display warnings if configuration is not supported by the NIC */
4706         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4707         if (ret != 0)
4708                 return;
4709
4710         if ((ports[res->port_id].tso_segsz != 0) &&
4711                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4712                 printf("Warning: TSO enabled but not "
4713                         "supported by port %d\n", res->port_id);
4714         }
4715
4716         cmd_reconfig_device_queue(res->port_id, 1, 1);
4717 }
4718
4719 cmdline_parse_token_string_t cmd_tso_set_tso =
4720         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4721                                 tso, "tso");
4722 cmdline_parse_token_string_t cmd_tso_set_mode =
4723         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4724                                 mode, "set");
4725 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4726         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4727                                 tso_segsz, UINT16);
4728 cmdline_parse_token_num_t cmd_tso_set_portid =
4729         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4730                                 port_id, UINT16);
4731
4732 cmdline_parse_inst_t cmd_tso_set = {
4733         .f = cmd_tso_set_parsed,
4734         .data = NULL,
4735         .help_str = "tso set <tso_segsz> <port_id>: "
4736                 "Set TSO segment size of non-tunneled packets for csum engine "
4737                 "(0 to disable)",
4738         .tokens = {
4739                 (void *)&cmd_tso_set_tso,
4740                 (void *)&cmd_tso_set_mode,
4741                 (void *)&cmd_tso_set_tso_segsz,
4742                 (void *)&cmd_tso_set_portid,
4743                 NULL,
4744         },
4745 };
4746
4747 cmdline_parse_token_string_t cmd_tso_show_mode =
4748         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4749                                 mode, "show");
4750
4751
4752 cmdline_parse_inst_t cmd_tso_show = {
4753         .f = cmd_tso_set_parsed,
4754         .data = NULL,
4755         .help_str = "tso show <port_id>: "
4756                 "Show TSO segment size of non-tunneled packets for csum engine",
4757         .tokens = {
4758                 (void *)&cmd_tso_set_tso,
4759                 (void *)&cmd_tso_show_mode,
4760                 (void *)&cmd_tso_set_portid,
4761                 NULL,
4762         },
4763 };
4764
4765 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4766 struct cmd_tunnel_tso_set_result {
4767         cmdline_fixed_string_t tso;
4768         cmdline_fixed_string_t mode;
4769         uint16_t tso_segsz;
4770         portid_t port_id;
4771 };
4772
4773 static struct rte_eth_dev_info
4774 check_tunnel_tso_nic_support(portid_t port_id)
4775 {
4776         struct rte_eth_dev_info dev_info;
4777
4778         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4779                 return dev_info;
4780
4781         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4782                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4783                        "not enabled for port %d\n", port_id);
4784         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4785                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4786                        "not enabled for port %d\n", port_id);
4787         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4788                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4789                        "not enabled for port %d\n", port_id);
4790         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4791                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4792                        "not enabled for port %d\n", port_id);
4793         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4794                 printf("Warning: IP TUNNEL TSO not supported therefore "
4795                        "not enabled for port %d\n", port_id);
4796         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4797                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4798                        "not enabled for port %d\n", port_id);
4799         return dev_info;
4800 }
4801
4802 static void
4803 cmd_tunnel_tso_set_parsed(void *parsed_result,
4804                           __attribute__((unused)) struct cmdline *cl,
4805                           __attribute__((unused)) void *data)
4806 {
4807         struct cmd_tunnel_tso_set_result *res = parsed_result;
4808         struct rte_eth_dev_info dev_info;
4809
4810         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4811                 return;
4812         if (!port_is_stopped(res->port_id)) {
4813                 printf("Please stop port %d first\n", res->port_id);
4814                 return;
4815         }
4816
4817         if (!strcmp(res->mode, "set"))
4818                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4819
4820         dev_info = check_tunnel_tso_nic_support(res->port_id);
4821         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4822                 ports[res->port_id].dev_conf.txmode.offloads &=
4823                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4824                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4825                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4826                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4827                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4828                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4829                 printf("TSO for tunneled packets is disabled\n");
4830         } else {
4831                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4832                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4833                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4834                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4835                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4836                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4837
4838                 ports[res->port_id].dev_conf.txmode.offloads |=
4839                         (tso_offloads & dev_info.tx_offload_capa);
4840                 printf("TSO segment size for tunneled packets is %d\n",
4841                         ports[res->port_id].tunnel_tso_segsz);
4842
4843                 /* Below conditions are needed to make it work:
4844                  * (1) tunnel TSO is supported by the NIC;
4845                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4846                  * are recognized;
4847                  * (3) for tunneled pkts with outer L3 of IPv4,
4848                  * "csum set outer-ip" must be set to hw, because after tso,
4849                  * total_len of outer IP header is changed, and the checksum
4850                  * of outer IP header calculated by sw should be wrong; that
4851                  * is not necessary for IPv6 tunneled pkts because there's no
4852                  * checksum in IP header anymore.
4853                  */
4854
4855                 if (!ports[res->port_id].parse_tunnel)
4856                         printf("Warning: csum parse_tunnel must be set "
4857                                 "so that tunneled packets are recognized\n");
4858                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4859                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4860                         printf("Warning: csum set outer-ip must be set to hw "
4861                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4862         }
4863
4864         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4865         cmd_reconfig_device_queue(res->port_id, 1, 1);
4866 }
4867
4868 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4869         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4870                                 tso, "tunnel_tso");
4871 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4872         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4873                                 mode, "set");
4874 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4875         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4876                                 tso_segsz, UINT16);
4877 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4878         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4879                                 port_id, UINT16);
4880
4881 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4882         .f = cmd_tunnel_tso_set_parsed,
4883         .data = NULL,
4884         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4885                 "Set TSO segment size of tunneled packets for csum engine "
4886                 "(0 to disable)",
4887         .tokens = {
4888                 (void *)&cmd_tunnel_tso_set_tso,
4889                 (void *)&cmd_tunnel_tso_set_mode,
4890                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4891                 (void *)&cmd_tunnel_tso_set_portid,
4892                 NULL,
4893         },
4894 };
4895
4896 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4897         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4898                                 mode, "show");
4899
4900
4901 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4902         .f = cmd_tunnel_tso_set_parsed,
4903         .data = NULL,
4904         .help_str = "tunnel_tso show <port_id> "
4905                 "Show TSO segment size of tunneled packets for csum engine",
4906         .tokens = {
4907                 (void *)&cmd_tunnel_tso_set_tso,
4908                 (void *)&cmd_tunnel_tso_show_mode,
4909                 (void *)&cmd_tunnel_tso_set_portid,
4910                 NULL,
4911         },
4912 };
4913
4914 /* *** SET GRO FOR A PORT *** */
4915 struct cmd_gro_enable_result {
4916         cmdline_fixed_string_t cmd_set;
4917         cmdline_fixed_string_t cmd_port;
4918         cmdline_fixed_string_t cmd_keyword;
4919         cmdline_fixed_string_t cmd_onoff;
4920         portid_t cmd_pid;
4921 };
4922
4923 static void
4924 cmd_gro_enable_parsed(void *parsed_result,
4925                 __attribute__((unused)) struct cmdline *cl,
4926                 __attribute__((unused)) void *data)
4927 {
4928         struct cmd_gro_enable_result *res;
4929
4930         res = parsed_result;
4931         if (!strcmp(res->cmd_keyword, "gro"))
4932                 setup_gro(res->cmd_onoff, res->cmd_pid);
4933 }
4934
4935 cmdline_parse_token_string_t cmd_gro_enable_set =
4936         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4937                         cmd_set, "set");
4938 cmdline_parse_token_string_t cmd_gro_enable_port =
4939         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4940                         cmd_keyword, "port");
4941 cmdline_parse_token_num_t cmd_gro_enable_pid =
4942         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4943                         cmd_pid, UINT16);
4944 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4945         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4946                         cmd_keyword, "gro");
4947 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4948         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4949                         cmd_onoff, "on#off");
4950
4951 cmdline_parse_inst_t cmd_gro_enable = {
4952         .f = cmd_gro_enable_parsed,
4953         .data = NULL,
4954         .help_str = "set port <port_id> gro on|off",
4955         .tokens = {
4956                 (void *)&cmd_gro_enable_set,
4957                 (void *)&cmd_gro_enable_port,
4958                 (void *)&cmd_gro_enable_pid,
4959                 (void *)&cmd_gro_enable_keyword,
4960                 (void *)&cmd_gro_enable_onoff,
4961                 NULL,
4962         },
4963 };
4964
4965 /* *** DISPLAY GRO CONFIGURATION *** */
4966 struct cmd_gro_show_result {
4967         cmdline_fixed_string_t cmd_show;
4968         cmdline_fixed_string_t cmd_port;
4969         cmdline_fixed_string_t cmd_keyword;
4970         portid_t cmd_pid;
4971 };
4972
4973 static void
4974 cmd_gro_show_parsed(void *parsed_result,
4975                 __attribute__((unused)) struct cmdline *cl,
4976                 __attribute__((unused)) void *data)
4977 {
4978         struct cmd_gro_show_result *res;
4979
4980         res = parsed_result;
4981         if (!strcmp(res->cmd_keyword, "gro"))
4982                 show_gro(res->cmd_pid);
4983 }
4984
4985 cmdline_parse_token_string_t cmd_gro_show_show =
4986         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4987                         cmd_show, "show");
4988 cmdline_parse_token_string_t cmd_gro_show_port =
4989         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4990                         cmd_port, "port");
4991 cmdline_parse_token_num_t cmd_gro_show_pid =
4992         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4993                         cmd_pid, UINT16);
4994 cmdline_parse_token_string_t cmd_gro_show_keyword =
4995         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4996                         cmd_keyword, "gro");
4997
4998 cmdline_parse_inst_t cmd_gro_show = {
4999         .f = cmd_gro_show_parsed,
5000         .data = NULL,
5001         .help_str = "show port <port_id> gro",
5002         .tokens = {
5003                 (void *)&cmd_gro_show_show,
5004                 (void *)&cmd_gro_show_port,
5005                 (void *)&cmd_gro_show_pid,
5006                 (void *)&cmd_gro_show_keyword,
5007                 NULL,
5008         },
5009 };
5010
5011 /* *** SET FLUSH CYCLES FOR GRO *** */
5012 struct cmd_gro_flush_result {
5013         cmdline_fixed_string_t cmd_set;
5014         cmdline_fixed_string_t cmd_keyword;
5015         cmdline_fixed_string_t cmd_flush;
5016         uint8_t cmd_cycles;
5017 };
5018
5019 static void
5020 cmd_gro_flush_parsed(void *parsed_result,
5021                 __attribute__((unused)) struct cmdline *cl,
5022                 __attribute__((unused)) void *data)
5023 {
5024         struct cmd_gro_flush_result *res;
5025
5026         res = parsed_result;
5027         if ((!strcmp(res->cmd_keyword, "gro")) &&
5028                         (!strcmp(res->cmd_flush, "flush")))
5029                 setup_gro_flush_cycles(res->cmd_cycles);
5030 }
5031
5032 cmdline_parse_token_string_t cmd_gro_flush_set =
5033         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5034                         cmd_set, "set");
5035 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5036         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5037                         cmd_keyword, "gro");
5038 cmdline_parse_token_string_t cmd_gro_flush_flush =
5039         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5040                         cmd_flush, "flush");
5041 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5042         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5043                         cmd_cycles, UINT8);
5044
5045 cmdline_parse_inst_t cmd_gro_flush = {
5046         .f = cmd_gro_flush_parsed,
5047         .data = NULL,
5048         .help_str = "set gro flush <cycles>",
5049         .tokens = {
5050                 (void *)&cmd_gro_flush_set,
5051                 (void *)&cmd_gro_flush_keyword,
5052                 (void *)&cmd_gro_flush_flush,
5053                 (void *)&cmd_gro_flush_cycles,
5054                 NULL,
5055         },
5056 };
5057
5058 /* *** ENABLE/DISABLE GSO *** */
5059 struct cmd_gso_enable_result {
5060         cmdline_fixed_string_t cmd_set;
5061         cmdline_fixed_string_t cmd_port;
5062         cmdline_fixed_string_t cmd_keyword;
5063         cmdline_fixed_string_t cmd_mode;
5064         portid_t cmd_pid;
5065 };
5066
5067 static void
5068 cmd_gso_enable_parsed(void *parsed_result,
5069                 __attribute__((unused)) struct cmdline *cl,
5070                 __attribute__((unused)) void *data)
5071 {
5072         struct cmd_gso_enable_result *res;
5073
5074         res = parsed_result;
5075         if (!strcmp(res->cmd_keyword, "gso"))
5076                 setup_gso(res->cmd_mode, res->cmd_pid);
5077 }
5078
5079 cmdline_parse_token_string_t cmd_gso_enable_set =
5080         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5081                         cmd_set, "set");
5082 cmdline_parse_token_string_t cmd_gso_enable_port =
5083         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5084                         cmd_port, "port");
5085 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5086         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5087                         cmd_keyword, "gso");
5088 cmdline_parse_token_string_t cmd_gso_enable_mode =
5089         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5090                         cmd_mode, "on#off");
5091 cmdline_parse_token_num_t cmd_gso_enable_pid =
5092         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5093                         cmd_pid, UINT16);
5094
5095 cmdline_parse_inst_t cmd_gso_enable = {
5096         .f = cmd_gso_enable_parsed,
5097         .data = NULL,
5098         .help_str = "set port <port_id> gso on|off",
5099         .tokens = {
5100                 (void *)&cmd_gso_enable_set,
5101                 (void *)&cmd_gso_enable_port,
5102                 (void *)&cmd_gso_enable_pid,
5103                 (void *)&cmd_gso_enable_keyword,
5104                 (void *)&cmd_gso_enable_mode,
5105                 NULL,
5106         },
5107 };
5108
5109 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5110 struct cmd_gso_size_result {
5111         cmdline_fixed_string_t cmd_set;
5112         cmdline_fixed_string_t cmd_keyword;
5113         cmdline_fixed_string_t cmd_segsz;
5114         uint16_t cmd_size;
5115 };
5116
5117 static void
5118 cmd_gso_size_parsed(void *parsed_result,
5119                        __attribute__((unused)) struct cmdline *cl,
5120                        __attribute__((unused)) void *data)
5121 {
5122         struct cmd_gso_size_result *res = parsed_result;
5123
5124         if (test_done == 0) {
5125                 printf("Before setting GSO segsz, please first"
5126                                 " stop fowarding\n");
5127                 return;
5128         }
5129
5130         if (!strcmp(res->cmd_keyword, "gso") &&
5131                         !strcmp(res->cmd_segsz, "segsz")) {
5132                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5133                         printf("gso_size should be larger than %zu."
5134                                         " Please input a legal value\n",
5135                                         RTE_GSO_SEG_SIZE_MIN);
5136                 else
5137                         gso_max_segment_size = res->cmd_size;
5138         }
5139 }
5140
5141 cmdline_parse_token_string_t cmd_gso_size_set =
5142         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5143                                 cmd_set, "set");
5144 cmdline_parse_token_string_t cmd_gso_size_keyword =
5145         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5146                                 cmd_keyword, "gso");
5147 cmdline_parse_token_string_t cmd_gso_size_segsz =
5148         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5149                                 cmd_segsz, "segsz");
5150 cmdline_parse_token_num_t cmd_gso_size_size =
5151         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5152                                 cmd_size, UINT16);
5153
5154 cmdline_parse_inst_t cmd_gso_size = {
5155         .f = cmd_gso_size_parsed,
5156         .data = NULL,
5157         .help_str = "set gso segsz <length>",
5158         .tokens = {
5159                 (void *)&cmd_gso_size_set,
5160                 (void *)&cmd_gso_size_keyword,
5161                 (void *)&cmd_gso_size_segsz,
5162                 (void *)&cmd_gso_size_size,
5163                 NULL,
5164         },
5165 };
5166
5167 /* *** SHOW GSO CONFIGURATION *** */
5168 struct cmd_gso_show_result {
5169         cmdline_fixed_string_t cmd_show;
5170         cmdline_fixed_string_t cmd_port;
5171         cmdline_fixed_string_t cmd_keyword;
5172         portid_t cmd_pid;
5173 };
5174
5175 static void
5176 cmd_gso_show_parsed(void *parsed_result,
5177                        __attribute__((unused)) struct cmdline *cl,
5178                        __attribute__((unused)) void *data)
5179 {
5180         struct cmd_gso_show_result *res = parsed_result;
5181
5182         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5183                 printf("invalid port id %u\n", res->cmd_pid);
5184                 return;
5185         }
5186         if (!strcmp(res->cmd_keyword, "gso")) {
5187                 if (gso_ports[res->cmd_pid].enable) {
5188                         printf("Max GSO'd packet size: %uB\n"
5189                                         "Supported GSO types: TCP/IPv4, "
5190                                         "UDP/IPv4, VxLAN with inner "
5191                                         "TCP/IPv4 packet, GRE with inner "
5192                                         "TCP/IPv4 packet\n",
5193                                         gso_max_segment_size);
5194                 } else
5195                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5196         }
5197 }
5198
5199 cmdline_parse_token_string_t cmd_gso_show_show =
5200 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5201                 cmd_show, "show");
5202 cmdline_parse_token_string_t cmd_gso_show_port =
5203 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5204                 cmd_port, "port");
5205 cmdline_parse_token_string_t cmd_gso_show_keyword =
5206         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5207                                 cmd_keyword, "gso");
5208 cmdline_parse_token_num_t cmd_gso_show_pid =
5209         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5210                                 cmd_pid, UINT16);
5211
5212 cmdline_parse_inst_t cmd_gso_show = {
5213         .f = cmd_gso_show_parsed,
5214         .data = NULL,
5215         .help_str = "show port <port_id> gso",
5216         .tokens = {
5217                 (void *)&cmd_gso_show_show,
5218                 (void *)&cmd_gso_show_port,
5219                 (void *)&cmd_gso_show_pid,
5220                 (void *)&cmd_gso_show_keyword,
5221                 NULL,
5222         },
5223 };
5224
5225 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5226 struct cmd_set_flush_rx {
5227         cmdline_fixed_string_t set;
5228         cmdline_fixed_string_t flush_rx;
5229         cmdline_fixed_string_t mode;
5230 };
5231
5232 static void
5233 cmd_set_flush_rx_parsed(void *parsed_result,
5234                 __attribute__((unused)) struct cmdline *cl,
5235                 __attribute__((unused)) void *data)
5236 {
5237         struct cmd_set_flush_rx *res = parsed_result;
5238         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5239 }
5240
5241 cmdline_parse_token_string_t cmd_setflushrx_set =
5242         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5243                         set, "set");
5244 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5245         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5246                         flush_rx, "flush_rx");
5247 cmdline_parse_token_string_t cmd_setflushrx_mode =
5248         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5249                         mode, "on#off");
5250
5251
5252 cmdline_parse_inst_t cmd_set_flush_rx = {
5253         .f = cmd_set_flush_rx_parsed,
5254         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5255         .data = NULL,
5256         .tokens = {
5257                 (void *)&cmd_setflushrx_set,
5258                 (void *)&cmd_setflushrx_flush_rx,
5259                 (void *)&cmd_setflushrx_mode,
5260                 NULL,
5261         },
5262 };
5263
5264 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5265 struct cmd_set_link_check {
5266         cmdline_fixed_string_t set;
5267         cmdline_fixed_string_t link_check;
5268         cmdline_fixed_string_t mode;
5269 };
5270
5271 static void
5272 cmd_set_link_check_parsed(void *parsed_result,
5273                 __attribute__((unused)) struct cmdline *cl,
5274                 __attribute__((unused)) void *data)
5275 {
5276         struct cmd_set_link_check *res = parsed_result;
5277         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5278 }
5279
5280 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5281         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5282                         set, "set");
5283 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5284         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5285                         link_check, "link_check");
5286 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5287         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5288                         mode, "on#off");
5289
5290
5291 cmdline_parse_inst_t cmd_set_link_check = {
5292         .f = cmd_set_link_check_parsed,
5293         .help_str = "set link_check on|off: Enable/Disable link status check "
5294                     "when starting/stopping a port",
5295         .data = NULL,
5296         .tokens = {
5297                 (void *)&cmd_setlinkcheck_set,
5298                 (void *)&cmd_setlinkcheck_link_check,
5299                 (void *)&cmd_setlinkcheck_mode,
5300                 NULL,
5301         },
5302 };
5303
5304 /* *** SET NIC BYPASS MODE *** */
5305 struct cmd_set_bypass_mode_result {
5306         cmdline_fixed_string_t set;
5307         cmdline_fixed_string_t bypass;
5308         cmdline_fixed_string_t mode;
5309         cmdline_fixed_string_t value;
5310         portid_t port_id;
5311 };
5312
5313 static void
5314 cmd_set_bypass_mode_parsed(void *parsed_result,
5315                 __attribute__((unused)) struct cmdline *cl,
5316                 __attribute__((unused)) void *data)
5317 {
5318         struct cmd_set_bypass_mode_result *res = parsed_result;
5319         portid_t port_id = res->port_id;
5320         int32_t rc = -EINVAL;
5321
5322 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5323         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5324
5325         if (!strcmp(res->value, "bypass"))
5326                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5327         else if (!strcmp(res->value, "isolate"))
5328                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5329         else
5330                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5331
5332         /* Set the bypass mode for the relevant port. */
5333         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5334 #endif
5335         if (rc != 0)
5336                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5337 }
5338
5339 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5340         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5341                         set, "set");
5342 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5343         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5344                         bypass, "bypass");
5345 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5346         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5347                         mode, "mode");
5348 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5349         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5350                         value, "normal#bypass#isolate");
5351 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5352         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5353                                 port_id, UINT16);
5354
5355 cmdline_parse_inst_t cmd_set_bypass_mode = {
5356         .f = cmd_set_bypass_mode_parsed,
5357         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5358                     "Set the NIC bypass mode for port_id",
5359         .data = NULL,
5360         .tokens = {
5361                 (void *)&cmd_setbypass_mode_set,
5362                 (void *)&cmd_setbypass_mode_bypass,
5363                 (void *)&cmd_setbypass_mode_mode,
5364                 (void *)&cmd_setbypass_mode_value,
5365                 (void *)&cmd_setbypass_mode_port,
5366                 NULL,
5367         },
5368 };
5369
5370 /* *** SET NIC BYPASS EVENT *** */
5371 struct cmd_set_bypass_event_result {
5372         cmdline_fixed_string_t set;
5373         cmdline_fixed_string_t bypass;
5374         cmdline_fixed_string_t event;
5375         cmdline_fixed_string_t event_value;
5376         cmdline_fixed_string_t mode;
5377         cmdline_fixed_string_t mode_value;
5378         portid_t port_id;
5379 };
5380
5381 static void
5382 cmd_set_bypass_event_parsed(void *parsed_result,
5383                 __attribute__((unused)) struct cmdline *cl,
5384                 __attribute__((unused)) void *data)
5385 {
5386         int32_t rc = -EINVAL;
5387         struct cmd_set_bypass_event_result *res = parsed_result;
5388         portid_t port_id = res->port_id;
5389
5390 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5391         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5392         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5393
5394         if (!strcmp(res->event_value, "timeout"))
5395                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5396         else if (!strcmp(res->event_value, "os_on"))
5397                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5398         else if (!strcmp(res->event_value, "os_off"))
5399                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5400         else if (!strcmp(res->event_value, "power_on"))
5401                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5402         else if (!strcmp(res->event_value, "power_off"))
5403                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5404         else
5405                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5406
5407         if (!strcmp(res->mode_value, "bypass"))
5408                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5409         else if (!strcmp(res->mode_value, "isolate"))
5410                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5411         else
5412                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5413
5414         /* Set the watchdog timeout. */
5415         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5416
5417                 rc = -EINVAL;
5418                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5419                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5420                                                            bypass_timeout);
5421                 }
5422                 if (rc != 0) {
5423                         printf("Failed to set timeout value %u "
5424                         "for port %d, errto code: %d.\n",
5425                         bypass_timeout, port_id, rc);
5426                 }
5427         }
5428
5429         /* Set the bypass event to transition to bypass mode. */
5430         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5431                                               bypass_mode);
5432 #endif
5433
5434         if (rc != 0)
5435                 printf("\t Failed to set bypass event for port = %d.\n",
5436                        port_id);
5437 }
5438
5439 cmdline_parse_token_string_t cmd_setbypass_event_set =
5440         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5441                         set, "set");
5442 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5443         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5444                         bypass, "bypass");
5445 cmdline_parse_token_string_t cmd_setbypass_event_event =
5446         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5447                         event, "event");
5448 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5449         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5450                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5451 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5452         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5453                         mode, "mode");
5454 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5455         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5456                         mode_value, "normal#bypass#isolate");
5457 cmdline_parse_token_num_t cmd_setbypass_event_port =
5458         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5459                                 port_id, UINT16);
5460
5461 cmdline_parse_inst_t cmd_set_bypass_event = {
5462         .f = cmd_set_bypass_event_parsed,
5463         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5464                 "power_off mode normal|bypass|isolate <port_id>: "
5465                 "Set the NIC bypass event mode for port_id",
5466         .data = NULL,
5467         .tokens = {
5468                 (void *)&cmd_setbypass_event_set,
5469                 (void *)&cmd_setbypass_event_bypass,
5470                 (void *)&cmd_setbypass_event_event,
5471                 (void *)&cmd_setbypass_event_event_value,
5472                 (void *)&cmd_setbypass_event_mode,
5473                 (void *)&cmd_setbypass_event_mode_value,
5474                 (void *)&cmd_setbypass_event_port,
5475                 NULL,
5476         },
5477 };
5478
5479
5480 /* *** SET NIC BYPASS TIMEOUT *** */
5481 struct cmd_set_bypass_timeout_result {
5482         cmdline_fixed_string_t set;
5483         cmdline_fixed_string_t bypass;
5484         cmdline_fixed_string_t timeout;
5485         cmdline_fixed_string_t value;
5486 };
5487
5488 static void
5489 cmd_set_bypass_timeout_parsed(void *parsed_result,
5490                 __attribute__((unused)) struct cmdline *cl,
5491                 __attribute__((unused)) void *data)
5492 {
5493         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5494
5495 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5496         if (!strcmp(res->value, "1.5"))
5497                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5498         else if (!strcmp(res->value, "2"))
5499                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5500         else if (!strcmp(res->value, "3"))
5501                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5502         else if (!strcmp(res->value, "4"))
5503                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5504         else if (!strcmp(res->value, "8"))
5505                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5506         else if (!strcmp(res->value, "16"))
5507                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5508         else if (!strcmp(res->value, "32"))
5509                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5510         else
5511                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5512 #endif
5513 }
5514
5515 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5516         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5517                         set, "set");
5518 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5519         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5520                         bypass, "bypass");
5521 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5522         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5523                         timeout, "timeout");
5524 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5525         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5526                         value, "0#1.5#2#3#4#8#16#32");
5527
5528 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5529         .f = cmd_set_bypass_timeout_parsed,
5530         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5531                 "Set the NIC bypass watchdog timeout in seconds",
5532         .data = NULL,
5533         .tokens = {
5534                 (void *)&cmd_setbypass_timeout_set,
5535                 (void *)&cmd_setbypass_timeout_bypass,
5536                 (void *)&cmd_setbypass_timeout_timeout,
5537                 (void *)&cmd_setbypass_timeout_value,
5538                 NULL,
5539         },
5540 };
5541
5542 /* *** SHOW NIC BYPASS MODE *** */
5543 struct cmd_show_bypass_config_result {
5544         cmdline_fixed_string_t show;
5545         cmdline_fixed_string_t bypass;
5546         cmdline_fixed_string_t config;
5547         portid_t port_id;
5548 };
5549
5550 static void
5551 cmd_show_bypass_config_parsed(void *parsed_result,
5552                 __attribute__((unused)) struct cmdline *cl,
5553                 __attribute__((unused)) void *data)
5554 {
5555         struct cmd_show_bypass_config_result *res = parsed_result;
5556         portid_t port_id = res->port_id;
5557         int rc = -EINVAL;
5558 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5559         uint32_t event_mode;
5560         uint32_t bypass_mode;
5561         uint32_t timeout = bypass_timeout;
5562         int i;
5563
5564         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5565                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5566         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5567                 {"UNKNOWN", "normal", "bypass", "isolate"};
5568         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5569                 "NONE",
5570                 "OS/board on",
5571                 "power supply on",
5572                 "OS/board off",
5573                 "power supply off",
5574                 "timeout"};
5575         int num_events = (sizeof events) / (sizeof events[0]);
5576
5577         /* Display the bypass mode.*/
5578         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5579                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5580                 return;
5581         }
5582         else {
5583                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5584                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5585
5586                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5587         }
5588
5589         /* Display the bypass timeout.*/
5590         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5591                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5592
5593         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5594
5595         /* Display the bypass events and associated modes. */
5596         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5597
5598                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5599                         printf("\tFailed to get bypass mode for event = %s\n",
5600                                 events[i]);
5601                 } else {
5602                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5603                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5604
5605                         printf("\tbypass event: %-16s = %s\n", events[i],
5606                                 modes[event_mode]);
5607                 }
5608         }
5609 #endif
5610         if (rc != 0)
5611                 printf("\tFailed to get bypass configuration for port = %d\n",
5612                        port_id);
5613 }
5614
5615 cmdline_parse_token_string_t cmd_showbypass_config_show =
5616         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5617                         show, "show");
5618 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5619         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5620                         bypass, "bypass");
5621 cmdline_parse_token_string_t cmd_showbypass_config_config =
5622         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5623                         config, "config");
5624 cmdline_parse_token_num_t cmd_showbypass_config_port =
5625         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5626                                 port_id, UINT16);
5627
5628 cmdline_parse_inst_t cmd_show_bypass_config = {
5629         .f = cmd_show_bypass_config_parsed,
5630         .help_str = "show bypass config <port_id>: "
5631                     "Show the NIC bypass config for port_id",
5632         .data = NULL,
5633         .tokens = {
5634                 (void *)&cmd_showbypass_config_show,
5635                 (void *)&cmd_showbypass_config_bypass,
5636                 (void *)&cmd_showbypass_config_config,
5637                 (void *)&cmd_showbypass_config_port,
5638                 NULL,
5639         },
5640 };
5641
5642 #ifdef RTE_LIBRTE_PMD_BOND
5643 /* *** SET BONDING MODE *** */
5644 struct cmd_set_bonding_mode_result {
5645         cmdline_fixed_string_t set;
5646         cmdline_fixed_string_t bonding;
5647         cmdline_fixed_string_t mode;
5648         uint8_t value;
5649         portid_t port_id;
5650 };
5651
5652 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5653                 __attribute__((unused))  struct cmdline *cl,
5654                 __attribute__((unused)) void *data)
5655 {
5656         struct cmd_set_bonding_mode_result *res = parsed_result;
5657         portid_t port_id = res->port_id;
5658
5659         /* Set the bonding mode for the relevant port. */
5660         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5661                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5662 }
5663
5664 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5665 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5666                 set, "set");
5667 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5668 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5669                 bonding, "bonding");
5670 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5671 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5672                 mode, "mode");
5673 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5674 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5675                 value, UINT8);
5676 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5677 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5678                 port_id, UINT16);
5679
5680 cmdline_parse_inst_t cmd_set_bonding_mode = {
5681                 .f = cmd_set_bonding_mode_parsed,
5682                 .help_str = "set bonding mode <mode_value> <port_id>: "
5683                         "Set the bonding mode for port_id",
5684                 .data = NULL,
5685                 .tokens = {
5686                                 (void *) &cmd_setbonding_mode_set,
5687                                 (void *) &cmd_setbonding_mode_bonding,
5688                                 (void *) &cmd_setbonding_mode_mode,
5689                                 (void *) &cmd_setbonding_mode_value,
5690                                 (void *) &cmd_setbonding_mode_port,
5691                                 NULL
5692                 }
5693 };
5694
5695 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5696 struct cmd_set_bonding_lacp_dedicated_queues_result {
5697         cmdline_fixed_string_t set;
5698         cmdline_fixed_string_t bonding;
5699         cmdline_fixed_string_t lacp;
5700         cmdline_fixed_string_t dedicated_queues;
5701         portid_t port_id;
5702         cmdline_fixed_string_t mode;
5703 };
5704
5705 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5706                 __attribute__((unused))  struct cmdline *cl,
5707                 __attribute__((unused)) void *data)
5708 {
5709         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5710         portid_t port_id = res->port_id;
5711         struct rte_port *port;
5712
5713         port = &ports[port_id];
5714
5715         /** Check if the port is not started **/
5716         if (port->port_status != RTE_PORT_STOPPED) {
5717                 printf("Please stop port %d first\n", port_id);
5718                 return;
5719         }
5720
5721         if (!strcmp(res->mode, "enable")) {
5722                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5723                         printf("Dedicate queues for LACP control packets"
5724                                         " enabled\n");
5725                 else
5726                         printf("Enabling dedicate queues for LACP control "
5727                                         "packets on port %d failed\n", port_id);
5728         } else if (!strcmp(res->mode, "disable")) {
5729                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5730                         printf("Dedicated queues for LACP control packets "
5731                                         "disabled\n");
5732                 else
5733                         printf("Disabling dedicated queues for LACP control "
5734                                         "traffic on port %d failed\n", port_id);
5735         }
5736 }
5737
5738 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5739 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5740                 set, "set");
5741 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5742 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5743                 bonding, "bonding");
5744 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5745 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5746                 lacp, "lacp");
5747 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5748 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5749                 dedicated_queues, "dedicated_queues");
5750 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5751 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5752                 port_id, UINT16);
5753 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5754 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5755                 mode, "enable#disable");
5756
5757 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5758                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5759                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5760                         "enable|disable: "
5761                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5762                 .data = NULL,
5763                 .tokens = {
5764                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5765                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5766                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5767                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5768                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5769                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5770                         NULL
5771                 }
5772 };
5773
5774 /* *** SET BALANCE XMIT POLICY *** */
5775 struct cmd_set_bonding_balance_xmit_policy_result {
5776         cmdline_fixed_string_t set;
5777         cmdline_fixed_string_t bonding;
5778         cmdline_fixed_string_t balance_xmit_policy;
5779         portid_t port_id;
5780         cmdline_fixed_string_t policy;
5781 };
5782
5783 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5784                 __attribute__((unused))  struct cmdline *cl,
5785                 __attribute__((unused)) void *data)
5786 {
5787         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5788         portid_t port_id = res->port_id;
5789         uint8_t policy;
5790
5791         if (!strcmp(res->policy, "l2")) {
5792                 policy = BALANCE_XMIT_POLICY_LAYER2;
5793         } else if (!strcmp(res->policy, "l23")) {
5794                 policy = BALANCE_XMIT_POLICY_LAYER23;
5795         } else if (!strcmp(res->policy, "l34")) {
5796                 policy = BALANCE_XMIT_POLICY_LAYER34;
5797         } else {
5798                 printf("\t Invalid xmit policy selection");
5799                 return;
5800         }
5801
5802         /* Set the bonding mode for the relevant port. */
5803         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5804                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5805                                 port_id);
5806         }
5807 }
5808
5809 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5810 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5811                 set, "set");
5812 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5813 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5814                 bonding, "bonding");
5815 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5816 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5817                 balance_xmit_policy, "balance_xmit_policy");
5818 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5819 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5820                 port_id, UINT16);
5821 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5822 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5823                 policy, "l2#l23#l34");
5824
5825 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5826                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5827                 .help_str = "set bonding balance_xmit_policy <port_id> "
5828                         "l2|l23|l34: "
5829                         "Set the bonding balance_xmit_policy for port_id",
5830                 .data = NULL,
5831                 .tokens = {
5832                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5833                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5834                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5835                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5836                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5837                                 NULL
5838                 }
5839 };
5840
5841 /* *** SHOW NIC BONDING CONFIGURATION *** */
5842 struct cmd_show_bonding_config_result {
5843         cmdline_fixed_string_t show;
5844         cmdline_fixed_string_t bonding;
5845         cmdline_fixed_string_t config;
5846         portid_t port_id;
5847 };
5848
5849 static void cmd_show_bonding_config_parsed(void *parsed_result,
5850                 __attribute__((unused))  struct cmdline *cl,
5851                 __attribute__((unused)) void *data)
5852 {
5853         struct cmd_show_bonding_config_result *res = parsed_result;
5854         int bonding_mode, agg_mode;
5855         portid_t slaves[RTE_MAX_ETHPORTS];
5856         int num_slaves, num_active_slaves;
5857         int primary_id;
5858         int i;
5859         portid_t port_id = res->port_id;
5860
5861         /* Display the bonding mode.*/
5862         bonding_mode = rte_eth_bond_mode_get(port_id);
5863         if (bonding_mode < 0) {
5864                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5865                 return;
5866         } else
5867                 printf("\tBonding mode: %d\n", bonding_mode);
5868
5869         if (bonding_mode == BONDING_MODE_BALANCE) {
5870                 int balance_xmit_policy;
5871
5872                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5873                 if (balance_xmit_policy < 0) {
5874                         printf("\tFailed to get balance xmit policy for port = %d\n",
5875                                         port_id);
5876                         return;
5877                 } else {
5878                         printf("\tBalance Xmit Policy: ");
5879
5880                         switch (balance_xmit_policy) {
5881                         case BALANCE_XMIT_POLICY_LAYER2:
5882                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5883                                 break;
5884                         case BALANCE_XMIT_POLICY_LAYER23:
5885                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5886                                 break;
5887                         case BALANCE_XMIT_POLICY_LAYER34:
5888                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5889                                 break;
5890                         }
5891                         printf("\n");
5892                 }
5893         }
5894
5895         if (bonding_mode == BONDING_MODE_8023AD) {
5896                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5897                 printf("\tIEEE802.3AD Aggregator Mode: ");
5898                 switch (agg_mode) {
5899                 case AGG_BANDWIDTH:
5900                         printf("bandwidth");
5901                         break;
5902                 case AGG_STABLE:
5903                         printf("stable");
5904                         break;
5905                 case AGG_COUNT:
5906                         printf("count");
5907                         break;
5908                 }
5909                 printf("\n");
5910         }
5911
5912         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5913
5914         if (num_slaves < 0) {
5915                 printf("\tFailed to get slave list for port = %d\n", port_id);
5916                 return;
5917         }
5918         if (num_slaves > 0) {
5919                 printf("\tSlaves (%d): [", num_slaves);
5920                 for (i = 0; i < num_slaves - 1; i++)
5921                         printf("%d ", slaves[i]);
5922
5923                 printf("%d]\n", slaves[num_slaves - 1]);
5924         } else {
5925                 printf("\tSlaves: []\n");
5926
5927         }
5928
5929         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5930                         RTE_MAX_ETHPORTS);
5931
5932         if (num_active_slaves < 0) {
5933                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5934                 return;
5935         }
5936         if (num_active_slaves > 0) {
5937                 printf("\tActive Slaves (%d): [", num_active_slaves);
5938                 for (i = 0; i < num_active_slaves - 1; i++)
5939                         printf("%d ", slaves[i]);
5940
5941                 printf("%d]\n", slaves[num_active_slaves - 1]);
5942
5943         } else {
5944                 printf("\tActive Slaves: []\n");
5945
5946         }
5947
5948         primary_id = rte_eth_bond_primary_get(port_id);
5949         if (primary_id < 0) {
5950                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5951                 return;
5952         } else
5953                 printf("\tPrimary: [%d]\n", primary_id);
5954
5955 }
5956
5957 cmdline_parse_token_string_t cmd_showbonding_config_show =
5958 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5959                 show, "show");
5960 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5961 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5962                 bonding, "bonding");
5963 cmdline_parse_token_string_t cmd_showbonding_config_config =
5964 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5965                 config, "config");
5966 cmdline_parse_token_num_t cmd_showbonding_config_port =
5967 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5968                 port_id, UINT16);
5969
5970 cmdline_parse_inst_t cmd_show_bonding_config = {
5971                 .f = cmd_show_bonding_config_parsed,
5972                 .help_str = "show bonding config <port_id>: "
5973                         "Show the bonding config for port_id",
5974                 .data = NULL,
5975                 .tokens = {
5976                                 (void *)&cmd_showbonding_config_show,
5977                                 (void *)&cmd_showbonding_config_bonding,
5978                                 (void *)&cmd_showbonding_config_config,
5979                                 (void *)&cmd_showbonding_config_port,
5980                                 NULL
5981                 }
5982 };
5983
5984 /* *** SET BONDING PRIMARY *** */
5985 struct cmd_set_bonding_primary_result {
5986         cmdline_fixed_string_t set;
5987         cmdline_fixed_string_t bonding;
5988         cmdline_fixed_string_t primary;
5989         portid_t slave_id;
5990         portid_t port_id;
5991 };
5992
5993 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5994                 __attribute__((unused))  struct cmdline *cl,
5995                 __attribute__((unused)) void *data)
5996 {
5997         struct cmd_set_bonding_primary_result *res = parsed_result;
5998         portid_t master_port_id = res->port_id;
5999         portid_t slave_port_id = res->slave_id;
6000
6001         /* Set the primary slave for a bonded device. */
6002         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6003                 printf("\t Failed to set primary slave for port = %d.\n",
6004                                 master_port_id);
6005                 return;
6006         }
6007         init_port_config();
6008 }
6009
6010 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6011 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6012                 set, "set");
6013 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6014 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6015                 bonding, "bonding");
6016 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6017 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6018                 primary, "primary");
6019 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6020 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6021                 slave_id, UINT16);
6022 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6023 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6024                 port_id, UINT16);
6025
6026 cmdline_parse_inst_t cmd_set_bonding_primary = {
6027                 .f = cmd_set_bonding_primary_parsed,
6028                 .help_str = "set bonding primary <slave_id> <port_id>: "
6029                         "Set the primary slave for port_id",
6030                 .data = NULL,
6031                 .tokens = {
6032                                 (void *)&cmd_setbonding_primary_set,
6033                                 (void *)&cmd_setbonding_primary_bonding,
6034                                 (void *)&cmd_setbonding_primary_primary,
6035                                 (void *)&cmd_setbonding_primary_slave,
6036                                 (void *)&cmd_setbonding_primary_port,
6037                                 NULL
6038                 }
6039 };
6040
6041 /* *** ADD SLAVE *** */
6042 struct cmd_add_bonding_slave_result {
6043         cmdline_fixed_string_t add;
6044         cmdline_fixed_string_t bonding;
6045         cmdline_fixed_string_t slave;
6046         portid_t slave_id;
6047         portid_t port_id;
6048 };
6049
6050 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6051                 __attribute__((unused))  struct cmdline *cl,
6052                 __attribute__((unused)) void *data)
6053 {
6054         struct cmd_add_bonding_slave_result *res = parsed_result;
6055         portid_t master_port_id = res->port_id;
6056         portid_t slave_port_id = res->slave_id;
6057
6058         /* add the slave for a bonded device. */
6059         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6060                 printf("\t Failed to add slave %d to master port = %d.\n",
6061                                 slave_port_id, master_port_id);
6062                 return;
6063         }
6064         init_port_config();
6065         set_port_slave_flag(slave_port_id);
6066 }
6067
6068 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6069 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6070                 add, "add");
6071 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6072 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6073                 bonding, "bonding");
6074 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6075 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6076                 slave, "slave");
6077 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6078 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6079                 slave_id, UINT16);
6080 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6081 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6082                 port_id, UINT16);
6083
6084 cmdline_parse_inst_t cmd_add_bonding_slave = {
6085                 .f = cmd_add_bonding_slave_parsed,
6086                 .help_str = "add bonding slave <slave_id> <port_id>: "
6087                         "Add a slave device to a bonded device",
6088                 .data = NULL,
6089                 .tokens = {
6090                                 (void *)&cmd_addbonding_slave_add,
6091                                 (void *)&cmd_addbonding_slave_bonding,
6092                                 (void *)&cmd_addbonding_slave_slave,
6093                                 (void *)&cmd_addbonding_slave_slaveid,
6094                                 (void *)&cmd_addbonding_slave_port,
6095                                 NULL
6096                 }
6097 };
6098
6099 /* *** REMOVE SLAVE *** */
6100 struct cmd_remove_bonding_slave_result {
6101         cmdline_fixed_string_t remove;
6102         cmdline_fixed_string_t bonding;
6103         cmdline_fixed_string_t slave;
6104         portid_t slave_id;
6105         portid_t port_id;
6106 };
6107
6108 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6109                 __attribute__((unused))  struct cmdline *cl,
6110                 __attribute__((unused)) void *data)
6111 {
6112         struct cmd_remove_bonding_slave_result *res = parsed_result;
6113         portid_t master_port_id = res->port_id;
6114         portid_t slave_port_id = res->slave_id;
6115
6116         /* remove the slave from a bonded device. */
6117         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6118                 printf("\t Failed to remove slave %d from master port = %d.\n",
6119                                 slave_port_id, master_port_id);
6120                 return;
6121         }
6122         init_port_config();
6123         clear_port_slave_flag(slave_port_id);
6124 }
6125
6126 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6127                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6128                                 remove, "remove");
6129 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6130                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6131                                 bonding, "bonding");
6132 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6133                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6134                                 slave, "slave");
6135 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6136                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6137                                 slave_id, UINT16);
6138 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6139                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6140                                 port_id, UINT16);
6141
6142 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6143                 .f = cmd_remove_bonding_slave_parsed,
6144                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6145                         "Remove a slave device from a bonded device",
6146                 .data = NULL,
6147                 .tokens = {
6148                                 (void *)&cmd_removebonding_slave_remove,
6149                                 (void *)&cmd_removebonding_slave_bonding,
6150                                 (void *)&cmd_removebonding_slave_slave,
6151                                 (void *)&cmd_removebonding_slave_slaveid,
6152                                 (void *)&cmd_removebonding_slave_port,
6153                                 NULL
6154                 }
6155 };
6156
6157 /* *** CREATE BONDED DEVICE *** */
6158 struct cmd_create_bonded_device_result {
6159         cmdline_fixed_string_t create;
6160         cmdline_fixed_string_t bonded;
6161         cmdline_fixed_string_t device;
6162         uint8_t mode;
6163         uint8_t socket;
6164 };
6165
6166 static int bond_dev_num = 0;
6167
6168 static void cmd_create_bonded_device_parsed(void *parsed_result,
6169                 __attribute__((unused))  struct cmdline *cl,
6170                 __attribute__((unused)) void *data)
6171 {
6172         struct cmd_create_bonded_device_result *res = parsed_result;
6173         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6174         int port_id;
6175         int ret;
6176
6177         if (test_done == 0) {
6178                 printf("Please stop forwarding first\n");
6179                 return;
6180         }
6181
6182         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6183                         bond_dev_num++);
6184
6185         /* Create a new bonded device. */
6186         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6187         if (port_id < 0) {
6188                 printf("\t Failed to create bonded device.\n");
6189                 return;
6190         } else {
6191                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6192                                 port_id);
6193
6194                 /* Update number of ports */
6195                 nb_ports = rte_eth_dev_count_avail();
6196                 reconfig(port_id, res->socket);
6197                 ret = rte_eth_promiscuous_enable(port_id);
6198                 if (ret != 0)
6199                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6200                                 port_id, rte_strerror(-ret));
6201
6202                 ports[port_id].need_setup = 0;
6203                 ports[port_id].port_status = RTE_PORT_STOPPED;
6204         }
6205
6206 }
6207
6208 cmdline_parse_token_string_t cmd_createbonded_device_create =
6209                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6210                                 create, "create");
6211 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6212                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6213                                 bonded, "bonded");
6214 cmdline_parse_token_string_t cmd_createbonded_device_device =
6215                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6216                                 device, "device");
6217 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6218                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6219                                 mode, UINT8);
6220 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6221                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6222                                 socket, UINT8);
6223
6224 cmdline_parse_inst_t cmd_create_bonded_device = {
6225                 .f = cmd_create_bonded_device_parsed,
6226                 .help_str = "create bonded device <mode> <socket>: "
6227                         "Create a new bonded device with specific bonding mode and socket",
6228                 .data = NULL,
6229                 .tokens = {
6230                                 (void *)&cmd_createbonded_device_create,
6231                                 (void *)&cmd_createbonded_device_bonded,
6232                                 (void *)&cmd_createbonded_device_device,
6233                                 (void *)&cmd_createbonded_device_mode,
6234                                 (void *)&cmd_createbonded_device_socket,
6235                                 NULL
6236                 }
6237 };
6238
6239 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6240 struct cmd_set_bond_mac_addr_result {
6241         cmdline_fixed_string_t set;
6242         cmdline_fixed_string_t bonding;
6243         cmdline_fixed_string_t mac_addr;
6244         uint16_t port_num;
6245         struct rte_ether_addr address;
6246 };
6247
6248 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6249                 __attribute__((unused))  struct cmdline *cl,
6250                 __attribute__((unused)) void *data)
6251 {
6252         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6253         int ret;
6254
6255         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6256                 return;
6257
6258         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6259
6260         /* check the return value and print it if is < 0 */
6261         if (ret < 0)
6262                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6263 }
6264
6265 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6266                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6267 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6268                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6269                                 "bonding");
6270 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6271                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6272                                 "mac_addr");
6273 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6274                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6275                                 port_num, UINT16);
6276 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6277                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6278
6279 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6280                 .f = cmd_set_bond_mac_addr_parsed,
6281                 .data = (void *) 0,
6282                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6283                 .tokens = {
6284                                 (void *)&cmd_set_bond_mac_addr_set,
6285                                 (void *)&cmd_set_bond_mac_addr_bonding,
6286                                 (void *)&cmd_set_bond_mac_addr_mac,
6287                                 (void *)&cmd_set_bond_mac_addr_portnum,
6288                                 (void *)&cmd_set_bond_mac_addr_addr,
6289                                 NULL
6290                 }
6291 };
6292
6293
6294 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6295 struct cmd_set_bond_mon_period_result {
6296         cmdline_fixed_string_t set;
6297         cmdline_fixed_string_t bonding;
6298         cmdline_fixed_string_t mon_period;
6299         uint16_t port_num;
6300         uint32_t period_ms;
6301 };
6302
6303 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6304                 __attribute__((unused))  struct cmdline *cl,
6305                 __attribute__((unused)) void *data)
6306 {
6307         struct cmd_set_bond_mon_period_result *res = parsed_result;
6308         int ret;
6309
6310         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6311
6312         /* check the return value and print it if is < 0 */
6313         if (ret < 0)
6314                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6315 }
6316
6317 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6318                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6319                                 set, "set");
6320 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6321                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6322                                 bonding, "bonding");
6323 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6324                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6325                                 mon_period,     "mon_period");
6326 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6327                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6328                                 port_num, UINT16);
6329 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6330                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6331                                 period_ms, UINT32);
6332
6333 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6334                 .f = cmd_set_bond_mon_period_parsed,
6335                 .data = (void *) 0,
6336                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6337                 .tokens = {
6338                                 (void *)&cmd_set_bond_mon_period_set,
6339                                 (void *)&cmd_set_bond_mon_period_bonding,
6340                                 (void *)&cmd_set_bond_mon_period_mon_period,
6341                                 (void *)&cmd_set_bond_mon_period_portnum,
6342                                 (void *)&cmd_set_bond_mon_period_period_ms,
6343                                 NULL
6344                 }
6345 };
6346
6347
6348
6349 struct cmd_set_bonding_agg_mode_policy_result {
6350         cmdline_fixed_string_t set;
6351         cmdline_fixed_string_t bonding;
6352         cmdline_fixed_string_t agg_mode;
6353         uint16_t port_num;
6354         cmdline_fixed_string_t policy;
6355 };
6356
6357
6358 static void
6359 cmd_set_bonding_agg_mode(void *parsed_result,
6360                 __attribute__((unused)) struct cmdline *cl,
6361                 __attribute__((unused)) void *data)
6362 {
6363         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6364         uint8_t policy = AGG_BANDWIDTH;
6365
6366         if (!strcmp(res->policy, "bandwidth"))
6367                 policy = AGG_BANDWIDTH;
6368         else if (!strcmp(res->policy, "stable"))
6369                 policy = AGG_STABLE;
6370         else if (!strcmp(res->policy, "count"))
6371                 policy = AGG_COUNT;
6372
6373         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6374 }
6375
6376
6377 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6378         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6379                                 set, "set");
6380 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6381         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6382                                 bonding, "bonding");
6383
6384 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6385         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6386                                 agg_mode, "agg_mode");
6387
6388 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6389         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6390                                 port_num, UINT16);
6391
6392 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6393         TOKEN_STRING_INITIALIZER(
6394                         struct cmd_set_bonding_balance_xmit_policy_result,
6395                 policy, "stable#bandwidth#count");
6396
6397 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6398         .f = cmd_set_bonding_agg_mode,
6399         .data = (void *) 0,
6400         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6401         .tokens = {
6402                         (void *)&cmd_set_bonding_agg_mode_set,
6403                         (void *)&cmd_set_bonding_agg_mode_bonding,
6404                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6405                         (void *)&cmd_set_bonding_agg_mode_portnum,
6406                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6407                         NULL
6408                 }
6409 };
6410
6411
6412 #endif /* RTE_LIBRTE_PMD_BOND */
6413
6414 /* *** SET FORWARDING MODE *** */
6415 struct cmd_set_fwd_mode_result {
6416         cmdline_fixed_string_t set;
6417         cmdline_fixed_string_t fwd;
6418         cmdline_fixed_string_t mode;
6419 };
6420
6421 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6422                                     __attribute__((unused)) struct cmdline *cl,
6423                                     __attribute__((unused)) void *data)
6424 {
6425         struct cmd_set_fwd_mode_result *res = parsed_result;
6426
6427         retry_enabled = 0;
6428         set_pkt_forwarding_mode(res->mode);
6429 }
6430
6431 cmdline_parse_token_string_t cmd_setfwd_set =
6432         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6433 cmdline_parse_token_string_t cmd_setfwd_fwd =
6434         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6435 cmdline_parse_token_string_t cmd_setfwd_mode =
6436         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6437                 "" /* defined at init */);
6438
6439 cmdline_parse_inst_t cmd_set_fwd_mode = {
6440         .f = cmd_set_fwd_mode_parsed,
6441         .data = NULL,
6442         .help_str = NULL, /* defined at init */
6443         .tokens = {
6444                 (void *)&cmd_setfwd_set,
6445                 (void *)&cmd_setfwd_fwd,
6446                 (void *)&cmd_setfwd_mode,
6447                 NULL,
6448         },
6449 };
6450
6451 static void cmd_set_fwd_mode_init(void)
6452 {
6453         char *modes, *c;
6454         static char token[128];
6455         static char help[256];
6456         cmdline_parse_token_string_t *token_struct;
6457
6458         modes = list_pkt_forwarding_modes();
6459         snprintf(help, sizeof(help), "set fwd %s: "
6460                 "Set packet forwarding mode", modes);
6461         cmd_set_fwd_mode.help_str = help;
6462
6463         /* string token separator is # */
6464         for (c = token; *modes != '\0'; modes++)
6465                 if (*modes == '|')
6466                         *c++ = '#';
6467                 else
6468                         *c++ = *modes;
6469         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6470         token_struct->string_data.str = token;
6471 }
6472
6473 /* *** SET RETRY FORWARDING MODE *** */
6474 struct cmd_set_fwd_retry_mode_result {
6475         cmdline_fixed_string_t set;
6476         cmdline_fixed_string_t fwd;
6477         cmdline_fixed_string_t mode;
6478         cmdline_fixed_string_t retry;
6479 };
6480
6481 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6482                             __attribute__((unused)) struct cmdline *cl,
6483                             __attribute__((unused)) void *data)
6484 {
6485         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6486
6487         retry_enabled = 1;
6488         set_pkt_forwarding_mode(res->mode);
6489 }
6490
6491 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6492         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6493                         set, "set");
6494 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6495         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6496                         fwd, "fwd");
6497 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6498         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6499                         mode,
6500                 "" /* defined at init */);
6501 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6502         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6503                         retry, "retry");
6504
6505 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6506         .f = cmd_set_fwd_retry_mode_parsed,
6507         .data = NULL,
6508         .help_str = NULL, /* defined at init */
6509         .tokens = {
6510                 (void *)&cmd_setfwd_retry_set,
6511                 (void *)&cmd_setfwd_retry_fwd,
6512                 (void *)&cmd_setfwd_retry_mode,
6513                 (void *)&cmd_setfwd_retry_retry,
6514                 NULL,
6515         },
6516 };
6517
6518 static void cmd_set_fwd_retry_mode_init(void)
6519 {
6520         char *modes, *c;
6521         static char token[128];
6522         static char help[256];
6523         cmdline_parse_token_string_t *token_struct;
6524
6525         modes = list_pkt_forwarding_retry_modes();
6526         snprintf(help, sizeof(help), "set fwd %s retry: "
6527                 "Set packet forwarding mode with retry", modes);
6528         cmd_set_fwd_retry_mode.help_str = help;
6529
6530         /* string token separator is # */
6531         for (c = token; *modes != '\0'; modes++)
6532                 if (*modes == '|')
6533                         *c++ = '#';
6534                 else
6535                         *c++ = *modes;
6536         token_struct = (cmdline_parse_token_string_t *)
6537                 cmd_set_fwd_retry_mode.tokens[2];
6538         token_struct->string_data.str = token;
6539 }
6540
6541 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6542 struct cmd_set_burst_tx_retry_result {
6543         cmdline_fixed_string_t set;
6544         cmdline_fixed_string_t burst;
6545         cmdline_fixed_string_t tx;
6546         cmdline_fixed_string_t delay;
6547         uint32_t time;
6548         cmdline_fixed_string_t retry;
6549         uint32_t retry_num;
6550 };
6551
6552 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6553                                         __attribute__((unused)) struct cmdline *cl,
6554                                         __attribute__((unused)) void *data)
6555 {
6556         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6557
6558         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6559                 && !strcmp(res->tx, "tx")) {
6560                 if (!strcmp(res->delay, "delay"))
6561                         burst_tx_delay_time = res->time;
6562                 if (!strcmp(res->retry, "retry"))
6563                         burst_tx_retry_num = res->retry_num;
6564         }
6565
6566 }
6567
6568 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6569         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6570 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6571         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6572                                  "burst");
6573 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6574         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6575 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6576         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6577 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6578         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6579 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6580         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6581 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6582         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6583
6584 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6585         .f = cmd_set_burst_tx_retry_parsed,
6586         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6587         .tokens = {
6588                 (void *)&cmd_set_burst_tx_retry_set,
6589                 (void *)&cmd_set_burst_tx_retry_burst,
6590                 (void *)&cmd_set_burst_tx_retry_tx,
6591                 (void *)&cmd_set_burst_tx_retry_delay,
6592                 (void *)&cmd_set_burst_tx_retry_time,
6593                 (void *)&cmd_set_burst_tx_retry_retry,
6594                 (void *)&cmd_set_burst_tx_retry_retry_num,
6595                 NULL,
6596         },
6597 };
6598
6599 /* *** SET PROMISC MODE *** */
6600 struct cmd_set_promisc_mode_result {
6601         cmdline_fixed_string_t set;
6602         cmdline_fixed_string_t promisc;
6603         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6604         uint16_t port_num;               /* valid if "allports" argument == 0 */
6605         cmdline_fixed_string_t mode;
6606 };
6607
6608 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6609                                         __attribute__((unused)) struct cmdline *cl,
6610                                         void *allports)
6611 {
6612         struct cmd_set_promisc_mode_result *res = parsed_result;
6613         int enable;
6614         portid_t i;
6615
6616         if (!strcmp(res->mode, "on"))
6617                 enable = 1;
6618         else
6619                 enable = 0;
6620
6621         /* all ports */
6622         if (allports) {
6623                 RTE_ETH_FOREACH_DEV(i)
6624                         eth_set_promisc_mode(i, enable);
6625         } else {
6626                 eth_set_promisc_mode(res->port_num, enable);
6627         }
6628 }
6629
6630 cmdline_parse_token_string_t cmd_setpromisc_set =
6631         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6632 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6633         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6634                                  "promisc");
6635 cmdline_parse_token_string_t cmd_setpromisc_portall =
6636         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6637                                  "all");
6638 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6639         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6640                               UINT16);
6641 cmdline_parse_token_string_t cmd_setpromisc_mode =
6642         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6643                                  "on#off");
6644
6645 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6646         .f = cmd_set_promisc_mode_parsed,
6647         .data = (void *)1,
6648         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6649         .tokens = {
6650                 (void *)&cmd_setpromisc_set,
6651                 (void *)&cmd_setpromisc_promisc,
6652                 (void *)&cmd_setpromisc_portall,
6653                 (void *)&cmd_setpromisc_mode,
6654                 NULL,
6655         },
6656 };
6657
6658 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6659         .f = cmd_set_promisc_mode_parsed,
6660         .data = (void *)0,
6661         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6662         .tokens = {
6663                 (void *)&cmd_setpromisc_set,
6664                 (void *)&cmd_setpromisc_promisc,
6665                 (void *)&cmd_setpromisc_portnum,
6666                 (void *)&cmd_setpromisc_mode,
6667                 NULL,
6668         },
6669 };
6670
6671 /* *** SET ALLMULTI MODE *** */
6672 struct cmd_set_allmulti_mode_result {
6673         cmdline_fixed_string_t set;
6674         cmdline_fixed_string_t allmulti;
6675         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6676         uint16_t port_num;               /* valid if "allports" argument == 0 */
6677         cmdline_fixed_string_t mode;
6678 };
6679
6680 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6681                                         __attribute__((unused)) struct cmdline *cl,
6682                                         void *allports)
6683 {
6684         struct cmd_set_allmulti_mode_result *res = parsed_result;
6685         int enable;
6686         portid_t i;
6687
6688         if (!strcmp(res->mode, "on"))
6689                 enable = 1;
6690         else
6691                 enable = 0;
6692
6693         /* all ports */
6694         if (allports) {
6695                 RTE_ETH_FOREACH_DEV(i) {
6696                         eth_set_allmulticast_mode(i, enable);
6697                 }
6698         }
6699         else {
6700                 eth_set_allmulticast_mode(res->port_num, enable);
6701         }
6702 }
6703
6704 cmdline_parse_token_string_t cmd_setallmulti_set =
6705         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6706 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6707         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6708                                  "allmulti");
6709 cmdline_parse_token_string_t cmd_setallmulti_portall =
6710         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6711                                  "all");
6712 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6713         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6714                               UINT16);
6715 cmdline_parse_token_string_t cmd_setallmulti_mode =
6716         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6717                                  "on#off");
6718
6719 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6720         .f = cmd_set_allmulti_mode_parsed,
6721         .data = (void *)1,
6722         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6723         .tokens = {
6724                 (void *)&cmd_setallmulti_set,
6725                 (void *)&cmd_setallmulti_allmulti,
6726                 (void *)&cmd_setallmulti_portall,
6727                 (void *)&cmd_setallmulti_mode,
6728                 NULL,
6729         },
6730 };
6731
6732 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6733         .f = cmd_set_allmulti_mode_parsed,
6734         .data = (void *)0,
6735         .help_str = "set allmulti <port_id> on|off: "
6736                 "Set allmulti mode on port_id",
6737         .tokens = {
6738                 (void *)&cmd_setallmulti_set,
6739                 (void *)&cmd_setallmulti_allmulti,
6740                 (void *)&cmd_setallmulti_portnum,
6741                 (void *)&cmd_setallmulti_mode,
6742                 NULL,
6743         },
6744 };
6745
6746 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6747 struct cmd_link_flow_ctrl_set_result {
6748         cmdline_fixed_string_t set;
6749         cmdline_fixed_string_t flow_ctrl;
6750         cmdline_fixed_string_t rx;
6751         cmdline_fixed_string_t rx_lfc_mode;
6752         cmdline_fixed_string_t tx;
6753         cmdline_fixed_string_t tx_lfc_mode;
6754         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6755         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6756         cmdline_fixed_string_t autoneg_str;
6757         cmdline_fixed_string_t autoneg;
6758         cmdline_fixed_string_t hw_str;
6759         uint32_t high_water;
6760         cmdline_fixed_string_t lw_str;
6761         uint32_t low_water;
6762         cmdline_fixed_string_t pt_str;
6763         uint16_t pause_time;
6764         cmdline_fixed_string_t xon_str;
6765         uint16_t send_xon;
6766         portid_t port_id;
6767 };
6768
6769 cmdline_parse_token_string_t cmd_lfc_set_set =
6770         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6771                                 set, "set");
6772 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6773         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6774                                 flow_ctrl, "flow_ctrl");
6775 cmdline_parse_token_string_t cmd_lfc_set_rx =
6776         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6777                                 rx, "rx");
6778 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6779         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6780                                 rx_lfc_mode, "on#off");
6781 cmdline_parse_token_string_t cmd_lfc_set_tx =
6782         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6783                                 tx, "tx");
6784 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6785         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6786                                 tx_lfc_mode, "on#off");
6787 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6788         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6789                                 hw_str, "high_water");
6790 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6791         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6792                                 high_water, UINT32);
6793 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6794         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6795                                 lw_str, "low_water");
6796 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6797         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6798                                 low_water, UINT32);
6799 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6800         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6801                                 pt_str, "pause_time");
6802 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6803         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6804                                 pause_time, UINT16);
6805 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6806         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6807                                 xon_str, "send_xon");
6808 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6809         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6810                                 send_xon, UINT16);
6811 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6812         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6813                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6814 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6815         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6816                                 mac_ctrl_frame_fwd_mode, "on#off");
6817 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6818         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6819                                 autoneg_str, "autoneg");
6820 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6821         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6822                                 autoneg, "on#off");
6823 cmdline_parse_token_num_t cmd_lfc_set_portid =
6824         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6825                                 port_id, UINT16);
6826
6827 /* forward declaration */
6828 static void
6829 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6830                               void *data);
6831
6832 cmdline_parse_inst_t cmd_link_flow_control_set = {
6833         .f = cmd_link_flow_ctrl_set_parsed,
6834         .data = NULL,
6835         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6836                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6837                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6838         .tokens = {
6839                 (void *)&cmd_lfc_set_set,
6840                 (void *)&cmd_lfc_set_flow_ctrl,
6841                 (void *)&cmd_lfc_set_rx,
6842                 (void *)&cmd_lfc_set_rx_mode,
6843                 (void *)&cmd_lfc_set_tx,
6844                 (void *)&cmd_lfc_set_tx_mode,
6845                 (void *)&cmd_lfc_set_high_water,
6846                 (void *)&cmd_lfc_set_low_water,
6847                 (void *)&cmd_lfc_set_pause_time,
6848                 (void *)&cmd_lfc_set_send_xon,
6849                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6850                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6851                 (void *)&cmd_lfc_set_autoneg_str,
6852                 (void *)&cmd_lfc_set_autoneg,
6853                 (void *)&cmd_lfc_set_portid,
6854                 NULL,
6855         },
6856 };
6857
6858 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6859         .f = cmd_link_flow_ctrl_set_parsed,
6860         .data = (void *)&cmd_link_flow_control_set_rx,
6861         .help_str = "set flow_ctrl rx on|off <port_id>: "
6862                 "Change rx flow control parameter",
6863         .tokens = {
6864                 (void *)&cmd_lfc_set_set,
6865                 (void *)&cmd_lfc_set_flow_ctrl,
6866                 (void *)&cmd_lfc_set_rx,
6867                 (void *)&cmd_lfc_set_rx_mode,
6868                 (void *)&cmd_lfc_set_portid,
6869                 NULL,
6870         },
6871 };
6872
6873 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6874         .f = cmd_link_flow_ctrl_set_parsed,
6875         .data = (void *)&cmd_link_flow_control_set_tx,
6876         .help_str = "set flow_ctrl tx on|off <port_id>: "
6877                 "Change tx flow control parameter",
6878         .tokens = {
6879                 (void *)&cmd_lfc_set_set,
6880                 (void *)&cmd_lfc_set_flow_ctrl,
6881                 (void *)&cmd_lfc_set_tx,
6882                 (void *)&cmd_lfc_set_tx_mode,
6883                 (void *)&cmd_lfc_set_portid,
6884                 NULL,
6885         },
6886 };
6887
6888 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6889         .f = cmd_link_flow_ctrl_set_parsed,
6890         .data = (void *)&cmd_link_flow_control_set_hw,
6891         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6892                 "Change high water flow control parameter",
6893         .tokens = {
6894                 (void *)&cmd_lfc_set_set,
6895                 (void *)&cmd_lfc_set_flow_ctrl,
6896                 (void *)&cmd_lfc_set_high_water_str,
6897                 (void *)&cmd_lfc_set_high_water,
6898                 (void *)&cmd_lfc_set_portid,
6899                 NULL,
6900         },
6901 };
6902
6903 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6904         .f = cmd_link_flow_ctrl_set_parsed,
6905         .data = (void *)&cmd_link_flow_control_set_lw,
6906         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6907                 "Change low water flow control parameter",
6908         .tokens = {
6909                 (void *)&cmd_lfc_set_set,
6910                 (void *)&cmd_lfc_set_flow_ctrl,
6911                 (void *)&cmd_lfc_set_low_water_str,
6912                 (void *)&cmd_lfc_set_low_water,
6913                 (void *)&cmd_lfc_set_portid,
6914                 NULL,
6915         },
6916 };
6917
6918 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6919         .f = cmd_link_flow_ctrl_set_parsed,
6920         .data = (void *)&cmd_link_flow_control_set_pt,
6921         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6922                 "Change pause time flow control parameter",
6923         .tokens = {
6924                 (void *)&cmd_lfc_set_set,
6925                 (void *)&cmd_lfc_set_flow_ctrl,
6926                 (void *)&cmd_lfc_set_pause_time_str,
6927                 (void *)&cmd_lfc_set_pause_time,
6928                 (void *)&cmd_lfc_set_portid,
6929                 NULL,
6930         },
6931 };
6932
6933 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6934         .f = cmd_link_flow_ctrl_set_parsed,
6935         .data = (void *)&cmd_link_flow_control_set_xon,
6936         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6937                 "Change send_xon flow control parameter",
6938         .tokens = {
6939                 (void *)&cmd_lfc_set_set,
6940                 (void *)&cmd_lfc_set_flow_ctrl,
6941                 (void *)&cmd_lfc_set_send_xon_str,
6942                 (void *)&cmd_lfc_set_send_xon,
6943                 (void *)&cmd_lfc_set_portid,
6944                 NULL,
6945         },
6946 };
6947
6948 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6949         .f = cmd_link_flow_ctrl_set_parsed,
6950         .data = (void *)&cmd_link_flow_control_set_macfwd,
6951         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6952                 "Change mac ctrl fwd flow control parameter",
6953         .tokens = {
6954                 (void *)&cmd_lfc_set_set,
6955                 (void *)&cmd_lfc_set_flow_ctrl,
6956                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6957                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6958                 (void *)&cmd_lfc_set_portid,
6959                 NULL,
6960         },
6961 };
6962
6963 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6964         .f = cmd_link_flow_ctrl_set_parsed,
6965         .data = (void *)&cmd_link_flow_control_set_autoneg,
6966         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6967                 "Change autoneg flow control parameter",
6968         .tokens = {
6969                 (void *)&cmd_lfc_set_set,
6970                 (void *)&cmd_lfc_set_flow_ctrl,
6971                 (void *)&cmd_lfc_set_autoneg_str,
6972                 (void *)&cmd_lfc_set_autoneg,
6973                 (void *)&cmd_lfc_set_portid,
6974                 NULL,
6975         },
6976 };
6977
6978 static void
6979 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6980                               __attribute__((unused)) struct cmdline *cl,
6981                               void *data)
6982 {
6983         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6984         cmdline_parse_inst_t *cmd = data;
6985         struct rte_eth_fc_conf fc_conf;
6986         int rx_fc_en = 0;
6987         int tx_fc_en = 0;
6988         int ret;
6989
6990         /*
6991          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6992          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6993          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6994          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6995          */
6996         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6997                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6998         };
6999
7000         /* Partial command line, retrieve current configuration */
7001         if (cmd) {
7002                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7003                 if (ret != 0) {
7004                         printf("cannot get current flow ctrl parameters, return"
7005                                "code = %d\n", ret);
7006                         return;
7007                 }
7008
7009                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7010                     (fc_conf.mode == RTE_FC_FULL))
7011                         rx_fc_en = 1;
7012                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7013                     (fc_conf.mode == RTE_FC_FULL))
7014                         tx_fc_en = 1;
7015         }
7016
7017         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7018                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7019
7020         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7021                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7022
7023         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7024
7025         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7026                 fc_conf.high_water = res->high_water;
7027
7028         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7029                 fc_conf.low_water = res->low_water;
7030
7031         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7032                 fc_conf.pause_time = res->pause_time;
7033
7034         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7035                 fc_conf.send_xon = res->send_xon;
7036
7037         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7038                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7039                         fc_conf.mac_ctrl_frame_fwd = 1;
7040                 else
7041                         fc_conf.mac_ctrl_frame_fwd = 0;
7042         }
7043
7044         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7045                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7046
7047         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7048         if (ret != 0)
7049                 printf("bad flow contrl parameter, return code = %d \n", ret);
7050 }
7051
7052 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7053 struct cmd_priority_flow_ctrl_set_result {
7054         cmdline_fixed_string_t set;
7055         cmdline_fixed_string_t pfc_ctrl;
7056         cmdline_fixed_string_t rx;
7057         cmdline_fixed_string_t rx_pfc_mode;
7058         cmdline_fixed_string_t tx;
7059         cmdline_fixed_string_t tx_pfc_mode;
7060         uint32_t high_water;
7061         uint32_t low_water;
7062         uint16_t pause_time;
7063         uint8_t  priority;
7064         portid_t port_id;
7065 };
7066
7067 static void
7068 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7069                        __attribute__((unused)) struct cmdline *cl,
7070                        __attribute__((unused)) void *data)
7071 {
7072         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7073         struct rte_eth_pfc_conf pfc_conf;
7074         int rx_fc_enable, tx_fc_enable;
7075         int ret;
7076
7077         /*
7078          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7079          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7080          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7081          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7082          */
7083         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7084                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
7085         };
7086
7087         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7088         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7089         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7090         pfc_conf.fc.high_water = res->high_water;
7091         pfc_conf.fc.low_water  = res->low_water;
7092         pfc_conf.fc.pause_time = res->pause_time;
7093         pfc_conf.priority      = res->priority;
7094
7095         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7096         if (ret != 0)
7097                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7098 }
7099
7100 cmdline_parse_token_string_t cmd_pfc_set_set =
7101         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7102                                 set, "set");
7103 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7104         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7105                                 pfc_ctrl, "pfc_ctrl");
7106 cmdline_parse_token_string_t cmd_pfc_set_rx =
7107         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7108                                 rx, "rx");
7109 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7110         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7111                                 rx_pfc_mode, "on#off");
7112 cmdline_parse_token_string_t cmd_pfc_set_tx =
7113         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7114                                 tx, "tx");
7115 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7116         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7117                                 tx_pfc_mode, "on#off");
7118 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7119         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7120                                 high_water, UINT32);
7121 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7122         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7123                                 low_water, UINT32);
7124 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7125         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7126                                 pause_time, UINT16);
7127 cmdline_parse_token_num_t cmd_pfc_set_priority =
7128         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7129                                 priority, UINT8);
7130 cmdline_parse_token_num_t cmd_pfc_set_portid =
7131         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7132                                 port_id, UINT16);
7133
7134 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7135         .f = cmd_priority_flow_ctrl_set_parsed,
7136         .data = NULL,
7137         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7138                 "<pause_time> <priority> <port_id>: "
7139                 "Configure the Ethernet priority flow control",
7140         .tokens = {
7141                 (void *)&cmd_pfc_set_set,
7142                 (void *)&cmd_pfc_set_flow_ctrl,
7143                 (void *)&cmd_pfc_set_rx,
7144                 (void *)&cmd_pfc_set_rx_mode,
7145                 (void *)&cmd_pfc_set_tx,
7146                 (void *)&cmd_pfc_set_tx_mode,
7147                 (void *)&cmd_pfc_set_high_water,
7148                 (void *)&cmd_pfc_set_low_water,
7149                 (void *)&cmd_pfc_set_pause_time,
7150                 (void *)&cmd_pfc_set_priority,
7151                 (void *)&cmd_pfc_set_portid,
7152                 NULL,
7153         },
7154 };
7155
7156 /* *** RESET CONFIGURATION *** */
7157 struct cmd_reset_result {
7158         cmdline_fixed_string_t reset;
7159         cmdline_fixed_string_t def;
7160 };
7161
7162 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7163                              struct cmdline *cl,
7164                              __attribute__((unused)) void *data)
7165 {
7166         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7167         set_def_fwd_config();
7168 }
7169
7170 cmdline_parse_token_string_t cmd_reset_set =
7171         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7172 cmdline_parse_token_string_t cmd_reset_def =
7173         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7174                                  "default");
7175
7176 cmdline_parse_inst_t cmd_reset = {
7177         .f = cmd_reset_parsed,
7178         .data = NULL,
7179         .help_str = "set default: Reset default forwarding configuration",
7180         .tokens = {
7181                 (void *)&cmd_reset_set,
7182                 (void *)&cmd_reset_def,
7183                 NULL,
7184         },
7185 };
7186
7187 /* *** START FORWARDING *** */
7188 struct cmd_start_result {
7189         cmdline_fixed_string_t start;
7190 };
7191
7192 cmdline_parse_token_string_t cmd_start_start =
7193         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7194
7195 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7196                              __attribute__((unused)) struct cmdline *cl,
7197                              __attribute__((unused)) void *data)
7198 {
7199         start_packet_forwarding(0);
7200 }
7201
7202 cmdline_parse_inst_t cmd_start = {
7203         .f = cmd_start_parsed,
7204         .data = NULL,
7205         .help_str = "start: Start packet forwarding",
7206         .tokens = {
7207                 (void *)&cmd_start_start,
7208                 NULL,
7209         },
7210 };
7211
7212 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7213 struct cmd_start_tx_first_result {
7214         cmdline_fixed_string_t start;
7215         cmdline_fixed_string_t tx_first;
7216 };
7217
7218 static void
7219 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7220                           __attribute__((unused)) struct cmdline *cl,
7221                           __attribute__((unused)) void *data)
7222 {
7223         start_packet_forwarding(1);
7224 }
7225
7226 cmdline_parse_token_string_t cmd_start_tx_first_start =
7227         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7228                                  "start");
7229 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7230         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7231                                  tx_first, "tx_first");
7232
7233 cmdline_parse_inst_t cmd_start_tx_first = {
7234         .f = cmd_start_tx_first_parsed,
7235         .data = NULL,
7236         .help_str = "start tx_first: Start packet forwarding, "
7237                 "after sending 1 burst of packets",
7238         .tokens = {
7239                 (void *)&cmd_start_tx_first_start,
7240                 (void *)&cmd_start_tx_first_tx_first,
7241                 NULL,
7242         },
7243 };
7244
7245 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7246 struct cmd_start_tx_first_n_result {
7247         cmdline_fixed_string_t start;
7248         cmdline_fixed_string_t tx_first;
7249         uint32_t tx_num;
7250 };
7251
7252 static void
7253 cmd_start_tx_first_n_parsed(void *parsed_result,
7254                           __attribute__((unused)) struct cmdline *cl,
7255                           __attribute__((unused)) void *data)
7256 {
7257         struct cmd_start_tx_first_n_result *res = parsed_result;
7258
7259         start_packet_forwarding(res->tx_num);
7260 }
7261
7262 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7263         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7264                         start, "start");
7265 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7266         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7267                         tx_first, "tx_first");
7268 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7269         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7270                         tx_num, UINT32);
7271
7272 cmdline_parse_inst_t cmd_start_tx_first_n = {
7273         .f = cmd_start_tx_first_n_parsed,
7274         .data = NULL,
7275         .help_str = "start tx_first <num>: "
7276                 "packet forwarding, after sending <num> bursts of packets",
7277         .tokens = {
7278                 (void *)&cmd_start_tx_first_n_start,
7279                 (void *)&cmd_start_tx_first_n_tx_first,
7280                 (void *)&cmd_start_tx_first_n_tx_num,
7281                 NULL,
7282         },
7283 };
7284
7285 /* *** SET LINK UP *** */
7286 struct cmd_set_link_up_result {
7287         cmdline_fixed_string_t set;
7288         cmdline_fixed_string_t link_up;
7289         cmdline_fixed_string_t port;
7290         portid_t port_id;
7291 };
7292
7293 cmdline_parse_token_string_t cmd_set_link_up_set =
7294         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7295 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7296         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7297                                 "link-up");
7298 cmdline_parse_token_string_t cmd_set_link_up_port =
7299         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7300 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7301         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7302
7303 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7304                              __attribute__((unused)) struct cmdline *cl,
7305                              __attribute__((unused)) void *data)
7306 {
7307         struct cmd_set_link_up_result *res = parsed_result;
7308         dev_set_link_up(res->port_id);
7309 }
7310
7311 cmdline_parse_inst_t cmd_set_link_up = {
7312         .f = cmd_set_link_up_parsed,
7313         .data = NULL,
7314         .help_str = "set link-up port <port id>",
7315         .tokens = {
7316                 (void *)&cmd_set_link_up_set,
7317                 (void *)&cmd_set_link_up_link_up,
7318                 (void *)&cmd_set_link_up_port,
7319                 (void *)&cmd_set_link_up_port_id,
7320                 NULL,
7321         },
7322 };
7323
7324 /* *** SET LINK DOWN *** */
7325 struct cmd_set_link_down_result {
7326         cmdline_fixed_string_t set;
7327         cmdline_fixed_string_t link_down;
7328         cmdline_fixed_string_t port;
7329         portid_t port_id;
7330 };
7331
7332 cmdline_parse_token_string_t cmd_set_link_down_set =
7333         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7334 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7335         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7336                                 "link-down");
7337 cmdline_parse_token_string_t cmd_set_link_down_port =
7338         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7339 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7340         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7341
7342 static void cmd_set_link_down_parsed(
7343                                 __attribute__((unused)) void *parsed_result,
7344                                 __attribute__((unused)) struct cmdline *cl,
7345                                 __attribute__((unused)) void *data)
7346 {
7347         struct cmd_set_link_down_result *res = parsed_result;
7348         dev_set_link_down(res->port_id);
7349 }
7350
7351 cmdline_parse_inst_t cmd_set_link_down = {
7352         .f = cmd_set_link_down_parsed,
7353         .data = NULL,
7354         .help_str = "set link-down port <port id>",
7355         .tokens = {
7356                 (void *)&cmd_set_link_down_set,
7357                 (void *)&cmd_set_link_down_link_down,
7358                 (void *)&cmd_set_link_down_port,
7359                 (void *)&cmd_set_link_down_port_id,
7360                 NULL,
7361         },
7362 };
7363
7364 /* *** SHOW CFG *** */
7365 struct cmd_showcfg_result {
7366         cmdline_fixed_string_t show;
7367         cmdline_fixed_string_t cfg;
7368         cmdline_fixed_string_t what;
7369 };
7370
7371 static void cmd_showcfg_parsed(void *parsed_result,
7372                                __attribute__((unused)) struct cmdline *cl,
7373                                __attribute__((unused)) void *data)
7374 {
7375         struct cmd_showcfg_result *res = parsed_result;
7376         if (!strcmp(res->what, "rxtx"))
7377                 rxtx_config_display();
7378         else if (!strcmp(res->what, "cores"))
7379                 fwd_lcores_config_display();
7380         else if (!strcmp(res->what, "fwd"))
7381                 pkt_fwd_config_display(&cur_fwd_config);
7382         else if (!strcmp(res->what, "txpkts"))
7383                 show_tx_pkt_segments();
7384 }
7385
7386 cmdline_parse_token_string_t cmd_showcfg_show =
7387         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7388 cmdline_parse_token_string_t cmd_showcfg_port =
7389         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7390 cmdline_parse_token_string_t cmd_showcfg_what =
7391         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7392                                  "rxtx#cores#fwd#txpkts");
7393
7394 cmdline_parse_inst_t cmd_showcfg = {
7395         .f = cmd_showcfg_parsed,
7396         .data = NULL,
7397         .help_str = "show config rxtx|cores|fwd|txpkts",
7398         .tokens = {
7399                 (void *)&cmd_showcfg_show,
7400                 (void *)&cmd_showcfg_port,
7401                 (void *)&cmd_showcfg_what,
7402                 NULL,
7403         },
7404 };
7405
7406 /* *** SHOW ALL PORT INFO *** */
7407 struct cmd_showportall_result {
7408         cmdline_fixed_string_t show;
7409         cmdline_fixed_string_t port;
7410         cmdline_fixed_string_t what;
7411         cmdline_fixed_string_t all;
7412 };
7413
7414 static void cmd_showportall_parsed(void *parsed_result,
7415                                 __attribute__((unused)) struct cmdline *cl,
7416                                 __attribute__((unused)) void *data)
7417 {
7418         portid_t i;
7419
7420         struct cmd_showportall_result *res = parsed_result;
7421         if (!strcmp(res->show, "clear")) {
7422                 if (!strcmp(res->what, "stats"))
7423                         RTE_ETH_FOREACH_DEV(i)
7424                                 nic_stats_clear(i);
7425                 else if (!strcmp(res->what, "xstats"))
7426                         RTE_ETH_FOREACH_DEV(i)
7427                                 nic_xstats_clear(i);
7428         } else if (!strcmp(res->what, "info"))
7429                 RTE_ETH_FOREACH_DEV(i)
7430                         port_infos_display(i);
7431         else if (!strcmp(res->what, "summary")) {
7432                 port_summary_header_display();
7433                 RTE_ETH_FOREACH_DEV(i)
7434                         port_summary_display(i);
7435         }
7436         else if (!strcmp(res->what, "stats"))
7437                 RTE_ETH_FOREACH_DEV(i)
7438                         nic_stats_display(i);
7439         else if (!strcmp(res->what, "xstats"))
7440                 RTE_ETH_FOREACH_DEV(i)
7441                         nic_xstats_display(i);
7442         else if (!strcmp(res->what, "fdir"))
7443                 RTE_ETH_FOREACH_DEV(i)
7444                         fdir_get_infos(i);
7445         else if (!strcmp(res->what, "stat_qmap"))
7446                 RTE_ETH_FOREACH_DEV(i)
7447                         nic_stats_mapping_display(i);
7448         else if (!strcmp(res->what, "dcb_tc"))
7449                 RTE_ETH_FOREACH_DEV(i)
7450                         port_dcb_info_display(i);
7451         else if (!strcmp(res->what, "cap"))
7452                 RTE_ETH_FOREACH_DEV(i)
7453                         port_offload_cap_display(i);
7454 }
7455
7456 cmdline_parse_token_string_t cmd_showportall_show =
7457         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7458                                  "show#clear");
7459 cmdline_parse_token_string_t cmd_showportall_port =
7460         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7461 cmdline_parse_token_string_t cmd_showportall_what =
7462         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7463                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7464 cmdline_parse_token_string_t cmd_showportall_all =
7465         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7466 cmdline_parse_inst_t cmd_showportall = {
7467         .f = cmd_showportall_parsed,
7468         .data = NULL,
7469         .help_str = "show|clear port "
7470                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7471         .tokens = {
7472                 (void *)&cmd_showportall_show,
7473                 (void *)&cmd_showportall_port,
7474                 (void *)&cmd_showportall_what,
7475                 (void *)&cmd_showportall_all,
7476                 NULL,
7477         },
7478 };
7479
7480 /* *** SHOW PORT INFO *** */
7481 struct cmd_showport_result {
7482         cmdline_fixed_string_t show;
7483         cmdline_fixed_string_t port;
7484         cmdline_fixed_string_t what;
7485         uint16_t portnum;
7486 };
7487
7488 static void cmd_showport_parsed(void *parsed_result,
7489                                 __attribute__((unused)) struct cmdline *cl,
7490                                 __attribute__((unused)) void *data)
7491 {
7492         struct cmd_showport_result *res = parsed_result;
7493         if (!strcmp(res->show, "clear")) {
7494                 if (!strcmp(res->what, "stats"))
7495                         nic_stats_clear(res->portnum);
7496                 else if (!strcmp(res->what, "xstats"))
7497                         nic_xstats_clear(res->portnum);
7498         } else if (!strcmp(res->what, "info"))
7499                 port_infos_display(res->portnum);
7500         else if (!strcmp(res->what, "summary")) {
7501                 port_summary_header_display();
7502                 port_summary_display(res->portnum);
7503         }
7504         else if (!strcmp(res->what, "stats"))
7505                 nic_stats_display(res->portnum);
7506         else if (!strcmp(res->what, "xstats"))
7507                 nic_xstats_display(res->portnum);
7508         else if (!strcmp(res->what, "fdir"))
7509                  fdir_get_infos(res->portnum);
7510         else if (!strcmp(res->what, "stat_qmap"))
7511                 nic_stats_mapping_display(res->portnum);
7512         else if (!strcmp(res->what, "dcb_tc"))
7513                 port_dcb_info_display(res->portnum);
7514         else if (!strcmp(res->what, "cap"))
7515                 port_offload_cap_display(res->portnum);
7516 }
7517
7518 cmdline_parse_token_string_t cmd_showport_show =
7519         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7520                                  "show#clear");
7521 cmdline_parse_token_string_t cmd_showport_port =
7522         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7523 cmdline_parse_token_string_t cmd_showport_what =
7524         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7525                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7526 cmdline_parse_token_num_t cmd_showport_portnum =
7527         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7528
7529 cmdline_parse_inst_t cmd_showport = {
7530         .f = cmd_showport_parsed,
7531         .data = NULL,
7532         .help_str = "show|clear port "
7533                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7534                 "<port_id>",
7535         .tokens = {
7536                 (void *)&cmd_showport_show,
7537                 (void *)&cmd_showport_port,
7538                 (void *)&cmd_showport_what,
7539                 (void *)&cmd_showport_portnum,
7540                 NULL,
7541         },
7542 };
7543
7544 /* *** SHOW DEVICE INFO *** */
7545 struct cmd_showdevice_result {
7546         cmdline_fixed_string_t show;
7547         cmdline_fixed_string_t device;
7548         cmdline_fixed_string_t what;
7549         cmdline_fixed_string_t identifier;
7550 };
7551
7552 static void cmd_showdevice_parsed(void *parsed_result,
7553                                 __attribute__((unused)) struct cmdline *cl,
7554                                 __attribute__((unused)) void *data)
7555 {
7556         struct cmd_showdevice_result *res = parsed_result;
7557         if (!strcmp(res->what, "info")) {
7558                 if (!strcmp(res->identifier, "all"))
7559                         device_infos_display(NULL);
7560                 else
7561                         device_infos_display(res->identifier);
7562         }
7563 }
7564
7565 cmdline_parse_token_string_t cmd_showdevice_show =
7566         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7567                                  "show");
7568 cmdline_parse_token_string_t cmd_showdevice_device =
7569         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7570 cmdline_parse_token_string_t cmd_showdevice_what =
7571         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7572                                  "info");
7573 cmdline_parse_token_string_t cmd_showdevice_identifier =
7574         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7575                         identifier, NULL);
7576
7577 cmdline_parse_inst_t cmd_showdevice = {
7578         .f = cmd_showdevice_parsed,
7579         .data = NULL,
7580         .help_str = "show device info <identifier>|all",
7581         .tokens = {
7582                 (void *)&cmd_showdevice_show,
7583                 (void *)&cmd_showdevice_device,
7584                 (void *)&cmd_showdevice_what,
7585                 (void *)&cmd_showdevice_identifier,
7586                 NULL,
7587         },
7588 };
7589 /* *** SHOW QUEUE INFO *** */
7590 struct cmd_showqueue_result {
7591         cmdline_fixed_string_t show;
7592         cmdline_fixed_string_t type;
7593         cmdline_fixed_string_t what;
7594         uint16_t portnum;
7595         uint16_t queuenum;
7596 };
7597
7598 static void
7599 cmd_showqueue_parsed(void *parsed_result,
7600         __attribute__((unused)) struct cmdline *cl,
7601         __attribute__((unused)) void *data)
7602 {
7603         struct cmd_showqueue_result *res = parsed_result;
7604
7605         if (!strcmp(res->type, "rxq"))
7606                 rx_queue_infos_display(res->portnum, res->queuenum);
7607         else if (!strcmp(res->type, "txq"))
7608                 tx_queue_infos_display(res->portnum, res->queuenum);
7609 }
7610
7611 cmdline_parse_token_string_t cmd_showqueue_show =
7612         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7613 cmdline_parse_token_string_t cmd_showqueue_type =
7614         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7615 cmdline_parse_token_string_t cmd_showqueue_what =
7616         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7617 cmdline_parse_token_num_t cmd_showqueue_portnum =
7618         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7619 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7620         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7621
7622 cmdline_parse_inst_t cmd_showqueue = {
7623         .f = cmd_showqueue_parsed,
7624         .data = NULL,
7625         .help_str = "show rxq|txq info <port_id> <queue_id>",
7626         .tokens = {
7627                 (void *)&cmd_showqueue_show,
7628                 (void *)&cmd_showqueue_type,
7629                 (void *)&cmd_showqueue_what,
7630                 (void *)&cmd_showqueue_portnum,
7631                 (void *)&cmd_showqueue_queuenum,
7632                 NULL,
7633         },
7634 };
7635
7636 /* show/clear fwd engine statistics */
7637 struct fwd_result {
7638         cmdline_fixed_string_t action;
7639         cmdline_fixed_string_t fwd;
7640         cmdline_fixed_string_t stats;
7641         cmdline_fixed_string_t all;
7642 };
7643
7644 cmdline_parse_token_string_t cmd_fwd_action =
7645         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7646 cmdline_parse_token_string_t cmd_fwd_fwd =
7647         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7648 cmdline_parse_token_string_t cmd_fwd_stats =
7649         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7650 cmdline_parse_token_string_t cmd_fwd_all =
7651         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7652
7653 static void
7654 cmd_showfwdall_parsed(void *parsed_result,
7655                       __rte_unused struct cmdline *cl,
7656                       __rte_unused void *data)
7657 {
7658         struct fwd_result *res = parsed_result;
7659
7660         if (!strcmp(res->action, "show"))
7661                 fwd_stats_display();
7662         else
7663                 fwd_stats_reset();
7664 }
7665
7666 static cmdline_parse_inst_t cmd_showfwdall = {
7667         .f = cmd_showfwdall_parsed,
7668         .data = NULL,
7669         .help_str = "show|clear fwd stats all",
7670         .tokens = {
7671                 (void *)&cmd_fwd_action,
7672                 (void *)&cmd_fwd_fwd,
7673                 (void *)&cmd_fwd_stats,
7674                 (void *)&cmd_fwd_all,
7675                 NULL,
7676         },
7677 };
7678
7679 /* *** READ PORT REGISTER *** */
7680 struct cmd_read_reg_result {
7681         cmdline_fixed_string_t read;
7682         cmdline_fixed_string_t reg;
7683         portid_t port_id;
7684         uint32_t reg_off;
7685 };
7686
7687 static void
7688 cmd_read_reg_parsed(void *parsed_result,
7689                     __attribute__((unused)) struct cmdline *cl,
7690                     __attribute__((unused)) void *data)
7691 {
7692         struct cmd_read_reg_result *res = parsed_result;
7693         port_reg_display(res->port_id, res->reg_off);
7694 }
7695
7696 cmdline_parse_token_string_t cmd_read_reg_read =
7697         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7698 cmdline_parse_token_string_t cmd_read_reg_reg =
7699         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7700 cmdline_parse_token_num_t cmd_read_reg_port_id =
7701         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7702 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7703         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7704
7705 cmdline_parse_inst_t cmd_read_reg = {
7706         .f = cmd_read_reg_parsed,
7707         .data = NULL,
7708         .help_str = "read reg <port_id> <reg_off>",
7709         .tokens = {
7710                 (void *)&cmd_read_reg_read,
7711                 (void *)&cmd_read_reg_reg,
7712                 (void *)&cmd_read_reg_port_id,
7713                 (void *)&cmd_read_reg_reg_off,
7714                 NULL,
7715         },
7716 };
7717
7718 /* *** READ PORT REGISTER BIT FIELD *** */
7719 struct cmd_read_reg_bit_field_result {
7720         cmdline_fixed_string_t read;
7721         cmdline_fixed_string_t regfield;
7722         portid_t port_id;
7723         uint32_t reg_off;
7724         uint8_t bit1_pos;
7725         uint8_t bit2_pos;
7726 };
7727
7728 static void
7729 cmd_read_reg_bit_field_parsed(void *parsed_result,
7730                               __attribute__((unused)) struct cmdline *cl,
7731                               __attribute__((unused)) void *data)
7732 {
7733         struct cmd_read_reg_bit_field_result *res = parsed_result;
7734         port_reg_bit_field_display(res->port_id, res->reg_off,
7735                                    res->bit1_pos, res->bit2_pos);
7736 }
7737
7738 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7739         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7740                                  "read");
7741 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7742         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7743                                  regfield, "regfield");
7744 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7745         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7746                               UINT16);
7747 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7748         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7749                               UINT32);
7750 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7751         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7752                               UINT8);
7753 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7754         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7755                               UINT8);
7756
7757 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7758         .f = cmd_read_reg_bit_field_parsed,
7759         .data = NULL,
7760         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7761         "Read register bit field between bit_x and bit_y included",
7762         .tokens = {
7763                 (void *)&cmd_read_reg_bit_field_read,
7764                 (void *)&cmd_read_reg_bit_field_regfield,
7765                 (void *)&cmd_read_reg_bit_field_port_id,
7766                 (void *)&cmd_read_reg_bit_field_reg_off,
7767                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7768                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7769                 NULL,
7770         },
7771 };
7772
7773 /* *** READ PORT REGISTER BIT *** */
7774 struct cmd_read_reg_bit_result {
7775         cmdline_fixed_string_t read;
7776         cmdline_fixed_string_t regbit;
7777         portid_t port_id;
7778         uint32_t reg_off;
7779         uint8_t bit_pos;
7780 };
7781
7782 static void
7783 cmd_read_reg_bit_parsed(void *parsed_result,
7784                         __attribute__((unused)) struct cmdline *cl,
7785                         __attribute__((unused)) void *data)
7786 {
7787         struct cmd_read_reg_bit_result *res = parsed_result;
7788         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7789 }
7790
7791 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7792         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7793 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7794         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7795                                  regbit, "regbit");
7796 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7797         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7798 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7799         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7800 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7801         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7802
7803 cmdline_parse_inst_t cmd_read_reg_bit = {
7804         .f = cmd_read_reg_bit_parsed,
7805         .data = NULL,
7806         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7807         .tokens = {
7808                 (void *)&cmd_read_reg_bit_read,
7809                 (void *)&cmd_read_reg_bit_regbit,
7810                 (void *)&cmd_read_reg_bit_port_id,
7811                 (void *)&cmd_read_reg_bit_reg_off,
7812                 (void *)&cmd_read_reg_bit_bit_pos,
7813                 NULL,
7814         },
7815 };
7816
7817 /* *** WRITE PORT REGISTER *** */
7818 struct cmd_write_reg_result {
7819         cmdline_fixed_string_t write;
7820         cmdline_fixed_string_t reg;
7821         portid_t port_id;
7822         uint32_t reg_off;
7823         uint32_t value;
7824 };
7825
7826 static void
7827 cmd_write_reg_parsed(void *parsed_result,
7828                      __attribute__((unused)) struct cmdline *cl,
7829                      __attribute__((unused)) void *data)
7830 {
7831         struct cmd_write_reg_result *res = parsed_result;
7832         port_reg_set(res->port_id, res->reg_off, res->value);
7833 }
7834
7835 cmdline_parse_token_string_t cmd_write_reg_write =
7836         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7837 cmdline_parse_token_string_t cmd_write_reg_reg =
7838         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7839 cmdline_parse_token_num_t cmd_write_reg_port_id =
7840         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7841 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7842         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7843 cmdline_parse_token_num_t cmd_write_reg_value =
7844         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7845
7846 cmdline_parse_inst_t cmd_write_reg = {
7847         .f = cmd_write_reg_parsed,
7848         .data = NULL,
7849         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7850         .tokens = {
7851                 (void *)&cmd_write_reg_write,
7852                 (void *)&cmd_write_reg_reg,
7853                 (void *)&cmd_write_reg_port_id,
7854                 (void *)&cmd_write_reg_reg_off,
7855                 (void *)&cmd_write_reg_value,
7856                 NULL,
7857         },
7858 };
7859
7860 /* *** WRITE PORT REGISTER BIT FIELD *** */
7861 struct cmd_write_reg_bit_field_result {
7862         cmdline_fixed_string_t write;
7863         cmdline_fixed_string_t regfield;
7864         portid_t port_id;
7865         uint32_t reg_off;
7866         uint8_t bit1_pos;
7867         uint8_t bit2_pos;
7868         uint32_t value;
7869 };
7870
7871 static void
7872 cmd_write_reg_bit_field_parsed(void *parsed_result,
7873                                __attribute__((unused)) struct cmdline *cl,
7874                                __attribute__((unused)) void *data)
7875 {
7876         struct cmd_write_reg_bit_field_result *res = parsed_result;
7877         port_reg_bit_field_set(res->port_id, res->reg_off,
7878                           res->bit1_pos, res->bit2_pos, res->value);
7879 }
7880
7881 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7882         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7883                                  "write");
7884 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7885         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7886                                  regfield, "regfield");
7887 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7888         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7889                               UINT16);
7890 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7891         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7892                               UINT32);
7893 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7894         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7895                               UINT8);
7896 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7897         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7898                               UINT8);
7899 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7900         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7901                               UINT32);
7902
7903 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7904         .f = cmd_write_reg_bit_field_parsed,
7905         .data = NULL,
7906         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7907                 "<reg_value>: "
7908                 "Set register bit field between bit_x and bit_y included",
7909         .tokens = {
7910                 (void *)&cmd_write_reg_bit_field_write,
7911                 (void *)&cmd_write_reg_bit_field_regfield,
7912                 (void *)&cmd_write_reg_bit_field_port_id,
7913                 (void *)&cmd_write_reg_bit_field_reg_off,
7914                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7915                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7916                 (void *)&cmd_write_reg_bit_field_value,
7917                 NULL,
7918         },
7919 };
7920
7921 /* *** WRITE PORT REGISTER BIT *** */
7922 struct cmd_write_reg_bit_result {
7923         cmdline_fixed_string_t write;
7924         cmdline_fixed_string_t regbit;
7925         portid_t port_id;
7926         uint32_t reg_off;
7927         uint8_t bit_pos;
7928         uint8_t value;
7929 };
7930
7931 static void
7932 cmd_write_reg_bit_parsed(void *parsed_result,
7933                          __attribute__((unused)) struct cmdline *cl,
7934                          __attribute__((unused)) void *data)
7935 {
7936         struct cmd_write_reg_bit_result *res = parsed_result;
7937         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7938 }
7939
7940 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7941         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7942                                  "write");
7943 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7944         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7945                                  regbit, "regbit");
7946 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7947         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7948 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7949         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7950 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7951         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7952 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7953         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7954
7955 cmdline_parse_inst_t cmd_write_reg_bit = {
7956         .f = cmd_write_reg_bit_parsed,
7957         .data = NULL,
7958         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7959                 "0 <= bit_x <= 31",
7960         .tokens = {
7961                 (void *)&cmd_write_reg_bit_write,
7962                 (void *)&cmd_write_reg_bit_regbit,
7963                 (void *)&cmd_write_reg_bit_port_id,
7964                 (void *)&cmd_write_reg_bit_reg_off,
7965                 (void *)&cmd_write_reg_bit_bit_pos,
7966                 (void *)&cmd_write_reg_bit_value,
7967                 NULL,
7968         },
7969 };
7970
7971 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7972 struct cmd_read_rxd_txd_result {
7973         cmdline_fixed_string_t read;
7974         cmdline_fixed_string_t rxd_txd;
7975         portid_t port_id;
7976         uint16_t queue_id;
7977         uint16_t desc_id;
7978 };
7979
7980 static void
7981 cmd_read_rxd_txd_parsed(void *parsed_result,
7982                         __attribute__((unused)) struct cmdline *cl,
7983                         __attribute__((unused)) void *data)
7984 {
7985         struct cmd_read_rxd_txd_result *res = parsed_result;
7986
7987         if (!strcmp(res->rxd_txd, "rxd"))
7988                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7989         else if (!strcmp(res->rxd_txd, "txd"))
7990                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7991 }
7992
7993 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7994         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7995 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7996         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7997                                  "rxd#txd");
7998 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7999         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8000 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8001         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8002 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8003         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8004
8005 cmdline_parse_inst_t cmd_read_rxd_txd = {
8006         .f = cmd_read_rxd_txd_parsed,
8007         .data = NULL,
8008         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8009         .tokens = {
8010                 (void *)&cmd_read_rxd_txd_read,
8011                 (void *)&cmd_read_rxd_txd_rxd_txd,
8012                 (void *)&cmd_read_rxd_txd_port_id,
8013                 (void *)&cmd_read_rxd_txd_queue_id,
8014                 (void *)&cmd_read_rxd_txd_desc_id,
8015                 NULL,
8016         },
8017 };
8018
8019 /* *** QUIT *** */
8020 struct cmd_quit_result {
8021         cmdline_fixed_string_t quit;
8022 };
8023
8024 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
8025                             struct cmdline *cl,
8026                             __attribute__((unused)) void *data)
8027 {
8028         cmdline_quit(cl);
8029 }
8030
8031 cmdline_parse_token_string_t cmd_quit_quit =
8032         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8033
8034 cmdline_parse_inst_t cmd_quit = {
8035         .f = cmd_quit_parsed,
8036         .data = NULL,
8037         .help_str = "quit: Exit application",
8038         .tokens = {
8039                 (void *)&cmd_quit_quit,
8040                 NULL,
8041         },
8042 };
8043
8044 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8045 struct cmd_mac_addr_result {
8046         cmdline_fixed_string_t mac_addr_cmd;
8047         cmdline_fixed_string_t what;
8048         uint16_t port_num;
8049         struct rte_ether_addr address;
8050 };
8051
8052 static void cmd_mac_addr_parsed(void *parsed_result,
8053                 __attribute__((unused)) struct cmdline *cl,
8054                 __attribute__((unused)) void *data)
8055 {
8056         struct cmd_mac_addr_result *res = parsed_result;
8057         int ret;
8058
8059         if (strcmp(res->what, "add") == 0)
8060                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8061         else if (strcmp(res->what, "set") == 0)
8062                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8063                                                        &res->address);
8064         else
8065                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8066
8067         /* check the return value and print it if is < 0 */
8068         if(ret < 0)
8069                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8070
8071 }
8072
8073 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8074         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8075                                 "mac_addr");
8076 cmdline_parse_token_string_t cmd_mac_addr_what =
8077         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8078                                 "add#remove#set");
8079 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8080                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8081                                         UINT16);
8082 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8083                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8084
8085 cmdline_parse_inst_t cmd_mac_addr = {
8086         .f = cmd_mac_addr_parsed,
8087         .data = (void *)0,
8088         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8089                         "Add/Remove/Set MAC address on port_id",
8090         .tokens = {
8091                 (void *)&cmd_mac_addr_cmd,
8092                 (void *)&cmd_mac_addr_what,
8093                 (void *)&cmd_mac_addr_portnum,
8094                 (void *)&cmd_mac_addr_addr,
8095                 NULL,
8096         },
8097 };
8098
8099 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8100 struct cmd_eth_peer_result {
8101         cmdline_fixed_string_t set;
8102         cmdline_fixed_string_t eth_peer;
8103         portid_t port_id;
8104         cmdline_fixed_string_t peer_addr;
8105 };
8106
8107 static void cmd_set_eth_peer_parsed(void *parsed_result,
8108                         __attribute__((unused)) struct cmdline *cl,
8109                         __attribute__((unused)) void *data)
8110 {
8111                 struct cmd_eth_peer_result *res = parsed_result;
8112
8113                 if (test_done == 0) {
8114                         printf("Please stop forwarding first\n");
8115                         return;
8116                 }
8117                 if (!strcmp(res->eth_peer, "eth-peer")) {
8118                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8119                         fwd_config_setup();
8120                 }
8121 }
8122 cmdline_parse_token_string_t cmd_eth_peer_set =
8123         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8124 cmdline_parse_token_string_t cmd_eth_peer =
8125         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8126 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8127         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8128 cmdline_parse_token_string_t cmd_eth_peer_addr =
8129         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8130
8131 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8132         .f = cmd_set_eth_peer_parsed,
8133         .data = NULL,
8134         .help_str = "set eth-peer <port_id> <peer_mac>",
8135         .tokens = {
8136                 (void *)&cmd_eth_peer_set,
8137                 (void *)&cmd_eth_peer,
8138                 (void *)&cmd_eth_peer_port_id,
8139                 (void *)&cmd_eth_peer_addr,
8140                 NULL,
8141         },
8142 };
8143
8144 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8145 struct cmd_set_qmap_result {
8146         cmdline_fixed_string_t set;
8147         cmdline_fixed_string_t qmap;
8148         cmdline_fixed_string_t what;
8149         portid_t port_id;
8150         uint16_t queue_id;
8151         uint8_t map_value;
8152 };
8153
8154 static void
8155 cmd_set_qmap_parsed(void *parsed_result,
8156                        __attribute__((unused)) struct cmdline *cl,
8157                        __attribute__((unused)) void *data)
8158 {
8159         struct cmd_set_qmap_result *res = parsed_result;
8160         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8161
8162         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8163 }
8164
8165 cmdline_parse_token_string_t cmd_setqmap_set =
8166         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8167                                  set, "set");
8168 cmdline_parse_token_string_t cmd_setqmap_qmap =
8169         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8170                                  qmap, "stat_qmap");
8171 cmdline_parse_token_string_t cmd_setqmap_what =
8172         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8173                                  what, "tx#rx");
8174 cmdline_parse_token_num_t cmd_setqmap_portid =
8175         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8176                               port_id, UINT16);
8177 cmdline_parse_token_num_t cmd_setqmap_queueid =
8178         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8179                               queue_id, UINT16);
8180 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8181         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8182                               map_value, UINT8);
8183
8184 cmdline_parse_inst_t cmd_set_qmap = {
8185         .f = cmd_set_qmap_parsed,
8186         .data = NULL,
8187         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8188                 "Set statistics mapping value on tx|rx queue_id of port_id",
8189         .tokens = {
8190                 (void *)&cmd_setqmap_set,
8191                 (void *)&cmd_setqmap_qmap,
8192                 (void *)&cmd_setqmap_what,
8193                 (void *)&cmd_setqmap_portid,
8194                 (void *)&cmd_setqmap_queueid,
8195                 (void *)&cmd_setqmap_mapvalue,
8196                 NULL,
8197         },
8198 };
8199
8200 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8201 struct cmd_set_xstats_hide_zero_result {
8202         cmdline_fixed_string_t keyword;
8203         cmdline_fixed_string_t name;
8204         cmdline_fixed_string_t on_off;
8205 };
8206
8207 static void
8208 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8209                         __attribute__((unused)) struct cmdline *cl,
8210                         __attribute__((unused)) void *data)
8211 {
8212         struct cmd_set_xstats_hide_zero_result *res;
8213         uint16_t on_off = 0;
8214
8215         res = parsed_result;
8216         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8217         set_xstats_hide_zero(on_off);
8218 }
8219
8220 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8221         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8222                                  keyword, "set");
8223 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8224         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8225                                  name, "xstats-hide-zero");
8226 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8227         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8228                                  on_off, "on#off");
8229
8230 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8231         .f = cmd_set_xstats_hide_zero_parsed,
8232         .data = NULL,
8233         .help_str = "set xstats-hide-zero on|off",
8234         .tokens = {
8235                 (void *)&cmd_set_xstats_hide_zero_keyword,
8236                 (void *)&cmd_set_xstats_hide_zero_name,
8237                 (void *)&cmd_set_xstats_hide_zero_on_off,
8238                 NULL,
8239         },
8240 };
8241
8242 /* *** CONFIGURE UNICAST HASH TABLE *** */
8243 struct cmd_set_uc_hash_table {
8244         cmdline_fixed_string_t set;
8245         cmdline_fixed_string_t port;
8246         portid_t port_id;
8247         cmdline_fixed_string_t what;
8248         struct rte_ether_addr address;
8249         cmdline_fixed_string_t mode;
8250 };
8251
8252 static void
8253 cmd_set_uc_hash_parsed(void *parsed_result,
8254                        __attribute__((unused)) struct cmdline *cl,
8255                        __attribute__((unused)) void *data)
8256 {
8257         int ret=0;
8258         struct cmd_set_uc_hash_table *res = parsed_result;
8259
8260         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8261
8262         if (strcmp(res->what, "uta") == 0)
8263                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8264                                                 &res->address,(uint8_t)is_on);
8265         if (ret < 0)
8266                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8267
8268 }
8269
8270 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8271         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8272                                  set, "set");
8273 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8274         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8275                                  port, "port");
8276 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8277         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8278                               port_id, UINT16);
8279 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8280         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8281                                  what, "uta");
8282 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8283         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8284                                 address);
8285 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8286         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8287                                  mode, "on#off");
8288
8289 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8290         .f = cmd_set_uc_hash_parsed,
8291         .data = NULL,
8292         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8293         .tokens = {
8294                 (void *)&cmd_set_uc_hash_set,
8295                 (void *)&cmd_set_uc_hash_port,
8296                 (void *)&cmd_set_uc_hash_portid,
8297                 (void *)&cmd_set_uc_hash_what,
8298                 (void *)&cmd_set_uc_hash_mac,
8299                 (void *)&cmd_set_uc_hash_mode,
8300                 NULL,
8301         },
8302 };
8303
8304 struct cmd_set_uc_all_hash_table {
8305         cmdline_fixed_string_t set;
8306         cmdline_fixed_string_t port;
8307         portid_t port_id;
8308         cmdline_fixed_string_t what;
8309         cmdline_fixed_string_t value;
8310         cmdline_fixed_string_t mode;
8311 };
8312
8313 static void
8314 cmd_set_uc_all_hash_parsed(void *parsed_result,
8315                        __attribute__((unused)) struct cmdline *cl,
8316                        __attribute__((unused)) void *data)
8317 {
8318         int ret=0;
8319         struct cmd_set_uc_all_hash_table *res = parsed_result;
8320
8321         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8322
8323         if ((strcmp(res->what, "uta") == 0) &&
8324                 (strcmp(res->value, "all") == 0))
8325                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8326         if (ret < 0)
8327                 printf("bad unicast hash table parameter,"
8328                         "return code = %d \n", ret);
8329 }
8330
8331 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8332         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8333                                  set, "set");
8334 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8335         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8336                                  port, "port");
8337 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8338         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8339                               port_id, UINT16);
8340 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8341         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8342                                  what, "uta");
8343 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8344         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8345                                 value,"all");
8346 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8347         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8348                                  mode, "on#off");
8349
8350 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8351         .f = cmd_set_uc_all_hash_parsed,
8352         .data = NULL,
8353         .help_str = "set port <port_id> uta all on|off",
8354         .tokens = {
8355                 (void *)&cmd_set_uc_all_hash_set,
8356                 (void *)&cmd_set_uc_all_hash_port,
8357                 (void *)&cmd_set_uc_all_hash_portid,
8358                 (void *)&cmd_set_uc_all_hash_what,
8359                 (void *)&cmd_set_uc_all_hash_value,
8360                 (void *)&cmd_set_uc_all_hash_mode,
8361                 NULL,
8362         },
8363 };
8364
8365 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8366 struct cmd_set_vf_macvlan_filter {
8367         cmdline_fixed_string_t set;
8368         cmdline_fixed_string_t port;
8369         portid_t port_id;
8370         cmdline_fixed_string_t vf;
8371         uint8_t vf_id;
8372         struct rte_ether_addr address;
8373         cmdline_fixed_string_t filter_type;
8374         cmdline_fixed_string_t mode;
8375 };
8376
8377 static void
8378 cmd_set_vf_macvlan_parsed(void *parsed_result,
8379                        __attribute__((unused)) struct cmdline *cl,
8380                        __attribute__((unused)) void *data)
8381 {
8382         int is_on, ret = 0;
8383         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8384         struct rte_eth_mac_filter filter;
8385
8386         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8387
8388         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8389
8390         /* set VF MAC filter */
8391         filter.is_vf = 1;
8392
8393         /* set VF ID */
8394         filter.dst_id = res->vf_id;
8395
8396         if (!strcmp(res->filter_type, "exact-mac"))
8397                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8398         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8399                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8400         else if (!strcmp(res->filter_type, "hashmac"))
8401                 filter.filter_type = RTE_MAC_HASH_MATCH;
8402         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8403                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8404
8405         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8406
8407         if (is_on)
8408                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8409                                         RTE_ETH_FILTER_MACVLAN,
8410                                         RTE_ETH_FILTER_ADD,
8411                                          &filter);
8412         else
8413                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8414                                         RTE_ETH_FILTER_MACVLAN,
8415                                         RTE_ETH_FILTER_DELETE,
8416                                         &filter);
8417
8418         if (ret < 0)
8419                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8420
8421 }
8422
8423 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8424         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8425                                  set, "set");
8426 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8427         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8428                                  port, "port");
8429 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8430         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8431                               port_id, UINT16);
8432 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8433         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8434                                  vf, "vf");
8435 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8436         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8437                                 vf_id, UINT8);
8438 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8439         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8440                                 address);
8441 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8442         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8443                                 filter_type, "exact-mac#exact-mac-vlan"
8444                                 "#hashmac#hashmac-vlan");
8445 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8446         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8447                                  mode, "on#off");
8448
8449 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8450         .f = cmd_set_vf_macvlan_parsed,
8451         .data = NULL,
8452         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8453                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8454                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8455                 "hash match rule: hash match of MAC and exact match of VLAN",
8456         .tokens = {
8457                 (void *)&cmd_set_vf_macvlan_set,
8458                 (void *)&cmd_set_vf_macvlan_port,
8459                 (void *)&cmd_set_vf_macvlan_portid,
8460                 (void *)&cmd_set_vf_macvlan_vf,
8461                 (void *)&cmd_set_vf_macvlan_vf_id,
8462                 (void *)&cmd_set_vf_macvlan_mac,
8463                 (void *)&cmd_set_vf_macvlan_filter_type,
8464                 (void *)&cmd_set_vf_macvlan_mode,
8465                 NULL,
8466         },
8467 };
8468
8469 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8470 struct cmd_set_vf_traffic {
8471         cmdline_fixed_string_t set;
8472         cmdline_fixed_string_t port;
8473         portid_t port_id;
8474         cmdline_fixed_string_t vf;
8475         uint8_t vf_id;
8476         cmdline_fixed_string_t what;
8477         cmdline_fixed_string_t mode;
8478 };
8479
8480 static void
8481 cmd_set_vf_traffic_parsed(void *parsed_result,
8482                        __attribute__((unused)) struct cmdline *cl,
8483                        __attribute__((unused)) void *data)
8484 {
8485         struct cmd_set_vf_traffic *res = parsed_result;
8486         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8487         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8488
8489         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8490 }
8491
8492 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8493         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8494                                  set, "set");
8495 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8496         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8497                                  port, "port");
8498 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8499         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8500                               port_id, UINT16);
8501 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8502         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8503                                  vf, "vf");
8504 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8505         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8506                               vf_id, UINT8);
8507 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8508         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8509                                  what, "tx#rx");
8510 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8511         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8512                                  mode, "on#off");
8513
8514 cmdline_parse_inst_t cmd_set_vf_traffic = {
8515         .f = cmd_set_vf_traffic_parsed,
8516         .data = NULL,
8517         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8518         .tokens = {
8519                 (void *)&cmd_setvf_traffic_set,
8520                 (void *)&cmd_setvf_traffic_port,
8521                 (void *)&cmd_setvf_traffic_portid,
8522                 (void *)&cmd_setvf_traffic_vf,
8523                 (void *)&cmd_setvf_traffic_vfid,
8524                 (void *)&cmd_setvf_traffic_what,
8525                 (void *)&cmd_setvf_traffic_mode,
8526                 NULL,
8527         },
8528 };
8529
8530 /* *** CONFIGURE VF RECEIVE MODE *** */
8531 struct cmd_set_vf_rxmode {
8532         cmdline_fixed_string_t set;
8533         cmdline_fixed_string_t port;
8534         portid_t port_id;
8535         cmdline_fixed_string_t vf;
8536         uint8_t vf_id;
8537         cmdline_fixed_string_t what;
8538         cmdline_fixed_string_t mode;
8539         cmdline_fixed_string_t on;
8540 };
8541
8542 static void
8543 cmd_set_vf_rxmode_parsed(void *parsed_result,
8544                        __attribute__((unused)) struct cmdline *cl,
8545                        __attribute__((unused)) void *data)
8546 {
8547         int ret = -ENOTSUP;
8548         uint16_t vf_rxmode = 0;
8549         struct cmd_set_vf_rxmode *res = parsed_result;
8550
8551         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8552         if (!strcmp(res->what,"rxmode")) {
8553                 if (!strcmp(res->mode, "AUPE"))
8554                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8555                 else if (!strcmp(res->mode, "ROPE"))
8556                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8557                 else if (!strcmp(res->mode, "BAM"))
8558                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8559                 else if (!strncmp(res->mode, "MPE",3))
8560                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8561         }
8562
8563         RTE_SET_USED(is_on);
8564
8565 #ifdef RTE_LIBRTE_IXGBE_PMD
8566         if (ret == -ENOTSUP)
8567                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8568                                                   vf_rxmode, (uint8_t)is_on);
8569 #endif
8570 #ifdef RTE_LIBRTE_BNXT_PMD
8571         if (ret == -ENOTSUP)
8572                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8573                                                  vf_rxmode, (uint8_t)is_on);
8574 #endif
8575         if (ret < 0)
8576                 printf("bad VF receive mode parameter, return code = %d \n",
8577                 ret);
8578 }
8579
8580 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8581         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8582                                  set, "set");
8583 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8584         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8585                                  port, "port");
8586 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8587         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8588                               port_id, UINT16);
8589 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8590         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8591                                  vf, "vf");
8592 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8593         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8594                               vf_id, UINT8);
8595 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8596         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8597                                  what, "rxmode");
8598 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8599         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8600                                  mode, "AUPE#ROPE#BAM#MPE");
8601 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8602         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8603                                  on, "on#off");
8604
8605 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8606         .f = cmd_set_vf_rxmode_parsed,
8607         .data = NULL,
8608         .help_str = "set port <port_id> vf <vf_id> rxmode "
8609                 "AUPE|ROPE|BAM|MPE on|off",
8610         .tokens = {
8611                 (void *)&cmd_set_vf_rxmode_set,
8612                 (void *)&cmd_set_vf_rxmode_port,
8613                 (void *)&cmd_set_vf_rxmode_portid,
8614                 (void *)&cmd_set_vf_rxmode_vf,
8615                 (void *)&cmd_set_vf_rxmode_vfid,
8616                 (void *)&cmd_set_vf_rxmode_what,
8617                 (void *)&cmd_set_vf_rxmode_mode,
8618                 (void *)&cmd_set_vf_rxmode_on,
8619                 NULL,
8620         },
8621 };
8622
8623 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8624 struct cmd_vf_mac_addr_result {
8625         cmdline_fixed_string_t mac_addr_cmd;
8626         cmdline_fixed_string_t what;
8627         cmdline_fixed_string_t port;
8628         uint16_t port_num;
8629         cmdline_fixed_string_t vf;
8630         uint8_t vf_num;
8631         struct rte_ether_addr address;
8632 };
8633
8634 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8635                 __attribute__((unused)) struct cmdline *cl,
8636                 __attribute__((unused)) void *data)
8637 {
8638         struct cmd_vf_mac_addr_result *res = parsed_result;
8639         int ret = -ENOTSUP;
8640
8641         if (strcmp(res->what, "add") != 0)
8642                 return;
8643
8644 #ifdef RTE_LIBRTE_I40E_PMD
8645         if (ret == -ENOTSUP)
8646                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8647                                                    &res->address);
8648 #endif
8649 #ifdef RTE_LIBRTE_BNXT_PMD
8650         if (ret == -ENOTSUP)
8651                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8652                                                 res->vf_num);
8653 #endif
8654
8655         if(ret < 0)
8656                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8657
8658 }
8659
8660 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8661         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8662                                 mac_addr_cmd,"mac_addr");
8663 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8664         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8665                                 what,"add");
8666 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8667         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8668                                 port,"port");
8669 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8670         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8671                                 port_num, UINT16);
8672 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8673         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8674                                 vf,"vf");
8675 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8676         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8677                                 vf_num, UINT8);
8678 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8679         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8680                                 address);
8681
8682 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8683         .f = cmd_vf_mac_addr_parsed,
8684         .data = (void *)0,
8685         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8686                 "Add MAC address filtering for a VF on port_id",
8687         .tokens = {
8688                 (void *)&cmd_vf_mac_addr_cmd,
8689                 (void *)&cmd_vf_mac_addr_what,
8690                 (void *)&cmd_vf_mac_addr_port,
8691                 (void *)&cmd_vf_mac_addr_portnum,
8692                 (void *)&cmd_vf_mac_addr_vf,
8693                 (void *)&cmd_vf_mac_addr_vfnum,
8694                 (void *)&cmd_vf_mac_addr_addr,
8695                 NULL,
8696         },
8697 };
8698
8699 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8700 struct cmd_vf_rx_vlan_filter {
8701         cmdline_fixed_string_t rx_vlan;
8702         cmdline_fixed_string_t what;
8703         uint16_t vlan_id;
8704         cmdline_fixed_string_t port;
8705         portid_t port_id;
8706         cmdline_fixed_string_t vf;
8707         uint64_t vf_mask;
8708 };
8709
8710 static void
8711 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8712                           __attribute__((unused)) struct cmdline *cl,
8713                           __attribute__((unused)) void *data)
8714 {
8715         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8716         int ret = -ENOTSUP;
8717
8718         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8719
8720 #ifdef RTE_LIBRTE_IXGBE_PMD
8721         if (ret == -ENOTSUP)
8722                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8723                                 res->vlan_id, res->vf_mask, is_add);
8724 #endif
8725 #ifdef RTE_LIBRTE_I40E_PMD
8726         if (ret == -ENOTSUP)
8727                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8728                                 res->vlan_id, res->vf_mask, is_add);
8729 #endif
8730 #ifdef RTE_LIBRTE_BNXT_PMD
8731         if (ret == -ENOTSUP)
8732                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8733                                 res->vlan_id, res->vf_mask, is_add);
8734 #endif
8735
8736         switch (ret) {
8737         case 0:
8738                 break;
8739         case -EINVAL:
8740                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8741                                 res->vlan_id, res->vf_mask);
8742                 break;
8743         case -ENODEV:
8744                 printf("invalid port_id %d\n", res->port_id);
8745                 break;
8746         case -ENOTSUP:
8747                 printf("function not implemented or supported\n");
8748                 break;
8749         default:
8750                 printf("programming error: (%s)\n", strerror(-ret));
8751         }
8752 }
8753
8754 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8755         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8756                                  rx_vlan, "rx_vlan");
8757 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8758         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8759                                  what, "add#rm");
8760 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8761         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8762                               vlan_id, UINT16);
8763 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8764         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8765                                  port, "port");
8766 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8767         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8768                               port_id, UINT16);
8769 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8770         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8771                                  vf, "vf");
8772 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8773         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8774                               vf_mask, UINT64);
8775
8776 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8777         .f = cmd_vf_rx_vlan_filter_parsed,
8778         .data = NULL,
8779         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8780                 "(vf_mask = hexadecimal VF mask)",
8781         .tokens = {
8782                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8783                 (void *)&cmd_vf_rx_vlan_filter_what,
8784                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8785                 (void *)&cmd_vf_rx_vlan_filter_port,
8786                 (void *)&cmd_vf_rx_vlan_filter_portid,
8787                 (void *)&cmd_vf_rx_vlan_filter_vf,
8788                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8789                 NULL,
8790         },
8791 };
8792
8793 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8794 struct cmd_queue_rate_limit_result {
8795         cmdline_fixed_string_t set;
8796         cmdline_fixed_string_t port;
8797         uint16_t port_num;
8798         cmdline_fixed_string_t queue;
8799         uint8_t queue_num;
8800         cmdline_fixed_string_t rate;
8801         uint16_t rate_num;
8802 };
8803
8804 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8805                 __attribute__((unused)) struct cmdline *cl,
8806                 __attribute__((unused)) void *data)
8807 {
8808         struct cmd_queue_rate_limit_result *res = parsed_result;
8809         int ret = 0;
8810
8811         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8812                 && (strcmp(res->queue, "queue") == 0)
8813                 && (strcmp(res->rate, "rate") == 0))
8814                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8815                                         res->rate_num);
8816         if (ret < 0)
8817                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8818
8819 }
8820
8821 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8822         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8823                                 set, "set");
8824 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8825         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8826                                 port, "port");
8827 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8828         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8829                                 port_num, UINT16);
8830 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8831         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8832                                 queue, "queue");
8833 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8834         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8835                                 queue_num, UINT8);
8836 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8837         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8838                                 rate, "rate");
8839 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8840         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8841                                 rate_num, UINT16);
8842
8843 cmdline_parse_inst_t cmd_queue_rate_limit = {
8844         .f = cmd_queue_rate_limit_parsed,
8845         .data = (void *)0,
8846         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8847                 "Set rate limit for a queue on port_id",
8848         .tokens = {
8849                 (void *)&cmd_queue_rate_limit_set,
8850                 (void *)&cmd_queue_rate_limit_port,
8851                 (void *)&cmd_queue_rate_limit_portnum,
8852                 (void *)&cmd_queue_rate_limit_queue,
8853                 (void *)&cmd_queue_rate_limit_queuenum,
8854                 (void *)&cmd_queue_rate_limit_rate,
8855                 (void *)&cmd_queue_rate_limit_ratenum,
8856                 NULL,
8857         },
8858 };
8859
8860 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8861 struct cmd_vf_rate_limit_result {
8862         cmdline_fixed_string_t set;
8863         cmdline_fixed_string_t port;
8864         uint16_t port_num;
8865         cmdline_fixed_string_t vf;
8866         uint8_t vf_num;
8867         cmdline_fixed_string_t rate;
8868         uint16_t rate_num;
8869         cmdline_fixed_string_t q_msk;
8870         uint64_t q_msk_val;
8871 };
8872
8873 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8874                 __attribute__((unused)) struct cmdline *cl,
8875                 __attribute__((unused)) void *data)
8876 {
8877         struct cmd_vf_rate_limit_result *res = parsed_result;
8878         int ret = 0;
8879
8880         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8881                 && (strcmp(res->vf, "vf") == 0)
8882                 && (strcmp(res->rate, "rate") == 0)
8883                 && (strcmp(res->q_msk, "queue_mask") == 0))
8884                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8885                                         res->rate_num, res->q_msk_val);
8886         if (ret < 0)
8887                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8888
8889 }
8890
8891 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8892         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8893                                 set, "set");
8894 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8895         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8896                                 port, "port");
8897 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8898         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8899                                 port_num, UINT16);
8900 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8901         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8902                                 vf, "vf");
8903 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8904         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8905                                 vf_num, UINT8);
8906 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8907         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8908                                 rate, "rate");
8909 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8910         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8911                                 rate_num, UINT16);
8912 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8913         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8914                                 q_msk, "queue_mask");
8915 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8916         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8917                                 q_msk_val, UINT64);
8918
8919 cmdline_parse_inst_t cmd_vf_rate_limit = {
8920         .f = cmd_vf_rate_limit_parsed,
8921         .data = (void *)0,
8922         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8923                 "queue_mask <queue_mask_value>: "
8924                 "Set rate limit for queues of VF on port_id",
8925         .tokens = {
8926                 (void *)&cmd_vf_rate_limit_set,
8927                 (void *)&cmd_vf_rate_limit_port,
8928                 (void *)&cmd_vf_rate_limit_portnum,
8929                 (void *)&cmd_vf_rate_limit_vf,
8930                 (void *)&cmd_vf_rate_limit_vfnum,
8931                 (void *)&cmd_vf_rate_limit_rate,
8932                 (void *)&cmd_vf_rate_limit_ratenum,
8933                 (void *)&cmd_vf_rate_limit_q_msk,
8934                 (void *)&cmd_vf_rate_limit_q_msk_val,
8935                 NULL,
8936         },
8937 };
8938
8939 /* *** ADD TUNNEL FILTER OF A PORT *** */
8940 struct cmd_tunnel_filter_result {
8941         cmdline_fixed_string_t cmd;
8942         cmdline_fixed_string_t what;
8943         portid_t port_id;
8944         struct rte_ether_addr outer_mac;
8945         struct rte_ether_addr inner_mac;
8946         cmdline_ipaddr_t ip_value;
8947         uint16_t inner_vlan;
8948         cmdline_fixed_string_t tunnel_type;
8949         cmdline_fixed_string_t filter_type;
8950         uint32_t tenant_id;
8951         uint16_t queue_num;
8952 };
8953
8954 static void
8955 cmd_tunnel_filter_parsed(void *parsed_result,
8956                           __attribute__((unused)) struct cmdline *cl,
8957                           __attribute__((unused)) void *data)
8958 {
8959         struct cmd_tunnel_filter_result *res = parsed_result;
8960         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8961         int ret = 0;
8962
8963         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8964
8965         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8966         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8967         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8968
8969         if (res->ip_value.family == AF_INET) {
8970                 tunnel_filter_conf.ip_addr.ipv4_addr =
8971                         res->ip_value.addr.ipv4.s_addr;
8972                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8973         } else {
8974                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8975                         &(res->ip_value.addr.ipv6),
8976                         sizeof(struct in6_addr));
8977                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8978         }
8979
8980         if (!strcmp(res->filter_type, "imac-ivlan"))
8981                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8982         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8983                 tunnel_filter_conf.filter_type =
8984                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8985         else if (!strcmp(res->filter_type, "imac-tenid"))
8986                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8987         else if (!strcmp(res->filter_type, "imac"))
8988                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8989         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8990                 tunnel_filter_conf.filter_type =
8991                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8992         else if (!strcmp(res->filter_type, "oip"))
8993                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8994         else if (!strcmp(res->filter_type, "iip"))
8995                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8996         else {
8997                 printf("The filter type is not supported");
8998                 return;
8999         }
9000
9001         if (!strcmp(res->tunnel_type, "vxlan"))
9002                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9003         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9004                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9005         else if (!strcmp(res->tunnel_type, "nvgre"))
9006                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9007         else if (!strcmp(res->tunnel_type, "ipingre"))
9008                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9009         else {
9010                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9011                 return;
9012         }
9013
9014         tunnel_filter_conf.tenant_id = res->tenant_id;
9015         tunnel_filter_conf.queue_id = res->queue_num;
9016         if (!strcmp(res->what, "add"))
9017                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9018                                         RTE_ETH_FILTER_TUNNEL,
9019                                         RTE_ETH_FILTER_ADD,
9020                                         &tunnel_filter_conf);
9021         else
9022                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9023                                         RTE_ETH_FILTER_TUNNEL,
9024                                         RTE_ETH_FILTER_DELETE,
9025                                         &tunnel_filter_conf);
9026         if (ret < 0)
9027                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9028                                 strerror(-ret));
9029
9030 }
9031 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9032         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9033         cmd, "tunnel_filter");
9034 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9035         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9036         what, "add#rm");
9037 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9038         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9039         port_id, UINT16);
9040 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9041         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9042         outer_mac);
9043 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9044         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9045         inner_mac);
9046 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9047         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9048         inner_vlan, UINT16);
9049 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9050         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9051         ip_value);
9052 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9053         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9054         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9055
9056 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9057         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9058         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9059                 "imac#omac-imac-tenid");
9060 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9061         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9062         tenant_id, UINT32);
9063 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9064         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9065         queue_num, UINT16);
9066
9067 cmdline_parse_inst_t cmd_tunnel_filter = {
9068         .f = cmd_tunnel_filter_parsed,
9069         .data = (void *)0,
9070         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9071                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9072                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9073                 "<queue_id>: Add/Rm tunnel filter of a port",
9074         .tokens = {
9075                 (void *)&cmd_tunnel_filter_cmd,
9076                 (void *)&cmd_tunnel_filter_what,
9077                 (void *)&cmd_tunnel_filter_port_id,
9078                 (void *)&cmd_tunnel_filter_outer_mac,
9079                 (void *)&cmd_tunnel_filter_inner_mac,
9080                 (void *)&cmd_tunnel_filter_ip_value,
9081                 (void *)&cmd_tunnel_filter_innner_vlan,
9082                 (void *)&cmd_tunnel_filter_tunnel_type,
9083                 (void *)&cmd_tunnel_filter_filter_type,
9084                 (void *)&cmd_tunnel_filter_tenant_id,
9085                 (void *)&cmd_tunnel_filter_queue_num,
9086                 NULL,
9087         },
9088 };
9089
9090 /* *** CONFIGURE TUNNEL UDP PORT *** */
9091 struct cmd_tunnel_udp_config {
9092         cmdline_fixed_string_t cmd;
9093         cmdline_fixed_string_t what;
9094         uint16_t udp_port;
9095         portid_t port_id;
9096 };
9097
9098 static void
9099 cmd_tunnel_udp_config_parsed(void *parsed_result,
9100                           __attribute__((unused)) struct cmdline *cl,
9101                           __attribute__((unused)) void *data)
9102 {
9103         struct cmd_tunnel_udp_config *res = parsed_result;
9104         struct rte_eth_udp_tunnel tunnel_udp;
9105         int ret;
9106
9107         tunnel_udp.udp_port = res->udp_port;
9108
9109         if (!strcmp(res->cmd, "rx_vxlan_port"))
9110                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9111
9112         if (!strcmp(res->what, "add"))
9113                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9114                                                       &tunnel_udp);
9115         else
9116                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9117                                                          &tunnel_udp);
9118
9119         if (ret < 0)
9120                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9121 }
9122
9123 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9124         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9125                                 cmd, "rx_vxlan_port");
9126 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9127         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9128                                 what, "add#rm");
9129 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9130         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9131                                 udp_port, UINT16);
9132 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9133         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9134                                 port_id, UINT16);
9135
9136 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9137         .f = cmd_tunnel_udp_config_parsed,
9138         .data = (void *)0,
9139         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9140                 "Add/Remove a tunneling UDP port filter",
9141         .tokens = {
9142                 (void *)&cmd_tunnel_udp_config_cmd,
9143                 (void *)&cmd_tunnel_udp_config_what,
9144                 (void *)&cmd_tunnel_udp_config_udp_port,
9145                 (void *)&cmd_tunnel_udp_config_port_id,
9146                 NULL,
9147         },
9148 };
9149
9150 struct cmd_config_tunnel_udp_port {
9151         cmdline_fixed_string_t port;
9152         cmdline_fixed_string_t config;
9153         portid_t port_id;
9154         cmdline_fixed_string_t udp_tunnel_port;
9155         cmdline_fixed_string_t action;
9156         cmdline_fixed_string_t tunnel_type;
9157         uint16_t udp_port;
9158 };
9159
9160 static void
9161 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9162                                __attribute__((unused)) struct cmdline *cl,
9163                                __attribute__((unused)) void *data)
9164 {
9165         struct cmd_config_tunnel_udp_port *res = parsed_result;
9166         struct rte_eth_udp_tunnel tunnel_udp;
9167         int ret = 0;
9168
9169         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9170                 return;
9171
9172         tunnel_udp.udp_port = res->udp_port;
9173
9174         if (!strcmp(res->tunnel_type, "vxlan")) {
9175                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9176         } else if (!strcmp(res->tunnel_type, "geneve")) {
9177                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9178         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9179                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9180         } else {
9181                 printf("Invalid tunnel type\n");
9182                 return;
9183         }
9184
9185         if (!strcmp(res->action, "add"))
9186                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9187                                                       &tunnel_udp);
9188         else
9189                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9190                                                          &tunnel_udp);
9191
9192         if (ret < 0)
9193                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9194 }
9195
9196 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9197         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9198                                  "port");
9199 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9200         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9201                                  "config");
9202 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9203         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9204                               UINT16);
9205 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9206         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9207                                  udp_tunnel_port,
9208                                  "udp_tunnel_port");
9209 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9210         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9211                                  "add#rm");
9212 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9213         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9214                                  "vxlan#geneve#vxlan-gpe");
9215 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9216         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9217                               UINT16);
9218
9219 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9220         .f = cmd_cfg_tunnel_udp_port_parsed,
9221         .data = NULL,
9222         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9223         .tokens = {
9224                 (void *)&cmd_config_tunnel_udp_port_port,
9225                 (void *)&cmd_config_tunnel_udp_port_config,
9226                 (void *)&cmd_config_tunnel_udp_port_port_id,
9227                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9228                 (void *)&cmd_config_tunnel_udp_port_action,
9229                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9230                 (void *)&cmd_config_tunnel_udp_port_value,
9231                 NULL,
9232         },
9233 };
9234
9235 /* *** GLOBAL CONFIG *** */
9236 struct cmd_global_config_result {
9237         cmdline_fixed_string_t cmd;
9238         portid_t port_id;
9239         cmdline_fixed_string_t cfg_type;
9240         uint8_t len;
9241 };
9242
9243 static void
9244 cmd_global_config_parsed(void *parsed_result,
9245                          __attribute__((unused)) struct cmdline *cl,
9246                          __attribute__((unused)) void *data)
9247 {
9248         struct cmd_global_config_result *res = parsed_result;
9249         struct rte_eth_global_cfg conf;
9250         int ret;
9251
9252         memset(&conf, 0, sizeof(conf));
9253         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9254         conf.cfg.gre_key_len = res->len;
9255         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9256                                       RTE_ETH_FILTER_SET, &conf);
9257         if (ret != 0)
9258                 printf("Global config error\n");
9259 }
9260
9261 cmdline_parse_token_string_t cmd_global_config_cmd =
9262         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9263                 "global_config");
9264 cmdline_parse_token_num_t cmd_global_config_port_id =
9265         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9266                                UINT16);
9267 cmdline_parse_token_string_t cmd_global_config_type =
9268         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9269                 cfg_type, "gre-key-len");
9270 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9271         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9272                 len, UINT8);
9273
9274 cmdline_parse_inst_t cmd_global_config = {
9275         .f = cmd_global_config_parsed,
9276         .data = (void *)NULL,
9277         .help_str = "global_config <port_id> gre-key-len <key_len>",
9278         .tokens = {
9279                 (void *)&cmd_global_config_cmd,
9280                 (void *)&cmd_global_config_port_id,
9281                 (void *)&cmd_global_config_type,
9282                 (void *)&cmd_global_config_gre_key_len,
9283                 NULL,
9284         },
9285 };
9286
9287 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9288 struct cmd_set_mirror_mask_result {
9289         cmdline_fixed_string_t set;
9290         cmdline_fixed_string_t port;
9291         portid_t port_id;
9292         cmdline_fixed_string_t mirror;
9293         uint8_t rule_id;
9294         cmdline_fixed_string_t what;
9295         cmdline_fixed_string_t value;
9296         cmdline_fixed_string_t dstpool;
9297         uint8_t dstpool_id;
9298         cmdline_fixed_string_t on;
9299 };
9300
9301 cmdline_parse_token_string_t cmd_mirror_mask_set =
9302         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9303                                 set, "set");
9304 cmdline_parse_token_string_t cmd_mirror_mask_port =
9305         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9306                                 port, "port");
9307 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9308         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9309                                 port_id, UINT16);
9310 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9311         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9312                                 mirror, "mirror-rule");
9313 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9314         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9315                                 rule_id, UINT8);
9316 cmdline_parse_token_string_t cmd_mirror_mask_what =
9317         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9318                                 what, "pool-mirror-up#pool-mirror-down"
9319                                       "#vlan-mirror");
9320 cmdline_parse_token_string_t cmd_mirror_mask_value =
9321         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9322                                 value, NULL);
9323 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9324         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9325                                 dstpool, "dst-pool");
9326 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9327         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9328                                 dstpool_id, UINT8);
9329 cmdline_parse_token_string_t cmd_mirror_mask_on =
9330         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9331                                 on, "on#off");
9332
9333 static void
9334 cmd_set_mirror_mask_parsed(void *parsed_result,
9335                        __attribute__((unused)) struct cmdline *cl,
9336                        __attribute__((unused)) void *data)
9337 {
9338         int ret,nb_item,i;
9339         struct cmd_set_mirror_mask_result *res = parsed_result;
9340         struct rte_eth_mirror_conf mr_conf;
9341
9342         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9343
9344         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9345
9346         mr_conf.dst_pool = res->dstpool_id;
9347
9348         if (!strcmp(res->what, "pool-mirror-up")) {
9349                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9350                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9351         } else if (!strcmp(res->what, "pool-mirror-down")) {
9352                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9353                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9354         } else if (!strcmp(res->what, "vlan-mirror")) {
9355                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9356                 nb_item = parse_item_list(res->value, "vlan",
9357                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9358                 if (nb_item <= 0)
9359                         return;
9360
9361                 for (i = 0; i < nb_item; i++) {
9362                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9363                                 printf("Invalid vlan_id: must be < 4096\n");
9364                                 return;
9365                         }
9366
9367                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9368                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9369                 }
9370         }
9371
9372         if (!strcmp(res->on, "on"))
9373                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9374                                                 res->rule_id, 1);
9375         else
9376                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9377                                                 res->rule_id, 0);
9378         if (ret < 0)
9379                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9380 }
9381
9382 cmdline_parse_inst_t cmd_set_mirror_mask = {
9383                 .f = cmd_set_mirror_mask_parsed,
9384                 .data = NULL,
9385                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9386                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9387                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9388                 .tokens = {
9389                         (void *)&cmd_mirror_mask_set,
9390                         (void *)&cmd_mirror_mask_port,
9391                         (void *)&cmd_mirror_mask_portid,
9392                         (void *)&cmd_mirror_mask_mirror,
9393                         (void *)&cmd_mirror_mask_ruleid,
9394                         (void *)&cmd_mirror_mask_what,
9395                         (void *)&cmd_mirror_mask_value,
9396                         (void *)&cmd_mirror_mask_dstpool,
9397                         (void *)&cmd_mirror_mask_poolid,
9398                         (void *)&cmd_mirror_mask_on,
9399                         NULL,
9400                 },
9401 };
9402
9403 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9404 struct cmd_set_mirror_link_result {
9405         cmdline_fixed_string_t set;
9406         cmdline_fixed_string_t port;
9407         portid_t port_id;
9408         cmdline_fixed_string_t mirror;
9409         uint8_t rule_id;
9410         cmdline_fixed_string_t what;
9411         cmdline_fixed_string_t dstpool;
9412         uint8_t dstpool_id;
9413         cmdline_fixed_string_t on;
9414 };
9415
9416 cmdline_parse_token_string_t cmd_mirror_link_set =
9417         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9418                                  set, "set");
9419 cmdline_parse_token_string_t cmd_mirror_link_port =
9420         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9421                                 port, "port");
9422 cmdline_parse_token_num_t cmd_mirror_link_portid =
9423         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9424                                 port_id, UINT16);
9425 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9426         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9427                                 mirror, "mirror-rule");
9428 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9429         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9430                             rule_id, UINT8);
9431 cmdline_parse_token_string_t cmd_mirror_link_what =
9432         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9433                                 what, "uplink-mirror#downlink-mirror");
9434 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9435         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9436                                 dstpool, "dst-pool");
9437 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9438         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9439                                 dstpool_id, UINT8);
9440 cmdline_parse_token_string_t cmd_mirror_link_on =
9441         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9442                                 on, "on#off");
9443
9444 static void
9445 cmd_set_mirror_link_parsed(void *parsed_result,
9446                        __attribute__((unused)) struct cmdline *cl,
9447                        __attribute__((unused)) void *data)
9448 {
9449         int ret;
9450         struct cmd_set_mirror_link_result *res = parsed_result;
9451         struct rte_eth_mirror_conf mr_conf;
9452
9453         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9454         if (!strcmp(res->what, "uplink-mirror"))
9455                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9456         else
9457                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9458
9459         mr_conf.dst_pool = res->dstpool_id;
9460
9461         if (!strcmp(res->on, "on"))
9462                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9463                                                 res->rule_id, 1);
9464         else
9465                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9466                                                 res->rule_id, 0);
9467
9468         /* check the return value and print it if is < 0 */
9469         if (ret < 0)
9470                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9471
9472 }
9473
9474 cmdline_parse_inst_t cmd_set_mirror_link = {
9475                 .f = cmd_set_mirror_link_parsed,
9476                 .data = NULL,
9477                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9478                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9479                 .tokens = {
9480                         (void *)&cmd_mirror_link_set,
9481                         (void *)&cmd_mirror_link_port,
9482                         (void *)&cmd_mirror_link_portid,
9483                         (void *)&cmd_mirror_link_mirror,
9484                         (void *)&cmd_mirror_link_ruleid,
9485                         (void *)&cmd_mirror_link_what,
9486                         (void *)&cmd_mirror_link_dstpool,
9487                         (void *)&cmd_mirror_link_poolid,
9488                         (void *)&cmd_mirror_link_on,
9489                         NULL,
9490                 },
9491 };
9492
9493 /* *** RESET VM MIRROR RULE *** */
9494 struct cmd_rm_mirror_rule_result {
9495         cmdline_fixed_string_t reset;
9496         cmdline_fixed_string_t port;
9497         portid_t port_id;
9498         cmdline_fixed_string_t mirror;
9499         uint8_t rule_id;
9500 };
9501
9502 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9503         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9504                                  reset, "reset");
9505 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9506         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9507                                 port, "port");
9508 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9509         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9510                                 port_id, UINT16);
9511 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9512         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9513                                 mirror, "mirror-rule");
9514 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9515         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9516                                 rule_id, UINT8);
9517
9518 static void
9519 cmd_reset_mirror_rule_parsed(void *parsed_result,
9520                        __attribute__((unused)) struct cmdline *cl,
9521                        __attribute__((unused)) void *data)
9522 {
9523         int ret;
9524         struct cmd_set_mirror_link_result *res = parsed_result;
9525         /* check rule_id */
9526         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9527         if(ret < 0)
9528                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9529 }
9530
9531 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9532                 .f = cmd_reset_mirror_rule_parsed,
9533                 .data = NULL,
9534                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9535                 .tokens = {
9536                         (void *)&cmd_rm_mirror_rule_reset,
9537                         (void *)&cmd_rm_mirror_rule_port,
9538                         (void *)&cmd_rm_mirror_rule_portid,
9539                         (void *)&cmd_rm_mirror_rule_mirror,
9540                         (void *)&cmd_rm_mirror_rule_ruleid,
9541                         NULL,
9542                 },
9543 };
9544
9545 /* ******************************************************************************** */
9546
9547 struct cmd_dump_result {
9548         cmdline_fixed_string_t dump;
9549 };
9550
9551 static void
9552 dump_struct_sizes(void)
9553 {
9554 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9555         DUMP_SIZE(struct rte_mbuf);
9556         DUMP_SIZE(struct rte_mempool);
9557         DUMP_SIZE(struct rte_ring);
9558 #undef DUMP_SIZE
9559 }
9560
9561 static void cmd_dump_parsed(void *parsed_result,
9562                             __attribute__((unused)) struct cmdline *cl,
9563                             __attribute__((unused)) void *data)
9564 {
9565         struct cmd_dump_result *res = parsed_result;
9566
9567         if (!strcmp(res->dump, "dump_physmem"))
9568                 rte_dump_physmem_layout(stdout);
9569         else if (!strcmp(res->dump, "dump_memzone"))
9570                 rte_memzone_dump(stdout);
9571         else if (!strcmp(res->dump, "dump_struct_sizes"))
9572                 dump_struct_sizes();
9573         else if (!strcmp(res->dump, "dump_ring"))
9574                 rte_ring_list_dump(stdout);
9575         else if (!strcmp(res->dump, "dump_mempool"))
9576                 rte_mempool_list_dump(stdout);
9577         else if (!strcmp(res->dump, "dump_devargs"))
9578                 rte_devargs_dump(stdout);
9579         else if (!strcmp(res->dump, "dump_log_types"))
9580                 rte_log_dump(stdout);
9581 }
9582
9583 cmdline_parse_token_string_t cmd_dump_dump =
9584         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9585                 "dump_physmem#"
9586                 "dump_memzone#"
9587                 "dump_struct_sizes#"
9588                 "dump_ring#"
9589                 "dump_mempool#"
9590                 "dump_devargs#"
9591                 "dump_log_types");
9592
9593 cmdline_parse_inst_t cmd_dump = {
9594         .f = cmd_dump_parsed,  /* function to call */
9595         .data = NULL,      /* 2nd arg of func */
9596         .help_str = "Dump status",
9597         .tokens = {        /* token list, NULL terminated */
9598                 (void *)&cmd_dump_dump,
9599                 NULL,
9600         },
9601 };
9602
9603 /* ******************************************************************************** */
9604
9605 struct cmd_dump_one_result {
9606         cmdline_fixed_string_t dump;
9607         cmdline_fixed_string_t name;
9608 };
9609
9610 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9611                                 __attribute__((unused)) void *data)
9612 {
9613         struct cmd_dump_one_result *res = parsed_result;
9614
9615         if (!strcmp(res->dump, "dump_ring")) {
9616                 struct rte_ring *r;
9617                 r = rte_ring_lookup(res->name);
9618                 if (r == NULL) {
9619                         cmdline_printf(cl, "Cannot find ring\n");
9620                         return;
9621                 }
9622                 rte_ring_dump(stdout, r);
9623         } else if (!strcmp(res->dump, "dump_mempool")) {
9624                 struct rte_mempool *mp;
9625                 mp = rte_mempool_lookup(res->name);
9626                 if (mp == NULL) {
9627                         cmdline_printf(cl, "Cannot find mempool\n");
9628                         return;
9629                 }
9630                 rte_mempool_dump(stdout, mp);
9631         }
9632 }
9633
9634 cmdline_parse_token_string_t cmd_dump_one_dump =
9635         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9636                                  "dump_ring#dump_mempool");
9637
9638 cmdline_parse_token_string_t cmd_dump_one_name =
9639         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9640
9641 cmdline_parse_inst_t cmd_dump_one = {
9642         .f = cmd_dump_one_parsed,  /* function to call */
9643         .data = NULL,      /* 2nd arg of func */
9644         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9645         .tokens = {        /* token list, NULL terminated */
9646                 (void *)&cmd_dump_one_dump,
9647                 (void *)&cmd_dump_one_name,
9648                 NULL,
9649         },
9650 };
9651
9652 /* *** Add/Del syn filter *** */
9653 struct cmd_syn_filter_result {
9654         cmdline_fixed_string_t filter;
9655         portid_t port_id;
9656         cmdline_fixed_string_t ops;
9657         cmdline_fixed_string_t priority;
9658         cmdline_fixed_string_t high;
9659         cmdline_fixed_string_t queue;
9660         uint16_t queue_id;
9661 };
9662
9663 static void
9664 cmd_syn_filter_parsed(void *parsed_result,
9665                         __attribute__((unused)) struct cmdline *cl,
9666                         __attribute__((unused)) void *data)
9667 {
9668         struct cmd_syn_filter_result *res = parsed_result;
9669         struct rte_eth_syn_filter syn_filter;
9670         int ret = 0;
9671
9672         ret = rte_eth_dev_filter_supported(res->port_id,
9673                                         RTE_ETH_FILTER_SYN);
9674         if (ret < 0) {
9675                 printf("syn filter is not supported on port %u.\n",
9676                                 res->port_id);
9677                 return;
9678         }
9679
9680         memset(&syn_filter, 0, sizeof(syn_filter));
9681
9682         if (!strcmp(res->ops, "add")) {
9683                 if (!strcmp(res->high, "high"))
9684                         syn_filter.hig_pri = 1;
9685                 else
9686                         syn_filter.hig_pri = 0;
9687
9688                 syn_filter.queue = res->queue_id;
9689                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9690                                                 RTE_ETH_FILTER_SYN,
9691                                                 RTE_ETH_FILTER_ADD,
9692                                                 &syn_filter);
9693         } else
9694                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9695                                                 RTE_ETH_FILTER_SYN,
9696                                                 RTE_ETH_FILTER_DELETE,
9697                                                 &syn_filter);
9698
9699         if (ret < 0)
9700                 printf("syn filter programming error: (%s)\n",
9701                                 strerror(-ret));
9702 }
9703
9704 cmdline_parse_token_string_t cmd_syn_filter_filter =
9705         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9706         filter, "syn_filter");
9707 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9708         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9709         port_id, UINT16);
9710 cmdline_parse_token_string_t cmd_syn_filter_ops =
9711         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9712         ops, "add#del");
9713 cmdline_parse_token_string_t cmd_syn_filter_priority =
9714         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9715                                 priority, "priority");
9716 cmdline_parse_token_string_t cmd_syn_filter_high =
9717         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9718                                 high, "high#low");
9719 cmdline_parse_token_string_t cmd_syn_filter_queue =
9720         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9721                                 queue, "queue");
9722 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9723         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9724                                 queue_id, UINT16);
9725
9726 cmdline_parse_inst_t cmd_syn_filter = {
9727         .f = cmd_syn_filter_parsed,
9728         .data = NULL,
9729         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9730                 "<queue_id>: Add/Delete syn filter",
9731         .tokens = {
9732                 (void *)&cmd_syn_filter_filter,
9733                 (void *)&cmd_syn_filter_port_id,
9734                 (void *)&cmd_syn_filter_ops,
9735                 (void *)&cmd_syn_filter_priority,
9736                 (void *)&cmd_syn_filter_high,
9737                 (void *)&cmd_syn_filter_queue,
9738                 (void *)&cmd_syn_filter_queue_id,
9739                 NULL,
9740         },
9741 };
9742
9743 /* *** queue region set *** */
9744 struct cmd_queue_region_result {
9745         cmdline_fixed_string_t set;
9746         cmdline_fixed_string_t port;
9747         portid_t port_id;
9748         cmdline_fixed_string_t cmd;
9749         cmdline_fixed_string_t region;
9750         uint8_t  region_id;
9751         cmdline_fixed_string_t queue_start_index;
9752         uint8_t  queue_id;
9753         cmdline_fixed_string_t queue_num;
9754         uint8_t  queue_num_value;
9755 };
9756
9757 static void
9758 cmd_queue_region_parsed(void *parsed_result,
9759                         __attribute__((unused)) struct cmdline *cl,
9760                         __attribute__((unused)) void *data)
9761 {
9762         struct cmd_queue_region_result *res = parsed_result;
9763         int ret = -ENOTSUP;
9764 #ifdef RTE_LIBRTE_I40E_PMD
9765         struct rte_pmd_i40e_queue_region_conf region_conf;
9766         enum rte_pmd_i40e_queue_region_op op_type;
9767 #endif
9768
9769         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9770                 return;
9771
9772 #ifdef RTE_LIBRTE_I40E_PMD
9773         memset(&region_conf, 0, sizeof(region_conf));
9774         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9775         region_conf.region_id = res->region_id;
9776         region_conf.queue_num = res->queue_num_value;
9777         region_conf.queue_start_index = res->queue_id;
9778
9779         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9780                                 op_type, &region_conf);
9781 #endif
9782
9783         switch (ret) {
9784         case 0:
9785                 break;
9786         case -ENOTSUP:
9787                 printf("function not implemented or supported\n");
9788                 break;
9789         default:
9790                 printf("queue region config error: (%s)\n", strerror(-ret));
9791         }
9792 }
9793
9794 cmdline_parse_token_string_t cmd_queue_region_set =
9795 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9796                 set, "set");
9797 cmdline_parse_token_string_t cmd_queue_region_port =
9798         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9799 cmdline_parse_token_num_t cmd_queue_region_port_id =
9800         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9801                                 port_id, UINT16);
9802 cmdline_parse_token_string_t cmd_queue_region_cmd =
9803         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9804                                  cmd, "queue-region");
9805 cmdline_parse_token_string_t cmd_queue_region_id =
9806         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9807                                 region, "region_id");
9808 cmdline_parse_token_num_t cmd_queue_region_index =
9809         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9810                                 region_id, UINT8);
9811 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9812         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9813                                 queue_start_index, "queue_start_index");
9814 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9815         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9816                                 queue_id, UINT8);
9817 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9818         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9819                                 queue_num, "queue_num");
9820 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9821         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9822                                 queue_num_value, UINT8);
9823
9824 cmdline_parse_inst_t cmd_queue_region = {
9825         .f = cmd_queue_region_parsed,
9826         .data = NULL,
9827         .help_str = "set port <port_id> queue-region region_id <value> "
9828                 "queue_start_index <value> queue_num <value>: Set a queue region",
9829         .tokens = {
9830                 (void *)&cmd_queue_region_set,
9831                 (void *)&cmd_queue_region_port,
9832                 (void *)&cmd_queue_region_port_id,
9833                 (void *)&cmd_queue_region_cmd,
9834                 (void *)&cmd_queue_region_id,
9835                 (void *)&cmd_queue_region_index,
9836                 (void *)&cmd_queue_region_queue_start_index,
9837                 (void *)&cmd_queue_region_queue_id,
9838                 (void *)&cmd_queue_region_queue_num,
9839                 (void *)&cmd_queue_region_queue_num_value,
9840                 NULL,
9841         },
9842 };
9843
9844 /* *** queue region and flowtype set *** */
9845 struct cmd_region_flowtype_result {
9846         cmdline_fixed_string_t set;
9847         cmdline_fixed_string_t port;
9848         portid_t port_id;
9849         cmdline_fixed_string_t cmd;
9850         cmdline_fixed_string_t region;
9851         uint8_t  region_id;
9852         cmdline_fixed_string_t flowtype;
9853         uint8_t  flowtype_id;
9854 };
9855
9856 static void
9857 cmd_region_flowtype_parsed(void *parsed_result,
9858                         __attribute__((unused)) struct cmdline *cl,
9859                         __attribute__((unused)) void *data)
9860 {
9861         struct cmd_region_flowtype_result *res = parsed_result;
9862         int ret = -ENOTSUP;
9863 #ifdef RTE_LIBRTE_I40E_PMD
9864         struct rte_pmd_i40e_queue_region_conf region_conf;
9865         enum rte_pmd_i40e_queue_region_op op_type;
9866 #endif
9867
9868         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9869                 return;
9870
9871 #ifdef RTE_LIBRTE_I40E_PMD
9872         memset(&region_conf, 0, sizeof(region_conf));
9873
9874         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9875         region_conf.region_id = res->region_id;
9876         region_conf.hw_flowtype = res->flowtype_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("region flowtype config error: (%s)\n", strerror(-ret));
9890         }
9891 }
9892
9893 cmdline_parse_token_string_t cmd_region_flowtype_set =
9894 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9895                                 set, "set");
9896 cmdline_parse_token_string_t cmd_region_flowtype_port =
9897         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9898                                 port, "port");
9899 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9900         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9901                                 port_id, UINT16);
9902 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9903         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9904                                 cmd, "queue-region");
9905 cmdline_parse_token_string_t cmd_region_flowtype_index =
9906         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9907                                 region, "region_id");
9908 cmdline_parse_token_num_t cmd_region_flowtype_id =
9909         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9910                                 region_id, UINT8);
9911 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9912         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9913                                 flowtype, "flowtype");
9914 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9915         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9916                                 flowtype_id, UINT8);
9917 cmdline_parse_inst_t cmd_region_flowtype = {
9918         .f = cmd_region_flowtype_parsed,
9919         .data = NULL,
9920         .help_str = "set port <port_id> queue-region region_id <value> "
9921                 "flowtype <value>: Set a flowtype region index",
9922         .tokens = {
9923                 (void *)&cmd_region_flowtype_set,
9924                 (void *)&cmd_region_flowtype_port,
9925                 (void *)&cmd_region_flowtype_port_index,
9926                 (void *)&cmd_region_flowtype_cmd,
9927                 (void *)&cmd_region_flowtype_index,
9928                 (void *)&cmd_region_flowtype_id,
9929                 (void *)&cmd_region_flowtype_flow_index,
9930                 (void *)&cmd_region_flowtype_flow_id,
9931                 NULL,
9932         },
9933 };
9934
9935 /* *** User Priority (UP) to queue region (region_id) set *** */
9936 struct cmd_user_priority_region_result {
9937         cmdline_fixed_string_t set;
9938         cmdline_fixed_string_t port;
9939         portid_t port_id;
9940         cmdline_fixed_string_t cmd;
9941         cmdline_fixed_string_t user_priority;
9942         uint8_t  user_priority_id;
9943         cmdline_fixed_string_t region;
9944         uint8_t  region_id;
9945 };
9946
9947 static void
9948 cmd_user_priority_region_parsed(void *parsed_result,
9949                         __attribute__((unused)) struct cmdline *cl,
9950                         __attribute__((unused)) void *data)
9951 {
9952         struct cmd_user_priority_region_result *res = parsed_result;
9953         int ret = -ENOTSUP;
9954 #ifdef RTE_LIBRTE_I40E_PMD
9955         struct rte_pmd_i40e_queue_region_conf region_conf;
9956         enum rte_pmd_i40e_queue_region_op op_type;
9957 #endif
9958
9959         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9960                 return;
9961
9962 #ifdef RTE_LIBRTE_I40E_PMD
9963         memset(&region_conf, 0, sizeof(region_conf));
9964         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9965         region_conf.user_priority = res->user_priority_id;
9966         region_conf.region_id = res->region_id;
9967
9968         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9969                                 op_type, &region_conf);
9970 #endif
9971
9972         switch (ret) {
9973         case 0:
9974                 break;
9975         case -ENOTSUP:
9976                 printf("function not implemented or supported\n");
9977                 break;
9978         default:
9979                 printf("user_priority region config error: (%s)\n",
9980                                 strerror(-ret));
9981         }
9982 }
9983
9984 cmdline_parse_token_string_t cmd_user_priority_region_set =
9985         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9986                                 set, "set");
9987 cmdline_parse_token_string_t cmd_user_priority_region_port =
9988         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9989                                 port, "port");
9990 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9991         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9992                                 port_id, UINT16);
9993 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9994         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9995                                 cmd, "queue-region");
9996 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9997         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9998                                 user_priority, "UP");
9999 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10000         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10001                                 user_priority_id, UINT8);
10002 cmdline_parse_token_string_t cmd_user_priority_region_region =
10003         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10004                                 region, "region_id");
10005 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10006         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10007                                 region_id, UINT8);
10008
10009 cmdline_parse_inst_t cmd_user_priority_region = {
10010         .f = cmd_user_priority_region_parsed,
10011         .data = NULL,
10012         .help_str = "set port <port_id> queue-region UP <value> "
10013                 "region_id <value>: Set the mapping of User Priority (UP) "
10014                 "to queue region (region_id) ",
10015         .tokens = {
10016                 (void *)&cmd_user_priority_region_set,
10017                 (void *)&cmd_user_priority_region_port,
10018                 (void *)&cmd_user_priority_region_port_index,
10019                 (void *)&cmd_user_priority_region_cmd,
10020                 (void *)&cmd_user_priority_region_UP,
10021                 (void *)&cmd_user_priority_region_UP_id,
10022                 (void *)&cmd_user_priority_region_region,
10023                 (void *)&cmd_user_priority_region_region_id,
10024                 NULL,
10025         },
10026 };
10027
10028 /* *** flush all queue region related configuration *** */
10029 struct cmd_flush_queue_region_result {
10030         cmdline_fixed_string_t set;
10031         cmdline_fixed_string_t port;
10032         portid_t port_id;
10033         cmdline_fixed_string_t cmd;
10034         cmdline_fixed_string_t flush;
10035         cmdline_fixed_string_t what;
10036 };
10037
10038 static void
10039 cmd_flush_queue_region_parsed(void *parsed_result,
10040                         __attribute__((unused)) struct cmdline *cl,
10041                         __attribute__((unused)) void *data)
10042 {
10043         struct cmd_flush_queue_region_result *res = parsed_result;
10044         int ret = -ENOTSUP;
10045 #ifdef RTE_LIBRTE_I40E_PMD
10046         struct rte_pmd_i40e_queue_region_conf region_conf;
10047         enum rte_pmd_i40e_queue_region_op op_type;
10048 #endif
10049
10050         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10051                 return;
10052
10053 #ifdef RTE_LIBRTE_I40E_PMD
10054         memset(&region_conf, 0, sizeof(region_conf));
10055
10056         if (strcmp(res->what, "on") == 0)
10057                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10058         else
10059                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10060
10061         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10062                                 op_type, &region_conf);
10063 #endif
10064
10065         switch (ret) {
10066         case 0:
10067                 break;
10068         case -ENOTSUP:
10069                 printf("function not implemented or supported\n");
10070                 break;
10071         default:
10072                 printf("queue region config flush error: (%s)\n",
10073                                 strerror(-ret));
10074         }
10075 }
10076
10077 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10078         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10079                                 set, "set");
10080 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10081         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10082                                 port, "port");
10083 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10084         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10085                                 port_id, UINT16);
10086 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10087         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10088                                 cmd, "queue-region");
10089 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10090         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10091                                 flush, "flush");
10092 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10093         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10094                                 what, "on#off");
10095
10096 cmdline_parse_inst_t cmd_flush_queue_region = {
10097         .f = cmd_flush_queue_region_parsed,
10098         .data = NULL,
10099         .help_str = "set port <port_id> queue-region flush on|off"
10100                 ": flush all queue region related configuration",
10101         .tokens = {
10102                 (void *)&cmd_flush_queue_region_set,
10103                 (void *)&cmd_flush_queue_region_port,
10104                 (void *)&cmd_flush_queue_region_port_index,
10105                 (void *)&cmd_flush_queue_region_cmd,
10106                 (void *)&cmd_flush_queue_region_flush,
10107                 (void *)&cmd_flush_queue_region_what,
10108                 NULL,
10109         },
10110 };
10111
10112 /* *** get all queue region related configuration info *** */
10113 struct cmd_show_queue_region_info {
10114         cmdline_fixed_string_t show;
10115         cmdline_fixed_string_t port;
10116         portid_t port_id;
10117         cmdline_fixed_string_t cmd;
10118 };
10119
10120 static void
10121 cmd_show_queue_region_info_parsed(void *parsed_result,
10122                         __attribute__((unused)) struct cmdline *cl,
10123                         __attribute__((unused)) void *data)
10124 {
10125         struct cmd_show_queue_region_info *res = parsed_result;
10126         int ret = -ENOTSUP;
10127 #ifdef RTE_LIBRTE_I40E_PMD
10128         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10129         enum rte_pmd_i40e_queue_region_op op_type;
10130 #endif
10131
10132         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10133                 return;
10134
10135 #ifdef RTE_LIBRTE_I40E_PMD
10136         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10137
10138         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10139
10140         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10141                                         op_type, &rte_pmd_regions);
10142
10143         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10144 #endif
10145
10146         switch (ret) {
10147         case 0:
10148                 break;
10149         case -ENOTSUP:
10150                 printf("function not implemented or supported\n");
10151                 break;
10152         default:
10153                 printf("queue region config info show error: (%s)\n",
10154                                 strerror(-ret));
10155         }
10156 }
10157
10158 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10159 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10160                                 show, "show");
10161 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10162         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10163                                 port, "port");
10164 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10165         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10166                                 port_id, UINT16);
10167 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10168         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10169                                 cmd, "queue-region");
10170
10171 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10172         .f = cmd_show_queue_region_info_parsed,
10173         .data = NULL,
10174         .help_str = "show port <port_id> queue-region"
10175                 ": show all queue region related configuration info",
10176         .tokens = {
10177                 (void *)&cmd_show_queue_region_info_get,
10178                 (void *)&cmd_show_queue_region_info_port,
10179                 (void *)&cmd_show_queue_region_info_port_index,
10180                 (void *)&cmd_show_queue_region_info_cmd,
10181                 NULL,
10182         },
10183 };
10184
10185 /* *** ADD/REMOVE A 2tuple FILTER *** */
10186 struct cmd_2tuple_filter_result {
10187         cmdline_fixed_string_t filter;
10188         portid_t port_id;
10189         cmdline_fixed_string_t ops;
10190         cmdline_fixed_string_t dst_port;
10191         uint16_t dst_port_value;
10192         cmdline_fixed_string_t protocol;
10193         uint8_t protocol_value;
10194         cmdline_fixed_string_t mask;
10195         uint8_t  mask_value;
10196         cmdline_fixed_string_t tcp_flags;
10197         uint8_t tcp_flags_value;
10198         cmdline_fixed_string_t priority;
10199         uint8_t  priority_value;
10200         cmdline_fixed_string_t queue;
10201         uint16_t  queue_id;
10202 };
10203
10204 static void
10205 cmd_2tuple_filter_parsed(void *parsed_result,
10206                         __attribute__((unused)) struct cmdline *cl,
10207                         __attribute__((unused)) void *data)
10208 {
10209         struct rte_eth_ntuple_filter filter;
10210         struct cmd_2tuple_filter_result *res = parsed_result;
10211         int ret = 0;
10212
10213         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10214         if (ret < 0) {
10215                 printf("ntuple filter is not supported on port %u.\n",
10216                         res->port_id);
10217                 return;
10218         }
10219
10220         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10221
10222         filter.flags = RTE_2TUPLE_FLAGS;
10223         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10224         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10225         filter.proto = res->protocol_value;
10226         filter.priority = res->priority_value;
10227         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10228                 printf("nonzero tcp_flags is only meaningful"
10229                         " when protocol is TCP.\n");
10230                 return;
10231         }
10232         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10233                 printf("invalid TCP flags.\n");
10234                 return;
10235         }
10236
10237         if (res->tcp_flags_value != 0) {
10238                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10239                 filter.tcp_flags = res->tcp_flags_value;
10240         }
10241
10242         /* need convert to big endian. */
10243         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10244         filter.queue = res->queue_id;
10245
10246         if (!strcmp(res->ops, "add"))
10247                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10248                                 RTE_ETH_FILTER_NTUPLE,
10249                                 RTE_ETH_FILTER_ADD,
10250                                 &filter);
10251         else
10252                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10253                                 RTE_ETH_FILTER_NTUPLE,
10254                                 RTE_ETH_FILTER_DELETE,
10255                                 &filter);
10256         if (ret < 0)
10257                 printf("2tuple filter programming error: (%s)\n",
10258                         strerror(-ret));
10259
10260 }
10261
10262 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10263         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10264                                  filter, "2tuple_filter");
10265 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10266         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10267                                 port_id, UINT16);
10268 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10269         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10270                                  ops, "add#del");
10271 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10272         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10273                                 dst_port, "dst_port");
10274 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10275         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10276                                 dst_port_value, UINT16);
10277 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10278         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10279                                 protocol, "protocol");
10280 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10281         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10282                                 protocol_value, UINT8);
10283 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10284         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10285                                 mask, "mask");
10286 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10287         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10288                                 mask_value, INT8);
10289 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10290         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10291                                 tcp_flags, "tcp_flags");
10292 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10293         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10294                                 tcp_flags_value, UINT8);
10295 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10296         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10297                                 priority, "priority");
10298 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10299         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10300                                 priority_value, UINT8);
10301 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10302         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10303                                 queue, "queue");
10304 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10305         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10306                                 queue_id, UINT16);
10307
10308 cmdline_parse_inst_t cmd_2tuple_filter = {
10309         .f = cmd_2tuple_filter_parsed,
10310         .data = NULL,
10311         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10312                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10313                 "<queue_id>: Add a 2tuple filter",
10314         .tokens = {
10315                 (void *)&cmd_2tuple_filter_filter,
10316                 (void *)&cmd_2tuple_filter_port_id,
10317                 (void *)&cmd_2tuple_filter_ops,
10318                 (void *)&cmd_2tuple_filter_dst_port,
10319                 (void *)&cmd_2tuple_filter_dst_port_value,
10320                 (void *)&cmd_2tuple_filter_protocol,
10321                 (void *)&cmd_2tuple_filter_protocol_value,
10322                 (void *)&cmd_2tuple_filter_mask,
10323                 (void *)&cmd_2tuple_filter_mask_value,
10324                 (void *)&cmd_2tuple_filter_tcp_flags,
10325                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10326                 (void *)&cmd_2tuple_filter_priority,
10327                 (void *)&cmd_2tuple_filter_priority_value,
10328                 (void *)&cmd_2tuple_filter_queue,
10329                 (void *)&cmd_2tuple_filter_queue_id,
10330                 NULL,
10331         },
10332 };
10333
10334 /* *** ADD/REMOVE A 5tuple FILTER *** */
10335 struct cmd_5tuple_filter_result {
10336         cmdline_fixed_string_t filter;
10337         portid_t port_id;
10338         cmdline_fixed_string_t ops;
10339         cmdline_fixed_string_t dst_ip;
10340         cmdline_ipaddr_t dst_ip_value;
10341         cmdline_fixed_string_t src_ip;
10342         cmdline_ipaddr_t src_ip_value;
10343         cmdline_fixed_string_t dst_port;
10344         uint16_t dst_port_value;
10345         cmdline_fixed_string_t src_port;
10346         uint16_t src_port_value;
10347         cmdline_fixed_string_t protocol;
10348         uint8_t protocol_value;
10349         cmdline_fixed_string_t mask;
10350         uint8_t  mask_value;
10351         cmdline_fixed_string_t tcp_flags;
10352         uint8_t tcp_flags_value;
10353         cmdline_fixed_string_t priority;
10354         uint8_t  priority_value;
10355         cmdline_fixed_string_t queue;
10356         uint16_t  queue_id;
10357 };
10358
10359 static void
10360 cmd_5tuple_filter_parsed(void *parsed_result,
10361                         __attribute__((unused)) struct cmdline *cl,
10362                         __attribute__((unused)) void *data)
10363 {
10364         struct rte_eth_ntuple_filter filter;
10365         struct cmd_5tuple_filter_result *res = parsed_result;
10366         int ret = 0;
10367
10368         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10369         if (ret < 0) {
10370                 printf("ntuple filter is not supported on port %u.\n",
10371                         res->port_id);
10372                 return;
10373         }
10374
10375         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10376
10377         filter.flags = RTE_5TUPLE_FLAGS;
10378         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10379         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10380         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10381         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10382         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10383         filter.proto = res->protocol_value;
10384         filter.priority = res->priority_value;
10385         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10386                 printf("nonzero tcp_flags is only meaningful"
10387                         " when protocol is TCP.\n");
10388                 return;
10389         }
10390         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10391                 printf("invalid TCP flags.\n");
10392                 return;
10393         }
10394
10395         if (res->tcp_flags_value != 0) {
10396                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10397                 filter.tcp_flags = res->tcp_flags_value;
10398         }
10399
10400         if (res->dst_ip_value.family == AF_INET)
10401                 /* no need to convert, already big endian. */
10402                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10403         else {
10404                 if (filter.dst_ip_mask == 0) {
10405                         printf("can not support ipv6 involved compare.\n");
10406                         return;
10407                 }
10408                 filter.dst_ip = 0;
10409         }
10410
10411         if (res->src_ip_value.family == AF_INET)
10412                 /* no need to convert, already big endian. */
10413                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10414         else {
10415                 if (filter.src_ip_mask == 0) {
10416                         printf("can not support ipv6 involved compare.\n");
10417                         return;
10418                 }
10419                 filter.src_ip = 0;
10420         }
10421         /* need convert to big endian. */
10422         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10423         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10424         filter.queue = res->queue_id;
10425
10426         if (!strcmp(res->ops, "add"))
10427                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10428                                 RTE_ETH_FILTER_NTUPLE,
10429                                 RTE_ETH_FILTER_ADD,
10430                                 &filter);
10431         else
10432                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10433                                 RTE_ETH_FILTER_NTUPLE,
10434                                 RTE_ETH_FILTER_DELETE,
10435                                 &filter);
10436         if (ret < 0)
10437                 printf("5tuple filter programming error: (%s)\n",
10438                         strerror(-ret));
10439 }
10440
10441 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10442         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10443                                  filter, "5tuple_filter");
10444 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10445         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10446                                 port_id, UINT16);
10447 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10448         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10449                                  ops, "add#del");
10450 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10451         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10452                                 dst_ip, "dst_ip");
10453 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10454         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10455                                 dst_ip_value);
10456 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10457         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10458                                 src_ip, "src_ip");
10459 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10460         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10461                                 src_ip_value);
10462 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10463         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10464                                 dst_port, "dst_port");
10465 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10466         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10467                                 dst_port_value, UINT16);
10468 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10469         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10470                                 src_port, "src_port");
10471 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10472         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10473                                 src_port_value, UINT16);
10474 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10475         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10476                                 protocol, "protocol");
10477 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10478         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10479                                 protocol_value, UINT8);
10480 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10481         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10482                                 mask, "mask");
10483 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10484         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10485                                 mask_value, INT8);
10486 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10487         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10488                                 tcp_flags, "tcp_flags");
10489 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10490         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10491                                 tcp_flags_value, UINT8);
10492 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10493         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10494                                 priority, "priority");
10495 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10496         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10497                                 priority_value, UINT8);
10498 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10499         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10500                                 queue, "queue");
10501 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10502         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10503                                 queue_id, UINT16);
10504
10505 cmdline_parse_inst_t cmd_5tuple_filter = {
10506         .f = cmd_5tuple_filter_parsed,
10507         .data = NULL,
10508         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10509                 "src_ip <value> dst_port <value> src_port <value> "
10510                 "protocol <value>  mask <value> tcp_flags <value> "
10511                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10512         .tokens = {
10513                 (void *)&cmd_5tuple_filter_filter,
10514                 (void *)&cmd_5tuple_filter_port_id,
10515                 (void *)&cmd_5tuple_filter_ops,
10516                 (void *)&cmd_5tuple_filter_dst_ip,
10517                 (void *)&cmd_5tuple_filter_dst_ip_value,
10518                 (void *)&cmd_5tuple_filter_src_ip,
10519                 (void *)&cmd_5tuple_filter_src_ip_value,
10520                 (void *)&cmd_5tuple_filter_dst_port,
10521                 (void *)&cmd_5tuple_filter_dst_port_value,
10522                 (void *)&cmd_5tuple_filter_src_port,
10523                 (void *)&cmd_5tuple_filter_src_port_value,
10524                 (void *)&cmd_5tuple_filter_protocol,
10525                 (void *)&cmd_5tuple_filter_protocol_value,
10526                 (void *)&cmd_5tuple_filter_mask,
10527                 (void *)&cmd_5tuple_filter_mask_value,
10528                 (void *)&cmd_5tuple_filter_tcp_flags,
10529                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10530                 (void *)&cmd_5tuple_filter_priority,
10531                 (void *)&cmd_5tuple_filter_priority_value,
10532                 (void *)&cmd_5tuple_filter_queue,
10533                 (void *)&cmd_5tuple_filter_queue_id,
10534                 NULL,
10535         },
10536 };
10537
10538 /* *** ADD/REMOVE A flex FILTER *** */
10539 struct cmd_flex_filter_result {
10540         cmdline_fixed_string_t filter;
10541         cmdline_fixed_string_t ops;
10542         portid_t port_id;
10543         cmdline_fixed_string_t len;
10544         uint8_t len_value;
10545         cmdline_fixed_string_t bytes;
10546         cmdline_fixed_string_t bytes_value;
10547         cmdline_fixed_string_t mask;
10548         cmdline_fixed_string_t mask_value;
10549         cmdline_fixed_string_t priority;
10550         uint8_t priority_value;
10551         cmdline_fixed_string_t queue;
10552         uint16_t queue_id;
10553 };
10554
10555 static int xdigit2val(unsigned char c)
10556 {
10557         int val;
10558         if (isdigit(c))
10559                 val = c - '0';
10560         else if (isupper(c))
10561                 val = c - 'A' + 10;
10562         else
10563                 val = c - 'a' + 10;
10564         return val;
10565 }
10566
10567 static void
10568 cmd_flex_filter_parsed(void *parsed_result,
10569                           __attribute__((unused)) struct cmdline *cl,
10570                           __attribute__((unused)) void *data)
10571 {
10572         int ret = 0;
10573         struct rte_eth_flex_filter filter;
10574         struct cmd_flex_filter_result *res = parsed_result;
10575         char *bytes_ptr, *mask_ptr;
10576         uint16_t len, i, j = 0;
10577         char c;
10578         int val;
10579         uint8_t byte = 0;
10580
10581         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10582                 printf("the len exceed the max length 128\n");
10583                 return;
10584         }
10585         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10586         filter.len = res->len_value;
10587         filter.priority = res->priority_value;
10588         filter.queue = res->queue_id;
10589         bytes_ptr = res->bytes_value;
10590         mask_ptr = res->mask_value;
10591
10592          /* translate bytes string to array. */
10593         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10594                 (bytes_ptr[1] == 'X')))
10595                 bytes_ptr += 2;
10596         len = strnlen(bytes_ptr, res->len_value * 2);
10597         if (len == 0 || (len % 8 != 0)) {
10598                 printf("please check len and bytes input\n");
10599                 return;
10600         }
10601         for (i = 0; i < len; i++) {
10602                 c = bytes_ptr[i];
10603                 if (isxdigit(c) == 0) {
10604                         /* invalid characters. */
10605                         printf("invalid input\n");
10606                         return;
10607                 }
10608                 val = xdigit2val(c);
10609                 if (i % 2) {
10610                         byte |= val;
10611                         filter.bytes[j] = byte;
10612                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10613                         j++;
10614                         byte = 0;
10615                 } else
10616                         byte |= val << 4;
10617         }
10618         printf("\n");
10619          /* translate mask string to uint8_t array. */
10620         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10621                 (mask_ptr[1] == 'X')))
10622                 mask_ptr += 2;
10623         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10624         if (len == 0) {
10625                 printf("invalid input\n");
10626                 return;
10627         }
10628         j = 0;
10629         byte = 0;
10630         for (i = 0; i < len; i++) {
10631                 c = mask_ptr[i];
10632                 if (isxdigit(c) == 0) {
10633                         /* invalid characters. */
10634                         printf("invalid input\n");
10635                         return;
10636                 }
10637                 val = xdigit2val(c);
10638                 if (i % 2) {
10639                         byte |= val;
10640                         filter.mask[j] = byte;
10641                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10642                         j++;
10643                         byte = 0;
10644                 } else
10645                         byte |= val << 4;
10646         }
10647         printf("\n");
10648
10649         if (!strcmp(res->ops, "add"))
10650                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10651                                 RTE_ETH_FILTER_FLEXIBLE,
10652                                 RTE_ETH_FILTER_ADD,
10653                                 &filter);
10654         else
10655                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10656                                 RTE_ETH_FILTER_FLEXIBLE,
10657                                 RTE_ETH_FILTER_DELETE,
10658                                 &filter);
10659
10660         if (ret < 0)
10661                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10662 }
10663
10664 cmdline_parse_token_string_t cmd_flex_filter_filter =
10665         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10666                                 filter, "flex_filter");
10667 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10668         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10669                                 port_id, UINT16);
10670 cmdline_parse_token_string_t cmd_flex_filter_ops =
10671         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10672                                 ops, "add#del");
10673 cmdline_parse_token_string_t cmd_flex_filter_len =
10674         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10675                                 len, "len");
10676 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10677         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10678                                 len_value, UINT8);
10679 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10680         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10681                                 bytes, "bytes");
10682 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10683         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10684                                 bytes_value, NULL);
10685 cmdline_parse_token_string_t cmd_flex_filter_mask =
10686         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10687                                 mask, "mask");
10688 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10689         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10690                                 mask_value, NULL);
10691 cmdline_parse_token_string_t cmd_flex_filter_priority =
10692         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10693                                 priority, "priority");
10694 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10695         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10696                                 priority_value, UINT8);
10697 cmdline_parse_token_string_t cmd_flex_filter_queue =
10698         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10699                                 queue, "queue");
10700 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10701         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10702                                 queue_id, UINT16);
10703 cmdline_parse_inst_t cmd_flex_filter = {
10704         .f = cmd_flex_filter_parsed,
10705         .data = NULL,
10706         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10707                 "<value> mask <value> priority <value> queue <queue_id>: "
10708                 "Add/Del a flex filter",
10709         .tokens = {
10710                 (void *)&cmd_flex_filter_filter,
10711                 (void *)&cmd_flex_filter_port_id,
10712                 (void *)&cmd_flex_filter_ops,
10713                 (void *)&cmd_flex_filter_len,
10714                 (void *)&cmd_flex_filter_len_value,
10715                 (void *)&cmd_flex_filter_bytes,
10716                 (void *)&cmd_flex_filter_bytes_value,
10717                 (void *)&cmd_flex_filter_mask,
10718                 (void *)&cmd_flex_filter_mask_value,
10719                 (void *)&cmd_flex_filter_priority,
10720                 (void *)&cmd_flex_filter_priority_value,
10721                 (void *)&cmd_flex_filter_queue,
10722                 (void *)&cmd_flex_filter_queue_id,
10723                 NULL,
10724         },
10725 };
10726
10727 /* *** Filters Control *** */
10728
10729 /* *** deal with ethertype filter *** */
10730 struct cmd_ethertype_filter_result {
10731         cmdline_fixed_string_t filter;
10732         portid_t port_id;
10733         cmdline_fixed_string_t ops;
10734         cmdline_fixed_string_t mac;
10735         struct rte_ether_addr mac_addr;
10736         cmdline_fixed_string_t ethertype;
10737         uint16_t ethertype_value;
10738         cmdline_fixed_string_t drop;
10739         cmdline_fixed_string_t queue;
10740         uint16_t  queue_id;
10741 };
10742
10743 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10744         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10745                                  filter, "ethertype_filter");
10746 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10747         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10748                               port_id, UINT16);
10749 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10750         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10751                                  ops, "add#del");
10752 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10753         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10754                                  mac, "mac_addr#mac_ignr");
10755 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10756         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10757                                      mac_addr);
10758 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10759         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10760                                  ethertype, "ethertype");
10761 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10762         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10763                               ethertype_value, UINT16);
10764 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10765         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10766                                  drop, "drop#fwd");
10767 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10768         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10769                                  queue, "queue");
10770 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10771         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10772                               queue_id, UINT16);
10773
10774 static void
10775 cmd_ethertype_filter_parsed(void *parsed_result,
10776                           __attribute__((unused)) struct cmdline *cl,
10777                           __attribute__((unused)) void *data)
10778 {
10779         struct cmd_ethertype_filter_result *res = parsed_result;
10780         struct rte_eth_ethertype_filter filter;
10781         int ret = 0;
10782
10783         ret = rte_eth_dev_filter_supported(res->port_id,
10784                         RTE_ETH_FILTER_ETHERTYPE);
10785         if (ret < 0) {
10786                 printf("ethertype filter is not supported on port %u.\n",
10787                         res->port_id);
10788                 return;
10789         }
10790
10791         memset(&filter, 0, sizeof(filter));
10792         if (!strcmp(res->mac, "mac_addr")) {
10793                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10794                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10795                         sizeof(struct rte_ether_addr));
10796         }
10797         if (!strcmp(res->drop, "drop"))
10798                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10799         filter.ether_type = res->ethertype_value;
10800         filter.queue = res->queue_id;
10801
10802         if (!strcmp(res->ops, "add"))
10803                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10804                                 RTE_ETH_FILTER_ETHERTYPE,
10805                                 RTE_ETH_FILTER_ADD,
10806                                 &filter);
10807         else
10808                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10809                                 RTE_ETH_FILTER_ETHERTYPE,
10810                                 RTE_ETH_FILTER_DELETE,
10811                                 &filter);
10812         if (ret < 0)
10813                 printf("ethertype filter programming error: (%s)\n",
10814                         strerror(-ret));
10815 }
10816
10817 cmdline_parse_inst_t cmd_ethertype_filter = {
10818         .f = cmd_ethertype_filter_parsed,
10819         .data = NULL,
10820         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10821                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10822                 "Add or delete an ethertype filter entry",
10823         .tokens = {
10824                 (void *)&cmd_ethertype_filter_filter,
10825                 (void *)&cmd_ethertype_filter_port_id,
10826                 (void *)&cmd_ethertype_filter_ops,
10827                 (void *)&cmd_ethertype_filter_mac,
10828                 (void *)&cmd_ethertype_filter_mac_addr,
10829                 (void *)&cmd_ethertype_filter_ethertype,
10830                 (void *)&cmd_ethertype_filter_ethertype_value,
10831                 (void *)&cmd_ethertype_filter_drop,
10832                 (void *)&cmd_ethertype_filter_queue,
10833                 (void *)&cmd_ethertype_filter_queue_id,
10834                 NULL,
10835         },
10836 };
10837
10838 /* *** deal with flow director filter *** */
10839 struct cmd_flow_director_result {
10840         cmdline_fixed_string_t flow_director_filter;
10841         portid_t port_id;
10842         cmdline_fixed_string_t mode;
10843         cmdline_fixed_string_t mode_value;
10844         cmdline_fixed_string_t ops;
10845         cmdline_fixed_string_t flow;
10846         cmdline_fixed_string_t flow_type;
10847         cmdline_fixed_string_t ether;
10848         uint16_t ether_type;
10849         cmdline_fixed_string_t src;
10850         cmdline_ipaddr_t ip_src;
10851         uint16_t port_src;
10852         cmdline_fixed_string_t dst;
10853         cmdline_ipaddr_t ip_dst;
10854         uint16_t port_dst;
10855         cmdline_fixed_string_t verify_tag;
10856         uint32_t verify_tag_value;
10857         cmdline_fixed_string_t tos;
10858         uint8_t tos_value;
10859         cmdline_fixed_string_t proto;
10860         uint8_t proto_value;
10861         cmdline_fixed_string_t ttl;
10862         uint8_t ttl_value;
10863         cmdline_fixed_string_t vlan;
10864         uint16_t vlan_value;
10865         cmdline_fixed_string_t flexbytes;
10866         cmdline_fixed_string_t flexbytes_value;
10867         cmdline_fixed_string_t pf_vf;
10868         cmdline_fixed_string_t drop;
10869         cmdline_fixed_string_t queue;
10870         uint16_t  queue_id;
10871         cmdline_fixed_string_t fd_id;
10872         uint32_t  fd_id_value;
10873         cmdline_fixed_string_t mac;
10874         struct rte_ether_addr mac_addr;
10875         cmdline_fixed_string_t tunnel;
10876         cmdline_fixed_string_t tunnel_type;
10877         cmdline_fixed_string_t tunnel_id;
10878         uint32_t tunnel_id_value;
10879         cmdline_fixed_string_t packet;
10880         char filepath[];
10881 };
10882
10883 static inline int
10884 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10885 {
10886         char s[256];
10887         const char *p, *p0 = q_arg;
10888         char *end;
10889         unsigned long int_fld;
10890         char *str_fld[max_num];
10891         int i;
10892         unsigned size;
10893         int ret = -1;
10894
10895         p = strchr(p0, '(');
10896         if (p == NULL)
10897                 return -1;
10898         ++p;
10899         p0 = strchr(p, ')');
10900         if (p0 == NULL)
10901                 return -1;
10902
10903         size = p0 - p;
10904         if (size >= sizeof(s))
10905                 return -1;
10906
10907         snprintf(s, sizeof(s), "%.*s", size, p);
10908         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10909         if (ret < 0 || ret > max_num)
10910                 return -1;
10911         for (i = 0; i < ret; i++) {
10912                 errno = 0;
10913                 int_fld = strtoul(str_fld[i], &end, 0);
10914                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10915                         return -1;
10916                 flexbytes[i] = (uint8_t)int_fld;
10917         }
10918         return ret;
10919 }
10920
10921 static uint16_t
10922 str2flowtype(char *string)
10923 {
10924         uint8_t i = 0;
10925         static const struct {
10926                 char str[32];
10927                 uint16_t type;
10928         } flowtype_str[] = {
10929                 {"raw", RTE_ETH_FLOW_RAW},
10930                 {"ipv4", RTE_ETH_FLOW_IPV4},
10931                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10932                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10933                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10934                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10935                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10936                 {"ipv6", RTE_ETH_FLOW_IPV6},
10937                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10938                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10939                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10940                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10941                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10942                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10943         };
10944
10945         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10946                 if (!strcmp(flowtype_str[i].str, string))
10947                         return flowtype_str[i].type;
10948         }
10949
10950         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10951                 return (uint16_t)atoi(string);
10952
10953         return RTE_ETH_FLOW_UNKNOWN;
10954 }
10955
10956 static enum rte_eth_fdir_tunnel_type
10957 str2fdir_tunneltype(char *string)
10958 {
10959         uint8_t i = 0;
10960
10961         static const struct {
10962                 char str[32];
10963                 enum rte_eth_fdir_tunnel_type type;
10964         } tunneltype_str[] = {
10965                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10966                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10967         };
10968
10969         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10970                 if (!strcmp(tunneltype_str[i].str, string))
10971                         return tunneltype_str[i].type;
10972         }
10973         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10974 }
10975
10976 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10977 do { \
10978         if ((ip_addr).family == AF_INET) \
10979                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10980         else { \
10981                 printf("invalid parameter.\n"); \
10982                 return; \
10983         } \
10984 } while (0)
10985
10986 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10987 do { \
10988         if ((ip_addr).family == AF_INET6) \
10989                 rte_memcpy(&(ip), \
10990                                  &((ip_addr).addr.ipv6), \
10991                                  sizeof(struct in6_addr)); \
10992         else { \
10993                 printf("invalid parameter.\n"); \
10994                 return; \
10995         } \
10996 } while (0)
10997
10998 static void
10999 cmd_flow_director_filter_parsed(void *parsed_result,
11000                           __attribute__((unused)) struct cmdline *cl,
11001                           __attribute__((unused)) void *data)
11002 {
11003         struct cmd_flow_director_result *res = parsed_result;
11004         struct rte_eth_fdir_filter entry;
11005         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11006         char *end;
11007         unsigned long vf_id;
11008         int ret = 0;
11009
11010         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11011         if (ret < 0) {
11012                 printf("flow director is not supported on port %u.\n",
11013                         res->port_id);
11014                 return;
11015         }
11016         memset(flexbytes, 0, sizeof(flexbytes));
11017         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11018
11019         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11020                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11021                         printf("Please set mode to MAC-VLAN.\n");
11022                         return;
11023                 }
11024         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11025                 if (strcmp(res->mode_value, "Tunnel")) {
11026                         printf("Please set mode to Tunnel.\n");
11027                         return;
11028                 }
11029         } else {
11030                 if (!strcmp(res->mode_value, "raw")) {
11031 #ifdef RTE_LIBRTE_I40E_PMD
11032                         struct rte_pmd_i40e_flow_type_mapping
11033                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11034                         struct rte_pmd_i40e_pkt_template_conf conf;
11035                         uint16_t flow_type = str2flowtype(res->flow_type);
11036                         uint16_t i, port = res->port_id;
11037                         uint8_t add;
11038
11039                         memset(&conf, 0, sizeof(conf));
11040
11041                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11042                                 printf("Invalid flow type specified.\n");
11043                                 return;
11044                         }
11045                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11046                                                                  mapping);
11047                         if (ret)
11048                                 return;
11049                         if (mapping[flow_type].pctype == 0ULL) {
11050                                 printf("Invalid flow type specified.\n");
11051                                 return;
11052                         }
11053                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11054                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11055                                         conf.input.pctype = i;
11056                                         break;
11057                                 }
11058                         }
11059
11060                         conf.input.packet = open_file(res->filepath,
11061                                                 &conf.input.length);
11062                         if (!conf.input.packet)
11063                                 return;
11064                         if (!strcmp(res->drop, "drop"))
11065                                 conf.action.behavior =
11066                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11067                         else
11068                                 conf.action.behavior =
11069                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11070                         conf.action.report_status =
11071                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11072                         conf.action.rx_queue = res->queue_id;
11073                         conf.soft_id = res->fd_id_value;
11074                         add  = strcmp(res->ops, "del") ? 1 : 0;
11075                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11076                                                                         &conf,
11077                                                                         add);
11078                         if (ret < 0)
11079                                 printf("flow director config error: (%s)\n",
11080                                        strerror(-ret));
11081                         close_file(conf.input.packet);
11082 #endif
11083                         return;
11084                 } else if (strcmp(res->mode_value, "IP")) {
11085                         printf("Please set mode to IP or raw.\n");
11086                         return;
11087                 }
11088                 entry.input.flow_type = str2flowtype(res->flow_type);
11089         }
11090
11091         ret = parse_flexbytes(res->flexbytes_value,
11092                                         flexbytes,
11093                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11094         if (ret < 0) {
11095                 printf("error: Cannot parse flexbytes input.\n");
11096                 return;
11097         }
11098
11099         switch (entry.input.flow_type) {
11100         case RTE_ETH_FLOW_FRAG_IPV4:
11101         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11102                 entry.input.flow.ip4_flow.proto = res->proto_value;
11103                 /* fall-through */
11104         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11105         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11106                 IPV4_ADDR_TO_UINT(res->ip_dst,
11107                         entry.input.flow.ip4_flow.dst_ip);
11108                 IPV4_ADDR_TO_UINT(res->ip_src,
11109                         entry.input.flow.ip4_flow.src_ip);
11110                 entry.input.flow.ip4_flow.tos = res->tos_value;
11111                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11112                 /* need convert to big endian. */
11113                 entry.input.flow.udp4_flow.dst_port =
11114                                 rte_cpu_to_be_16(res->port_dst);
11115                 entry.input.flow.udp4_flow.src_port =
11116                                 rte_cpu_to_be_16(res->port_src);
11117                 break;
11118         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11119                 IPV4_ADDR_TO_UINT(res->ip_dst,
11120                         entry.input.flow.sctp4_flow.ip.dst_ip);
11121                 IPV4_ADDR_TO_UINT(res->ip_src,
11122                         entry.input.flow.sctp4_flow.ip.src_ip);
11123                 entry.input.flow.ip4_flow.tos = res->tos_value;
11124                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11125                 /* need convert to big endian. */
11126                 entry.input.flow.sctp4_flow.dst_port =
11127                                 rte_cpu_to_be_16(res->port_dst);
11128                 entry.input.flow.sctp4_flow.src_port =
11129                                 rte_cpu_to_be_16(res->port_src);
11130                 entry.input.flow.sctp4_flow.verify_tag =
11131                                 rte_cpu_to_be_32(res->verify_tag_value);
11132                 break;
11133         case RTE_ETH_FLOW_FRAG_IPV6:
11134         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11135                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11136                 /* fall-through */
11137         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11138         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11139                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11140                         entry.input.flow.ipv6_flow.dst_ip);
11141                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11142                         entry.input.flow.ipv6_flow.src_ip);
11143                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11144                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11145                 /* need convert to big endian. */
11146                 entry.input.flow.udp6_flow.dst_port =
11147                                 rte_cpu_to_be_16(res->port_dst);
11148                 entry.input.flow.udp6_flow.src_port =
11149                                 rte_cpu_to_be_16(res->port_src);
11150                 break;
11151         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11152                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11153                         entry.input.flow.sctp6_flow.ip.dst_ip);
11154                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11155                         entry.input.flow.sctp6_flow.ip.src_ip);
11156                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11157                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11158                 /* need convert to big endian. */
11159                 entry.input.flow.sctp6_flow.dst_port =
11160                                 rte_cpu_to_be_16(res->port_dst);
11161                 entry.input.flow.sctp6_flow.src_port =
11162                                 rte_cpu_to_be_16(res->port_src);
11163                 entry.input.flow.sctp6_flow.verify_tag =
11164                                 rte_cpu_to_be_32(res->verify_tag_value);
11165                 break;
11166         case RTE_ETH_FLOW_L2_PAYLOAD:
11167                 entry.input.flow.l2_flow.ether_type =
11168                         rte_cpu_to_be_16(res->ether_type);
11169                 break;
11170         default:
11171                 break;
11172         }
11173
11174         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11175                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11176                                  &res->mac_addr,
11177                                  sizeof(struct rte_ether_addr));
11178
11179         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11180                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11181                                  &res->mac_addr,
11182                                  sizeof(struct rte_ether_addr));
11183                 entry.input.flow.tunnel_flow.tunnel_type =
11184                         str2fdir_tunneltype(res->tunnel_type);
11185                 entry.input.flow.tunnel_flow.tunnel_id =
11186                         rte_cpu_to_be_32(res->tunnel_id_value);
11187         }
11188
11189         rte_memcpy(entry.input.flow_ext.flexbytes,
11190                    flexbytes,
11191                    RTE_ETH_FDIR_MAX_FLEXLEN);
11192
11193         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11194
11195         entry.action.flex_off = 0;  /*use 0 by default */
11196         if (!strcmp(res->drop, "drop"))
11197                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11198         else
11199                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11200
11201         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11202             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11203                 if (!strcmp(res->pf_vf, "pf"))
11204                         entry.input.flow_ext.is_vf = 0;
11205                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11206                         struct rte_eth_dev_info dev_info;
11207
11208                         ret = eth_dev_info_get_print_err(res->port_id,
11209                                                 &dev_info);
11210                         if (ret != 0)
11211                                 return;
11212
11213                         errno = 0;
11214                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11215                         if (errno != 0 || *end != '\0' ||
11216                             vf_id >= dev_info.max_vfs) {
11217                                 printf("invalid parameter %s.\n", res->pf_vf);
11218                                 return;
11219                         }
11220                         entry.input.flow_ext.is_vf = 1;
11221                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11222                 } else {
11223                         printf("invalid parameter %s.\n", res->pf_vf);
11224                         return;
11225                 }
11226         }
11227
11228         /* set to report FD ID by default */
11229         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11230         entry.action.rx_queue = res->queue_id;
11231         entry.soft_id = res->fd_id_value;
11232         if (!strcmp(res->ops, "add"))
11233                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11234                                              RTE_ETH_FILTER_ADD, &entry);
11235         else if (!strcmp(res->ops, "del"))
11236                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11237                                              RTE_ETH_FILTER_DELETE, &entry);
11238         else
11239                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11240                                              RTE_ETH_FILTER_UPDATE, &entry);
11241         if (ret < 0)
11242                 printf("flow director programming error: (%s)\n",
11243                         strerror(-ret));
11244 }
11245
11246 cmdline_parse_token_string_t cmd_flow_director_filter =
11247         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11248                                  flow_director_filter, "flow_director_filter");
11249 cmdline_parse_token_num_t cmd_flow_director_port_id =
11250         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11251                               port_id, UINT16);
11252 cmdline_parse_token_string_t cmd_flow_director_ops =
11253         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11254                                  ops, "add#del#update");
11255 cmdline_parse_token_string_t cmd_flow_director_flow =
11256         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11257                                  flow, "flow");
11258 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11259         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11260                 flow_type, NULL);
11261 cmdline_parse_token_string_t cmd_flow_director_ether =
11262         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11263                                  ether, "ether");
11264 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11265         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11266                               ether_type, UINT16);
11267 cmdline_parse_token_string_t cmd_flow_director_src =
11268         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11269                                  src, "src");
11270 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11271         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11272                                  ip_src);
11273 cmdline_parse_token_num_t cmd_flow_director_port_src =
11274         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11275                               port_src, UINT16);
11276 cmdline_parse_token_string_t cmd_flow_director_dst =
11277         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11278                                  dst, "dst");
11279 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11280         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11281                                  ip_dst);
11282 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11283         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11284                               port_dst, UINT16);
11285 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11286         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11287                                   verify_tag, "verify_tag");
11288 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11289         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11290                               verify_tag_value, UINT32);
11291 cmdline_parse_token_string_t cmd_flow_director_tos =
11292         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11293                                  tos, "tos");
11294 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11295         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11296                               tos_value, UINT8);
11297 cmdline_parse_token_string_t cmd_flow_director_proto =
11298         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11299                                  proto, "proto");
11300 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11301         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11302                               proto_value, UINT8);
11303 cmdline_parse_token_string_t cmd_flow_director_ttl =
11304         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11305                                  ttl, "ttl");
11306 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11307         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11308                               ttl_value, UINT8);
11309 cmdline_parse_token_string_t cmd_flow_director_vlan =
11310         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11311                                  vlan, "vlan");
11312 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11313         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11314                               vlan_value, UINT16);
11315 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11316         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11317                                  flexbytes, "flexbytes");
11318 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11319         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11320                               flexbytes_value, NULL);
11321 cmdline_parse_token_string_t cmd_flow_director_drop =
11322         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11323                                  drop, "drop#fwd");
11324 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11325         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11326                               pf_vf, NULL);
11327 cmdline_parse_token_string_t cmd_flow_director_queue =
11328         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11329                                  queue, "queue");
11330 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11331         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11332                               queue_id, UINT16);
11333 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11334         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11335                                  fd_id, "fd_id");
11336 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11337         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11338                               fd_id_value, UINT32);
11339
11340 cmdline_parse_token_string_t cmd_flow_director_mode =
11341         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11342                                  mode, "mode");
11343 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11344         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11345                                  mode_value, "IP");
11346 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11347         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11348                                  mode_value, "MAC-VLAN");
11349 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11350         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11351                                  mode_value, "Tunnel");
11352 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11353         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11354                                  mode_value, "raw");
11355 cmdline_parse_token_string_t cmd_flow_director_mac =
11356         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11357                                  mac, "mac");
11358 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11359         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11360                                     mac_addr);
11361 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11362         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11363                                  tunnel, "tunnel");
11364 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11365         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11366                                  tunnel_type, "NVGRE#VxLAN");
11367 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11368         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11369                                  tunnel_id, "tunnel-id");
11370 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11371         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11372                               tunnel_id_value, UINT32);
11373 cmdline_parse_token_string_t cmd_flow_director_packet =
11374         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11375                                  packet, "packet");
11376 cmdline_parse_token_string_t cmd_flow_director_filepath =
11377         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11378                                  filepath, NULL);
11379
11380 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11381         .f = cmd_flow_director_filter_parsed,
11382         .data = NULL,
11383         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11384                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11385                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11386                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11387                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11388                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11389                 "fd_id <fd_id_value>: "
11390                 "Add or delete an ip flow director entry on NIC",
11391         .tokens = {
11392                 (void *)&cmd_flow_director_filter,
11393                 (void *)&cmd_flow_director_port_id,
11394                 (void *)&cmd_flow_director_mode,
11395                 (void *)&cmd_flow_director_mode_ip,
11396                 (void *)&cmd_flow_director_ops,
11397                 (void *)&cmd_flow_director_flow,
11398                 (void *)&cmd_flow_director_flow_type,
11399                 (void *)&cmd_flow_director_src,
11400                 (void *)&cmd_flow_director_ip_src,
11401                 (void *)&cmd_flow_director_dst,
11402                 (void *)&cmd_flow_director_ip_dst,
11403                 (void *)&cmd_flow_director_tos,
11404                 (void *)&cmd_flow_director_tos_value,
11405                 (void *)&cmd_flow_director_proto,
11406                 (void *)&cmd_flow_director_proto_value,
11407                 (void *)&cmd_flow_director_ttl,
11408                 (void *)&cmd_flow_director_ttl_value,
11409                 (void *)&cmd_flow_director_vlan,
11410                 (void *)&cmd_flow_director_vlan_value,
11411                 (void *)&cmd_flow_director_flexbytes,
11412                 (void *)&cmd_flow_director_flexbytes_value,
11413                 (void *)&cmd_flow_director_drop,
11414                 (void *)&cmd_flow_director_pf_vf,
11415                 (void *)&cmd_flow_director_queue,
11416                 (void *)&cmd_flow_director_queue_id,
11417                 (void *)&cmd_flow_director_fd_id,
11418                 (void *)&cmd_flow_director_fd_id_value,
11419                 NULL,
11420         },
11421 };
11422
11423 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11424         .f = cmd_flow_director_filter_parsed,
11425         .data = NULL,
11426         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11427                 "director entry on NIC",
11428         .tokens = {
11429                 (void *)&cmd_flow_director_filter,
11430                 (void *)&cmd_flow_director_port_id,
11431                 (void *)&cmd_flow_director_mode,
11432                 (void *)&cmd_flow_director_mode_ip,
11433                 (void *)&cmd_flow_director_ops,
11434                 (void *)&cmd_flow_director_flow,
11435                 (void *)&cmd_flow_director_flow_type,
11436                 (void *)&cmd_flow_director_src,
11437                 (void *)&cmd_flow_director_ip_src,
11438                 (void *)&cmd_flow_director_port_src,
11439                 (void *)&cmd_flow_director_dst,
11440                 (void *)&cmd_flow_director_ip_dst,
11441                 (void *)&cmd_flow_director_port_dst,
11442                 (void *)&cmd_flow_director_tos,
11443                 (void *)&cmd_flow_director_tos_value,
11444                 (void *)&cmd_flow_director_ttl,
11445                 (void *)&cmd_flow_director_ttl_value,
11446                 (void *)&cmd_flow_director_vlan,
11447                 (void *)&cmd_flow_director_vlan_value,
11448                 (void *)&cmd_flow_director_flexbytes,
11449                 (void *)&cmd_flow_director_flexbytes_value,
11450                 (void *)&cmd_flow_director_drop,
11451                 (void *)&cmd_flow_director_pf_vf,
11452                 (void *)&cmd_flow_director_queue,
11453                 (void *)&cmd_flow_director_queue_id,
11454                 (void *)&cmd_flow_director_fd_id,
11455                 (void *)&cmd_flow_director_fd_id_value,
11456                 NULL,
11457         },
11458 };
11459
11460 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11461         .f = cmd_flow_director_filter_parsed,
11462         .data = NULL,
11463         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11464                 "director entry on NIC",
11465         .tokens = {
11466                 (void *)&cmd_flow_director_filter,
11467                 (void *)&cmd_flow_director_port_id,
11468                 (void *)&cmd_flow_director_mode,
11469                 (void *)&cmd_flow_director_mode_ip,
11470                 (void *)&cmd_flow_director_ops,
11471                 (void *)&cmd_flow_director_flow,
11472                 (void *)&cmd_flow_director_flow_type,
11473                 (void *)&cmd_flow_director_src,
11474                 (void *)&cmd_flow_director_ip_src,
11475                 (void *)&cmd_flow_director_port_src,
11476                 (void *)&cmd_flow_director_dst,
11477                 (void *)&cmd_flow_director_ip_dst,
11478                 (void *)&cmd_flow_director_port_dst,
11479                 (void *)&cmd_flow_director_verify_tag,
11480                 (void *)&cmd_flow_director_verify_tag_value,
11481                 (void *)&cmd_flow_director_tos,
11482                 (void *)&cmd_flow_director_tos_value,
11483                 (void *)&cmd_flow_director_ttl,
11484                 (void *)&cmd_flow_director_ttl_value,
11485                 (void *)&cmd_flow_director_vlan,
11486                 (void *)&cmd_flow_director_vlan_value,
11487                 (void *)&cmd_flow_director_flexbytes,
11488                 (void *)&cmd_flow_director_flexbytes_value,
11489                 (void *)&cmd_flow_director_drop,
11490                 (void *)&cmd_flow_director_pf_vf,
11491                 (void *)&cmd_flow_director_queue,
11492                 (void *)&cmd_flow_director_queue_id,
11493                 (void *)&cmd_flow_director_fd_id,
11494                 (void *)&cmd_flow_director_fd_id_value,
11495                 NULL,
11496         },
11497 };
11498
11499 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11500         .f = cmd_flow_director_filter_parsed,
11501         .data = NULL,
11502         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11503                 "director entry on NIC",
11504         .tokens = {
11505                 (void *)&cmd_flow_director_filter,
11506                 (void *)&cmd_flow_director_port_id,
11507                 (void *)&cmd_flow_director_mode,
11508                 (void *)&cmd_flow_director_mode_ip,
11509                 (void *)&cmd_flow_director_ops,
11510                 (void *)&cmd_flow_director_flow,
11511                 (void *)&cmd_flow_director_flow_type,
11512                 (void *)&cmd_flow_director_ether,
11513                 (void *)&cmd_flow_director_ether_type,
11514                 (void *)&cmd_flow_director_flexbytes,
11515                 (void *)&cmd_flow_director_flexbytes_value,
11516                 (void *)&cmd_flow_director_drop,
11517                 (void *)&cmd_flow_director_pf_vf,
11518                 (void *)&cmd_flow_director_queue,
11519                 (void *)&cmd_flow_director_queue_id,
11520                 (void *)&cmd_flow_director_fd_id,
11521                 (void *)&cmd_flow_director_fd_id_value,
11522                 NULL,
11523         },
11524 };
11525
11526 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11527         .f = cmd_flow_director_filter_parsed,
11528         .data = NULL,
11529         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11530                 "director entry on NIC",
11531         .tokens = {
11532                 (void *)&cmd_flow_director_filter,
11533                 (void *)&cmd_flow_director_port_id,
11534                 (void *)&cmd_flow_director_mode,
11535                 (void *)&cmd_flow_director_mode_mac_vlan,
11536                 (void *)&cmd_flow_director_ops,
11537                 (void *)&cmd_flow_director_mac,
11538                 (void *)&cmd_flow_director_mac_addr,
11539                 (void *)&cmd_flow_director_vlan,
11540                 (void *)&cmd_flow_director_vlan_value,
11541                 (void *)&cmd_flow_director_flexbytes,
11542                 (void *)&cmd_flow_director_flexbytes_value,
11543                 (void *)&cmd_flow_director_drop,
11544                 (void *)&cmd_flow_director_queue,
11545                 (void *)&cmd_flow_director_queue_id,
11546                 (void *)&cmd_flow_director_fd_id,
11547                 (void *)&cmd_flow_director_fd_id_value,
11548                 NULL,
11549         },
11550 };
11551
11552 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11553         .f = cmd_flow_director_filter_parsed,
11554         .data = NULL,
11555         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11556                 "director entry on NIC",
11557         .tokens = {
11558                 (void *)&cmd_flow_director_filter,
11559                 (void *)&cmd_flow_director_port_id,
11560                 (void *)&cmd_flow_director_mode,
11561                 (void *)&cmd_flow_director_mode_tunnel,
11562                 (void *)&cmd_flow_director_ops,
11563                 (void *)&cmd_flow_director_mac,
11564                 (void *)&cmd_flow_director_mac_addr,
11565                 (void *)&cmd_flow_director_vlan,
11566                 (void *)&cmd_flow_director_vlan_value,
11567                 (void *)&cmd_flow_director_tunnel,
11568                 (void *)&cmd_flow_director_tunnel_type,
11569                 (void *)&cmd_flow_director_tunnel_id,
11570                 (void *)&cmd_flow_director_tunnel_id_value,
11571                 (void *)&cmd_flow_director_flexbytes,
11572                 (void *)&cmd_flow_director_flexbytes_value,
11573                 (void *)&cmd_flow_director_drop,
11574                 (void *)&cmd_flow_director_queue,
11575                 (void *)&cmd_flow_director_queue_id,
11576                 (void *)&cmd_flow_director_fd_id,
11577                 (void *)&cmd_flow_director_fd_id_value,
11578                 NULL,
11579         },
11580 };
11581
11582 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11583         .f = cmd_flow_director_filter_parsed,
11584         .data = NULL,
11585         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11586                 "director entry on NIC",
11587         .tokens = {
11588                 (void *)&cmd_flow_director_filter,
11589                 (void *)&cmd_flow_director_port_id,
11590                 (void *)&cmd_flow_director_mode,
11591                 (void *)&cmd_flow_director_mode_raw,
11592                 (void *)&cmd_flow_director_ops,
11593                 (void *)&cmd_flow_director_flow,
11594                 (void *)&cmd_flow_director_flow_type,
11595                 (void *)&cmd_flow_director_drop,
11596                 (void *)&cmd_flow_director_queue,
11597                 (void *)&cmd_flow_director_queue_id,
11598                 (void *)&cmd_flow_director_fd_id,
11599                 (void *)&cmd_flow_director_fd_id_value,
11600                 (void *)&cmd_flow_director_packet,
11601                 (void *)&cmd_flow_director_filepath,
11602                 NULL,
11603         },
11604 };
11605
11606 struct cmd_flush_flow_director_result {
11607         cmdline_fixed_string_t flush_flow_director;
11608         portid_t port_id;
11609 };
11610
11611 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11612         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11613                                  flush_flow_director, "flush_flow_director");
11614 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11615         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11616                               port_id, UINT16);
11617
11618 static void
11619 cmd_flush_flow_director_parsed(void *parsed_result,
11620                           __attribute__((unused)) struct cmdline *cl,
11621                           __attribute__((unused)) void *data)
11622 {
11623         struct cmd_flow_director_result *res = parsed_result;
11624         int ret = 0;
11625
11626         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11627         if (ret < 0) {
11628                 printf("flow director is not supported on port %u.\n",
11629                         res->port_id);
11630                 return;
11631         }
11632
11633         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11634                         RTE_ETH_FILTER_FLUSH, NULL);
11635         if (ret < 0)
11636                 printf("flow director table flushing error: (%s)\n",
11637                         strerror(-ret));
11638 }
11639
11640 cmdline_parse_inst_t cmd_flush_flow_director = {
11641         .f = cmd_flush_flow_director_parsed,
11642         .data = NULL,
11643         .help_str = "flush_flow_director <port_id>: "
11644                 "Flush all flow director entries of a device on NIC",
11645         .tokens = {
11646                 (void *)&cmd_flush_flow_director_flush,
11647                 (void *)&cmd_flush_flow_director_port_id,
11648                 NULL,
11649         },
11650 };
11651
11652 /* *** deal with flow director mask *** */
11653 struct cmd_flow_director_mask_result {
11654         cmdline_fixed_string_t flow_director_mask;
11655         portid_t port_id;
11656         cmdline_fixed_string_t mode;
11657         cmdline_fixed_string_t mode_value;
11658         cmdline_fixed_string_t vlan;
11659         uint16_t vlan_mask;
11660         cmdline_fixed_string_t src_mask;
11661         cmdline_ipaddr_t ipv4_src;
11662         cmdline_ipaddr_t ipv6_src;
11663         uint16_t port_src;
11664         cmdline_fixed_string_t dst_mask;
11665         cmdline_ipaddr_t ipv4_dst;
11666         cmdline_ipaddr_t ipv6_dst;
11667         uint16_t port_dst;
11668         cmdline_fixed_string_t mac;
11669         uint8_t mac_addr_byte_mask;
11670         cmdline_fixed_string_t tunnel_id;
11671         uint32_t tunnel_id_mask;
11672         cmdline_fixed_string_t tunnel_type;
11673         uint8_t tunnel_type_mask;
11674 };
11675
11676 static void
11677 cmd_flow_director_mask_parsed(void *parsed_result,
11678                           __attribute__((unused)) struct cmdline *cl,
11679                           __attribute__((unused)) void *data)
11680 {
11681         struct cmd_flow_director_mask_result *res = parsed_result;
11682         struct rte_eth_fdir_masks *mask;
11683         struct rte_port *port;
11684
11685         port = &ports[res->port_id];
11686         /** Check if the port is not started **/
11687         if (port->port_status != RTE_PORT_STOPPED) {
11688                 printf("Please stop port %d first\n", res->port_id);
11689                 return;
11690         }
11691
11692         mask = &port->dev_conf.fdir_conf.mask;
11693
11694         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11695                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11696                         printf("Please set mode to MAC-VLAN.\n");
11697                         return;
11698                 }
11699
11700                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11701         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11702                 if (strcmp(res->mode_value, "Tunnel")) {
11703                         printf("Please set mode to Tunnel.\n");
11704                         return;
11705                 }
11706
11707                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11708                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11709                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11710                 mask->tunnel_type_mask = res->tunnel_type_mask;
11711         } else {
11712                 if (strcmp(res->mode_value, "IP")) {
11713                         printf("Please set mode to IP.\n");
11714                         return;
11715                 }
11716
11717                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11718                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11719                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11720                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11721                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11722                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11723                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11724         }
11725
11726         cmd_reconfig_device_queue(res->port_id, 1, 1);
11727 }
11728
11729 cmdline_parse_token_string_t cmd_flow_director_mask =
11730         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11731                                  flow_director_mask, "flow_director_mask");
11732 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11733         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11734                               port_id, UINT16);
11735 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11736         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11737                                  vlan, "vlan");
11738 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11739         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11740                               vlan_mask, UINT16);
11741 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11742         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11743                                  src_mask, "src_mask");
11744 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11745         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11746                                  ipv4_src);
11747 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11748         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11749                                  ipv6_src);
11750 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11751         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11752                               port_src, UINT16);
11753 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11754         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11755                                  dst_mask, "dst_mask");
11756 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11757         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11758                                  ipv4_dst);
11759 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11760         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11761                                  ipv6_dst);
11762 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11763         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11764                               port_dst, UINT16);
11765
11766 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11767         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11768                                  mode, "mode");
11769 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11770         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11771                                  mode_value, "IP");
11772 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11773         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11774                                  mode_value, "MAC-VLAN");
11775 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11776         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11777                                  mode_value, "Tunnel");
11778 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11779         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11780                                  mac, "mac");
11781 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11782         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11783                               mac_addr_byte_mask, UINT8);
11784 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11785         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11786                                  tunnel_type, "tunnel-type");
11787 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11788         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11789                               tunnel_type_mask, UINT8);
11790 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11791         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11792                                  tunnel_id, "tunnel-id");
11793 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11794         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11795                               tunnel_id_mask, UINT32);
11796
11797 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11798         .f = cmd_flow_director_mask_parsed,
11799         .data = NULL,
11800         .help_str = "flow_director_mask ... : "
11801                 "Set IP mode flow director's mask on NIC",
11802         .tokens = {
11803                 (void *)&cmd_flow_director_mask,
11804                 (void *)&cmd_flow_director_mask_port_id,
11805                 (void *)&cmd_flow_director_mask_mode,
11806                 (void *)&cmd_flow_director_mask_mode_ip,
11807                 (void *)&cmd_flow_director_mask_vlan,
11808                 (void *)&cmd_flow_director_mask_vlan_value,
11809                 (void *)&cmd_flow_director_mask_src,
11810                 (void *)&cmd_flow_director_mask_ipv4_src,
11811                 (void *)&cmd_flow_director_mask_ipv6_src,
11812                 (void *)&cmd_flow_director_mask_port_src,
11813                 (void *)&cmd_flow_director_mask_dst,
11814                 (void *)&cmd_flow_director_mask_ipv4_dst,
11815                 (void *)&cmd_flow_director_mask_ipv6_dst,
11816                 (void *)&cmd_flow_director_mask_port_dst,
11817                 NULL,
11818         },
11819 };
11820
11821 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11822         .f = cmd_flow_director_mask_parsed,
11823         .data = NULL,
11824         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11825                 "flow director's mask on NIC",
11826         .tokens = {
11827                 (void *)&cmd_flow_director_mask,
11828                 (void *)&cmd_flow_director_mask_port_id,
11829                 (void *)&cmd_flow_director_mask_mode,
11830                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11831                 (void *)&cmd_flow_director_mask_vlan,
11832                 (void *)&cmd_flow_director_mask_vlan_value,
11833                 NULL,
11834         },
11835 };
11836
11837 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11838         .f = cmd_flow_director_mask_parsed,
11839         .data = NULL,
11840         .help_str = "flow_director_mask ... : Set tunnel mode "
11841                 "flow director's mask on NIC",
11842         .tokens = {
11843                 (void *)&cmd_flow_director_mask,
11844                 (void *)&cmd_flow_director_mask_port_id,
11845                 (void *)&cmd_flow_director_mask_mode,
11846                 (void *)&cmd_flow_director_mask_mode_tunnel,
11847                 (void *)&cmd_flow_director_mask_vlan,
11848                 (void *)&cmd_flow_director_mask_vlan_value,
11849                 (void *)&cmd_flow_director_mask_mac,
11850                 (void *)&cmd_flow_director_mask_mac_value,
11851                 (void *)&cmd_flow_director_mask_tunnel_type,
11852                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11853                 (void *)&cmd_flow_director_mask_tunnel_id,
11854                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11855                 NULL,
11856         },
11857 };
11858
11859 /* *** deal with flow director mask on flexible payload *** */
11860 struct cmd_flow_director_flex_mask_result {
11861         cmdline_fixed_string_t flow_director_flexmask;
11862         portid_t port_id;
11863         cmdline_fixed_string_t flow;
11864         cmdline_fixed_string_t flow_type;
11865         cmdline_fixed_string_t mask;
11866 };
11867
11868 static void
11869 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11870                           __attribute__((unused)) struct cmdline *cl,
11871                           __attribute__((unused)) void *data)
11872 {
11873         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11874         struct rte_eth_fdir_info fdir_info;
11875         struct rte_eth_fdir_flex_mask flex_mask;
11876         struct rte_port *port;
11877         uint64_t flow_type_mask;
11878         uint16_t i;
11879         int ret;
11880
11881         port = &ports[res->port_id];
11882         /** Check if the port is not started **/
11883         if (port->port_status != RTE_PORT_STOPPED) {
11884                 printf("Please stop port %d first\n", res->port_id);
11885                 return;
11886         }
11887
11888         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11889         ret = parse_flexbytes(res->mask,
11890                         flex_mask.mask,
11891                         RTE_ETH_FDIR_MAX_FLEXLEN);
11892         if (ret < 0) {
11893                 printf("error: Cannot parse mask input.\n");
11894                 return;
11895         }
11896
11897         memset(&fdir_info, 0, sizeof(fdir_info));
11898         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11899                                 RTE_ETH_FILTER_INFO, &fdir_info);
11900         if (ret < 0) {
11901                 printf("Cannot get FDir filter info\n");
11902                 return;
11903         }
11904
11905         if (!strcmp(res->flow_type, "none")) {
11906                 /* means don't specify the flow type */
11907                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11908                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11909                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11910                                0, sizeof(struct rte_eth_fdir_flex_mask));
11911                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11912                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11913                                  &flex_mask,
11914                                  sizeof(struct rte_eth_fdir_flex_mask));
11915                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11916                 return;
11917         }
11918         flow_type_mask = fdir_info.flow_types_mask[0];
11919         if (!strcmp(res->flow_type, "all")) {
11920                 if (!flow_type_mask) {
11921                         printf("No flow type supported\n");
11922                         return;
11923                 }
11924                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11925                         if (flow_type_mask & (1ULL << i)) {
11926                                 flex_mask.flow_type = i;
11927                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11928                         }
11929                 }
11930                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11931                 return;
11932         }
11933         flex_mask.flow_type = str2flowtype(res->flow_type);
11934         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11935                 printf("Flow type %s not supported on port %d\n",
11936                                 res->flow_type, res->port_id);
11937                 return;
11938         }
11939         fdir_set_flex_mask(res->port_id, &flex_mask);
11940         cmd_reconfig_device_queue(res->port_id, 1, 1);
11941 }
11942
11943 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11944         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11945                                  flow_director_flexmask,
11946                                  "flow_director_flex_mask");
11947 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11948         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11949                               port_id, UINT16);
11950 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11951         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11952                                  flow, "flow");
11953 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11954         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11955                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11956                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11957 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11958         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11959                                  mask, NULL);
11960
11961 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11962         .f = cmd_flow_director_flex_mask_parsed,
11963         .data = NULL,
11964         .help_str = "flow_director_flex_mask ... : "
11965                 "Set flow director's flex mask on NIC",
11966         .tokens = {
11967                 (void *)&cmd_flow_director_flexmask,
11968                 (void *)&cmd_flow_director_flexmask_port_id,
11969                 (void *)&cmd_flow_director_flexmask_flow,
11970                 (void *)&cmd_flow_director_flexmask_flow_type,
11971                 (void *)&cmd_flow_director_flexmask_mask,
11972                 NULL,
11973         },
11974 };
11975
11976 /* *** deal with flow director flexible payload configuration *** */
11977 struct cmd_flow_director_flexpayload_result {
11978         cmdline_fixed_string_t flow_director_flexpayload;
11979         portid_t port_id;
11980         cmdline_fixed_string_t payload_layer;
11981         cmdline_fixed_string_t payload_cfg;
11982 };
11983
11984 static inline int
11985 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11986 {
11987         char s[256];
11988         const char *p, *p0 = q_arg;
11989         char *end;
11990         unsigned long int_fld;
11991         char *str_fld[max_num];
11992         int i;
11993         unsigned size;
11994         int ret = -1;
11995
11996         p = strchr(p0, '(');
11997         if (p == NULL)
11998                 return -1;
11999         ++p;
12000         p0 = strchr(p, ')');
12001         if (p0 == NULL)
12002                 return -1;
12003
12004         size = p0 - p;
12005         if (size >= sizeof(s))
12006                 return -1;
12007
12008         snprintf(s, sizeof(s), "%.*s", size, p);
12009         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12010         if (ret < 0 || ret > max_num)
12011                 return -1;
12012         for (i = 0; i < ret; i++) {
12013                 errno = 0;
12014                 int_fld = strtoul(str_fld[i], &end, 0);
12015                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12016                         return -1;
12017                 offsets[i] = (uint16_t)int_fld;
12018         }
12019         return ret;
12020 }
12021
12022 static void
12023 cmd_flow_director_flxpld_parsed(void *parsed_result,
12024                           __attribute__((unused)) struct cmdline *cl,
12025                           __attribute__((unused)) void *data)
12026 {
12027         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12028         struct rte_eth_flex_payload_cfg flex_cfg;
12029         struct rte_port *port;
12030         int ret = 0;
12031
12032         port = &ports[res->port_id];
12033         /** Check if the port is not started **/
12034         if (port->port_status != RTE_PORT_STOPPED) {
12035                 printf("Please stop port %d first\n", res->port_id);
12036                 return;
12037         }
12038
12039         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12040
12041         if (!strcmp(res->payload_layer, "raw"))
12042                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12043         else if (!strcmp(res->payload_layer, "l2"))
12044                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12045         else if (!strcmp(res->payload_layer, "l3"))
12046                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12047         else if (!strcmp(res->payload_layer, "l4"))
12048                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12049
12050         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12051                             RTE_ETH_FDIR_MAX_FLEXLEN);
12052         if (ret < 0) {
12053                 printf("error: Cannot parse flex payload input.\n");
12054                 return;
12055         }
12056
12057         fdir_set_flex_payload(res->port_id, &flex_cfg);
12058         cmd_reconfig_device_queue(res->port_id, 1, 1);
12059 }
12060
12061 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12062         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12063                                  flow_director_flexpayload,
12064                                  "flow_director_flex_payload");
12065 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12066         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12067                               port_id, UINT16);
12068 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12069         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12070                                  payload_layer, "raw#l2#l3#l4");
12071 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12072         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12073                                  payload_cfg, NULL);
12074
12075 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12076         .f = cmd_flow_director_flxpld_parsed,
12077         .data = NULL,
12078         .help_str = "flow_director_flexpayload ... : "
12079                 "Set flow director's flex payload on NIC",
12080         .tokens = {
12081                 (void *)&cmd_flow_director_flexpayload,
12082                 (void *)&cmd_flow_director_flexpayload_port_id,
12083                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12084                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12085                 NULL,
12086         },
12087 };
12088
12089 /* Generic flow interface command. */
12090 extern cmdline_parse_inst_t cmd_flow;
12091
12092 /* *** Classification Filters Control *** */
12093 /* *** Get symmetric hash enable per port *** */
12094 struct cmd_get_sym_hash_ena_per_port_result {
12095         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12096         portid_t port_id;
12097 };
12098
12099 static void
12100 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12101                                  __rte_unused struct cmdline *cl,
12102                                  __rte_unused void *data)
12103 {
12104         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12105         struct rte_eth_hash_filter_info info;
12106         int ret;
12107
12108         if (rte_eth_dev_filter_supported(res->port_id,
12109                                 RTE_ETH_FILTER_HASH) < 0) {
12110                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12111                                                         res->port_id);
12112                 return;
12113         }
12114
12115         memset(&info, 0, sizeof(info));
12116         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12117         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12118                                                 RTE_ETH_FILTER_GET, &info);
12119
12120         if (ret < 0) {
12121                 printf("Cannot get symmetric hash enable per port "
12122                                         "on port %u\n", res->port_id);
12123                 return;
12124         }
12125
12126         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12127                                 "enabled" : "disabled", res->port_id);
12128 }
12129
12130 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12131         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12132                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12133 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12134         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12135                 port_id, UINT16);
12136
12137 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12138         .f = cmd_get_sym_hash_per_port_parsed,
12139         .data = NULL,
12140         .help_str = "get_sym_hash_ena_per_port <port_id>",
12141         .tokens = {
12142                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12143                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12144                 NULL,
12145         },
12146 };
12147
12148 /* *** Set symmetric hash enable per port *** */
12149 struct cmd_set_sym_hash_ena_per_port_result {
12150         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12151         cmdline_fixed_string_t enable;
12152         portid_t port_id;
12153 };
12154
12155 static void
12156 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12157                                  __rte_unused struct cmdline *cl,
12158                                  __rte_unused void *data)
12159 {
12160         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12161         struct rte_eth_hash_filter_info info;
12162         int ret;
12163
12164         if (rte_eth_dev_filter_supported(res->port_id,
12165                                 RTE_ETH_FILTER_HASH) < 0) {
12166                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12167                                                         res->port_id);
12168                 return;
12169         }
12170
12171         memset(&info, 0, sizeof(info));
12172         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12173         if (!strcmp(res->enable, "enable"))
12174                 info.info.enable = 1;
12175         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12176                                         RTE_ETH_FILTER_SET, &info);
12177         if (ret < 0) {
12178                 printf("Cannot set symmetric hash enable per port on "
12179                                         "port %u\n", res->port_id);
12180                 return;
12181         }
12182         printf("Symmetric hash has been set to %s on port %u\n",
12183                                         res->enable, res->port_id);
12184 }
12185
12186 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12187         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12188                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12189 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12190         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12191                 port_id, UINT16);
12192 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12193         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12194                 enable, "enable#disable");
12195
12196 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12197         .f = cmd_set_sym_hash_per_port_parsed,
12198         .data = NULL,
12199         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12200         .tokens = {
12201                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12202                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12203                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12204                 NULL,
12205         },
12206 };
12207
12208 /* Get global config of hash function */
12209 struct cmd_get_hash_global_config_result {
12210         cmdline_fixed_string_t get_hash_global_config;
12211         portid_t port_id;
12212 };
12213
12214 static char *
12215 flowtype_to_str(uint16_t ftype)
12216 {
12217         uint16_t i;
12218         static struct {
12219                 char str[16];
12220                 uint16_t ftype;
12221         } ftype_table[] = {
12222                 {"ipv4", RTE_ETH_FLOW_IPV4},
12223                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12224                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12225                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12226                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12227                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12228                 {"ipv6", RTE_ETH_FLOW_IPV6},
12229                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12230                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12231                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12232                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12233                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12234                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12235                 {"port", RTE_ETH_FLOW_PORT},
12236                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12237                 {"geneve", RTE_ETH_FLOW_GENEVE},
12238                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12239                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12240         };
12241
12242         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12243                 if (ftype_table[i].ftype == ftype)
12244                         return ftype_table[i].str;
12245         }
12246
12247         return NULL;
12248 }
12249
12250 static void
12251 cmd_get_hash_global_config_parsed(void *parsed_result,
12252                                   __rte_unused struct cmdline *cl,
12253                                   __rte_unused void *data)
12254 {
12255         struct cmd_get_hash_global_config_result *res = parsed_result;
12256         struct rte_eth_hash_filter_info info;
12257         uint32_t idx, offset;
12258         uint16_t i;
12259         char *str;
12260         int ret;
12261
12262         if (rte_eth_dev_filter_supported(res->port_id,
12263                         RTE_ETH_FILTER_HASH) < 0) {
12264                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12265                                                         res->port_id);
12266                 return;
12267         }
12268
12269         memset(&info, 0, sizeof(info));
12270         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12271         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12272                                         RTE_ETH_FILTER_GET, &info);
12273         if (ret < 0) {
12274                 printf("Cannot get hash global configurations by port %d\n",
12275                                                         res->port_id);
12276                 return;
12277         }
12278
12279         switch (info.info.global_conf.hash_func) {
12280         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12281                 printf("Hash function is Toeplitz\n");
12282                 break;
12283         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12284                 printf("Hash function is Simple XOR\n");
12285                 break;
12286         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12287                 printf("Hash function is Symmetric Toeplitz\n");
12288                 break;
12289         default:
12290                 printf("Unknown hash function\n");
12291                 break;
12292         }
12293
12294         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12295                 idx = i / UINT64_BIT;
12296                 offset = i % UINT64_BIT;
12297                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12298                                                 (1ULL << offset)))
12299                         continue;
12300                 str = flowtype_to_str(i);
12301                 if (!str)
12302                         continue;
12303                 printf("Symmetric hash is %s globally for flow type %s "
12304                                                         "by port %d\n",
12305                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12306                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12307                                                         res->port_id);
12308         }
12309 }
12310
12311 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12312         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12313                 get_hash_global_config, "get_hash_global_config");
12314 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12315         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12316                 port_id, UINT16);
12317
12318 cmdline_parse_inst_t cmd_get_hash_global_config = {
12319         .f = cmd_get_hash_global_config_parsed,
12320         .data = NULL,
12321         .help_str = "get_hash_global_config <port_id>",
12322         .tokens = {
12323                 (void *)&cmd_get_hash_global_config_all,
12324                 (void *)&cmd_get_hash_global_config_port_id,
12325                 NULL,
12326         },
12327 };
12328
12329 /* Set global config of hash function */
12330 struct cmd_set_hash_global_config_result {
12331         cmdline_fixed_string_t set_hash_global_config;
12332         portid_t port_id;
12333         cmdline_fixed_string_t hash_func;
12334         cmdline_fixed_string_t flow_type;
12335         cmdline_fixed_string_t enable;
12336 };
12337
12338 static void
12339 cmd_set_hash_global_config_parsed(void *parsed_result,
12340                                   __rte_unused struct cmdline *cl,
12341                                   __rte_unused void *data)
12342 {
12343         struct cmd_set_hash_global_config_result *res = parsed_result;
12344         struct rte_eth_hash_filter_info info;
12345         uint32_t ftype, idx, offset;
12346         int ret;
12347
12348         if (rte_eth_dev_filter_supported(res->port_id,
12349                                 RTE_ETH_FILTER_HASH) < 0) {
12350                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12351                                                         res->port_id);
12352                 return;
12353         }
12354         memset(&info, 0, sizeof(info));
12355         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12356         if (!strcmp(res->hash_func, "toeplitz"))
12357                 info.info.global_conf.hash_func =
12358                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12359         else if (!strcmp(res->hash_func, "simple_xor"))
12360                 info.info.global_conf.hash_func =
12361                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12362         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12363                 info.info.global_conf.hash_func =
12364                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12365         else if (!strcmp(res->hash_func, "default"))
12366                 info.info.global_conf.hash_func =
12367                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12368
12369         ftype = str2flowtype(res->flow_type);
12370         idx = ftype / UINT64_BIT;
12371         offset = ftype % UINT64_BIT;
12372         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12373         if (!strcmp(res->enable, "enable"))
12374                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12375                                                 (1ULL << offset);
12376         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12377                                         RTE_ETH_FILTER_SET, &info);
12378         if (ret < 0)
12379                 printf("Cannot set global hash configurations by port %d\n",
12380                                                         res->port_id);
12381         else
12382                 printf("Global hash configurations have been set "
12383                         "successfully by port %d\n", res->port_id);
12384 }
12385
12386 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12387         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12388                 set_hash_global_config, "set_hash_global_config");
12389 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12390         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12391                 port_id, UINT16);
12392 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12393         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12394                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12395 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12396         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12397                 flow_type,
12398                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12399                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12400 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12401         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12402                 enable, "enable#disable");
12403
12404 cmdline_parse_inst_t cmd_set_hash_global_config = {
12405         .f = cmd_set_hash_global_config_parsed,
12406         .data = NULL,
12407         .help_str = "set_hash_global_config <port_id> "
12408                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12409                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12410                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12411                 "l2_payload enable|disable",
12412         .tokens = {
12413                 (void *)&cmd_set_hash_global_config_all,
12414                 (void *)&cmd_set_hash_global_config_port_id,
12415                 (void *)&cmd_set_hash_global_config_hash_func,
12416                 (void *)&cmd_set_hash_global_config_flow_type,
12417                 (void *)&cmd_set_hash_global_config_enable,
12418                 NULL,
12419         },
12420 };
12421
12422 /* Set hash input set */
12423 struct cmd_set_hash_input_set_result {
12424         cmdline_fixed_string_t set_hash_input_set;
12425         portid_t port_id;
12426         cmdline_fixed_string_t flow_type;
12427         cmdline_fixed_string_t inset_field;
12428         cmdline_fixed_string_t select;
12429 };
12430
12431 static enum rte_eth_input_set_field
12432 str2inset(char *string)
12433 {
12434         uint16_t i;
12435
12436         static const struct {
12437                 char str[32];
12438                 enum rte_eth_input_set_field inset;
12439         } inset_table[] = {
12440                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12441                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12442                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12443                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12444                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12445                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12446                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12447                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12448                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12449                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12450                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12451                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12452                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12453                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12454                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12455                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12456                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12457                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12458                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12459                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12460                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12461                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12462                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12463                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12464                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12465                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12466                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12467                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12468                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12469                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12470                 {"none", RTE_ETH_INPUT_SET_NONE},
12471         };
12472
12473         for (i = 0; i < RTE_DIM(inset_table); i++) {
12474                 if (!strcmp(string, inset_table[i].str))
12475                         return inset_table[i].inset;
12476         }
12477
12478         return RTE_ETH_INPUT_SET_UNKNOWN;
12479 }
12480
12481 static void
12482 cmd_set_hash_input_set_parsed(void *parsed_result,
12483                               __rte_unused struct cmdline *cl,
12484                               __rte_unused void *data)
12485 {
12486         struct cmd_set_hash_input_set_result *res = parsed_result;
12487         struct rte_eth_hash_filter_info info;
12488
12489         memset(&info, 0, sizeof(info));
12490         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12491         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12492         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12493         info.info.input_set_conf.inset_size = 1;
12494         if (!strcmp(res->select, "select"))
12495                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12496         else if (!strcmp(res->select, "add"))
12497                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12498         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12499                                 RTE_ETH_FILTER_SET, &info);
12500 }
12501
12502 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12503         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12504                 set_hash_input_set, "set_hash_input_set");
12505 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12506         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12507                 port_id, UINT16);
12508 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12509         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12510                 flow_type, NULL);
12511 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12512         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12513                 inset_field,
12514                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12515                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12516                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12517                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12518                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12519                 "fld-8th#none");
12520 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12521         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12522                 select, "select#add");
12523
12524 cmdline_parse_inst_t cmd_set_hash_input_set = {
12525         .f = cmd_set_hash_input_set_parsed,
12526         .data = NULL,
12527         .help_str = "set_hash_input_set <port_id> "
12528         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12529         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12530         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12531         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12532         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12533         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12534         "fld-7th|fld-8th|none select|add",
12535         .tokens = {
12536                 (void *)&cmd_set_hash_input_set_cmd,
12537                 (void *)&cmd_set_hash_input_set_port_id,
12538                 (void *)&cmd_set_hash_input_set_flow_type,
12539                 (void *)&cmd_set_hash_input_set_field,
12540                 (void *)&cmd_set_hash_input_set_select,
12541                 NULL,
12542         },
12543 };
12544
12545 /* Set flow director input set */
12546 struct cmd_set_fdir_input_set_result {
12547         cmdline_fixed_string_t set_fdir_input_set;
12548         portid_t port_id;
12549         cmdline_fixed_string_t flow_type;
12550         cmdline_fixed_string_t inset_field;
12551         cmdline_fixed_string_t select;
12552 };
12553
12554 static void
12555 cmd_set_fdir_input_set_parsed(void *parsed_result,
12556         __rte_unused struct cmdline *cl,
12557         __rte_unused void *data)
12558 {
12559         struct cmd_set_fdir_input_set_result *res = parsed_result;
12560         struct rte_eth_fdir_filter_info info;
12561
12562         memset(&info, 0, sizeof(info));
12563         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12564         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12565         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12566         info.info.input_set_conf.inset_size = 1;
12567         if (!strcmp(res->select, "select"))
12568                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12569         else if (!strcmp(res->select, "add"))
12570                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12571         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12572                 RTE_ETH_FILTER_SET, &info);
12573 }
12574
12575 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12576         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12577         set_fdir_input_set, "set_fdir_input_set");
12578 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12579         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12580         port_id, UINT16);
12581 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12582         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12583         flow_type,
12584         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12585         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12586 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12587         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12588         inset_field,
12589         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12590         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12591         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12592         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12593         "sctp-veri-tag#none");
12594 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12595         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12596         select, "select#add");
12597
12598 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12599         .f = cmd_set_fdir_input_set_parsed,
12600         .data = NULL,
12601         .help_str = "set_fdir_input_set <port_id> "
12602         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12603         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12604         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12605         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12606         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12607         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12608         "sctp-veri-tag|none select|add",
12609         .tokens = {
12610                 (void *)&cmd_set_fdir_input_set_cmd,
12611                 (void *)&cmd_set_fdir_input_set_port_id,
12612                 (void *)&cmd_set_fdir_input_set_flow_type,
12613                 (void *)&cmd_set_fdir_input_set_field,
12614                 (void *)&cmd_set_fdir_input_set_select,
12615                 NULL,
12616         },
12617 };
12618
12619 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12620 struct cmd_mcast_addr_result {
12621         cmdline_fixed_string_t mcast_addr_cmd;
12622         cmdline_fixed_string_t what;
12623         uint16_t port_num;
12624         struct rte_ether_addr mc_addr;
12625 };
12626
12627 static void cmd_mcast_addr_parsed(void *parsed_result,
12628                 __attribute__((unused)) struct cmdline *cl,
12629                 __attribute__((unused)) void *data)
12630 {
12631         struct cmd_mcast_addr_result *res = parsed_result;
12632
12633         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12634                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12635                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12636                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12637                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12638                 return;
12639         }
12640         if (strcmp(res->what, "add") == 0)
12641                 mcast_addr_add(res->port_num, &res->mc_addr);
12642         else
12643                 mcast_addr_remove(res->port_num, &res->mc_addr);
12644 }
12645
12646 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12647         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12648                                  mcast_addr_cmd, "mcast_addr");
12649 cmdline_parse_token_string_t cmd_mcast_addr_what =
12650         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12651                                  "add#remove");
12652 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12653         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12654 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12655         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12656
12657 cmdline_parse_inst_t cmd_mcast_addr = {
12658         .f = cmd_mcast_addr_parsed,
12659         .data = (void *)0,
12660         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12661                 "Add/Remove multicast MAC address on port_id",
12662         .tokens = {
12663                 (void *)&cmd_mcast_addr_cmd,
12664                 (void *)&cmd_mcast_addr_what,
12665                 (void *)&cmd_mcast_addr_portnum,
12666                 (void *)&cmd_mcast_addr_addr,
12667                 NULL,
12668         },
12669 };
12670
12671 /* l2 tunnel config
12672  * only support E-tag now.
12673  */
12674
12675 /* Ether type config */
12676 struct cmd_config_l2_tunnel_eth_type_result {
12677         cmdline_fixed_string_t port;
12678         cmdline_fixed_string_t config;
12679         cmdline_fixed_string_t all;
12680         portid_t id;
12681         cmdline_fixed_string_t l2_tunnel;
12682         cmdline_fixed_string_t l2_tunnel_type;
12683         cmdline_fixed_string_t eth_type;
12684         uint16_t eth_type_val;
12685 };
12686
12687 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12688         TOKEN_STRING_INITIALIZER
12689                 (struct cmd_config_l2_tunnel_eth_type_result,
12690                  port, "port");
12691 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12692         TOKEN_STRING_INITIALIZER
12693                 (struct cmd_config_l2_tunnel_eth_type_result,
12694                  config, "config");
12695 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12696         TOKEN_STRING_INITIALIZER
12697                 (struct cmd_config_l2_tunnel_eth_type_result,
12698                  all, "all");
12699 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12700         TOKEN_NUM_INITIALIZER
12701                 (struct cmd_config_l2_tunnel_eth_type_result,
12702                  id, UINT16);
12703 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12704         TOKEN_STRING_INITIALIZER
12705                 (struct cmd_config_l2_tunnel_eth_type_result,
12706                  l2_tunnel, "l2-tunnel");
12707 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12708         TOKEN_STRING_INITIALIZER
12709                 (struct cmd_config_l2_tunnel_eth_type_result,
12710                  l2_tunnel_type, "E-tag");
12711 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12712         TOKEN_STRING_INITIALIZER
12713                 (struct cmd_config_l2_tunnel_eth_type_result,
12714                  eth_type, "ether-type");
12715 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12716         TOKEN_NUM_INITIALIZER
12717                 (struct cmd_config_l2_tunnel_eth_type_result,
12718                  eth_type_val, UINT16);
12719
12720 static enum rte_eth_tunnel_type
12721 str2fdir_l2_tunnel_type(char *string)
12722 {
12723         uint32_t i = 0;
12724
12725         static const struct {
12726                 char str[32];
12727                 enum rte_eth_tunnel_type type;
12728         } l2_tunnel_type_str[] = {
12729                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12730         };
12731
12732         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12733                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12734                         return l2_tunnel_type_str[i].type;
12735         }
12736         return RTE_TUNNEL_TYPE_NONE;
12737 }
12738
12739 /* ether type config for all ports */
12740 static void
12741 cmd_config_l2_tunnel_eth_type_all_parsed
12742         (void *parsed_result,
12743          __attribute__((unused)) struct cmdline *cl,
12744          __attribute__((unused)) void *data)
12745 {
12746         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12747         struct rte_eth_l2_tunnel_conf entry;
12748         portid_t pid;
12749
12750         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12751         entry.ether_type = res->eth_type_val;
12752
12753         RTE_ETH_FOREACH_DEV(pid) {
12754                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12755         }
12756 }
12757
12758 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12759         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12760         .data = NULL,
12761         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12762         .tokens = {
12763                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12764                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12765                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12766                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12767                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12768                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12769                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12770                 NULL,
12771         },
12772 };
12773
12774 /* ether type config for a specific port */
12775 static void
12776 cmd_config_l2_tunnel_eth_type_specific_parsed(
12777         void *parsed_result,
12778         __attribute__((unused)) struct cmdline *cl,
12779         __attribute__((unused)) void *data)
12780 {
12781         struct cmd_config_l2_tunnel_eth_type_result *res =
12782                  parsed_result;
12783         struct rte_eth_l2_tunnel_conf entry;
12784
12785         if (port_id_is_invalid(res->id, ENABLED_WARN))
12786                 return;
12787
12788         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12789         entry.ether_type = res->eth_type_val;
12790
12791         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12792 }
12793
12794 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12795         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12796         .data = NULL,
12797         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12798         .tokens = {
12799                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12800                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12801                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12802                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12803                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12804                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12805                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12806                 NULL,
12807         },
12808 };
12809
12810 /* Enable/disable l2 tunnel */
12811 struct cmd_config_l2_tunnel_en_dis_result {
12812         cmdline_fixed_string_t port;
12813         cmdline_fixed_string_t config;
12814         cmdline_fixed_string_t all;
12815         portid_t id;
12816         cmdline_fixed_string_t l2_tunnel;
12817         cmdline_fixed_string_t l2_tunnel_type;
12818         cmdline_fixed_string_t en_dis;
12819 };
12820
12821 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12822         TOKEN_STRING_INITIALIZER
12823                 (struct cmd_config_l2_tunnel_en_dis_result,
12824                  port, "port");
12825 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12826         TOKEN_STRING_INITIALIZER
12827                 (struct cmd_config_l2_tunnel_en_dis_result,
12828                  config, "config");
12829 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12830         TOKEN_STRING_INITIALIZER
12831                 (struct cmd_config_l2_tunnel_en_dis_result,
12832                  all, "all");
12833 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12834         TOKEN_NUM_INITIALIZER
12835                 (struct cmd_config_l2_tunnel_en_dis_result,
12836                  id, UINT16);
12837 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12838         TOKEN_STRING_INITIALIZER
12839                 (struct cmd_config_l2_tunnel_en_dis_result,
12840                  l2_tunnel, "l2-tunnel");
12841 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12842         TOKEN_STRING_INITIALIZER
12843                 (struct cmd_config_l2_tunnel_en_dis_result,
12844                  l2_tunnel_type, "E-tag");
12845 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12846         TOKEN_STRING_INITIALIZER
12847                 (struct cmd_config_l2_tunnel_en_dis_result,
12848                  en_dis, "enable#disable");
12849
12850 /* enable/disable l2 tunnel for all ports */
12851 static void
12852 cmd_config_l2_tunnel_en_dis_all_parsed(
12853         void *parsed_result,
12854         __attribute__((unused)) struct cmdline *cl,
12855         __attribute__((unused)) void *data)
12856 {
12857         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12858         struct rte_eth_l2_tunnel_conf entry;
12859         portid_t pid;
12860         uint8_t en;
12861
12862         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12863
12864         if (!strcmp("enable", res->en_dis))
12865                 en = 1;
12866         else
12867                 en = 0;
12868
12869         RTE_ETH_FOREACH_DEV(pid) {
12870                 rte_eth_dev_l2_tunnel_offload_set(pid,
12871                                                   &entry,
12872                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12873                                                   en);
12874         }
12875 }
12876
12877 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12878         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12879         .data = NULL,
12880         .help_str = "port config all l2-tunnel E-tag enable|disable",
12881         .tokens = {
12882                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12883                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12884                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12885                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12886                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12887                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12888                 NULL,
12889         },
12890 };
12891
12892 /* enable/disable l2 tunnel for a port */
12893 static void
12894 cmd_config_l2_tunnel_en_dis_specific_parsed(
12895         void *parsed_result,
12896         __attribute__((unused)) struct cmdline *cl,
12897         __attribute__((unused)) void *data)
12898 {
12899         struct cmd_config_l2_tunnel_en_dis_result *res =
12900                 parsed_result;
12901         struct rte_eth_l2_tunnel_conf entry;
12902
12903         if (port_id_is_invalid(res->id, ENABLED_WARN))
12904                 return;
12905
12906         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12907
12908         if (!strcmp("enable", res->en_dis))
12909                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12910                                                   &entry,
12911                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12912                                                   1);
12913         else
12914                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12915                                                   &entry,
12916                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12917                                                   0);
12918 }
12919
12920 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12921         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12922         .data = NULL,
12923         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12924         .tokens = {
12925                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12926                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12927                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12928                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12929                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12930                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12931                 NULL,
12932         },
12933 };
12934
12935 /* E-tag configuration */
12936
12937 /* Common result structure for all E-tag configuration */
12938 struct cmd_config_e_tag_result {
12939         cmdline_fixed_string_t e_tag;
12940         cmdline_fixed_string_t set;
12941         cmdline_fixed_string_t insertion;
12942         cmdline_fixed_string_t stripping;
12943         cmdline_fixed_string_t forwarding;
12944         cmdline_fixed_string_t filter;
12945         cmdline_fixed_string_t add;
12946         cmdline_fixed_string_t del;
12947         cmdline_fixed_string_t on;
12948         cmdline_fixed_string_t off;
12949         cmdline_fixed_string_t on_off;
12950         cmdline_fixed_string_t port_tag_id;
12951         uint32_t port_tag_id_val;
12952         cmdline_fixed_string_t e_tag_id;
12953         uint16_t e_tag_id_val;
12954         cmdline_fixed_string_t dst_pool;
12955         uint8_t dst_pool_val;
12956         cmdline_fixed_string_t port;
12957         portid_t port_id;
12958         cmdline_fixed_string_t vf;
12959         uint8_t vf_id;
12960 };
12961
12962 /* Common CLI fields for all E-tag configuration */
12963 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12964         TOKEN_STRING_INITIALIZER
12965                 (struct cmd_config_e_tag_result,
12966                  e_tag, "E-tag");
12967 cmdline_parse_token_string_t cmd_config_e_tag_set =
12968         TOKEN_STRING_INITIALIZER
12969                 (struct cmd_config_e_tag_result,
12970                  set, "set");
12971 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12972         TOKEN_STRING_INITIALIZER
12973                 (struct cmd_config_e_tag_result,
12974                  insertion, "insertion");
12975 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12976         TOKEN_STRING_INITIALIZER
12977                 (struct cmd_config_e_tag_result,
12978                  stripping, "stripping");
12979 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12980         TOKEN_STRING_INITIALIZER
12981                 (struct cmd_config_e_tag_result,
12982                  forwarding, "forwarding");
12983 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12984         TOKEN_STRING_INITIALIZER
12985                 (struct cmd_config_e_tag_result,
12986                  filter, "filter");
12987 cmdline_parse_token_string_t cmd_config_e_tag_add =
12988         TOKEN_STRING_INITIALIZER
12989                 (struct cmd_config_e_tag_result,
12990                  add, "add");
12991 cmdline_parse_token_string_t cmd_config_e_tag_del =
12992         TOKEN_STRING_INITIALIZER
12993                 (struct cmd_config_e_tag_result,
12994                  del, "del");
12995 cmdline_parse_token_string_t cmd_config_e_tag_on =
12996         TOKEN_STRING_INITIALIZER
12997                 (struct cmd_config_e_tag_result,
12998                  on, "on");
12999 cmdline_parse_token_string_t cmd_config_e_tag_off =
13000         TOKEN_STRING_INITIALIZER
13001                 (struct cmd_config_e_tag_result,
13002                  off, "off");
13003 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13004         TOKEN_STRING_INITIALIZER
13005                 (struct cmd_config_e_tag_result,
13006                  on_off, "on#off");
13007 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13008         TOKEN_STRING_INITIALIZER
13009                 (struct cmd_config_e_tag_result,
13010                  port_tag_id, "port-tag-id");
13011 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13012         TOKEN_NUM_INITIALIZER
13013                 (struct cmd_config_e_tag_result,
13014                  port_tag_id_val, UINT32);
13015 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13016         TOKEN_STRING_INITIALIZER
13017                 (struct cmd_config_e_tag_result,
13018                  e_tag_id, "e-tag-id");
13019 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13020         TOKEN_NUM_INITIALIZER
13021                 (struct cmd_config_e_tag_result,
13022                  e_tag_id_val, UINT16);
13023 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13024         TOKEN_STRING_INITIALIZER
13025                 (struct cmd_config_e_tag_result,
13026                  dst_pool, "dst-pool");
13027 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13028         TOKEN_NUM_INITIALIZER
13029                 (struct cmd_config_e_tag_result,
13030                  dst_pool_val, UINT8);
13031 cmdline_parse_token_string_t cmd_config_e_tag_port =
13032         TOKEN_STRING_INITIALIZER
13033                 (struct cmd_config_e_tag_result,
13034                  port, "port");
13035 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13036         TOKEN_NUM_INITIALIZER
13037                 (struct cmd_config_e_tag_result,
13038                  port_id, UINT16);
13039 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13040         TOKEN_STRING_INITIALIZER
13041                 (struct cmd_config_e_tag_result,
13042                  vf, "vf");
13043 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13044         TOKEN_NUM_INITIALIZER
13045                 (struct cmd_config_e_tag_result,
13046                  vf_id, UINT8);
13047
13048 /* E-tag insertion configuration */
13049 static void
13050 cmd_config_e_tag_insertion_en_parsed(
13051         void *parsed_result,
13052         __attribute__((unused)) struct cmdline *cl,
13053         __attribute__((unused)) void *data)
13054 {
13055         struct cmd_config_e_tag_result *res =
13056                 parsed_result;
13057         struct rte_eth_l2_tunnel_conf entry;
13058
13059         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13060                 return;
13061
13062         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13063         entry.tunnel_id = res->port_tag_id_val;
13064         entry.vf_id = res->vf_id;
13065         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13066                                           &entry,
13067                                           ETH_L2_TUNNEL_INSERTION_MASK,
13068                                           1);
13069 }
13070
13071 static void
13072 cmd_config_e_tag_insertion_dis_parsed(
13073         void *parsed_result,
13074         __attribute__((unused)) struct cmdline *cl,
13075         __attribute__((unused)) void *data)
13076 {
13077         struct cmd_config_e_tag_result *res =
13078                 parsed_result;
13079         struct rte_eth_l2_tunnel_conf entry;
13080
13081         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13082                 return;
13083
13084         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13085         entry.vf_id = res->vf_id;
13086
13087         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13088                                           &entry,
13089                                           ETH_L2_TUNNEL_INSERTION_MASK,
13090                                           0);
13091 }
13092
13093 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13094         .f = cmd_config_e_tag_insertion_en_parsed,
13095         .data = NULL,
13096         .help_str = "E-tag ... : E-tag insertion enable",
13097         .tokens = {
13098                 (void *)&cmd_config_e_tag_e_tag,
13099                 (void *)&cmd_config_e_tag_set,
13100                 (void *)&cmd_config_e_tag_insertion,
13101                 (void *)&cmd_config_e_tag_on,
13102                 (void *)&cmd_config_e_tag_port_tag_id,
13103                 (void *)&cmd_config_e_tag_port_tag_id_val,
13104                 (void *)&cmd_config_e_tag_port,
13105                 (void *)&cmd_config_e_tag_port_id,
13106                 (void *)&cmd_config_e_tag_vf,
13107                 (void *)&cmd_config_e_tag_vf_id,
13108                 NULL,
13109         },
13110 };
13111
13112 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13113         .f = cmd_config_e_tag_insertion_dis_parsed,
13114         .data = NULL,
13115         .help_str = "E-tag ... : E-tag insertion disable",
13116         .tokens = {
13117                 (void *)&cmd_config_e_tag_e_tag,
13118                 (void *)&cmd_config_e_tag_set,
13119                 (void *)&cmd_config_e_tag_insertion,
13120                 (void *)&cmd_config_e_tag_off,
13121                 (void *)&cmd_config_e_tag_port,
13122                 (void *)&cmd_config_e_tag_port_id,
13123                 (void *)&cmd_config_e_tag_vf,
13124                 (void *)&cmd_config_e_tag_vf_id,
13125                 NULL,
13126         },
13127 };
13128
13129 /* E-tag stripping configuration */
13130 static void
13131 cmd_config_e_tag_stripping_parsed(
13132         void *parsed_result,
13133         __attribute__((unused)) struct cmdline *cl,
13134         __attribute__((unused)) void *data)
13135 {
13136         struct cmd_config_e_tag_result *res =
13137                 parsed_result;
13138         struct rte_eth_l2_tunnel_conf entry;
13139
13140         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13141                 return;
13142
13143         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13144
13145         if (!strcmp(res->on_off, "on"))
13146                 rte_eth_dev_l2_tunnel_offload_set
13147                         (res->port_id,
13148                          &entry,
13149                          ETH_L2_TUNNEL_STRIPPING_MASK,
13150                          1);
13151         else
13152                 rte_eth_dev_l2_tunnel_offload_set
13153                         (res->port_id,
13154                          &entry,
13155                          ETH_L2_TUNNEL_STRIPPING_MASK,
13156                          0);
13157 }
13158
13159 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13160         .f = cmd_config_e_tag_stripping_parsed,
13161         .data = NULL,
13162         .help_str = "E-tag ... : E-tag stripping enable/disable",
13163         .tokens = {
13164                 (void *)&cmd_config_e_tag_e_tag,
13165                 (void *)&cmd_config_e_tag_set,
13166                 (void *)&cmd_config_e_tag_stripping,
13167                 (void *)&cmd_config_e_tag_on_off,
13168                 (void *)&cmd_config_e_tag_port,
13169                 (void *)&cmd_config_e_tag_port_id,
13170                 NULL,
13171         },
13172 };
13173
13174 /* E-tag forwarding configuration */
13175 static void
13176 cmd_config_e_tag_forwarding_parsed(
13177         void *parsed_result,
13178         __attribute__((unused)) struct cmdline *cl,
13179         __attribute__((unused)) void *data)
13180 {
13181         struct cmd_config_e_tag_result *res = parsed_result;
13182         struct rte_eth_l2_tunnel_conf entry;
13183
13184         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13185                 return;
13186
13187         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13188
13189         if (!strcmp(res->on_off, "on"))
13190                 rte_eth_dev_l2_tunnel_offload_set
13191                         (res->port_id,
13192                          &entry,
13193                          ETH_L2_TUNNEL_FORWARDING_MASK,
13194                          1);
13195         else
13196                 rte_eth_dev_l2_tunnel_offload_set
13197                         (res->port_id,
13198                          &entry,
13199                          ETH_L2_TUNNEL_FORWARDING_MASK,
13200                          0);
13201 }
13202
13203 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13204         .f = cmd_config_e_tag_forwarding_parsed,
13205         .data = NULL,
13206         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13207         .tokens = {
13208                 (void *)&cmd_config_e_tag_e_tag,
13209                 (void *)&cmd_config_e_tag_set,
13210                 (void *)&cmd_config_e_tag_forwarding,
13211                 (void *)&cmd_config_e_tag_on_off,
13212                 (void *)&cmd_config_e_tag_port,
13213                 (void *)&cmd_config_e_tag_port_id,
13214                 NULL,
13215         },
13216 };
13217
13218 /* E-tag filter configuration */
13219 static void
13220 cmd_config_e_tag_filter_add_parsed(
13221         void *parsed_result,
13222         __attribute__((unused)) struct cmdline *cl,
13223         __attribute__((unused)) void *data)
13224 {
13225         struct cmd_config_e_tag_result *res = parsed_result;
13226         struct rte_eth_l2_tunnel_conf entry;
13227         int ret = 0;
13228
13229         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13230                 return;
13231
13232         if (res->e_tag_id_val > 0x3fff) {
13233                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13234                 return;
13235         }
13236
13237         ret = rte_eth_dev_filter_supported(res->port_id,
13238                                            RTE_ETH_FILTER_L2_TUNNEL);
13239         if (ret < 0) {
13240                 printf("E-tag filter is not supported on port %u.\n",
13241                        res->port_id);
13242                 return;
13243         }
13244
13245         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13246         entry.tunnel_id = res->e_tag_id_val;
13247         entry.pool = res->dst_pool_val;
13248
13249         ret = rte_eth_dev_filter_ctrl(res->port_id,
13250                                       RTE_ETH_FILTER_L2_TUNNEL,
13251                                       RTE_ETH_FILTER_ADD,
13252                                       &entry);
13253         if (ret < 0)
13254                 printf("E-tag filter programming error: (%s)\n",
13255                        strerror(-ret));
13256 }
13257
13258 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13259         .f = cmd_config_e_tag_filter_add_parsed,
13260         .data = NULL,
13261         .help_str = "E-tag ... : E-tag filter add",
13262         .tokens = {
13263                 (void *)&cmd_config_e_tag_e_tag,
13264                 (void *)&cmd_config_e_tag_set,
13265                 (void *)&cmd_config_e_tag_filter,
13266                 (void *)&cmd_config_e_tag_add,
13267                 (void *)&cmd_config_e_tag_e_tag_id,
13268                 (void *)&cmd_config_e_tag_e_tag_id_val,
13269                 (void *)&cmd_config_e_tag_dst_pool,
13270                 (void *)&cmd_config_e_tag_dst_pool_val,
13271                 (void *)&cmd_config_e_tag_port,
13272                 (void *)&cmd_config_e_tag_port_id,
13273                 NULL,
13274         },
13275 };
13276
13277 static void
13278 cmd_config_e_tag_filter_del_parsed(
13279         void *parsed_result,
13280         __attribute__((unused)) struct cmdline *cl,
13281         __attribute__((unused)) void *data)
13282 {
13283         struct cmd_config_e_tag_result *res = parsed_result;
13284         struct rte_eth_l2_tunnel_conf entry;
13285         int ret = 0;
13286
13287         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13288                 return;
13289
13290         if (res->e_tag_id_val > 0x3fff) {
13291                 printf("e-tag-id must be less than 0x3fff.\n");
13292                 return;
13293         }
13294
13295         ret = rte_eth_dev_filter_supported(res->port_id,
13296                                            RTE_ETH_FILTER_L2_TUNNEL);
13297         if (ret < 0) {
13298                 printf("E-tag filter is not supported on port %u.\n",
13299                        res->port_id);
13300                 return;
13301         }
13302
13303         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13304         entry.tunnel_id = res->e_tag_id_val;
13305
13306         ret = rte_eth_dev_filter_ctrl(res->port_id,
13307                                       RTE_ETH_FILTER_L2_TUNNEL,
13308                                       RTE_ETH_FILTER_DELETE,
13309                                       &entry);
13310         if (ret < 0)
13311                 printf("E-tag filter programming error: (%s)\n",
13312                        strerror(-ret));
13313 }
13314
13315 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13316         .f = cmd_config_e_tag_filter_del_parsed,
13317         .data = NULL,
13318         .help_str = "E-tag ... : E-tag filter delete",
13319         .tokens = {
13320                 (void *)&cmd_config_e_tag_e_tag,
13321                 (void *)&cmd_config_e_tag_set,
13322                 (void *)&cmd_config_e_tag_filter,
13323                 (void *)&cmd_config_e_tag_del,
13324                 (void *)&cmd_config_e_tag_e_tag_id,
13325                 (void *)&cmd_config_e_tag_e_tag_id_val,
13326                 (void *)&cmd_config_e_tag_port,
13327                 (void *)&cmd_config_e_tag_port_id,
13328                 NULL,
13329         },
13330 };
13331
13332 /* vf vlan anti spoof configuration */
13333
13334 /* Common result structure for vf vlan anti spoof */
13335 struct cmd_vf_vlan_anti_spoof_result {
13336         cmdline_fixed_string_t set;
13337         cmdline_fixed_string_t vf;
13338         cmdline_fixed_string_t vlan;
13339         cmdline_fixed_string_t antispoof;
13340         portid_t port_id;
13341         uint32_t vf_id;
13342         cmdline_fixed_string_t on_off;
13343 };
13344
13345 /* Common CLI fields for vf vlan anti spoof enable disable */
13346 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13347         TOKEN_STRING_INITIALIZER
13348                 (struct cmd_vf_vlan_anti_spoof_result,
13349                  set, "set");
13350 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13351         TOKEN_STRING_INITIALIZER
13352                 (struct cmd_vf_vlan_anti_spoof_result,
13353                  vf, "vf");
13354 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13355         TOKEN_STRING_INITIALIZER
13356                 (struct cmd_vf_vlan_anti_spoof_result,
13357                  vlan, "vlan");
13358 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13359         TOKEN_STRING_INITIALIZER
13360                 (struct cmd_vf_vlan_anti_spoof_result,
13361                  antispoof, "antispoof");
13362 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13363         TOKEN_NUM_INITIALIZER
13364                 (struct cmd_vf_vlan_anti_spoof_result,
13365                  port_id, UINT16);
13366 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13367         TOKEN_NUM_INITIALIZER
13368                 (struct cmd_vf_vlan_anti_spoof_result,
13369                  vf_id, UINT32);
13370 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13371         TOKEN_STRING_INITIALIZER
13372                 (struct cmd_vf_vlan_anti_spoof_result,
13373                  on_off, "on#off");
13374
13375 static void
13376 cmd_set_vf_vlan_anti_spoof_parsed(
13377         void *parsed_result,
13378         __attribute__((unused)) struct cmdline *cl,
13379         __attribute__((unused)) void *data)
13380 {
13381         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13382         int ret = -ENOTSUP;
13383
13384         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13385
13386         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13387                 return;
13388
13389 #ifdef RTE_LIBRTE_IXGBE_PMD
13390         if (ret == -ENOTSUP)
13391                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13392                                 res->vf_id, is_on);
13393 #endif
13394 #ifdef RTE_LIBRTE_I40E_PMD
13395         if (ret == -ENOTSUP)
13396                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13397                                 res->vf_id, is_on);
13398 #endif
13399 #ifdef RTE_LIBRTE_BNXT_PMD
13400         if (ret == -ENOTSUP)
13401                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13402                                 res->vf_id, is_on);
13403 #endif
13404
13405         switch (ret) {
13406         case 0:
13407                 break;
13408         case -EINVAL:
13409                 printf("invalid vf_id %d\n", res->vf_id);
13410                 break;
13411         case -ENODEV:
13412                 printf("invalid port_id %d\n", res->port_id);
13413                 break;
13414         case -ENOTSUP:
13415                 printf("function not implemented\n");
13416                 break;
13417         default:
13418                 printf("programming error: (%s)\n", strerror(-ret));
13419         }
13420 }
13421
13422 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13423         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13424         .data = NULL,
13425         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13426         .tokens = {
13427                 (void *)&cmd_vf_vlan_anti_spoof_set,
13428                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13429                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13430                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13431                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13432                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13433                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13434                 NULL,
13435         },
13436 };
13437
13438 /* vf mac anti spoof configuration */
13439
13440 /* Common result structure for vf mac anti spoof */
13441 struct cmd_vf_mac_anti_spoof_result {
13442         cmdline_fixed_string_t set;
13443         cmdline_fixed_string_t vf;
13444         cmdline_fixed_string_t mac;
13445         cmdline_fixed_string_t antispoof;
13446         portid_t port_id;
13447         uint32_t vf_id;
13448         cmdline_fixed_string_t on_off;
13449 };
13450
13451 /* Common CLI fields for vf mac anti spoof enable disable */
13452 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13453         TOKEN_STRING_INITIALIZER
13454                 (struct cmd_vf_mac_anti_spoof_result,
13455                  set, "set");
13456 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13457         TOKEN_STRING_INITIALIZER
13458                 (struct cmd_vf_mac_anti_spoof_result,
13459                  vf, "vf");
13460 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13461         TOKEN_STRING_INITIALIZER
13462                 (struct cmd_vf_mac_anti_spoof_result,
13463                  mac, "mac");
13464 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13465         TOKEN_STRING_INITIALIZER
13466                 (struct cmd_vf_mac_anti_spoof_result,
13467                  antispoof, "antispoof");
13468 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13469         TOKEN_NUM_INITIALIZER
13470                 (struct cmd_vf_mac_anti_spoof_result,
13471                  port_id, UINT16);
13472 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13473         TOKEN_NUM_INITIALIZER
13474                 (struct cmd_vf_mac_anti_spoof_result,
13475                  vf_id, UINT32);
13476 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13477         TOKEN_STRING_INITIALIZER
13478                 (struct cmd_vf_mac_anti_spoof_result,
13479                  on_off, "on#off");
13480
13481 static void
13482 cmd_set_vf_mac_anti_spoof_parsed(
13483         void *parsed_result,
13484         __attribute__((unused)) struct cmdline *cl,
13485         __attribute__((unused)) void *data)
13486 {
13487         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13488         int ret = -ENOTSUP;
13489
13490         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13491
13492         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13493                 return;
13494
13495 #ifdef RTE_LIBRTE_IXGBE_PMD
13496         if (ret == -ENOTSUP)
13497                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13498                         res->vf_id, is_on);
13499 #endif
13500 #ifdef RTE_LIBRTE_I40E_PMD
13501         if (ret == -ENOTSUP)
13502                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13503                         res->vf_id, is_on);
13504 #endif
13505 #ifdef RTE_LIBRTE_BNXT_PMD
13506         if (ret == -ENOTSUP)
13507                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13508                         res->vf_id, is_on);
13509 #endif
13510
13511         switch (ret) {
13512         case 0:
13513                 break;
13514         case -EINVAL:
13515                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13516                 break;
13517         case -ENODEV:
13518                 printf("invalid port_id %d\n", res->port_id);
13519                 break;
13520         case -ENOTSUP:
13521                 printf("function not implemented\n");
13522                 break;
13523         default:
13524                 printf("programming error: (%s)\n", strerror(-ret));
13525         }
13526 }
13527
13528 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13529         .f = cmd_set_vf_mac_anti_spoof_parsed,
13530         .data = NULL,
13531         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13532         .tokens = {
13533                 (void *)&cmd_vf_mac_anti_spoof_set,
13534                 (void *)&cmd_vf_mac_anti_spoof_vf,
13535                 (void *)&cmd_vf_mac_anti_spoof_mac,
13536                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13537                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13538                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13539                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13540                 NULL,
13541         },
13542 };
13543
13544 /* vf vlan strip queue configuration */
13545
13546 /* Common result structure for vf mac anti spoof */
13547 struct cmd_vf_vlan_stripq_result {
13548         cmdline_fixed_string_t set;
13549         cmdline_fixed_string_t vf;
13550         cmdline_fixed_string_t vlan;
13551         cmdline_fixed_string_t stripq;
13552         portid_t port_id;
13553         uint16_t vf_id;
13554         cmdline_fixed_string_t on_off;
13555 };
13556
13557 /* Common CLI fields for vf vlan strip enable disable */
13558 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13559         TOKEN_STRING_INITIALIZER
13560                 (struct cmd_vf_vlan_stripq_result,
13561                  set, "set");
13562 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13563         TOKEN_STRING_INITIALIZER
13564                 (struct cmd_vf_vlan_stripq_result,
13565                  vf, "vf");
13566 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13567         TOKEN_STRING_INITIALIZER
13568                 (struct cmd_vf_vlan_stripq_result,
13569                  vlan, "vlan");
13570 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13571         TOKEN_STRING_INITIALIZER
13572                 (struct cmd_vf_vlan_stripq_result,
13573                  stripq, "stripq");
13574 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13575         TOKEN_NUM_INITIALIZER
13576                 (struct cmd_vf_vlan_stripq_result,
13577                  port_id, UINT16);
13578 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13579         TOKEN_NUM_INITIALIZER
13580                 (struct cmd_vf_vlan_stripq_result,
13581                  vf_id, UINT16);
13582 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13583         TOKEN_STRING_INITIALIZER
13584                 (struct cmd_vf_vlan_stripq_result,
13585                  on_off, "on#off");
13586
13587 static void
13588 cmd_set_vf_vlan_stripq_parsed(
13589         void *parsed_result,
13590         __attribute__((unused)) struct cmdline *cl,
13591         __attribute__((unused)) void *data)
13592 {
13593         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13594         int ret = -ENOTSUP;
13595
13596         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13597
13598         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13599                 return;
13600
13601 #ifdef RTE_LIBRTE_IXGBE_PMD
13602         if (ret == -ENOTSUP)
13603                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13604                         res->vf_id, is_on);
13605 #endif
13606 #ifdef RTE_LIBRTE_I40E_PMD
13607         if (ret == -ENOTSUP)
13608                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13609                         res->vf_id, is_on);
13610 #endif
13611 #ifdef RTE_LIBRTE_BNXT_PMD
13612         if (ret == -ENOTSUP)
13613                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13614                         res->vf_id, is_on);
13615 #endif
13616
13617         switch (ret) {
13618         case 0:
13619                 break;
13620         case -EINVAL:
13621                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13622                 break;
13623         case -ENODEV:
13624                 printf("invalid port_id %d\n", res->port_id);
13625                 break;
13626         case -ENOTSUP:
13627                 printf("function not implemented\n");
13628                 break;
13629         default:
13630                 printf("programming error: (%s)\n", strerror(-ret));
13631         }
13632 }
13633
13634 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13635         .f = cmd_set_vf_vlan_stripq_parsed,
13636         .data = NULL,
13637         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13638         .tokens = {
13639                 (void *)&cmd_vf_vlan_stripq_set,
13640                 (void *)&cmd_vf_vlan_stripq_vf,
13641                 (void *)&cmd_vf_vlan_stripq_vlan,
13642                 (void *)&cmd_vf_vlan_stripq_stripq,
13643                 (void *)&cmd_vf_vlan_stripq_port_id,
13644                 (void *)&cmd_vf_vlan_stripq_vf_id,
13645                 (void *)&cmd_vf_vlan_stripq_on_off,
13646                 NULL,
13647         },
13648 };
13649
13650 /* vf vlan insert configuration */
13651
13652 /* Common result structure for vf vlan insert */
13653 struct cmd_vf_vlan_insert_result {
13654         cmdline_fixed_string_t set;
13655         cmdline_fixed_string_t vf;
13656         cmdline_fixed_string_t vlan;
13657         cmdline_fixed_string_t insert;
13658         portid_t port_id;
13659         uint16_t vf_id;
13660         uint16_t vlan_id;
13661 };
13662
13663 /* Common CLI fields for vf vlan insert enable disable */
13664 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13665         TOKEN_STRING_INITIALIZER
13666                 (struct cmd_vf_vlan_insert_result,
13667                  set, "set");
13668 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13669         TOKEN_STRING_INITIALIZER
13670                 (struct cmd_vf_vlan_insert_result,
13671                  vf, "vf");
13672 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13673         TOKEN_STRING_INITIALIZER
13674                 (struct cmd_vf_vlan_insert_result,
13675                  vlan, "vlan");
13676 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13677         TOKEN_STRING_INITIALIZER
13678                 (struct cmd_vf_vlan_insert_result,
13679                  insert, "insert");
13680 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13681         TOKEN_NUM_INITIALIZER
13682                 (struct cmd_vf_vlan_insert_result,
13683                  port_id, UINT16);
13684 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13685         TOKEN_NUM_INITIALIZER
13686                 (struct cmd_vf_vlan_insert_result,
13687                  vf_id, UINT16);
13688 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13689         TOKEN_NUM_INITIALIZER
13690                 (struct cmd_vf_vlan_insert_result,
13691                  vlan_id, UINT16);
13692
13693 static void
13694 cmd_set_vf_vlan_insert_parsed(
13695         void *parsed_result,
13696         __attribute__((unused)) struct cmdline *cl,
13697         __attribute__((unused)) void *data)
13698 {
13699         struct cmd_vf_vlan_insert_result *res = parsed_result;
13700         int ret = -ENOTSUP;
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_vf_vlan_insert(res->port_id, res->vf_id,
13708                         res->vlan_id);
13709 #endif
13710 #ifdef RTE_LIBRTE_I40E_PMD
13711         if (ret == -ENOTSUP)
13712                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13713                         res->vlan_id);
13714 #endif
13715 #ifdef RTE_LIBRTE_BNXT_PMD
13716         if (ret == -ENOTSUP)
13717                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13718                         res->vlan_id);
13719 #endif
13720
13721         switch (ret) {
13722         case 0:
13723                 break;
13724         case -EINVAL:
13725                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13726                 break;
13727         case -ENODEV:
13728                 printf("invalid port_id %d\n", res->port_id);
13729                 break;
13730         case -ENOTSUP:
13731                 printf("function not implemented\n");
13732                 break;
13733         default:
13734                 printf("programming error: (%s)\n", strerror(-ret));
13735         }
13736 }
13737
13738 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13739         .f = cmd_set_vf_vlan_insert_parsed,
13740         .data = NULL,
13741         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13742         .tokens = {
13743                 (void *)&cmd_vf_vlan_insert_set,
13744                 (void *)&cmd_vf_vlan_insert_vf,
13745                 (void *)&cmd_vf_vlan_insert_vlan,
13746                 (void *)&cmd_vf_vlan_insert_insert,
13747                 (void *)&cmd_vf_vlan_insert_port_id,
13748                 (void *)&cmd_vf_vlan_insert_vf_id,
13749                 (void *)&cmd_vf_vlan_insert_vlan_id,
13750                 NULL,
13751         },
13752 };
13753
13754 /* tx loopback configuration */
13755
13756 /* Common result structure for tx loopback */
13757 struct cmd_tx_loopback_result {
13758         cmdline_fixed_string_t set;
13759         cmdline_fixed_string_t tx;
13760         cmdline_fixed_string_t loopback;
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_tx_loopback_set =
13767         TOKEN_STRING_INITIALIZER
13768                 (struct cmd_tx_loopback_result,
13769                  set, "set");
13770 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13771         TOKEN_STRING_INITIALIZER
13772                 (struct cmd_tx_loopback_result,
13773                  tx, "tx");
13774 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13775         TOKEN_STRING_INITIALIZER
13776                 (struct cmd_tx_loopback_result,
13777                  loopback, "loopback");
13778 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13779         TOKEN_NUM_INITIALIZER
13780                 (struct cmd_tx_loopback_result,
13781                  port_id, UINT16);
13782 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13783         TOKEN_STRING_INITIALIZER
13784                 (struct cmd_tx_loopback_result,
13785                  on_off, "on#off");
13786
13787 static void
13788 cmd_set_tx_loopback_parsed(
13789         void *parsed_result,
13790         __attribute__((unused)) struct cmdline *cl,
13791         __attribute__((unused)) void *data)
13792 {
13793         struct cmd_tx_loopback_result *res = parsed_result;
13794         int ret = -ENOTSUP;
13795
13796         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13797
13798         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13799                 return;
13800
13801 #ifdef RTE_LIBRTE_IXGBE_PMD
13802         if (ret == -ENOTSUP)
13803                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13804 #endif
13805 #ifdef RTE_LIBRTE_I40E_PMD
13806         if (ret == -ENOTSUP)
13807                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13808 #endif
13809 #ifdef RTE_LIBRTE_BNXT_PMD
13810         if (ret == -ENOTSUP)
13811                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13812 #endif
13813 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13814         if (ret == -ENOTSUP)
13815                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13816 #endif
13817
13818         switch (ret) {
13819         case 0:
13820                 break;
13821         case -EINVAL:
13822                 printf("invalid is_on %d\n", is_on);
13823                 break;
13824         case -ENODEV:
13825                 printf("invalid port_id %d\n", res->port_id);
13826                 break;
13827         case -ENOTSUP:
13828                 printf("function not implemented\n");
13829                 break;
13830         default:
13831                 printf("programming error: (%s)\n", strerror(-ret));
13832         }
13833 }
13834
13835 cmdline_parse_inst_t cmd_set_tx_loopback = {
13836         .f = cmd_set_tx_loopback_parsed,
13837         .data = NULL,
13838         .help_str = "set tx loopback <port_id> on|off",
13839         .tokens = {
13840                 (void *)&cmd_tx_loopback_set,
13841                 (void *)&cmd_tx_loopback_tx,
13842                 (void *)&cmd_tx_loopback_loopback,
13843                 (void *)&cmd_tx_loopback_port_id,
13844                 (void *)&cmd_tx_loopback_on_off,
13845                 NULL,
13846         },
13847 };
13848
13849 /* all queues drop enable configuration */
13850
13851 /* Common result structure for all queues drop enable */
13852 struct cmd_all_queues_drop_en_result {
13853         cmdline_fixed_string_t set;
13854         cmdline_fixed_string_t all;
13855         cmdline_fixed_string_t queues;
13856         cmdline_fixed_string_t drop;
13857         portid_t port_id;
13858         cmdline_fixed_string_t on_off;
13859 };
13860
13861 /* Common CLI fields for tx loopback enable disable */
13862 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13863         TOKEN_STRING_INITIALIZER
13864                 (struct cmd_all_queues_drop_en_result,
13865                  set, "set");
13866 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13867         TOKEN_STRING_INITIALIZER
13868                 (struct cmd_all_queues_drop_en_result,
13869                  all, "all");
13870 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13871         TOKEN_STRING_INITIALIZER
13872                 (struct cmd_all_queues_drop_en_result,
13873                  queues, "queues");
13874 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13875         TOKEN_STRING_INITIALIZER
13876                 (struct cmd_all_queues_drop_en_result,
13877                  drop, "drop");
13878 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13879         TOKEN_NUM_INITIALIZER
13880                 (struct cmd_all_queues_drop_en_result,
13881                  port_id, UINT16);
13882 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13883         TOKEN_STRING_INITIALIZER
13884                 (struct cmd_all_queues_drop_en_result,
13885                  on_off, "on#off");
13886
13887 static void
13888 cmd_set_all_queues_drop_en_parsed(
13889         void *parsed_result,
13890         __attribute__((unused)) struct cmdline *cl,
13891         __attribute__((unused)) void *data)
13892 {
13893         struct cmd_all_queues_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         if (ret == -ENOTSUP)
13902                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13903 #endif
13904 #ifdef RTE_LIBRTE_BNXT_PMD
13905         if (ret == -ENOTSUP)
13906                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13907 #endif
13908         switch (ret) {
13909         case 0:
13910                 break;
13911         case -EINVAL:
13912                 printf("invalid is_on %d\n", is_on);
13913                 break;
13914         case -ENODEV:
13915                 printf("invalid port_id %d\n", res->port_id);
13916                 break;
13917         case -ENOTSUP:
13918                 printf("function not implemented\n");
13919                 break;
13920         default:
13921                 printf("programming error: (%s)\n", strerror(-ret));
13922         }
13923 }
13924
13925 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13926         .f = cmd_set_all_queues_drop_en_parsed,
13927         .data = NULL,
13928         .help_str = "set all queues drop <port_id> on|off",
13929         .tokens = {
13930                 (void *)&cmd_all_queues_drop_en_set,
13931                 (void *)&cmd_all_queues_drop_en_all,
13932                 (void *)&cmd_all_queues_drop_en_queues,
13933                 (void *)&cmd_all_queues_drop_en_drop,
13934                 (void *)&cmd_all_queues_drop_en_port_id,
13935                 (void *)&cmd_all_queues_drop_en_on_off,
13936                 NULL,
13937         },
13938 };
13939
13940 /* vf split drop enable configuration */
13941
13942 /* Common result structure for vf split drop enable */
13943 struct cmd_vf_split_drop_en_result {
13944         cmdline_fixed_string_t set;
13945         cmdline_fixed_string_t vf;
13946         cmdline_fixed_string_t split;
13947         cmdline_fixed_string_t drop;
13948         portid_t port_id;
13949         uint16_t vf_id;
13950         cmdline_fixed_string_t on_off;
13951 };
13952
13953 /* Common CLI fields for vf split drop enable disable */
13954 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13955         TOKEN_STRING_INITIALIZER
13956                 (struct cmd_vf_split_drop_en_result,
13957                  set, "set");
13958 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13959         TOKEN_STRING_INITIALIZER
13960                 (struct cmd_vf_split_drop_en_result,
13961                  vf, "vf");
13962 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13963         TOKEN_STRING_INITIALIZER
13964                 (struct cmd_vf_split_drop_en_result,
13965                  split, "split");
13966 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13967         TOKEN_STRING_INITIALIZER
13968                 (struct cmd_vf_split_drop_en_result,
13969                  drop, "drop");
13970 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13971         TOKEN_NUM_INITIALIZER
13972                 (struct cmd_vf_split_drop_en_result,
13973                  port_id, UINT16);
13974 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13975         TOKEN_NUM_INITIALIZER
13976                 (struct cmd_vf_split_drop_en_result,
13977                  vf_id, UINT16);
13978 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13979         TOKEN_STRING_INITIALIZER
13980                 (struct cmd_vf_split_drop_en_result,
13981                  on_off, "on#off");
13982
13983 static void
13984 cmd_set_vf_split_drop_en_parsed(
13985         void *parsed_result,
13986         __attribute__((unused)) struct cmdline *cl,
13987         __attribute__((unused)) void *data)
13988 {
13989         struct cmd_vf_split_drop_en_result *res = parsed_result;
13990         int ret = -ENOTSUP;
13991         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13992
13993         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13994                 return;
13995
13996 #ifdef RTE_LIBRTE_IXGBE_PMD
13997         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13998                         is_on);
13999 #endif
14000         switch (ret) {
14001         case 0:
14002                 break;
14003         case -EINVAL:
14004                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14005                 break;
14006         case -ENODEV:
14007                 printf("invalid port_id %d\n", res->port_id);
14008                 break;
14009         case -ENOTSUP:
14010                 printf("not supported on port %d\n", res->port_id);
14011                 break;
14012         default:
14013                 printf("programming error: (%s)\n", strerror(-ret));
14014         }
14015 }
14016
14017 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14018         .f = cmd_set_vf_split_drop_en_parsed,
14019         .data = NULL,
14020         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14021         .tokens = {
14022                 (void *)&cmd_vf_split_drop_en_set,
14023                 (void *)&cmd_vf_split_drop_en_vf,
14024                 (void *)&cmd_vf_split_drop_en_split,
14025                 (void *)&cmd_vf_split_drop_en_drop,
14026                 (void *)&cmd_vf_split_drop_en_port_id,
14027                 (void *)&cmd_vf_split_drop_en_vf_id,
14028                 (void *)&cmd_vf_split_drop_en_on_off,
14029                 NULL,
14030         },
14031 };
14032
14033 /* vf mac address configuration */
14034
14035 /* Common result structure for vf mac address */
14036 struct cmd_set_vf_mac_addr_result {
14037         cmdline_fixed_string_t set;
14038         cmdline_fixed_string_t vf;
14039         cmdline_fixed_string_t mac;
14040         cmdline_fixed_string_t addr;
14041         portid_t port_id;
14042         uint16_t vf_id;
14043         struct rte_ether_addr mac_addr;
14044
14045 };
14046
14047 /* Common CLI fields for vf split drop enable disable */
14048 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14049         TOKEN_STRING_INITIALIZER
14050                 (struct cmd_set_vf_mac_addr_result,
14051                  set, "set");
14052 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14053         TOKEN_STRING_INITIALIZER
14054                 (struct cmd_set_vf_mac_addr_result,
14055                  vf, "vf");
14056 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14057         TOKEN_STRING_INITIALIZER
14058                 (struct cmd_set_vf_mac_addr_result,
14059                  mac, "mac");
14060 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14061         TOKEN_STRING_INITIALIZER
14062                 (struct cmd_set_vf_mac_addr_result,
14063                  addr, "addr");
14064 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14065         TOKEN_NUM_INITIALIZER
14066                 (struct cmd_set_vf_mac_addr_result,
14067                  port_id, UINT16);
14068 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14069         TOKEN_NUM_INITIALIZER
14070                 (struct cmd_set_vf_mac_addr_result,
14071                  vf_id, UINT16);
14072 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14073         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14074                  mac_addr);
14075
14076 static void
14077 cmd_set_vf_mac_addr_parsed(
14078         void *parsed_result,
14079         __attribute__((unused)) struct cmdline *cl,
14080         __attribute__((unused)) void *data)
14081 {
14082         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14083         int ret = -ENOTSUP;
14084
14085         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14086                 return;
14087
14088 #ifdef RTE_LIBRTE_IXGBE_PMD
14089         if (ret == -ENOTSUP)
14090                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14091                                 &res->mac_addr);
14092 #endif
14093 #ifdef RTE_LIBRTE_I40E_PMD
14094         if (ret == -ENOTSUP)
14095                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14096                                 &res->mac_addr);
14097 #endif
14098 #ifdef RTE_LIBRTE_BNXT_PMD
14099         if (ret == -ENOTSUP)
14100                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14101                                 &res->mac_addr);
14102 #endif
14103
14104         switch (ret) {
14105         case 0:
14106                 break;
14107         case -EINVAL:
14108                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14109                 break;
14110         case -ENODEV:
14111                 printf("invalid port_id %d\n", res->port_id);
14112                 break;
14113         case -ENOTSUP:
14114                 printf("function not implemented\n");
14115                 break;
14116         default:
14117                 printf("programming error: (%s)\n", strerror(-ret));
14118         }
14119 }
14120
14121 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14122         .f = cmd_set_vf_mac_addr_parsed,
14123         .data = NULL,
14124         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14125         .tokens = {
14126                 (void *)&cmd_set_vf_mac_addr_set,
14127                 (void *)&cmd_set_vf_mac_addr_vf,
14128                 (void *)&cmd_set_vf_mac_addr_mac,
14129                 (void *)&cmd_set_vf_mac_addr_addr,
14130                 (void *)&cmd_set_vf_mac_addr_port_id,
14131                 (void *)&cmd_set_vf_mac_addr_vf_id,
14132                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14133                 NULL,
14134         },
14135 };
14136
14137 /* MACsec configuration */
14138
14139 /* Common result structure for MACsec offload enable */
14140 struct cmd_macsec_offload_on_result {
14141         cmdline_fixed_string_t set;
14142         cmdline_fixed_string_t macsec;
14143         cmdline_fixed_string_t offload;
14144         portid_t port_id;
14145         cmdline_fixed_string_t on;
14146         cmdline_fixed_string_t encrypt;
14147         cmdline_fixed_string_t en_on_off;
14148         cmdline_fixed_string_t replay_protect;
14149         cmdline_fixed_string_t rp_on_off;
14150 };
14151
14152 /* Common CLI fields for MACsec offload disable */
14153 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14154         TOKEN_STRING_INITIALIZER
14155                 (struct cmd_macsec_offload_on_result,
14156                  set, "set");
14157 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14158         TOKEN_STRING_INITIALIZER
14159                 (struct cmd_macsec_offload_on_result,
14160                  macsec, "macsec");
14161 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14162         TOKEN_STRING_INITIALIZER
14163                 (struct cmd_macsec_offload_on_result,
14164                  offload, "offload");
14165 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14166         TOKEN_NUM_INITIALIZER
14167                 (struct cmd_macsec_offload_on_result,
14168                  port_id, UINT16);
14169 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14170         TOKEN_STRING_INITIALIZER
14171                 (struct cmd_macsec_offload_on_result,
14172                  on, "on");
14173 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14174         TOKEN_STRING_INITIALIZER
14175                 (struct cmd_macsec_offload_on_result,
14176                  encrypt, "encrypt");
14177 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14178         TOKEN_STRING_INITIALIZER
14179                 (struct cmd_macsec_offload_on_result,
14180                  en_on_off, "on#off");
14181 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14182         TOKEN_STRING_INITIALIZER
14183                 (struct cmd_macsec_offload_on_result,
14184                  replay_protect, "replay-protect");
14185 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14186         TOKEN_STRING_INITIALIZER
14187                 (struct cmd_macsec_offload_on_result,
14188                  rp_on_off, "on#off");
14189
14190 static void
14191 cmd_set_macsec_offload_on_parsed(
14192         void *parsed_result,
14193         __attribute__((unused)) struct cmdline *cl,
14194         __attribute__((unused)) void *data)
14195 {
14196         struct cmd_macsec_offload_on_result *res = parsed_result;
14197         int ret = -ENOTSUP;
14198         portid_t port_id = res->port_id;
14199         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14200         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14201         struct rte_eth_dev_info dev_info;
14202
14203         if (port_id_is_invalid(port_id, ENABLED_WARN))
14204                 return;
14205         if (!port_is_stopped(port_id)) {
14206                 printf("Please stop port %d first\n", port_id);
14207                 return;
14208         }
14209
14210         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14211         if (ret != 0)
14212                 return;
14213
14214         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14215 #ifdef RTE_LIBRTE_IXGBE_PMD
14216                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14217 #endif
14218         }
14219         RTE_SET_USED(en);
14220         RTE_SET_USED(rp);
14221
14222         switch (ret) {
14223         case 0:
14224                 ports[port_id].dev_conf.txmode.offloads |=
14225                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14226                 cmd_reconfig_device_queue(port_id, 1, 1);
14227                 break;
14228         case -ENODEV:
14229                 printf("invalid port_id %d\n", port_id);
14230                 break;
14231         case -ENOTSUP:
14232                 printf("not supported on port %d\n", port_id);
14233                 break;
14234         default:
14235                 printf("programming error: (%s)\n", strerror(-ret));
14236         }
14237 }
14238
14239 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14240         .f = cmd_set_macsec_offload_on_parsed,
14241         .data = NULL,
14242         .help_str = "set macsec offload <port_id> on "
14243                 "encrypt on|off replay-protect on|off",
14244         .tokens = {
14245                 (void *)&cmd_macsec_offload_on_set,
14246                 (void *)&cmd_macsec_offload_on_macsec,
14247                 (void *)&cmd_macsec_offload_on_offload,
14248                 (void *)&cmd_macsec_offload_on_port_id,
14249                 (void *)&cmd_macsec_offload_on_on,
14250                 (void *)&cmd_macsec_offload_on_encrypt,
14251                 (void *)&cmd_macsec_offload_on_en_on_off,
14252                 (void *)&cmd_macsec_offload_on_replay_protect,
14253                 (void *)&cmd_macsec_offload_on_rp_on_off,
14254                 NULL,
14255         },
14256 };
14257
14258 /* Common result structure for MACsec offload disable */
14259 struct cmd_macsec_offload_off_result {
14260         cmdline_fixed_string_t set;
14261         cmdline_fixed_string_t macsec;
14262         cmdline_fixed_string_t offload;
14263         portid_t port_id;
14264         cmdline_fixed_string_t off;
14265 };
14266
14267 /* Common CLI fields for MACsec offload disable */
14268 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14269         TOKEN_STRING_INITIALIZER
14270                 (struct cmd_macsec_offload_off_result,
14271                  set, "set");
14272 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14273         TOKEN_STRING_INITIALIZER
14274                 (struct cmd_macsec_offload_off_result,
14275                  macsec, "macsec");
14276 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14277         TOKEN_STRING_INITIALIZER
14278                 (struct cmd_macsec_offload_off_result,
14279                  offload, "offload");
14280 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14281         TOKEN_NUM_INITIALIZER
14282                 (struct cmd_macsec_offload_off_result,
14283                  port_id, UINT16);
14284 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14285         TOKEN_STRING_INITIALIZER
14286                 (struct cmd_macsec_offload_off_result,
14287                  off, "off");
14288
14289 static void
14290 cmd_set_macsec_offload_off_parsed(
14291         void *parsed_result,
14292         __attribute__((unused)) struct cmdline *cl,
14293         __attribute__((unused)) void *data)
14294 {
14295         struct cmd_macsec_offload_off_result *res = parsed_result;
14296         int ret = -ENOTSUP;
14297         struct rte_eth_dev_info dev_info;
14298         portid_t port_id = res->port_id;
14299
14300         if (port_id_is_invalid(port_id, ENABLED_WARN))
14301                 return;
14302         if (!port_is_stopped(port_id)) {
14303                 printf("Please stop port %d first\n", port_id);
14304                 return;
14305         }
14306
14307         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14308         if (ret != 0)
14309                 return;
14310
14311         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14312 #ifdef RTE_LIBRTE_IXGBE_PMD
14313                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14314 #endif
14315         }
14316         switch (ret) {
14317         case 0:
14318                 ports[port_id].dev_conf.txmode.offloads &=
14319                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14320                 cmd_reconfig_device_queue(port_id, 1, 1);
14321                 break;
14322         case -ENODEV:
14323                 printf("invalid port_id %d\n", port_id);
14324                 break;
14325         case -ENOTSUP:
14326                 printf("not supported on port %d\n", port_id);
14327                 break;
14328         default:
14329                 printf("programming error: (%s)\n", strerror(-ret));
14330         }
14331 }
14332
14333 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14334         .f = cmd_set_macsec_offload_off_parsed,
14335         .data = NULL,
14336         .help_str = "set macsec offload <port_id> off",
14337         .tokens = {
14338                 (void *)&cmd_macsec_offload_off_set,
14339                 (void *)&cmd_macsec_offload_off_macsec,
14340                 (void *)&cmd_macsec_offload_off_offload,
14341                 (void *)&cmd_macsec_offload_off_port_id,
14342                 (void *)&cmd_macsec_offload_off_off,
14343                 NULL,
14344         },
14345 };
14346
14347 /* Common result structure for MACsec secure connection configure */
14348 struct cmd_macsec_sc_result {
14349         cmdline_fixed_string_t set;
14350         cmdline_fixed_string_t macsec;
14351         cmdline_fixed_string_t sc;
14352         cmdline_fixed_string_t tx_rx;
14353         portid_t port_id;
14354         struct rte_ether_addr mac;
14355         uint16_t pi;
14356 };
14357
14358 /* Common CLI fields for MACsec secure connection configure */
14359 cmdline_parse_token_string_t cmd_macsec_sc_set =
14360         TOKEN_STRING_INITIALIZER
14361                 (struct cmd_macsec_sc_result,
14362                  set, "set");
14363 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14364         TOKEN_STRING_INITIALIZER
14365                 (struct cmd_macsec_sc_result,
14366                  macsec, "macsec");
14367 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14368         TOKEN_STRING_INITIALIZER
14369                 (struct cmd_macsec_sc_result,
14370                  sc, "sc");
14371 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14372         TOKEN_STRING_INITIALIZER
14373                 (struct cmd_macsec_sc_result,
14374                  tx_rx, "tx#rx");
14375 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14376         TOKEN_NUM_INITIALIZER
14377                 (struct cmd_macsec_sc_result,
14378                  port_id, UINT16);
14379 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14380         TOKEN_ETHERADDR_INITIALIZER
14381                 (struct cmd_macsec_sc_result,
14382                  mac);
14383 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14384         TOKEN_NUM_INITIALIZER
14385                 (struct cmd_macsec_sc_result,
14386                  pi, UINT16);
14387
14388 static void
14389 cmd_set_macsec_sc_parsed(
14390         void *parsed_result,
14391         __attribute__((unused)) struct cmdline *cl,
14392         __attribute__((unused)) void *data)
14393 {
14394         struct cmd_macsec_sc_result *res = parsed_result;
14395         int ret = -ENOTSUP;
14396         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14397
14398 #ifdef RTE_LIBRTE_IXGBE_PMD
14399         ret = is_tx ?
14400                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14401                                 res->mac.addr_bytes) :
14402                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14403                                 res->mac.addr_bytes, res->pi);
14404 #endif
14405         RTE_SET_USED(is_tx);
14406
14407         switch (ret) {
14408         case 0:
14409                 break;
14410         case -ENODEV:
14411                 printf("invalid port_id %d\n", res->port_id);
14412                 break;
14413         case -ENOTSUP:
14414                 printf("not supported on port %d\n", res->port_id);
14415                 break;
14416         default:
14417                 printf("programming error: (%s)\n", strerror(-ret));
14418         }
14419 }
14420
14421 cmdline_parse_inst_t cmd_set_macsec_sc = {
14422         .f = cmd_set_macsec_sc_parsed,
14423         .data = NULL,
14424         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14425         .tokens = {
14426                 (void *)&cmd_macsec_sc_set,
14427                 (void *)&cmd_macsec_sc_macsec,
14428                 (void *)&cmd_macsec_sc_sc,
14429                 (void *)&cmd_macsec_sc_tx_rx,
14430                 (void *)&cmd_macsec_sc_port_id,
14431                 (void *)&cmd_macsec_sc_mac,
14432                 (void *)&cmd_macsec_sc_pi,
14433                 NULL,
14434         },
14435 };
14436
14437 /* Common result structure for MACsec secure connection configure */
14438 struct cmd_macsec_sa_result {
14439         cmdline_fixed_string_t set;
14440         cmdline_fixed_string_t macsec;
14441         cmdline_fixed_string_t sa;
14442         cmdline_fixed_string_t tx_rx;
14443         portid_t port_id;
14444         uint8_t idx;
14445         uint8_t an;
14446         uint32_t pn;
14447         cmdline_fixed_string_t key;
14448 };
14449
14450 /* Common CLI fields for MACsec secure connection configure */
14451 cmdline_parse_token_string_t cmd_macsec_sa_set =
14452         TOKEN_STRING_INITIALIZER
14453                 (struct cmd_macsec_sa_result,
14454                  set, "set");
14455 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14456         TOKEN_STRING_INITIALIZER
14457                 (struct cmd_macsec_sa_result,
14458                  macsec, "macsec");
14459 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14460         TOKEN_STRING_INITIALIZER
14461                 (struct cmd_macsec_sa_result,
14462                  sa, "sa");
14463 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14464         TOKEN_STRING_INITIALIZER
14465                 (struct cmd_macsec_sa_result,
14466                  tx_rx, "tx#rx");
14467 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14468         TOKEN_NUM_INITIALIZER
14469                 (struct cmd_macsec_sa_result,
14470                  port_id, UINT16);
14471 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14472         TOKEN_NUM_INITIALIZER
14473                 (struct cmd_macsec_sa_result,
14474                  idx, UINT8);
14475 cmdline_parse_token_num_t cmd_macsec_sa_an =
14476         TOKEN_NUM_INITIALIZER
14477                 (struct cmd_macsec_sa_result,
14478                  an, UINT8);
14479 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14480         TOKEN_NUM_INITIALIZER
14481                 (struct cmd_macsec_sa_result,
14482                  pn, UINT32);
14483 cmdline_parse_token_string_t cmd_macsec_sa_key =
14484         TOKEN_STRING_INITIALIZER
14485                 (struct cmd_macsec_sa_result,
14486                  key, NULL);
14487
14488 static void
14489 cmd_set_macsec_sa_parsed(
14490         void *parsed_result,
14491         __attribute__((unused)) struct cmdline *cl,
14492         __attribute__((unused)) void *data)
14493 {
14494         struct cmd_macsec_sa_result *res = parsed_result;
14495         int ret = -ENOTSUP;
14496         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14497         uint8_t key[16] = { 0 };
14498         uint8_t xdgt0;
14499         uint8_t xdgt1;
14500         int key_len;
14501         int i;
14502
14503         key_len = strlen(res->key) / 2;
14504         if (key_len > 16)
14505                 key_len = 16;
14506
14507         for (i = 0; i < key_len; i++) {
14508                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14509                 if (xdgt0 == 0xFF)
14510                         return;
14511                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14512                 if (xdgt1 == 0xFF)
14513                         return;
14514                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14515         }
14516
14517 #ifdef RTE_LIBRTE_IXGBE_PMD
14518         ret = is_tx ?
14519                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14520                         res->idx, res->an, res->pn, key) :
14521                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14522                         res->idx, res->an, res->pn, key);
14523 #endif
14524         RTE_SET_USED(is_tx);
14525         RTE_SET_USED(key);
14526
14527         switch (ret) {
14528         case 0:
14529                 break;
14530         case -EINVAL:
14531                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14532                 break;
14533         case -ENODEV:
14534                 printf("invalid port_id %d\n", res->port_id);
14535                 break;
14536         case -ENOTSUP:
14537                 printf("not supported on port %d\n", res->port_id);
14538                 break;
14539         default:
14540                 printf("programming error: (%s)\n", strerror(-ret));
14541         }
14542 }
14543
14544 cmdline_parse_inst_t cmd_set_macsec_sa = {
14545         .f = cmd_set_macsec_sa_parsed,
14546         .data = NULL,
14547         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14548         .tokens = {
14549                 (void *)&cmd_macsec_sa_set,
14550                 (void *)&cmd_macsec_sa_macsec,
14551                 (void *)&cmd_macsec_sa_sa,
14552                 (void *)&cmd_macsec_sa_tx_rx,
14553                 (void *)&cmd_macsec_sa_port_id,
14554                 (void *)&cmd_macsec_sa_idx,
14555                 (void *)&cmd_macsec_sa_an,
14556                 (void *)&cmd_macsec_sa_pn,
14557                 (void *)&cmd_macsec_sa_key,
14558                 NULL,
14559         },
14560 };
14561
14562 /* VF unicast promiscuous mode configuration */
14563
14564 /* Common result structure for VF unicast promiscuous mode */
14565 struct cmd_vf_promisc_result {
14566         cmdline_fixed_string_t set;
14567         cmdline_fixed_string_t vf;
14568         cmdline_fixed_string_t promisc;
14569         portid_t port_id;
14570         uint32_t vf_id;
14571         cmdline_fixed_string_t on_off;
14572 };
14573
14574 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14575 cmdline_parse_token_string_t cmd_vf_promisc_set =
14576         TOKEN_STRING_INITIALIZER
14577                 (struct cmd_vf_promisc_result,
14578                  set, "set");
14579 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14580         TOKEN_STRING_INITIALIZER
14581                 (struct cmd_vf_promisc_result,
14582                  vf, "vf");
14583 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14584         TOKEN_STRING_INITIALIZER
14585                 (struct cmd_vf_promisc_result,
14586                  promisc, "promisc");
14587 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14588         TOKEN_NUM_INITIALIZER
14589                 (struct cmd_vf_promisc_result,
14590                  port_id, UINT16);
14591 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14592         TOKEN_NUM_INITIALIZER
14593                 (struct cmd_vf_promisc_result,
14594                  vf_id, UINT32);
14595 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14596         TOKEN_STRING_INITIALIZER
14597                 (struct cmd_vf_promisc_result,
14598                  on_off, "on#off");
14599
14600 static void
14601 cmd_set_vf_promisc_parsed(
14602         void *parsed_result,
14603         __attribute__((unused)) struct cmdline *cl,
14604         __attribute__((unused)) void *data)
14605 {
14606         struct cmd_vf_promisc_result *res = parsed_result;
14607         int ret = -ENOTSUP;
14608
14609         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14610
14611         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14612                 return;
14613
14614 #ifdef RTE_LIBRTE_I40E_PMD
14615         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14616                                                   res->vf_id, is_on);
14617 #endif
14618
14619         switch (ret) {
14620         case 0:
14621                 break;
14622         case -EINVAL:
14623                 printf("invalid vf_id %d\n", res->vf_id);
14624                 break;
14625         case -ENODEV:
14626                 printf("invalid port_id %d\n", res->port_id);
14627                 break;
14628         case -ENOTSUP:
14629                 printf("function not implemented\n");
14630                 break;
14631         default:
14632                 printf("programming error: (%s)\n", strerror(-ret));
14633         }
14634 }
14635
14636 cmdline_parse_inst_t cmd_set_vf_promisc = {
14637         .f = cmd_set_vf_promisc_parsed,
14638         .data = NULL,
14639         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14640                 "Set unicast promiscuous mode for a VF from the PF",
14641         .tokens = {
14642                 (void *)&cmd_vf_promisc_set,
14643                 (void *)&cmd_vf_promisc_vf,
14644                 (void *)&cmd_vf_promisc_promisc,
14645                 (void *)&cmd_vf_promisc_port_id,
14646                 (void *)&cmd_vf_promisc_vf_id,
14647                 (void *)&cmd_vf_promisc_on_off,
14648                 NULL,
14649         },
14650 };
14651
14652 /* VF multicast promiscuous mode configuration */
14653
14654 /* Common result structure for VF multicast promiscuous mode */
14655 struct cmd_vf_allmulti_result {
14656         cmdline_fixed_string_t set;
14657         cmdline_fixed_string_t vf;
14658         cmdline_fixed_string_t allmulti;
14659         portid_t port_id;
14660         uint32_t vf_id;
14661         cmdline_fixed_string_t on_off;
14662 };
14663
14664 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14665 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14666         TOKEN_STRING_INITIALIZER
14667                 (struct cmd_vf_allmulti_result,
14668                  set, "set");
14669 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14670         TOKEN_STRING_INITIALIZER
14671                 (struct cmd_vf_allmulti_result,
14672                  vf, "vf");
14673 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14674         TOKEN_STRING_INITIALIZER
14675                 (struct cmd_vf_allmulti_result,
14676                  allmulti, "allmulti");
14677 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14678         TOKEN_NUM_INITIALIZER
14679                 (struct cmd_vf_allmulti_result,
14680                  port_id, UINT16);
14681 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14682         TOKEN_NUM_INITIALIZER
14683                 (struct cmd_vf_allmulti_result,
14684                  vf_id, UINT32);
14685 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14686         TOKEN_STRING_INITIALIZER
14687                 (struct cmd_vf_allmulti_result,
14688                  on_off, "on#off");
14689
14690 static void
14691 cmd_set_vf_allmulti_parsed(
14692         void *parsed_result,
14693         __attribute__((unused)) struct cmdline *cl,
14694         __attribute__((unused)) void *data)
14695 {
14696         struct cmd_vf_allmulti_result *res = parsed_result;
14697         int ret = -ENOTSUP;
14698
14699         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14700
14701         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14702                 return;
14703
14704 #ifdef RTE_LIBRTE_I40E_PMD
14705         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14706                                                     res->vf_id, is_on);
14707 #endif
14708
14709         switch (ret) {
14710         case 0:
14711                 break;
14712         case -EINVAL:
14713                 printf("invalid vf_id %d\n", res->vf_id);
14714                 break;
14715         case -ENODEV:
14716                 printf("invalid port_id %d\n", res->port_id);
14717                 break;
14718         case -ENOTSUP:
14719                 printf("function not implemented\n");
14720                 break;
14721         default:
14722                 printf("programming error: (%s)\n", strerror(-ret));
14723         }
14724 }
14725
14726 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14727         .f = cmd_set_vf_allmulti_parsed,
14728         .data = NULL,
14729         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14730                 "Set multicast promiscuous mode for a VF from the PF",
14731         .tokens = {
14732                 (void *)&cmd_vf_allmulti_set,
14733                 (void *)&cmd_vf_allmulti_vf,
14734                 (void *)&cmd_vf_allmulti_allmulti,
14735                 (void *)&cmd_vf_allmulti_port_id,
14736                 (void *)&cmd_vf_allmulti_vf_id,
14737                 (void *)&cmd_vf_allmulti_on_off,
14738                 NULL,
14739         },
14740 };
14741
14742 /* vf broadcast mode configuration */
14743
14744 /* Common result structure for vf broadcast */
14745 struct cmd_set_vf_broadcast_result {
14746         cmdline_fixed_string_t set;
14747         cmdline_fixed_string_t vf;
14748         cmdline_fixed_string_t broadcast;
14749         portid_t port_id;
14750         uint16_t vf_id;
14751         cmdline_fixed_string_t on_off;
14752 };
14753
14754 /* Common CLI fields for vf broadcast enable disable */
14755 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14756         TOKEN_STRING_INITIALIZER
14757                 (struct cmd_set_vf_broadcast_result,
14758                  set, "set");
14759 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14760         TOKEN_STRING_INITIALIZER
14761                 (struct cmd_set_vf_broadcast_result,
14762                  vf, "vf");
14763 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14764         TOKEN_STRING_INITIALIZER
14765                 (struct cmd_set_vf_broadcast_result,
14766                  broadcast, "broadcast");
14767 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14768         TOKEN_NUM_INITIALIZER
14769                 (struct cmd_set_vf_broadcast_result,
14770                  port_id, UINT16);
14771 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14772         TOKEN_NUM_INITIALIZER
14773                 (struct cmd_set_vf_broadcast_result,
14774                  vf_id, UINT16);
14775 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14776         TOKEN_STRING_INITIALIZER
14777                 (struct cmd_set_vf_broadcast_result,
14778                  on_off, "on#off");
14779
14780 static void
14781 cmd_set_vf_broadcast_parsed(
14782         void *parsed_result,
14783         __attribute__((unused)) struct cmdline *cl,
14784         __attribute__((unused)) void *data)
14785 {
14786         struct cmd_set_vf_broadcast_result *res = parsed_result;
14787         int ret = -ENOTSUP;
14788
14789         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14790
14791         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14792                 return;
14793
14794 #ifdef RTE_LIBRTE_I40E_PMD
14795         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14796                                             res->vf_id, is_on);
14797 #endif
14798
14799         switch (ret) {
14800         case 0:
14801                 break;
14802         case -EINVAL:
14803                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14804                 break;
14805         case -ENODEV:
14806                 printf("invalid port_id %d\n", res->port_id);
14807                 break;
14808         case -ENOTSUP:
14809                 printf("function not implemented\n");
14810                 break;
14811         default:
14812                 printf("programming error: (%s)\n", strerror(-ret));
14813         }
14814 }
14815
14816 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14817         .f = cmd_set_vf_broadcast_parsed,
14818         .data = NULL,
14819         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14820         .tokens = {
14821                 (void *)&cmd_set_vf_broadcast_set,
14822                 (void *)&cmd_set_vf_broadcast_vf,
14823                 (void *)&cmd_set_vf_broadcast_broadcast,
14824                 (void *)&cmd_set_vf_broadcast_port_id,
14825                 (void *)&cmd_set_vf_broadcast_vf_id,
14826                 (void *)&cmd_set_vf_broadcast_on_off,
14827                 NULL,
14828         },
14829 };
14830
14831 /* vf vlan tag configuration */
14832
14833 /* Common result structure for vf vlan tag */
14834 struct cmd_set_vf_vlan_tag_result {
14835         cmdline_fixed_string_t set;
14836         cmdline_fixed_string_t vf;
14837         cmdline_fixed_string_t vlan;
14838         cmdline_fixed_string_t tag;
14839         portid_t port_id;
14840         uint16_t vf_id;
14841         cmdline_fixed_string_t on_off;
14842 };
14843
14844 /* Common CLI fields for vf vlan tag enable disable */
14845 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14846         TOKEN_STRING_INITIALIZER
14847                 (struct cmd_set_vf_vlan_tag_result,
14848                  set, "set");
14849 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14850         TOKEN_STRING_INITIALIZER
14851                 (struct cmd_set_vf_vlan_tag_result,
14852                  vf, "vf");
14853 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14854         TOKEN_STRING_INITIALIZER
14855                 (struct cmd_set_vf_vlan_tag_result,
14856                  vlan, "vlan");
14857 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14858         TOKEN_STRING_INITIALIZER
14859                 (struct cmd_set_vf_vlan_tag_result,
14860                  tag, "tag");
14861 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14862         TOKEN_NUM_INITIALIZER
14863                 (struct cmd_set_vf_vlan_tag_result,
14864                  port_id, UINT16);
14865 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14866         TOKEN_NUM_INITIALIZER
14867                 (struct cmd_set_vf_vlan_tag_result,
14868                  vf_id, UINT16);
14869 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14870         TOKEN_STRING_INITIALIZER
14871                 (struct cmd_set_vf_vlan_tag_result,
14872                  on_off, "on#off");
14873
14874 static void
14875 cmd_set_vf_vlan_tag_parsed(
14876         void *parsed_result,
14877         __attribute__((unused)) struct cmdline *cl,
14878         __attribute__((unused)) void *data)
14879 {
14880         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14881         int ret = -ENOTSUP;
14882
14883         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14884
14885         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14886                 return;
14887
14888 #ifdef RTE_LIBRTE_I40E_PMD
14889         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14890                                            res->vf_id, is_on);
14891 #endif
14892
14893         switch (ret) {
14894         case 0:
14895                 break;
14896         case -EINVAL:
14897                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14898                 break;
14899         case -ENODEV:
14900                 printf("invalid port_id %d\n", res->port_id);
14901                 break;
14902         case -ENOTSUP:
14903                 printf("function not implemented\n");
14904                 break;
14905         default:
14906                 printf("programming error: (%s)\n", strerror(-ret));
14907         }
14908 }
14909
14910 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14911         .f = cmd_set_vf_vlan_tag_parsed,
14912         .data = NULL,
14913         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14914         .tokens = {
14915                 (void *)&cmd_set_vf_vlan_tag_set,
14916                 (void *)&cmd_set_vf_vlan_tag_vf,
14917                 (void *)&cmd_set_vf_vlan_tag_vlan,
14918                 (void *)&cmd_set_vf_vlan_tag_tag,
14919                 (void *)&cmd_set_vf_vlan_tag_port_id,
14920                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14921                 (void *)&cmd_set_vf_vlan_tag_on_off,
14922                 NULL,
14923         },
14924 };
14925
14926 /* Common definition of VF and TC TX bandwidth configuration */
14927 struct cmd_vf_tc_bw_result {
14928         cmdline_fixed_string_t set;
14929         cmdline_fixed_string_t vf;
14930         cmdline_fixed_string_t tc;
14931         cmdline_fixed_string_t tx;
14932         cmdline_fixed_string_t min_bw;
14933         cmdline_fixed_string_t max_bw;
14934         cmdline_fixed_string_t strict_link_prio;
14935         portid_t port_id;
14936         uint16_t vf_id;
14937         uint8_t tc_no;
14938         uint32_t bw;
14939         cmdline_fixed_string_t bw_list;
14940         uint8_t tc_map;
14941 };
14942
14943 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14944         TOKEN_STRING_INITIALIZER
14945                 (struct cmd_vf_tc_bw_result,
14946                  set, "set");
14947 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14948         TOKEN_STRING_INITIALIZER
14949                 (struct cmd_vf_tc_bw_result,
14950                  vf, "vf");
14951 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14952         TOKEN_STRING_INITIALIZER
14953                 (struct cmd_vf_tc_bw_result,
14954                  tc, "tc");
14955 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14956         TOKEN_STRING_INITIALIZER
14957                 (struct cmd_vf_tc_bw_result,
14958                  tx, "tx");
14959 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14960         TOKEN_STRING_INITIALIZER
14961                 (struct cmd_vf_tc_bw_result,
14962                  strict_link_prio, "strict-link-priority");
14963 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14964         TOKEN_STRING_INITIALIZER
14965                 (struct cmd_vf_tc_bw_result,
14966                  min_bw, "min-bandwidth");
14967 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14968         TOKEN_STRING_INITIALIZER
14969                 (struct cmd_vf_tc_bw_result,
14970                  max_bw, "max-bandwidth");
14971 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14972         TOKEN_NUM_INITIALIZER
14973                 (struct cmd_vf_tc_bw_result,
14974                  port_id, UINT16);
14975 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14976         TOKEN_NUM_INITIALIZER
14977                 (struct cmd_vf_tc_bw_result,
14978                  vf_id, UINT16);
14979 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14980         TOKEN_NUM_INITIALIZER
14981                 (struct cmd_vf_tc_bw_result,
14982                  tc_no, UINT8);
14983 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14984         TOKEN_NUM_INITIALIZER
14985                 (struct cmd_vf_tc_bw_result,
14986                  bw, UINT32);
14987 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14988         TOKEN_STRING_INITIALIZER
14989                 (struct cmd_vf_tc_bw_result,
14990                  bw_list, NULL);
14991 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14992         TOKEN_NUM_INITIALIZER
14993                 (struct cmd_vf_tc_bw_result,
14994                  tc_map, UINT8);
14995
14996 /* VF max bandwidth setting */
14997 static void
14998 cmd_vf_max_bw_parsed(
14999         void *parsed_result,
15000         __attribute__((unused)) struct cmdline *cl,
15001         __attribute__((unused)) void *data)
15002 {
15003         struct cmd_vf_tc_bw_result *res = parsed_result;
15004         int ret = -ENOTSUP;
15005
15006         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15007                 return;
15008
15009 #ifdef RTE_LIBRTE_I40E_PMD
15010         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15011                                          res->vf_id, res->bw);
15012 #endif
15013
15014         switch (ret) {
15015         case 0:
15016                 break;
15017         case -EINVAL:
15018                 printf("invalid vf_id %d or bandwidth %d\n",
15019                        res->vf_id, res->bw);
15020                 break;
15021         case -ENODEV:
15022                 printf("invalid port_id %d\n", res->port_id);
15023                 break;
15024         case -ENOTSUP:
15025                 printf("function not implemented\n");
15026                 break;
15027         default:
15028                 printf("programming error: (%s)\n", strerror(-ret));
15029         }
15030 }
15031
15032 cmdline_parse_inst_t cmd_vf_max_bw = {
15033         .f = cmd_vf_max_bw_parsed,
15034         .data = NULL,
15035         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15036         .tokens = {
15037                 (void *)&cmd_vf_tc_bw_set,
15038                 (void *)&cmd_vf_tc_bw_vf,
15039                 (void *)&cmd_vf_tc_bw_tx,
15040                 (void *)&cmd_vf_tc_bw_max_bw,
15041                 (void *)&cmd_vf_tc_bw_port_id,
15042                 (void *)&cmd_vf_tc_bw_vf_id,
15043                 (void *)&cmd_vf_tc_bw_bw,
15044                 NULL,
15045         },
15046 };
15047
15048 static int
15049 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15050                            uint8_t *tc_num,
15051                            char *str)
15052 {
15053         uint32_t size;
15054         const char *p, *p0 = str;
15055         char s[256];
15056         char *end;
15057         char *str_fld[16];
15058         uint16_t i;
15059         int ret;
15060
15061         p = strchr(p0, '(');
15062         if (p == NULL) {
15063                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15064                 return -1;
15065         }
15066         p++;
15067         p0 = strchr(p, ')');
15068         if (p0 == NULL) {
15069                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15070                 return -1;
15071         }
15072         size = p0 - p;
15073         if (size >= sizeof(s)) {
15074                 printf("The string size exceeds the internal buffer size\n");
15075                 return -1;
15076         }
15077         snprintf(s, sizeof(s), "%.*s", size, p);
15078         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15079         if (ret <= 0) {
15080                 printf("Failed to get the bandwidth list. ");
15081                 return -1;
15082         }
15083         *tc_num = ret;
15084         for (i = 0; i < ret; i++)
15085                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15086
15087         return 0;
15088 }
15089
15090 /* TC min bandwidth setting */
15091 static void
15092 cmd_vf_tc_min_bw_parsed(
15093         void *parsed_result,
15094         __attribute__((unused)) struct cmdline *cl,
15095         __attribute__((unused)) void *data)
15096 {
15097         struct cmd_vf_tc_bw_result *res = parsed_result;
15098         uint8_t tc_num;
15099         uint8_t bw[16];
15100         int ret = -ENOTSUP;
15101
15102         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15103                 return;
15104
15105         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15106         if (ret)
15107                 return;
15108
15109 #ifdef RTE_LIBRTE_I40E_PMD
15110         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15111                                               tc_num, bw);
15112 #endif
15113
15114         switch (ret) {
15115         case 0:
15116                 break;
15117         case -EINVAL:
15118                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15119                 break;
15120         case -ENODEV:
15121                 printf("invalid port_id %d\n", res->port_id);
15122                 break;
15123         case -ENOTSUP:
15124                 printf("function not implemented\n");
15125                 break;
15126         default:
15127                 printf("programming error: (%s)\n", strerror(-ret));
15128         }
15129 }
15130
15131 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15132         .f = cmd_vf_tc_min_bw_parsed,
15133         .data = NULL,
15134         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15135                     " <bw1, bw2, ...>",
15136         .tokens = {
15137                 (void *)&cmd_vf_tc_bw_set,
15138                 (void *)&cmd_vf_tc_bw_vf,
15139                 (void *)&cmd_vf_tc_bw_tc,
15140                 (void *)&cmd_vf_tc_bw_tx,
15141                 (void *)&cmd_vf_tc_bw_min_bw,
15142                 (void *)&cmd_vf_tc_bw_port_id,
15143                 (void *)&cmd_vf_tc_bw_vf_id,
15144                 (void *)&cmd_vf_tc_bw_bw_list,
15145                 NULL,
15146         },
15147 };
15148
15149 static void
15150 cmd_tc_min_bw_parsed(
15151         void *parsed_result,
15152         __attribute__((unused)) struct cmdline *cl,
15153         __attribute__((unused)) void *data)
15154 {
15155         struct cmd_vf_tc_bw_result *res = parsed_result;
15156         struct rte_port *port;
15157         uint8_t tc_num;
15158         uint8_t bw[16];
15159         int ret = -ENOTSUP;
15160
15161         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15162                 return;
15163
15164         port = &ports[res->port_id];
15165         /** Check if the port is not started **/
15166         if (port->port_status != RTE_PORT_STOPPED) {
15167                 printf("Please stop port %d first\n", res->port_id);
15168                 return;
15169         }
15170
15171         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15172         if (ret)
15173                 return;
15174
15175 #ifdef RTE_LIBRTE_IXGBE_PMD
15176         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15177 #endif
15178
15179         switch (ret) {
15180         case 0:
15181                 break;
15182         case -EINVAL:
15183                 printf("invalid bandwidth\n");
15184                 break;
15185         case -ENODEV:
15186                 printf("invalid port_id %d\n", res->port_id);
15187                 break;
15188         case -ENOTSUP:
15189                 printf("function not implemented\n");
15190                 break;
15191         default:
15192                 printf("programming error: (%s)\n", strerror(-ret));
15193         }
15194 }
15195
15196 cmdline_parse_inst_t cmd_tc_min_bw = {
15197         .f = cmd_tc_min_bw_parsed,
15198         .data = NULL,
15199         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15200         .tokens = {
15201                 (void *)&cmd_vf_tc_bw_set,
15202                 (void *)&cmd_vf_tc_bw_tc,
15203                 (void *)&cmd_vf_tc_bw_tx,
15204                 (void *)&cmd_vf_tc_bw_min_bw,
15205                 (void *)&cmd_vf_tc_bw_port_id,
15206                 (void *)&cmd_vf_tc_bw_bw_list,
15207                 NULL,
15208         },
15209 };
15210
15211 /* TC max bandwidth setting */
15212 static void
15213 cmd_vf_tc_max_bw_parsed(
15214         void *parsed_result,
15215         __attribute__((unused)) struct cmdline *cl,
15216         __attribute__((unused)) void *data)
15217 {
15218         struct cmd_vf_tc_bw_result *res = parsed_result;
15219         int ret = -ENOTSUP;
15220
15221         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15222                 return;
15223
15224 #ifdef RTE_LIBRTE_I40E_PMD
15225         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15226                                             res->tc_no, res->bw);
15227 #endif
15228
15229         switch (ret) {
15230         case 0:
15231                 break;
15232         case -EINVAL:
15233                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15234                        res->vf_id, res->tc_no, res->bw);
15235                 break;
15236         case -ENODEV:
15237                 printf("invalid port_id %d\n", res->port_id);
15238                 break;
15239         case -ENOTSUP:
15240                 printf("function not implemented\n");
15241                 break;
15242         default:
15243                 printf("programming error: (%s)\n", strerror(-ret));
15244         }
15245 }
15246
15247 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15248         .f = cmd_vf_tc_max_bw_parsed,
15249         .data = NULL,
15250         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15251                     " <bandwidth>",
15252         .tokens = {
15253                 (void *)&cmd_vf_tc_bw_set,
15254                 (void *)&cmd_vf_tc_bw_vf,
15255                 (void *)&cmd_vf_tc_bw_tc,
15256                 (void *)&cmd_vf_tc_bw_tx,
15257                 (void *)&cmd_vf_tc_bw_max_bw,
15258                 (void *)&cmd_vf_tc_bw_port_id,
15259                 (void *)&cmd_vf_tc_bw_vf_id,
15260                 (void *)&cmd_vf_tc_bw_tc_no,
15261                 (void *)&cmd_vf_tc_bw_bw,
15262                 NULL,
15263         },
15264 };
15265
15266
15267 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15268
15269 /* *** Set Port default Traffic Management Hierarchy *** */
15270 struct cmd_set_port_tm_hierarchy_default_result {
15271         cmdline_fixed_string_t set;
15272         cmdline_fixed_string_t port;
15273         cmdline_fixed_string_t tm;
15274         cmdline_fixed_string_t hierarchy;
15275         cmdline_fixed_string_t def;
15276         portid_t port_id;
15277 };
15278
15279 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15280         TOKEN_STRING_INITIALIZER(
15281                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15282 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15283         TOKEN_STRING_INITIALIZER(
15284                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15285 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15286         TOKEN_STRING_INITIALIZER(
15287                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15288 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15289         TOKEN_STRING_INITIALIZER(
15290                 struct cmd_set_port_tm_hierarchy_default_result,
15291                         hierarchy, "hierarchy");
15292 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15293         TOKEN_STRING_INITIALIZER(
15294                 struct cmd_set_port_tm_hierarchy_default_result,
15295                         def, "default");
15296 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15297         TOKEN_NUM_INITIALIZER(
15298                 struct cmd_set_port_tm_hierarchy_default_result,
15299                         port_id, UINT16);
15300
15301 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15302         __attribute__((unused)) struct cmdline *cl,
15303         __attribute__((unused)) void *data)
15304 {
15305         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15306         struct rte_port *p;
15307         portid_t port_id = res->port_id;
15308
15309         if (port_id_is_invalid(port_id, ENABLED_WARN))
15310                 return;
15311
15312         p = &ports[port_id];
15313
15314         /* Forward mode: tm */
15315         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15316                 printf("  softnicfwd mode not enabled(error)\n");
15317                 return;
15318         }
15319
15320         /* Set the default tm hierarchy */
15321         p->softport.default_tm_hierarchy_enable = 1;
15322 }
15323
15324 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15325         .f = cmd_set_port_tm_hierarchy_default_parsed,
15326         .data = NULL,
15327         .help_str = "set port tm hierarchy default <port_id>",
15328         .tokens = {
15329                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15330                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15331                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15332                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15333                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15334                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15335                 NULL,
15336         },
15337 };
15338 #endif
15339
15340 /** Set VXLAN encapsulation details */
15341 struct cmd_set_vxlan_result {
15342         cmdline_fixed_string_t set;
15343         cmdline_fixed_string_t vxlan;
15344         cmdline_fixed_string_t pos_token;
15345         cmdline_fixed_string_t ip_version;
15346         uint32_t vlan_present:1;
15347         uint32_t vni;
15348         uint16_t udp_src;
15349         uint16_t udp_dst;
15350         cmdline_ipaddr_t ip_src;
15351         cmdline_ipaddr_t ip_dst;
15352         uint16_t tci;
15353         uint8_t tos;
15354         uint8_t ttl;
15355         struct rte_ether_addr eth_src;
15356         struct rte_ether_addr eth_dst;
15357 };
15358
15359 cmdline_parse_token_string_t cmd_set_vxlan_set =
15360         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15361 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15362         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15363 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15364         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15365                                  "vxlan-tos-ttl");
15366 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15367         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15368                                  "vxlan-with-vlan");
15369 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15370         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15371                                  "ip-version");
15372 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15373         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15374                                  "ipv4#ipv6");
15375 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15376         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15377                                  "vni");
15378 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15379         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15380 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15381         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15382                                  "udp-src");
15383 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15384         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15385 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15386         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15387                                  "udp-dst");
15388 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15389         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15390 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15391         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15392                                  "ip-tos");
15393 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15394         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15395 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15396         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15397                                  "ip-ttl");
15398 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15399         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15400 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15401         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15402                                  "ip-src");
15403 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15404         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15405 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15406         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15407                                  "ip-dst");
15408 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15409         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15410 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15411         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15412                                  "vlan-tci");
15413 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15414         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15415 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15416         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15417                                  "eth-src");
15418 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15419         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15420 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15421         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15422                                  "eth-dst");
15423 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15424         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15425
15426 static void cmd_set_vxlan_parsed(void *parsed_result,
15427         __attribute__((unused)) struct cmdline *cl,
15428         __attribute__((unused)) void *data)
15429 {
15430         struct cmd_set_vxlan_result *res = parsed_result;
15431         union {
15432                 uint32_t vxlan_id;
15433                 uint8_t vni[4];
15434         } id = {
15435                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15436         };
15437
15438         vxlan_encap_conf.select_tos_ttl = 0;
15439         if (strcmp(res->vxlan, "vxlan") == 0)
15440                 vxlan_encap_conf.select_vlan = 0;
15441         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15442                 vxlan_encap_conf.select_vlan = 1;
15443         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15444                 vxlan_encap_conf.select_vlan = 0;
15445                 vxlan_encap_conf.select_tos_ttl = 1;
15446         }
15447         if (strcmp(res->ip_version, "ipv4") == 0)
15448                 vxlan_encap_conf.select_ipv4 = 1;
15449         else if (strcmp(res->ip_version, "ipv6") == 0)
15450                 vxlan_encap_conf.select_ipv4 = 0;
15451         else
15452                 return;
15453         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15454         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15455         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15456         vxlan_encap_conf.ip_tos = res->tos;
15457         vxlan_encap_conf.ip_ttl = res->ttl;
15458         if (vxlan_encap_conf.select_ipv4) {
15459                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15460                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15461         } else {
15462                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15463                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15464         }
15465         if (vxlan_encap_conf.select_vlan)
15466                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15467         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15468                    RTE_ETHER_ADDR_LEN);
15469         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15470                    RTE_ETHER_ADDR_LEN);
15471 }
15472
15473 cmdline_parse_inst_t cmd_set_vxlan = {
15474         .f = cmd_set_vxlan_parsed,
15475         .data = NULL,
15476         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15477                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15478                 " eth-src <eth-src> eth-dst <eth-dst>",
15479         .tokens = {
15480                 (void *)&cmd_set_vxlan_set,
15481                 (void *)&cmd_set_vxlan_vxlan,
15482                 (void *)&cmd_set_vxlan_ip_version,
15483                 (void *)&cmd_set_vxlan_ip_version_value,
15484                 (void *)&cmd_set_vxlan_vni,
15485                 (void *)&cmd_set_vxlan_vni_value,
15486                 (void *)&cmd_set_vxlan_udp_src,
15487                 (void *)&cmd_set_vxlan_udp_src_value,
15488                 (void *)&cmd_set_vxlan_udp_dst,
15489                 (void *)&cmd_set_vxlan_udp_dst_value,
15490                 (void *)&cmd_set_vxlan_ip_src,
15491                 (void *)&cmd_set_vxlan_ip_src_value,
15492                 (void *)&cmd_set_vxlan_ip_dst,
15493                 (void *)&cmd_set_vxlan_ip_dst_value,
15494                 (void *)&cmd_set_vxlan_eth_src,
15495                 (void *)&cmd_set_vxlan_eth_src_value,
15496                 (void *)&cmd_set_vxlan_eth_dst,
15497                 (void *)&cmd_set_vxlan_eth_dst_value,
15498                 NULL,
15499         },
15500 };
15501
15502 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15503         .f = cmd_set_vxlan_parsed,
15504         .data = NULL,
15505         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15506                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15507                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15508                 " eth-dst <eth-dst>",
15509         .tokens = {
15510                 (void *)&cmd_set_vxlan_set,
15511                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15512                 (void *)&cmd_set_vxlan_ip_version,
15513                 (void *)&cmd_set_vxlan_ip_version_value,
15514                 (void *)&cmd_set_vxlan_vni,
15515                 (void *)&cmd_set_vxlan_vni_value,
15516                 (void *)&cmd_set_vxlan_udp_src,
15517                 (void *)&cmd_set_vxlan_udp_src_value,
15518                 (void *)&cmd_set_vxlan_udp_dst,
15519                 (void *)&cmd_set_vxlan_udp_dst_value,
15520                 (void *)&cmd_set_vxlan_ip_tos,
15521                 (void *)&cmd_set_vxlan_ip_tos_value,
15522                 (void *)&cmd_set_vxlan_ip_ttl,
15523                 (void *)&cmd_set_vxlan_ip_ttl_value,
15524                 (void *)&cmd_set_vxlan_ip_src,
15525                 (void *)&cmd_set_vxlan_ip_src_value,
15526                 (void *)&cmd_set_vxlan_ip_dst,
15527                 (void *)&cmd_set_vxlan_ip_dst_value,
15528                 (void *)&cmd_set_vxlan_eth_src,
15529                 (void *)&cmd_set_vxlan_eth_src_value,
15530                 (void *)&cmd_set_vxlan_eth_dst,
15531                 (void *)&cmd_set_vxlan_eth_dst_value,
15532                 NULL,
15533         },
15534 };
15535
15536 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15537         .f = cmd_set_vxlan_parsed,
15538         .data = NULL,
15539         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15540                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15541                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15542                 " <eth-dst>",
15543         .tokens = {
15544                 (void *)&cmd_set_vxlan_set,
15545                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15546                 (void *)&cmd_set_vxlan_ip_version,
15547                 (void *)&cmd_set_vxlan_ip_version_value,
15548                 (void *)&cmd_set_vxlan_vni,
15549                 (void *)&cmd_set_vxlan_vni_value,
15550                 (void *)&cmd_set_vxlan_udp_src,
15551                 (void *)&cmd_set_vxlan_udp_src_value,
15552                 (void *)&cmd_set_vxlan_udp_dst,
15553                 (void *)&cmd_set_vxlan_udp_dst_value,
15554                 (void *)&cmd_set_vxlan_ip_src,
15555                 (void *)&cmd_set_vxlan_ip_src_value,
15556                 (void *)&cmd_set_vxlan_ip_dst,
15557                 (void *)&cmd_set_vxlan_ip_dst_value,
15558                 (void *)&cmd_set_vxlan_vlan,
15559                 (void *)&cmd_set_vxlan_vlan_value,
15560                 (void *)&cmd_set_vxlan_eth_src,
15561                 (void *)&cmd_set_vxlan_eth_src_value,
15562                 (void *)&cmd_set_vxlan_eth_dst,
15563                 (void *)&cmd_set_vxlan_eth_dst_value,
15564                 NULL,
15565         },
15566 };
15567
15568 /** Set NVGRE encapsulation details */
15569 struct cmd_set_nvgre_result {
15570         cmdline_fixed_string_t set;
15571         cmdline_fixed_string_t nvgre;
15572         cmdline_fixed_string_t pos_token;
15573         cmdline_fixed_string_t ip_version;
15574         uint32_t tni;
15575         cmdline_ipaddr_t ip_src;
15576         cmdline_ipaddr_t ip_dst;
15577         uint16_t tci;
15578         struct rte_ether_addr eth_src;
15579         struct rte_ether_addr eth_dst;
15580 };
15581
15582 cmdline_parse_token_string_t cmd_set_nvgre_set =
15583         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15584 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15585         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15586 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15587         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15588                                  "nvgre-with-vlan");
15589 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15590         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15591                                  "ip-version");
15592 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15593         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15594                                  "ipv4#ipv6");
15595 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15596         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15597                                  "tni");
15598 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15599         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15600 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15601         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15602                                  "ip-src");
15603 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15604         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15605 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15606         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15607                                  "ip-dst");
15608 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15609         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15610 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15611         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15612                                  "vlan-tci");
15613 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15614         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15615 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15616         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15617                                  "eth-src");
15618 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15619         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15620 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15621         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15622                                  "eth-dst");
15623 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15624         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15625
15626 static void cmd_set_nvgre_parsed(void *parsed_result,
15627         __attribute__((unused)) struct cmdline *cl,
15628         __attribute__((unused)) void *data)
15629 {
15630         struct cmd_set_nvgre_result *res = parsed_result;
15631         union {
15632                 uint32_t nvgre_tni;
15633                 uint8_t tni[4];
15634         } id = {
15635                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15636         };
15637
15638         if (strcmp(res->nvgre, "nvgre") == 0)
15639                 nvgre_encap_conf.select_vlan = 0;
15640         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15641                 nvgre_encap_conf.select_vlan = 1;
15642         if (strcmp(res->ip_version, "ipv4") == 0)
15643                 nvgre_encap_conf.select_ipv4 = 1;
15644         else if (strcmp(res->ip_version, "ipv6") == 0)
15645                 nvgre_encap_conf.select_ipv4 = 0;
15646         else
15647                 return;
15648         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15649         if (nvgre_encap_conf.select_ipv4) {
15650                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15651                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15652         } else {
15653                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15654                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15655         }
15656         if (nvgre_encap_conf.select_vlan)
15657                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15658         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15659                    RTE_ETHER_ADDR_LEN);
15660         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15661                    RTE_ETHER_ADDR_LEN);
15662 }
15663
15664 cmdline_parse_inst_t cmd_set_nvgre = {
15665         .f = cmd_set_nvgre_parsed,
15666         .data = NULL,
15667         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15668                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15669                 " eth-dst <eth-dst>",
15670         .tokens = {
15671                 (void *)&cmd_set_nvgre_set,
15672                 (void *)&cmd_set_nvgre_nvgre,
15673                 (void *)&cmd_set_nvgre_ip_version,
15674                 (void *)&cmd_set_nvgre_ip_version_value,
15675                 (void *)&cmd_set_nvgre_tni,
15676                 (void *)&cmd_set_nvgre_tni_value,
15677                 (void *)&cmd_set_nvgre_ip_src,
15678                 (void *)&cmd_set_nvgre_ip_src_value,
15679                 (void *)&cmd_set_nvgre_ip_dst,
15680                 (void *)&cmd_set_nvgre_ip_dst_value,
15681                 (void *)&cmd_set_nvgre_eth_src,
15682                 (void *)&cmd_set_nvgre_eth_src_value,
15683                 (void *)&cmd_set_nvgre_eth_dst,
15684                 (void *)&cmd_set_nvgre_eth_dst_value,
15685                 NULL,
15686         },
15687 };
15688
15689 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15690         .f = cmd_set_nvgre_parsed,
15691         .data = NULL,
15692         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15693                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15694                 " eth-src <eth-src> eth-dst <eth-dst>",
15695         .tokens = {
15696                 (void *)&cmd_set_nvgre_set,
15697                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15698                 (void *)&cmd_set_nvgre_ip_version,
15699                 (void *)&cmd_set_nvgre_ip_version_value,
15700                 (void *)&cmd_set_nvgre_tni,
15701                 (void *)&cmd_set_nvgre_tni_value,
15702                 (void *)&cmd_set_nvgre_ip_src,
15703                 (void *)&cmd_set_nvgre_ip_src_value,
15704                 (void *)&cmd_set_nvgre_ip_dst,
15705                 (void *)&cmd_set_nvgre_ip_dst_value,
15706                 (void *)&cmd_set_nvgre_vlan,
15707                 (void *)&cmd_set_nvgre_vlan_value,
15708                 (void *)&cmd_set_nvgre_eth_src,
15709                 (void *)&cmd_set_nvgre_eth_src_value,
15710                 (void *)&cmd_set_nvgre_eth_dst,
15711                 (void *)&cmd_set_nvgre_eth_dst_value,
15712                 NULL,
15713         },
15714 };
15715
15716 /** Set L2 encapsulation details */
15717 struct cmd_set_l2_encap_result {
15718         cmdline_fixed_string_t set;
15719         cmdline_fixed_string_t l2_encap;
15720         cmdline_fixed_string_t pos_token;
15721         cmdline_fixed_string_t ip_version;
15722         uint32_t vlan_present:1;
15723         uint16_t tci;
15724         struct rte_ether_addr eth_src;
15725         struct rte_ether_addr eth_dst;
15726 };
15727
15728 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15729         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15730 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15731         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15732 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15733         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15734                                  "l2_encap-with-vlan");
15735 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15736         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15737                                  "ip-version");
15738 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15739         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15740                                  "ipv4#ipv6");
15741 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15742         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15743                                  "vlan-tci");
15744 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15745         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15746 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15747         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15748                                  "eth-src");
15749 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15750         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15751 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15752         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15753                                  "eth-dst");
15754 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15755         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15756
15757 static void cmd_set_l2_encap_parsed(void *parsed_result,
15758         __attribute__((unused)) struct cmdline *cl,
15759         __attribute__((unused)) void *data)
15760 {
15761         struct cmd_set_l2_encap_result *res = parsed_result;
15762
15763         if (strcmp(res->l2_encap, "l2_encap") == 0)
15764                 l2_encap_conf.select_vlan = 0;
15765         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15766                 l2_encap_conf.select_vlan = 1;
15767         if (strcmp(res->ip_version, "ipv4") == 0)
15768                 l2_encap_conf.select_ipv4 = 1;
15769         else if (strcmp(res->ip_version, "ipv6") == 0)
15770                 l2_encap_conf.select_ipv4 = 0;
15771         else
15772                 return;
15773         if (l2_encap_conf.select_vlan)
15774                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15775         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15776                    RTE_ETHER_ADDR_LEN);
15777         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15778                    RTE_ETHER_ADDR_LEN);
15779 }
15780
15781 cmdline_parse_inst_t cmd_set_l2_encap = {
15782         .f = cmd_set_l2_encap_parsed,
15783         .data = NULL,
15784         .help_str = "set l2_encap ip-version ipv4|ipv6"
15785                 " eth-src <eth-src> eth-dst <eth-dst>",
15786         .tokens = {
15787                 (void *)&cmd_set_l2_encap_set,
15788                 (void *)&cmd_set_l2_encap_l2_encap,
15789                 (void *)&cmd_set_l2_encap_ip_version,
15790                 (void *)&cmd_set_l2_encap_ip_version_value,
15791                 (void *)&cmd_set_l2_encap_eth_src,
15792                 (void *)&cmd_set_l2_encap_eth_src_value,
15793                 (void *)&cmd_set_l2_encap_eth_dst,
15794                 (void *)&cmd_set_l2_encap_eth_dst_value,
15795                 NULL,
15796         },
15797 };
15798
15799 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15800         .f = cmd_set_l2_encap_parsed,
15801         .data = NULL,
15802         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15803                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15804         .tokens = {
15805                 (void *)&cmd_set_l2_encap_set,
15806                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15807                 (void *)&cmd_set_l2_encap_ip_version,
15808                 (void *)&cmd_set_l2_encap_ip_version_value,
15809                 (void *)&cmd_set_l2_encap_vlan,
15810                 (void *)&cmd_set_l2_encap_vlan_value,
15811                 (void *)&cmd_set_l2_encap_eth_src,
15812                 (void *)&cmd_set_l2_encap_eth_src_value,
15813                 (void *)&cmd_set_l2_encap_eth_dst,
15814                 (void *)&cmd_set_l2_encap_eth_dst_value,
15815                 NULL,
15816         },
15817 };
15818
15819 /** Set L2 decapsulation details */
15820 struct cmd_set_l2_decap_result {
15821         cmdline_fixed_string_t set;
15822         cmdline_fixed_string_t l2_decap;
15823         cmdline_fixed_string_t pos_token;
15824         uint32_t vlan_present:1;
15825 };
15826
15827 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15828         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15829 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15830         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15831                                  "l2_decap");
15832 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15833         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15834                                  "l2_decap-with-vlan");
15835
15836 static void cmd_set_l2_decap_parsed(void *parsed_result,
15837         __attribute__((unused)) struct cmdline *cl,
15838         __attribute__((unused)) void *data)
15839 {
15840         struct cmd_set_l2_decap_result *res = parsed_result;
15841
15842         if (strcmp(res->l2_decap, "l2_decap") == 0)
15843                 l2_decap_conf.select_vlan = 0;
15844         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15845                 l2_decap_conf.select_vlan = 1;
15846 }
15847
15848 cmdline_parse_inst_t cmd_set_l2_decap = {
15849         .f = cmd_set_l2_decap_parsed,
15850         .data = NULL,
15851         .help_str = "set l2_decap",
15852         .tokens = {
15853                 (void *)&cmd_set_l2_decap_set,
15854                 (void *)&cmd_set_l2_decap_l2_decap,
15855                 NULL,
15856         },
15857 };
15858
15859 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15860         .f = cmd_set_l2_decap_parsed,
15861         .data = NULL,
15862         .help_str = "set l2_decap-with-vlan",
15863         .tokens = {
15864                 (void *)&cmd_set_l2_decap_set,
15865                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15866                 NULL,
15867         },
15868 };
15869
15870 /** Set MPLSoGRE encapsulation details */
15871 struct cmd_set_mplsogre_encap_result {
15872         cmdline_fixed_string_t set;
15873         cmdline_fixed_string_t mplsogre;
15874         cmdline_fixed_string_t pos_token;
15875         cmdline_fixed_string_t ip_version;
15876         uint32_t vlan_present:1;
15877         uint32_t label;
15878         cmdline_ipaddr_t ip_src;
15879         cmdline_ipaddr_t ip_dst;
15880         uint16_t tci;
15881         struct rte_ether_addr eth_src;
15882         struct rte_ether_addr eth_dst;
15883 };
15884
15885 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15886         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15887                                  "set");
15888 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15889         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15890                                  "mplsogre_encap");
15891 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15892         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15893                                  mplsogre, "mplsogre_encap-with-vlan");
15894 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15895         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15896                                  pos_token, "ip-version");
15897 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15898         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15899                                  ip_version, "ipv4#ipv6");
15900 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15901         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15902                                  pos_token, "label");
15903 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15904         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15905                               UINT32);
15906 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15907         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15908                                  pos_token, "ip-src");
15909 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15910         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15911 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15912         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15913                                  pos_token, "ip-dst");
15914 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15915         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15916 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15917         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15918                                  pos_token, "vlan-tci");
15919 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15920         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15921                               UINT16);
15922 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15923         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15924                                  pos_token, "eth-src");
15925 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15926         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15927                                     eth_src);
15928 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15929         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15930                                  pos_token, "eth-dst");
15931 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15932         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15933                                     eth_dst);
15934
15935 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15936         __attribute__((unused)) struct cmdline *cl,
15937         __attribute__((unused)) void *data)
15938 {
15939         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15940         union {
15941                 uint32_t mplsogre_label;
15942                 uint8_t label[4];
15943         } id = {
15944                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15945         };
15946
15947         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15948                 mplsogre_encap_conf.select_vlan = 0;
15949         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15950                 mplsogre_encap_conf.select_vlan = 1;
15951         if (strcmp(res->ip_version, "ipv4") == 0)
15952                 mplsogre_encap_conf.select_ipv4 = 1;
15953         else if (strcmp(res->ip_version, "ipv6") == 0)
15954                 mplsogre_encap_conf.select_ipv4 = 0;
15955         else
15956                 return;
15957         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15958         if (mplsogre_encap_conf.select_ipv4) {
15959                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15960                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15961         } else {
15962                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15963                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15964         }
15965         if (mplsogre_encap_conf.select_vlan)
15966                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15967         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15968                    RTE_ETHER_ADDR_LEN);
15969         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15970                    RTE_ETHER_ADDR_LEN);
15971 }
15972
15973 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15974         .f = cmd_set_mplsogre_encap_parsed,
15975         .data = NULL,
15976         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15977                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15978                 " eth-dst <eth-dst>",
15979         .tokens = {
15980                 (void *)&cmd_set_mplsogre_encap_set,
15981                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15982                 (void *)&cmd_set_mplsogre_encap_ip_version,
15983                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15984                 (void *)&cmd_set_mplsogre_encap_label,
15985                 (void *)&cmd_set_mplsogre_encap_label_value,
15986                 (void *)&cmd_set_mplsogre_encap_ip_src,
15987                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15988                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15989                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15990                 (void *)&cmd_set_mplsogre_encap_eth_src,
15991                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15992                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15993                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15994                 NULL,
15995         },
15996 };
15997
15998 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15999         .f = cmd_set_mplsogre_encap_parsed,
16000         .data = NULL,
16001         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16002                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16003                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16004         .tokens = {
16005                 (void *)&cmd_set_mplsogre_encap_set,
16006                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16007                 (void *)&cmd_set_mplsogre_encap_ip_version,
16008                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16009                 (void *)&cmd_set_mplsogre_encap_label,
16010                 (void *)&cmd_set_mplsogre_encap_label_value,
16011                 (void *)&cmd_set_mplsogre_encap_ip_src,
16012                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16013                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16014                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16015                 (void *)&cmd_set_mplsogre_encap_vlan,
16016                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16017                 (void *)&cmd_set_mplsogre_encap_eth_src,
16018                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16019                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16020                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16021                 NULL,
16022         },
16023 };
16024
16025 /** Set MPLSoGRE decapsulation details */
16026 struct cmd_set_mplsogre_decap_result {
16027         cmdline_fixed_string_t set;
16028         cmdline_fixed_string_t mplsogre;
16029         cmdline_fixed_string_t pos_token;
16030         cmdline_fixed_string_t ip_version;
16031         uint32_t vlan_present:1;
16032 };
16033
16034 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16035         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16036                                  "set");
16037 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16038         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16039                                  "mplsogre_decap");
16040 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16041         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16042                                  mplsogre, "mplsogre_decap-with-vlan");
16043 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16044         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16045                                  pos_token, "ip-version");
16046 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16047         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16048                                  ip_version, "ipv4#ipv6");
16049
16050 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16051         __attribute__((unused)) struct cmdline *cl,
16052         __attribute__((unused)) void *data)
16053 {
16054         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16055
16056         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16057                 mplsogre_decap_conf.select_vlan = 0;
16058         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16059                 mplsogre_decap_conf.select_vlan = 1;
16060         if (strcmp(res->ip_version, "ipv4") == 0)
16061                 mplsogre_decap_conf.select_ipv4 = 1;
16062         else if (strcmp(res->ip_version, "ipv6") == 0)
16063                 mplsogre_decap_conf.select_ipv4 = 0;
16064 }
16065
16066 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16067         .f = cmd_set_mplsogre_decap_parsed,
16068         .data = NULL,
16069         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16070         .tokens = {
16071                 (void *)&cmd_set_mplsogre_decap_set,
16072                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16073                 (void *)&cmd_set_mplsogre_decap_ip_version,
16074                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16075                 NULL,
16076         },
16077 };
16078
16079 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16080         .f = cmd_set_mplsogre_decap_parsed,
16081         .data = NULL,
16082         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16083         .tokens = {
16084                 (void *)&cmd_set_mplsogre_decap_set,
16085                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16086                 (void *)&cmd_set_mplsogre_decap_ip_version,
16087                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16088                 NULL,
16089         },
16090 };
16091
16092 /** Set MPLSoUDP encapsulation details */
16093 struct cmd_set_mplsoudp_encap_result {
16094         cmdline_fixed_string_t set;
16095         cmdline_fixed_string_t mplsoudp;
16096         cmdline_fixed_string_t pos_token;
16097         cmdline_fixed_string_t ip_version;
16098         uint32_t vlan_present:1;
16099         uint32_t label;
16100         uint16_t udp_src;
16101         uint16_t udp_dst;
16102         cmdline_ipaddr_t ip_src;
16103         cmdline_ipaddr_t ip_dst;
16104         uint16_t tci;
16105         struct rte_ether_addr eth_src;
16106         struct rte_ether_addr eth_dst;
16107 };
16108
16109 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16110         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16111                                  "set");
16112 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16113         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16114                                  "mplsoudp_encap");
16115 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16116         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16117                                  mplsoudp, "mplsoudp_encap-with-vlan");
16118 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16119         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16120                                  pos_token, "ip-version");
16121 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16122         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16123                                  ip_version, "ipv4#ipv6");
16124 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16125         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16126                                  pos_token, "label");
16127 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16128         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16129                               UINT32);
16130 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16131         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16132                                  pos_token, "udp-src");
16133 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16134         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16135                               UINT16);
16136 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16137         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16138                                  pos_token, "udp-dst");
16139 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16140         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16141                               UINT16);
16142 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16143         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16144                                  pos_token, "ip-src");
16145 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16146         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16147 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16148         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16149                                  pos_token, "ip-dst");
16150 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16151         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16152 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16153         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16154                                  pos_token, "vlan-tci");
16155 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16156         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16157                               UINT16);
16158 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16159         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16160                                  pos_token, "eth-src");
16161 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16162         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16163                                     eth_src);
16164 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16165         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16166                                  pos_token, "eth-dst");
16167 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16168         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16169                                     eth_dst);
16170
16171 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16172         __attribute__((unused)) struct cmdline *cl,
16173         __attribute__((unused)) void *data)
16174 {
16175         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16176         union {
16177                 uint32_t mplsoudp_label;
16178                 uint8_t label[4];
16179         } id = {
16180                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16181         };
16182
16183         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16184                 mplsoudp_encap_conf.select_vlan = 0;
16185         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16186                 mplsoudp_encap_conf.select_vlan = 1;
16187         if (strcmp(res->ip_version, "ipv4") == 0)
16188                 mplsoudp_encap_conf.select_ipv4 = 1;
16189         else if (strcmp(res->ip_version, "ipv6") == 0)
16190                 mplsoudp_encap_conf.select_ipv4 = 0;
16191         else
16192                 return;
16193         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16194         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16195         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16196         if (mplsoudp_encap_conf.select_ipv4) {
16197                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16198                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16199         } else {
16200                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16201                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16202         }
16203         if (mplsoudp_encap_conf.select_vlan)
16204                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16205         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16206                    RTE_ETHER_ADDR_LEN);
16207         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16208                    RTE_ETHER_ADDR_LEN);
16209 }
16210
16211 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16212         .f = cmd_set_mplsoudp_encap_parsed,
16213         .data = NULL,
16214         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16215                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16216                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16217         .tokens = {
16218                 (void *)&cmd_set_mplsoudp_encap_set,
16219                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16220                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16221                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16222                 (void *)&cmd_set_mplsoudp_encap_label,
16223                 (void *)&cmd_set_mplsoudp_encap_label_value,
16224                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16225                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16226                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16227                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16228                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16229                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16230                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16231                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16232                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16233                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16234                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16235                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16236                 NULL,
16237         },
16238 };
16239
16240 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16241         .f = cmd_set_mplsoudp_encap_parsed,
16242         .data = NULL,
16243         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16244                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16245                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16246                 " eth-src <eth-src> eth-dst <eth-dst>",
16247         .tokens = {
16248                 (void *)&cmd_set_mplsoudp_encap_set,
16249                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16250                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16251                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16252                 (void *)&cmd_set_mplsoudp_encap_label,
16253                 (void *)&cmd_set_mplsoudp_encap_label_value,
16254                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16255                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16256                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16257                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16258                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16259                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16260                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16261                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16262                 (void *)&cmd_set_mplsoudp_encap_vlan,
16263                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16264                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16265                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16266                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16267                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16268                 NULL,
16269         },
16270 };
16271
16272 /** Set MPLSoUDP decapsulation details */
16273 struct cmd_set_mplsoudp_decap_result {
16274         cmdline_fixed_string_t set;
16275         cmdline_fixed_string_t mplsoudp;
16276         cmdline_fixed_string_t pos_token;
16277         cmdline_fixed_string_t ip_version;
16278         uint32_t vlan_present:1;
16279 };
16280
16281 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16282         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16283                                  "set");
16284 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16285         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16286                                  "mplsoudp_decap");
16287 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16288         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16289                                  mplsoudp, "mplsoudp_decap-with-vlan");
16290 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16291         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16292                                  pos_token, "ip-version");
16293 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16294         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16295                                  ip_version, "ipv4#ipv6");
16296
16297 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16298         __attribute__((unused)) struct cmdline *cl,
16299         __attribute__((unused)) void *data)
16300 {
16301         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16302
16303         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16304                 mplsoudp_decap_conf.select_vlan = 0;
16305         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16306                 mplsoudp_decap_conf.select_vlan = 1;
16307         if (strcmp(res->ip_version, "ipv4") == 0)
16308                 mplsoudp_decap_conf.select_ipv4 = 1;
16309         else if (strcmp(res->ip_version, "ipv6") == 0)
16310                 mplsoudp_decap_conf.select_ipv4 = 0;
16311 }
16312
16313 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16314         .f = cmd_set_mplsoudp_decap_parsed,
16315         .data = NULL,
16316         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16317         .tokens = {
16318                 (void *)&cmd_set_mplsoudp_decap_set,
16319                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16320                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16321                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16322                 NULL,
16323         },
16324 };
16325
16326 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16327         .f = cmd_set_mplsoudp_decap_parsed,
16328         .data = NULL,
16329         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16330         .tokens = {
16331                 (void *)&cmd_set_mplsoudp_decap_set,
16332                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16333                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16334                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16335                 NULL,
16336         },
16337 };
16338
16339 /* Strict link priority scheduling mode setting */
16340 static void
16341 cmd_strict_link_prio_parsed(
16342         void *parsed_result,
16343         __attribute__((unused)) struct cmdline *cl,
16344         __attribute__((unused)) void *data)
16345 {
16346         struct cmd_vf_tc_bw_result *res = parsed_result;
16347         int ret = -ENOTSUP;
16348
16349         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16350                 return;
16351
16352 #ifdef RTE_LIBRTE_I40E_PMD
16353         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16354 #endif
16355
16356         switch (ret) {
16357         case 0:
16358                 break;
16359         case -EINVAL:
16360                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16361                 break;
16362         case -ENODEV:
16363                 printf("invalid port_id %d\n", res->port_id);
16364                 break;
16365         case -ENOTSUP:
16366                 printf("function not implemented\n");
16367                 break;
16368         default:
16369                 printf("programming error: (%s)\n", strerror(-ret));
16370         }
16371 }
16372
16373 cmdline_parse_inst_t cmd_strict_link_prio = {
16374         .f = cmd_strict_link_prio_parsed,
16375         .data = NULL,
16376         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16377         .tokens = {
16378                 (void *)&cmd_vf_tc_bw_set,
16379                 (void *)&cmd_vf_tc_bw_tx,
16380                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16381                 (void *)&cmd_vf_tc_bw_port_id,
16382                 (void *)&cmd_vf_tc_bw_tc_map,
16383                 NULL,
16384         },
16385 };
16386
16387 /* Load dynamic device personalization*/
16388 struct cmd_ddp_add_result {
16389         cmdline_fixed_string_t ddp;
16390         cmdline_fixed_string_t add;
16391         portid_t port_id;
16392         char filepath[];
16393 };
16394
16395 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16396         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16397 cmdline_parse_token_string_t cmd_ddp_add_add =
16398         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16399 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16400         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16401 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16402         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16403
16404 static void
16405 cmd_ddp_add_parsed(
16406         void *parsed_result,
16407         __attribute__((unused)) struct cmdline *cl,
16408         __attribute__((unused)) void *data)
16409 {
16410         struct cmd_ddp_add_result *res = parsed_result;
16411         uint8_t *buff;
16412         uint32_t size;
16413         char *filepath;
16414         char *file_fld[2];
16415         int file_num;
16416         int ret = -ENOTSUP;
16417
16418         if (!all_ports_stopped()) {
16419                 printf("Please stop all ports first\n");
16420                 return;
16421         }
16422
16423         filepath = strdup(res->filepath);
16424         if (filepath == NULL) {
16425                 printf("Failed to allocate memory\n");
16426                 return;
16427         }
16428         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16429
16430         buff = open_file(file_fld[0], &size);
16431         if (!buff) {
16432                 free((void *)filepath);
16433                 return;
16434         }
16435
16436 #ifdef RTE_LIBRTE_I40E_PMD
16437         if (ret == -ENOTSUP)
16438                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16439                                                buff, size,
16440                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16441 #endif
16442
16443         if (ret == -EEXIST)
16444                 printf("Profile has already existed.\n");
16445         else if (ret < 0)
16446                 printf("Failed to load profile.\n");
16447         else if (file_num == 2)
16448                 save_file(file_fld[1], buff, size);
16449
16450         close_file(buff);
16451         free((void *)filepath);
16452 }
16453
16454 cmdline_parse_inst_t cmd_ddp_add = {
16455         .f = cmd_ddp_add_parsed,
16456         .data = NULL,
16457         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16458         .tokens = {
16459                 (void *)&cmd_ddp_add_ddp,
16460                 (void *)&cmd_ddp_add_add,
16461                 (void *)&cmd_ddp_add_port_id,
16462                 (void *)&cmd_ddp_add_filepath,
16463                 NULL,
16464         },
16465 };
16466
16467 /* Delete dynamic device personalization*/
16468 struct cmd_ddp_del_result {
16469         cmdline_fixed_string_t ddp;
16470         cmdline_fixed_string_t del;
16471         portid_t port_id;
16472         char filepath[];
16473 };
16474
16475 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16476         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16477 cmdline_parse_token_string_t cmd_ddp_del_del =
16478         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16479 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16480         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16481 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16482         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16483
16484 static void
16485 cmd_ddp_del_parsed(
16486         void *parsed_result,
16487         __attribute__((unused)) struct cmdline *cl,
16488         __attribute__((unused)) void *data)
16489 {
16490         struct cmd_ddp_del_result *res = parsed_result;
16491         uint8_t *buff;
16492         uint32_t size;
16493         int ret = -ENOTSUP;
16494
16495         if (!all_ports_stopped()) {
16496                 printf("Please stop all ports first\n");
16497                 return;
16498         }
16499
16500         buff = open_file(res->filepath, &size);
16501         if (!buff)
16502                 return;
16503
16504 #ifdef RTE_LIBRTE_I40E_PMD
16505         if (ret == -ENOTSUP)
16506                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16507                                                buff, size,
16508                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16509 #endif
16510
16511         if (ret == -EACCES)
16512                 printf("Profile does not exist.\n");
16513         else if (ret < 0)
16514                 printf("Failed to delete profile.\n");
16515
16516         close_file(buff);
16517 }
16518
16519 cmdline_parse_inst_t cmd_ddp_del = {
16520         .f = cmd_ddp_del_parsed,
16521         .data = NULL,
16522         .help_str = "ddp del <port_id> <backup_profile_path>",
16523         .tokens = {
16524                 (void *)&cmd_ddp_del_ddp,
16525                 (void *)&cmd_ddp_del_del,
16526                 (void *)&cmd_ddp_del_port_id,
16527                 (void *)&cmd_ddp_del_filepath,
16528                 NULL,
16529         },
16530 };
16531
16532 /* Get dynamic device personalization profile info */
16533 struct cmd_ddp_info_result {
16534         cmdline_fixed_string_t ddp;
16535         cmdline_fixed_string_t get;
16536         cmdline_fixed_string_t info;
16537         char filepath[];
16538 };
16539
16540 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16541         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16542 cmdline_parse_token_string_t cmd_ddp_info_get =
16543         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16544 cmdline_parse_token_string_t cmd_ddp_info_info =
16545         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16546 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16547         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16548
16549 static void
16550 cmd_ddp_info_parsed(
16551         void *parsed_result,
16552         __attribute__((unused)) struct cmdline *cl,
16553         __attribute__((unused)) void *data)
16554 {
16555         struct cmd_ddp_info_result *res = parsed_result;
16556         uint8_t *pkg;
16557         uint32_t pkg_size;
16558         int ret = -ENOTSUP;
16559 #ifdef RTE_LIBRTE_I40E_PMD
16560         uint32_t i, j, n;
16561         uint8_t *buff;
16562         uint32_t buff_size = 0;
16563         struct rte_pmd_i40e_profile_info info;
16564         uint32_t dev_num = 0;
16565         struct rte_pmd_i40e_ddp_device_id *devs;
16566         uint32_t proto_num = 0;
16567         struct rte_pmd_i40e_proto_info *proto = NULL;
16568         uint32_t pctype_num = 0;
16569         struct rte_pmd_i40e_ptype_info *pctype;
16570         uint32_t ptype_num = 0;
16571         struct rte_pmd_i40e_ptype_info *ptype;
16572         uint8_t proto_id;
16573
16574 #endif
16575
16576         pkg = open_file(res->filepath, &pkg_size);
16577         if (!pkg)
16578                 return;
16579
16580 #ifdef RTE_LIBRTE_I40E_PMD
16581         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16582                                 (uint8_t *)&info, sizeof(info),
16583                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16584         if (!ret) {
16585                 printf("Global Track id:       0x%x\n", info.track_id);
16586                 printf("Global Version:        %d.%d.%d.%d\n",
16587                         info.version.major,
16588                         info.version.minor,
16589                         info.version.update,
16590                         info.version.draft);
16591                 printf("Global Package name:   %s\n\n", info.name);
16592         }
16593
16594         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16595                                 (uint8_t *)&info, sizeof(info),
16596                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16597         if (!ret) {
16598                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16599                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16600                         info.version.major,
16601                         info.version.minor,
16602                         info.version.update,
16603                         info.version.draft);
16604                 printf("i40e Profile name:     %s\n\n", info.name);
16605         }
16606
16607         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16608                                 (uint8_t *)&buff_size, sizeof(buff_size),
16609                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16610         if (!ret && buff_size) {
16611                 buff = (uint8_t *)malloc(buff_size);
16612                 if (buff) {
16613                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16614                                                 buff, buff_size,
16615                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16616                         if (!ret)
16617                                 printf("Package Notes:\n%s\n\n", buff);
16618                         free(buff);
16619                 }
16620         }
16621
16622         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16623                                 (uint8_t *)&dev_num, sizeof(dev_num),
16624                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16625         if (!ret && dev_num) {
16626                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16627                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16628                 if (devs) {
16629                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16630                                                 (uint8_t *)devs, buff_size,
16631                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16632                         if (!ret) {
16633                                 printf("List of supported devices:\n");
16634                                 for (i = 0; i < dev_num; i++) {
16635                                         printf("  %04X:%04X %04X:%04X\n",
16636                                                 devs[i].vendor_dev_id >> 16,
16637                                                 devs[i].vendor_dev_id & 0xFFFF,
16638                                                 devs[i].sub_vendor_dev_id >> 16,
16639                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16640                                 }
16641                                 printf("\n");
16642                         }
16643                         free(devs);
16644                 }
16645         }
16646
16647         /* get information about protocols and packet types */
16648         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16649                 (uint8_t *)&proto_num, sizeof(proto_num),
16650                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16651         if (ret || !proto_num)
16652                 goto no_print_return;
16653
16654         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16655         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16656         if (!proto)
16657                 goto no_print_return;
16658
16659         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16660                                         buff_size,
16661                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16662         if (!ret) {
16663                 printf("List of used protocols:\n");
16664                 for (i = 0; i < proto_num; i++)
16665                         printf("  %2u: %s\n", proto[i].proto_id,
16666                                proto[i].name);
16667                 printf("\n");
16668         }
16669         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16670                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16671                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16672         if (ret || !pctype_num)
16673                 goto no_print_pctypes;
16674
16675         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16676         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16677         if (!pctype)
16678                 goto no_print_pctypes;
16679
16680         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16681                                         buff_size,
16682                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16683         if (ret) {
16684                 free(pctype);
16685                 goto no_print_pctypes;
16686         }
16687
16688         printf("List of defined packet classification types:\n");
16689         for (i = 0; i < pctype_num; i++) {
16690                 printf("  %2u:", pctype[i].ptype_id);
16691                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16692                         proto_id = pctype[i].protocols[j];
16693                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16694                                 for (n = 0; n < proto_num; n++) {
16695                                         if (proto[n].proto_id == proto_id) {
16696                                                 printf(" %s", proto[n].name);
16697                                                 break;
16698                                         }
16699                                 }
16700                         }
16701                 }
16702                 printf("\n");
16703         }
16704         printf("\n");
16705         free(pctype);
16706
16707 no_print_pctypes:
16708
16709         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16710                                         sizeof(ptype_num),
16711                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16712         if (ret || !ptype_num)
16713                 goto no_print_return;
16714
16715         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16716         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16717         if (!ptype)
16718                 goto no_print_return;
16719
16720         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16721                                         buff_size,
16722                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16723         if (ret) {
16724                 free(ptype);
16725                 goto no_print_return;
16726         }
16727         printf("List of defined packet types:\n");
16728         for (i = 0; i < ptype_num; i++) {
16729                 printf("  %2u:", ptype[i].ptype_id);
16730                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16731                         proto_id = ptype[i].protocols[j];
16732                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16733                                 for (n = 0; n < proto_num; n++) {
16734                                         if (proto[n].proto_id == proto_id) {
16735                                                 printf(" %s", proto[n].name);
16736                                                 break;
16737                                         }
16738                                 }
16739                         }
16740                 }
16741                 printf("\n");
16742         }
16743         free(ptype);
16744         printf("\n");
16745
16746         ret = 0;
16747 no_print_return:
16748         if (proto)
16749                 free(proto);
16750 #endif
16751         if (ret == -ENOTSUP)
16752                 printf("Function not supported in PMD driver\n");
16753         close_file(pkg);
16754 }
16755
16756 cmdline_parse_inst_t cmd_ddp_get_info = {
16757         .f = cmd_ddp_info_parsed,
16758         .data = NULL,
16759         .help_str = "ddp get info <profile_path>",
16760         .tokens = {
16761                 (void *)&cmd_ddp_info_ddp,
16762                 (void *)&cmd_ddp_info_get,
16763                 (void *)&cmd_ddp_info_info,
16764                 (void *)&cmd_ddp_info_filepath,
16765                 NULL,
16766         },
16767 };
16768
16769 /* Get dynamic device personalization profile info list*/
16770 #define PROFILE_INFO_SIZE 48
16771 #define MAX_PROFILE_NUM 16
16772
16773 struct cmd_ddp_get_list_result {
16774         cmdline_fixed_string_t ddp;
16775         cmdline_fixed_string_t get;
16776         cmdline_fixed_string_t list;
16777         portid_t port_id;
16778 };
16779
16780 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16781         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16782 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16783         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16784 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16785         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16786 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16787         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16788
16789 static void
16790 cmd_ddp_get_list_parsed(
16791         __attribute__((unused)) void *parsed_result,
16792         __attribute__((unused)) struct cmdline *cl,
16793         __attribute__((unused)) void *data)
16794 {
16795 #ifdef RTE_LIBRTE_I40E_PMD
16796         struct cmd_ddp_get_list_result *res = parsed_result;
16797         struct rte_pmd_i40e_profile_list *p_list;
16798         struct rte_pmd_i40e_profile_info *p_info;
16799         uint32_t p_num;
16800         uint32_t size;
16801         uint32_t i;
16802 #endif
16803         int ret = -ENOTSUP;
16804
16805 #ifdef RTE_LIBRTE_I40E_PMD
16806         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16807         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16808         if (!p_list)
16809                 printf("%s: Failed to malloc buffer\n", __func__);
16810
16811         if (ret == -ENOTSUP)
16812                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16813                                                 (uint8_t *)p_list, size);
16814
16815         if (!ret) {
16816                 p_num = p_list->p_count;
16817                 printf("Profile number is: %d\n\n", p_num);
16818
16819                 for (i = 0; i < p_num; i++) {
16820                         p_info = &p_list->p_info[i];
16821                         printf("Profile %d:\n", i);
16822                         printf("Track id:     0x%x\n", p_info->track_id);
16823                         printf("Version:      %d.%d.%d.%d\n",
16824                                p_info->version.major,
16825                                p_info->version.minor,
16826                                p_info->version.update,
16827                                p_info->version.draft);
16828                         printf("Profile name: %s\n\n", p_info->name);
16829                 }
16830         }
16831
16832         free(p_list);
16833 #endif
16834
16835         if (ret < 0)
16836                 printf("Failed to get ddp list\n");
16837 }
16838
16839 cmdline_parse_inst_t cmd_ddp_get_list = {
16840         .f = cmd_ddp_get_list_parsed,
16841         .data = NULL,
16842         .help_str = "ddp get list <port_id>",
16843         .tokens = {
16844                 (void *)&cmd_ddp_get_list_ddp,
16845                 (void *)&cmd_ddp_get_list_get,
16846                 (void *)&cmd_ddp_get_list_list,
16847                 (void *)&cmd_ddp_get_list_port_id,
16848                 NULL,
16849         },
16850 };
16851
16852 /* Configure input set */
16853 struct cmd_cfg_input_set_result {
16854         cmdline_fixed_string_t port;
16855         cmdline_fixed_string_t cfg;
16856         portid_t port_id;
16857         cmdline_fixed_string_t pctype;
16858         uint8_t pctype_id;
16859         cmdline_fixed_string_t inset_type;
16860         cmdline_fixed_string_t opt;
16861         cmdline_fixed_string_t field;
16862         uint8_t field_idx;
16863 };
16864
16865 static void
16866 cmd_cfg_input_set_parsed(
16867         __attribute__((unused)) void *parsed_result,
16868         __attribute__((unused)) struct cmdline *cl,
16869         __attribute__((unused)) void *data)
16870 {
16871 #ifdef RTE_LIBRTE_I40E_PMD
16872         struct cmd_cfg_input_set_result *res = parsed_result;
16873         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16874         struct rte_pmd_i40e_inset inset;
16875 #endif
16876         int ret = -ENOTSUP;
16877
16878         if (!all_ports_stopped()) {
16879                 printf("Please stop all ports first\n");
16880                 return;
16881         }
16882
16883 #ifdef RTE_LIBRTE_I40E_PMD
16884         if (!strcmp(res->inset_type, "hash_inset"))
16885                 inset_type = INSET_HASH;
16886         else if (!strcmp(res->inset_type, "fdir_inset"))
16887                 inset_type = INSET_FDIR;
16888         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16889                 inset_type = INSET_FDIR_FLX;
16890         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16891                                      &inset, inset_type);
16892         if (ret) {
16893                 printf("Failed to get input set.\n");
16894                 return;
16895         }
16896
16897         if (!strcmp(res->opt, "get")) {
16898                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16899                                                    res->field_idx);
16900                 if (ret)
16901                         printf("Field index %d is enabled.\n", res->field_idx);
16902                 else
16903                         printf("Field index %d is disabled.\n", res->field_idx);
16904                 return;
16905         } else if (!strcmp(res->opt, "set"))
16906                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16907                                                    res->field_idx);
16908         else if (!strcmp(res->opt, "clear"))
16909                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16910                                                      res->field_idx);
16911         if (ret) {
16912                 printf("Failed to configure input set field.\n");
16913                 return;
16914         }
16915
16916         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16917                                      &inset, inset_type);
16918         if (ret) {
16919                 printf("Failed to set input set.\n");
16920                 return;
16921         }
16922 #endif
16923
16924         if (ret == -ENOTSUP)
16925                 printf("Function not supported\n");
16926 }
16927
16928 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16929         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16930                                  port, "port");
16931 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16932         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16933                                  cfg, "config");
16934 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16935         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16936                               port_id, UINT16);
16937 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16938         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16939                                  pctype, "pctype");
16940 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16941         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16942                               pctype_id, UINT8);
16943 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16944         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16945                                  inset_type,
16946                                  "hash_inset#fdir_inset#fdir_flx_inset");
16947 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16948         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16949                                  opt, "get#set#clear");
16950 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16951         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16952                                  field, "field");
16953 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16954         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16955                               field_idx, UINT8);
16956
16957 cmdline_parse_inst_t cmd_cfg_input_set = {
16958         .f = cmd_cfg_input_set_parsed,
16959         .data = NULL,
16960         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16961                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16962         .tokens = {
16963                 (void *)&cmd_cfg_input_set_port,
16964                 (void *)&cmd_cfg_input_set_cfg,
16965                 (void *)&cmd_cfg_input_set_port_id,
16966                 (void *)&cmd_cfg_input_set_pctype,
16967                 (void *)&cmd_cfg_input_set_pctype_id,
16968                 (void *)&cmd_cfg_input_set_inset_type,
16969                 (void *)&cmd_cfg_input_set_opt,
16970                 (void *)&cmd_cfg_input_set_field,
16971                 (void *)&cmd_cfg_input_set_field_idx,
16972                 NULL,
16973         },
16974 };
16975
16976 /* Clear input set */
16977 struct cmd_clear_input_set_result {
16978         cmdline_fixed_string_t port;
16979         cmdline_fixed_string_t cfg;
16980         portid_t port_id;
16981         cmdline_fixed_string_t pctype;
16982         uint8_t pctype_id;
16983         cmdline_fixed_string_t inset_type;
16984         cmdline_fixed_string_t clear;
16985         cmdline_fixed_string_t all;
16986 };
16987
16988 static void
16989 cmd_clear_input_set_parsed(
16990         __attribute__((unused)) void *parsed_result,
16991         __attribute__((unused)) struct cmdline *cl,
16992         __attribute__((unused)) void *data)
16993 {
16994 #ifdef RTE_LIBRTE_I40E_PMD
16995         struct cmd_clear_input_set_result *res = parsed_result;
16996         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16997         struct rte_pmd_i40e_inset inset;
16998 #endif
16999         int ret = -ENOTSUP;
17000
17001         if (!all_ports_stopped()) {
17002                 printf("Please stop all ports first\n");
17003                 return;
17004         }
17005
17006 #ifdef RTE_LIBRTE_I40E_PMD
17007         if (!strcmp(res->inset_type, "hash_inset"))
17008                 inset_type = INSET_HASH;
17009         else if (!strcmp(res->inset_type, "fdir_inset"))
17010                 inset_type = INSET_FDIR;
17011         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17012                 inset_type = INSET_FDIR_FLX;
17013
17014         memset(&inset, 0, sizeof(inset));
17015
17016         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17017                                      &inset, inset_type);
17018         if (ret) {
17019                 printf("Failed to clear input set.\n");
17020                 return;
17021         }
17022
17023 #endif
17024
17025         if (ret == -ENOTSUP)
17026                 printf("Function not supported\n");
17027 }
17028
17029 cmdline_parse_token_string_t cmd_clear_input_set_port =
17030         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17031                                  port, "port");
17032 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17033         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17034                                  cfg, "config");
17035 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17036         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17037                               port_id, UINT16);
17038 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17039         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17040                                  pctype, "pctype");
17041 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17042         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17043                               pctype_id, UINT8);
17044 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17045         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17046                                  inset_type,
17047                                  "hash_inset#fdir_inset#fdir_flx_inset");
17048 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17049         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17050                                  clear, "clear");
17051 cmdline_parse_token_string_t cmd_clear_input_set_all =
17052         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17053                                  all, "all");
17054
17055 cmdline_parse_inst_t cmd_clear_input_set = {
17056         .f = cmd_clear_input_set_parsed,
17057         .data = NULL,
17058         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17059                     "fdir_inset|fdir_flx_inset clear all",
17060         .tokens = {
17061                 (void *)&cmd_clear_input_set_port,
17062                 (void *)&cmd_clear_input_set_cfg,
17063                 (void *)&cmd_clear_input_set_port_id,
17064                 (void *)&cmd_clear_input_set_pctype,
17065                 (void *)&cmd_clear_input_set_pctype_id,
17066                 (void *)&cmd_clear_input_set_inset_type,
17067                 (void *)&cmd_clear_input_set_clear,
17068                 (void *)&cmd_clear_input_set_all,
17069                 NULL,
17070         },
17071 };
17072
17073 /* show vf stats */
17074
17075 /* Common result structure for show vf stats */
17076 struct cmd_show_vf_stats_result {
17077         cmdline_fixed_string_t show;
17078         cmdline_fixed_string_t vf;
17079         cmdline_fixed_string_t stats;
17080         portid_t port_id;
17081         uint16_t vf_id;
17082 };
17083
17084 /* Common CLI fields show vf stats*/
17085 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17086         TOKEN_STRING_INITIALIZER
17087                 (struct cmd_show_vf_stats_result,
17088                  show, "show");
17089 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17090         TOKEN_STRING_INITIALIZER
17091                 (struct cmd_show_vf_stats_result,
17092                  vf, "vf");
17093 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17094         TOKEN_STRING_INITIALIZER
17095                 (struct cmd_show_vf_stats_result,
17096                  stats, "stats");
17097 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17098         TOKEN_NUM_INITIALIZER
17099                 (struct cmd_show_vf_stats_result,
17100                  port_id, UINT16);
17101 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17102         TOKEN_NUM_INITIALIZER
17103                 (struct cmd_show_vf_stats_result,
17104                  vf_id, UINT16);
17105
17106 static void
17107 cmd_show_vf_stats_parsed(
17108         void *parsed_result,
17109         __attribute__((unused)) struct cmdline *cl,
17110         __attribute__((unused)) void *data)
17111 {
17112         struct cmd_show_vf_stats_result *res = parsed_result;
17113         struct rte_eth_stats stats;
17114         int ret = -ENOTSUP;
17115         static const char *nic_stats_border = "########################";
17116
17117         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17118                 return;
17119
17120         memset(&stats, 0, sizeof(stats));
17121
17122 #ifdef RTE_LIBRTE_I40E_PMD
17123         if (ret == -ENOTSUP)
17124                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17125                                                 res->vf_id,
17126                                                 &stats);
17127 #endif
17128 #ifdef RTE_LIBRTE_BNXT_PMD
17129         if (ret == -ENOTSUP)
17130                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17131                                                 res->vf_id,
17132                                                 &stats);
17133 #endif
17134
17135         switch (ret) {
17136         case 0:
17137                 break;
17138         case -EINVAL:
17139                 printf("invalid vf_id %d\n", res->vf_id);
17140                 break;
17141         case -ENODEV:
17142                 printf("invalid port_id %d\n", res->port_id);
17143                 break;
17144         case -ENOTSUP:
17145                 printf("function not implemented\n");
17146                 break;
17147         default:
17148                 printf("programming error: (%s)\n", strerror(-ret));
17149         }
17150
17151         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17152                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17153
17154         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17155                "%-"PRIu64"\n",
17156                stats.ipackets, stats.imissed, stats.ibytes);
17157         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17158         printf("  RX-nombuf:  %-10"PRIu64"\n",
17159                stats.rx_nombuf);
17160         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17161                "%-"PRIu64"\n",
17162                stats.opackets, stats.oerrors, stats.obytes);
17163
17164         printf("  %s############################%s\n",
17165                                nic_stats_border, nic_stats_border);
17166 }
17167
17168 cmdline_parse_inst_t cmd_show_vf_stats = {
17169         .f = cmd_show_vf_stats_parsed,
17170         .data = NULL,
17171         .help_str = "show vf stats <port_id> <vf_id>",
17172         .tokens = {
17173                 (void *)&cmd_show_vf_stats_show,
17174                 (void *)&cmd_show_vf_stats_vf,
17175                 (void *)&cmd_show_vf_stats_stats,
17176                 (void *)&cmd_show_vf_stats_port_id,
17177                 (void *)&cmd_show_vf_stats_vf_id,
17178                 NULL,
17179         },
17180 };
17181
17182 /* clear vf stats */
17183
17184 /* Common result structure for clear vf stats */
17185 struct cmd_clear_vf_stats_result {
17186         cmdline_fixed_string_t clear;
17187         cmdline_fixed_string_t vf;
17188         cmdline_fixed_string_t stats;
17189         portid_t port_id;
17190         uint16_t vf_id;
17191 };
17192
17193 /* Common CLI fields clear vf stats*/
17194 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17195         TOKEN_STRING_INITIALIZER
17196                 (struct cmd_clear_vf_stats_result,
17197                  clear, "clear");
17198 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17199         TOKEN_STRING_INITIALIZER
17200                 (struct cmd_clear_vf_stats_result,
17201                  vf, "vf");
17202 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17203         TOKEN_STRING_INITIALIZER
17204                 (struct cmd_clear_vf_stats_result,
17205                  stats, "stats");
17206 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17207         TOKEN_NUM_INITIALIZER
17208                 (struct cmd_clear_vf_stats_result,
17209                  port_id, UINT16);
17210 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17211         TOKEN_NUM_INITIALIZER
17212                 (struct cmd_clear_vf_stats_result,
17213                  vf_id, UINT16);
17214
17215 static void
17216 cmd_clear_vf_stats_parsed(
17217         void *parsed_result,
17218         __attribute__((unused)) struct cmdline *cl,
17219         __attribute__((unused)) void *data)
17220 {
17221         struct cmd_clear_vf_stats_result *res = parsed_result;
17222         int ret = -ENOTSUP;
17223
17224         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17225                 return;
17226
17227 #ifdef RTE_LIBRTE_I40E_PMD
17228         if (ret == -ENOTSUP)
17229                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17230                                                   res->vf_id);
17231 #endif
17232 #ifdef RTE_LIBRTE_BNXT_PMD
17233         if (ret == -ENOTSUP)
17234                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17235                                                   res->vf_id);
17236 #endif
17237
17238         switch (ret) {
17239         case 0:
17240                 break;
17241         case -EINVAL:
17242                 printf("invalid vf_id %d\n", res->vf_id);
17243                 break;
17244         case -ENODEV:
17245                 printf("invalid port_id %d\n", res->port_id);
17246                 break;
17247         case -ENOTSUP:
17248                 printf("function not implemented\n");
17249                 break;
17250         default:
17251                 printf("programming error: (%s)\n", strerror(-ret));
17252         }
17253 }
17254
17255 cmdline_parse_inst_t cmd_clear_vf_stats = {
17256         .f = cmd_clear_vf_stats_parsed,
17257         .data = NULL,
17258         .help_str = "clear vf stats <port_id> <vf_id>",
17259         .tokens = {
17260                 (void *)&cmd_clear_vf_stats_clear,
17261                 (void *)&cmd_clear_vf_stats_vf,
17262                 (void *)&cmd_clear_vf_stats_stats,
17263                 (void *)&cmd_clear_vf_stats_port_id,
17264                 (void *)&cmd_clear_vf_stats_vf_id,
17265                 NULL,
17266         },
17267 };
17268
17269 /* port config pctype mapping reset */
17270
17271 /* Common result structure for port config pctype mapping reset */
17272 struct cmd_pctype_mapping_reset_result {
17273         cmdline_fixed_string_t port;
17274         cmdline_fixed_string_t config;
17275         portid_t port_id;
17276         cmdline_fixed_string_t pctype;
17277         cmdline_fixed_string_t mapping;
17278         cmdline_fixed_string_t reset;
17279 };
17280
17281 /* Common CLI fields for port config pctype mapping reset*/
17282 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17283         TOKEN_STRING_INITIALIZER
17284                 (struct cmd_pctype_mapping_reset_result,
17285                  port, "port");
17286 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17287         TOKEN_STRING_INITIALIZER
17288                 (struct cmd_pctype_mapping_reset_result,
17289                  config, "config");
17290 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17291         TOKEN_NUM_INITIALIZER
17292                 (struct cmd_pctype_mapping_reset_result,
17293                  port_id, UINT16);
17294 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17295         TOKEN_STRING_INITIALIZER
17296                 (struct cmd_pctype_mapping_reset_result,
17297                  pctype, "pctype");
17298 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17299         TOKEN_STRING_INITIALIZER
17300                 (struct cmd_pctype_mapping_reset_result,
17301                  mapping, "mapping");
17302 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17303         TOKEN_STRING_INITIALIZER
17304                 (struct cmd_pctype_mapping_reset_result,
17305                  reset, "reset");
17306
17307 static void
17308 cmd_pctype_mapping_reset_parsed(
17309         void *parsed_result,
17310         __attribute__((unused)) struct cmdline *cl,
17311         __attribute__((unused)) void *data)
17312 {
17313         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17314         int ret = -ENOTSUP;
17315
17316         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17317                 return;
17318
17319 #ifdef RTE_LIBRTE_I40E_PMD
17320         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17321 #endif
17322
17323         switch (ret) {
17324         case 0:
17325                 break;
17326         case -ENODEV:
17327                 printf("invalid port_id %d\n", res->port_id);
17328                 break;
17329         case -ENOTSUP:
17330                 printf("function not implemented\n");
17331                 break;
17332         default:
17333                 printf("programming error: (%s)\n", strerror(-ret));
17334         }
17335 }
17336
17337 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17338         .f = cmd_pctype_mapping_reset_parsed,
17339         .data = NULL,
17340         .help_str = "port config <port_id> pctype mapping reset",
17341         .tokens = {
17342                 (void *)&cmd_pctype_mapping_reset_port,
17343                 (void *)&cmd_pctype_mapping_reset_config,
17344                 (void *)&cmd_pctype_mapping_reset_port_id,
17345                 (void *)&cmd_pctype_mapping_reset_pctype,
17346                 (void *)&cmd_pctype_mapping_reset_mapping,
17347                 (void *)&cmd_pctype_mapping_reset_reset,
17348                 NULL,
17349         },
17350 };
17351
17352 /* show port pctype mapping */
17353
17354 /* Common result structure for show port pctype mapping */
17355 struct cmd_pctype_mapping_get_result {
17356         cmdline_fixed_string_t show;
17357         cmdline_fixed_string_t port;
17358         portid_t port_id;
17359         cmdline_fixed_string_t pctype;
17360         cmdline_fixed_string_t mapping;
17361 };
17362
17363 /* Common CLI fields for pctype mapping get */
17364 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17365         TOKEN_STRING_INITIALIZER
17366                 (struct cmd_pctype_mapping_get_result,
17367                  show, "show");
17368 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17369         TOKEN_STRING_INITIALIZER
17370                 (struct cmd_pctype_mapping_get_result,
17371                  port, "port");
17372 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17373         TOKEN_NUM_INITIALIZER
17374                 (struct cmd_pctype_mapping_get_result,
17375                  port_id, UINT16);
17376 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17377         TOKEN_STRING_INITIALIZER
17378                 (struct cmd_pctype_mapping_get_result,
17379                  pctype, "pctype");
17380 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17381         TOKEN_STRING_INITIALIZER
17382                 (struct cmd_pctype_mapping_get_result,
17383                  mapping, "mapping");
17384
17385 static void
17386 cmd_pctype_mapping_get_parsed(
17387         void *parsed_result,
17388         __attribute__((unused)) struct cmdline *cl,
17389         __attribute__((unused)) void *data)
17390 {
17391         struct cmd_pctype_mapping_get_result *res = parsed_result;
17392         int ret = -ENOTSUP;
17393 #ifdef RTE_LIBRTE_I40E_PMD
17394         struct rte_pmd_i40e_flow_type_mapping
17395                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17396         int i, j, first_pctype;
17397 #endif
17398
17399         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17400                 return;
17401
17402 #ifdef RTE_LIBRTE_I40E_PMD
17403         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17404 #endif
17405
17406         switch (ret) {
17407         case 0:
17408                 break;
17409         case -ENODEV:
17410                 printf("invalid port_id %d\n", res->port_id);
17411                 return;
17412         case -ENOTSUP:
17413                 printf("function not implemented\n");
17414                 return;
17415         default:
17416                 printf("programming error: (%s)\n", strerror(-ret));
17417                 return;
17418         }
17419
17420 #ifdef RTE_LIBRTE_I40E_PMD
17421         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17422                 if (mapping[i].pctype != 0ULL) {
17423                         first_pctype = 1;
17424
17425                         printf("pctype: ");
17426                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17427                                 if (mapping[i].pctype & (1ULL << j)) {
17428                                         printf(first_pctype ?
17429                                                "%02d" : ",%02d", j);
17430                                         first_pctype = 0;
17431                                 }
17432                         }
17433                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17434                 }
17435         }
17436 #endif
17437 }
17438
17439 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17440         .f = cmd_pctype_mapping_get_parsed,
17441         .data = NULL,
17442         .help_str = "show port <port_id> pctype mapping",
17443         .tokens = {
17444                 (void *)&cmd_pctype_mapping_get_show,
17445                 (void *)&cmd_pctype_mapping_get_port,
17446                 (void *)&cmd_pctype_mapping_get_port_id,
17447                 (void *)&cmd_pctype_mapping_get_pctype,
17448                 (void *)&cmd_pctype_mapping_get_mapping,
17449                 NULL,
17450         },
17451 };
17452
17453 /* port config pctype mapping update */
17454
17455 /* Common result structure for port config pctype mapping update */
17456 struct cmd_pctype_mapping_update_result {
17457         cmdline_fixed_string_t port;
17458         cmdline_fixed_string_t config;
17459         portid_t port_id;
17460         cmdline_fixed_string_t pctype;
17461         cmdline_fixed_string_t mapping;
17462         cmdline_fixed_string_t update;
17463         cmdline_fixed_string_t pctype_list;
17464         uint16_t flow_type;
17465 };
17466
17467 /* Common CLI fields for pctype mapping update*/
17468 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17469         TOKEN_STRING_INITIALIZER
17470                 (struct cmd_pctype_mapping_update_result,
17471                  port, "port");
17472 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17473         TOKEN_STRING_INITIALIZER
17474                 (struct cmd_pctype_mapping_update_result,
17475                  config, "config");
17476 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17477         TOKEN_NUM_INITIALIZER
17478                 (struct cmd_pctype_mapping_update_result,
17479                  port_id, UINT16);
17480 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17481         TOKEN_STRING_INITIALIZER
17482                 (struct cmd_pctype_mapping_update_result,
17483                  pctype, "pctype");
17484 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17485         TOKEN_STRING_INITIALIZER
17486                 (struct cmd_pctype_mapping_update_result,
17487                  mapping, "mapping");
17488 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17489         TOKEN_STRING_INITIALIZER
17490                 (struct cmd_pctype_mapping_update_result,
17491                  update, "update");
17492 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17493         TOKEN_STRING_INITIALIZER
17494                 (struct cmd_pctype_mapping_update_result,
17495                  pctype_list, NULL);
17496 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17497         TOKEN_NUM_INITIALIZER
17498                 (struct cmd_pctype_mapping_update_result,
17499                  flow_type, UINT16);
17500
17501 static void
17502 cmd_pctype_mapping_update_parsed(
17503         void *parsed_result,
17504         __attribute__((unused)) struct cmdline *cl,
17505         __attribute__((unused)) void *data)
17506 {
17507         struct cmd_pctype_mapping_update_result *res = parsed_result;
17508         int ret = -ENOTSUP;
17509 #ifdef RTE_LIBRTE_I40E_PMD
17510         struct rte_pmd_i40e_flow_type_mapping mapping;
17511         unsigned int i;
17512         unsigned int nb_item;
17513         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17514 #endif
17515
17516         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17517                 return;
17518
17519 #ifdef RTE_LIBRTE_I40E_PMD
17520         nb_item = parse_item_list(res->pctype_list, "pctypes",
17521                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17522         mapping.flow_type = res->flow_type;
17523         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17524                 mapping.pctype |= (1ULL << pctype_list[i]);
17525         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17526                                                 &mapping,
17527                                                 1,
17528                                                 0);
17529 #endif
17530
17531         switch (ret) {
17532         case 0:
17533                 break;
17534         case -EINVAL:
17535                 printf("invalid pctype or flow type\n");
17536                 break;
17537         case -ENODEV:
17538                 printf("invalid port_id %d\n", res->port_id);
17539                 break;
17540         case -ENOTSUP:
17541                 printf("function not implemented\n");
17542                 break;
17543         default:
17544                 printf("programming error: (%s)\n", strerror(-ret));
17545         }
17546 }
17547
17548 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17549         .f = cmd_pctype_mapping_update_parsed,
17550         .data = NULL,
17551         .help_str = "port config <port_id> pctype mapping update"
17552         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17553         .tokens = {
17554                 (void *)&cmd_pctype_mapping_update_port,
17555                 (void *)&cmd_pctype_mapping_update_config,
17556                 (void *)&cmd_pctype_mapping_update_port_id,
17557                 (void *)&cmd_pctype_mapping_update_pctype,
17558                 (void *)&cmd_pctype_mapping_update_mapping,
17559                 (void *)&cmd_pctype_mapping_update_update,
17560                 (void *)&cmd_pctype_mapping_update_pc_type,
17561                 (void *)&cmd_pctype_mapping_update_flow_type,
17562                 NULL,
17563         },
17564 };
17565
17566 /* ptype mapping get */
17567
17568 /* Common result structure for ptype mapping get */
17569 struct cmd_ptype_mapping_get_result {
17570         cmdline_fixed_string_t ptype;
17571         cmdline_fixed_string_t mapping;
17572         cmdline_fixed_string_t get;
17573         portid_t port_id;
17574         uint8_t valid_only;
17575 };
17576
17577 /* Common CLI fields for ptype mapping get */
17578 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17579         TOKEN_STRING_INITIALIZER
17580                 (struct cmd_ptype_mapping_get_result,
17581                  ptype, "ptype");
17582 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17583         TOKEN_STRING_INITIALIZER
17584                 (struct cmd_ptype_mapping_get_result,
17585                  mapping, "mapping");
17586 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17587         TOKEN_STRING_INITIALIZER
17588                 (struct cmd_ptype_mapping_get_result,
17589                  get, "get");
17590 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17591         TOKEN_NUM_INITIALIZER
17592                 (struct cmd_ptype_mapping_get_result,
17593                  port_id, UINT16);
17594 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17595         TOKEN_NUM_INITIALIZER
17596                 (struct cmd_ptype_mapping_get_result,
17597                  valid_only, UINT8);
17598
17599 static void
17600 cmd_ptype_mapping_get_parsed(
17601         void *parsed_result,
17602         __attribute__((unused)) struct cmdline *cl,
17603         __attribute__((unused)) void *data)
17604 {
17605         struct cmd_ptype_mapping_get_result *res = parsed_result;
17606         int ret = -ENOTSUP;
17607 #ifdef RTE_LIBRTE_I40E_PMD
17608         int max_ptype_num = 256;
17609         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17610         uint16_t count;
17611         int i;
17612 #endif
17613
17614         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17615                 return;
17616
17617 #ifdef RTE_LIBRTE_I40E_PMD
17618         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17619                                         mapping,
17620                                         max_ptype_num,
17621                                         &count,
17622                                         res->valid_only);
17623 #endif
17624
17625         switch (ret) {
17626         case 0:
17627                 break;
17628         case -ENODEV:
17629                 printf("invalid port_id %d\n", res->port_id);
17630                 break;
17631         case -ENOTSUP:
17632                 printf("function not implemented\n");
17633                 break;
17634         default:
17635                 printf("programming error: (%s)\n", strerror(-ret));
17636         }
17637
17638 #ifdef RTE_LIBRTE_I40E_PMD
17639         if (!ret) {
17640                 for (i = 0; i < count; i++)
17641                         printf("%3d\t0x%08x\n",
17642                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17643         }
17644 #endif
17645 }
17646
17647 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17648         .f = cmd_ptype_mapping_get_parsed,
17649         .data = NULL,
17650         .help_str = "ptype mapping get <port_id> <valid_only>",
17651         .tokens = {
17652                 (void *)&cmd_ptype_mapping_get_ptype,
17653                 (void *)&cmd_ptype_mapping_get_mapping,
17654                 (void *)&cmd_ptype_mapping_get_get,
17655                 (void *)&cmd_ptype_mapping_get_port_id,
17656                 (void *)&cmd_ptype_mapping_get_valid_only,
17657                 NULL,
17658         },
17659 };
17660
17661 /* ptype mapping replace */
17662
17663 /* Common result structure for ptype mapping replace */
17664 struct cmd_ptype_mapping_replace_result {
17665         cmdline_fixed_string_t ptype;
17666         cmdline_fixed_string_t mapping;
17667         cmdline_fixed_string_t replace;
17668         portid_t port_id;
17669         uint32_t target;
17670         uint8_t mask;
17671         uint32_t pkt_type;
17672 };
17673
17674 /* Common CLI fields for ptype mapping replace */
17675 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17676         TOKEN_STRING_INITIALIZER
17677                 (struct cmd_ptype_mapping_replace_result,
17678                  ptype, "ptype");
17679 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17680         TOKEN_STRING_INITIALIZER
17681                 (struct cmd_ptype_mapping_replace_result,
17682                  mapping, "mapping");
17683 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17684         TOKEN_STRING_INITIALIZER
17685                 (struct cmd_ptype_mapping_replace_result,
17686                  replace, "replace");
17687 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17688         TOKEN_NUM_INITIALIZER
17689                 (struct cmd_ptype_mapping_replace_result,
17690                  port_id, UINT16);
17691 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17692         TOKEN_NUM_INITIALIZER
17693                 (struct cmd_ptype_mapping_replace_result,
17694                  target, UINT32);
17695 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17696         TOKEN_NUM_INITIALIZER
17697                 (struct cmd_ptype_mapping_replace_result,
17698                  mask, UINT8);
17699 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17700         TOKEN_NUM_INITIALIZER
17701                 (struct cmd_ptype_mapping_replace_result,
17702                  pkt_type, UINT32);
17703
17704 static void
17705 cmd_ptype_mapping_replace_parsed(
17706         void *parsed_result,
17707         __attribute__((unused)) struct cmdline *cl,
17708         __attribute__((unused)) void *data)
17709 {
17710         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17711         int ret = -ENOTSUP;
17712
17713         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17714                 return;
17715
17716 #ifdef RTE_LIBRTE_I40E_PMD
17717         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17718                                         res->target,
17719                                         res->mask,
17720                                         res->pkt_type);
17721 #endif
17722
17723         switch (ret) {
17724         case 0:
17725                 break;
17726         case -EINVAL:
17727                 printf("invalid ptype 0x%8x or 0x%8x\n",
17728                                 res->target, res->pkt_type);
17729                 break;
17730         case -ENODEV:
17731                 printf("invalid port_id %d\n", res->port_id);
17732                 break;
17733         case -ENOTSUP:
17734                 printf("function not implemented\n");
17735                 break;
17736         default:
17737                 printf("programming error: (%s)\n", strerror(-ret));
17738         }
17739 }
17740
17741 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17742         .f = cmd_ptype_mapping_replace_parsed,
17743         .data = NULL,
17744         .help_str =
17745                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17746         .tokens = {
17747                 (void *)&cmd_ptype_mapping_replace_ptype,
17748                 (void *)&cmd_ptype_mapping_replace_mapping,
17749                 (void *)&cmd_ptype_mapping_replace_replace,
17750                 (void *)&cmd_ptype_mapping_replace_port_id,
17751                 (void *)&cmd_ptype_mapping_replace_target,
17752                 (void *)&cmd_ptype_mapping_replace_mask,
17753                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17754                 NULL,
17755         },
17756 };
17757
17758 /* ptype mapping reset */
17759
17760 /* Common result structure for ptype mapping reset */
17761 struct cmd_ptype_mapping_reset_result {
17762         cmdline_fixed_string_t ptype;
17763         cmdline_fixed_string_t mapping;
17764         cmdline_fixed_string_t reset;
17765         portid_t port_id;
17766 };
17767
17768 /* Common CLI fields for ptype mapping reset*/
17769 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17770         TOKEN_STRING_INITIALIZER
17771                 (struct cmd_ptype_mapping_reset_result,
17772                  ptype, "ptype");
17773 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17774         TOKEN_STRING_INITIALIZER
17775                 (struct cmd_ptype_mapping_reset_result,
17776                  mapping, "mapping");
17777 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17778         TOKEN_STRING_INITIALIZER
17779                 (struct cmd_ptype_mapping_reset_result,
17780                  reset, "reset");
17781 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17782         TOKEN_NUM_INITIALIZER
17783                 (struct cmd_ptype_mapping_reset_result,
17784                  port_id, UINT16);
17785
17786 static void
17787 cmd_ptype_mapping_reset_parsed(
17788         void *parsed_result,
17789         __attribute__((unused)) struct cmdline *cl,
17790         __attribute__((unused)) void *data)
17791 {
17792         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17793         int ret = -ENOTSUP;
17794
17795         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17796                 return;
17797
17798 #ifdef RTE_LIBRTE_I40E_PMD
17799         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17800 #endif
17801
17802         switch (ret) {
17803         case 0:
17804                 break;
17805         case -ENODEV:
17806                 printf("invalid port_id %d\n", res->port_id);
17807                 break;
17808         case -ENOTSUP:
17809                 printf("function not implemented\n");
17810                 break;
17811         default:
17812                 printf("programming error: (%s)\n", strerror(-ret));
17813         }
17814 }
17815
17816 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17817         .f = cmd_ptype_mapping_reset_parsed,
17818         .data = NULL,
17819         .help_str = "ptype mapping reset <port_id>",
17820         .tokens = {
17821                 (void *)&cmd_ptype_mapping_reset_ptype,
17822                 (void *)&cmd_ptype_mapping_reset_mapping,
17823                 (void *)&cmd_ptype_mapping_reset_reset,
17824                 (void *)&cmd_ptype_mapping_reset_port_id,
17825                 NULL,
17826         },
17827 };
17828
17829 /* ptype mapping update */
17830
17831 /* Common result structure for ptype mapping update */
17832 struct cmd_ptype_mapping_update_result {
17833         cmdline_fixed_string_t ptype;
17834         cmdline_fixed_string_t mapping;
17835         cmdline_fixed_string_t reset;
17836         portid_t port_id;
17837         uint8_t hw_ptype;
17838         uint32_t sw_ptype;
17839 };
17840
17841 /* Common CLI fields for ptype mapping update*/
17842 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17843         TOKEN_STRING_INITIALIZER
17844                 (struct cmd_ptype_mapping_update_result,
17845                  ptype, "ptype");
17846 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17847         TOKEN_STRING_INITIALIZER
17848                 (struct cmd_ptype_mapping_update_result,
17849                  mapping, "mapping");
17850 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17851         TOKEN_STRING_INITIALIZER
17852                 (struct cmd_ptype_mapping_update_result,
17853                  reset, "update");
17854 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17855         TOKEN_NUM_INITIALIZER
17856                 (struct cmd_ptype_mapping_update_result,
17857                  port_id, UINT16);
17858 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17859         TOKEN_NUM_INITIALIZER
17860                 (struct cmd_ptype_mapping_update_result,
17861                  hw_ptype, UINT8);
17862 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17863         TOKEN_NUM_INITIALIZER
17864                 (struct cmd_ptype_mapping_update_result,
17865                  sw_ptype, UINT32);
17866
17867 static void
17868 cmd_ptype_mapping_update_parsed(
17869         void *parsed_result,
17870         __attribute__((unused)) struct cmdline *cl,
17871         __attribute__((unused)) void *data)
17872 {
17873         struct cmd_ptype_mapping_update_result *res = parsed_result;
17874         int ret = -ENOTSUP;
17875 #ifdef RTE_LIBRTE_I40E_PMD
17876         struct rte_pmd_i40e_ptype_mapping mapping;
17877 #endif
17878         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17879                 return;
17880
17881 #ifdef RTE_LIBRTE_I40E_PMD
17882         mapping.hw_ptype = res->hw_ptype;
17883         mapping.sw_ptype = res->sw_ptype;
17884         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17885                                                 &mapping,
17886                                                 1,
17887                                                 0);
17888 #endif
17889
17890         switch (ret) {
17891         case 0:
17892                 break;
17893         case -EINVAL:
17894                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17895                 break;
17896         case -ENODEV:
17897                 printf("invalid port_id %d\n", res->port_id);
17898                 break;
17899         case -ENOTSUP:
17900                 printf("function not implemented\n");
17901                 break;
17902         default:
17903                 printf("programming error: (%s)\n", strerror(-ret));
17904         }
17905 }
17906
17907 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17908         .f = cmd_ptype_mapping_update_parsed,
17909         .data = NULL,
17910         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17911         .tokens = {
17912                 (void *)&cmd_ptype_mapping_update_ptype,
17913                 (void *)&cmd_ptype_mapping_update_mapping,
17914                 (void *)&cmd_ptype_mapping_update_update,
17915                 (void *)&cmd_ptype_mapping_update_port_id,
17916                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17917                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17918                 NULL,
17919         },
17920 };
17921
17922 /* Common result structure for file commands */
17923 struct cmd_cmdfile_result {
17924         cmdline_fixed_string_t load;
17925         cmdline_fixed_string_t filename;
17926 };
17927
17928 /* Common CLI fields for file commands */
17929 cmdline_parse_token_string_t cmd_load_cmdfile =
17930         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17931 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17932         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17933
17934 static void
17935 cmd_load_from_file_parsed(
17936         void *parsed_result,
17937         __attribute__((unused)) struct cmdline *cl,
17938         __attribute__((unused)) void *data)
17939 {
17940         struct cmd_cmdfile_result *res = parsed_result;
17941
17942         cmdline_read_from_file(res->filename);
17943 }
17944
17945 cmdline_parse_inst_t cmd_load_from_file = {
17946         .f = cmd_load_from_file_parsed,
17947         .data = NULL,
17948         .help_str = "load <filename>",
17949         .tokens = {
17950                 (void *)&cmd_load_cmdfile,
17951                 (void *)&cmd_load_cmdfile_filename,
17952                 NULL,
17953         },
17954 };
17955
17956 /* Get Rx offloads capabilities */
17957 struct cmd_rx_offload_get_capa_result {
17958         cmdline_fixed_string_t show;
17959         cmdline_fixed_string_t port;
17960         portid_t port_id;
17961         cmdline_fixed_string_t rx_offload;
17962         cmdline_fixed_string_t capabilities;
17963 };
17964
17965 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17966         TOKEN_STRING_INITIALIZER
17967                 (struct cmd_rx_offload_get_capa_result,
17968                  show, "show");
17969 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17970         TOKEN_STRING_INITIALIZER
17971                 (struct cmd_rx_offload_get_capa_result,
17972                  port, "port");
17973 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17974         TOKEN_NUM_INITIALIZER
17975                 (struct cmd_rx_offload_get_capa_result,
17976                  port_id, UINT16);
17977 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17978         TOKEN_STRING_INITIALIZER
17979                 (struct cmd_rx_offload_get_capa_result,
17980                  rx_offload, "rx_offload");
17981 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17982         TOKEN_STRING_INITIALIZER
17983                 (struct cmd_rx_offload_get_capa_result,
17984                  capabilities, "capabilities");
17985
17986 static void
17987 print_rx_offloads(uint64_t offloads)
17988 {
17989         uint64_t single_offload;
17990         int begin;
17991         int end;
17992         int bit;
17993
17994         if (offloads == 0)
17995                 return;
17996
17997         begin = __builtin_ctzll(offloads);
17998         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17999
18000         single_offload = 1ULL << begin;
18001         for (bit = begin; bit < end; bit++) {
18002                 if (offloads & single_offload)
18003                         printf(" %s",
18004                                rte_eth_dev_rx_offload_name(single_offload));
18005                 single_offload <<= 1;
18006         }
18007 }
18008
18009 static void
18010 cmd_rx_offload_get_capa_parsed(
18011         void *parsed_result,
18012         __attribute__((unused)) struct cmdline *cl,
18013         __attribute__((unused)) void *data)
18014 {
18015         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18016         struct rte_eth_dev_info dev_info;
18017         portid_t port_id = res->port_id;
18018         uint64_t queue_offloads;
18019         uint64_t port_offloads;
18020         int ret;
18021
18022         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18023         if (ret != 0)
18024                 return;
18025
18026         queue_offloads = dev_info.rx_queue_offload_capa;
18027         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18028
18029         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18030         printf("  Per Queue :");
18031         print_rx_offloads(queue_offloads);
18032
18033         printf("\n");
18034         printf("  Per Port  :");
18035         print_rx_offloads(port_offloads);
18036         printf("\n\n");
18037 }
18038
18039 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18040         .f = cmd_rx_offload_get_capa_parsed,
18041         .data = NULL,
18042         .help_str = "show port <port_id> rx_offload capabilities",
18043         .tokens = {
18044                 (void *)&cmd_rx_offload_get_capa_show,
18045                 (void *)&cmd_rx_offload_get_capa_port,
18046                 (void *)&cmd_rx_offload_get_capa_port_id,
18047                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18048                 (void *)&cmd_rx_offload_get_capa_capabilities,
18049                 NULL,
18050         }
18051 };
18052
18053 /* Get Rx offloads configuration */
18054 struct cmd_rx_offload_get_configuration_result {
18055         cmdline_fixed_string_t show;
18056         cmdline_fixed_string_t port;
18057         portid_t port_id;
18058         cmdline_fixed_string_t rx_offload;
18059         cmdline_fixed_string_t configuration;
18060 };
18061
18062 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18063         TOKEN_STRING_INITIALIZER
18064                 (struct cmd_rx_offload_get_configuration_result,
18065                  show, "show");
18066 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18067         TOKEN_STRING_INITIALIZER
18068                 (struct cmd_rx_offload_get_configuration_result,
18069                  port, "port");
18070 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18071         TOKEN_NUM_INITIALIZER
18072                 (struct cmd_rx_offload_get_configuration_result,
18073                  port_id, UINT16);
18074 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18075         TOKEN_STRING_INITIALIZER
18076                 (struct cmd_rx_offload_get_configuration_result,
18077                  rx_offload, "rx_offload");
18078 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18079         TOKEN_STRING_INITIALIZER
18080                 (struct cmd_rx_offload_get_configuration_result,
18081                  configuration, "configuration");
18082
18083 static void
18084 cmd_rx_offload_get_configuration_parsed(
18085         void *parsed_result,
18086         __attribute__((unused)) struct cmdline *cl,
18087         __attribute__((unused)) void *data)
18088 {
18089         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18090         struct rte_eth_dev_info dev_info;
18091         portid_t port_id = res->port_id;
18092         struct rte_port *port = &ports[port_id];
18093         uint64_t port_offloads;
18094         uint64_t queue_offloads;
18095         uint16_t nb_rx_queues;
18096         int q;
18097         int ret;
18098
18099         printf("Rx Offloading Configuration of port %d :\n", port_id);
18100
18101         port_offloads = port->dev_conf.rxmode.offloads;
18102         printf("  Port :");
18103         print_rx_offloads(port_offloads);
18104         printf("\n");
18105
18106         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18107         if (ret != 0)
18108                 return;
18109
18110         nb_rx_queues = dev_info.nb_rx_queues;
18111         for (q = 0; q < nb_rx_queues; q++) {
18112                 queue_offloads = port->rx_conf[q].offloads;
18113                 printf("  Queue[%2d] :", q);
18114                 print_rx_offloads(queue_offloads);
18115                 printf("\n");
18116         }
18117         printf("\n");
18118 }
18119
18120 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18121         .f = cmd_rx_offload_get_configuration_parsed,
18122         .data = NULL,
18123         .help_str = "show port <port_id> rx_offload configuration",
18124         .tokens = {
18125                 (void *)&cmd_rx_offload_get_configuration_show,
18126                 (void *)&cmd_rx_offload_get_configuration_port,
18127                 (void *)&cmd_rx_offload_get_configuration_port_id,
18128                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18129                 (void *)&cmd_rx_offload_get_configuration_configuration,
18130                 NULL,
18131         }
18132 };
18133
18134 /* Enable/Disable a per port offloading */
18135 struct cmd_config_per_port_rx_offload_result {
18136         cmdline_fixed_string_t port;
18137         cmdline_fixed_string_t config;
18138         portid_t port_id;
18139         cmdline_fixed_string_t rx_offload;
18140         cmdline_fixed_string_t offload;
18141         cmdline_fixed_string_t on_off;
18142 };
18143
18144 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18145         TOKEN_STRING_INITIALIZER
18146                 (struct cmd_config_per_port_rx_offload_result,
18147                  port, "port");
18148 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18149         TOKEN_STRING_INITIALIZER
18150                 (struct cmd_config_per_port_rx_offload_result,
18151                  config, "config");
18152 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18153         TOKEN_NUM_INITIALIZER
18154                 (struct cmd_config_per_port_rx_offload_result,
18155                  port_id, UINT16);
18156 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18157         TOKEN_STRING_INITIALIZER
18158                 (struct cmd_config_per_port_rx_offload_result,
18159                  rx_offload, "rx_offload");
18160 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18161         TOKEN_STRING_INITIALIZER
18162                 (struct cmd_config_per_port_rx_offload_result,
18163                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18164                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18165                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18166                            "scatter#timestamp#security#keep_crc#rss_hash");
18167 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18168         TOKEN_STRING_INITIALIZER
18169                 (struct cmd_config_per_port_rx_offload_result,
18170                  on_off, "on#off");
18171
18172 static uint64_t
18173 search_rx_offload(const char *name)
18174 {
18175         uint64_t single_offload;
18176         const char *single_name;
18177         int found = 0;
18178         unsigned int bit;
18179
18180         single_offload = 1;
18181         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18182                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18183                 if (!strcasecmp(single_name, name)) {
18184                         found = 1;
18185                         break;
18186                 }
18187                 single_offload <<= 1;
18188         }
18189
18190         if (found)
18191                 return single_offload;
18192
18193         return 0;
18194 }
18195
18196 static void
18197 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18198                                 __attribute__((unused)) struct cmdline *cl,
18199                                 __attribute__((unused)) void *data)
18200 {
18201         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18202         portid_t port_id = res->port_id;
18203         struct rte_eth_dev_info dev_info;
18204         struct rte_port *port = &ports[port_id];
18205         uint64_t single_offload;
18206         uint16_t nb_rx_queues;
18207         int q;
18208         int ret;
18209
18210         if (port->port_status != RTE_PORT_STOPPED) {
18211                 printf("Error: Can't config offload when Port %d "
18212                        "is not stopped\n", port_id);
18213                 return;
18214         }
18215
18216         single_offload = search_rx_offload(res->offload);
18217         if (single_offload == 0) {
18218                 printf("Unknown offload name: %s\n", res->offload);
18219                 return;
18220         }
18221
18222         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18223         if (ret != 0)
18224                 return;
18225
18226         nb_rx_queues = dev_info.nb_rx_queues;
18227         if (!strcmp(res->on_off, "on")) {
18228                 port->dev_conf.rxmode.offloads |= single_offload;
18229                 for (q = 0; q < nb_rx_queues; q++)
18230                         port->rx_conf[q].offloads |= single_offload;
18231         } else {
18232                 port->dev_conf.rxmode.offloads &= ~single_offload;
18233                 for (q = 0; q < nb_rx_queues; q++)
18234                         port->rx_conf[q].offloads &= ~single_offload;
18235         }
18236
18237         cmd_reconfig_device_queue(port_id, 1, 1);
18238 }
18239
18240 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18241         .f = cmd_config_per_port_rx_offload_parsed,
18242         .data = NULL,
18243         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18244                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18245                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18246                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18247                     "on|off",
18248         .tokens = {
18249                 (void *)&cmd_config_per_port_rx_offload_result_port,
18250                 (void *)&cmd_config_per_port_rx_offload_result_config,
18251                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18252                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18253                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18254                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18255                 NULL,
18256         }
18257 };
18258
18259 /* Enable/Disable a per queue offloading */
18260 struct cmd_config_per_queue_rx_offload_result {
18261         cmdline_fixed_string_t port;
18262         portid_t port_id;
18263         cmdline_fixed_string_t rxq;
18264         uint16_t queue_id;
18265         cmdline_fixed_string_t rx_offload;
18266         cmdline_fixed_string_t offload;
18267         cmdline_fixed_string_t on_off;
18268 };
18269
18270 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18271         TOKEN_STRING_INITIALIZER
18272                 (struct cmd_config_per_queue_rx_offload_result,
18273                  port, "port");
18274 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18275         TOKEN_NUM_INITIALIZER
18276                 (struct cmd_config_per_queue_rx_offload_result,
18277                  port_id, UINT16);
18278 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18279         TOKEN_STRING_INITIALIZER
18280                 (struct cmd_config_per_queue_rx_offload_result,
18281                  rxq, "rxq");
18282 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18283         TOKEN_NUM_INITIALIZER
18284                 (struct cmd_config_per_queue_rx_offload_result,
18285                  queue_id, UINT16);
18286 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18287         TOKEN_STRING_INITIALIZER
18288                 (struct cmd_config_per_queue_rx_offload_result,
18289                  rx_offload, "rx_offload");
18290 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18291         TOKEN_STRING_INITIALIZER
18292                 (struct cmd_config_per_queue_rx_offload_result,
18293                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18294                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18295                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18296                            "scatter#timestamp#security#keep_crc");
18297 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18298         TOKEN_STRING_INITIALIZER
18299                 (struct cmd_config_per_queue_rx_offload_result,
18300                  on_off, "on#off");
18301
18302 static void
18303 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18304                                 __attribute__((unused)) struct cmdline *cl,
18305                                 __attribute__((unused)) void *data)
18306 {
18307         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18308         struct rte_eth_dev_info dev_info;
18309         portid_t port_id = res->port_id;
18310         uint16_t queue_id = res->queue_id;
18311         struct rte_port *port = &ports[port_id];
18312         uint64_t single_offload;
18313         int ret;
18314
18315         if (port->port_status != RTE_PORT_STOPPED) {
18316                 printf("Error: Can't config offload when Port %d "
18317                        "is not stopped\n", port_id);
18318                 return;
18319         }
18320
18321         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18322         if (ret != 0)
18323                 return;
18324
18325         if (queue_id >= dev_info.nb_rx_queues) {
18326                 printf("Error: input queue_id should be 0 ... "
18327                        "%d\n", dev_info.nb_rx_queues - 1);
18328                 return;
18329         }
18330
18331         single_offload = search_rx_offload(res->offload);
18332         if (single_offload == 0) {
18333                 printf("Unknown offload name: %s\n", res->offload);
18334                 return;
18335         }
18336
18337         if (!strcmp(res->on_off, "on"))
18338                 port->rx_conf[queue_id].offloads |= single_offload;
18339         else
18340                 port->rx_conf[queue_id].offloads &= ~single_offload;
18341
18342         cmd_reconfig_device_queue(port_id, 1, 1);
18343 }
18344
18345 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18346         .f = cmd_config_per_queue_rx_offload_parsed,
18347         .data = NULL,
18348         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18349                     "vlan_strip|ipv4_cksum|"
18350                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18351                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18352                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18353                     "on|off",
18354         .tokens = {
18355                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18356                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18357                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18358                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18359                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18360                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18361                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18362                 NULL,
18363         }
18364 };
18365
18366 /* Get Tx offloads capabilities */
18367 struct cmd_tx_offload_get_capa_result {
18368         cmdline_fixed_string_t show;
18369         cmdline_fixed_string_t port;
18370         portid_t port_id;
18371         cmdline_fixed_string_t tx_offload;
18372         cmdline_fixed_string_t capabilities;
18373 };
18374
18375 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18376         TOKEN_STRING_INITIALIZER
18377                 (struct cmd_tx_offload_get_capa_result,
18378                  show, "show");
18379 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18380         TOKEN_STRING_INITIALIZER
18381                 (struct cmd_tx_offload_get_capa_result,
18382                  port, "port");
18383 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18384         TOKEN_NUM_INITIALIZER
18385                 (struct cmd_tx_offload_get_capa_result,
18386                  port_id, UINT16);
18387 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18388         TOKEN_STRING_INITIALIZER
18389                 (struct cmd_tx_offload_get_capa_result,
18390                  tx_offload, "tx_offload");
18391 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18392         TOKEN_STRING_INITIALIZER
18393                 (struct cmd_tx_offload_get_capa_result,
18394                  capabilities, "capabilities");
18395
18396 static void
18397 print_tx_offloads(uint64_t offloads)
18398 {
18399         uint64_t single_offload;
18400         int begin;
18401         int end;
18402         int bit;
18403
18404         if (offloads == 0)
18405                 return;
18406
18407         begin = __builtin_ctzll(offloads);
18408         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18409
18410         single_offload = 1ULL << begin;
18411         for (bit = begin; bit < end; bit++) {
18412                 if (offloads & single_offload)
18413                         printf(" %s",
18414                                rte_eth_dev_tx_offload_name(single_offload));
18415                 single_offload <<= 1;
18416         }
18417 }
18418
18419 static void
18420 cmd_tx_offload_get_capa_parsed(
18421         void *parsed_result,
18422         __attribute__((unused)) struct cmdline *cl,
18423         __attribute__((unused)) void *data)
18424 {
18425         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18426         struct rte_eth_dev_info dev_info;
18427         portid_t port_id = res->port_id;
18428         uint64_t queue_offloads;
18429         uint64_t port_offloads;
18430         int ret;
18431
18432         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18433         if (ret != 0)
18434                 return;
18435
18436         queue_offloads = dev_info.tx_queue_offload_capa;
18437         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18438
18439         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18440         printf("  Per Queue :");
18441         print_tx_offloads(queue_offloads);
18442
18443         printf("\n");
18444         printf("  Per Port  :");
18445         print_tx_offloads(port_offloads);
18446         printf("\n\n");
18447 }
18448
18449 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18450         .f = cmd_tx_offload_get_capa_parsed,
18451         .data = NULL,
18452         .help_str = "show port <port_id> tx_offload capabilities",
18453         .tokens = {
18454                 (void *)&cmd_tx_offload_get_capa_show,
18455                 (void *)&cmd_tx_offload_get_capa_port,
18456                 (void *)&cmd_tx_offload_get_capa_port_id,
18457                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18458                 (void *)&cmd_tx_offload_get_capa_capabilities,
18459                 NULL,
18460         }
18461 };
18462
18463 /* Get Tx offloads configuration */
18464 struct cmd_tx_offload_get_configuration_result {
18465         cmdline_fixed_string_t show;
18466         cmdline_fixed_string_t port;
18467         portid_t port_id;
18468         cmdline_fixed_string_t tx_offload;
18469         cmdline_fixed_string_t configuration;
18470 };
18471
18472 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18473         TOKEN_STRING_INITIALIZER
18474                 (struct cmd_tx_offload_get_configuration_result,
18475                  show, "show");
18476 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18477         TOKEN_STRING_INITIALIZER
18478                 (struct cmd_tx_offload_get_configuration_result,
18479                  port, "port");
18480 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18481         TOKEN_NUM_INITIALIZER
18482                 (struct cmd_tx_offload_get_configuration_result,
18483                  port_id, UINT16);
18484 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18485         TOKEN_STRING_INITIALIZER
18486                 (struct cmd_tx_offload_get_configuration_result,
18487                  tx_offload, "tx_offload");
18488 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18489         TOKEN_STRING_INITIALIZER
18490                 (struct cmd_tx_offload_get_configuration_result,
18491                  configuration, "configuration");
18492
18493 static void
18494 cmd_tx_offload_get_configuration_parsed(
18495         void *parsed_result,
18496         __attribute__((unused)) struct cmdline *cl,
18497         __attribute__((unused)) void *data)
18498 {
18499         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18500         struct rte_eth_dev_info dev_info;
18501         portid_t port_id = res->port_id;
18502         struct rte_port *port = &ports[port_id];
18503         uint64_t port_offloads;
18504         uint64_t queue_offloads;
18505         uint16_t nb_tx_queues;
18506         int q;
18507         int ret;
18508
18509         printf("Tx Offloading Configuration of port %d :\n", port_id);
18510
18511         port_offloads = port->dev_conf.txmode.offloads;
18512         printf("  Port :");
18513         print_tx_offloads(port_offloads);
18514         printf("\n");
18515
18516         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18517         if (ret != 0)
18518                 return;
18519
18520         nb_tx_queues = dev_info.nb_tx_queues;
18521         for (q = 0; q < nb_tx_queues; q++) {
18522                 queue_offloads = port->tx_conf[q].offloads;
18523                 printf("  Queue[%2d] :", q);
18524                 print_tx_offloads(queue_offloads);
18525                 printf("\n");
18526         }
18527         printf("\n");
18528 }
18529
18530 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18531         .f = cmd_tx_offload_get_configuration_parsed,
18532         .data = NULL,
18533         .help_str = "show port <port_id> tx_offload configuration",
18534         .tokens = {
18535                 (void *)&cmd_tx_offload_get_configuration_show,
18536                 (void *)&cmd_tx_offload_get_configuration_port,
18537                 (void *)&cmd_tx_offload_get_configuration_port_id,
18538                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18539                 (void *)&cmd_tx_offload_get_configuration_configuration,
18540                 NULL,
18541         }
18542 };
18543
18544 /* Enable/Disable a per port offloading */
18545 struct cmd_config_per_port_tx_offload_result {
18546         cmdline_fixed_string_t port;
18547         cmdline_fixed_string_t config;
18548         portid_t port_id;
18549         cmdline_fixed_string_t tx_offload;
18550         cmdline_fixed_string_t offload;
18551         cmdline_fixed_string_t on_off;
18552 };
18553
18554 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18555         TOKEN_STRING_INITIALIZER
18556                 (struct cmd_config_per_port_tx_offload_result,
18557                  port, "port");
18558 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18559         TOKEN_STRING_INITIALIZER
18560                 (struct cmd_config_per_port_tx_offload_result,
18561                  config, "config");
18562 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18563         TOKEN_NUM_INITIALIZER
18564                 (struct cmd_config_per_port_tx_offload_result,
18565                  port_id, UINT16);
18566 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18567         TOKEN_STRING_INITIALIZER
18568                 (struct cmd_config_per_port_tx_offload_result,
18569                  tx_offload, "tx_offload");
18570 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18571         TOKEN_STRING_INITIALIZER
18572                 (struct cmd_config_per_port_tx_offload_result,
18573                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18574                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18575                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18576                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18577                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18578 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18579         TOKEN_STRING_INITIALIZER
18580                 (struct cmd_config_per_port_tx_offload_result,
18581                  on_off, "on#off");
18582
18583 static uint64_t
18584 search_tx_offload(const char *name)
18585 {
18586         uint64_t single_offload;
18587         const char *single_name;
18588         int found = 0;
18589         unsigned int bit;
18590
18591         single_offload = 1;
18592         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18593                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18594                 if (single_name == NULL)
18595                         break;
18596                 if (!strcasecmp(single_name, name)) {
18597                         found = 1;
18598                         break;
18599                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18600                         break;
18601                 single_offload <<= 1;
18602         }
18603
18604         if (found)
18605                 return single_offload;
18606
18607         return 0;
18608 }
18609
18610 static void
18611 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18612                                 __attribute__((unused)) struct cmdline *cl,
18613                                 __attribute__((unused)) void *data)
18614 {
18615         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18616         portid_t port_id = res->port_id;
18617         struct rte_eth_dev_info dev_info;
18618         struct rte_port *port = &ports[port_id];
18619         uint64_t single_offload;
18620         uint16_t nb_tx_queues;
18621         int q;
18622         int ret;
18623
18624         if (port->port_status != RTE_PORT_STOPPED) {
18625                 printf("Error: Can't config offload when Port %d "
18626                        "is not stopped\n", port_id);
18627                 return;
18628         }
18629
18630         single_offload = search_tx_offload(res->offload);
18631         if (single_offload == 0) {
18632                 printf("Unknown offload name: %s\n", res->offload);
18633                 return;
18634         }
18635
18636         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18637         if (ret != 0)
18638                 return;
18639
18640         nb_tx_queues = dev_info.nb_tx_queues;
18641         if (!strcmp(res->on_off, "on")) {
18642                 port->dev_conf.txmode.offloads |= single_offload;
18643                 for (q = 0; q < nb_tx_queues; q++)
18644                         port->tx_conf[q].offloads |= single_offload;
18645         } else {
18646                 port->dev_conf.txmode.offloads &= ~single_offload;
18647                 for (q = 0; q < nb_tx_queues; q++)
18648                         port->tx_conf[q].offloads &= ~single_offload;
18649         }
18650
18651         cmd_reconfig_device_queue(port_id, 1, 1);
18652 }
18653
18654 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18655         .f = cmd_config_per_port_tx_offload_parsed,
18656         .data = NULL,
18657         .help_str = "port config <port_id> tx_offload "
18658                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18659                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18660                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18661                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18662                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18663         .tokens = {
18664                 (void *)&cmd_config_per_port_tx_offload_result_port,
18665                 (void *)&cmd_config_per_port_tx_offload_result_config,
18666                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18667                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18668                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18669                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18670                 NULL,
18671         }
18672 };
18673
18674 /* Enable/Disable a per queue offloading */
18675 struct cmd_config_per_queue_tx_offload_result {
18676         cmdline_fixed_string_t port;
18677         portid_t port_id;
18678         cmdline_fixed_string_t txq;
18679         uint16_t queue_id;
18680         cmdline_fixed_string_t tx_offload;
18681         cmdline_fixed_string_t offload;
18682         cmdline_fixed_string_t on_off;
18683 };
18684
18685 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18686         TOKEN_STRING_INITIALIZER
18687                 (struct cmd_config_per_queue_tx_offload_result,
18688                  port, "port");
18689 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18690         TOKEN_NUM_INITIALIZER
18691                 (struct cmd_config_per_queue_tx_offload_result,
18692                  port_id, UINT16);
18693 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18694         TOKEN_STRING_INITIALIZER
18695                 (struct cmd_config_per_queue_tx_offload_result,
18696                  txq, "txq");
18697 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18698         TOKEN_NUM_INITIALIZER
18699                 (struct cmd_config_per_queue_tx_offload_result,
18700                  queue_id, UINT16);
18701 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18702         TOKEN_STRING_INITIALIZER
18703                 (struct cmd_config_per_queue_tx_offload_result,
18704                  tx_offload, "tx_offload");
18705 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18706         TOKEN_STRING_INITIALIZER
18707                 (struct cmd_config_per_queue_tx_offload_result,
18708                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18709                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18710                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18711                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18712                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18713 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18714         TOKEN_STRING_INITIALIZER
18715                 (struct cmd_config_per_queue_tx_offload_result,
18716                  on_off, "on#off");
18717
18718 static void
18719 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18720                                 __attribute__((unused)) struct cmdline *cl,
18721                                 __attribute__((unused)) void *data)
18722 {
18723         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18724         struct rte_eth_dev_info dev_info;
18725         portid_t port_id = res->port_id;
18726         uint16_t queue_id = res->queue_id;
18727         struct rte_port *port = &ports[port_id];
18728         uint64_t single_offload;
18729         int ret;
18730
18731         if (port->port_status != RTE_PORT_STOPPED) {
18732                 printf("Error: Can't config offload when Port %d "
18733                        "is not stopped\n", port_id);
18734                 return;
18735         }
18736
18737         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18738         if (ret != 0)
18739                 return;
18740
18741         if (queue_id >= dev_info.nb_tx_queues) {
18742                 printf("Error: input queue_id should be 0 ... "
18743                        "%d\n", dev_info.nb_tx_queues - 1);
18744                 return;
18745         }
18746
18747         single_offload = search_tx_offload(res->offload);
18748         if (single_offload == 0) {
18749                 printf("Unknown offload name: %s\n", res->offload);
18750                 return;
18751         }
18752
18753         if (!strcmp(res->on_off, "on"))
18754                 port->tx_conf[queue_id].offloads |= single_offload;
18755         else
18756                 port->tx_conf[queue_id].offloads &= ~single_offload;
18757
18758         cmd_reconfig_device_queue(port_id, 1, 1);
18759 }
18760
18761 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18762         .f = cmd_config_per_queue_tx_offload_parsed,
18763         .data = NULL,
18764         .help_str = "port <port_id> txq <queue_id> tx_offload "
18765                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18766                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18767                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18768                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18769                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18770                     "on|off",
18771         .tokens = {
18772                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18773                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18774                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18775                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18776                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18777                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18778                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18779                 NULL,
18780         }
18781 };
18782
18783 /* *** configure tx_metadata for specific port *** */
18784 struct cmd_config_tx_metadata_specific_result {
18785         cmdline_fixed_string_t port;
18786         cmdline_fixed_string_t keyword;
18787         uint16_t port_id;
18788         cmdline_fixed_string_t item;
18789         uint32_t value;
18790 };
18791
18792 static void
18793 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18794                                 __attribute__((unused)) struct cmdline *cl,
18795                                 __attribute__((unused)) void *data)
18796 {
18797         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18798
18799         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18800                 return;
18801         ports[res->port_id].tx_metadata = res->value;
18802         /* Add/remove callback to insert valid metadata in every Tx packet. */
18803         if (ports[res->port_id].tx_metadata)
18804                 add_tx_md_callback(res->port_id);
18805         else
18806                 remove_tx_md_callback(res->port_id);
18807         rte_flow_dynf_metadata_register();
18808 }
18809
18810 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18811         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18812                         port, "port");
18813 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18814         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18815                         keyword, "config");
18816 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18817         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18818                         port_id, UINT16);
18819 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18820         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18821                         item, "tx_metadata");
18822 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18823         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18824                         value, UINT32);
18825
18826 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18827         .f = cmd_config_tx_metadata_specific_parsed,
18828         .data = NULL,
18829         .help_str = "port config <port_id> tx_metadata <value>",
18830         .tokens = {
18831                 (void *)&cmd_config_tx_metadata_specific_port,
18832                 (void *)&cmd_config_tx_metadata_specific_keyword,
18833                 (void *)&cmd_config_tx_metadata_specific_id,
18834                 (void *)&cmd_config_tx_metadata_specific_item,
18835                 (void *)&cmd_config_tx_metadata_specific_value,
18836                 NULL,
18837         },
18838 };
18839
18840 /* *** display tx_metadata per port configuration *** */
18841 struct cmd_show_tx_metadata_result {
18842         cmdline_fixed_string_t cmd_show;
18843         cmdline_fixed_string_t cmd_port;
18844         cmdline_fixed_string_t cmd_keyword;
18845         portid_t cmd_pid;
18846 };
18847
18848 static void
18849 cmd_show_tx_metadata_parsed(void *parsed_result,
18850                 __attribute__((unused)) struct cmdline *cl,
18851                 __attribute__((unused)) void *data)
18852 {
18853         struct cmd_show_tx_metadata_result *res = parsed_result;
18854
18855         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18856                 printf("invalid port id %u\n", res->cmd_pid);
18857                 return;
18858         }
18859         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18860                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18861                        ports[res->cmd_pid].tx_metadata);
18862         }
18863 }
18864
18865 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18866         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18867                         cmd_show, "show");
18868 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18869         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18870                         cmd_port, "port");
18871 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18872         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18873                         cmd_pid, UINT16);
18874 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18875         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18876                         cmd_keyword, "tx_metadata");
18877
18878 cmdline_parse_inst_t cmd_show_tx_metadata = {
18879         .f = cmd_show_tx_metadata_parsed,
18880         .data = NULL,
18881         .help_str = "show port <port_id> tx_metadata",
18882         .tokens = {
18883                 (void *)&cmd_show_tx_metadata_show,
18884                 (void *)&cmd_show_tx_metadata_port,
18885                 (void *)&cmd_show_tx_metadata_pid,
18886                 (void *)&cmd_show_tx_metadata_keyword,
18887                 NULL,
18888         },
18889 };
18890
18891 /* show port supported ptypes */
18892
18893 /* Common result structure for show port ptypes */
18894 struct cmd_show_port_supported_ptypes_result {
18895         cmdline_fixed_string_t show;
18896         cmdline_fixed_string_t port;
18897         portid_t port_id;
18898         cmdline_fixed_string_t ptypes;
18899 };
18900
18901 /* Common CLI fields for show port ptypes */
18902 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
18903         TOKEN_STRING_INITIALIZER
18904                 (struct cmd_show_port_supported_ptypes_result,
18905                  show, "show");
18906 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
18907         TOKEN_STRING_INITIALIZER
18908                 (struct cmd_show_port_supported_ptypes_result,
18909                  port, "port");
18910 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
18911         TOKEN_NUM_INITIALIZER
18912                 (struct cmd_show_port_supported_ptypes_result,
18913                  port_id, UINT16);
18914 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
18915         TOKEN_STRING_INITIALIZER
18916                 (struct cmd_show_port_supported_ptypes_result,
18917                  ptypes, "ptypes");
18918
18919 static void
18920 cmd_show_port_supported_ptypes_parsed(
18921         void *parsed_result,
18922         __attribute__((unused)) struct cmdline *cl,
18923         __attribute__((unused)) void *data)
18924 {
18925 #define RSVD_PTYPE_MASK       0xf0000000
18926 #define MAX_PTYPES_PER_LAYER  16
18927 #define LTYPE_NAMESIZE        32
18928 #define PTYPE_NAMESIZE        256
18929         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
18930         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
18931         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
18932         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
18933         uint16_t port_id = res->port_id;
18934         int ret, i;
18935
18936         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
18937         if (ret < 0)
18938                 return;
18939
18940         while (ptype_mask != RSVD_PTYPE_MASK) {
18941
18942                 switch (ptype_mask) {
18943                 case RTE_PTYPE_L2_MASK:
18944                         strlcpy(ltype, "L2", sizeof(ltype));
18945                         break;
18946                 case RTE_PTYPE_L3_MASK:
18947                         strlcpy(ltype, "L3", sizeof(ltype));
18948                         break;
18949                 case RTE_PTYPE_L4_MASK:
18950                         strlcpy(ltype, "L4", sizeof(ltype));
18951                         break;
18952                 case RTE_PTYPE_TUNNEL_MASK:
18953                         strlcpy(ltype, "Tunnel", sizeof(ltype));
18954                         break;
18955                 case RTE_PTYPE_INNER_L2_MASK:
18956                         strlcpy(ltype, "Inner L2", sizeof(ltype));
18957                         break;
18958                 case RTE_PTYPE_INNER_L3_MASK:
18959                         strlcpy(ltype, "Inner L3", sizeof(ltype));
18960                         break;
18961                 case RTE_PTYPE_INNER_L4_MASK:
18962                         strlcpy(ltype, "Inner L4", sizeof(ltype));
18963                         break;
18964                 default:
18965                         return;
18966                 }
18967
18968                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
18969                                                        ptype_mask, ptypes,
18970                                                        MAX_PTYPES_PER_LAYER);
18971
18972                 if (ret > 0)
18973                         printf("Supported %s ptypes:\n", ltype);
18974                 else
18975                         printf("%s ptypes unsupported\n", ltype);
18976
18977                 for (i = 0; i < ret; ++i) {
18978                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
18979                         printf("%s\n", buf);
18980                 }
18981
18982                 ptype_mask <<= 4;
18983         }
18984 }
18985
18986 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
18987         .f = cmd_show_port_supported_ptypes_parsed,
18988         .data = NULL,
18989         .help_str = "show port <port_id> ptypes",
18990         .tokens = {
18991                 (void *)&cmd_show_port_supported_ptypes_show,
18992                 (void *)&cmd_show_port_supported_ptypes_port,
18993                 (void *)&cmd_show_port_supported_ptypes_port_id,
18994                 (void *)&cmd_show_port_supported_ptypes_ptypes,
18995                 NULL,
18996         },
18997 };
18998
18999 /* *** display rx/tx descriptor status *** */
19000 struct cmd_show_rx_tx_desc_status_result {
19001         cmdline_fixed_string_t cmd_show;
19002         cmdline_fixed_string_t cmd_port;
19003         cmdline_fixed_string_t cmd_keyword;
19004         cmdline_fixed_string_t cmd_desc;
19005         cmdline_fixed_string_t cmd_status;
19006         portid_t cmd_pid;
19007         portid_t cmd_qid;
19008         portid_t cmd_did;
19009 };
19010
19011 static void
19012 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19013                 __attribute__((unused)) struct cmdline *cl,
19014                 __attribute__((unused)) void *data)
19015 {
19016         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19017         int rc;
19018
19019         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19020                 printf("invalid port id %u\n", res->cmd_pid);
19021                 return;
19022         }
19023
19024         if (!strcmp(res->cmd_keyword, "rxq")) {
19025                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19026                                              res->cmd_did);
19027                 if (rc < 0) {
19028                         printf("Invalid queueid = %d\n", res->cmd_qid);
19029                         return;
19030                 }
19031                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19032                         printf("Desc status = AVAILABLE\n");
19033                 else if (rc == RTE_ETH_RX_DESC_DONE)
19034                         printf("Desc status = DONE\n");
19035                 else
19036                         printf("Desc status = UNAVAILABLE\n");
19037         } else if (!strcmp(res->cmd_keyword, "txq")) {
19038                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19039                                              res->cmd_did);
19040                 if (rc < 0) {
19041                         printf("Invalid queueid = %d\n", res->cmd_qid);
19042                         return;
19043                 }
19044                 if (rc == RTE_ETH_TX_DESC_FULL)
19045                         printf("Desc status = FULL\n");
19046                 else if (rc == RTE_ETH_TX_DESC_DONE)
19047                         printf("Desc status = DONE\n");
19048                 else
19049                         printf("Desc status = UNAVAILABLE\n");
19050         }
19051 }
19052
19053 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19054         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19055                         cmd_show, "show");
19056 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19057         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19058                         cmd_port, "port");
19059 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19060         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19061                         cmd_pid, UINT16);
19062 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19063         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19064                         cmd_keyword, "rxq#txq");
19065 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19066         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19067                         cmd_qid, UINT16);
19068 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19069         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19070                         cmd_desc, "desc");
19071 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19072         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19073                         cmd_did, UINT16);
19074 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19075         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19076                         cmd_status, "status");
19077 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19078         .f = cmd_show_rx_tx_desc_status_parsed,
19079         .data = NULL,
19080         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19081                 "status",
19082         .tokens = {
19083                 (void *)&cmd_show_rx_tx_desc_status_show,
19084                 (void *)&cmd_show_rx_tx_desc_status_port,
19085                 (void *)&cmd_show_rx_tx_desc_status_pid,
19086                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19087                 (void *)&cmd_show_rx_tx_desc_status_qid,
19088                 (void *)&cmd_show_rx_tx_desc_status_desc,
19089                 (void *)&cmd_show_rx_tx_desc_status_did,
19090                 (void *)&cmd_show_rx_tx_desc_status_status,
19091                 NULL,
19092         },
19093 };
19094
19095 /* Common result structure for set port ptypes */
19096 struct cmd_set_port_ptypes_result {
19097         cmdline_fixed_string_t set;
19098         cmdline_fixed_string_t port;
19099         portid_t port_id;
19100         cmdline_fixed_string_t ptype_mask;
19101         uint32_t mask;
19102 };
19103
19104 /* Common CLI fields for set port ptypes */
19105 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19106         TOKEN_STRING_INITIALIZER
19107                 (struct cmd_set_port_ptypes_result,
19108                  set, "set");
19109 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19110         TOKEN_STRING_INITIALIZER
19111                 (struct cmd_set_port_ptypes_result,
19112                  port, "port");
19113 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19114         TOKEN_NUM_INITIALIZER
19115                 (struct cmd_set_port_ptypes_result,
19116                  port_id, UINT16);
19117 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19118         TOKEN_STRING_INITIALIZER
19119                 (struct cmd_set_port_ptypes_result,
19120                  ptype_mask, "ptype_mask");
19121 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19122         TOKEN_NUM_INITIALIZER
19123                 (struct cmd_set_port_ptypes_result,
19124                  mask, UINT32);
19125
19126 static void
19127 cmd_set_port_ptypes_parsed(
19128         void *parsed_result,
19129         __attribute__((unused)) struct cmdline *cl,
19130         __attribute__((unused)) void *data)
19131 {
19132         struct cmd_set_port_ptypes_result *res = parsed_result;
19133 #define PTYPE_NAMESIZE        256
19134         char ptype_name[PTYPE_NAMESIZE];
19135         uint16_t port_id = res->port_id;
19136         uint32_t ptype_mask = res->mask;
19137         int ret, i;
19138
19139         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19140                                                NULL, 0);
19141         if (ret <= 0) {
19142                 printf("Port %d doesn't support any ptypes.\n", port_id);
19143                 return;
19144         }
19145
19146         uint32_t ptypes[ret];
19147
19148         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19149         if (ret < 0) {
19150                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19151                 return;
19152         }
19153
19154         printf("Successfully set following ptypes for Port %d\n", port_id);
19155         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19156                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19157                 printf("%s\n", ptype_name);
19158         }
19159
19160         clear_ptypes = false;
19161 }
19162
19163 cmdline_parse_inst_t cmd_set_port_ptypes = {
19164         .f = cmd_set_port_ptypes_parsed,
19165         .data = NULL,
19166         .help_str = "set port <port_id> ptype_mask <mask>",
19167         .tokens = {
19168                 (void *)&cmd_set_port_ptypes_set,
19169                 (void *)&cmd_set_port_ptypes_port,
19170                 (void *)&cmd_set_port_ptypes_port_id,
19171                 (void *)&cmd_set_port_ptypes_mask_str,
19172                 (void *)&cmd_set_port_ptypes_mask_u32,
19173                 NULL,
19174         },
19175 };
19176
19177 /* *** display mac addresses added to a port *** */
19178 struct cmd_showport_macs_result {
19179         cmdline_fixed_string_t cmd_show;
19180         cmdline_fixed_string_t cmd_port;
19181         cmdline_fixed_string_t cmd_keyword;
19182         portid_t cmd_pid;
19183 };
19184
19185 static void
19186 cmd_showport_macs_parsed(void *parsed_result,
19187                 __attribute__((unused)) struct cmdline *cl,
19188                 __attribute__((unused)) void *data)
19189 {
19190         struct cmd_showport_macs_result *res = parsed_result;
19191
19192         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19193                 return;
19194
19195         if (!strcmp(res->cmd_keyword, "macs"))
19196                 show_macs(res->cmd_pid);
19197         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19198                 show_mcast_macs(res->cmd_pid);
19199 }
19200
19201 cmdline_parse_token_string_t cmd_showport_macs_show =
19202         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19203                         cmd_show, "show");
19204 cmdline_parse_token_string_t cmd_showport_macs_port =
19205         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19206                         cmd_port, "port");
19207 cmdline_parse_token_num_t cmd_showport_macs_pid =
19208         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19209                         cmd_pid, UINT16);
19210 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19211         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19212                         cmd_keyword, "macs#mcast_macs");
19213
19214 cmdline_parse_inst_t cmd_showport_macs = {
19215         .f = cmd_showport_macs_parsed,
19216         .data = NULL,
19217         .help_str = "show port <port_id> macs|mcast_macs",
19218         .tokens = {
19219                 (void *)&cmd_showport_macs_show,
19220                 (void *)&cmd_showport_macs_port,
19221                 (void *)&cmd_showport_macs_pid,
19222                 (void *)&cmd_showport_macs_keyword,
19223                 NULL,
19224         },
19225 };
19226
19227 /* ******************************************************************************** */
19228
19229 /* list of instructions */
19230 cmdline_parse_ctx_t main_ctx[] = {
19231         (cmdline_parse_inst_t *)&cmd_help_brief,
19232         (cmdline_parse_inst_t *)&cmd_help_long,
19233         (cmdline_parse_inst_t *)&cmd_quit,
19234         (cmdline_parse_inst_t *)&cmd_load_from_file,
19235         (cmdline_parse_inst_t *)&cmd_showport,
19236         (cmdline_parse_inst_t *)&cmd_showqueue,
19237         (cmdline_parse_inst_t *)&cmd_showportall,
19238         (cmdline_parse_inst_t *)&cmd_showdevice,
19239         (cmdline_parse_inst_t *)&cmd_showcfg,
19240         (cmdline_parse_inst_t *)&cmd_showfwdall,
19241         (cmdline_parse_inst_t *)&cmd_start,
19242         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19243         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19244         (cmdline_parse_inst_t *)&cmd_set_link_up,
19245         (cmdline_parse_inst_t *)&cmd_set_link_down,
19246         (cmdline_parse_inst_t *)&cmd_reset,
19247         (cmdline_parse_inst_t *)&cmd_set_numbers,
19248         (cmdline_parse_inst_t *)&cmd_set_log,
19249         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19250         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19251         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19252         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19253         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19254         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19255         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19256         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19257         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19258         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19259         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19260         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19261         (cmdline_parse_inst_t *)&cmd_set_link_check,
19262         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19263         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19264         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19265         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19266 #ifdef RTE_LIBRTE_PMD_BOND
19267         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19268         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19269         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19270         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19271         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19272         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19273         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19274         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19275         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19276         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19277         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19278 #endif
19279         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19280         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19281         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19282         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19283         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19284         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19285         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19286         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19287         (cmdline_parse_inst_t *)&cmd_csum_set,
19288         (cmdline_parse_inst_t *)&cmd_csum_show,
19289         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19290         (cmdline_parse_inst_t *)&cmd_tso_set,
19291         (cmdline_parse_inst_t *)&cmd_tso_show,
19292         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19293         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19294         (cmdline_parse_inst_t *)&cmd_gro_enable,
19295         (cmdline_parse_inst_t *)&cmd_gro_flush,
19296         (cmdline_parse_inst_t *)&cmd_gro_show,
19297         (cmdline_parse_inst_t *)&cmd_gso_enable,
19298         (cmdline_parse_inst_t *)&cmd_gso_size,
19299         (cmdline_parse_inst_t *)&cmd_gso_show,
19300         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19301         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19302         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19303         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19304         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19305         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19306         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19307         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19308         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19309         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19310         (cmdline_parse_inst_t *)&cmd_config_dcb,
19311         (cmdline_parse_inst_t *)&cmd_read_reg,
19312         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19313         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19314         (cmdline_parse_inst_t *)&cmd_write_reg,
19315         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19316         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19317         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19318         (cmdline_parse_inst_t *)&cmd_stop,
19319         (cmdline_parse_inst_t *)&cmd_mac_addr,
19320         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19321         (cmdline_parse_inst_t *)&cmd_set_qmap,
19322         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19323         (cmdline_parse_inst_t *)&cmd_operate_port,
19324         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19325         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19326         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19327         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19328         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19329         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19330         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19331         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19332         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19333         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19334         (cmdline_parse_inst_t *)&cmd_config_mtu,
19335         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19336         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19337         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19338         (cmdline_parse_inst_t *)&cmd_config_rss,
19339         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19340         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19341         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19342         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19343         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19344         (cmdline_parse_inst_t *)&cmd_showport_reta,
19345         (cmdline_parse_inst_t *)&cmd_showport_macs,
19346         (cmdline_parse_inst_t *)&cmd_config_burst,
19347         (cmdline_parse_inst_t *)&cmd_config_thresh,
19348         (cmdline_parse_inst_t *)&cmd_config_threshold,
19349         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19350         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19351         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19352         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19353         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19354         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19355         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19356         (cmdline_parse_inst_t *)&cmd_global_config,
19357         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19358         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19359         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19360         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19361         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19362         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19363         (cmdline_parse_inst_t *)&cmd_dump,
19364         (cmdline_parse_inst_t *)&cmd_dump_one,
19365         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19366         (cmdline_parse_inst_t *)&cmd_syn_filter,
19367         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19368         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19369         (cmdline_parse_inst_t *)&cmd_flex_filter,
19370         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19371         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19372         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19373         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19374         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19375         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19376         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19377         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19378         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19379         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19380         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19381         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19382         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19383         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19384         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19385         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19386         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19387         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19388         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19389         (cmdline_parse_inst_t *)&cmd_flow,
19390         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19391         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19392         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19393         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19394         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19395         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19396         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19397         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19398         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19399         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19400         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19401         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19402         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19403         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19404         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19405         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19406         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19407         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19408         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19409         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19410         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19411         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19412         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19413         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19414         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19415         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19416         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19417         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19418         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19419         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19420         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19421         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19422         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19423         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19424         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19425         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19426         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19427         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19428         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19429         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19430         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19431         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19432         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19433         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19434         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19435         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19436         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19437         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19438         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19439 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19440         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19441 #endif
19442         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19443         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19444         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19445         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19446         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19447         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19448         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19449         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19450         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19451         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19452         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19453         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19454         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19455         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19456         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19457         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19458         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19459         (cmdline_parse_inst_t *)&cmd_ddp_add,
19460         (cmdline_parse_inst_t *)&cmd_ddp_del,
19461         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19462         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19463         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19464         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19465         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19466         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19467         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19468         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19469         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19470         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19471         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19472         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19473
19474         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19475         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19476         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19477         (cmdline_parse_inst_t *)&cmd_queue_region,
19478         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19479         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19480         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19481         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19482         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19483         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19484         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19485         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19486         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19487         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19488         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19489         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19490         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19491         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19492         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19493         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19494         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19495         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19496         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19497         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19498         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19499         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19500         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19501         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19502         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19503         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19504         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19505         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19506         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19507         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19508         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19509         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19510         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19511         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19512         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19513 #ifdef RTE_LIBRTE_BPF
19514         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19515         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19516 #endif
19517         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19518         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19519         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19520         (cmdline_parse_inst_t *)&cmd_set_raw,
19521         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19522         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19523         NULL,
19524 };
19525
19526 /* read cmdline commands from file */
19527 void
19528 cmdline_read_from_file(const char *filename)
19529 {
19530         struct cmdline *cl;
19531
19532         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19533         if (cl == NULL) {
19534                 printf("Failed to create file based cmdline context: %s\n",
19535                        filename);
19536                 return;
19537         }
19538
19539         cmdline_interact(cl);
19540         cmdline_quit(cl);
19541
19542         cmdline_free(cl);
19543
19544         printf("Read CLI commands from %s\n", filename);
19545 }
19546
19547 /* prompt function, called from main on MASTER lcore */
19548 void
19549 prompt(void)
19550 {
19551         /* initialize non-constant commands */
19552         cmd_set_fwd_mode_init();
19553         cmd_set_fwd_retry_mode_init();
19554
19555         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19556         if (testpmd_cl == NULL)
19557                 return;
19558         cmdline_interact(testpmd_cl);
19559         cmdline_stdin_exit(testpmd_cl);
19560 }
19561
19562 void
19563 prompt_exit(void)
19564 {
19565         if (testpmd_cl != NULL)
19566                 cmdline_quit(testpmd_cl);
19567 }
19568
19569 static void
19570 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19571 {
19572         if (id == (portid_t)RTE_PORT_ALL) {
19573                 portid_t pid;
19574
19575                 RTE_ETH_FOREACH_DEV(pid) {
19576                         /* check if need_reconfig has been set to 1 */
19577                         if (ports[pid].need_reconfig == 0)
19578                                 ports[pid].need_reconfig = dev;
19579                         /* check if need_reconfig_queues has been set to 1 */
19580                         if (ports[pid].need_reconfig_queues == 0)
19581                                 ports[pid].need_reconfig_queues = queue;
19582                 }
19583         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19584                 /* check if need_reconfig has been set to 1 */
19585                 if (ports[id].need_reconfig == 0)
19586                         ports[id].need_reconfig = dev;
19587                 /* check if need_reconfig_queues has been set to 1 */
19588                 if (ports[id].need_reconfig_queues == 0)
19589                         ports[id].need_reconfig_queues = queue;
19590         }
19591 }