2ab03c11131631f4d8c8f48b7192c99643ccc4a9
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #ifndef __linux__
15 #ifndef __FreeBSD__
16 #include <net/socket.h>
17 #else
18 #include <sys/socket.h>
19 #endif
20 #endif
21 #include <netinet/in.h>
22
23 #include <sys/queue.h>
24
25 #include <rte_common.h>
26 #include <rte_byteorder.h>
27 #include <rte_log.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memzone.h>
32 #include <rte_malloc.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_ring.h>
40 #include <rte_mempool.h>
41 #include <rte_interrupts.h>
42 #include <rte_pci.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
45 #include <rte_string_fns.h>
46 #include <rte_devargs.h>
47 #include <rte_eth_ctrl.h>
48 #include <rte_flow.h>
49 #include <rte_gro.h>
50
51 #include <cmdline_rdline.h>
52 #include <cmdline_parse.h>
53 #include <cmdline_parse_num.h>
54 #include <cmdline_parse_string.h>
55 #include <cmdline_parse_ipaddr.h>
56 #include <cmdline_parse_etheraddr.h>
57 #include <cmdline_socket.h>
58 #include <cmdline.h>
59 #ifdef RTE_LIBRTE_PMD_BOND
60 #include <rte_eth_bond.h>
61 #include <rte_eth_bond_8023ad.h>
62 #endif
63 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
64 #include <rte_pmd_dpaa.h>
65 #endif
66 #ifdef RTE_LIBRTE_IXGBE_PMD
67 #include <rte_pmd_ixgbe.h>
68 #endif
69 #ifdef RTE_LIBRTE_I40E_PMD
70 #include <rte_pmd_i40e.h>
71 #endif
72 #ifdef RTE_LIBRTE_BNXT_PMD
73 #include <rte_pmd_bnxt.h>
74 #endif
75 #include "testpmd.h"
76 #include "cmdline_mtr.h"
77 #include "cmdline_tm.h"
78 #include "bpf_cmd.h"
79
80 static struct cmdline *testpmd_cl;
81
82 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
83
84 /* *** Help command with introduction. *** */
85 struct cmd_help_brief_result {
86         cmdline_fixed_string_t help;
87 };
88
89 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
90                                   struct cmdline *cl,
91                                   __attribute__((unused)) void *data)
92 {
93         cmdline_printf(
94                 cl,
95                 "\n"
96                 "Help is available for the following sections:\n\n"
97                 "    help control    : Start and stop forwarding.\n"
98                 "    help display    : Displaying port, stats and config "
99                 "information.\n"
100                 "    help config     : Configuration information.\n"
101                 "    help ports      : Configuring ports.\n"
102                 "    help registers  : Reading and setting port registers.\n"
103                 "    help filters    : Filters configuration help.\n"
104                 "    help all        : All of the above sections.\n\n"
105         );
106
107 }
108
109 cmdline_parse_token_string_t cmd_help_brief_help =
110         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
111
112 cmdline_parse_inst_t cmd_help_brief = {
113         .f = cmd_help_brief_parsed,
114         .data = NULL,
115         .help_str = "help: Show help",
116         .tokens = {
117                 (void *)&cmd_help_brief_help,
118                 NULL,
119         },
120 };
121
122 /* *** Help command with help sections. *** */
123 struct cmd_help_long_result {
124         cmdline_fixed_string_t help;
125         cmdline_fixed_string_t section;
126 };
127
128 static void cmd_help_long_parsed(void *parsed_result,
129                                  struct cmdline *cl,
130                                  __attribute__((unused)) void *data)
131 {
132         int show_all = 0;
133         struct cmd_help_long_result *res = parsed_result;
134
135         if (!strcmp(res->section, "all"))
136                 show_all = 1;
137
138         if (show_all || !strcmp(res->section, "control")) {
139
140                 cmdline_printf(
141                         cl,
142                         "\n"
143                         "Control forwarding:\n"
144                         "-------------------\n\n"
145
146                         "start\n"
147                         "    Start packet forwarding with current configuration.\n\n"
148
149                         "start tx_first\n"
150                         "    Start packet forwarding with current config"
151                         " after sending one burst of packets.\n\n"
152
153                         "stop\n"
154                         "    Stop packet forwarding, and display accumulated"
155                         " statistics.\n\n"
156
157                         "quit\n"
158                         "    Quit to prompt.\n\n"
159                 );
160         }
161
162         if (show_all || !strcmp(res->section, "display")) {
163
164                 cmdline_printf(
165                         cl,
166                         "\n"
167                         "Display:\n"
168                         "--------\n\n"
169
170                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
171                         "    Display information for port_id, or all.\n\n"
172
173                         "show port X rss reta (size) (mask0,mask1,...)\n"
174                         "    Display the rss redirection table entry indicated"
175                         " by masks on port X. size is used to indicate the"
176                         " hardware supported reta size\n\n"
177
178                         "show port (port_id) rss-hash [key]\n"
179                         "    Display the RSS hash functions and RSS hash key of port\n\n"
180
181                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
182                         "    Clear information for port_id, or all.\n\n"
183
184                         "show (rxq|txq) info (port_id) (queue_id)\n"
185                         "    Display information for configured RX/TX queue.\n\n"
186
187                         "show config (rxtx|cores|fwd|txpkts)\n"
188                         "    Display the given configuration.\n\n"
189
190                         "read rxd (port_id) (queue_id) (rxd_id)\n"
191                         "    Display an RX descriptor of a port RX queue.\n\n"
192
193                         "read txd (port_id) (queue_id) (txd_id)\n"
194                         "    Display a TX descriptor of a port TX queue.\n\n"
195
196                         "ddp get list (port_id)\n"
197                         "    Get ddp profile info list\n\n"
198
199                         "ddp get info (profile_path)\n"
200                         "    Get ddp profile information.\n\n"
201
202                         "show vf stats (port_id) (vf_id)\n"
203                         "    Display a VF's statistics.\n\n"
204
205                         "clear vf stats (port_id) (vf_id)\n"
206                         "    Reset a VF's statistics.\n\n"
207
208                         "show port (port_id) pctype mapping\n"
209                         "    Get flow ptype to pctype mapping on a port\n\n"
210
211                         "show port meter stats (port_id) (meter_id) (clear)\n"
212                         "    Get meter stats on a port\n\n"
213                         "show port tm cap (port_id)\n"
214                         "       Display the port TM capability.\n\n"
215
216                         "show port tm level cap (port_id) (level_id)\n"
217                         "       Display the port TM hierarchical level capability.\n\n"
218
219                         "show port tm node cap (port_id) (node_id)\n"
220                         "       Display the port TM node capability.\n\n"
221
222                         "show port tm node type (port_id) (node_id)\n"
223                         "       Display the port TM node type.\n\n"
224
225                         "show port tm node stats (port_id) (node_id) (clear)\n"
226                         "       Display the port TM node stats.\n\n"
227
228                         "show fwd stats all\n"
229                         "    Display statistics for all fwd engines.\n\n"
230
231                         "clear fwd stats all\n"
232                         "    Clear statistics for all fwd engines.\n\n"
233                 );
234         }
235
236         if (show_all || !strcmp(res->section, "config")) {
237                 cmdline_printf(
238                         cl,
239                         "\n"
240                         "Configuration:\n"
241                         "--------------\n"
242                         "Configuration changes only become active when"
243                         " forwarding is started/restarted.\n\n"
244
245                         "set default\n"
246                         "    Reset forwarding to the default configuration.\n\n"
247
248                         "set verbose (level)\n"
249                         "    Set the debug verbosity level X.\n\n"
250
251                         "set log global|(type) (level)\n"
252                         "    Set the log level.\n\n"
253
254                         "set nbport (num)\n"
255                         "    Set number of ports.\n\n"
256
257                         "set nbcore (num)\n"
258                         "    Set number of cores.\n\n"
259
260                         "set coremask (mask)\n"
261                         "    Set the forwarding cores hexadecimal mask.\n\n"
262
263                         "set portmask (mask)\n"
264                         "    Set the forwarding ports hexadecimal mask.\n\n"
265
266                         "set burst (num)\n"
267                         "    Set number of packets per burst.\n\n"
268
269                         "set burst tx delay (microseconds) retry (num)\n"
270                         "    Set the transmit delay time and number of retries,"
271                         " effective when retry is enabled.\n\n"
272
273                         "set txpkts (x[,y]*)\n"
274                         "    Set the length of each segment of TXONLY"
275                         " and optionally CSUM packets.\n\n"
276
277                         "set txsplit (off|on|rand)\n"
278                         "    Set the split policy for the TX packets."
279                         " Right now only applicable for CSUM and TXONLY"
280                         " modes\n\n"
281
282                         "set corelist (x[,y]*)\n"
283                         "    Set the list of forwarding cores.\n\n"
284
285                         "set portlist (x[,y]*)\n"
286                         "    Set the list of forwarding ports.\n\n"
287
288                         "set port setup on (iterator|event)\n"
289                         "    Select how attached port is retrieved for setup.\n\n"
290
291                         "set tx loopback (port_id) (on|off)\n"
292                         "    Enable or disable tx loopback.\n\n"
293
294                         "set all queues drop (port_id) (on|off)\n"
295                         "    Set drop enable bit for all queues.\n\n"
296
297                         "set vf split drop (port_id) (vf_id) (on|off)\n"
298                         "    Set split drop enable bit for a VF from the PF.\n\n"
299
300                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
301                         "    Set MAC antispoof for a VF from the PF.\n\n"
302
303                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
304                         "    Enable MACsec offload.\n\n"
305
306                         "set macsec offload (port_id) off\n"
307                         "    Disable MACsec offload.\n\n"
308
309                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
310                         "    Configure MACsec secure connection (SC).\n\n"
311
312                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
313                         "    Configure MACsec secure association (SA).\n\n"
314
315                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
316                         "    Set VF broadcast for a VF from the PF.\n\n"
317
318                         "vlan set strip (on|off) (port_id)\n"
319                         "    Set the VLAN strip on a port.\n\n"
320
321                         "vlan set stripq (on|off) (port_id,queue_id)\n"
322                         "    Set the VLAN strip for a queue on a port.\n\n"
323
324                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
325                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
326
327                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
328                         "    Set VLAN insert for a VF from the PF.\n\n"
329
330                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
331                         "    Set VLAN antispoof for a VF from the PF.\n\n"
332
333                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
334                         "    Set VLAN tag for a VF from the PF.\n\n"
335
336                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
337                         "    Set a VF's max bandwidth(Mbps).\n\n"
338
339                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
340                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
341
342                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
343                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
344
345                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
346                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
347
348                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
349                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
350
351                         "vlan set filter (on|off) (port_id)\n"
352                         "    Set the VLAN filter on a port.\n\n"
353
354                         "vlan set qinq (on|off) (port_id)\n"
355                         "    Set the VLAN QinQ (extended queue in queue)"
356                         " on a port.\n\n"
357
358                         "vlan set (inner|outer) tpid (value) (port_id)\n"
359                         "    Set the VLAN TPID for Packet Filtering on"
360                         " a port\n\n"
361
362                         "rx_vlan add (vlan_id|all) (port_id)\n"
363                         "    Add a vlan_id, or all identifiers, to the set"
364                         " of VLAN identifiers filtered by port_id.\n\n"
365
366                         "rx_vlan rm (vlan_id|all) (port_id)\n"
367                         "    Remove a vlan_id, or all identifiers, from the set"
368                         " of VLAN identifiers filtered by port_id.\n\n"
369
370                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
371                         "    Add a vlan_id, to the set of VLAN identifiers"
372                         "filtered for VF(s) from port_id.\n\n"
373
374                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
375                         "    Remove a vlan_id, to the set of VLAN identifiers"
376                         "filtered for VF(s) from port_id.\n\n"
377
378                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
379                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
380                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
381                         "   add a tunnel filter of a port.\n\n"
382
383                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
384                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
385                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
386                         "   remove a tunnel filter of a port.\n\n"
387
388                         "rx_vxlan_port add (udp_port) (port_id)\n"
389                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
390
391                         "rx_vxlan_port rm (udp_port) (port_id)\n"
392                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
393
394                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
395                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
396                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
397
398                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
399                         "    Set port based TX VLAN insertion.\n\n"
400
401                         "tx_vlan reset (port_id)\n"
402                         "    Disable hardware insertion of a VLAN header in"
403                         " packets sent on a port.\n\n"
404
405                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
406                         "    Select hardware or software calculation of the"
407                         " checksum when transmitting a packet using the"
408                         " csum forward engine.\n"
409                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
410                         "    outer-ip concerns the outer IP layer in"
411                         "    outer-udp concerns the outer UDP layer in"
412                         " case the packet is recognized as a tunnel packet by"
413                         " the forward engine (vxlan, gre and ipip are supported)\n"
414                         "    Please check the NIC datasheet for HW limits.\n\n"
415
416                         "csum parse-tunnel (on|off) (tx_port_id)\n"
417                         "    If disabled, treat tunnel packets as non-tunneled"
418                         " packets (treat inner headers as payload). The port\n"
419                         "    argument is the port used for TX in csum forward"
420                         " engine.\n\n"
421
422                         "csum show (port_id)\n"
423                         "    Display tx checksum offload configuration\n\n"
424
425                         "tso set (segsize) (portid)\n"
426                         "    Enable TCP Segmentation Offload in csum forward"
427                         " engine.\n"
428                         "    Please check the NIC datasheet for HW limits.\n\n"
429
430                         "tso show (portid)"
431                         "    Display the status of TCP Segmentation Offload.\n\n"
432
433                         "set port (port_id) gro on|off\n"
434                         "    Enable or disable Generic Receive Offload in"
435                         " csum forwarding engine.\n\n"
436
437                         "show port (port_id) gro\n"
438                         "    Display GRO configuration.\n\n"
439
440                         "set gro flush (cycles)\n"
441                         "    Set the cycle to flush GROed packets from"
442                         " reassembly tables.\n\n"
443
444                         "set port (port_id) gso (on|off)"
445                         "    Enable or disable Generic Segmentation Offload in"
446                         " csum forwarding engine.\n\n"
447
448                         "set gso segsz (length)\n"
449                         "    Set max packet length for output GSO segments,"
450                         " including packet header and payload.\n\n"
451
452                         "show port (port_id) gso\n"
453                         "    Show GSO configuration.\n\n"
454
455                         "set fwd (%s)\n"
456                         "    Set packet forwarding mode.\n\n"
457
458                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
459                         "    Add a MAC address on port_id.\n\n"
460
461                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
462                         "    Remove a MAC address from port_id.\n\n"
463
464                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
465                         "    Set the default MAC address for port_id.\n\n"
466
467                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
468                         "    Add a MAC address for a VF on the port.\n\n"
469
470                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
471                         "    Set the MAC address for a VF from the PF.\n\n"
472
473                         "set eth-peer (port_id) (peer_addr)\n"
474                         "    set the peer address for certain port.\n\n"
475
476                         "set port (port_id) uta (mac_address|all) (on|off)\n"
477                         "    Add/Remove a or all unicast hash filter(s)"
478                         "from port X.\n\n"
479
480                         "set promisc (port_id|all) (on|off)\n"
481                         "    Set the promiscuous mode on port_id, or all.\n\n"
482
483                         "set allmulti (port_id|all) (on|off)\n"
484                         "    Set the allmulti mode on port_id, or all.\n\n"
485
486                         "set vf promisc (port_id) (vf_id) (on|off)\n"
487                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
488
489                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
490                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
491
492                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
493                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
494                         " (on|off) autoneg (on|off) (port_id)\n"
495                         "set flow_ctrl rx (on|off) (portid)\n"
496                         "set flow_ctrl tx (on|off) (portid)\n"
497                         "set flow_ctrl high_water (high_water) (portid)\n"
498                         "set flow_ctrl low_water (low_water) (portid)\n"
499                         "set flow_ctrl pause_time (pause_time) (portid)\n"
500                         "set flow_ctrl send_xon (send_xon) (portid)\n"
501                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
502                         "set flow_ctrl autoneg (on|off) (port_id)\n"
503                         "    Set the link flow control parameter on a port.\n\n"
504
505                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
506                         " (low_water) (pause_time) (priority) (port_id)\n"
507                         "    Set the priority flow control parameter on a"
508                         " port.\n\n"
509
510                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
511                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
512                         " queue on port.\n"
513                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
514                         " on port 0 to mapping 5.\n\n"
515
516                         "set xstats-hide-zero on|off\n"
517                         "    Set the option to hide the zero values"
518                         " for xstats display.\n"
519
520                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
521                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
522
523                         "set port (port_id) vf (vf_id) (mac_addr)"
524                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
525                         "   Add/Remove unicast or multicast MAC addr filter"
526                         " for a VF.\n\n"
527
528                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
529                         "|MPE) (on|off)\n"
530                         "    AUPE:accepts untagged VLAN;"
531                         "ROPE:accept unicast hash\n\n"
532                         "    BAM:accepts broadcast packets;"
533                         "MPE:accepts all multicast packets\n\n"
534                         "    Enable/Disable a VF receive mode of a port\n\n"
535
536                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
537                         "    Set rate limit for a queue of a port\n\n"
538
539                         "set port (port_id) vf (vf_id) rate (rate_num) "
540                         "queue_mask (queue_mask_value)\n"
541                         "    Set rate limit for queues in VF of a port\n\n"
542
543                         "set port (port_id) mirror-rule (rule_id)"
544                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
545                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
546                         "   Set pool or vlan type mirror rule on a port.\n"
547                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
548                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
549                         " to pool 0.\n\n"
550
551                         "set port (port_id) mirror-rule (rule_id)"
552                         " (uplink-mirror|downlink-mirror) dst-pool"
553                         " (pool_id) (on|off)\n"
554                         "   Set uplink or downlink type mirror rule on a port.\n"
555                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
556                         " 0 on' enable mirror income traffic to pool 0.\n\n"
557
558                         "reset port (port_id) mirror-rule (rule_id)\n"
559                         "   Reset a mirror rule.\n\n"
560
561                         "set flush_rx (on|off)\n"
562                         "   Flush (default) or don't flush RX streams before"
563                         " forwarding. Mainly used with PCAP drivers.\n\n"
564
565                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
566                         "   Set the bypass mode for the lowest port on bypass enabled"
567                         " NIC.\n\n"
568
569                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
570                         "mode (normal|bypass|isolate) (port_id)\n"
571                         "   Set the event required to initiate specified bypass mode for"
572                         " the lowest port on a bypass enabled NIC where:\n"
573                         "       timeout   = enable bypass after watchdog timeout.\n"
574                         "       os_on     = enable bypass when OS/board is powered on.\n"
575                         "       os_off    = enable bypass when OS/board is powered off.\n"
576                         "       power_on  = enable bypass when power supply is turned on.\n"
577                         "       power_off = enable bypass when power supply is turned off."
578                         "\n\n"
579
580                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
581                         "   Set the bypass watchdog timeout to 'n' seconds"
582                         " where 0 = instant.\n\n"
583
584                         "show bypass config (port_id)\n"
585                         "   Show the bypass configuration for a bypass enabled NIC"
586                         " using the lowest port on the NIC.\n\n"
587
588 #ifdef RTE_LIBRTE_PMD_BOND
589                         "create bonded device (mode) (socket)\n"
590                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
591
592                         "add bonding slave (slave_id) (port_id)\n"
593                         "       Add a slave device to a bonded device.\n\n"
594
595                         "remove bonding slave (slave_id) (port_id)\n"
596                         "       Remove a slave device from a bonded device.\n\n"
597
598                         "set bonding mode (value) (port_id)\n"
599                         "       Set the bonding mode on a bonded device.\n\n"
600
601                         "set bonding primary (slave_id) (port_id)\n"
602                         "       Set the primary slave for a bonded device.\n\n"
603
604                         "show bonding config (port_id)\n"
605                         "       Show the bonding config for port_id.\n\n"
606
607                         "set bonding mac_addr (port_id) (address)\n"
608                         "       Set the MAC address of a bonded device.\n\n"
609
610                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
611                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
612
613                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
614                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
615
616                         "set bonding mon_period (port_id) (value)\n"
617                         "       Set the bonding link status monitoring polling period in ms.\n\n"
618
619                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
620                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
621
622 #endif
623                         "set link-up port (port_id)\n"
624                         "       Set link up for a port.\n\n"
625
626                         "set link-down port (port_id)\n"
627                         "       Set link down for a port.\n\n"
628
629                         "E-tag set insertion on port-tag-id (value)"
630                         " port (port_id) vf (vf_id)\n"
631                         "    Enable E-tag insertion for a VF on a port\n\n"
632
633                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
634                         "    Disable E-tag insertion for a VF on a port\n\n"
635
636                         "E-tag set stripping (on|off) port (port_id)\n"
637                         "    Enable/disable E-tag stripping on a port\n\n"
638
639                         "E-tag set forwarding (on|off) port (port_id)\n"
640                         "    Enable/disable E-tag based forwarding"
641                         " on a port\n\n"
642
643                         "E-tag set filter add e-tag-id (value) dst-pool"
644                         " (pool_id) port (port_id)\n"
645                         "    Add an E-tag forwarding filter on a port\n\n"
646
647                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
648                         "    Delete an E-tag forwarding filter on a port\n\n"
649
650 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
651                         "set port tm hierarchy default (port_id)\n"
652                         "       Set default traffic Management hierarchy on a port\n\n"
653
654 #endif
655                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
656                         "    Load a profile package on a port\n\n"
657
658                         "ddp del (port_id) (backup_profile_path)\n"
659                         "    Delete a profile package from a port\n\n"
660
661                         "ptype mapping get (port_id) (valid_only)\n"
662                         "    Get ptype mapping on a port\n\n"
663
664                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
665                         "    Replace target with the pkt_type in ptype mapping\n\n"
666
667                         "ptype mapping reset (port_id)\n"
668                         "    Reset ptype mapping on a port\n\n"
669
670                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
671                         "    Update a ptype mapping item on a port\n\n"
672
673                         "set port (port_id) queue-region region_id (value) "
674                         "queue_start_index (value) queue_num (value)\n"
675                         "    Set a queue region on a port\n\n"
676
677                         "set port (port_id) queue-region region_id (value) "
678                         "flowtype (value)\n"
679                         "    Set a flowtype region index on a port\n\n"
680
681                         "set port (port_id) queue-region UP (value) region_id (value)\n"
682                         "    Set the mapping of User Priority to "
683                         "queue region on a port\n\n"
684
685                         "set port (port_id) queue-region flush (on|off)\n"
686                         "    flush all queue region related configuration\n\n"
687
688                         "show port meter cap (port_id)\n"
689                         "    Show port meter capability information\n\n"
690
691                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
692                         "    meter profile add - srtcm rfc 2697\n\n"
693
694                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
695                         "    meter profile add - trtcm rfc 2698\n\n"
696
697                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
698                         "    meter profile add - trtcm rfc 4115\n\n"
699
700                         "del port meter profile (port_id) (profile_id)\n"
701                         "    meter profile delete\n\n"
702
703                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
704                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
705                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
706                         "(dscp_tbl_entry63)]\n"
707                         "    meter create\n\n"
708
709                         "enable port meter (port_id) (mtr_id)\n"
710                         "    meter enable\n\n"
711
712                         "disable port meter (port_id) (mtr_id)\n"
713                         "    meter disable\n\n"
714
715                         "del port meter (port_id) (mtr_id)\n"
716                         "    meter delete\n\n"
717
718                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
719                         "    meter update meter profile\n\n"
720
721                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
722                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
723                         "    update meter dscp table entries\n\n"
724
725                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
726                         "(action0) [(action1) (action2)]\n"
727                         "    meter update policer action\n\n"
728
729                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
730                         "    meter update stats\n\n"
731
732                         "show port (port_id) queue-region\n"
733                         "    show all queue region related configuration info\n\n"
734
735                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
736                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
737                         " (packet_length_adjust)\n"
738                         "       Add port tm node private shaper profile.\n\n"
739
740                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
741                         "       Delete port tm node private shaper profile.\n\n"
742
743                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
744                         " (shaper_profile_id)\n"
745                         "       Add/update port tm node shared shaper.\n\n"
746
747                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
748                         "       Delete port tm node shared shaper.\n\n"
749
750                         "set port tm node shaper profile (port_id) (node_id)"
751                         " (shaper_profile_id)\n"
752                         "       Set port tm node shaper profile.\n\n"
753
754                         "add port tm node wred profile (port_id) (wred_profile_id)"
755                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
756                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
757                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
758                         "       Add port tm node wred profile.\n\n"
759
760                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
761                         "       Delete port tm node wred profile.\n\n"
762
763                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
764                         " (priority) (weight) (level_id) (shaper_profile_id)"
765                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
766                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
767                         "       Add port tm nonleaf node.\n\n"
768
769                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
770                         " (priority) (weight) (level_id) (shaper_profile_id)"
771                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
772                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
773                         "       Add port tm leaf node.\n\n"
774
775                         "del port tm node (port_id) (node_id)\n"
776                         "       Delete port tm node.\n\n"
777
778                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
779                         " (priority) (weight)\n"
780                         "       Set port tm node parent.\n\n"
781
782                         "suspend port tm node (port_id) (node_id)"
783                         "       Suspend tm node.\n\n"
784
785                         "resume port tm node (port_id) (node_id)"
786                         "       Resume tm node.\n\n"
787
788                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
789                         "       Commit tm hierarchy.\n\n"
790
791                         "vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
792                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
793                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
794                         "       Configure the VXLAN encapsulation for flows.\n\n"
795
796                         "vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
797                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
798                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
799                         " eth-dst (eth-dst)\n"
800                         "       Configure the VXLAN encapsulation for flows.\n\n"
801
802                         "vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
803                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
804                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
805                         " eth-dst (eth-dst)\n"
806                         "       Configure the VXLAN encapsulation for flows.\n\n"
807
808                         "nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
809                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
810                         " (eth-dst)\n"
811                         "       Configure the NVGRE encapsulation for flows.\n\n"
812
813                         "nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
814                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
815                         " eth-src (eth-src) eth-dst (eth-dst)\n"
816                         "       Configure the NVGRE encapsulation for flows.\n\n"
817
818                         , list_pkt_forwarding_modes()
819                 );
820         }
821
822         if (show_all || !strcmp(res->section, "ports")) {
823
824                 cmdline_printf(
825                         cl,
826                         "\n"
827                         "Port Operations:\n"
828                         "----------------\n\n"
829
830                         "port start (port_id|all)\n"
831                         "    Start all ports or port_id.\n\n"
832
833                         "port stop (port_id|all)\n"
834                         "    Stop all ports or port_id.\n\n"
835
836                         "port close (port_id|all)\n"
837                         "    Close all ports or port_id.\n\n"
838
839                         "port attach (ident)\n"
840                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
841
842                         "port detach (port_id)\n"
843                         "    Detach physical or virtual dev by port_id\n\n"
844
845                         "port config (port_id|all)"
846                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
847                         " duplex (half|full|auto)\n"
848                         "    Set speed and duplex for all ports or port_id\n\n"
849
850                         "port config (port_id|all) loopback (mode)\n"
851                         "    Set loopback mode for all ports or port_id\n\n"
852
853                         "port config all (rxq|txq|rxd|txd) (value)\n"
854                         "    Set number for rxq/txq/rxd/txd.\n\n"
855
856                         "port config all max-pkt-len (value)\n"
857                         "    Set the max packet length.\n\n"
858
859                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
860                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
861                         " (on|off)\n"
862                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
863                         " for ports.\n\n"
864
865                         "port config all rss (all|default|ip|tcp|udp|sctp|"
866                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
867                         "    Set the RSS mode.\n\n"
868
869                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
870                         "    Set the RSS redirection table.\n\n"
871
872                         "port config (port_id) dcb vt (on|off) (traffic_class)"
873                         " pfc (on|off)\n"
874                         "    Set the DCB mode.\n\n"
875
876                         "port config all burst (value)\n"
877                         "    Set the number of packets per burst.\n\n"
878
879                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
880                         " (value)\n"
881                         "    Set the ring prefetch/host/writeback threshold"
882                         " for tx/rx queue.\n\n"
883
884                         "port config all (txfreet|txrst|rxfreet) (value)\n"
885                         "    Set free threshold for rx/tx, or set"
886                         " tx rs bit threshold.\n\n"
887                         "port config mtu X value\n"
888                         "    Set the MTU of port X to a given value\n\n"
889
890                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
891                         "    Set a rx/tx queue's ring size configuration, the new"
892                         " value will take effect after command that (re-)start the port"
893                         " or command that setup the specific queue\n\n"
894
895                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
896                         "    Start/stop a rx/tx queue of port X. Only take effect"
897                         " when port X is started\n\n"
898
899                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
900                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
901                         " take effect when port X is stopped.\n\n"
902
903                         "port (port_id) (rxq|txq) (queue_id) setup\n"
904                         "    Setup a rx/tx queue of port X.\n\n"
905
906                         "port config (port_id|all) l2-tunnel E-tag ether-type"
907                         " (value)\n"
908                         "    Set the value of E-tag ether-type.\n\n"
909
910                         "port config (port_id|all) l2-tunnel E-tag"
911                         " (enable|disable)\n"
912                         "    Enable/disable the E-tag support.\n\n"
913
914                         "port config (port_id) pctype mapping reset\n"
915                         "    Reset flow type to pctype mapping on a port\n\n"
916
917                         "port config (port_id) pctype mapping update"
918                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
919                         "    Update a flow type to pctype mapping item on a port\n\n"
920
921                         "port config (port_id) pctype (pctype_id) hash_inset|"
922                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
923                         " (field_idx)\n"
924                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
925
926                         "port config (port_id) pctype (pctype_id) hash_inset|"
927                         "fdir_inset|fdir_flx_inset clear all"
928                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
929
930                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
931                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
932                 );
933         }
934
935         if (show_all || !strcmp(res->section, "registers")) {
936
937                 cmdline_printf(
938                         cl,
939                         "\n"
940                         "Registers:\n"
941                         "----------\n\n"
942
943                         "read reg (port_id) (address)\n"
944                         "    Display value of a port register.\n\n"
945
946                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
947                         "    Display a port register bit field.\n\n"
948
949                         "read regbit (port_id) (address) (bit_x)\n"
950                         "    Display a single port register bit.\n\n"
951
952                         "write reg (port_id) (address) (value)\n"
953                         "    Set value of a port register.\n\n"
954
955                         "write regfield (port_id) (address) (bit_x) (bit_y)"
956                         " (value)\n"
957                         "    Set bit field of a port register.\n\n"
958
959                         "write regbit (port_id) (address) (bit_x) (value)\n"
960                         "    Set single bit value of a port register.\n\n"
961                 );
962         }
963         if (show_all || !strcmp(res->section, "filters")) {
964
965                 cmdline_printf(
966                         cl,
967                         "\n"
968                         "filters:\n"
969                         "--------\n\n"
970
971                         "ethertype_filter (port_id) (add|del)"
972                         " (mac_addr|mac_ignr) (mac_address) ethertype"
973                         " (ether_type) (drop|fwd) queue (queue_id)\n"
974                         "    Add/Del an ethertype filter.\n\n"
975
976                         "2tuple_filter (port_id) (add|del)"
977                         " dst_port (dst_port_value) protocol (protocol_value)"
978                         " mask (mask_value) tcp_flags (tcp_flags_value)"
979                         " priority (prio_value) queue (queue_id)\n"
980                         "    Add/Del a 2tuple filter.\n\n"
981
982                         "5tuple_filter (port_id) (add|del)"
983                         " dst_ip (dst_address) src_ip (src_address)"
984                         " dst_port (dst_port_value) src_port (src_port_value)"
985                         " protocol (protocol_value)"
986                         " mask (mask_value) tcp_flags (tcp_flags_value)"
987                         " priority (prio_value) queue (queue_id)\n"
988                         "    Add/Del a 5tuple filter.\n\n"
989
990                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
991                         "    Add/Del syn filter.\n\n"
992
993                         "flex_filter (port_id) (add|del) len (len_value)"
994                         " bytes (bytes_value) mask (mask_value)"
995                         " priority (prio_value) queue (queue_id)\n"
996                         "    Add/Del a flex filter.\n\n"
997
998                         "flow_director_filter (port_id) mode IP (add|del|update)"
999                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
1000                         " src (src_ip_address) dst (dst_ip_address)"
1001                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
1002                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1003                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1004                         " fd_id (fd_id_value)\n"
1005                         "    Add/Del an IP type flow director filter.\n\n"
1006
1007                         "flow_director_filter (port_id) mode IP (add|del|update)"
1008                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1009                         " src (src_ip_address) (src_port)"
1010                         " dst (dst_ip_address) (dst_port)"
1011                         " tos (tos_value) ttl (ttl_value)"
1012                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1013                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1014                         " fd_id (fd_id_value)\n"
1015                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1016
1017                         "flow_director_filter (port_id) mode IP (add|del|update)"
1018                         " flow (ipv4-sctp|ipv6-sctp)"
1019                         " src (src_ip_address) (src_port)"
1020                         " dst (dst_ip_address) (dst_port)"
1021                         " tag (verification_tag) "
1022                         " tos (tos_value) ttl (ttl_value)"
1023                         " vlan (vlan_value)"
1024                         " flexbytes (flexbytes_value) (drop|fwd)"
1025                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1026                         "    Add/Del a SCTP type flow director filter.\n\n"
1027
1028                         "flow_director_filter (port_id) mode IP (add|del|update)"
1029                         " flow l2_payload ether (ethertype)"
1030                         " flexbytes (flexbytes_value) (drop|fwd)"
1031                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1032                         "    Add/Del a l2 payload type flow director filter.\n\n"
1033
1034                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1035                         " mac (mac_address) vlan (vlan_value)"
1036                         " flexbytes (flexbytes_value) (drop|fwd)"
1037                         " queue (queue_id) fd_id (fd_id_value)\n"
1038                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1039
1040                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1041                         " mac (mac_address) vlan (vlan_value)"
1042                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1043                         " flexbytes (flexbytes_value) (drop|fwd)"
1044                         " queue (queue_id) fd_id (fd_id_value)\n"
1045                         "    Add/Del a Tunnel flow director filter.\n\n"
1046
1047                         "flow_director_filter (port_id) mode raw (add|del|update)"
1048                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1049                         " fd_id (fd_id_value) packet (packet file name)\n"
1050                         "    Add/Del a raw type flow director filter.\n\n"
1051
1052                         "flush_flow_director (port_id)\n"
1053                         "    Flush all flow director entries of a device.\n\n"
1054
1055                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1056                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1057                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1058                         "    Set flow director IP mask.\n\n"
1059
1060                         "flow_director_mask (port_id) mode MAC-VLAN"
1061                         " vlan (vlan_value)\n"
1062                         "    Set flow director MAC-VLAN mask.\n\n"
1063
1064                         "flow_director_mask (port_id) mode Tunnel"
1065                         " vlan (vlan_value) mac (mac_value)"
1066                         " tunnel-type (tunnel_type_value)"
1067                         " tunnel-id (tunnel_id_value)\n"
1068                         "    Set flow director Tunnel mask.\n\n"
1069
1070                         "flow_director_flex_mask (port_id)"
1071                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1072                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1073                         " (mask)\n"
1074                         "    Configure mask of flex payload.\n\n"
1075
1076                         "flow_director_flex_payload (port_id)"
1077                         " (raw|l2|l3|l4) (config)\n"
1078                         "    Configure flex payload selection.\n\n"
1079
1080                         "get_sym_hash_ena_per_port (port_id)\n"
1081                         "    get symmetric hash enable configuration per port.\n\n"
1082
1083                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1084                         "    set symmetric hash enable configuration per port"
1085                         " to enable or disable.\n\n"
1086
1087                         "get_hash_global_config (port_id)\n"
1088                         "    Get the global configurations of hash filters.\n\n"
1089
1090                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1091                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1092                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1093                         " (enable|disable)\n"
1094                         "    Set the global configurations of hash filters.\n\n"
1095
1096                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1097                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1098                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1099                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1100                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1101                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1102                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1103                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1104                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1105                         "fld-8th|none) (select|add)\n"
1106                         "    Set the input set for hash.\n\n"
1107
1108                         "set_fdir_input_set (port_id) "
1109                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1110                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1111                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1112                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1113                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1114                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1115                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1116                         " (select|add)\n"
1117                         "    Set the input set for FDir.\n\n"
1118
1119                         "flow validate {port_id}"
1120                         " [group {group_id}] [priority {level}]"
1121                         " [ingress] [egress]"
1122                         " pattern {item} [/ {item} [...]] / end"
1123                         " actions {action} [/ {action} [...]] / end\n"
1124                         "    Check whether a flow rule can be created.\n\n"
1125
1126                         "flow create {port_id}"
1127                         " [group {group_id}] [priority {level}]"
1128                         " [ingress] [egress]"
1129                         " pattern {item} [/ {item} [...]] / end"
1130                         " actions {action} [/ {action} [...]] / end\n"
1131                         "    Create a flow rule.\n\n"
1132
1133                         "flow destroy {port_id} rule {rule_id} [...]\n"
1134                         "    Destroy specific flow rules.\n\n"
1135
1136                         "flow flush {port_id}\n"
1137                         "    Destroy all flow rules.\n\n"
1138
1139                         "flow query {port_id} {rule_id} {action}\n"
1140                         "    Query an existing flow rule.\n\n"
1141
1142                         "flow list {port_id} [group {group_id}] [...]\n"
1143                         "    List existing flow rules sorted by priority,"
1144                         " filtered by group identifiers.\n\n"
1145
1146                         "flow isolate {port_id} {boolean}\n"
1147                         "    Restrict ingress traffic to the defined"
1148                         " flow rules\n\n"
1149                 );
1150         }
1151 }
1152
1153 cmdline_parse_token_string_t cmd_help_long_help =
1154         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1155
1156 cmdline_parse_token_string_t cmd_help_long_section =
1157         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1158                         "all#control#display#config#"
1159                         "ports#registers#filters");
1160
1161 cmdline_parse_inst_t cmd_help_long = {
1162         .f = cmd_help_long_parsed,
1163         .data = NULL,
1164         .help_str = "help all|control|display|config|ports|register|filters: "
1165                 "Show help",
1166         .tokens = {
1167                 (void *)&cmd_help_long_help,
1168                 (void *)&cmd_help_long_section,
1169                 NULL,
1170         },
1171 };
1172
1173
1174 /* *** start/stop/close all ports *** */
1175 struct cmd_operate_port_result {
1176         cmdline_fixed_string_t keyword;
1177         cmdline_fixed_string_t name;
1178         cmdline_fixed_string_t value;
1179 };
1180
1181 static void cmd_operate_port_parsed(void *parsed_result,
1182                                 __attribute__((unused)) struct cmdline *cl,
1183                                 __attribute__((unused)) void *data)
1184 {
1185         struct cmd_operate_port_result *res = parsed_result;
1186
1187         if (!strcmp(res->name, "start"))
1188                 start_port(RTE_PORT_ALL);
1189         else if (!strcmp(res->name, "stop"))
1190                 stop_port(RTE_PORT_ALL);
1191         else if (!strcmp(res->name, "close"))
1192                 close_port(RTE_PORT_ALL);
1193         else if (!strcmp(res->name, "reset"))
1194                 reset_port(RTE_PORT_ALL);
1195         else
1196                 printf("Unknown parameter\n");
1197 }
1198
1199 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1200         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1201                                                                 "port");
1202 cmdline_parse_token_string_t cmd_operate_port_all_port =
1203         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1204                                                 "start#stop#close#reset");
1205 cmdline_parse_token_string_t cmd_operate_port_all_all =
1206         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1207
1208 cmdline_parse_inst_t cmd_operate_port = {
1209         .f = cmd_operate_port_parsed,
1210         .data = NULL,
1211         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1212         .tokens = {
1213                 (void *)&cmd_operate_port_all_cmd,
1214                 (void *)&cmd_operate_port_all_port,
1215                 (void *)&cmd_operate_port_all_all,
1216                 NULL,
1217         },
1218 };
1219
1220 /* *** start/stop/close specific port *** */
1221 struct cmd_operate_specific_port_result {
1222         cmdline_fixed_string_t keyword;
1223         cmdline_fixed_string_t name;
1224         uint8_t value;
1225 };
1226
1227 static void cmd_operate_specific_port_parsed(void *parsed_result,
1228                         __attribute__((unused)) struct cmdline *cl,
1229                                 __attribute__((unused)) void *data)
1230 {
1231         struct cmd_operate_specific_port_result *res = parsed_result;
1232
1233         if (!strcmp(res->name, "start"))
1234                 start_port(res->value);
1235         else if (!strcmp(res->name, "stop"))
1236                 stop_port(res->value);
1237         else if (!strcmp(res->name, "close"))
1238                 close_port(res->value);
1239         else if (!strcmp(res->name, "reset"))
1240                 reset_port(res->value);
1241         else
1242                 printf("Unknown parameter\n");
1243 }
1244
1245 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1246         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1247                                                         keyword, "port");
1248 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1249         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1250                                                 name, "start#stop#close#reset");
1251 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1252         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1253                                                         value, UINT8);
1254
1255 cmdline_parse_inst_t cmd_operate_specific_port = {
1256         .f = cmd_operate_specific_port_parsed,
1257         .data = NULL,
1258         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1259         .tokens = {
1260                 (void *)&cmd_operate_specific_port_cmd,
1261                 (void *)&cmd_operate_specific_port_port,
1262                 (void *)&cmd_operate_specific_port_id,
1263                 NULL,
1264         },
1265 };
1266
1267 /* *** enable port setup (after attach) via iterator or event *** */
1268 struct cmd_set_port_setup_on_result {
1269         cmdline_fixed_string_t set;
1270         cmdline_fixed_string_t port;
1271         cmdline_fixed_string_t setup;
1272         cmdline_fixed_string_t on;
1273         cmdline_fixed_string_t mode;
1274 };
1275
1276 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1277                                 __attribute__((unused)) struct cmdline *cl,
1278                                 __attribute__((unused)) void *data)
1279 {
1280         struct cmd_set_port_setup_on_result *res = parsed_result;
1281
1282         if (strcmp(res->mode, "event") == 0)
1283                 setup_on_probe_event = true;
1284         else if (strcmp(res->mode, "iterator") == 0)
1285                 setup_on_probe_event = false;
1286         else
1287                 printf("Unknown mode\n");
1288 }
1289
1290 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1291         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1292                         set, "set");
1293 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1294         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1295                         port, "port");
1296 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1297         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1298                         setup, "setup");
1299 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1300         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1301                         on, "on");
1302 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1303         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1304                         mode, "iterator#event");
1305
1306 cmdline_parse_inst_t cmd_set_port_setup_on = {
1307         .f = cmd_set_port_setup_on_parsed,
1308         .data = NULL,
1309         .help_str = "set port setup on iterator|event",
1310         .tokens = {
1311                 (void *)&cmd_set_port_setup_on_set,
1312                 (void *)&cmd_set_port_setup_on_port,
1313                 (void *)&cmd_set_port_setup_on_setup,
1314                 (void *)&cmd_set_port_setup_on_on,
1315                 (void *)&cmd_set_port_setup_on_mode,
1316                 NULL,
1317         },
1318 };
1319
1320 /* *** attach a specified port *** */
1321 struct cmd_operate_attach_port_result {
1322         cmdline_fixed_string_t port;
1323         cmdline_fixed_string_t keyword;
1324         cmdline_fixed_string_t identifier;
1325 };
1326
1327 static void cmd_operate_attach_port_parsed(void *parsed_result,
1328                                 __attribute__((unused)) struct cmdline *cl,
1329                                 __attribute__((unused)) void *data)
1330 {
1331         struct cmd_operate_attach_port_result *res = parsed_result;
1332
1333         if (!strcmp(res->keyword, "attach"))
1334                 attach_port(res->identifier);
1335         else
1336                 printf("Unknown parameter\n");
1337 }
1338
1339 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1340         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1341                         port, "port");
1342 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1343         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1344                         keyword, "attach");
1345 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1346         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1347                         identifier, NULL);
1348
1349 cmdline_parse_inst_t cmd_operate_attach_port = {
1350         .f = cmd_operate_attach_port_parsed,
1351         .data = NULL,
1352         .help_str = "port attach <identifier>: "
1353                 "(identifier: pci address or virtual dev name)",
1354         .tokens = {
1355                 (void *)&cmd_operate_attach_port_port,
1356                 (void *)&cmd_operate_attach_port_keyword,
1357                 (void *)&cmd_operate_attach_port_identifier,
1358                 NULL,
1359         },
1360 };
1361
1362 /* *** detach a specified port *** */
1363 struct cmd_operate_detach_port_result {
1364         cmdline_fixed_string_t port;
1365         cmdline_fixed_string_t keyword;
1366         portid_t port_id;
1367 };
1368
1369 static void cmd_operate_detach_port_parsed(void *parsed_result,
1370                                 __attribute__((unused)) struct cmdline *cl,
1371                                 __attribute__((unused)) void *data)
1372 {
1373         struct cmd_operate_detach_port_result *res = parsed_result;
1374
1375         if (!strcmp(res->keyword, "detach"))
1376                 detach_port_device(res->port_id);
1377         else
1378                 printf("Unknown parameter\n");
1379 }
1380
1381 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1382         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1383                         port, "port");
1384 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1385         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1386                         keyword, "detach");
1387 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1388         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1389                         port_id, UINT16);
1390
1391 cmdline_parse_inst_t cmd_operate_detach_port = {
1392         .f = cmd_operate_detach_port_parsed,
1393         .data = NULL,
1394         .help_str = "port detach <port_id>",
1395         .tokens = {
1396                 (void *)&cmd_operate_detach_port_port,
1397                 (void *)&cmd_operate_detach_port_keyword,
1398                 (void *)&cmd_operate_detach_port_port_id,
1399                 NULL,
1400         },
1401 };
1402
1403 /* *** configure speed for all ports *** */
1404 struct cmd_config_speed_all {
1405         cmdline_fixed_string_t port;
1406         cmdline_fixed_string_t keyword;
1407         cmdline_fixed_string_t all;
1408         cmdline_fixed_string_t item1;
1409         cmdline_fixed_string_t item2;
1410         cmdline_fixed_string_t value1;
1411         cmdline_fixed_string_t value2;
1412 };
1413
1414 static int
1415 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1416 {
1417
1418         int duplex;
1419
1420         if (!strcmp(duplexstr, "half")) {
1421                 duplex = ETH_LINK_HALF_DUPLEX;
1422         } else if (!strcmp(duplexstr, "full")) {
1423                 duplex = ETH_LINK_FULL_DUPLEX;
1424         } else if (!strcmp(duplexstr, "auto")) {
1425                 duplex = ETH_LINK_FULL_DUPLEX;
1426         } else {
1427                 printf("Unknown duplex parameter\n");
1428                 return -1;
1429         }
1430
1431         if (!strcmp(speedstr, "10")) {
1432                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1433                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1434         } else if (!strcmp(speedstr, "100")) {
1435                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1436                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1437         } else {
1438                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1439                         printf("Invalid speed/duplex parameters\n");
1440                         return -1;
1441                 }
1442                 if (!strcmp(speedstr, "1000")) {
1443                         *speed = ETH_LINK_SPEED_1G;
1444                 } else if (!strcmp(speedstr, "10000")) {
1445                         *speed = ETH_LINK_SPEED_10G;
1446                 } else if (!strcmp(speedstr, "25000")) {
1447                         *speed = ETH_LINK_SPEED_25G;
1448                 } else if (!strcmp(speedstr, "40000")) {
1449                         *speed = ETH_LINK_SPEED_40G;
1450                 } else if (!strcmp(speedstr, "50000")) {
1451                         *speed = ETH_LINK_SPEED_50G;
1452                 } else if (!strcmp(speedstr, "100000")) {
1453                         *speed = ETH_LINK_SPEED_100G;
1454                 } else if (!strcmp(speedstr, "auto")) {
1455                         *speed = ETH_LINK_SPEED_AUTONEG;
1456                 } else {
1457                         printf("Unknown speed parameter\n");
1458                         return -1;
1459                 }
1460         }
1461
1462         return 0;
1463 }
1464
1465 static void
1466 cmd_config_speed_all_parsed(void *parsed_result,
1467                         __attribute__((unused)) struct cmdline *cl,
1468                         __attribute__((unused)) void *data)
1469 {
1470         struct cmd_config_speed_all *res = parsed_result;
1471         uint32_t link_speed;
1472         portid_t pid;
1473
1474         if (!all_ports_stopped()) {
1475                 printf("Please stop all ports first\n");
1476                 return;
1477         }
1478
1479         if (parse_and_check_speed_duplex(res->value1, res->value2,
1480                         &link_speed) < 0)
1481                 return;
1482
1483         RTE_ETH_FOREACH_DEV(pid) {
1484                 ports[pid].dev_conf.link_speeds = link_speed;
1485         }
1486
1487         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1488 }
1489
1490 cmdline_parse_token_string_t cmd_config_speed_all_port =
1491         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1492 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1493         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1494                                                         "config");
1495 cmdline_parse_token_string_t cmd_config_speed_all_all =
1496         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1497 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1498         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1499 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1500         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1501                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1502 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1503         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1504 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1505         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1506                                                 "half#full#auto");
1507
1508 cmdline_parse_inst_t cmd_config_speed_all = {
1509         .f = cmd_config_speed_all_parsed,
1510         .data = NULL,
1511         .help_str = "port config all speed "
1512                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1513                                                         "half|full|auto",
1514         .tokens = {
1515                 (void *)&cmd_config_speed_all_port,
1516                 (void *)&cmd_config_speed_all_keyword,
1517                 (void *)&cmd_config_speed_all_all,
1518                 (void *)&cmd_config_speed_all_item1,
1519                 (void *)&cmd_config_speed_all_value1,
1520                 (void *)&cmd_config_speed_all_item2,
1521                 (void *)&cmd_config_speed_all_value2,
1522                 NULL,
1523         },
1524 };
1525
1526 /* *** configure speed for specific port *** */
1527 struct cmd_config_speed_specific {
1528         cmdline_fixed_string_t port;
1529         cmdline_fixed_string_t keyword;
1530         portid_t id;
1531         cmdline_fixed_string_t item1;
1532         cmdline_fixed_string_t item2;
1533         cmdline_fixed_string_t value1;
1534         cmdline_fixed_string_t value2;
1535 };
1536
1537 static void
1538 cmd_config_speed_specific_parsed(void *parsed_result,
1539                                 __attribute__((unused)) struct cmdline *cl,
1540                                 __attribute__((unused)) void *data)
1541 {
1542         struct cmd_config_speed_specific *res = parsed_result;
1543         uint32_t link_speed;
1544
1545         if (!all_ports_stopped()) {
1546                 printf("Please stop all ports first\n");
1547                 return;
1548         }
1549
1550         if (port_id_is_invalid(res->id, ENABLED_WARN))
1551                 return;
1552
1553         if (parse_and_check_speed_duplex(res->value1, res->value2,
1554                         &link_speed) < 0)
1555                 return;
1556
1557         ports[res->id].dev_conf.link_speeds = link_speed;
1558
1559         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1560 }
1561
1562
1563 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1565                                                                 "port");
1566 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1568                                                                 "config");
1569 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1570         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1571 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1572         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1573                                                                 "speed");
1574 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1575         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1576                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1577 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1578         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1579                                                                 "duplex");
1580 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1581         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1582                                                         "half#full#auto");
1583
1584 cmdline_parse_inst_t cmd_config_speed_specific = {
1585         .f = cmd_config_speed_specific_parsed,
1586         .data = NULL,
1587         .help_str = "port config <port_id> speed "
1588                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1589                                                         "half|full|auto",
1590         .tokens = {
1591                 (void *)&cmd_config_speed_specific_port,
1592                 (void *)&cmd_config_speed_specific_keyword,
1593                 (void *)&cmd_config_speed_specific_id,
1594                 (void *)&cmd_config_speed_specific_item1,
1595                 (void *)&cmd_config_speed_specific_value1,
1596                 (void *)&cmd_config_speed_specific_item2,
1597                 (void *)&cmd_config_speed_specific_value2,
1598                 NULL,
1599         },
1600 };
1601
1602 /* *** configure loopback for all ports *** */
1603 struct cmd_config_loopback_all {
1604         cmdline_fixed_string_t port;
1605         cmdline_fixed_string_t keyword;
1606         cmdline_fixed_string_t all;
1607         cmdline_fixed_string_t item;
1608         uint32_t mode;
1609 };
1610
1611 static void
1612 cmd_config_loopback_all_parsed(void *parsed_result,
1613                         __attribute__((unused)) struct cmdline *cl,
1614                         __attribute__((unused)) void *data)
1615 {
1616         struct cmd_config_loopback_all *res = parsed_result;
1617         portid_t pid;
1618
1619         if (!all_ports_stopped()) {
1620                 printf("Please stop all ports first\n");
1621                 return;
1622         }
1623
1624         RTE_ETH_FOREACH_DEV(pid) {
1625                 ports[pid].dev_conf.lpbk_mode = res->mode;
1626         }
1627
1628         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1629 }
1630
1631 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1632         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1633 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1635                                                         "config");
1636 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1638 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1639         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1640                                                         "loopback");
1641 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1642         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1643
1644 cmdline_parse_inst_t cmd_config_loopback_all = {
1645         .f = cmd_config_loopback_all_parsed,
1646         .data = NULL,
1647         .help_str = "port config all loopback <mode>",
1648         .tokens = {
1649                 (void *)&cmd_config_loopback_all_port,
1650                 (void *)&cmd_config_loopback_all_keyword,
1651                 (void *)&cmd_config_loopback_all_all,
1652                 (void *)&cmd_config_loopback_all_item,
1653                 (void *)&cmd_config_loopback_all_mode,
1654                 NULL,
1655         },
1656 };
1657
1658 /* *** configure loopback for specific port *** */
1659 struct cmd_config_loopback_specific {
1660         cmdline_fixed_string_t port;
1661         cmdline_fixed_string_t keyword;
1662         uint16_t port_id;
1663         cmdline_fixed_string_t item;
1664         uint32_t mode;
1665 };
1666
1667 static void
1668 cmd_config_loopback_specific_parsed(void *parsed_result,
1669                                 __attribute__((unused)) struct cmdline *cl,
1670                                 __attribute__((unused)) void *data)
1671 {
1672         struct cmd_config_loopback_specific *res = parsed_result;
1673
1674         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1675                 return;
1676
1677         if (!port_is_stopped(res->port_id)) {
1678                 printf("Please stop port %u first\n", res->port_id);
1679                 return;
1680         }
1681
1682         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1683
1684         cmd_reconfig_device_queue(res->port_id, 1, 1);
1685 }
1686
1687
1688 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1689         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1690                                                                 "port");
1691 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1692         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1693                                                                 "config");
1694 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1695         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1696                                                                 UINT16);
1697 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1698         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1699                                                                 "loopback");
1700 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1701         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1702                               UINT32);
1703
1704 cmdline_parse_inst_t cmd_config_loopback_specific = {
1705         .f = cmd_config_loopback_specific_parsed,
1706         .data = NULL,
1707         .help_str = "port config <port_id> loopback <mode>",
1708         .tokens = {
1709                 (void *)&cmd_config_loopback_specific_port,
1710                 (void *)&cmd_config_loopback_specific_keyword,
1711                 (void *)&cmd_config_loopback_specific_id,
1712                 (void *)&cmd_config_loopback_specific_item,
1713                 (void *)&cmd_config_loopback_specific_mode,
1714                 NULL,
1715         },
1716 };
1717
1718 /* *** configure txq/rxq, txd/rxd *** */
1719 struct cmd_config_rx_tx {
1720         cmdline_fixed_string_t port;
1721         cmdline_fixed_string_t keyword;
1722         cmdline_fixed_string_t all;
1723         cmdline_fixed_string_t name;
1724         uint16_t value;
1725 };
1726
1727 static void
1728 cmd_config_rx_tx_parsed(void *parsed_result,
1729                         __attribute__((unused)) struct cmdline *cl,
1730                         __attribute__((unused)) void *data)
1731 {
1732         struct cmd_config_rx_tx *res = parsed_result;
1733
1734         if (!all_ports_stopped()) {
1735                 printf("Please stop all ports first\n");
1736                 return;
1737         }
1738         if (!strcmp(res->name, "rxq")) {
1739                 if (!res->value && !nb_txq) {
1740                         printf("Warning: Either rx or tx queues should be non zero\n");
1741                         return;
1742                 }
1743                 if (check_nb_rxq(res->value) != 0)
1744                         return;
1745                 nb_rxq = res->value;
1746         }
1747         else if (!strcmp(res->name, "txq")) {
1748                 if (!res->value && !nb_rxq) {
1749                         printf("Warning: Either rx or tx queues should be non zero\n");
1750                         return;
1751                 }
1752                 if (check_nb_txq(res->value) != 0)
1753                         return;
1754                 nb_txq = res->value;
1755         }
1756         else if (!strcmp(res->name, "rxd")) {
1757                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1758                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1759                                         res->value, RTE_TEST_RX_DESC_MAX);
1760                         return;
1761                 }
1762                 nb_rxd = res->value;
1763         } else if (!strcmp(res->name, "txd")) {
1764                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1765                         printf("txd %d invalid - must be > 0 && <= %d\n",
1766                                         res->value, RTE_TEST_TX_DESC_MAX);
1767                         return;
1768                 }
1769                 nb_txd = res->value;
1770         } else {
1771                 printf("Unknown parameter\n");
1772                 return;
1773         }
1774
1775         fwd_config_setup();
1776
1777         init_port_config();
1778
1779         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1780 }
1781
1782 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1783         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1784 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1785         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1786 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1787         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1788 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1789         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1790                                                 "rxq#txq#rxd#txd");
1791 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1792         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1793
1794 cmdline_parse_inst_t cmd_config_rx_tx = {
1795         .f = cmd_config_rx_tx_parsed,
1796         .data = NULL,
1797         .help_str = "port config all rxq|txq|rxd|txd <value>",
1798         .tokens = {
1799                 (void *)&cmd_config_rx_tx_port,
1800                 (void *)&cmd_config_rx_tx_keyword,
1801                 (void *)&cmd_config_rx_tx_all,
1802                 (void *)&cmd_config_rx_tx_name,
1803                 (void *)&cmd_config_rx_tx_value,
1804                 NULL,
1805         },
1806 };
1807
1808 /* *** config max packet length *** */
1809 struct cmd_config_max_pkt_len_result {
1810         cmdline_fixed_string_t port;
1811         cmdline_fixed_string_t keyword;
1812         cmdline_fixed_string_t all;
1813         cmdline_fixed_string_t name;
1814         uint32_t value;
1815 };
1816
1817 static void
1818 cmd_config_max_pkt_len_parsed(void *parsed_result,
1819                                 __attribute__((unused)) struct cmdline *cl,
1820                                 __attribute__((unused)) void *data)
1821 {
1822         struct cmd_config_max_pkt_len_result *res = parsed_result;
1823         portid_t pid;
1824
1825         if (!all_ports_stopped()) {
1826                 printf("Please stop all ports first\n");
1827                 return;
1828         }
1829
1830         RTE_ETH_FOREACH_DEV(pid) {
1831                 struct rte_port *port = &ports[pid];
1832                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1833
1834                 if (!strcmp(res->name, "max-pkt-len")) {
1835                         if (res->value < ETHER_MIN_LEN) {
1836                                 printf("max-pkt-len can not be less than %d\n",
1837                                                 ETHER_MIN_LEN);
1838                                 return;
1839                         }
1840                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1841                                 return;
1842
1843                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1844                         if (res->value > ETHER_MAX_LEN)
1845                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1846                         else
1847                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1848                         port->dev_conf.rxmode.offloads = rx_offloads;
1849                 } else {
1850                         printf("Unknown parameter\n");
1851                         return;
1852                 }
1853         }
1854
1855         init_port_config();
1856
1857         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1858 }
1859
1860 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1861         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1862                                                                 "port");
1863 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1864         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1865                                                                 "config");
1866 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1867         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1868                                                                 "all");
1869 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1870         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1871                                                                 "max-pkt-len");
1872 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1873         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1874                                                                 UINT32);
1875
1876 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1877         .f = cmd_config_max_pkt_len_parsed,
1878         .data = NULL,
1879         .help_str = "port config all max-pkt-len <value>",
1880         .tokens = {
1881                 (void *)&cmd_config_max_pkt_len_port,
1882                 (void *)&cmd_config_max_pkt_len_keyword,
1883                 (void *)&cmd_config_max_pkt_len_all,
1884                 (void *)&cmd_config_max_pkt_len_name,
1885                 (void *)&cmd_config_max_pkt_len_value,
1886                 NULL,
1887         },
1888 };
1889
1890 /* *** configure port MTU *** */
1891 struct cmd_config_mtu_result {
1892         cmdline_fixed_string_t port;
1893         cmdline_fixed_string_t keyword;
1894         cmdline_fixed_string_t mtu;
1895         portid_t port_id;
1896         uint16_t value;
1897 };
1898
1899 static void
1900 cmd_config_mtu_parsed(void *parsed_result,
1901                       __attribute__((unused)) struct cmdline *cl,
1902                       __attribute__((unused)) void *data)
1903 {
1904         struct cmd_config_mtu_result *res = parsed_result;
1905
1906         if (res->value < ETHER_MIN_LEN) {
1907                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1908                 return;
1909         }
1910         port_mtu_set(res->port_id, res->value);
1911 }
1912
1913 cmdline_parse_token_string_t cmd_config_mtu_port =
1914         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1915                                  "port");
1916 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1917         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1918                                  "config");
1919 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1920         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1921                                  "mtu");
1922 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1923         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1924 cmdline_parse_token_num_t cmd_config_mtu_value =
1925         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1926
1927 cmdline_parse_inst_t cmd_config_mtu = {
1928         .f = cmd_config_mtu_parsed,
1929         .data = NULL,
1930         .help_str = "port config mtu <port_id> <value>",
1931         .tokens = {
1932                 (void *)&cmd_config_mtu_port,
1933                 (void *)&cmd_config_mtu_keyword,
1934                 (void *)&cmd_config_mtu_mtu,
1935                 (void *)&cmd_config_mtu_port_id,
1936                 (void *)&cmd_config_mtu_value,
1937                 NULL,
1938         },
1939 };
1940
1941 /* *** configure rx mode *** */
1942 struct cmd_config_rx_mode_flag {
1943         cmdline_fixed_string_t port;
1944         cmdline_fixed_string_t keyword;
1945         cmdline_fixed_string_t all;
1946         cmdline_fixed_string_t name;
1947         cmdline_fixed_string_t value;
1948 };
1949
1950 static void
1951 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1952                                 __attribute__((unused)) struct cmdline *cl,
1953                                 __attribute__((unused)) void *data)
1954 {
1955         struct cmd_config_rx_mode_flag *res = parsed_result;
1956         portid_t pid;
1957
1958         if (!all_ports_stopped()) {
1959                 printf("Please stop all ports first\n");
1960                 return;
1961         }
1962
1963         RTE_ETH_FOREACH_DEV(pid) {
1964                 struct rte_port *port;
1965                 uint64_t rx_offloads;
1966
1967                 port = &ports[pid];
1968                 rx_offloads = port->dev_conf.rxmode.offloads;
1969                 if (!strcmp(res->name, "crc-strip")) {
1970                         if (!strcmp(res->value, "on")) {
1971                                 rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
1972                         } else if (!strcmp(res->value, "off")) {
1973                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
1974                         } else {
1975                                 printf("Unknown parameter\n");
1976                                 return;
1977                         }
1978                 } else if (!strcmp(res->name, "scatter")) {
1979                         if (!strcmp(res->value, "on")) {
1980                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1981                         } else if (!strcmp(res->value, "off")) {
1982                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1983                         } else {
1984                                 printf("Unknown parameter\n");
1985                                 return;
1986                         }
1987                 } else if (!strcmp(res->name, "rx-cksum")) {
1988                         if (!strcmp(res->value, "on"))
1989                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1990                         else if (!strcmp(res->value, "off"))
1991                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1992                         else {
1993                                 printf("Unknown parameter\n");
1994                                 return;
1995                         }
1996                 } else if (!strcmp(res->name, "rx-timestamp")) {
1997                         if (!strcmp(res->value, "on"))
1998                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1999                         else if (!strcmp(res->value, "off"))
2000                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
2001                         else {
2002                                 printf("Unknown parameter\n");
2003                                 return;
2004                         }
2005                 } else if (!strcmp(res->name, "hw-vlan")) {
2006                         if (!strcmp(res->value, "on")) {
2007                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
2008                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2009                         } else if (!strcmp(res->value, "off")) {
2010                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
2011                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2012                         } else {
2013                                 printf("Unknown parameter\n");
2014                                 return;
2015                         }
2016                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
2017                         if (!strcmp(res->value, "on"))
2018                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2019                         else if (!strcmp(res->value, "off"))
2020                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2021                         else {
2022                                 printf("Unknown parameter\n");
2023                                 return;
2024                         }
2025                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
2026                         if (!strcmp(res->value, "on"))
2027                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2028                         else if (!strcmp(res->value, "off"))
2029                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2030                         else {
2031                                 printf("Unknown parameter\n");
2032                                 return;
2033                         }
2034                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
2035                         if (!strcmp(res->value, "on"))
2036                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2037                         else if (!strcmp(res->value, "off"))
2038                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2039                         else {
2040                                 printf("Unknown parameter\n");
2041                                 return;
2042                         }
2043                 } else if (!strcmp(res->name, "drop-en")) {
2044                         if (!strcmp(res->value, "on"))
2045                                 rx_drop_en = 1;
2046                         else if (!strcmp(res->value, "off"))
2047                                 rx_drop_en = 0;
2048                         else {
2049                                 printf("Unknown parameter\n");
2050                                 return;
2051                         }
2052                 } else {
2053                         printf("Unknown parameter\n");
2054                         return;
2055                 }
2056                 port->dev_conf.rxmode.offloads = rx_offloads;
2057         }
2058
2059         init_port_config();
2060
2061         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2062 }
2063
2064 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2065         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2066 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2067         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2068                                                                 "config");
2069 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2070         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2071 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2072         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2073                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2074                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2075 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2076         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2077                                                         "on#off");
2078
2079 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2080         .f = cmd_config_rx_mode_flag_parsed,
2081         .data = NULL,
2082         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2083                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2084         .tokens = {
2085                 (void *)&cmd_config_rx_mode_flag_port,
2086                 (void *)&cmd_config_rx_mode_flag_keyword,
2087                 (void *)&cmd_config_rx_mode_flag_all,
2088                 (void *)&cmd_config_rx_mode_flag_name,
2089                 (void *)&cmd_config_rx_mode_flag_value,
2090                 NULL,
2091         },
2092 };
2093
2094 /* *** configure rss *** */
2095 struct cmd_config_rss {
2096         cmdline_fixed_string_t port;
2097         cmdline_fixed_string_t keyword;
2098         cmdline_fixed_string_t all;
2099         cmdline_fixed_string_t name;
2100         cmdline_fixed_string_t value;
2101 };
2102
2103 static void
2104 cmd_config_rss_parsed(void *parsed_result,
2105                         __attribute__((unused)) struct cmdline *cl,
2106                         __attribute__((unused)) void *data)
2107 {
2108         struct cmd_config_rss *res = parsed_result;
2109         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2110         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2111         int use_default = 0;
2112         int all_updated = 1;
2113         int diag;
2114         uint16_t i;
2115
2116         if (!strcmp(res->value, "all"))
2117                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2118                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2119                                         ETH_RSS_L2_PAYLOAD;
2120         else if (!strcmp(res->value, "ip"))
2121                 rss_conf.rss_hf = ETH_RSS_IP;
2122         else if (!strcmp(res->value, "udp"))
2123                 rss_conf.rss_hf = ETH_RSS_UDP;
2124         else if (!strcmp(res->value, "tcp"))
2125                 rss_conf.rss_hf = ETH_RSS_TCP;
2126         else if (!strcmp(res->value, "sctp"))
2127                 rss_conf.rss_hf = ETH_RSS_SCTP;
2128         else if (!strcmp(res->value, "ether"))
2129                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2130         else if (!strcmp(res->value, "port"))
2131                 rss_conf.rss_hf = ETH_RSS_PORT;
2132         else if (!strcmp(res->value, "vxlan"))
2133                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2134         else if (!strcmp(res->value, "geneve"))
2135                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2136         else if (!strcmp(res->value, "nvgre"))
2137                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2138         else if (!strcmp(res->value, "none"))
2139                 rss_conf.rss_hf = 0;
2140         else if (!strcmp(res->value, "default"))
2141                 use_default = 1;
2142         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2143                                                 atoi(res->value) < 64)
2144                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2145         else {
2146                 printf("Unknown parameter\n");
2147                 return;
2148         }
2149         rss_conf.rss_key = NULL;
2150         /* Update global configuration for RSS types. */
2151         RTE_ETH_FOREACH_DEV(i) {
2152                 struct rte_eth_rss_conf local_rss_conf;
2153
2154                 rte_eth_dev_info_get(i, &dev_info);
2155                 if (use_default)
2156                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2157
2158                 local_rss_conf = rss_conf;
2159                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2160                         dev_info.flow_type_rss_offloads;
2161                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2162                         printf("Port %u modified RSS hash function based on hardware support,"
2163                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2164                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2165                 }
2166                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2167                 if (diag < 0) {
2168                         all_updated = 0;
2169                         printf("Configuration of RSS hash at ethernet port %d "
2170                                 "failed with error (%d): %s.\n",
2171                                 i, -diag, strerror(-diag));
2172                 }
2173         }
2174         if (all_updated && !use_default)
2175                 rss_hf = rss_conf.rss_hf;
2176 }
2177
2178 cmdline_parse_token_string_t cmd_config_rss_port =
2179         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2180 cmdline_parse_token_string_t cmd_config_rss_keyword =
2181         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2182 cmdline_parse_token_string_t cmd_config_rss_all =
2183         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2184 cmdline_parse_token_string_t cmd_config_rss_name =
2185         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2186 cmdline_parse_token_string_t cmd_config_rss_value =
2187         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2188
2189 cmdline_parse_inst_t cmd_config_rss = {
2190         .f = cmd_config_rss_parsed,
2191         .data = NULL,
2192         .help_str = "port config all rss "
2193                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2194         .tokens = {
2195                 (void *)&cmd_config_rss_port,
2196                 (void *)&cmd_config_rss_keyword,
2197                 (void *)&cmd_config_rss_all,
2198                 (void *)&cmd_config_rss_name,
2199                 (void *)&cmd_config_rss_value,
2200                 NULL,
2201         },
2202 };
2203
2204 /* *** configure rss hash key *** */
2205 struct cmd_config_rss_hash_key {
2206         cmdline_fixed_string_t port;
2207         cmdline_fixed_string_t config;
2208         portid_t port_id;
2209         cmdline_fixed_string_t rss_hash_key;
2210         cmdline_fixed_string_t rss_type;
2211         cmdline_fixed_string_t key;
2212 };
2213
2214 static uint8_t
2215 hexa_digit_to_value(char hexa_digit)
2216 {
2217         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2218                 return (uint8_t) (hexa_digit - '0');
2219         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2220                 return (uint8_t) ((hexa_digit - 'a') + 10);
2221         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2222                 return (uint8_t) ((hexa_digit - 'A') + 10);
2223         /* Invalid hexa digit */
2224         return 0xFF;
2225 }
2226
2227 static uint8_t
2228 parse_and_check_key_hexa_digit(char *key, int idx)
2229 {
2230         uint8_t hexa_v;
2231
2232         hexa_v = hexa_digit_to_value(key[idx]);
2233         if (hexa_v == 0xFF)
2234                 printf("invalid key: character %c at position %d is not a "
2235                        "valid hexa digit\n", key[idx], idx);
2236         return hexa_v;
2237 }
2238
2239 static void
2240 cmd_config_rss_hash_key_parsed(void *parsed_result,
2241                                __attribute__((unused)) struct cmdline *cl,
2242                                __attribute__((unused)) void *data)
2243 {
2244         struct cmd_config_rss_hash_key *res = parsed_result;
2245         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2246         uint8_t xdgt0;
2247         uint8_t xdgt1;
2248         int i;
2249         struct rte_eth_dev_info dev_info;
2250         uint8_t hash_key_size;
2251         uint32_t key_len;
2252
2253         memset(&dev_info, 0, sizeof(dev_info));
2254         rte_eth_dev_info_get(res->port_id, &dev_info);
2255         if (dev_info.hash_key_size > 0 &&
2256                         dev_info.hash_key_size <= sizeof(hash_key))
2257                 hash_key_size = dev_info.hash_key_size;
2258         else {
2259                 printf("dev_info did not provide a valid hash key size\n");
2260                 return;
2261         }
2262         /* Check the length of the RSS hash key */
2263         key_len = strlen(res->key);
2264         if (key_len != (hash_key_size * 2)) {
2265                 printf("key length: %d invalid - key must be a string of %d"
2266                            " hexa-decimal numbers\n",
2267                            (int) key_len, hash_key_size * 2);
2268                 return;
2269         }
2270         /* Translate RSS hash key into binary representation */
2271         for (i = 0; i < hash_key_size; i++) {
2272                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2273                 if (xdgt0 == 0xFF)
2274                         return;
2275                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2276                 if (xdgt1 == 0xFF)
2277                         return;
2278                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2279         }
2280         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2281                         hash_key_size);
2282 }
2283
2284 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2285         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2286 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2287         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2288                                  "config");
2289 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2290         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2291 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2292         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2293                                  rss_hash_key, "rss-hash-key");
2294 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2295         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2296                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2297                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2298                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2299                                  "ipv6-tcp-ex#ipv6-udp-ex");
2300 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2301         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2302
2303 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2304         .f = cmd_config_rss_hash_key_parsed,
2305         .data = NULL,
2306         .help_str = "port config <port_id> rss-hash-key "
2307                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2308                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2309                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2310                 "<string of hex digits (variable length, NIC dependent)>",
2311         .tokens = {
2312                 (void *)&cmd_config_rss_hash_key_port,
2313                 (void *)&cmd_config_rss_hash_key_config,
2314                 (void *)&cmd_config_rss_hash_key_port_id,
2315                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2316                 (void *)&cmd_config_rss_hash_key_rss_type,
2317                 (void *)&cmd_config_rss_hash_key_value,
2318                 NULL,
2319         },
2320 };
2321
2322 /* *** configure port rxq/txq ring size *** */
2323 struct cmd_config_rxtx_ring_size {
2324         cmdline_fixed_string_t port;
2325         cmdline_fixed_string_t config;
2326         portid_t portid;
2327         cmdline_fixed_string_t rxtxq;
2328         uint16_t qid;
2329         cmdline_fixed_string_t rsize;
2330         uint16_t size;
2331 };
2332
2333 static void
2334 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2335                                  __attribute__((unused)) struct cmdline *cl,
2336                                  __attribute__((unused)) void *data)
2337 {
2338         struct cmd_config_rxtx_ring_size *res = parsed_result;
2339         struct rte_port *port;
2340         uint8_t isrx;
2341
2342         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2343                 return;
2344
2345         if (res->portid == (portid_t)RTE_PORT_ALL) {
2346                 printf("Invalid port id\n");
2347                 return;
2348         }
2349
2350         port = &ports[res->portid];
2351
2352         if (!strcmp(res->rxtxq, "rxq"))
2353                 isrx = 1;
2354         else if (!strcmp(res->rxtxq, "txq"))
2355                 isrx = 0;
2356         else {
2357                 printf("Unknown parameter\n");
2358                 return;
2359         }
2360
2361         if (isrx && rx_queue_id_is_invalid(res->qid))
2362                 return;
2363         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2364                 return;
2365
2366         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2367                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2368                        rx_free_thresh);
2369                 return;
2370         }
2371
2372         if (isrx)
2373                 port->nb_rx_desc[res->qid] = res->size;
2374         else
2375                 port->nb_tx_desc[res->qid] = res->size;
2376
2377         cmd_reconfig_device_queue(res->portid, 0, 1);
2378 }
2379
2380 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2381         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2382                                  port, "port");
2383 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2384         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2385                                  config, "config");
2386 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2387         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2388                                  portid, UINT16);
2389 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2390         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2391                                  rxtxq, "rxq#txq");
2392 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2393         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2394                               qid, UINT16);
2395 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2396         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2397                                  rsize, "ring_size");
2398 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2399         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2400                               size, UINT16);
2401
2402 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2403         .f = cmd_config_rxtx_ring_size_parsed,
2404         .data = NULL,
2405         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2406         .tokens = {
2407                 (void *)&cmd_config_rxtx_ring_size_port,
2408                 (void *)&cmd_config_rxtx_ring_size_config,
2409                 (void *)&cmd_config_rxtx_ring_size_portid,
2410                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2411                 (void *)&cmd_config_rxtx_ring_size_qid,
2412                 (void *)&cmd_config_rxtx_ring_size_rsize,
2413                 (void *)&cmd_config_rxtx_ring_size_size,
2414                 NULL,
2415         },
2416 };
2417
2418 /* *** configure port rxq/txq start/stop *** */
2419 struct cmd_config_rxtx_queue {
2420         cmdline_fixed_string_t port;
2421         portid_t portid;
2422         cmdline_fixed_string_t rxtxq;
2423         uint16_t qid;
2424         cmdline_fixed_string_t opname;
2425 };
2426
2427 static void
2428 cmd_config_rxtx_queue_parsed(void *parsed_result,
2429                         __attribute__((unused)) struct cmdline *cl,
2430                         __attribute__((unused)) void *data)
2431 {
2432         struct cmd_config_rxtx_queue *res = parsed_result;
2433         uint8_t isrx;
2434         uint8_t isstart;
2435         int ret = 0;
2436
2437         if (test_done == 0) {
2438                 printf("Please stop forwarding first\n");
2439                 return;
2440         }
2441
2442         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2443                 return;
2444
2445         if (port_is_started(res->portid) != 1) {
2446                 printf("Please start port %u first\n", res->portid);
2447                 return;
2448         }
2449
2450         if (!strcmp(res->rxtxq, "rxq"))
2451                 isrx = 1;
2452         else if (!strcmp(res->rxtxq, "txq"))
2453                 isrx = 0;
2454         else {
2455                 printf("Unknown parameter\n");
2456                 return;
2457         }
2458
2459         if (isrx && rx_queue_id_is_invalid(res->qid))
2460                 return;
2461         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2462                 return;
2463
2464         if (!strcmp(res->opname, "start"))
2465                 isstart = 1;
2466         else if (!strcmp(res->opname, "stop"))
2467                 isstart = 0;
2468         else {
2469                 printf("Unknown parameter\n");
2470                 return;
2471         }
2472
2473         if (isstart && isrx)
2474                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2475         else if (!isstart && isrx)
2476                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2477         else if (isstart && !isrx)
2478                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2479         else
2480                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2481
2482         if (ret == -ENOTSUP)
2483                 printf("Function not supported in PMD driver\n");
2484 }
2485
2486 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2487         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2488 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2489         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2490 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2491         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2492 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2493         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2494 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2495         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2496                                                 "start#stop");
2497
2498 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2499         .f = cmd_config_rxtx_queue_parsed,
2500         .data = NULL,
2501         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2502         .tokens = {
2503                 (void *)&cmd_config_rxtx_queue_port,
2504                 (void *)&cmd_config_rxtx_queue_portid,
2505                 (void *)&cmd_config_rxtx_queue_rxtxq,
2506                 (void *)&cmd_config_rxtx_queue_qid,
2507                 (void *)&cmd_config_rxtx_queue_opname,
2508                 NULL,
2509         },
2510 };
2511
2512 /* *** configure port rxq/txq deferred start on/off *** */
2513 struct cmd_config_deferred_start_rxtx_queue {
2514         cmdline_fixed_string_t port;
2515         portid_t port_id;
2516         cmdline_fixed_string_t rxtxq;
2517         uint16_t qid;
2518         cmdline_fixed_string_t opname;
2519         cmdline_fixed_string_t state;
2520 };
2521
2522 static void
2523 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2524                         __attribute__((unused)) struct cmdline *cl,
2525                         __attribute__((unused)) void *data)
2526 {
2527         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2528         struct rte_port *port;
2529         uint8_t isrx;
2530         uint8_t ison;
2531         uint8_t needreconfig = 0;
2532
2533         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2534                 return;
2535
2536         if (port_is_started(res->port_id) != 0) {
2537                 printf("Please stop port %u first\n", res->port_id);
2538                 return;
2539         }
2540
2541         port = &ports[res->port_id];
2542
2543         isrx = !strcmp(res->rxtxq, "rxq");
2544
2545         if (isrx && rx_queue_id_is_invalid(res->qid))
2546                 return;
2547         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2548                 return;
2549
2550         ison = !strcmp(res->state, "on");
2551
2552         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2553                 port->rx_conf[res->qid].rx_deferred_start = ison;
2554                 needreconfig = 1;
2555         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2556                 port->tx_conf[res->qid].tx_deferred_start = ison;
2557                 needreconfig = 1;
2558         }
2559
2560         if (needreconfig)
2561                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2562 }
2563
2564 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2565         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2566                                                 port, "port");
2567 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2568         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2569                                                 port_id, UINT16);
2570 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2571         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2572                                                 rxtxq, "rxq#txq");
2573 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2574         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2575                                                 qid, UINT16);
2576 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2577         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2578                                                 opname, "deferred_start");
2579 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2580         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2581                                                 state, "on#off");
2582
2583 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2584         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2585         .data = NULL,
2586         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2587         .tokens = {
2588                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2589                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2590                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2591                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2592                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2593                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2594                 NULL,
2595         },
2596 };
2597
2598 /* *** configure port rxq/txq setup *** */
2599 struct cmd_setup_rxtx_queue {
2600         cmdline_fixed_string_t port;
2601         portid_t portid;
2602         cmdline_fixed_string_t rxtxq;
2603         uint16_t qid;
2604         cmdline_fixed_string_t setup;
2605 };
2606
2607 /* Common CLI fields for queue setup */
2608 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2609         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2610 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2611         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2612 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2613         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2614 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2615         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2616 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2617         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2618
2619 static void
2620 cmd_setup_rxtx_queue_parsed(
2621         void *parsed_result,
2622         __attribute__((unused)) struct cmdline *cl,
2623         __attribute__((unused)) void *data)
2624 {
2625         struct cmd_setup_rxtx_queue *res = parsed_result;
2626         struct rte_port *port;
2627         struct rte_mempool *mp;
2628         unsigned int socket_id;
2629         uint8_t isrx = 0;
2630         int ret;
2631
2632         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2633                 return;
2634
2635         if (res->portid == (portid_t)RTE_PORT_ALL) {
2636                 printf("Invalid port id\n");
2637                 return;
2638         }
2639
2640         if (!strcmp(res->rxtxq, "rxq"))
2641                 isrx = 1;
2642         else if (!strcmp(res->rxtxq, "txq"))
2643                 isrx = 0;
2644         else {
2645                 printf("Unknown parameter\n");
2646                 return;
2647         }
2648
2649         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2650                 printf("Invalid rx queue\n");
2651                 return;
2652         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2653                 printf("Invalid tx queue\n");
2654                 return;
2655         }
2656
2657         port = &ports[res->portid];
2658         if (isrx) {
2659                 socket_id = rxring_numa[res->portid];
2660                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2661                         socket_id = port->socket_id;
2662
2663                 mp = mbuf_pool_find(socket_id);
2664                 if (mp == NULL) {
2665                         printf("Failed to setup RX queue: "
2666                                 "No mempool allocation"
2667                                 " on the socket %d\n",
2668                                 rxring_numa[res->portid]);
2669                         return;
2670                 }
2671                 ret = rte_eth_rx_queue_setup(res->portid,
2672                                              res->qid,
2673                                              port->nb_rx_desc[res->qid],
2674                                              socket_id,
2675                                              &port->rx_conf[res->qid],
2676                                              mp);
2677                 if (ret)
2678                         printf("Failed to setup RX queue\n");
2679         } else {
2680                 socket_id = txring_numa[res->portid];
2681                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2682                         socket_id = port->socket_id;
2683
2684                 ret = rte_eth_tx_queue_setup(res->portid,
2685                                              res->qid,
2686                                              port->nb_tx_desc[res->qid],
2687                                              socket_id,
2688                                              &port->tx_conf[res->qid]);
2689                 if (ret)
2690                         printf("Failed to setup TX queue\n");
2691         }
2692 }
2693
2694 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2695         .f = cmd_setup_rxtx_queue_parsed,
2696         .data = NULL,
2697         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2698         .tokens = {
2699                 (void *)&cmd_setup_rxtx_queue_port,
2700                 (void *)&cmd_setup_rxtx_queue_portid,
2701                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2702                 (void *)&cmd_setup_rxtx_queue_qid,
2703                 (void *)&cmd_setup_rxtx_queue_setup,
2704                 NULL,
2705         },
2706 };
2707
2708
2709 /* *** Configure RSS RETA *** */
2710 struct cmd_config_rss_reta {
2711         cmdline_fixed_string_t port;
2712         cmdline_fixed_string_t keyword;
2713         portid_t port_id;
2714         cmdline_fixed_string_t name;
2715         cmdline_fixed_string_t list_name;
2716         cmdline_fixed_string_t list_of_items;
2717 };
2718
2719 static int
2720 parse_reta_config(const char *str,
2721                   struct rte_eth_rss_reta_entry64 *reta_conf,
2722                   uint16_t nb_entries)
2723 {
2724         int i;
2725         unsigned size;
2726         uint16_t hash_index, idx, shift;
2727         uint16_t nb_queue;
2728         char s[256];
2729         const char *p, *p0 = str;
2730         char *end;
2731         enum fieldnames {
2732                 FLD_HASH_INDEX = 0,
2733                 FLD_QUEUE,
2734                 _NUM_FLD
2735         };
2736         unsigned long int_fld[_NUM_FLD];
2737         char *str_fld[_NUM_FLD];
2738
2739         while ((p = strchr(p0,'(')) != NULL) {
2740                 ++p;
2741                 if((p0 = strchr(p,')')) == NULL)
2742                         return -1;
2743
2744                 size = p0 - p;
2745                 if(size >= sizeof(s))
2746                         return -1;
2747
2748                 snprintf(s, sizeof(s), "%.*s", size, p);
2749                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2750                         return -1;
2751                 for (i = 0; i < _NUM_FLD; i++) {
2752                         errno = 0;
2753                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2754                         if (errno != 0 || end == str_fld[i] ||
2755                                         int_fld[i] > 65535)
2756                                 return -1;
2757                 }
2758
2759                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2760                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2761
2762                 if (hash_index >= nb_entries) {
2763                         printf("Invalid RETA hash index=%d\n", hash_index);
2764                         return -1;
2765                 }
2766
2767                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2768                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2769                 reta_conf[idx].mask |= (1ULL << shift);
2770                 reta_conf[idx].reta[shift] = nb_queue;
2771         }
2772
2773         return 0;
2774 }
2775
2776 static void
2777 cmd_set_rss_reta_parsed(void *parsed_result,
2778                         __attribute__((unused)) struct cmdline *cl,
2779                         __attribute__((unused)) void *data)
2780 {
2781         int ret;
2782         struct rte_eth_dev_info dev_info;
2783         struct rte_eth_rss_reta_entry64 reta_conf[8];
2784         struct cmd_config_rss_reta *res = parsed_result;
2785
2786         memset(&dev_info, 0, sizeof(dev_info));
2787         rte_eth_dev_info_get(res->port_id, &dev_info);
2788         if (dev_info.reta_size == 0) {
2789                 printf("Redirection table size is 0 which is "
2790                                         "invalid for RSS\n");
2791                 return;
2792         } else
2793                 printf("The reta size of port %d is %u\n",
2794                         res->port_id, dev_info.reta_size);
2795         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2796                 printf("Currently do not support more than %u entries of "
2797                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2798                 return;
2799         }
2800
2801         memset(reta_conf, 0, sizeof(reta_conf));
2802         if (!strcmp(res->list_name, "reta")) {
2803                 if (parse_reta_config(res->list_of_items, reta_conf,
2804                                                 dev_info.reta_size)) {
2805                         printf("Invalid RSS Redirection Table "
2806                                         "config entered\n");
2807                         return;
2808                 }
2809                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2810                                 reta_conf, dev_info.reta_size);
2811                 if (ret != 0)
2812                         printf("Bad redirection table parameter, "
2813                                         "return code = %d \n", ret);
2814         }
2815 }
2816
2817 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2818         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2819 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2820         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2821 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2822         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2823 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2824         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2825 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2826         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2827 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2828         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2829                                  NULL);
2830 cmdline_parse_inst_t cmd_config_rss_reta = {
2831         .f = cmd_set_rss_reta_parsed,
2832         .data = NULL,
2833         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2834         .tokens = {
2835                 (void *)&cmd_config_rss_reta_port,
2836                 (void *)&cmd_config_rss_reta_keyword,
2837                 (void *)&cmd_config_rss_reta_port_id,
2838                 (void *)&cmd_config_rss_reta_name,
2839                 (void *)&cmd_config_rss_reta_list_name,
2840                 (void *)&cmd_config_rss_reta_list_of_items,
2841                 NULL,
2842         },
2843 };
2844
2845 /* *** SHOW PORT RETA INFO *** */
2846 struct cmd_showport_reta {
2847         cmdline_fixed_string_t show;
2848         cmdline_fixed_string_t port;
2849         portid_t port_id;
2850         cmdline_fixed_string_t rss;
2851         cmdline_fixed_string_t reta;
2852         uint16_t size;
2853         cmdline_fixed_string_t list_of_items;
2854 };
2855
2856 static int
2857 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2858                            uint16_t nb_entries,
2859                            char *str)
2860 {
2861         uint32_t size;
2862         const char *p, *p0 = str;
2863         char s[256];
2864         char *end;
2865         char *str_fld[8];
2866         uint16_t i;
2867         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2868                         RTE_RETA_GROUP_SIZE;
2869         int ret;
2870
2871         p = strchr(p0, '(');
2872         if (p == NULL)
2873                 return -1;
2874         p++;
2875         p0 = strchr(p, ')');
2876         if (p0 == NULL)
2877                 return -1;
2878         size = p0 - p;
2879         if (size >= sizeof(s)) {
2880                 printf("The string size exceeds the internal buffer size\n");
2881                 return -1;
2882         }
2883         snprintf(s, sizeof(s), "%.*s", size, p);
2884         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2885         if (ret <= 0 || ret != num) {
2886                 printf("The bits of masks do not match the number of "
2887                                         "reta entries: %u\n", num);
2888                 return -1;
2889         }
2890         for (i = 0; i < ret; i++)
2891                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2892
2893         return 0;
2894 }
2895
2896 static void
2897 cmd_showport_reta_parsed(void *parsed_result,
2898                          __attribute__((unused)) struct cmdline *cl,
2899                          __attribute__((unused)) void *data)
2900 {
2901         struct cmd_showport_reta *res = parsed_result;
2902         struct rte_eth_rss_reta_entry64 reta_conf[8];
2903         struct rte_eth_dev_info dev_info;
2904         uint16_t max_reta_size;
2905
2906         memset(&dev_info, 0, sizeof(dev_info));
2907         rte_eth_dev_info_get(res->port_id, &dev_info);
2908         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2909         if (res->size == 0 || res->size > max_reta_size) {
2910                 printf("Invalid redirection table size: %u (1-%u)\n",
2911                         res->size, max_reta_size);
2912                 return;
2913         }
2914
2915         memset(reta_conf, 0, sizeof(reta_conf));
2916         if (showport_parse_reta_config(reta_conf, res->size,
2917                                 res->list_of_items) < 0) {
2918                 printf("Invalid string: %s for reta masks\n",
2919                                         res->list_of_items);
2920                 return;
2921         }
2922         port_rss_reta_info(res->port_id, reta_conf, res->size);
2923 }
2924
2925 cmdline_parse_token_string_t cmd_showport_reta_show =
2926         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2927 cmdline_parse_token_string_t cmd_showport_reta_port =
2928         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2929 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2930         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2931 cmdline_parse_token_string_t cmd_showport_reta_rss =
2932         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2933 cmdline_parse_token_string_t cmd_showport_reta_reta =
2934         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2935 cmdline_parse_token_num_t cmd_showport_reta_size =
2936         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2937 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2938         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2939                                         list_of_items, NULL);
2940
2941 cmdline_parse_inst_t cmd_showport_reta = {
2942         .f = cmd_showport_reta_parsed,
2943         .data = NULL,
2944         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2945         .tokens = {
2946                 (void *)&cmd_showport_reta_show,
2947                 (void *)&cmd_showport_reta_port,
2948                 (void *)&cmd_showport_reta_port_id,
2949                 (void *)&cmd_showport_reta_rss,
2950                 (void *)&cmd_showport_reta_reta,
2951                 (void *)&cmd_showport_reta_size,
2952                 (void *)&cmd_showport_reta_list_of_items,
2953                 NULL,
2954         },
2955 };
2956
2957 /* *** Show RSS hash configuration *** */
2958 struct cmd_showport_rss_hash {
2959         cmdline_fixed_string_t show;
2960         cmdline_fixed_string_t port;
2961         portid_t port_id;
2962         cmdline_fixed_string_t rss_hash;
2963         cmdline_fixed_string_t rss_type;
2964         cmdline_fixed_string_t key; /* optional argument */
2965 };
2966
2967 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2968                                 __attribute__((unused)) struct cmdline *cl,
2969                                 void *show_rss_key)
2970 {
2971         struct cmd_showport_rss_hash *res = parsed_result;
2972
2973         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
2974 }
2975
2976 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2977         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2978 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2979         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2980 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2981         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2982 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2983         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2984                                  "rss-hash");
2985 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2986         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2987
2988 cmdline_parse_inst_t cmd_showport_rss_hash = {
2989         .f = cmd_showport_rss_hash_parsed,
2990         .data = NULL,
2991         .help_str = "show port <port_id> rss-hash",
2992         .tokens = {
2993                 (void *)&cmd_showport_rss_hash_show,
2994                 (void *)&cmd_showport_rss_hash_port,
2995                 (void *)&cmd_showport_rss_hash_port_id,
2996                 (void *)&cmd_showport_rss_hash_rss_hash,
2997                 NULL,
2998         },
2999 };
3000
3001 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3002         .f = cmd_showport_rss_hash_parsed,
3003         .data = (void *)1,
3004         .help_str = "show port <port_id> rss-hash key",
3005         .tokens = {
3006                 (void *)&cmd_showport_rss_hash_show,
3007                 (void *)&cmd_showport_rss_hash_port,
3008                 (void *)&cmd_showport_rss_hash_port_id,
3009                 (void *)&cmd_showport_rss_hash_rss_hash,
3010                 (void *)&cmd_showport_rss_hash_rss_key,
3011                 NULL,
3012         },
3013 };
3014
3015 /* *** Configure DCB *** */
3016 struct cmd_config_dcb {
3017         cmdline_fixed_string_t port;
3018         cmdline_fixed_string_t config;
3019         portid_t port_id;
3020         cmdline_fixed_string_t dcb;
3021         cmdline_fixed_string_t vt;
3022         cmdline_fixed_string_t vt_en;
3023         uint8_t num_tcs;
3024         cmdline_fixed_string_t pfc;
3025         cmdline_fixed_string_t pfc_en;
3026 };
3027
3028 static void
3029 cmd_config_dcb_parsed(void *parsed_result,
3030                         __attribute__((unused)) struct cmdline *cl,
3031                         __attribute__((unused)) void *data)
3032 {
3033         struct cmd_config_dcb *res = parsed_result;
3034         portid_t port_id = res->port_id;
3035         struct rte_port *port;
3036         uint8_t pfc_en;
3037         int ret;
3038
3039         port = &ports[port_id];
3040         /** Check if the port is not started **/
3041         if (port->port_status != RTE_PORT_STOPPED) {
3042                 printf("Please stop port %d first\n", port_id);
3043                 return;
3044         }
3045
3046         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3047                 printf("The invalid number of traffic class,"
3048                         " only 4 or 8 allowed.\n");
3049                 return;
3050         }
3051
3052         if (nb_fwd_lcores < res->num_tcs) {
3053                 printf("nb_cores shouldn't be less than number of TCs.\n");
3054                 return;
3055         }
3056         if (!strncmp(res->pfc_en, "on", 2))
3057                 pfc_en = 1;
3058         else
3059                 pfc_en = 0;
3060
3061         /* DCB in VT mode */
3062         if (!strncmp(res->vt_en, "on", 2))
3063                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3064                                 (enum rte_eth_nb_tcs)res->num_tcs,
3065                                 pfc_en);
3066         else
3067                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3068                                 (enum rte_eth_nb_tcs)res->num_tcs,
3069                                 pfc_en);
3070
3071
3072         if (ret != 0) {
3073                 printf("Cannot initialize network ports.\n");
3074                 return;
3075         }
3076
3077         cmd_reconfig_device_queue(port_id, 1, 1);
3078 }
3079
3080 cmdline_parse_token_string_t cmd_config_dcb_port =
3081         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3082 cmdline_parse_token_string_t cmd_config_dcb_config =
3083         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3084 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3085         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3086 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3087         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3088 cmdline_parse_token_string_t cmd_config_dcb_vt =
3089         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3090 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3091         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3092 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3093         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3094 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3095         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3096 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3097         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3098
3099 cmdline_parse_inst_t cmd_config_dcb = {
3100         .f = cmd_config_dcb_parsed,
3101         .data = NULL,
3102         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3103         .tokens = {
3104                 (void *)&cmd_config_dcb_port,
3105                 (void *)&cmd_config_dcb_config,
3106                 (void *)&cmd_config_dcb_port_id,
3107                 (void *)&cmd_config_dcb_dcb,
3108                 (void *)&cmd_config_dcb_vt,
3109                 (void *)&cmd_config_dcb_vt_en,
3110                 (void *)&cmd_config_dcb_num_tcs,
3111                 (void *)&cmd_config_dcb_pfc,
3112                 (void *)&cmd_config_dcb_pfc_en,
3113                 NULL,
3114         },
3115 };
3116
3117 /* *** configure number of packets per burst *** */
3118 struct cmd_config_burst {
3119         cmdline_fixed_string_t port;
3120         cmdline_fixed_string_t keyword;
3121         cmdline_fixed_string_t all;
3122         cmdline_fixed_string_t name;
3123         uint16_t value;
3124 };
3125
3126 static void
3127 cmd_config_burst_parsed(void *parsed_result,
3128                         __attribute__((unused)) struct cmdline *cl,
3129                         __attribute__((unused)) void *data)
3130 {
3131         struct cmd_config_burst *res = parsed_result;
3132         struct rte_eth_dev_info dev_info;
3133         uint16_t rec_nb_pkts;
3134
3135         if (!all_ports_stopped()) {
3136                 printf("Please stop all ports first\n");
3137                 return;
3138         }
3139
3140         if (!strcmp(res->name, "burst")) {
3141                 if (res->value == 0) {
3142                         /* If user gives a value of zero, query the PMD for
3143                          * its recommended Rx burst size. Testpmd uses a single
3144                          * size for all ports, so assume all ports are the same
3145                          * NIC model and use the values from Port 0.
3146                          */
3147                         rte_eth_dev_info_get(0, &dev_info);
3148                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3149
3150                         if (rec_nb_pkts == 0) {
3151                                 printf("PMD does not recommend a burst size.\n"
3152                                         "User provided value must be between"
3153                                         " 1 and %d\n", MAX_PKT_BURST);
3154                                 return;
3155                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3156                                 printf("PMD recommended burst size of %d"
3157                                         " exceeds maximum value of %d\n",
3158                                         rec_nb_pkts, MAX_PKT_BURST);
3159                                 return;
3160                         }
3161                         printf("Using PMD-provided burst value of %d\n",
3162                                 rec_nb_pkts);
3163                         nb_pkt_per_burst = rec_nb_pkts;
3164                 } else if (res->value > MAX_PKT_BURST) {
3165                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3166                         return;
3167                 } else
3168                         nb_pkt_per_burst = res->value;
3169         } else {
3170                 printf("Unknown parameter\n");
3171                 return;
3172         }
3173
3174         init_port_config();
3175
3176         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3177 }
3178
3179 cmdline_parse_token_string_t cmd_config_burst_port =
3180         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3181 cmdline_parse_token_string_t cmd_config_burst_keyword =
3182         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3183 cmdline_parse_token_string_t cmd_config_burst_all =
3184         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3185 cmdline_parse_token_string_t cmd_config_burst_name =
3186         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3187 cmdline_parse_token_num_t cmd_config_burst_value =
3188         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3189
3190 cmdline_parse_inst_t cmd_config_burst = {
3191         .f = cmd_config_burst_parsed,
3192         .data = NULL,
3193         .help_str = "port config all burst <value>",
3194         .tokens = {
3195                 (void *)&cmd_config_burst_port,
3196                 (void *)&cmd_config_burst_keyword,
3197                 (void *)&cmd_config_burst_all,
3198                 (void *)&cmd_config_burst_name,
3199                 (void *)&cmd_config_burst_value,
3200                 NULL,
3201         },
3202 };
3203
3204 /* *** configure rx/tx queues *** */
3205 struct cmd_config_thresh {
3206         cmdline_fixed_string_t port;
3207         cmdline_fixed_string_t keyword;
3208         cmdline_fixed_string_t all;
3209         cmdline_fixed_string_t name;
3210         uint8_t value;
3211 };
3212
3213 static void
3214 cmd_config_thresh_parsed(void *parsed_result,
3215                         __attribute__((unused)) struct cmdline *cl,
3216                         __attribute__((unused)) void *data)
3217 {
3218         struct cmd_config_thresh *res = parsed_result;
3219
3220         if (!all_ports_stopped()) {
3221                 printf("Please stop all ports first\n");
3222                 return;
3223         }
3224
3225         if (!strcmp(res->name, "txpt"))
3226                 tx_pthresh = res->value;
3227         else if(!strcmp(res->name, "txht"))
3228                 tx_hthresh = res->value;
3229         else if(!strcmp(res->name, "txwt"))
3230                 tx_wthresh = res->value;
3231         else if(!strcmp(res->name, "rxpt"))
3232                 rx_pthresh = res->value;
3233         else if(!strcmp(res->name, "rxht"))
3234                 rx_hthresh = res->value;
3235         else if(!strcmp(res->name, "rxwt"))
3236                 rx_wthresh = res->value;
3237         else {
3238                 printf("Unknown parameter\n");
3239                 return;
3240         }
3241
3242         init_port_config();
3243
3244         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3245 }
3246
3247 cmdline_parse_token_string_t cmd_config_thresh_port =
3248         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3249 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3250         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3251 cmdline_parse_token_string_t cmd_config_thresh_all =
3252         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3253 cmdline_parse_token_string_t cmd_config_thresh_name =
3254         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3255                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3256 cmdline_parse_token_num_t cmd_config_thresh_value =
3257         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3258
3259 cmdline_parse_inst_t cmd_config_thresh = {
3260         .f = cmd_config_thresh_parsed,
3261         .data = NULL,
3262         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3263         .tokens = {
3264                 (void *)&cmd_config_thresh_port,
3265                 (void *)&cmd_config_thresh_keyword,
3266                 (void *)&cmd_config_thresh_all,
3267                 (void *)&cmd_config_thresh_name,
3268                 (void *)&cmd_config_thresh_value,
3269                 NULL,
3270         },
3271 };
3272
3273 /* *** configure free/rs threshold *** */
3274 struct cmd_config_threshold {
3275         cmdline_fixed_string_t port;
3276         cmdline_fixed_string_t keyword;
3277         cmdline_fixed_string_t all;
3278         cmdline_fixed_string_t name;
3279         uint16_t value;
3280 };
3281
3282 static void
3283 cmd_config_threshold_parsed(void *parsed_result,
3284                         __attribute__((unused)) struct cmdline *cl,
3285                         __attribute__((unused)) void *data)
3286 {
3287         struct cmd_config_threshold *res = parsed_result;
3288
3289         if (!all_ports_stopped()) {
3290                 printf("Please stop all ports first\n");
3291                 return;
3292         }
3293
3294         if (!strcmp(res->name, "txfreet"))
3295                 tx_free_thresh = res->value;
3296         else if (!strcmp(res->name, "txrst"))
3297                 tx_rs_thresh = res->value;
3298         else if (!strcmp(res->name, "rxfreet"))
3299                 rx_free_thresh = res->value;
3300         else {
3301                 printf("Unknown parameter\n");
3302                 return;
3303         }
3304
3305         init_port_config();
3306
3307         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3308 }
3309
3310 cmdline_parse_token_string_t cmd_config_threshold_port =
3311         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3312 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3313         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3314                                                                 "config");
3315 cmdline_parse_token_string_t cmd_config_threshold_all =
3316         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3317 cmdline_parse_token_string_t cmd_config_threshold_name =
3318         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3319                                                 "txfreet#txrst#rxfreet");
3320 cmdline_parse_token_num_t cmd_config_threshold_value =
3321         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3322
3323 cmdline_parse_inst_t cmd_config_threshold = {
3324         .f = cmd_config_threshold_parsed,
3325         .data = NULL,
3326         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3327         .tokens = {
3328                 (void *)&cmd_config_threshold_port,
3329                 (void *)&cmd_config_threshold_keyword,
3330                 (void *)&cmd_config_threshold_all,
3331                 (void *)&cmd_config_threshold_name,
3332                 (void *)&cmd_config_threshold_value,
3333                 NULL,
3334         },
3335 };
3336
3337 /* *** stop *** */
3338 struct cmd_stop_result {
3339         cmdline_fixed_string_t stop;
3340 };
3341
3342 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3343                             __attribute__((unused)) struct cmdline *cl,
3344                             __attribute__((unused)) void *data)
3345 {
3346         stop_packet_forwarding();
3347 }
3348
3349 cmdline_parse_token_string_t cmd_stop_stop =
3350         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3351
3352 cmdline_parse_inst_t cmd_stop = {
3353         .f = cmd_stop_parsed,
3354         .data = NULL,
3355         .help_str = "stop: Stop packet forwarding",
3356         .tokens = {
3357                 (void *)&cmd_stop_stop,
3358                 NULL,
3359         },
3360 };
3361
3362 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3363
3364 unsigned int
3365 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3366                 unsigned int *parsed_items, int check_unique_values)
3367 {
3368         unsigned int nb_item;
3369         unsigned int value;
3370         unsigned int i;
3371         unsigned int j;
3372         int value_ok;
3373         char c;
3374
3375         /*
3376          * First parse all items in the list and store their value.
3377          */
3378         value = 0;
3379         nb_item = 0;
3380         value_ok = 0;
3381         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3382                 c = str[i];
3383                 if ((c >= '0') && (c <= '9')) {
3384                         value = (unsigned int) (value * 10 + (c - '0'));
3385                         value_ok = 1;
3386                         continue;
3387                 }
3388                 if (c != ',') {
3389                         printf("character %c is not a decimal digit\n", c);
3390                         return 0;
3391                 }
3392                 if (! value_ok) {
3393                         printf("No valid value before comma\n");
3394                         return 0;
3395                 }
3396                 if (nb_item < max_items) {
3397                         parsed_items[nb_item] = value;
3398                         value_ok = 0;
3399                         value = 0;
3400                 }
3401                 nb_item++;
3402         }
3403         if (nb_item >= max_items) {
3404                 printf("Number of %s = %u > %u (maximum items)\n",
3405                        item_name, nb_item + 1, max_items);
3406                 return 0;
3407         }
3408         parsed_items[nb_item++] = value;
3409         if (! check_unique_values)
3410                 return nb_item;
3411
3412         /*
3413          * Then, check that all values in the list are differents.
3414          * No optimization here...
3415          */
3416         for (i = 0; i < nb_item; i++) {
3417                 for (j = i + 1; j < nb_item; j++) {
3418                         if (parsed_items[j] == parsed_items[i]) {
3419                                 printf("duplicated %s %u at index %u and %u\n",
3420                                        item_name, parsed_items[i], i, j);
3421                                 return 0;
3422                         }
3423                 }
3424         }
3425         return nb_item;
3426 }
3427
3428 struct cmd_set_list_result {
3429         cmdline_fixed_string_t cmd_keyword;
3430         cmdline_fixed_string_t list_name;
3431         cmdline_fixed_string_t list_of_items;
3432 };
3433
3434 static void cmd_set_list_parsed(void *parsed_result,
3435                                 __attribute__((unused)) struct cmdline *cl,
3436                                 __attribute__((unused)) void *data)
3437 {
3438         struct cmd_set_list_result *res;
3439         union {
3440                 unsigned int lcorelist[RTE_MAX_LCORE];
3441                 unsigned int portlist[RTE_MAX_ETHPORTS];
3442         } parsed_items;
3443         unsigned int nb_item;
3444
3445         if (test_done == 0) {
3446                 printf("Please stop forwarding first\n");
3447                 return;
3448         }
3449
3450         res = parsed_result;
3451         if (!strcmp(res->list_name, "corelist")) {
3452                 nb_item = parse_item_list(res->list_of_items, "core",
3453                                           RTE_MAX_LCORE,
3454                                           parsed_items.lcorelist, 1);
3455                 if (nb_item > 0) {
3456                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3457                         fwd_config_setup();
3458                 }
3459                 return;
3460         }
3461         if (!strcmp(res->list_name, "portlist")) {
3462                 nb_item = parse_item_list(res->list_of_items, "port",
3463                                           RTE_MAX_ETHPORTS,
3464                                           parsed_items.portlist, 1);
3465                 if (nb_item > 0) {
3466                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3467                         fwd_config_setup();
3468                 }
3469         }
3470 }
3471
3472 cmdline_parse_token_string_t cmd_set_list_keyword =
3473         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3474                                  "set");
3475 cmdline_parse_token_string_t cmd_set_list_name =
3476         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3477                                  "corelist#portlist");
3478 cmdline_parse_token_string_t cmd_set_list_of_items =
3479         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3480                                  NULL);
3481
3482 cmdline_parse_inst_t cmd_set_fwd_list = {
3483         .f = cmd_set_list_parsed,
3484         .data = NULL,
3485         .help_str = "set corelist|portlist <list0[,list1]*>",
3486         .tokens = {
3487                 (void *)&cmd_set_list_keyword,
3488                 (void *)&cmd_set_list_name,
3489                 (void *)&cmd_set_list_of_items,
3490                 NULL,
3491         },
3492 };
3493
3494 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3495
3496 struct cmd_setmask_result {
3497         cmdline_fixed_string_t set;
3498         cmdline_fixed_string_t mask;
3499         uint64_t hexavalue;
3500 };
3501
3502 static void cmd_set_mask_parsed(void *parsed_result,
3503                                 __attribute__((unused)) struct cmdline *cl,
3504                                 __attribute__((unused)) void *data)
3505 {
3506         struct cmd_setmask_result *res = parsed_result;
3507
3508         if (test_done == 0) {
3509                 printf("Please stop forwarding first\n");
3510                 return;
3511         }
3512         if (!strcmp(res->mask, "coremask")) {
3513                 set_fwd_lcores_mask(res->hexavalue);
3514                 fwd_config_setup();
3515         } else if (!strcmp(res->mask, "portmask")) {
3516                 set_fwd_ports_mask(res->hexavalue);
3517                 fwd_config_setup();
3518         }
3519 }
3520
3521 cmdline_parse_token_string_t cmd_setmask_set =
3522         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3523 cmdline_parse_token_string_t cmd_setmask_mask =
3524         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3525                                  "coremask#portmask");
3526 cmdline_parse_token_num_t cmd_setmask_value =
3527         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3528
3529 cmdline_parse_inst_t cmd_set_fwd_mask = {
3530         .f = cmd_set_mask_parsed,
3531         .data = NULL,
3532         .help_str = "set coremask|portmask <hexadecimal value>",
3533         .tokens = {
3534                 (void *)&cmd_setmask_set,
3535                 (void *)&cmd_setmask_mask,
3536                 (void *)&cmd_setmask_value,
3537                 NULL,
3538         },
3539 };
3540
3541 /*
3542  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3543  */
3544 struct cmd_set_result {
3545         cmdline_fixed_string_t set;
3546         cmdline_fixed_string_t what;
3547         uint16_t value;
3548 };
3549
3550 static void cmd_set_parsed(void *parsed_result,
3551                            __attribute__((unused)) struct cmdline *cl,
3552                            __attribute__((unused)) void *data)
3553 {
3554         struct cmd_set_result *res = parsed_result;
3555         if (!strcmp(res->what, "nbport")) {
3556                 set_fwd_ports_number(res->value);
3557                 fwd_config_setup();
3558         } else if (!strcmp(res->what, "nbcore")) {
3559                 set_fwd_lcores_number(res->value);
3560                 fwd_config_setup();
3561         } else if (!strcmp(res->what, "burst"))
3562                 set_nb_pkt_per_burst(res->value);
3563         else if (!strcmp(res->what, "verbose"))
3564                 set_verbose_level(res->value);
3565 }
3566
3567 cmdline_parse_token_string_t cmd_set_set =
3568         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3569 cmdline_parse_token_string_t cmd_set_what =
3570         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3571                                  "nbport#nbcore#burst#verbose");
3572 cmdline_parse_token_num_t cmd_set_value =
3573         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3574
3575 cmdline_parse_inst_t cmd_set_numbers = {
3576         .f = cmd_set_parsed,
3577         .data = NULL,
3578         .help_str = "set nbport|nbcore|burst|verbose <value>",
3579         .tokens = {
3580                 (void *)&cmd_set_set,
3581                 (void *)&cmd_set_what,
3582                 (void *)&cmd_set_value,
3583                 NULL,
3584         },
3585 };
3586
3587 /* *** SET LOG LEVEL CONFIGURATION *** */
3588
3589 struct cmd_set_log_result {
3590         cmdline_fixed_string_t set;
3591         cmdline_fixed_string_t log;
3592         cmdline_fixed_string_t type;
3593         uint32_t level;
3594 };
3595
3596 static void
3597 cmd_set_log_parsed(void *parsed_result,
3598                    __attribute__((unused)) struct cmdline *cl,
3599                    __attribute__((unused)) void *data)
3600 {
3601         struct cmd_set_log_result *res;
3602         int ret;
3603
3604         res = parsed_result;
3605         if (!strcmp(res->type, "global"))
3606                 rte_log_set_global_level(res->level);
3607         else {
3608                 ret = rte_log_set_level_regexp(res->type, res->level);
3609                 if (ret < 0)
3610                         printf("Unable to set log level\n");
3611         }
3612 }
3613
3614 cmdline_parse_token_string_t cmd_set_log_set =
3615         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3616 cmdline_parse_token_string_t cmd_set_log_log =
3617         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3618 cmdline_parse_token_string_t cmd_set_log_type =
3619         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3620 cmdline_parse_token_num_t cmd_set_log_level =
3621         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3622
3623 cmdline_parse_inst_t cmd_set_log = {
3624         .f = cmd_set_log_parsed,
3625         .data = NULL,
3626         .help_str = "set log global|<type> <level>",
3627         .tokens = {
3628                 (void *)&cmd_set_log_set,
3629                 (void *)&cmd_set_log_log,
3630                 (void *)&cmd_set_log_type,
3631                 (void *)&cmd_set_log_level,
3632                 NULL,
3633         },
3634 };
3635
3636 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3637
3638 struct cmd_set_txpkts_result {
3639         cmdline_fixed_string_t cmd_keyword;
3640         cmdline_fixed_string_t txpkts;
3641         cmdline_fixed_string_t seg_lengths;
3642 };
3643
3644 static void
3645 cmd_set_txpkts_parsed(void *parsed_result,
3646                       __attribute__((unused)) struct cmdline *cl,
3647                       __attribute__((unused)) void *data)
3648 {
3649         struct cmd_set_txpkts_result *res;
3650         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3651         unsigned int nb_segs;
3652
3653         res = parsed_result;
3654         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3655                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3656         if (nb_segs > 0)
3657                 set_tx_pkt_segments(seg_lengths, nb_segs);
3658 }
3659
3660 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3661         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3662                                  cmd_keyword, "set");
3663 cmdline_parse_token_string_t cmd_set_txpkts_name =
3664         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3665                                  txpkts, "txpkts");
3666 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3667         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3668                                  seg_lengths, NULL);
3669
3670 cmdline_parse_inst_t cmd_set_txpkts = {
3671         .f = cmd_set_txpkts_parsed,
3672         .data = NULL,
3673         .help_str = "set txpkts <len0[,len1]*>",
3674         .tokens = {
3675                 (void *)&cmd_set_txpkts_keyword,
3676                 (void *)&cmd_set_txpkts_name,
3677                 (void *)&cmd_set_txpkts_lengths,
3678                 NULL,
3679         },
3680 };
3681
3682 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3683
3684 struct cmd_set_txsplit_result {
3685         cmdline_fixed_string_t cmd_keyword;
3686         cmdline_fixed_string_t txsplit;
3687         cmdline_fixed_string_t mode;
3688 };
3689
3690 static void
3691 cmd_set_txsplit_parsed(void *parsed_result,
3692                       __attribute__((unused)) struct cmdline *cl,
3693                       __attribute__((unused)) void *data)
3694 {
3695         struct cmd_set_txsplit_result *res;
3696
3697         res = parsed_result;
3698         set_tx_pkt_split(res->mode);
3699 }
3700
3701 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3702         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3703                                  cmd_keyword, "set");
3704 cmdline_parse_token_string_t cmd_set_txsplit_name =
3705         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3706                                  txsplit, "txsplit");
3707 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3708         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3709                                  mode, NULL);
3710
3711 cmdline_parse_inst_t cmd_set_txsplit = {
3712         .f = cmd_set_txsplit_parsed,
3713         .data = NULL,
3714         .help_str = "set txsplit on|off|rand",
3715         .tokens = {
3716                 (void *)&cmd_set_txsplit_keyword,
3717                 (void *)&cmd_set_txsplit_name,
3718                 (void *)&cmd_set_txsplit_mode,
3719                 NULL,
3720         },
3721 };
3722
3723 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3724 struct cmd_rx_vlan_filter_all_result {
3725         cmdline_fixed_string_t rx_vlan;
3726         cmdline_fixed_string_t what;
3727         cmdline_fixed_string_t all;
3728         portid_t port_id;
3729 };
3730
3731 static void
3732 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3733                               __attribute__((unused)) struct cmdline *cl,
3734                               __attribute__((unused)) void *data)
3735 {
3736         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3737
3738         if (!strcmp(res->what, "add"))
3739                 rx_vlan_all_filter_set(res->port_id, 1);
3740         else
3741                 rx_vlan_all_filter_set(res->port_id, 0);
3742 }
3743
3744 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3745         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3746                                  rx_vlan, "rx_vlan");
3747 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3748         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3749                                  what, "add#rm");
3750 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3751         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3752                                  all, "all");
3753 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3754         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3755                               port_id, UINT16);
3756
3757 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3758         .f = cmd_rx_vlan_filter_all_parsed,
3759         .data = NULL,
3760         .help_str = "rx_vlan add|rm all <port_id>: "
3761                 "Add/Remove all identifiers to/from the set of VLAN "
3762                 "identifiers filtered by a port",
3763         .tokens = {
3764                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3765                 (void *)&cmd_rx_vlan_filter_all_what,
3766                 (void *)&cmd_rx_vlan_filter_all_all,
3767                 (void *)&cmd_rx_vlan_filter_all_portid,
3768                 NULL,
3769         },
3770 };
3771
3772 /* *** VLAN OFFLOAD SET ON A PORT *** */
3773 struct cmd_vlan_offload_result {
3774         cmdline_fixed_string_t vlan;
3775         cmdline_fixed_string_t set;
3776         cmdline_fixed_string_t vlan_type;
3777         cmdline_fixed_string_t what;
3778         cmdline_fixed_string_t on;
3779         cmdline_fixed_string_t port_id;
3780 };
3781
3782 static void
3783 cmd_vlan_offload_parsed(void *parsed_result,
3784                           __attribute__((unused)) struct cmdline *cl,
3785                           __attribute__((unused)) void *data)
3786 {
3787         int on;
3788         struct cmd_vlan_offload_result *res = parsed_result;
3789         char *str;
3790         int i, len = 0;
3791         portid_t port_id = 0;
3792         unsigned int tmp;
3793
3794         str = res->port_id;
3795         len = strnlen(str, STR_TOKEN_SIZE);
3796         i = 0;
3797         /* Get port_id first */
3798         while(i < len){
3799                 if(str[i] == ',')
3800                         break;
3801
3802                 i++;
3803         }
3804         str[i]='\0';
3805         tmp = strtoul(str, NULL, 0);
3806         /* If port_id greater that what portid_t can represent, return */
3807         if(tmp >= RTE_MAX_ETHPORTS)
3808                 return;
3809         port_id = (portid_t)tmp;
3810
3811         if (!strcmp(res->on, "on"))
3812                 on = 1;
3813         else
3814                 on = 0;
3815
3816         if (!strcmp(res->what, "strip"))
3817                 rx_vlan_strip_set(port_id,  on);
3818         else if(!strcmp(res->what, "stripq")){
3819                 uint16_t queue_id = 0;
3820
3821                 /* No queue_id, return */
3822                 if(i + 1 >= len) {
3823                         printf("must specify (port,queue_id)\n");
3824                         return;
3825                 }
3826                 tmp = strtoul(str + i + 1, NULL, 0);
3827                 /* If queue_id greater that what 16-bits can represent, return */
3828                 if(tmp > 0xffff)
3829                         return;
3830
3831                 queue_id = (uint16_t)tmp;
3832                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3833         }
3834         else if (!strcmp(res->what, "filter"))
3835                 rx_vlan_filter_set(port_id, on);
3836         else
3837                 vlan_extend_set(port_id, on);
3838
3839         return;
3840 }
3841
3842 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3843         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3844                                  vlan, "vlan");
3845 cmdline_parse_token_string_t cmd_vlan_offload_set =
3846         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3847                                  set, "set");
3848 cmdline_parse_token_string_t cmd_vlan_offload_what =
3849         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3850                                  what, "strip#filter#qinq#stripq");
3851 cmdline_parse_token_string_t cmd_vlan_offload_on =
3852         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3853                               on, "on#off");
3854 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3855         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3856                               port_id, NULL);
3857
3858 cmdline_parse_inst_t cmd_vlan_offload = {
3859         .f = cmd_vlan_offload_parsed,
3860         .data = NULL,
3861         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3862                 "<port_id[,queue_id]>: "
3863                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3864         .tokens = {
3865                 (void *)&cmd_vlan_offload_vlan,
3866                 (void *)&cmd_vlan_offload_set,
3867                 (void *)&cmd_vlan_offload_what,
3868                 (void *)&cmd_vlan_offload_on,
3869                 (void *)&cmd_vlan_offload_portid,
3870                 NULL,
3871         },
3872 };
3873
3874 /* *** VLAN TPID SET ON A PORT *** */
3875 struct cmd_vlan_tpid_result {
3876         cmdline_fixed_string_t vlan;
3877         cmdline_fixed_string_t set;
3878         cmdline_fixed_string_t vlan_type;
3879         cmdline_fixed_string_t what;
3880         uint16_t tp_id;
3881         portid_t port_id;
3882 };
3883
3884 static void
3885 cmd_vlan_tpid_parsed(void *parsed_result,
3886                           __attribute__((unused)) struct cmdline *cl,
3887                           __attribute__((unused)) void *data)
3888 {
3889         struct cmd_vlan_tpid_result *res = parsed_result;
3890         enum rte_vlan_type vlan_type;
3891
3892         if (!strcmp(res->vlan_type, "inner"))
3893                 vlan_type = ETH_VLAN_TYPE_INNER;
3894         else if (!strcmp(res->vlan_type, "outer"))
3895                 vlan_type = ETH_VLAN_TYPE_OUTER;
3896         else {
3897                 printf("Unknown vlan type\n");
3898                 return;
3899         }
3900         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3901 }
3902
3903 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3904         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3905                                  vlan, "vlan");
3906 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3907         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3908                                  set, "set");
3909 cmdline_parse_token_string_t cmd_vlan_type =
3910         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3911                                  vlan_type, "inner#outer");
3912 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3913         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3914                                  what, "tpid");
3915 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3916         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3917                               tp_id, UINT16);
3918 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3919         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3920                               port_id, UINT16);
3921
3922 cmdline_parse_inst_t cmd_vlan_tpid = {
3923         .f = cmd_vlan_tpid_parsed,
3924         .data = NULL,
3925         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3926                 "Set the VLAN Ether type",
3927         .tokens = {
3928                 (void *)&cmd_vlan_tpid_vlan,
3929                 (void *)&cmd_vlan_tpid_set,
3930                 (void *)&cmd_vlan_type,
3931                 (void *)&cmd_vlan_tpid_what,
3932                 (void *)&cmd_vlan_tpid_tpid,
3933                 (void *)&cmd_vlan_tpid_portid,
3934                 NULL,
3935         },
3936 };
3937
3938 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3939 struct cmd_rx_vlan_filter_result {
3940         cmdline_fixed_string_t rx_vlan;
3941         cmdline_fixed_string_t what;
3942         uint16_t vlan_id;
3943         portid_t port_id;
3944 };
3945
3946 static void
3947 cmd_rx_vlan_filter_parsed(void *parsed_result,
3948                           __attribute__((unused)) struct cmdline *cl,
3949                           __attribute__((unused)) void *data)
3950 {
3951         struct cmd_rx_vlan_filter_result *res = parsed_result;
3952
3953         if (!strcmp(res->what, "add"))
3954                 rx_vft_set(res->port_id, res->vlan_id, 1);
3955         else
3956                 rx_vft_set(res->port_id, res->vlan_id, 0);
3957 }
3958
3959 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3960         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3961                                  rx_vlan, "rx_vlan");
3962 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3963         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3964                                  what, "add#rm");
3965 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3966         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3967                               vlan_id, UINT16);
3968 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3969         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3970                               port_id, UINT16);
3971
3972 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3973         .f = cmd_rx_vlan_filter_parsed,
3974         .data = NULL,
3975         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3976                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3977                 "identifiers filtered by a port",
3978         .tokens = {
3979                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3980                 (void *)&cmd_rx_vlan_filter_what,
3981                 (void *)&cmd_rx_vlan_filter_vlanid,
3982                 (void *)&cmd_rx_vlan_filter_portid,
3983                 NULL,
3984         },
3985 };
3986
3987 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3988 struct cmd_tx_vlan_set_result {
3989         cmdline_fixed_string_t tx_vlan;
3990         cmdline_fixed_string_t set;
3991         portid_t port_id;
3992         uint16_t vlan_id;
3993 };
3994
3995 static void
3996 cmd_tx_vlan_set_parsed(void *parsed_result,
3997                        __attribute__((unused)) struct cmdline *cl,
3998                        __attribute__((unused)) void *data)
3999 {
4000         struct cmd_tx_vlan_set_result *res = parsed_result;
4001
4002         if (!port_is_stopped(res->port_id)) {
4003                 printf("Please stop port %d first\n", res->port_id);
4004                 return;
4005         }
4006
4007         tx_vlan_set(res->port_id, res->vlan_id);
4008
4009         cmd_reconfig_device_queue(res->port_id, 1, 1);
4010 }
4011
4012 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4013         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4014                                  tx_vlan, "tx_vlan");
4015 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4016         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4017                                  set, "set");
4018 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4019         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4020                               port_id, UINT16);
4021 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4022         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4023                               vlan_id, UINT16);
4024
4025 cmdline_parse_inst_t cmd_tx_vlan_set = {
4026         .f = cmd_tx_vlan_set_parsed,
4027         .data = NULL,
4028         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4029                 "Enable hardware insertion of a single VLAN header "
4030                 "with a given TAG Identifier in packets sent on a port",
4031         .tokens = {
4032                 (void *)&cmd_tx_vlan_set_tx_vlan,
4033                 (void *)&cmd_tx_vlan_set_set,
4034                 (void *)&cmd_tx_vlan_set_portid,
4035                 (void *)&cmd_tx_vlan_set_vlanid,
4036                 NULL,
4037         },
4038 };
4039
4040 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4041 struct cmd_tx_vlan_set_qinq_result {
4042         cmdline_fixed_string_t tx_vlan;
4043         cmdline_fixed_string_t set;
4044         portid_t port_id;
4045         uint16_t vlan_id;
4046         uint16_t vlan_id_outer;
4047 };
4048
4049 static void
4050 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4051                             __attribute__((unused)) struct cmdline *cl,
4052                             __attribute__((unused)) void *data)
4053 {
4054         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4055
4056         if (!port_is_stopped(res->port_id)) {
4057                 printf("Please stop port %d first\n", res->port_id);
4058                 return;
4059         }
4060
4061         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4062
4063         cmd_reconfig_device_queue(res->port_id, 1, 1);
4064 }
4065
4066 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4067         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4068                 tx_vlan, "tx_vlan");
4069 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4070         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4071                 set, "set");
4072 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4073         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4074                 port_id, UINT16);
4075 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4076         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4077                 vlan_id, UINT16);
4078 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4079         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4080                 vlan_id_outer, UINT16);
4081
4082 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4083         .f = cmd_tx_vlan_set_qinq_parsed,
4084         .data = NULL,
4085         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4086                 "Enable hardware insertion of double VLAN header "
4087                 "with given TAG Identifiers in packets sent on a port",
4088         .tokens = {
4089                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4090                 (void *)&cmd_tx_vlan_set_qinq_set,
4091                 (void *)&cmd_tx_vlan_set_qinq_portid,
4092                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4093                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4094                 NULL,
4095         },
4096 };
4097
4098 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4099 struct cmd_tx_vlan_set_pvid_result {
4100         cmdline_fixed_string_t tx_vlan;
4101         cmdline_fixed_string_t set;
4102         cmdline_fixed_string_t pvid;
4103         portid_t port_id;
4104         uint16_t vlan_id;
4105         cmdline_fixed_string_t mode;
4106 };
4107
4108 static void
4109 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4110                             __attribute__((unused)) struct cmdline *cl,
4111                             __attribute__((unused)) void *data)
4112 {
4113         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4114
4115         if (strcmp(res->mode, "on") == 0)
4116                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4117         else
4118                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4119 }
4120
4121 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4122         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4123                                  tx_vlan, "tx_vlan");
4124 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4125         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4126                                  set, "set");
4127 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4128         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4129                                  pvid, "pvid");
4130 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4131         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4132                              port_id, UINT16);
4133 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4134         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4135                               vlan_id, UINT16);
4136 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4137         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4138                                  mode, "on#off");
4139
4140 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4141         .f = cmd_tx_vlan_set_pvid_parsed,
4142         .data = NULL,
4143         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4144         .tokens = {
4145                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4146                 (void *)&cmd_tx_vlan_set_pvid_set,
4147                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4148                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4149                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4150                 (void *)&cmd_tx_vlan_set_pvid_mode,
4151                 NULL,
4152         },
4153 };
4154
4155 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4156 struct cmd_tx_vlan_reset_result {
4157         cmdline_fixed_string_t tx_vlan;
4158         cmdline_fixed_string_t reset;
4159         portid_t port_id;
4160 };
4161
4162 static void
4163 cmd_tx_vlan_reset_parsed(void *parsed_result,
4164                          __attribute__((unused)) struct cmdline *cl,
4165                          __attribute__((unused)) void *data)
4166 {
4167         struct cmd_tx_vlan_reset_result *res = parsed_result;
4168
4169         if (!port_is_stopped(res->port_id)) {
4170                 printf("Please stop port %d first\n", res->port_id);
4171                 return;
4172         }
4173
4174         tx_vlan_reset(res->port_id);
4175
4176         cmd_reconfig_device_queue(res->port_id, 1, 1);
4177 }
4178
4179 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4180         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4181                                  tx_vlan, "tx_vlan");
4182 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4183         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4184                                  reset, "reset");
4185 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4186         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4187                               port_id, UINT16);
4188
4189 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4190         .f = cmd_tx_vlan_reset_parsed,
4191         .data = NULL,
4192         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4193                 "VLAN header in packets sent on a port",
4194         .tokens = {
4195                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4196                 (void *)&cmd_tx_vlan_reset_reset,
4197                 (void *)&cmd_tx_vlan_reset_portid,
4198                 NULL,
4199         },
4200 };
4201
4202
4203 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4204 struct cmd_csum_result {
4205         cmdline_fixed_string_t csum;
4206         cmdline_fixed_string_t mode;
4207         cmdline_fixed_string_t proto;
4208         cmdline_fixed_string_t hwsw;
4209         portid_t port_id;
4210 };
4211
4212 static void
4213 csum_show(int port_id)
4214 {
4215         struct rte_eth_dev_info dev_info;
4216         uint64_t tx_offloads;
4217
4218         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4219         printf("Parse tunnel is %s\n",
4220                 (ports[port_id].parse_tunnel) ? "on" : "off");
4221         printf("IP checksum offload is %s\n",
4222                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4223         printf("UDP checksum offload is %s\n",
4224                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4225         printf("TCP checksum offload is %s\n",
4226                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4227         printf("SCTP checksum offload is %s\n",
4228                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4229         printf("Outer-Ip checksum offload is %s\n",
4230                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4231         printf("Outer-Udp checksum offload is %s\n",
4232                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4233
4234         /* display warnings if configuration is not supported by the NIC */
4235         rte_eth_dev_info_get(port_id, &dev_info);
4236         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4237                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4238                 printf("Warning: hardware IP checksum enabled but not "
4239                         "supported by port %d\n", port_id);
4240         }
4241         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4242                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4243                 printf("Warning: hardware UDP checksum enabled but not "
4244                         "supported by port %d\n", port_id);
4245         }
4246         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4247                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4248                 printf("Warning: hardware TCP checksum enabled but not "
4249                         "supported by port %d\n", port_id);
4250         }
4251         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4252                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4253                 printf("Warning: hardware SCTP checksum enabled but not "
4254                         "supported by port %d\n", port_id);
4255         }
4256         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4257                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4258                 printf("Warning: hardware outer IP checksum enabled but not "
4259                         "supported by port %d\n", port_id);
4260         }
4261         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4262                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4263                         == 0) {
4264                 printf("Warning: hardware outer UDP checksum enabled but not "
4265                         "supported by port %d\n", port_id);
4266         }
4267 }
4268
4269 static void
4270 cmd_csum_parsed(void *parsed_result,
4271                        __attribute__((unused)) struct cmdline *cl,
4272                        __attribute__((unused)) void *data)
4273 {
4274         struct cmd_csum_result *res = parsed_result;
4275         int hw = 0;
4276         uint64_t csum_offloads = 0;
4277         struct rte_eth_dev_info dev_info;
4278
4279         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4280                 printf("invalid port %d\n", res->port_id);
4281                 return;
4282         }
4283         if (!port_is_stopped(res->port_id)) {
4284                 printf("Please stop port %d first\n", res->port_id);
4285                 return;
4286         }
4287
4288         rte_eth_dev_info_get(res->port_id, &dev_info);
4289         if (!strcmp(res->mode, "set")) {
4290
4291                 if (!strcmp(res->hwsw, "hw"))
4292                         hw = 1;
4293
4294                 if (!strcmp(res->proto, "ip")) {
4295                         if (hw == 0 || (dev_info.tx_offload_capa &
4296                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4297                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4298                         } else {
4299                                 printf("IP checksum offload is not supported "
4300                                        "by port %u\n", res->port_id);
4301                         }
4302                 } else if (!strcmp(res->proto, "udp")) {
4303                         if (hw == 0 || (dev_info.tx_offload_capa &
4304                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4305                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4306                         } else {
4307                                 printf("UDP checksum offload is not supported "
4308                                        "by port %u\n", res->port_id);
4309                         }
4310                 } else if (!strcmp(res->proto, "tcp")) {
4311                         if (hw == 0 || (dev_info.tx_offload_capa &
4312                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4313                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4314                         } else {
4315                                 printf("TCP checksum offload is not supported "
4316                                        "by port %u\n", res->port_id);
4317                         }
4318                 } else if (!strcmp(res->proto, "sctp")) {
4319                         if (hw == 0 || (dev_info.tx_offload_capa &
4320                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4321                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4322                         } else {
4323                                 printf("SCTP checksum offload is not supported "
4324                                        "by port %u\n", res->port_id);
4325                         }
4326                 } else if (!strcmp(res->proto, "outer-ip")) {
4327                         if (hw == 0 || (dev_info.tx_offload_capa &
4328                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4329                                 csum_offloads |=
4330                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4331                         } else {
4332                                 printf("Outer IP checksum offload is not "
4333                                        "supported by port %u\n", res->port_id);
4334                         }
4335                 } else if (!strcmp(res->proto, "outer-udp")) {
4336                         if (hw == 0 || (dev_info.tx_offload_capa &
4337                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4338                                 csum_offloads |=
4339                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4340                         } else {
4341                                 printf("Outer UDP checksum offload is not "
4342                                        "supported by port %u\n", res->port_id);
4343                         }
4344                 }
4345
4346                 if (hw) {
4347                         ports[res->port_id].dev_conf.txmode.offloads |=
4348                                                         csum_offloads;
4349                 } else {
4350                         ports[res->port_id].dev_conf.txmode.offloads &=
4351                                                         (~csum_offloads);
4352                 }
4353         }
4354         csum_show(res->port_id);
4355
4356         cmd_reconfig_device_queue(res->port_id, 1, 1);
4357 }
4358
4359 cmdline_parse_token_string_t cmd_csum_csum =
4360         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4361                                 csum, "csum");
4362 cmdline_parse_token_string_t cmd_csum_mode =
4363         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4364                                 mode, "set");
4365 cmdline_parse_token_string_t cmd_csum_proto =
4366         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4367                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4368 cmdline_parse_token_string_t cmd_csum_hwsw =
4369         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4370                                 hwsw, "hw#sw");
4371 cmdline_parse_token_num_t cmd_csum_portid =
4372         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4373                                 port_id, UINT16);
4374
4375 cmdline_parse_inst_t cmd_csum_set = {
4376         .f = cmd_csum_parsed,
4377         .data = NULL,
4378         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4379                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4380                 "using csum forward engine",
4381         .tokens = {
4382                 (void *)&cmd_csum_csum,
4383                 (void *)&cmd_csum_mode,
4384                 (void *)&cmd_csum_proto,
4385                 (void *)&cmd_csum_hwsw,
4386                 (void *)&cmd_csum_portid,
4387                 NULL,
4388         },
4389 };
4390
4391 cmdline_parse_token_string_t cmd_csum_mode_show =
4392         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4393                                 mode, "show");
4394
4395 cmdline_parse_inst_t cmd_csum_show = {
4396         .f = cmd_csum_parsed,
4397         .data = NULL,
4398         .help_str = "csum show <port_id>: Show checksum offload configuration",
4399         .tokens = {
4400                 (void *)&cmd_csum_csum,
4401                 (void *)&cmd_csum_mode_show,
4402                 (void *)&cmd_csum_portid,
4403                 NULL,
4404         },
4405 };
4406
4407 /* Enable/disable tunnel parsing */
4408 struct cmd_csum_tunnel_result {
4409         cmdline_fixed_string_t csum;
4410         cmdline_fixed_string_t parse;
4411         cmdline_fixed_string_t onoff;
4412         portid_t port_id;
4413 };
4414
4415 static void
4416 cmd_csum_tunnel_parsed(void *parsed_result,
4417                        __attribute__((unused)) struct cmdline *cl,
4418                        __attribute__((unused)) void *data)
4419 {
4420         struct cmd_csum_tunnel_result *res = parsed_result;
4421
4422         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4423                 return;
4424
4425         if (!strcmp(res->onoff, "on"))
4426                 ports[res->port_id].parse_tunnel = 1;
4427         else
4428                 ports[res->port_id].parse_tunnel = 0;
4429
4430         csum_show(res->port_id);
4431 }
4432
4433 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4434         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4435                                 csum, "csum");
4436 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4437         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4438                                 parse, "parse-tunnel");
4439 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4440         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4441                                 onoff, "on#off");
4442 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4443         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4444                                 port_id, UINT16);
4445
4446 cmdline_parse_inst_t cmd_csum_tunnel = {
4447         .f = cmd_csum_tunnel_parsed,
4448         .data = NULL,
4449         .help_str = "csum parse-tunnel on|off <port_id>: "
4450                 "Enable/Disable parsing of tunnels for csum engine",
4451         .tokens = {
4452                 (void *)&cmd_csum_tunnel_csum,
4453                 (void *)&cmd_csum_tunnel_parse,
4454                 (void *)&cmd_csum_tunnel_onoff,
4455                 (void *)&cmd_csum_tunnel_portid,
4456                 NULL,
4457         },
4458 };
4459
4460 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4461 struct cmd_tso_set_result {
4462         cmdline_fixed_string_t tso;
4463         cmdline_fixed_string_t mode;
4464         uint16_t tso_segsz;
4465         portid_t port_id;
4466 };
4467
4468 static void
4469 cmd_tso_set_parsed(void *parsed_result,
4470                        __attribute__((unused)) struct cmdline *cl,
4471                        __attribute__((unused)) void *data)
4472 {
4473         struct cmd_tso_set_result *res = parsed_result;
4474         struct rte_eth_dev_info dev_info;
4475
4476         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4477                 return;
4478         if (!port_is_stopped(res->port_id)) {
4479                 printf("Please stop port %d first\n", res->port_id);
4480                 return;
4481         }
4482
4483         if (!strcmp(res->mode, "set"))
4484                 ports[res->port_id].tso_segsz = res->tso_segsz;
4485
4486         rte_eth_dev_info_get(res->port_id, &dev_info);
4487         if ((ports[res->port_id].tso_segsz != 0) &&
4488                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4489                 printf("Error: TSO is not supported by port %d\n",
4490                        res->port_id);
4491                 return;
4492         }
4493
4494         if (ports[res->port_id].tso_segsz == 0) {
4495                 ports[res->port_id].dev_conf.txmode.offloads &=
4496                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4497                 printf("TSO for non-tunneled packets is disabled\n");
4498         } else {
4499                 ports[res->port_id].dev_conf.txmode.offloads |=
4500                                                 DEV_TX_OFFLOAD_TCP_TSO;
4501                 printf("TSO segment size for non-tunneled packets is %d\n",
4502                         ports[res->port_id].tso_segsz);
4503         }
4504
4505         /* display warnings if configuration is not supported by the NIC */
4506         rte_eth_dev_info_get(res->port_id, &dev_info);
4507         if ((ports[res->port_id].tso_segsz != 0) &&
4508                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4509                 printf("Warning: TSO enabled but not "
4510                         "supported by port %d\n", res->port_id);
4511         }
4512
4513         cmd_reconfig_device_queue(res->port_id, 1, 1);
4514 }
4515
4516 cmdline_parse_token_string_t cmd_tso_set_tso =
4517         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4518                                 tso, "tso");
4519 cmdline_parse_token_string_t cmd_tso_set_mode =
4520         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4521                                 mode, "set");
4522 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4523         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4524                                 tso_segsz, UINT16);
4525 cmdline_parse_token_num_t cmd_tso_set_portid =
4526         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4527                                 port_id, UINT16);
4528
4529 cmdline_parse_inst_t cmd_tso_set = {
4530         .f = cmd_tso_set_parsed,
4531         .data = NULL,
4532         .help_str = "tso set <tso_segsz> <port_id>: "
4533                 "Set TSO segment size of non-tunneled packets for csum engine "
4534                 "(0 to disable)",
4535         .tokens = {
4536                 (void *)&cmd_tso_set_tso,
4537                 (void *)&cmd_tso_set_mode,
4538                 (void *)&cmd_tso_set_tso_segsz,
4539                 (void *)&cmd_tso_set_portid,
4540                 NULL,
4541         },
4542 };
4543
4544 cmdline_parse_token_string_t cmd_tso_show_mode =
4545         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4546                                 mode, "show");
4547
4548
4549 cmdline_parse_inst_t cmd_tso_show = {
4550         .f = cmd_tso_set_parsed,
4551         .data = NULL,
4552         .help_str = "tso show <port_id>: "
4553                 "Show TSO segment size of non-tunneled packets for csum engine",
4554         .tokens = {
4555                 (void *)&cmd_tso_set_tso,
4556                 (void *)&cmd_tso_show_mode,
4557                 (void *)&cmd_tso_set_portid,
4558                 NULL,
4559         },
4560 };
4561
4562 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4563 struct cmd_tunnel_tso_set_result {
4564         cmdline_fixed_string_t tso;
4565         cmdline_fixed_string_t mode;
4566         uint16_t tso_segsz;
4567         portid_t port_id;
4568 };
4569
4570 static struct rte_eth_dev_info
4571 check_tunnel_tso_nic_support(portid_t port_id)
4572 {
4573         struct rte_eth_dev_info dev_info;
4574
4575         rte_eth_dev_info_get(port_id, &dev_info);
4576         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4577                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4578                        "not enabled for port %d\n", port_id);
4579         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4580                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4581                        "not enabled for port %d\n", port_id);
4582         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4583                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4584                        "not enabled for port %d\n", port_id);
4585         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4586                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4587                        "not enabled for port %d\n", port_id);
4588         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4589                 printf("Warning: IP TUNNEL TSO not supported therefore "
4590                        "not enabled for port %d\n", port_id);
4591         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4592                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4593                        "not enabled for port %d\n", port_id);
4594         return dev_info;
4595 }
4596
4597 static void
4598 cmd_tunnel_tso_set_parsed(void *parsed_result,
4599                           __attribute__((unused)) struct cmdline *cl,
4600                           __attribute__((unused)) void *data)
4601 {
4602         struct cmd_tunnel_tso_set_result *res = parsed_result;
4603         struct rte_eth_dev_info dev_info;
4604
4605         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4606                 return;
4607         if (!port_is_stopped(res->port_id)) {
4608                 printf("Please stop port %d first\n", res->port_id);
4609                 return;
4610         }
4611
4612         if (!strcmp(res->mode, "set"))
4613                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4614
4615         dev_info = check_tunnel_tso_nic_support(res->port_id);
4616         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4617                 ports[res->port_id].dev_conf.txmode.offloads &=
4618                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4619                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4620                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4621                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4622                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4623                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4624                 printf("TSO for tunneled packets is disabled\n");
4625         } else {
4626                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4627                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4628                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4629                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4630                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4631                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4632
4633                 ports[res->port_id].dev_conf.txmode.offloads |=
4634                         (tso_offloads & dev_info.tx_offload_capa);
4635                 printf("TSO segment size for tunneled packets is %d\n",
4636                         ports[res->port_id].tunnel_tso_segsz);
4637
4638                 /* Below conditions are needed to make it work:
4639                  * (1) tunnel TSO is supported by the NIC;
4640                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4641                  * are recognized;
4642                  * (3) for tunneled pkts with outer L3 of IPv4,
4643                  * "csum set outer-ip" must be set to hw, because after tso,
4644                  * total_len of outer IP header is changed, and the checksum
4645                  * of outer IP header calculated by sw should be wrong; that
4646                  * is not necessary for IPv6 tunneled pkts because there's no
4647                  * checksum in IP header anymore.
4648                  */
4649
4650                 if (!ports[res->port_id].parse_tunnel)
4651                         printf("Warning: csum parse_tunnel must be set "
4652                                 "so that tunneled packets are recognized\n");
4653                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4654                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4655                         printf("Warning: csum set outer-ip must be set to hw "
4656                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4657         }
4658
4659         cmd_reconfig_device_queue(res->port_id, 1, 1);
4660 }
4661
4662 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4663         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4664                                 tso, "tunnel_tso");
4665 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4666         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4667                                 mode, "set");
4668 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4669         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4670                                 tso_segsz, UINT16);
4671 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4672         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4673                                 port_id, UINT16);
4674
4675 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4676         .f = cmd_tunnel_tso_set_parsed,
4677         .data = NULL,
4678         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4679                 "Set TSO segment size of tunneled packets for csum engine "
4680                 "(0 to disable)",
4681         .tokens = {
4682                 (void *)&cmd_tunnel_tso_set_tso,
4683                 (void *)&cmd_tunnel_tso_set_mode,
4684                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4685                 (void *)&cmd_tunnel_tso_set_portid,
4686                 NULL,
4687         },
4688 };
4689
4690 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4691         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4692                                 mode, "show");
4693
4694
4695 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4696         .f = cmd_tunnel_tso_set_parsed,
4697         .data = NULL,
4698         .help_str = "tunnel_tso show <port_id> "
4699                 "Show TSO segment size of tunneled packets for csum engine",
4700         .tokens = {
4701                 (void *)&cmd_tunnel_tso_set_tso,
4702                 (void *)&cmd_tunnel_tso_show_mode,
4703                 (void *)&cmd_tunnel_tso_set_portid,
4704                 NULL,
4705         },
4706 };
4707
4708 /* *** SET GRO FOR A PORT *** */
4709 struct cmd_gro_enable_result {
4710         cmdline_fixed_string_t cmd_set;
4711         cmdline_fixed_string_t cmd_port;
4712         cmdline_fixed_string_t cmd_keyword;
4713         cmdline_fixed_string_t cmd_onoff;
4714         portid_t cmd_pid;
4715 };
4716
4717 static void
4718 cmd_gro_enable_parsed(void *parsed_result,
4719                 __attribute__((unused)) struct cmdline *cl,
4720                 __attribute__((unused)) void *data)
4721 {
4722         struct cmd_gro_enable_result *res;
4723
4724         res = parsed_result;
4725         if (!strcmp(res->cmd_keyword, "gro"))
4726                 setup_gro(res->cmd_onoff, res->cmd_pid);
4727 }
4728
4729 cmdline_parse_token_string_t cmd_gro_enable_set =
4730         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4731                         cmd_set, "set");
4732 cmdline_parse_token_string_t cmd_gro_enable_port =
4733         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4734                         cmd_keyword, "port");
4735 cmdline_parse_token_num_t cmd_gro_enable_pid =
4736         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4737                         cmd_pid, UINT16);
4738 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4739         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4740                         cmd_keyword, "gro");
4741 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4742         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4743                         cmd_onoff, "on#off");
4744
4745 cmdline_parse_inst_t cmd_gro_enable = {
4746         .f = cmd_gro_enable_parsed,
4747         .data = NULL,
4748         .help_str = "set port <port_id> gro on|off",
4749         .tokens = {
4750                 (void *)&cmd_gro_enable_set,
4751                 (void *)&cmd_gro_enable_port,
4752                 (void *)&cmd_gro_enable_pid,
4753                 (void *)&cmd_gro_enable_keyword,
4754                 (void *)&cmd_gro_enable_onoff,
4755                 NULL,
4756         },
4757 };
4758
4759 /* *** DISPLAY GRO CONFIGURATION *** */
4760 struct cmd_gro_show_result {
4761         cmdline_fixed_string_t cmd_show;
4762         cmdline_fixed_string_t cmd_port;
4763         cmdline_fixed_string_t cmd_keyword;
4764         portid_t cmd_pid;
4765 };
4766
4767 static void
4768 cmd_gro_show_parsed(void *parsed_result,
4769                 __attribute__((unused)) struct cmdline *cl,
4770                 __attribute__((unused)) void *data)
4771 {
4772         struct cmd_gro_show_result *res;
4773
4774         res = parsed_result;
4775         if (!strcmp(res->cmd_keyword, "gro"))
4776                 show_gro(res->cmd_pid);
4777 }
4778
4779 cmdline_parse_token_string_t cmd_gro_show_show =
4780         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4781                         cmd_show, "show");
4782 cmdline_parse_token_string_t cmd_gro_show_port =
4783         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4784                         cmd_port, "port");
4785 cmdline_parse_token_num_t cmd_gro_show_pid =
4786         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4787                         cmd_pid, UINT16);
4788 cmdline_parse_token_string_t cmd_gro_show_keyword =
4789         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4790                         cmd_keyword, "gro");
4791
4792 cmdline_parse_inst_t cmd_gro_show = {
4793         .f = cmd_gro_show_parsed,
4794         .data = NULL,
4795         .help_str = "show port <port_id> gro",
4796         .tokens = {
4797                 (void *)&cmd_gro_show_show,
4798                 (void *)&cmd_gro_show_port,
4799                 (void *)&cmd_gro_show_pid,
4800                 (void *)&cmd_gro_show_keyword,
4801                 NULL,
4802         },
4803 };
4804
4805 /* *** SET FLUSH CYCLES FOR GRO *** */
4806 struct cmd_gro_flush_result {
4807         cmdline_fixed_string_t cmd_set;
4808         cmdline_fixed_string_t cmd_keyword;
4809         cmdline_fixed_string_t cmd_flush;
4810         uint8_t cmd_cycles;
4811 };
4812
4813 static void
4814 cmd_gro_flush_parsed(void *parsed_result,
4815                 __attribute__((unused)) struct cmdline *cl,
4816                 __attribute__((unused)) void *data)
4817 {
4818         struct cmd_gro_flush_result *res;
4819
4820         res = parsed_result;
4821         if ((!strcmp(res->cmd_keyword, "gro")) &&
4822                         (!strcmp(res->cmd_flush, "flush")))
4823                 setup_gro_flush_cycles(res->cmd_cycles);
4824 }
4825
4826 cmdline_parse_token_string_t cmd_gro_flush_set =
4827         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4828                         cmd_set, "set");
4829 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4830         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4831                         cmd_keyword, "gro");
4832 cmdline_parse_token_string_t cmd_gro_flush_flush =
4833         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4834                         cmd_flush, "flush");
4835 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4836         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4837                         cmd_cycles, UINT8);
4838
4839 cmdline_parse_inst_t cmd_gro_flush = {
4840         .f = cmd_gro_flush_parsed,
4841         .data = NULL,
4842         .help_str = "set gro flush <cycles>",
4843         .tokens = {
4844                 (void *)&cmd_gro_flush_set,
4845                 (void *)&cmd_gro_flush_keyword,
4846                 (void *)&cmd_gro_flush_flush,
4847                 (void *)&cmd_gro_flush_cycles,
4848                 NULL,
4849         },
4850 };
4851
4852 /* *** ENABLE/DISABLE GSO *** */
4853 struct cmd_gso_enable_result {
4854         cmdline_fixed_string_t cmd_set;
4855         cmdline_fixed_string_t cmd_port;
4856         cmdline_fixed_string_t cmd_keyword;
4857         cmdline_fixed_string_t cmd_mode;
4858         portid_t cmd_pid;
4859 };
4860
4861 static void
4862 cmd_gso_enable_parsed(void *parsed_result,
4863                 __attribute__((unused)) struct cmdline *cl,
4864                 __attribute__((unused)) void *data)
4865 {
4866         struct cmd_gso_enable_result *res;
4867
4868         res = parsed_result;
4869         if (!strcmp(res->cmd_keyword, "gso"))
4870                 setup_gso(res->cmd_mode, res->cmd_pid);
4871 }
4872
4873 cmdline_parse_token_string_t cmd_gso_enable_set =
4874         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4875                         cmd_set, "set");
4876 cmdline_parse_token_string_t cmd_gso_enable_port =
4877         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4878                         cmd_port, "port");
4879 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4880         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4881                         cmd_keyword, "gso");
4882 cmdline_parse_token_string_t cmd_gso_enable_mode =
4883         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4884                         cmd_mode, "on#off");
4885 cmdline_parse_token_num_t cmd_gso_enable_pid =
4886         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4887                         cmd_pid, UINT16);
4888
4889 cmdline_parse_inst_t cmd_gso_enable = {
4890         .f = cmd_gso_enable_parsed,
4891         .data = NULL,
4892         .help_str = "set port <port_id> gso on|off",
4893         .tokens = {
4894                 (void *)&cmd_gso_enable_set,
4895                 (void *)&cmd_gso_enable_port,
4896                 (void *)&cmd_gso_enable_pid,
4897                 (void *)&cmd_gso_enable_keyword,
4898                 (void *)&cmd_gso_enable_mode,
4899                 NULL,
4900         },
4901 };
4902
4903 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4904 struct cmd_gso_size_result {
4905         cmdline_fixed_string_t cmd_set;
4906         cmdline_fixed_string_t cmd_keyword;
4907         cmdline_fixed_string_t cmd_segsz;
4908         uint16_t cmd_size;
4909 };
4910
4911 static void
4912 cmd_gso_size_parsed(void *parsed_result,
4913                        __attribute__((unused)) struct cmdline *cl,
4914                        __attribute__((unused)) void *data)
4915 {
4916         struct cmd_gso_size_result *res = parsed_result;
4917
4918         if (test_done == 0) {
4919                 printf("Before setting GSO segsz, please first"
4920                                 " stop fowarding\n");
4921                 return;
4922         }
4923
4924         if (!strcmp(res->cmd_keyword, "gso") &&
4925                         !strcmp(res->cmd_segsz, "segsz")) {
4926                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4927                         printf("gso_size should be larger than %zu."
4928                                         " Please input a legal value\n",
4929                                         RTE_GSO_SEG_SIZE_MIN);
4930                 else
4931                         gso_max_segment_size = res->cmd_size;
4932         }
4933 }
4934
4935 cmdline_parse_token_string_t cmd_gso_size_set =
4936         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4937                                 cmd_set, "set");
4938 cmdline_parse_token_string_t cmd_gso_size_keyword =
4939         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4940                                 cmd_keyword, "gso");
4941 cmdline_parse_token_string_t cmd_gso_size_segsz =
4942         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4943                                 cmd_segsz, "segsz");
4944 cmdline_parse_token_num_t cmd_gso_size_size =
4945         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4946                                 cmd_size, UINT16);
4947
4948 cmdline_parse_inst_t cmd_gso_size = {
4949         .f = cmd_gso_size_parsed,
4950         .data = NULL,
4951         .help_str = "set gso segsz <length>",
4952         .tokens = {
4953                 (void *)&cmd_gso_size_set,
4954                 (void *)&cmd_gso_size_keyword,
4955                 (void *)&cmd_gso_size_segsz,
4956                 (void *)&cmd_gso_size_size,
4957                 NULL,
4958         },
4959 };
4960
4961 /* *** SHOW GSO CONFIGURATION *** */
4962 struct cmd_gso_show_result {
4963         cmdline_fixed_string_t cmd_show;
4964         cmdline_fixed_string_t cmd_port;
4965         cmdline_fixed_string_t cmd_keyword;
4966         portid_t cmd_pid;
4967 };
4968
4969 static void
4970 cmd_gso_show_parsed(void *parsed_result,
4971                        __attribute__((unused)) struct cmdline *cl,
4972                        __attribute__((unused)) void *data)
4973 {
4974         struct cmd_gso_show_result *res = parsed_result;
4975
4976         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4977                 printf("invalid port id %u\n", res->cmd_pid);
4978                 return;
4979         }
4980         if (!strcmp(res->cmd_keyword, "gso")) {
4981                 if (gso_ports[res->cmd_pid].enable) {
4982                         printf("Max GSO'd packet size: %uB\n"
4983                                         "Supported GSO types: TCP/IPv4, "
4984                                         "UDP/IPv4, VxLAN with inner "
4985                                         "TCP/IPv4 packet, GRE with inner "
4986                                         "TCP/IPv4 packet\n",
4987                                         gso_max_segment_size);
4988                 } else
4989                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4990         }
4991 }
4992
4993 cmdline_parse_token_string_t cmd_gso_show_show =
4994 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4995                 cmd_show, "show");
4996 cmdline_parse_token_string_t cmd_gso_show_port =
4997 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4998                 cmd_port, "port");
4999 cmdline_parse_token_string_t cmd_gso_show_keyword =
5000         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5001                                 cmd_keyword, "gso");
5002 cmdline_parse_token_num_t cmd_gso_show_pid =
5003         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5004                                 cmd_pid, UINT16);
5005
5006 cmdline_parse_inst_t cmd_gso_show = {
5007         .f = cmd_gso_show_parsed,
5008         .data = NULL,
5009         .help_str = "show port <port_id> gso",
5010         .tokens = {
5011                 (void *)&cmd_gso_show_show,
5012                 (void *)&cmd_gso_show_port,
5013                 (void *)&cmd_gso_show_pid,
5014                 (void *)&cmd_gso_show_keyword,
5015                 NULL,
5016         },
5017 };
5018
5019 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5020 struct cmd_set_flush_rx {
5021         cmdline_fixed_string_t set;
5022         cmdline_fixed_string_t flush_rx;
5023         cmdline_fixed_string_t mode;
5024 };
5025
5026 static void
5027 cmd_set_flush_rx_parsed(void *parsed_result,
5028                 __attribute__((unused)) struct cmdline *cl,
5029                 __attribute__((unused)) void *data)
5030 {
5031         struct cmd_set_flush_rx *res = parsed_result;
5032         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5033 }
5034
5035 cmdline_parse_token_string_t cmd_setflushrx_set =
5036         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5037                         set, "set");
5038 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5039         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5040                         flush_rx, "flush_rx");
5041 cmdline_parse_token_string_t cmd_setflushrx_mode =
5042         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5043                         mode, "on#off");
5044
5045
5046 cmdline_parse_inst_t cmd_set_flush_rx = {
5047         .f = cmd_set_flush_rx_parsed,
5048         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5049         .data = NULL,
5050         .tokens = {
5051                 (void *)&cmd_setflushrx_set,
5052                 (void *)&cmd_setflushrx_flush_rx,
5053                 (void *)&cmd_setflushrx_mode,
5054                 NULL,
5055         },
5056 };
5057
5058 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5059 struct cmd_set_link_check {
5060         cmdline_fixed_string_t set;
5061         cmdline_fixed_string_t link_check;
5062         cmdline_fixed_string_t mode;
5063 };
5064
5065 static void
5066 cmd_set_link_check_parsed(void *parsed_result,
5067                 __attribute__((unused)) struct cmdline *cl,
5068                 __attribute__((unused)) void *data)
5069 {
5070         struct cmd_set_link_check *res = parsed_result;
5071         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5072 }
5073
5074 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5075         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5076                         set, "set");
5077 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5078         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5079                         link_check, "link_check");
5080 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5081         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5082                         mode, "on#off");
5083
5084
5085 cmdline_parse_inst_t cmd_set_link_check = {
5086         .f = cmd_set_link_check_parsed,
5087         .help_str = "set link_check on|off: Enable/Disable link status check "
5088                     "when starting/stopping a port",
5089         .data = NULL,
5090         .tokens = {
5091                 (void *)&cmd_setlinkcheck_set,
5092                 (void *)&cmd_setlinkcheck_link_check,
5093                 (void *)&cmd_setlinkcheck_mode,
5094                 NULL,
5095         },
5096 };
5097
5098 /* *** SET NIC BYPASS MODE *** */
5099 struct cmd_set_bypass_mode_result {
5100         cmdline_fixed_string_t set;
5101         cmdline_fixed_string_t bypass;
5102         cmdline_fixed_string_t mode;
5103         cmdline_fixed_string_t value;
5104         portid_t port_id;
5105 };
5106
5107 static void
5108 cmd_set_bypass_mode_parsed(void *parsed_result,
5109                 __attribute__((unused)) struct cmdline *cl,
5110                 __attribute__((unused)) void *data)
5111 {
5112         struct cmd_set_bypass_mode_result *res = parsed_result;
5113         portid_t port_id = res->port_id;
5114         int32_t rc = -EINVAL;
5115
5116 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5117         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5118
5119         if (!strcmp(res->value, "bypass"))
5120                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5121         else if (!strcmp(res->value, "isolate"))
5122                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5123         else
5124                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5125
5126         /* Set the bypass mode for the relevant port. */
5127         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5128 #endif
5129         if (rc != 0)
5130                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5131 }
5132
5133 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5134         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5135                         set, "set");
5136 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5137         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5138                         bypass, "bypass");
5139 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5140         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5141                         mode, "mode");
5142 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5143         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5144                         value, "normal#bypass#isolate");
5145 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5146         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5147                                 port_id, UINT16);
5148
5149 cmdline_parse_inst_t cmd_set_bypass_mode = {
5150         .f = cmd_set_bypass_mode_parsed,
5151         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5152                     "Set the NIC bypass mode for port_id",
5153         .data = NULL,
5154         .tokens = {
5155                 (void *)&cmd_setbypass_mode_set,
5156                 (void *)&cmd_setbypass_mode_bypass,
5157                 (void *)&cmd_setbypass_mode_mode,
5158                 (void *)&cmd_setbypass_mode_value,
5159                 (void *)&cmd_setbypass_mode_port,
5160                 NULL,
5161         },
5162 };
5163
5164 /* *** SET NIC BYPASS EVENT *** */
5165 struct cmd_set_bypass_event_result {
5166         cmdline_fixed_string_t set;
5167         cmdline_fixed_string_t bypass;
5168         cmdline_fixed_string_t event;
5169         cmdline_fixed_string_t event_value;
5170         cmdline_fixed_string_t mode;
5171         cmdline_fixed_string_t mode_value;
5172         portid_t port_id;
5173 };
5174
5175 static void
5176 cmd_set_bypass_event_parsed(void *parsed_result,
5177                 __attribute__((unused)) struct cmdline *cl,
5178                 __attribute__((unused)) void *data)
5179 {
5180         int32_t rc = -EINVAL;
5181         struct cmd_set_bypass_event_result *res = parsed_result;
5182         portid_t port_id = res->port_id;
5183
5184 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5185         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5186         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5187
5188         if (!strcmp(res->event_value, "timeout"))
5189                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5190         else if (!strcmp(res->event_value, "os_on"))
5191                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5192         else if (!strcmp(res->event_value, "os_off"))
5193                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5194         else if (!strcmp(res->event_value, "power_on"))
5195                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5196         else if (!strcmp(res->event_value, "power_off"))
5197                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5198         else
5199                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5200
5201         if (!strcmp(res->mode_value, "bypass"))
5202                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5203         else if (!strcmp(res->mode_value, "isolate"))
5204                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5205         else
5206                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5207
5208         /* Set the watchdog timeout. */
5209         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5210
5211                 rc = -EINVAL;
5212                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5213                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5214                                                            bypass_timeout);
5215                 }
5216                 if (rc != 0) {
5217                         printf("Failed to set timeout value %u "
5218                         "for port %d, errto code: %d.\n",
5219                         bypass_timeout, port_id, rc);
5220                 }
5221         }
5222
5223         /* Set the bypass event to transition to bypass mode. */
5224         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5225                                               bypass_mode);
5226 #endif
5227
5228         if (rc != 0)
5229                 printf("\t Failed to set bypass event for port = %d.\n",
5230                        port_id);
5231 }
5232
5233 cmdline_parse_token_string_t cmd_setbypass_event_set =
5234         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5235                         set, "set");
5236 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5237         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5238                         bypass, "bypass");
5239 cmdline_parse_token_string_t cmd_setbypass_event_event =
5240         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5241                         event, "event");
5242 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5243         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5244                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5245 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5246         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5247                         mode, "mode");
5248 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5249         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5250                         mode_value, "normal#bypass#isolate");
5251 cmdline_parse_token_num_t cmd_setbypass_event_port =
5252         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5253                                 port_id, UINT16);
5254
5255 cmdline_parse_inst_t cmd_set_bypass_event = {
5256         .f = cmd_set_bypass_event_parsed,
5257         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5258                 "power_off mode normal|bypass|isolate <port_id>: "
5259                 "Set the NIC bypass event mode for port_id",
5260         .data = NULL,
5261         .tokens = {
5262                 (void *)&cmd_setbypass_event_set,
5263                 (void *)&cmd_setbypass_event_bypass,
5264                 (void *)&cmd_setbypass_event_event,
5265                 (void *)&cmd_setbypass_event_event_value,
5266                 (void *)&cmd_setbypass_event_mode,
5267                 (void *)&cmd_setbypass_event_mode_value,
5268                 (void *)&cmd_setbypass_event_port,
5269                 NULL,
5270         },
5271 };
5272
5273
5274 /* *** SET NIC BYPASS TIMEOUT *** */
5275 struct cmd_set_bypass_timeout_result {
5276         cmdline_fixed_string_t set;
5277         cmdline_fixed_string_t bypass;
5278         cmdline_fixed_string_t timeout;
5279         cmdline_fixed_string_t value;
5280 };
5281
5282 static void
5283 cmd_set_bypass_timeout_parsed(void *parsed_result,
5284                 __attribute__((unused)) struct cmdline *cl,
5285                 __attribute__((unused)) void *data)
5286 {
5287         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5288
5289 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5290         if (!strcmp(res->value, "1.5"))
5291                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5292         else if (!strcmp(res->value, "2"))
5293                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5294         else if (!strcmp(res->value, "3"))
5295                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5296         else if (!strcmp(res->value, "4"))
5297                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5298         else if (!strcmp(res->value, "8"))
5299                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5300         else if (!strcmp(res->value, "16"))
5301                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5302         else if (!strcmp(res->value, "32"))
5303                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5304         else
5305                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5306 #endif
5307 }
5308
5309 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5310         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5311                         set, "set");
5312 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5313         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5314                         bypass, "bypass");
5315 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5316         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5317                         timeout, "timeout");
5318 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5319         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5320                         value, "0#1.5#2#3#4#8#16#32");
5321
5322 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5323         .f = cmd_set_bypass_timeout_parsed,
5324         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5325                 "Set the NIC bypass watchdog timeout in seconds",
5326         .data = NULL,
5327         .tokens = {
5328                 (void *)&cmd_setbypass_timeout_set,
5329                 (void *)&cmd_setbypass_timeout_bypass,
5330                 (void *)&cmd_setbypass_timeout_timeout,
5331                 (void *)&cmd_setbypass_timeout_value,
5332                 NULL,
5333         },
5334 };
5335
5336 /* *** SHOW NIC BYPASS MODE *** */
5337 struct cmd_show_bypass_config_result {
5338         cmdline_fixed_string_t show;
5339         cmdline_fixed_string_t bypass;
5340         cmdline_fixed_string_t config;
5341         portid_t port_id;
5342 };
5343
5344 static void
5345 cmd_show_bypass_config_parsed(void *parsed_result,
5346                 __attribute__((unused)) struct cmdline *cl,
5347                 __attribute__((unused)) void *data)
5348 {
5349         struct cmd_show_bypass_config_result *res = parsed_result;
5350         portid_t port_id = res->port_id;
5351         int rc = -EINVAL;
5352 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5353         uint32_t event_mode;
5354         uint32_t bypass_mode;
5355         uint32_t timeout = bypass_timeout;
5356         int i;
5357
5358         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5359                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5360         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5361                 {"UNKNOWN", "normal", "bypass", "isolate"};
5362         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5363                 "NONE",
5364                 "OS/board on",
5365                 "power supply on",
5366                 "OS/board off",
5367                 "power supply off",
5368                 "timeout"};
5369         int num_events = (sizeof events) / (sizeof events[0]);
5370
5371         /* Display the bypass mode.*/
5372         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5373                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5374                 return;
5375         }
5376         else {
5377                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5378                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5379
5380                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5381         }
5382
5383         /* Display the bypass timeout.*/
5384         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5385                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5386
5387         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5388
5389         /* Display the bypass events and associated modes. */
5390         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5391
5392                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5393                         printf("\tFailed to get bypass mode for event = %s\n",
5394                                 events[i]);
5395                 } else {
5396                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5397                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5398
5399                         printf("\tbypass event: %-16s = %s\n", events[i],
5400                                 modes[event_mode]);
5401                 }
5402         }
5403 #endif
5404         if (rc != 0)
5405                 printf("\tFailed to get bypass configuration for port = %d\n",
5406                        port_id);
5407 }
5408
5409 cmdline_parse_token_string_t cmd_showbypass_config_show =
5410         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5411                         show, "show");
5412 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5413         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5414                         bypass, "bypass");
5415 cmdline_parse_token_string_t cmd_showbypass_config_config =
5416         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5417                         config, "config");
5418 cmdline_parse_token_num_t cmd_showbypass_config_port =
5419         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5420                                 port_id, UINT16);
5421
5422 cmdline_parse_inst_t cmd_show_bypass_config = {
5423         .f = cmd_show_bypass_config_parsed,
5424         .help_str = "show bypass config <port_id>: "
5425                     "Show the NIC bypass config for port_id",
5426         .data = NULL,
5427         .tokens = {
5428                 (void *)&cmd_showbypass_config_show,
5429                 (void *)&cmd_showbypass_config_bypass,
5430                 (void *)&cmd_showbypass_config_config,
5431                 (void *)&cmd_showbypass_config_port,
5432                 NULL,
5433         },
5434 };
5435
5436 #ifdef RTE_LIBRTE_PMD_BOND
5437 /* *** SET BONDING MODE *** */
5438 struct cmd_set_bonding_mode_result {
5439         cmdline_fixed_string_t set;
5440         cmdline_fixed_string_t bonding;
5441         cmdline_fixed_string_t mode;
5442         uint8_t value;
5443         portid_t port_id;
5444 };
5445
5446 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5447                 __attribute__((unused))  struct cmdline *cl,
5448                 __attribute__((unused)) void *data)
5449 {
5450         struct cmd_set_bonding_mode_result *res = parsed_result;
5451         portid_t port_id = res->port_id;
5452
5453         /* Set the bonding mode for the relevant port. */
5454         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5455                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5456 }
5457
5458 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5459 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5460                 set, "set");
5461 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5462 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5463                 bonding, "bonding");
5464 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5465 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5466                 mode, "mode");
5467 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5468 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5469                 value, UINT8);
5470 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5471 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5472                 port_id, UINT16);
5473
5474 cmdline_parse_inst_t cmd_set_bonding_mode = {
5475                 .f = cmd_set_bonding_mode_parsed,
5476                 .help_str = "set bonding mode <mode_value> <port_id>: "
5477                         "Set the bonding mode for port_id",
5478                 .data = NULL,
5479                 .tokens = {
5480                                 (void *) &cmd_setbonding_mode_set,
5481                                 (void *) &cmd_setbonding_mode_bonding,
5482                                 (void *) &cmd_setbonding_mode_mode,
5483                                 (void *) &cmd_setbonding_mode_value,
5484                                 (void *) &cmd_setbonding_mode_port,
5485                                 NULL
5486                 }
5487 };
5488
5489 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5490 struct cmd_set_bonding_lacp_dedicated_queues_result {
5491         cmdline_fixed_string_t set;
5492         cmdline_fixed_string_t bonding;
5493         cmdline_fixed_string_t lacp;
5494         cmdline_fixed_string_t dedicated_queues;
5495         portid_t port_id;
5496         cmdline_fixed_string_t mode;
5497 };
5498
5499 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5500                 __attribute__((unused))  struct cmdline *cl,
5501                 __attribute__((unused)) void *data)
5502 {
5503         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5504         portid_t port_id = res->port_id;
5505         struct rte_port *port;
5506
5507         port = &ports[port_id];
5508
5509         /** Check if the port is not started **/
5510         if (port->port_status != RTE_PORT_STOPPED) {
5511                 printf("Please stop port %d first\n", port_id);
5512                 return;
5513         }
5514
5515         if (!strcmp(res->mode, "enable")) {
5516                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5517                         printf("Dedicate queues for LACP control packets"
5518                                         " enabled\n");
5519                 else
5520                         printf("Enabling dedicate queues for LACP control "
5521                                         "packets on port %d failed\n", port_id);
5522         } else if (!strcmp(res->mode, "disable")) {
5523                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5524                         printf("Dedicated queues for LACP control packets "
5525                                         "disabled\n");
5526                 else
5527                         printf("Disabling dedicated queues for LACP control "
5528                                         "traffic on port %d failed\n", port_id);
5529         }
5530 }
5531
5532 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5533 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5534                 set, "set");
5535 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5536 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5537                 bonding, "bonding");
5538 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5539 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5540                 lacp, "lacp");
5541 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5542 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5543                 dedicated_queues, "dedicated_queues");
5544 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5545 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5546                 port_id, UINT16);
5547 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5548 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5549                 mode, "enable#disable");
5550
5551 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5552                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5553                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5554                         "enable|disable: "
5555                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5556                 .data = NULL,
5557                 .tokens = {
5558                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5559                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5560                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5561                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5562                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5563                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5564                         NULL
5565                 }
5566 };
5567
5568 /* *** SET BALANCE XMIT POLICY *** */
5569 struct cmd_set_bonding_balance_xmit_policy_result {
5570         cmdline_fixed_string_t set;
5571         cmdline_fixed_string_t bonding;
5572         cmdline_fixed_string_t balance_xmit_policy;
5573         portid_t port_id;
5574         cmdline_fixed_string_t policy;
5575 };
5576
5577 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5578                 __attribute__((unused))  struct cmdline *cl,
5579                 __attribute__((unused)) void *data)
5580 {
5581         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5582         portid_t port_id = res->port_id;
5583         uint8_t policy;
5584
5585         if (!strcmp(res->policy, "l2")) {
5586                 policy = BALANCE_XMIT_POLICY_LAYER2;
5587         } else if (!strcmp(res->policy, "l23")) {
5588                 policy = BALANCE_XMIT_POLICY_LAYER23;
5589         } else if (!strcmp(res->policy, "l34")) {
5590                 policy = BALANCE_XMIT_POLICY_LAYER34;
5591         } else {
5592                 printf("\t Invalid xmit policy selection");
5593                 return;
5594         }
5595
5596         /* Set the bonding mode for the relevant port. */
5597         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5598                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5599                                 port_id);
5600         }
5601 }
5602
5603 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5604 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5605                 set, "set");
5606 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5607 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5608                 bonding, "bonding");
5609 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5610 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5611                 balance_xmit_policy, "balance_xmit_policy");
5612 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5613 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5614                 port_id, UINT16);
5615 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5616 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5617                 policy, "l2#l23#l34");
5618
5619 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5620                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5621                 .help_str = "set bonding balance_xmit_policy <port_id> "
5622                         "l2|l23|l34: "
5623                         "Set the bonding balance_xmit_policy for port_id",
5624                 .data = NULL,
5625                 .tokens = {
5626                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5627                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5628                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5629                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5630                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5631                                 NULL
5632                 }
5633 };
5634
5635 /* *** SHOW NIC BONDING CONFIGURATION *** */
5636 struct cmd_show_bonding_config_result {
5637         cmdline_fixed_string_t show;
5638         cmdline_fixed_string_t bonding;
5639         cmdline_fixed_string_t config;
5640         portid_t port_id;
5641 };
5642
5643 static void cmd_show_bonding_config_parsed(void *parsed_result,
5644                 __attribute__((unused))  struct cmdline *cl,
5645                 __attribute__((unused)) void *data)
5646 {
5647         struct cmd_show_bonding_config_result *res = parsed_result;
5648         int bonding_mode, agg_mode;
5649         portid_t slaves[RTE_MAX_ETHPORTS];
5650         int num_slaves, num_active_slaves;
5651         int primary_id;
5652         int i;
5653         portid_t port_id = res->port_id;
5654
5655         /* Display the bonding mode.*/
5656         bonding_mode = rte_eth_bond_mode_get(port_id);
5657         if (bonding_mode < 0) {
5658                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5659                 return;
5660         } else
5661                 printf("\tBonding mode: %d\n", bonding_mode);
5662
5663         if (bonding_mode == BONDING_MODE_BALANCE) {
5664                 int balance_xmit_policy;
5665
5666                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5667                 if (balance_xmit_policy < 0) {
5668                         printf("\tFailed to get balance xmit policy for port = %d\n",
5669                                         port_id);
5670                         return;
5671                 } else {
5672                         printf("\tBalance Xmit Policy: ");
5673
5674                         switch (balance_xmit_policy) {
5675                         case BALANCE_XMIT_POLICY_LAYER2:
5676                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5677                                 break;
5678                         case BALANCE_XMIT_POLICY_LAYER23:
5679                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5680                                 break;
5681                         case BALANCE_XMIT_POLICY_LAYER34:
5682                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5683                                 break;
5684                         }
5685                         printf("\n");
5686                 }
5687         }
5688
5689         if (bonding_mode == BONDING_MODE_8023AD) {
5690                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5691                 printf("\tIEEE802.3AD Aggregator Mode: ");
5692                 switch (agg_mode) {
5693                 case AGG_BANDWIDTH:
5694                         printf("bandwidth");
5695                         break;
5696                 case AGG_STABLE:
5697                         printf("stable");
5698                         break;
5699                 case AGG_COUNT:
5700                         printf("count");
5701                         break;
5702                 }
5703                 printf("\n");
5704         }
5705
5706         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5707
5708         if (num_slaves < 0) {
5709                 printf("\tFailed to get slave list for port = %d\n", port_id);
5710                 return;
5711         }
5712         if (num_slaves > 0) {
5713                 printf("\tSlaves (%d): [", num_slaves);
5714                 for (i = 0; i < num_slaves - 1; i++)
5715                         printf("%d ", slaves[i]);
5716
5717                 printf("%d]\n", slaves[num_slaves - 1]);
5718         } else {
5719                 printf("\tSlaves: []\n");
5720
5721         }
5722
5723         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5724                         RTE_MAX_ETHPORTS);
5725
5726         if (num_active_slaves < 0) {
5727                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5728                 return;
5729         }
5730         if (num_active_slaves > 0) {
5731                 printf("\tActive Slaves (%d): [", num_active_slaves);
5732                 for (i = 0; i < num_active_slaves - 1; i++)
5733                         printf("%d ", slaves[i]);
5734
5735                 printf("%d]\n", slaves[num_active_slaves - 1]);
5736
5737         } else {
5738                 printf("\tActive Slaves: []\n");
5739
5740         }
5741
5742         primary_id = rte_eth_bond_primary_get(port_id);
5743         if (primary_id < 0) {
5744                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5745                 return;
5746         } else
5747                 printf("\tPrimary: [%d]\n", primary_id);
5748
5749 }
5750
5751 cmdline_parse_token_string_t cmd_showbonding_config_show =
5752 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5753                 show, "show");
5754 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5755 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5756                 bonding, "bonding");
5757 cmdline_parse_token_string_t cmd_showbonding_config_config =
5758 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5759                 config, "config");
5760 cmdline_parse_token_num_t cmd_showbonding_config_port =
5761 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5762                 port_id, UINT16);
5763
5764 cmdline_parse_inst_t cmd_show_bonding_config = {
5765                 .f = cmd_show_bonding_config_parsed,
5766                 .help_str = "show bonding config <port_id>: "
5767                         "Show the bonding config for port_id",
5768                 .data = NULL,
5769                 .tokens = {
5770                                 (void *)&cmd_showbonding_config_show,
5771                                 (void *)&cmd_showbonding_config_bonding,
5772                                 (void *)&cmd_showbonding_config_config,
5773                                 (void *)&cmd_showbonding_config_port,
5774                                 NULL
5775                 }
5776 };
5777
5778 /* *** SET BONDING PRIMARY *** */
5779 struct cmd_set_bonding_primary_result {
5780         cmdline_fixed_string_t set;
5781         cmdline_fixed_string_t bonding;
5782         cmdline_fixed_string_t primary;
5783         portid_t slave_id;
5784         portid_t port_id;
5785 };
5786
5787 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5788                 __attribute__((unused))  struct cmdline *cl,
5789                 __attribute__((unused)) void *data)
5790 {
5791         struct cmd_set_bonding_primary_result *res = parsed_result;
5792         portid_t master_port_id = res->port_id;
5793         portid_t slave_port_id = res->slave_id;
5794
5795         /* Set the primary slave for a bonded device. */
5796         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5797                 printf("\t Failed to set primary slave for port = %d.\n",
5798                                 master_port_id);
5799                 return;
5800         }
5801         init_port_config();
5802 }
5803
5804 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5805 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5806                 set, "set");
5807 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5808 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5809                 bonding, "bonding");
5810 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5811 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5812                 primary, "primary");
5813 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5814 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5815                 slave_id, UINT16);
5816 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5817 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5818                 port_id, UINT16);
5819
5820 cmdline_parse_inst_t cmd_set_bonding_primary = {
5821                 .f = cmd_set_bonding_primary_parsed,
5822                 .help_str = "set bonding primary <slave_id> <port_id>: "
5823                         "Set the primary slave for port_id",
5824                 .data = NULL,
5825                 .tokens = {
5826                                 (void *)&cmd_setbonding_primary_set,
5827                                 (void *)&cmd_setbonding_primary_bonding,
5828                                 (void *)&cmd_setbonding_primary_primary,
5829                                 (void *)&cmd_setbonding_primary_slave,
5830                                 (void *)&cmd_setbonding_primary_port,
5831                                 NULL
5832                 }
5833 };
5834
5835 /* *** ADD SLAVE *** */
5836 struct cmd_add_bonding_slave_result {
5837         cmdline_fixed_string_t add;
5838         cmdline_fixed_string_t bonding;
5839         cmdline_fixed_string_t slave;
5840         portid_t slave_id;
5841         portid_t port_id;
5842 };
5843
5844 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5845                 __attribute__((unused))  struct cmdline *cl,
5846                 __attribute__((unused)) void *data)
5847 {
5848         struct cmd_add_bonding_slave_result *res = parsed_result;
5849         portid_t master_port_id = res->port_id;
5850         portid_t slave_port_id = res->slave_id;
5851
5852         /* add the slave for a bonded device. */
5853         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5854                 printf("\t Failed to add slave %d to master port = %d.\n",
5855                                 slave_port_id, master_port_id);
5856                 return;
5857         }
5858         init_port_config();
5859         set_port_slave_flag(slave_port_id);
5860 }
5861
5862 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5863 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5864                 add, "add");
5865 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5866 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5867                 bonding, "bonding");
5868 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5869 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5870                 slave, "slave");
5871 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5872 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5873                 slave_id, UINT16);
5874 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5875 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5876                 port_id, UINT16);
5877
5878 cmdline_parse_inst_t cmd_add_bonding_slave = {
5879                 .f = cmd_add_bonding_slave_parsed,
5880                 .help_str = "add bonding slave <slave_id> <port_id>: "
5881                         "Add a slave device to a bonded device",
5882                 .data = NULL,
5883                 .tokens = {
5884                                 (void *)&cmd_addbonding_slave_add,
5885                                 (void *)&cmd_addbonding_slave_bonding,
5886                                 (void *)&cmd_addbonding_slave_slave,
5887                                 (void *)&cmd_addbonding_slave_slaveid,
5888                                 (void *)&cmd_addbonding_slave_port,
5889                                 NULL
5890                 }
5891 };
5892
5893 /* *** REMOVE SLAVE *** */
5894 struct cmd_remove_bonding_slave_result {
5895         cmdline_fixed_string_t remove;
5896         cmdline_fixed_string_t bonding;
5897         cmdline_fixed_string_t slave;
5898         portid_t slave_id;
5899         portid_t port_id;
5900 };
5901
5902 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5903                 __attribute__((unused))  struct cmdline *cl,
5904                 __attribute__((unused)) void *data)
5905 {
5906         struct cmd_remove_bonding_slave_result *res = parsed_result;
5907         portid_t master_port_id = res->port_id;
5908         portid_t slave_port_id = res->slave_id;
5909
5910         /* remove the slave from a bonded device. */
5911         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5912                 printf("\t Failed to remove slave %d from master port = %d.\n",
5913                                 slave_port_id, master_port_id);
5914                 return;
5915         }
5916         init_port_config();
5917         clear_port_slave_flag(slave_port_id);
5918 }
5919
5920 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5921                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5922                                 remove, "remove");
5923 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5924                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5925                                 bonding, "bonding");
5926 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5927                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5928                                 slave, "slave");
5929 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5930                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5931                                 slave_id, UINT16);
5932 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5933                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5934                                 port_id, UINT16);
5935
5936 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5937                 .f = cmd_remove_bonding_slave_parsed,
5938                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5939                         "Remove a slave device from a bonded device",
5940                 .data = NULL,
5941                 .tokens = {
5942                                 (void *)&cmd_removebonding_slave_remove,
5943                                 (void *)&cmd_removebonding_slave_bonding,
5944                                 (void *)&cmd_removebonding_slave_slave,
5945                                 (void *)&cmd_removebonding_slave_slaveid,
5946                                 (void *)&cmd_removebonding_slave_port,
5947                                 NULL
5948                 }
5949 };
5950
5951 /* *** CREATE BONDED DEVICE *** */
5952 struct cmd_create_bonded_device_result {
5953         cmdline_fixed_string_t create;
5954         cmdline_fixed_string_t bonded;
5955         cmdline_fixed_string_t device;
5956         uint8_t mode;
5957         uint8_t socket;
5958 };
5959
5960 static int bond_dev_num = 0;
5961
5962 static void cmd_create_bonded_device_parsed(void *parsed_result,
5963                 __attribute__((unused))  struct cmdline *cl,
5964                 __attribute__((unused)) void *data)
5965 {
5966         struct cmd_create_bonded_device_result *res = parsed_result;
5967         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5968         int port_id;
5969
5970         if (test_done == 0) {
5971                 printf("Please stop forwarding first\n");
5972                 return;
5973         }
5974
5975         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5976                         bond_dev_num++);
5977
5978         /* Create a new bonded device. */
5979         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5980         if (port_id < 0) {
5981                 printf("\t Failed to create bonded device.\n");
5982                 return;
5983         } else {
5984                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5985                                 port_id);
5986
5987                 /* Update number of ports */
5988                 nb_ports = rte_eth_dev_count_avail();
5989                 reconfig(port_id, res->socket);
5990                 rte_eth_promiscuous_enable(port_id);
5991                 ports[port_id].need_setup = 0;
5992                 ports[port_id].port_status = RTE_PORT_STOPPED;
5993         }
5994
5995 }
5996
5997 cmdline_parse_token_string_t cmd_createbonded_device_create =
5998                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5999                                 create, "create");
6000 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6001                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6002                                 bonded, "bonded");
6003 cmdline_parse_token_string_t cmd_createbonded_device_device =
6004                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6005                                 device, "device");
6006 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6007                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6008                                 mode, UINT8);
6009 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6010                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6011                                 socket, UINT8);
6012
6013 cmdline_parse_inst_t cmd_create_bonded_device = {
6014                 .f = cmd_create_bonded_device_parsed,
6015                 .help_str = "create bonded device <mode> <socket>: "
6016                         "Create a new bonded device with specific bonding mode and socket",
6017                 .data = NULL,
6018                 .tokens = {
6019                                 (void *)&cmd_createbonded_device_create,
6020                                 (void *)&cmd_createbonded_device_bonded,
6021                                 (void *)&cmd_createbonded_device_device,
6022                                 (void *)&cmd_createbonded_device_mode,
6023                                 (void *)&cmd_createbonded_device_socket,
6024                                 NULL
6025                 }
6026 };
6027
6028 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6029 struct cmd_set_bond_mac_addr_result {
6030         cmdline_fixed_string_t set;
6031         cmdline_fixed_string_t bonding;
6032         cmdline_fixed_string_t mac_addr;
6033         uint16_t port_num;
6034         struct ether_addr address;
6035 };
6036
6037 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6038                 __attribute__((unused))  struct cmdline *cl,
6039                 __attribute__((unused)) void *data)
6040 {
6041         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6042         int ret;
6043
6044         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6045                 return;
6046
6047         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6048
6049         /* check the return value and print it if is < 0 */
6050         if (ret < 0)
6051                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6052 }
6053
6054 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6055                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6056 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6057                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6058                                 "bonding");
6059 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6060                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6061                                 "mac_addr");
6062 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6063                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6064                                 port_num, UINT16);
6065 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6066                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6067
6068 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6069                 .f = cmd_set_bond_mac_addr_parsed,
6070                 .data = (void *) 0,
6071                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6072                 .tokens = {
6073                                 (void *)&cmd_set_bond_mac_addr_set,
6074                                 (void *)&cmd_set_bond_mac_addr_bonding,
6075                                 (void *)&cmd_set_bond_mac_addr_mac,
6076                                 (void *)&cmd_set_bond_mac_addr_portnum,
6077                                 (void *)&cmd_set_bond_mac_addr_addr,
6078                                 NULL
6079                 }
6080 };
6081
6082
6083 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6084 struct cmd_set_bond_mon_period_result {
6085         cmdline_fixed_string_t set;
6086         cmdline_fixed_string_t bonding;
6087         cmdline_fixed_string_t mon_period;
6088         uint16_t port_num;
6089         uint32_t period_ms;
6090 };
6091
6092 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6093                 __attribute__((unused))  struct cmdline *cl,
6094                 __attribute__((unused)) void *data)
6095 {
6096         struct cmd_set_bond_mon_period_result *res = parsed_result;
6097         int ret;
6098
6099         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6100
6101         /* check the return value and print it if is < 0 */
6102         if (ret < 0)
6103                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6104 }
6105
6106 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6107                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6108                                 set, "set");
6109 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6110                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6111                                 bonding, "bonding");
6112 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6113                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6114                                 mon_period,     "mon_period");
6115 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6116                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6117                                 port_num, UINT16);
6118 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6119                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6120                                 period_ms, UINT32);
6121
6122 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6123                 .f = cmd_set_bond_mon_period_parsed,
6124                 .data = (void *) 0,
6125                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6126                 .tokens = {
6127                                 (void *)&cmd_set_bond_mon_period_set,
6128                                 (void *)&cmd_set_bond_mon_period_bonding,
6129                                 (void *)&cmd_set_bond_mon_period_mon_period,
6130                                 (void *)&cmd_set_bond_mon_period_portnum,
6131                                 (void *)&cmd_set_bond_mon_period_period_ms,
6132                                 NULL
6133                 }
6134 };
6135
6136
6137
6138 struct cmd_set_bonding_agg_mode_policy_result {
6139         cmdline_fixed_string_t set;
6140         cmdline_fixed_string_t bonding;
6141         cmdline_fixed_string_t agg_mode;
6142         uint16_t port_num;
6143         cmdline_fixed_string_t policy;
6144 };
6145
6146
6147 static void
6148 cmd_set_bonding_agg_mode(void *parsed_result,
6149                 __attribute__((unused)) struct cmdline *cl,
6150                 __attribute__((unused)) void *data)
6151 {
6152         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6153         uint8_t policy = AGG_BANDWIDTH;
6154
6155         if (!strcmp(res->policy, "bandwidth"))
6156                 policy = AGG_BANDWIDTH;
6157         else if (!strcmp(res->policy, "stable"))
6158                 policy = AGG_STABLE;
6159         else if (!strcmp(res->policy, "count"))
6160                 policy = AGG_COUNT;
6161
6162         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6163 }
6164
6165
6166 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6167         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6168                                 set, "set");
6169 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6170         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6171                                 bonding, "bonding");
6172
6173 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6174         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6175                                 agg_mode, "agg_mode");
6176
6177 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6178         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6179                                 port_num, UINT16);
6180
6181 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6182         TOKEN_STRING_INITIALIZER(
6183                         struct cmd_set_bonding_balance_xmit_policy_result,
6184                 policy, "stable#bandwidth#count");
6185
6186 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6187         .f = cmd_set_bonding_agg_mode,
6188         .data = (void *) 0,
6189         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6190         .tokens = {
6191                         (void *)&cmd_set_bonding_agg_mode_set,
6192                         (void *)&cmd_set_bonding_agg_mode_bonding,
6193                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6194                         (void *)&cmd_set_bonding_agg_mode_portnum,
6195                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6196                         NULL
6197                 }
6198 };
6199
6200
6201 #endif /* RTE_LIBRTE_PMD_BOND */
6202
6203 /* *** SET FORWARDING MODE *** */
6204 struct cmd_set_fwd_mode_result {
6205         cmdline_fixed_string_t set;
6206         cmdline_fixed_string_t fwd;
6207         cmdline_fixed_string_t mode;
6208 };
6209
6210 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6211                                     __attribute__((unused)) struct cmdline *cl,
6212                                     __attribute__((unused)) void *data)
6213 {
6214         struct cmd_set_fwd_mode_result *res = parsed_result;
6215
6216         retry_enabled = 0;
6217         set_pkt_forwarding_mode(res->mode);
6218 }
6219
6220 cmdline_parse_token_string_t cmd_setfwd_set =
6221         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6222 cmdline_parse_token_string_t cmd_setfwd_fwd =
6223         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6224 cmdline_parse_token_string_t cmd_setfwd_mode =
6225         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6226                 "" /* defined at init */);
6227
6228 cmdline_parse_inst_t cmd_set_fwd_mode = {
6229         .f = cmd_set_fwd_mode_parsed,
6230         .data = NULL,
6231         .help_str = NULL, /* defined at init */
6232         .tokens = {
6233                 (void *)&cmd_setfwd_set,
6234                 (void *)&cmd_setfwd_fwd,
6235                 (void *)&cmd_setfwd_mode,
6236                 NULL,
6237         },
6238 };
6239
6240 static void cmd_set_fwd_mode_init(void)
6241 {
6242         char *modes, *c;
6243         static char token[128];
6244         static char help[256];
6245         cmdline_parse_token_string_t *token_struct;
6246
6247         modes = list_pkt_forwarding_modes();
6248         snprintf(help, sizeof(help), "set fwd %s: "
6249                 "Set packet forwarding mode", modes);
6250         cmd_set_fwd_mode.help_str = help;
6251
6252         /* string token separator is # */
6253         for (c = token; *modes != '\0'; modes++)
6254                 if (*modes == '|')
6255                         *c++ = '#';
6256                 else
6257                         *c++ = *modes;
6258         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6259         token_struct->string_data.str = token;
6260 }
6261
6262 /* *** SET RETRY FORWARDING MODE *** */
6263 struct cmd_set_fwd_retry_mode_result {
6264         cmdline_fixed_string_t set;
6265         cmdline_fixed_string_t fwd;
6266         cmdline_fixed_string_t mode;
6267         cmdline_fixed_string_t retry;
6268 };
6269
6270 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6271                             __attribute__((unused)) struct cmdline *cl,
6272                             __attribute__((unused)) void *data)
6273 {
6274         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6275
6276         retry_enabled = 1;
6277         set_pkt_forwarding_mode(res->mode);
6278 }
6279
6280 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6281         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6282                         set, "set");
6283 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6284         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6285                         fwd, "fwd");
6286 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6287         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6288                         mode,
6289                 "" /* defined at init */);
6290 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6291         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6292                         retry, "retry");
6293
6294 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6295         .f = cmd_set_fwd_retry_mode_parsed,
6296         .data = NULL,
6297         .help_str = NULL, /* defined at init */
6298         .tokens = {
6299                 (void *)&cmd_setfwd_retry_set,
6300                 (void *)&cmd_setfwd_retry_fwd,
6301                 (void *)&cmd_setfwd_retry_mode,
6302                 (void *)&cmd_setfwd_retry_retry,
6303                 NULL,
6304         },
6305 };
6306
6307 static void cmd_set_fwd_retry_mode_init(void)
6308 {
6309         char *modes, *c;
6310         static char token[128];
6311         static char help[256];
6312         cmdline_parse_token_string_t *token_struct;
6313
6314         modes = list_pkt_forwarding_retry_modes();
6315         snprintf(help, sizeof(help), "set fwd %s retry: "
6316                 "Set packet forwarding mode with retry", modes);
6317         cmd_set_fwd_retry_mode.help_str = help;
6318
6319         /* string token separator is # */
6320         for (c = token; *modes != '\0'; modes++)
6321                 if (*modes == '|')
6322                         *c++ = '#';
6323                 else
6324                         *c++ = *modes;
6325         token_struct = (cmdline_parse_token_string_t *)
6326                 cmd_set_fwd_retry_mode.tokens[2];
6327         token_struct->string_data.str = token;
6328 }
6329
6330 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6331 struct cmd_set_burst_tx_retry_result {
6332         cmdline_fixed_string_t set;
6333         cmdline_fixed_string_t burst;
6334         cmdline_fixed_string_t tx;
6335         cmdline_fixed_string_t delay;
6336         uint32_t time;
6337         cmdline_fixed_string_t retry;
6338         uint32_t retry_num;
6339 };
6340
6341 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6342                                         __attribute__((unused)) struct cmdline *cl,
6343                                         __attribute__((unused)) void *data)
6344 {
6345         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6346
6347         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6348                 && !strcmp(res->tx, "tx")) {
6349                 if (!strcmp(res->delay, "delay"))
6350                         burst_tx_delay_time = res->time;
6351                 if (!strcmp(res->retry, "retry"))
6352                         burst_tx_retry_num = res->retry_num;
6353         }
6354
6355 }
6356
6357 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6358         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6359 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6360         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6361                                  "burst");
6362 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6363         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6364 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6365         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6366 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6367         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6368 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6369         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6370 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6371         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6372
6373 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6374         .f = cmd_set_burst_tx_retry_parsed,
6375         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6376         .tokens = {
6377                 (void *)&cmd_set_burst_tx_retry_set,
6378                 (void *)&cmd_set_burst_tx_retry_burst,
6379                 (void *)&cmd_set_burst_tx_retry_tx,
6380                 (void *)&cmd_set_burst_tx_retry_delay,
6381                 (void *)&cmd_set_burst_tx_retry_time,
6382                 (void *)&cmd_set_burst_tx_retry_retry,
6383                 (void *)&cmd_set_burst_tx_retry_retry_num,
6384                 NULL,
6385         },
6386 };
6387
6388 /* *** SET PROMISC MODE *** */
6389 struct cmd_set_promisc_mode_result {
6390         cmdline_fixed_string_t set;
6391         cmdline_fixed_string_t promisc;
6392         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6393         uint16_t port_num;               /* valid if "allports" argument == 0 */
6394         cmdline_fixed_string_t mode;
6395 };
6396
6397 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6398                                         __attribute__((unused)) struct cmdline *cl,
6399                                         void *allports)
6400 {
6401         struct cmd_set_promisc_mode_result *res = parsed_result;
6402         int enable;
6403         portid_t i;
6404
6405         if (!strcmp(res->mode, "on"))
6406                 enable = 1;
6407         else
6408                 enable = 0;
6409
6410         /* all ports */
6411         if (allports) {
6412                 RTE_ETH_FOREACH_DEV(i) {
6413                         if (enable)
6414                                 rte_eth_promiscuous_enable(i);
6415                         else
6416                                 rte_eth_promiscuous_disable(i);
6417                 }
6418         }
6419         else {
6420                 if (enable)
6421                         rte_eth_promiscuous_enable(res->port_num);
6422                 else
6423                         rte_eth_promiscuous_disable(res->port_num);
6424         }
6425 }
6426
6427 cmdline_parse_token_string_t cmd_setpromisc_set =
6428         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6429 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6430         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6431                                  "promisc");
6432 cmdline_parse_token_string_t cmd_setpromisc_portall =
6433         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6434                                  "all");
6435 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6436         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6437                               UINT16);
6438 cmdline_parse_token_string_t cmd_setpromisc_mode =
6439         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6440                                  "on#off");
6441
6442 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6443         .f = cmd_set_promisc_mode_parsed,
6444         .data = (void *)1,
6445         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6446         .tokens = {
6447                 (void *)&cmd_setpromisc_set,
6448                 (void *)&cmd_setpromisc_promisc,
6449                 (void *)&cmd_setpromisc_portall,
6450                 (void *)&cmd_setpromisc_mode,
6451                 NULL,
6452         },
6453 };
6454
6455 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6456         .f = cmd_set_promisc_mode_parsed,
6457         .data = (void *)0,
6458         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6459         .tokens = {
6460                 (void *)&cmd_setpromisc_set,
6461                 (void *)&cmd_setpromisc_promisc,
6462                 (void *)&cmd_setpromisc_portnum,
6463                 (void *)&cmd_setpromisc_mode,
6464                 NULL,
6465         },
6466 };
6467
6468 /* *** SET ALLMULTI MODE *** */
6469 struct cmd_set_allmulti_mode_result {
6470         cmdline_fixed_string_t set;
6471         cmdline_fixed_string_t allmulti;
6472         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6473         uint16_t port_num;               /* valid if "allports" argument == 0 */
6474         cmdline_fixed_string_t mode;
6475 };
6476
6477 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6478                                         __attribute__((unused)) struct cmdline *cl,
6479                                         void *allports)
6480 {
6481         struct cmd_set_allmulti_mode_result *res = parsed_result;
6482         int enable;
6483         portid_t i;
6484
6485         if (!strcmp(res->mode, "on"))
6486                 enable = 1;
6487         else
6488                 enable = 0;
6489
6490         /* all ports */
6491         if (allports) {
6492                 RTE_ETH_FOREACH_DEV(i) {
6493                         if (enable)
6494                                 rte_eth_allmulticast_enable(i);
6495                         else
6496                                 rte_eth_allmulticast_disable(i);
6497                 }
6498         }
6499         else {
6500                 if (enable)
6501                         rte_eth_allmulticast_enable(res->port_num);
6502                 else
6503                         rte_eth_allmulticast_disable(res->port_num);
6504         }
6505 }
6506
6507 cmdline_parse_token_string_t cmd_setallmulti_set =
6508         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6509 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6510         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6511                                  "allmulti");
6512 cmdline_parse_token_string_t cmd_setallmulti_portall =
6513         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6514                                  "all");
6515 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6516         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6517                               UINT16);
6518 cmdline_parse_token_string_t cmd_setallmulti_mode =
6519         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6520                                  "on#off");
6521
6522 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6523         .f = cmd_set_allmulti_mode_parsed,
6524         .data = (void *)1,
6525         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6526         .tokens = {
6527                 (void *)&cmd_setallmulti_set,
6528                 (void *)&cmd_setallmulti_allmulti,
6529                 (void *)&cmd_setallmulti_portall,
6530                 (void *)&cmd_setallmulti_mode,
6531                 NULL,
6532         },
6533 };
6534
6535 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6536         .f = cmd_set_allmulti_mode_parsed,
6537         .data = (void *)0,
6538         .help_str = "set allmulti <port_id> on|off: "
6539                 "Set allmulti mode on port_id",
6540         .tokens = {
6541                 (void *)&cmd_setallmulti_set,
6542                 (void *)&cmd_setallmulti_allmulti,
6543                 (void *)&cmd_setallmulti_portnum,
6544                 (void *)&cmd_setallmulti_mode,
6545                 NULL,
6546         },
6547 };
6548
6549 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6550 struct cmd_link_flow_ctrl_set_result {
6551         cmdline_fixed_string_t set;
6552         cmdline_fixed_string_t flow_ctrl;
6553         cmdline_fixed_string_t rx;
6554         cmdline_fixed_string_t rx_lfc_mode;
6555         cmdline_fixed_string_t tx;
6556         cmdline_fixed_string_t tx_lfc_mode;
6557         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6558         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6559         cmdline_fixed_string_t autoneg_str;
6560         cmdline_fixed_string_t autoneg;
6561         cmdline_fixed_string_t hw_str;
6562         uint32_t high_water;
6563         cmdline_fixed_string_t lw_str;
6564         uint32_t low_water;
6565         cmdline_fixed_string_t pt_str;
6566         uint16_t pause_time;
6567         cmdline_fixed_string_t xon_str;
6568         uint16_t send_xon;
6569         portid_t port_id;
6570 };
6571
6572 cmdline_parse_token_string_t cmd_lfc_set_set =
6573         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6574                                 set, "set");
6575 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6576         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6577                                 flow_ctrl, "flow_ctrl");
6578 cmdline_parse_token_string_t cmd_lfc_set_rx =
6579         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6580                                 rx, "rx");
6581 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6582         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6583                                 rx_lfc_mode, "on#off");
6584 cmdline_parse_token_string_t cmd_lfc_set_tx =
6585         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6586                                 tx, "tx");
6587 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6588         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6589                                 tx_lfc_mode, "on#off");
6590 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6591         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6592                                 hw_str, "high_water");
6593 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6594         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6595                                 high_water, UINT32);
6596 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6597         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6598                                 lw_str, "low_water");
6599 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6600         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6601                                 low_water, UINT32);
6602 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6603         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6604                                 pt_str, "pause_time");
6605 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6606         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6607                                 pause_time, UINT16);
6608 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6609         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6610                                 xon_str, "send_xon");
6611 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6612         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6613                                 send_xon, UINT16);
6614 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6615         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6616                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6617 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6618         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6619                                 mac_ctrl_frame_fwd_mode, "on#off");
6620 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6621         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6622                                 autoneg_str, "autoneg");
6623 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6624         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6625                                 autoneg, "on#off");
6626 cmdline_parse_token_num_t cmd_lfc_set_portid =
6627         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6628                                 port_id, UINT16);
6629
6630 /* forward declaration */
6631 static void
6632 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6633                               void *data);
6634
6635 cmdline_parse_inst_t cmd_link_flow_control_set = {
6636         .f = cmd_link_flow_ctrl_set_parsed,
6637         .data = NULL,
6638         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6639                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6640                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6641         .tokens = {
6642                 (void *)&cmd_lfc_set_set,
6643                 (void *)&cmd_lfc_set_flow_ctrl,
6644                 (void *)&cmd_lfc_set_rx,
6645                 (void *)&cmd_lfc_set_rx_mode,
6646                 (void *)&cmd_lfc_set_tx,
6647                 (void *)&cmd_lfc_set_tx_mode,
6648                 (void *)&cmd_lfc_set_high_water,
6649                 (void *)&cmd_lfc_set_low_water,
6650                 (void *)&cmd_lfc_set_pause_time,
6651                 (void *)&cmd_lfc_set_send_xon,
6652                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6653                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6654                 (void *)&cmd_lfc_set_autoneg_str,
6655                 (void *)&cmd_lfc_set_autoneg,
6656                 (void *)&cmd_lfc_set_portid,
6657                 NULL,
6658         },
6659 };
6660
6661 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6662         .f = cmd_link_flow_ctrl_set_parsed,
6663         .data = (void *)&cmd_link_flow_control_set_rx,
6664         .help_str = "set flow_ctrl rx on|off <port_id>: "
6665                 "Change rx flow control parameter",
6666         .tokens = {
6667                 (void *)&cmd_lfc_set_set,
6668                 (void *)&cmd_lfc_set_flow_ctrl,
6669                 (void *)&cmd_lfc_set_rx,
6670                 (void *)&cmd_lfc_set_rx_mode,
6671                 (void *)&cmd_lfc_set_portid,
6672                 NULL,
6673         },
6674 };
6675
6676 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6677         .f = cmd_link_flow_ctrl_set_parsed,
6678         .data = (void *)&cmd_link_flow_control_set_tx,
6679         .help_str = "set flow_ctrl tx on|off <port_id>: "
6680                 "Change tx flow control parameter",
6681         .tokens = {
6682                 (void *)&cmd_lfc_set_set,
6683                 (void *)&cmd_lfc_set_flow_ctrl,
6684                 (void *)&cmd_lfc_set_tx,
6685                 (void *)&cmd_lfc_set_tx_mode,
6686                 (void *)&cmd_lfc_set_portid,
6687                 NULL,
6688         },
6689 };
6690
6691 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6692         .f = cmd_link_flow_ctrl_set_parsed,
6693         .data = (void *)&cmd_link_flow_control_set_hw,
6694         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6695                 "Change high water flow control parameter",
6696         .tokens = {
6697                 (void *)&cmd_lfc_set_set,
6698                 (void *)&cmd_lfc_set_flow_ctrl,
6699                 (void *)&cmd_lfc_set_high_water_str,
6700                 (void *)&cmd_lfc_set_high_water,
6701                 (void *)&cmd_lfc_set_portid,
6702                 NULL,
6703         },
6704 };
6705
6706 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6707         .f = cmd_link_flow_ctrl_set_parsed,
6708         .data = (void *)&cmd_link_flow_control_set_lw,
6709         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6710                 "Change low water flow control parameter",
6711         .tokens = {
6712                 (void *)&cmd_lfc_set_set,
6713                 (void *)&cmd_lfc_set_flow_ctrl,
6714                 (void *)&cmd_lfc_set_low_water_str,
6715                 (void *)&cmd_lfc_set_low_water,
6716                 (void *)&cmd_lfc_set_portid,
6717                 NULL,
6718         },
6719 };
6720
6721 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6722         .f = cmd_link_flow_ctrl_set_parsed,
6723         .data = (void *)&cmd_link_flow_control_set_pt,
6724         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6725                 "Change pause time flow control parameter",
6726         .tokens = {
6727                 (void *)&cmd_lfc_set_set,
6728                 (void *)&cmd_lfc_set_flow_ctrl,
6729                 (void *)&cmd_lfc_set_pause_time_str,
6730                 (void *)&cmd_lfc_set_pause_time,
6731                 (void *)&cmd_lfc_set_portid,
6732                 NULL,
6733         },
6734 };
6735
6736 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6737         .f = cmd_link_flow_ctrl_set_parsed,
6738         .data = (void *)&cmd_link_flow_control_set_xon,
6739         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6740                 "Change send_xon flow control parameter",
6741         .tokens = {
6742                 (void *)&cmd_lfc_set_set,
6743                 (void *)&cmd_lfc_set_flow_ctrl,
6744                 (void *)&cmd_lfc_set_send_xon_str,
6745                 (void *)&cmd_lfc_set_send_xon,
6746                 (void *)&cmd_lfc_set_portid,
6747                 NULL,
6748         },
6749 };
6750
6751 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6752         .f = cmd_link_flow_ctrl_set_parsed,
6753         .data = (void *)&cmd_link_flow_control_set_macfwd,
6754         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6755                 "Change mac ctrl fwd flow control parameter",
6756         .tokens = {
6757                 (void *)&cmd_lfc_set_set,
6758                 (void *)&cmd_lfc_set_flow_ctrl,
6759                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6760                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6761                 (void *)&cmd_lfc_set_portid,
6762                 NULL,
6763         },
6764 };
6765
6766 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6767         .f = cmd_link_flow_ctrl_set_parsed,
6768         .data = (void *)&cmd_link_flow_control_set_autoneg,
6769         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6770                 "Change autoneg flow control parameter",
6771         .tokens = {
6772                 (void *)&cmd_lfc_set_set,
6773                 (void *)&cmd_lfc_set_flow_ctrl,
6774                 (void *)&cmd_lfc_set_autoneg_str,
6775                 (void *)&cmd_lfc_set_autoneg,
6776                 (void *)&cmd_lfc_set_portid,
6777                 NULL,
6778         },
6779 };
6780
6781 static void
6782 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6783                               __attribute__((unused)) struct cmdline *cl,
6784                               void *data)
6785 {
6786         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6787         cmdline_parse_inst_t *cmd = data;
6788         struct rte_eth_fc_conf fc_conf;
6789         int rx_fc_en = 0;
6790         int tx_fc_en = 0;
6791         int ret;
6792
6793         /*
6794          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6795          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6796          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6797          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6798          */
6799         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6800                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6801         };
6802
6803         /* Partial command line, retrieve current configuration */
6804         if (cmd) {
6805                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6806                 if (ret != 0) {
6807                         printf("cannot get current flow ctrl parameters, return"
6808                                "code = %d\n", ret);
6809                         return;
6810                 }
6811
6812                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6813                     (fc_conf.mode == RTE_FC_FULL))
6814                         rx_fc_en = 1;
6815                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6816                     (fc_conf.mode == RTE_FC_FULL))
6817                         tx_fc_en = 1;
6818         }
6819
6820         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6821                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6822
6823         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6824                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6825
6826         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6827
6828         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6829                 fc_conf.high_water = res->high_water;
6830
6831         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6832                 fc_conf.low_water = res->low_water;
6833
6834         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6835                 fc_conf.pause_time = res->pause_time;
6836
6837         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6838                 fc_conf.send_xon = res->send_xon;
6839
6840         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6841                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6842                         fc_conf.mac_ctrl_frame_fwd = 1;
6843                 else
6844                         fc_conf.mac_ctrl_frame_fwd = 0;
6845         }
6846
6847         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6848                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6849
6850         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6851         if (ret != 0)
6852                 printf("bad flow contrl parameter, return code = %d \n", ret);
6853 }
6854
6855 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6856 struct cmd_priority_flow_ctrl_set_result {
6857         cmdline_fixed_string_t set;
6858         cmdline_fixed_string_t pfc_ctrl;
6859         cmdline_fixed_string_t rx;
6860         cmdline_fixed_string_t rx_pfc_mode;
6861         cmdline_fixed_string_t tx;
6862         cmdline_fixed_string_t tx_pfc_mode;
6863         uint32_t high_water;
6864         uint32_t low_water;
6865         uint16_t pause_time;
6866         uint8_t  priority;
6867         portid_t port_id;
6868 };
6869
6870 static void
6871 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6872                        __attribute__((unused)) struct cmdline *cl,
6873                        __attribute__((unused)) void *data)
6874 {
6875         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6876         struct rte_eth_pfc_conf pfc_conf;
6877         int rx_fc_enable, tx_fc_enable;
6878         int ret;
6879
6880         /*
6881          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6882          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6883          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6884          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6885          */
6886         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6887                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6888         };
6889
6890         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6891         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6892         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6893         pfc_conf.fc.high_water = res->high_water;
6894         pfc_conf.fc.low_water  = res->low_water;
6895         pfc_conf.fc.pause_time = res->pause_time;
6896         pfc_conf.priority      = res->priority;
6897
6898         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6899         if (ret != 0)
6900                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6901 }
6902
6903 cmdline_parse_token_string_t cmd_pfc_set_set =
6904         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6905                                 set, "set");
6906 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6907         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6908                                 pfc_ctrl, "pfc_ctrl");
6909 cmdline_parse_token_string_t cmd_pfc_set_rx =
6910         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6911                                 rx, "rx");
6912 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6913         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6914                                 rx_pfc_mode, "on#off");
6915 cmdline_parse_token_string_t cmd_pfc_set_tx =
6916         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6917                                 tx, "tx");
6918 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6919         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6920                                 tx_pfc_mode, "on#off");
6921 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6922         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6923                                 high_water, UINT32);
6924 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6925         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6926                                 low_water, UINT32);
6927 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6928         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6929                                 pause_time, UINT16);
6930 cmdline_parse_token_num_t cmd_pfc_set_priority =
6931         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6932                                 priority, UINT8);
6933 cmdline_parse_token_num_t cmd_pfc_set_portid =
6934         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6935                                 port_id, UINT16);
6936
6937 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6938         .f = cmd_priority_flow_ctrl_set_parsed,
6939         .data = NULL,
6940         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6941                 "<pause_time> <priority> <port_id>: "
6942                 "Configure the Ethernet priority flow control",
6943         .tokens = {
6944                 (void *)&cmd_pfc_set_set,
6945                 (void *)&cmd_pfc_set_flow_ctrl,
6946                 (void *)&cmd_pfc_set_rx,
6947                 (void *)&cmd_pfc_set_rx_mode,
6948                 (void *)&cmd_pfc_set_tx,
6949                 (void *)&cmd_pfc_set_tx_mode,
6950                 (void *)&cmd_pfc_set_high_water,
6951                 (void *)&cmd_pfc_set_low_water,
6952                 (void *)&cmd_pfc_set_pause_time,
6953                 (void *)&cmd_pfc_set_priority,
6954                 (void *)&cmd_pfc_set_portid,
6955                 NULL,
6956         },
6957 };
6958
6959 /* *** RESET CONFIGURATION *** */
6960 struct cmd_reset_result {
6961         cmdline_fixed_string_t reset;
6962         cmdline_fixed_string_t def;
6963 };
6964
6965 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6966                              struct cmdline *cl,
6967                              __attribute__((unused)) void *data)
6968 {
6969         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6970         set_def_fwd_config();
6971 }
6972
6973 cmdline_parse_token_string_t cmd_reset_set =
6974         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6975 cmdline_parse_token_string_t cmd_reset_def =
6976         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6977                                  "default");
6978
6979 cmdline_parse_inst_t cmd_reset = {
6980         .f = cmd_reset_parsed,
6981         .data = NULL,
6982         .help_str = "set default: Reset default forwarding configuration",
6983         .tokens = {
6984                 (void *)&cmd_reset_set,
6985                 (void *)&cmd_reset_def,
6986                 NULL,
6987         },
6988 };
6989
6990 /* *** START FORWARDING *** */
6991 struct cmd_start_result {
6992         cmdline_fixed_string_t start;
6993 };
6994
6995 cmdline_parse_token_string_t cmd_start_start =
6996         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6997
6998 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6999                              __attribute__((unused)) struct cmdline *cl,
7000                              __attribute__((unused)) void *data)
7001 {
7002         start_packet_forwarding(0);
7003 }
7004
7005 cmdline_parse_inst_t cmd_start = {
7006         .f = cmd_start_parsed,
7007         .data = NULL,
7008         .help_str = "start: Start packet forwarding",
7009         .tokens = {
7010                 (void *)&cmd_start_start,
7011                 NULL,
7012         },
7013 };
7014
7015 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7016 struct cmd_start_tx_first_result {
7017         cmdline_fixed_string_t start;
7018         cmdline_fixed_string_t tx_first;
7019 };
7020
7021 static void
7022 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7023                           __attribute__((unused)) struct cmdline *cl,
7024                           __attribute__((unused)) void *data)
7025 {
7026         start_packet_forwarding(1);
7027 }
7028
7029 cmdline_parse_token_string_t cmd_start_tx_first_start =
7030         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7031                                  "start");
7032 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7033         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7034                                  tx_first, "tx_first");
7035
7036 cmdline_parse_inst_t cmd_start_tx_first = {
7037         .f = cmd_start_tx_first_parsed,
7038         .data = NULL,
7039         .help_str = "start tx_first: Start packet forwarding, "
7040                 "after sending 1 burst of packets",
7041         .tokens = {
7042                 (void *)&cmd_start_tx_first_start,
7043                 (void *)&cmd_start_tx_first_tx_first,
7044                 NULL,
7045         },
7046 };
7047
7048 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7049 struct cmd_start_tx_first_n_result {
7050         cmdline_fixed_string_t start;
7051         cmdline_fixed_string_t tx_first;
7052         uint32_t tx_num;
7053 };
7054
7055 static void
7056 cmd_start_tx_first_n_parsed(void *parsed_result,
7057                           __attribute__((unused)) struct cmdline *cl,
7058                           __attribute__((unused)) void *data)
7059 {
7060         struct cmd_start_tx_first_n_result *res = parsed_result;
7061
7062         start_packet_forwarding(res->tx_num);
7063 }
7064
7065 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7066         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7067                         start, "start");
7068 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7069         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7070                         tx_first, "tx_first");
7071 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7072         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7073                         tx_num, UINT32);
7074
7075 cmdline_parse_inst_t cmd_start_tx_first_n = {
7076         .f = cmd_start_tx_first_n_parsed,
7077         .data = NULL,
7078         .help_str = "start tx_first <num>: "
7079                 "packet forwarding, after sending <num> bursts of packets",
7080         .tokens = {
7081                 (void *)&cmd_start_tx_first_n_start,
7082                 (void *)&cmd_start_tx_first_n_tx_first,
7083                 (void *)&cmd_start_tx_first_n_tx_num,
7084                 NULL,
7085         },
7086 };
7087
7088 /* *** SET LINK UP *** */
7089 struct cmd_set_link_up_result {
7090         cmdline_fixed_string_t set;
7091         cmdline_fixed_string_t link_up;
7092         cmdline_fixed_string_t port;
7093         portid_t port_id;
7094 };
7095
7096 cmdline_parse_token_string_t cmd_set_link_up_set =
7097         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7098 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7099         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7100                                 "link-up");
7101 cmdline_parse_token_string_t cmd_set_link_up_port =
7102         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7103 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7104         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7105
7106 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7107                              __attribute__((unused)) struct cmdline *cl,
7108                              __attribute__((unused)) void *data)
7109 {
7110         struct cmd_set_link_up_result *res = parsed_result;
7111         dev_set_link_up(res->port_id);
7112 }
7113
7114 cmdline_parse_inst_t cmd_set_link_up = {
7115         .f = cmd_set_link_up_parsed,
7116         .data = NULL,
7117         .help_str = "set link-up port <port id>",
7118         .tokens = {
7119                 (void *)&cmd_set_link_up_set,
7120                 (void *)&cmd_set_link_up_link_up,
7121                 (void *)&cmd_set_link_up_port,
7122                 (void *)&cmd_set_link_up_port_id,
7123                 NULL,
7124         },
7125 };
7126
7127 /* *** SET LINK DOWN *** */
7128 struct cmd_set_link_down_result {
7129         cmdline_fixed_string_t set;
7130         cmdline_fixed_string_t link_down;
7131         cmdline_fixed_string_t port;
7132         portid_t port_id;
7133 };
7134
7135 cmdline_parse_token_string_t cmd_set_link_down_set =
7136         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7137 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7138         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7139                                 "link-down");
7140 cmdline_parse_token_string_t cmd_set_link_down_port =
7141         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7142 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7143         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7144
7145 static void cmd_set_link_down_parsed(
7146                                 __attribute__((unused)) void *parsed_result,
7147                                 __attribute__((unused)) struct cmdline *cl,
7148                                 __attribute__((unused)) void *data)
7149 {
7150         struct cmd_set_link_down_result *res = parsed_result;
7151         dev_set_link_down(res->port_id);
7152 }
7153
7154 cmdline_parse_inst_t cmd_set_link_down = {
7155         .f = cmd_set_link_down_parsed,
7156         .data = NULL,
7157         .help_str = "set link-down port <port id>",
7158         .tokens = {
7159                 (void *)&cmd_set_link_down_set,
7160                 (void *)&cmd_set_link_down_link_down,
7161                 (void *)&cmd_set_link_down_port,
7162                 (void *)&cmd_set_link_down_port_id,
7163                 NULL,
7164         },
7165 };
7166
7167 /* *** SHOW CFG *** */
7168 struct cmd_showcfg_result {
7169         cmdline_fixed_string_t show;
7170         cmdline_fixed_string_t cfg;
7171         cmdline_fixed_string_t what;
7172 };
7173
7174 static void cmd_showcfg_parsed(void *parsed_result,
7175                                __attribute__((unused)) struct cmdline *cl,
7176                                __attribute__((unused)) void *data)
7177 {
7178         struct cmd_showcfg_result *res = parsed_result;
7179         if (!strcmp(res->what, "rxtx"))
7180                 rxtx_config_display();
7181         else if (!strcmp(res->what, "cores"))
7182                 fwd_lcores_config_display();
7183         else if (!strcmp(res->what, "fwd"))
7184                 pkt_fwd_config_display(&cur_fwd_config);
7185         else if (!strcmp(res->what, "txpkts"))
7186                 show_tx_pkt_segments();
7187 }
7188
7189 cmdline_parse_token_string_t cmd_showcfg_show =
7190         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7191 cmdline_parse_token_string_t cmd_showcfg_port =
7192         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7193 cmdline_parse_token_string_t cmd_showcfg_what =
7194         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7195                                  "rxtx#cores#fwd#txpkts");
7196
7197 cmdline_parse_inst_t cmd_showcfg = {
7198         .f = cmd_showcfg_parsed,
7199         .data = NULL,
7200         .help_str = "show config rxtx|cores|fwd|txpkts",
7201         .tokens = {
7202                 (void *)&cmd_showcfg_show,
7203                 (void *)&cmd_showcfg_port,
7204                 (void *)&cmd_showcfg_what,
7205                 NULL,
7206         },
7207 };
7208
7209 /* *** SHOW ALL PORT INFO *** */
7210 struct cmd_showportall_result {
7211         cmdline_fixed_string_t show;
7212         cmdline_fixed_string_t port;
7213         cmdline_fixed_string_t what;
7214         cmdline_fixed_string_t all;
7215 };
7216
7217 static void cmd_showportall_parsed(void *parsed_result,
7218                                 __attribute__((unused)) struct cmdline *cl,
7219                                 __attribute__((unused)) void *data)
7220 {
7221         portid_t i;
7222
7223         struct cmd_showportall_result *res = parsed_result;
7224         if (!strcmp(res->show, "clear")) {
7225                 if (!strcmp(res->what, "stats"))
7226                         RTE_ETH_FOREACH_DEV(i)
7227                                 nic_stats_clear(i);
7228                 else if (!strcmp(res->what, "xstats"))
7229                         RTE_ETH_FOREACH_DEV(i)
7230                                 nic_xstats_clear(i);
7231         } else if (!strcmp(res->what, "info"))
7232                 RTE_ETH_FOREACH_DEV(i)
7233                         port_infos_display(i);
7234         else if (!strcmp(res->what, "summary")) {
7235                 port_summary_header_display();
7236                 RTE_ETH_FOREACH_DEV(i)
7237                         port_summary_display(i);
7238         }
7239         else if (!strcmp(res->what, "stats"))
7240                 RTE_ETH_FOREACH_DEV(i)
7241                         nic_stats_display(i);
7242         else if (!strcmp(res->what, "xstats"))
7243                 RTE_ETH_FOREACH_DEV(i)
7244                         nic_xstats_display(i);
7245         else if (!strcmp(res->what, "fdir"))
7246                 RTE_ETH_FOREACH_DEV(i)
7247                         fdir_get_infos(i);
7248         else if (!strcmp(res->what, "stat_qmap"))
7249                 RTE_ETH_FOREACH_DEV(i)
7250                         nic_stats_mapping_display(i);
7251         else if (!strcmp(res->what, "dcb_tc"))
7252                 RTE_ETH_FOREACH_DEV(i)
7253                         port_dcb_info_display(i);
7254         else if (!strcmp(res->what, "cap"))
7255                 RTE_ETH_FOREACH_DEV(i)
7256                         port_offload_cap_display(i);
7257 }
7258
7259 cmdline_parse_token_string_t cmd_showportall_show =
7260         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7261                                  "show#clear");
7262 cmdline_parse_token_string_t cmd_showportall_port =
7263         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7264 cmdline_parse_token_string_t cmd_showportall_what =
7265         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7266                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7267 cmdline_parse_token_string_t cmd_showportall_all =
7268         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7269 cmdline_parse_inst_t cmd_showportall = {
7270         .f = cmd_showportall_parsed,
7271         .data = NULL,
7272         .help_str = "show|clear port "
7273                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7274         .tokens = {
7275                 (void *)&cmd_showportall_show,
7276                 (void *)&cmd_showportall_port,
7277                 (void *)&cmd_showportall_what,
7278                 (void *)&cmd_showportall_all,
7279                 NULL,
7280         },
7281 };
7282
7283 /* *** SHOW PORT INFO *** */
7284 struct cmd_showport_result {
7285         cmdline_fixed_string_t show;
7286         cmdline_fixed_string_t port;
7287         cmdline_fixed_string_t what;
7288         uint16_t portnum;
7289 };
7290
7291 static void cmd_showport_parsed(void *parsed_result,
7292                                 __attribute__((unused)) struct cmdline *cl,
7293                                 __attribute__((unused)) void *data)
7294 {
7295         struct cmd_showport_result *res = parsed_result;
7296         if (!strcmp(res->show, "clear")) {
7297                 if (!strcmp(res->what, "stats"))
7298                         nic_stats_clear(res->portnum);
7299                 else if (!strcmp(res->what, "xstats"))
7300                         nic_xstats_clear(res->portnum);
7301         } else if (!strcmp(res->what, "info"))
7302                 port_infos_display(res->portnum);
7303         else if (!strcmp(res->what, "summary")) {
7304                 port_summary_header_display();
7305                 port_summary_display(res->portnum);
7306         }
7307         else if (!strcmp(res->what, "stats"))
7308                 nic_stats_display(res->portnum);
7309         else if (!strcmp(res->what, "xstats"))
7310                 nic_xstats_display(res->portnum);
7311         else if (!strcmp(res->what, "fdir"))
7312                  fdir_get_infos(res->portnum);
7313         else if (!strcmp(res->what, "stat_qmap"))
7314                 nic_stats_mapping_display(res->portnum);
7315         else if (!strcmp(res->what, "dcb_tc"))
7316                 port_dcb_info_display(res->portnum);
7317         else if (!strcmp(res->what, "cap"))
7318                 port_offload_cap_display(res->portnum);
7319 }
7320
7321 cmdline_parse_token_string_t cmd_showport_show =
7322         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7323                                  "show#clear");
7324 cmdline_parse_token_string_t cmd_showport_port =
7325         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7326 cmdline_parse_token_string_t cmd_showport_what =
7327         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7328                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7329 cmdline_parse_token_num_t cmd_showport_portnum =
7330         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7331
7332 cmdline_parse_inst_t cmd_showport = {
7333         .f = cmd_showport_parsed,
7334         .data = NULL,
7335         .help_str = "show|clear port "
7336                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7337                 "<port_id>",
7338         .tokens = {
7339                 (void *)&cmd_showport_show,
7340                 (void *)&cmd_showport_port,
7341                 (void *)&cmd_showport_what,
7342                 (void *)&cmd_showport_portnum,
7343                 NULL,
7344         },
7345 };
7346
7347 /* *** SHOW QUEUE INFO *** */
7348 struct cmd_showqueue_result {
7349         cmdline_fixed_string_t show;
7350         cmdline_fixed_string_t type;
7351         cmdline_fixed_string_t what;
7352         uint16_t portnum;
7353         uint16_t queuenum;
7354 };
7355
7356 static void
7357 cmd_showqueue_parsed(void *parsed_result,
7358         __attribute__((unused)) struct cmdline *cl,
7359         __attribute__((unused)) void *data)
7360 {
7361         struct cmd_showqueue_result *res = parsed_result;
7362
7363         if (!strcmp(res->type, "rxq"))
7364                 rx_queue_infos_display(res->portnum, res->queuenum);
7365         else if (!strcmp(res->type, "txq"))
7366                 tx_queue_infos_display(res->portnum, res->queuenum);
7367 }
7368
7369 cmdline_parse_token_string_t cmd_showqueue_show =
7370         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7371 cmdline_parse_token_string_t cmd_showqueue_type =
7372         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7373 cmdline_parse_token_string_t cmd_showqueue_what =
7374         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7375 cmdline_parse_token_num_t cmd_showqueue_portnum =
7376         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7377 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7378         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7379
7380 cmdline_parse_inst_t cmd_showqueue = {
7381         .f = cmd_showqueue_parsed,
7382         .data = NULL,
7383         .help_str = "show rxq|txq info <port_id> <queue_id>",
7384         .tokens = {
7385                 (void *)&cmd_showqueue_show,
7386                 (void *)&cmd_showqueue_type,
7387                 (void *)&cmd_showqueue_what,
7388                 (void *)&cmd_showqueue_portnum,
7389                 (void *)&cmd_showqueue_queuenum,
7390                 NULL,
7391         },
7392 };
7393
7394 /* show/clear fwd engine statistics */
7395 struct fwd_result {
7396         cmdline_fixed_string_t action;
7397         cmdline_fixed_string_t fwd;
7398         cmdline_fixed_string_t stats;
7399         cmdline_fixed_string_t all;
7400 };
7401
7402 cmdline_parse_token_string_t cmd_fwd_action =
7403         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7404 cmdline_parse_token_string_t cmd_fwd_fwd =
7405         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7406 cmdline_parse_token_string_t cmd_fwd_stats =
7407         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7408 cmdline_parse_token_string_t cmd_fwd_all =
7409         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7410
7411 static void
7412 cmd_showfwdall_parsed(void *parsed_result,
7413                       __rte_unused struct cmdline *cl,
7414                       __rte_unused void *data)
7415 {
7416         struct fwd_result *res = parsed_result;
7417
7418         if (!strcmp(res->action, "show"))
7419                 fwd_stats_display();
7420         else
7421                 fwd_stats_reset();
7422 }
7423
7424 static cmdline_parse_inst_t cmd_showfwdall = {
7425         .f = cmd_showfwdall_parsed,
7426         .data = NULL,
7427         .help_str = "show|clear fwd stats all",
7428         .tokens = {
7429                 (void *)&cmd_fwd_action,
7430                 (void *)&cmd_fwd_fwd,
7431                 (void *)&cmd_fwd_stats,
7432                 (void *)&cmd_fwd_all,
7433                 NULL,
7434         },
7435 };
7436
7437 /* *** READ PORT REGISTER *** */
7438 struct cmd_read_reg_result {
7439         cmdline_fixed_string_t read;
7440         cmdline_fixed_string_t reg;
7441         portid_t port_id;
7442         uint32_t reg_off;
7443 };
7444
7445 static void
7446 cmd_read_reg_parsed(void *parsed_result,
7447                     __attribute__((unused)) struct cmdline *cl,
7448                     __attribute__((unused)) void *data)
7449 {
7450         struct cmd_read_reg_result *res = parsed_result;
7451         port_reg_display(res->port_id, res->reg_off);
7452 }
7453
7454 cmdline_parse_token_string_t cmd_read_reg_read =
7455         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7456 cmdline_parse_token_string_t cmd_read_reg_reg =
7457         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7458 cmdline_parse_token_num_t cmd_read_reg_port_id =
7459         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7460 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7461         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7462
7463 cmdline_parse_inst_t cmd_read_reg = {
7464         .f = cmd_read_reg_parsed,
7465         .data = NULL,
7466         .help_str = "read reg <port_id> <reg_off>",
7467         .tokens = {
7468                 (void *)&cmd_read_reg_read,
7469                 (void *)&cmd_read_reg_reg,
7470                 (void *)&cmd_read_reg_port_id,
7471                 (void *)&cmd_read_reg_reg_off,
7472                 NULL,
7473         },
7474 };
7475
7476 /* *** READ PORT REGISTER BIT FIELD *** */
7477 struct cmd_read_reg_bit_field_result {
7478         cmdline_fixed_string_t read;
7479         cmdline_fixed_string_t regfield;
7480         portid_t port_id;
7481         uint32_t reg_off;
7482         uint8_t bit1_pos;
7483         uint8_t bit2_pos;
7484 };
7485
7486 static void
7487 cmd_read_reg_bit_field_parsed(void *parsed_result,
7488                               __attribute__((unused)) struct cmdline *cl,
7489                               __attribute__((unused)) void *data)
7490 {
7491         struct cmd_read_reg_bit_field_result *res = parsed_result;
7492         port_reg_bit_field_display(res->port_id, res->reg_off,
7493                                    res->bit1_pos, res->bit2_pos);
7494 }
7495
7496 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7497         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7498                                  "read");
7499 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7500         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7501                                  regfield, "regfield");
7502 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7503         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7504                               UINT16);
7505 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7506         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7507                               UINT32);
7508 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7509         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7510                               UINT8);
7511 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7512         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7513                               UINT8);
7514
7515 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7516         .f = cmd_read_reg_bit_field_parsed,
7517         .data = NULL,
7518         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7519         "Read register bit field between bit_x and bit_y included",
7520         .tokens = {
7521                 (void *)&cmd_read_reg_bit_field_read,
7522                 (void *)&cmd_read_reg_bit_field_regfield,
7523                 (void *)&cmd_read_reg_bit_field_port_id,
7524                 (void *)&cmd_read_reg_bit_field_reg_off,
7525                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7526                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7527                 NULL,
7528         },
7529 };
7530
7531 /* *** READ PORT REGISTER BIT *** */
7532 struct cmd_read_reg_bit_result {
7533         cmdline_fixed_string_t read;
7534         cmdline_fixed_string_t regbit;
7535         portid_t port_id;
7536         uint32_t reg_off;
7537         uint8_t bit_pos;
7538 };
7539
7540 static void
7541 cmd_read_reg_bit_parsed(void *parsed_result,
7542                         __attribute__((unused)) struct cmdline *cl,
7543                         __attribute__((unused)) void *data)
7544 {
7545         struct cmd_read_reg_bit_result *res = parsed_result;
7546         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7547 }
7548
7549 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7550         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7551 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7552         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7553                                  regbit, "regbit");
7554 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7555         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7556 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7557         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7558 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7559         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7560
7561 cmdline_parse_inst_t cmd_read_reg_bit = {
7562         .f = cmd_read_reg_bit_parsed,
7563         .data = NULL,
7564         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7565         .tokens = {
7566                 (void *)&cmd_read_reg_bit_read,
7567                 (void *)&cmd_read_reg_bit_regbit,
7568                 (void *)&cmd_read_reg_bit_port_id,
7569                 (void *)&cmd_read_reg_bit_reg_off,
7570                 (void *)&cmd_read_reg_bit_bit_pos,
7571                 NULL,
7572         },
7573 };
7574
7575 /* *** WRITE PORT REGISTER *** */
7576 struct cmd_write_reg_result {
7577         cmdline_fixed_string_t write;
7578         cmdline_fixed_string_t reg;
7579         portid_t port_id;
7580         uint32_t reg_off;
7581         uint32_t value;
7582 };
7583
7584 static void
7585 cmd_write_reg_parsed(void *parsed_result,
7586                      __attribute__((unused)) struct cmdline *cl,
7587                      __attribute__((unused)) void *data)
7588 {
7589         struct cmd_write_reg_result *res = parsed_result;
7590         port_reg_set(res->port_id, res->reg_off, res->value);
7591 }
7592
7593 cmdline_parse_token_string_t cmd_write_reg_write =
7594         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7595 cmdline_parse_token_string_t cmd_write_reg_reg =
7596         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7597 cmdline_parse_token_num_t cmd_write_reg_port_id =
7598         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7599 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7600         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7601 cmdline_parse_token_num_t cmd_write_reg_value =
7602         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7603
7604 cmdline_parse_inst_t cmd_write_reg = {
7605         .f = cmd_write_reg_parsed,
7606         .data = NULL,
7607         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7608         .tokens = {
7609                 (void *)&cmd_write_reg_write,
7610                 (void *)&cmd_write_reg_reg,
7611                 (void *)&cmd_write_reg_port_id,
7612                 (void *)&cmd_write_reg_reg_off,
7613                 (void *)&cmd_write_reg_value,
7614                 NULL,
7615         },
7616 };
7617
7618 /* *** WRITE PORT REGISTER BIT FIELD *** */
7619 struct cmd_write_reg_bit_field_result {
7620         cmdline_fixed_string_t write;
7621         cmdline_fixed_string_t regfield;
7622         portid_t port_id;
7623         uint32_t reg_off;
7624         uint8_t bit1_pos;
7625         uint8_t bit2_pos;
7626         uint32_t value;
7627 };
7628
7629 static void
7630 cmd_write_reg_bit_field_parsed(void *parsed_result,
7631                                __attribute__((unused)) struct cmdline *cl,
7632                                __attribute__((unused)) void *data)
7633 {
7634         struct cmd_write_reg_bit_field_result *res = parsed_result;
7635         port_reg_bit_field_set(res->port_id, res->reg_off,
7636                           res->bit1_pos, res->bit2_pos, res->value);
7637 }
7638
7639 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7640         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7641                                  "write");
7642 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7643         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7644                                  regfield, "regfield");
7645 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7646         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7647                               UINT16);
7648 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7649         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7650                               UINT32);
7651 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7652         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7653                               UINT8);
7654 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7655         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7656                               UINT8);
7657 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7658         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7659                               UINT32);
7660
7661 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7662         .f = cmd_write_reg_bit_field_parsed,
7663         .data = NULL,
7664         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7665                 "<reg_value>: "
7666                 "Set register bit field between bit_x and bit_y included",
7667         .tokens = {
7668                 (void *)&cmd_write_reg_bit_field_write,
7669                 (void *)&cmd_write_reg_bit_field_regfield,
7670                 (void *)&cmd_write_reg_bit_field_port_id,
7671                 (void *)&cmd_write_reg_bit_field_reg_off,
7672                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7673                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7674                 (void *)&cmd_write_reg_bit_field_value,
7675                 NULL,
7676         },
7677 };
7678
7679 /* *** WRITE PORT REGISTER BIT *** */
7680 struct cmd_write_reg_bit_result {
7681         cmdline_fixed_string_t write;
7682         cmdline_fixed_string_t regbit;
7683         portid_t port_id;
7684         uint32_t reg_off;
7685         uint8_t bit_pos;
7686         uint8_t value;
7687 };
7688
7689 static void
7690 cmd_write_reg_bit_parsed(void *parsed_result,
7691                          __attribute__((unused)) struct cmdline *cl,
7692                          __attribute__((unused)) void *data)
7693 {
7694         struct cmd_write_reg_bit_result *res = parsed_result;
7695         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7696 }
7697
7698 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7699         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7700                                  "write");
7701 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7702         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7703                                  regbit, "regbit");
7704 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7705         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7706 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7707         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7708 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7709         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7710 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7711         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7712
7713 cmdline_parse_inst_t cmd_write_reg_bit = {
7714         .f = cmd_write_reg_bit_parsed,
7715         .data = NULL,
7716         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7717                 "0 <= bit_x <= 31",
7718         .tokens = {
7719                 (void *)&cmd_write_reg_bit_write,
7720                 (void *)&cmd_write_reg_bit_regbit,
7721                 (void *)&cmd_write_reg_bit_port_id,
7722                 (void *)&cmd_write_reg_bit_reg_off,
7723                 (void *)&cmd_write_reg_bit_bit_pos,
7724                 (void *)&cmd_write_reg_bit_value,
7725                 NULL,
7726         },
7727 };
7728
7729 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7730 struct cmd_read_rxd_txd_result {
7731         cmdline_fixed_string_t read;
7732         cmdline_fixed_string_t rxd_txd;
7733         portid_t port_id;
7734         uint16_t queue_id;
7735         uint16_t desc_id;
7736 };
7737
7738 static void
7739 cmd_read_rxd_txd_parsed(void *parsed_result,
7740                         __attribute__((unused)) struct cmdline *cl,
7741                         __attribute__((unused)) void *data)
7742 {
7743         struct cmd_read_rxd_txd_result *res = parsed_result;
7744
7745         if (!strcmp(res->rxd_txd, "rxd"))
7746                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7747         else if (!strcmp(res->rxd_txd, "txd"))
7748                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7749 }
7750
7751 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7752         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7753 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7754         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7755                                  "rxd#txd");
7756 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7757         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7758 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7759         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7760 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7761         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7762
7763 cmdline_parse_inst_t cmd_read_rxd_txd = {
7764         .f = cmd_read_rxd_txd_parsed,
7765         .data = NULL,
7766         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7767         .tokens = {
7768                 (void *)&cmd_read_rxd_txd_read,
7769                 (void *)&cmd_read_rxd_txd_rxd_txd,
7770                 (void *)&cmd_read_rxd_txd_port_id,
7771                 (void *)&cmd_read_rxd_txd_queue_id,
7772                 (void *)&cmd_read_rxd_txd_desc_id,
7773                 NULL,
7774         },
7775 };
7776
7777 /* *** QUIT *** */
7778 struct cmd_quit_result {
7779         cmdline_fixed_string_t quit;
7780 };
7781
7782 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7783                             struct cmdline *cl,
7784                             __attribute__((unused)) void *data)
7785 {
7786         cmdline_quit(cl);
7787 }
7788
7789 cmdline_parse_token_string_t cmd_quit_quit =
7790         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7791
7792 cmdline_parse_inst_t cmd_quit = {
7793         .f = cmd_quit_parsed,
7794         .data = NULL,
7795         .help_str = "quit: Exit application",
7796         .tokens = {
7797                 (void *)&cmd_quit_quit,
7798                 NULL,
7799         },
7800 };
7801
7802 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7803 struct cmd_mac_addr_result {
7804         cmdline_fixed_string_t mac_addr_cmd;
7805         cmdline_fixed_string_t what;
7806         uint16_t port_num;
7807         struct ether_addr address;
7808 };
7809
7810 static void cmd_mac_addr_parsed(void *parsed_result,
7811                 __attribute__((unused)) struct cmdline *cl,
7812                 __attribute__((unused)) void *data)
7813 {
7814         struct cmd_mac_addr_result *res = parsed_result;
7815         int ret;
7816
7817         if (strcmp(res->what, "add") == 0)
7818                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7819         else if (strcmp(res->what, "set") == 0)
7820                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7821                                                        &res->address);
7822         else
7823                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7824
7825         /* check the return value and print it if is < 0 */
7826         if(ret < 0)
7827                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7828
7829 }
7830
7831 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7832         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7833                                 "mac_addr");
7834 cmdline_parse_token_string_t cmd_mac_addr_what =
7835         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7836                                 "add#remove#set");
7837 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7838                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7839                                         UINT16);
7840 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7841                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7842
7843 cmdline_parse_inst_t cmd_mac_addr = {
7844         .f = cmd_mac_addr_parsed,
7845         .data = (void *)0,
7846         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7847                         "Add/Remove/Set MAC address on port_id",
7848         .tokens = {
7849                 (void *)&cmd_mac_addr_cmd,
7850                 (void *)&cmd_mac_addr_what,
7851                 (void *)&cmd_mac_addr_portnum,
7852                 (void *)&cmd_mac_addr_addr,
7853                 NULL,
7854         },
7855 };
7856
7857 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7858 struct cmd_eth_peer_result {
7859         cmdline_fixed_string_t set;
7860         cmdline_fixed_string_t eth_peer;
7861         portid_t port_id;
7862         cmdline_fixed_string_t peer_addr;
7863 };
7864
7865 static void cmd_set_eth_peer_parsed(void *parsed_result,
7866                         __attribute__((unused)) struct cmdline *cl,
7867                         __attribute__((unused)) void *data)
7868 {
7869                 struct cmd_eth_peer_result *res = parsed_result;
7870
7871                 if (test_done == 0) {
7872                         printf("Please stop forwarding first\n");
7873                         return;
7874                 }
7875                 if (!strcmp(res->eth_peer, "eth-peer")) {
7876                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7877                         fwd_config_setup();
7878                 }
7879 }
7880 cmdline_parse_token_string_t cmd_eth_peer_set =
7881         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7882 cmdline_parse_token_string_t cmd_eth_peer =
7883         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7884 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7885         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7886 cmdline_parse_token_string_t cmd_eth_peer_addr =
7887         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7888
7889 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7890         .f = cmd_set_eth_peer_parsed,
7891         .data = NULL,
7892         .help_str = "set eth-peer <port_id> <peer_mac>",
7893         .tokens = {
7894                 (void *)&cmd_eth_peer_set,
7895                 (void *)&cmd_eth_peer,
7896                 (void *)&cmd_eth_peer_port_id,
7897                 (void *)&cmd_eth_peer_addr,
7898                 NULL,
7899         },
7900 };
7901
7902 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7903 struct cmd_set_qmap_result {
7904         cmdline_fixed_string_t set;
7905         cmdline_fixed_string_t qmap;
7906         cmdline_fixed_string_t what;
7907         portid_t port_id;
7908         uint16_t queue_id;
7909         uint8_t map_value;
7910 };
7911
7912 static void
7913 cmd_set_qmap_parsed(void *parsed_result,
7914                        __attribute__((unused)) struct cmdline *cl,
7915                        __attribute__((unused)) void *data)
7916 {
7917         struct cmd_set_qmap_result *res = parsed_result;
7918         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7919
7920         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7921 }
7922
7923 cmdline_parse_token_string_t cmd_setqmap_set =
7924         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7925                                  set, "set");
7926 cmdline_parse_token_string_t cmd_setqmap_qmap =
7927         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7928                                  qmap, "stat_qmap");
7929 cmdline_parse_token_string_t cmd_setqmap_what =
7930         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7931                                  what, "tx#rx");
7932 cmdline_parse_token_num_t cmd_setqmap_portid =
7933         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7934                               port_id, UINT16);
7935 cmdline_parse_token_num_t cmd_setqmap_queueid =
7936         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7937                               queue_id, UINT16);
7938 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7939         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7940                               map_value, UINT8);
7941
7942 cmdline_parse_inst_t cmd_set_qmap = {
7943         .f = cmd_set_qmap_parsed,
7944         .data = NULL,
7945         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7946                 "Set statistics mapping value on tx|rx queue_id of port_id",
7947         .tokens = {
7948                 (void *)&cmd_setqmap_set,
7949                 (void *)&cmd_setqmap_qmap,
7950                 (void *)&cmd_setqmap_what,
7951                 (void *)&cmd_setqmap_portid,
7952                 (void *)&cmd_setqmap_queueid,
7953                 (void *)&cmd_setqmap_mapvalue,
7954                 NULL,
7955         },
7956 };
7957
7958 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7959 struct cmd_set_xstats_hide_zero_result {
7960         cmdline_fixed_string_t keyword;
7961         cmdline_fixed_string_t name;
7962         cmdline_fixed_string_t on_off;
7963 };
7964
7965 static void
7966 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7967                         __attribute__((unused)) struct cmdline *cl,
7968                         __attribute__((unused)) void *data)
7969 {
7970         struct cmd_set_xstats_hide_zero_result *res;
7971         uint16_t on_off = 0;
7972
7973         res = parsed_result;
7974         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7975         set_xstats_hide_zero(on_off);
7976 }
7977
7978 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7979         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7980                                  keyword, "set");
7981 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7982         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7983                                  name, "xstats-hide-zero");
7984 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7985         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7986                                  on_off, "on#off");
7987
7988 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7989         .f = cmd_set_xstats_hide_zero_parsed,
7990         .data = NULL,
7991         .help_str = "set xstats-hide-zero on|off",
7992         .tokens = {
7993                 (void *)&cmd_set_xstats_hide_zero_keyword,
7994                 (void *)&cmd_set_xstats_hide_zero_name,
7995                 (void *)&cmd_set_xstats_hide_zero_on_off,
7996                 NULL,
7997         },
7998 };
7999
8000 /* *** CONFIGURE UNICAST HASH TABLE *** */
8001 struct cmd_set_uc_hash_table {
8002         cmdline_fixed_string_t set;
8003         cmdline_fixed_string_t port;
8004         portid_t port_id;
8005         cmdline_fixed_string_t what;
8006         struct ether_addr address;
8007         cmdline_fixed_string_t mode;
8008 };
8009
8010 static void
8011 cmd_set_uc_hash_parsed(void *parsed_result,
8012                        __attribute__((unused)) struct cmdline *cl,
8013                        __attribute__((unused)) void *data)
8014 {
8015         int ret=0;
8016         struct cmd_set_uc_hash_table *res = parsed_result;
8017
8018         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8019
8020         if (strcmp(res->what, "uta") == 0)
8021                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8022                                                 &res->address,(uint8_t)is_on);
8023         if (ret < 0)
8024                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8025
8026 }
8027
8028 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8029         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8030                                  set, "set");
8031 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8032         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8033                                  port, "port");
8034 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8035         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8036                               port_id, UINT16);
8037 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8038         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8039                                  what, "uta");
8040 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8041         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8042                                 address);
8043 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8044         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8045                                  mode, "on#off");
8046
8047 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8048         .f = cmd_set_uc_hash_parsed,
8049         .data = NULL,
8050         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8051         .tokens = {
8052                 (void *)&cmd_set_uc_hash_set,
8053                 (void *)&cmd_set_uc_hash_port,
8054                 (void *)&cmd_set_uc_hash_portid,
8055                 (void *)&cmd_set_uc_hash_what,
8056                 (void *)&cmd_set_uc_hash_mac,
8057                 (void *)&cmd_set_uc_hash_mode,
8058                 NULL,
8059         },
8060 };
8061
8062 struct cmd_set_uc_all_hash_table {
8063         cmdline_fixed_string_t set;
8064         cmdline_fixed_string_t port;
8065         portid_t port_id;
8066         cmdline_fixed_string_t what;
8067         cmdline_fixed_string_t value;
8068         cmdline_fixed_string_t mode;
8069 };
8070
8071 static void
8072 cmd_set_uc_all_hash_parsed(void *parsed_result,
8073                        __attribute__((unused)) struct cmdline *cl,
8074                        __attribute__((unused)) void *data)
8075 {
8076         int ret=0;
8077         struct cmd_set_uc_all_hash_table *res = parsed_result;
8078
8079         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8080
8081         if ((strcmp(res->what, "uta") == 0) &&
8082                 (strcmp(res->value, "all") == 0))
8083                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8084         if (ret < 0)
8085                 printf("bad unicast hash table parameter,"
8086                         "return code = %d \n", ret);
8087 }
8088
8089 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8090         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8091                                  set, "set");
8092 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8093         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8094                                  port, "port");
8095 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8096         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8097                               port_id, UINT16);
8098 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8099         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8100                                  what, "uta");
8101 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8102         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8103                                 value,"all");
8104 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8105         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8106                                  mode, "on#off");
8107
8108 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8109         .f = cmd_set_uc_all_hash_parsed,
8110         .data = NULL,
8111         .help_str = "set port <port_id> uta all on|off",
8112         .tokens = {
8113                 (void *)&cmd_set_uc_all_hash_set,
8114                 (void *)&cmd_set_uc_all_hash_port,
8115                 (void *)&cmd_set_uc_all_hash_portid,
8116                 (void *)&cmd_set_uc_all_hash_what,
8117                 (void *)&cmd_set_uc_all_hash_value,
8118                 (void *)&cmd_set_uc_all_hash_mode,
8119                 NULL,
8120         },
8121 };
8122
8123 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8124 struct cmd_set_vf_macvlan_filter {
8125         cmdline_fixed_string_t set;
8126         cmdline_fixed_string_t port;
8127         portid_t port_id;
8128         cmdline_fixed_string_t vf;
8129         uint8_t vf_id;
8130         struct ether_addr address;
8131         cmdline_fixed_string_t filter_type;
8132         cmdline_fixed_string_t mode;
8133 };
8134
8135 static void
8136 cmd_set_vf_macvlan_parsed(void *parsed_result,
8137                        __attribute__((unused)) struct cmdline *cl,
8138                        __attribute__((unused)) void *data)
8139 {
8140         int is_on, ret = 0;
8141         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8142         struct rte_eth_mac_filter filter;
8143
8144         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8145
8146         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
8147
8148         /* set VF MAC filter */
8149         filter.is_vf = 1;
8150
8151         /* set VF ID */
8152         filter.dst_id = res->vf_id;
8153
8154         if (!strcmp(res->filter_type, "exact-mac"))
8155                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8156         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8157                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8158         else if (!strcmp(res->filter_type, "hashmac"))
8159                 filter.filter_type = RTE_MAC_HASH_MATCH;
8160         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8161                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8162
8163         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8164
8165         if (is_on)
8166                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8167                                         RTE_ETH_FILTER_MACVLAN,
8168                                         RTE_ETH_FILTER_ADD,
8169                                          &filter);
8170         else
8171                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8172                                         RTE_ETH_FILTER_MACVLAN,
8173                                         RTE_ETH_FILTER_DELETE,
8174                                         &filter);
8175
8176         if (ret < 0)
8177                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8178
8179 }
8180
8181 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8182         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8183                                  set, "set");
8184 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8185         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8186                                  port, "port");
8187 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8188         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8189                               port_id, UINT16);
8190 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8191         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8192                                  vf, "vf");
8193 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8194         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8195                                 vf_id, UINT8);
8196 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8197         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8198                                 address);
8199 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8200         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8201                                 filter_type, "exact-mac#exact-mac-vlan"
8202                                 "#hashmac#hashmac-vlan");
8203 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8204         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8205                                  mode, "on#off");
8206
8207 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8208         .f = cmd_set_vf_macvlan_parsed,
8209         .data = NULL,
8210         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8211                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8212                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8213                 "hash match rule: hash match of MAC and exact match of VLAN",
8214         .tokens = {
8215                 (void *)&cmd_set_vf_macvlan_set,
8216                 (void *)&cmd_set_vf_macvlan_port,
8217                 (void *)&cmd_set_vf_macvlan_portid,
8218                 (void *)&cmd_set_vf_macvlan_vf,
8219                 (void *)&cmd_set_vf_macvlan_vf_id,
8220                 (void *)&cmd_set_vf_macvlan_mac,
8221                 (void *)&cmd_set_vf_macvlan_filter_type,
8222                 (void *)&cmd_set_vf_macvlan_mode,
8223                 NULL,
8224         },
8225 };
8226
8227 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8228 struct cmd_set_vf_traffic {
8229         cmdline_fixed_string_t set;
8230         cmdline_fixed_string_t port;
8231         portid_t port_id;
8232         cmdline_fixed_string_t vf;
8233         uint8_t vf_id;
8234         cmdline_fixed_string_t what;
8235         cmdline_fixed_string_t mode;
8236 };
8237
8238 static void
8239 cmd_set_vf_traffic_parsed(void *parsed_result,
8240                        __attribute__((unused)) struct cmdline *cl,
8241                        __attribute__((unused)) void *data)
8242 {
8243         struct cmd_set_vf_traffic *res = parsed_result;
8244         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8245         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8246
8247         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8248 }
8249
8250 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8251         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8252                                  set, "set");
8253 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8254         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8255                                  port, "port");
8256 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8257         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8258                               port_id, UINT16);
8259 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8260         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8261                                  vf, "vf");
8262 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8263         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8264                               vf_id, UINT8);
8265 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8266         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8267                                  what, "tx#rx");
8268 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8269         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8270                                  mode, "on#off");
8271
8272 cmdline_parse_inst_t cmd_set_vf_traffic = {
8273         .f = cmd_set_vf_traffic_parsed,
8274         .data = NULL,
8275         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8276         .tokens = {
8277                 (void *)&cmd_setvf_traffic_set,
8278                 (void *)&cmd_setvf_traffic_port,
8279                 (void *)&cmd_setvf_traffic_portid,
8280                 (void *)&cmd_setvf_traffic_vf,
8281                 (void *)&cmd_setvf_traffic_vfid,
8282                 (void *)&cmd_setvf_traffic_what,
8283                 (void *)&cmd_setvf_traffic_mode,
8284                 NULL,
8285         },
8286 };
8287
8288 /* *** CONFIGURE VF RECEIVE MODE *** */
8289 struct cmd_set_vf_rxmode {
8290         cmdline_fixed_string_t set;
8291         cmdline_fixed_string_t port;
8292         portid_t port_id;
8293         cmdline_fixed_string_t vf;
8294         uint8_t vf_id;
8295         cmdline_fixed_string_t what;
8296         cmdline_fixed_string_t mode;
8297         cmdline_fixed_string_t on;
8298 };
8299
8300 static void
8301 cmd_set_vf_rxmode_parsed(void *parsed_result,
8302                        __attribute__((unused)) struct cmdline *cl,
8303                        __attribute__((unused)) void *data)
8304 {
8305         int ret = -ENOTSUP;
8306         uint16_t rx_mode = 0;
8307         struct cmd_set_vf_rxmode *res = parsed_result;
8308
8309         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8310         if (!strcmp(res->what,"rxmode")) {
8311                 if (!strcmp(res->mode, "AUPE"))
8312                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8313                 else if (!strcmp(res->mode, "ROPE"))
8314                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8315                 else if (!strcmp(res->mode, "BAM"))
8316                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8317                 else if (!strncmp(res->mode, "MPE",3))
8318                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8319         }
8320
8321         RTE_SET_USED(is_on);
8322
8323 #ifdef RTE_LIBRTE_IXGBE_PMD
8324         if (ret == -ENOTSUP)
8325                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8326                                                   rx_mode, (uint8_t)is_on);
8327 #endif
8328 #ifdef RTE_LIBRTE_BNXT_PMD
8329         if (ret == -ENOTSUP)
8330                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8331                                                  rx_mode, (uint8_t)is_on);
8332 #endif
8333         if (ret < 0)
8334                 printf("bad VF receive mode parameter, return code = %d \n",
8335                 ret);
8336 }
8337
8338 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8339         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8340                                  set, "set");
8341 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8342         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8343                                  port, "port");
8344 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8345         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8346                               port_id, UINT16);
8347 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8348         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8349                                  vf, "vf");
8350 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8351         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8352                               vf_id, UINT8);
8353 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8354         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8355                                  what, "rxmode");
8356 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8357         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8358                                  mode, "AUPE#ROPE#BAM#MPE");
8359 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8360         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8361                                  on, "on#off");
8362
8363 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8364         .f = cmd_set_vf_rxmode_parsed,
8365         .data = NULL,
8366         .help_str = "set port <port_id> vf <vf_id> rxmode "
8367                 "AUPE|ROPE|BAM|MPE on|off",
8368         .tokens = {
8369                 (void *)&cmd_set_vf_rxmode_set,
8370                 (void *)&cmd_set_vf_rxmode_port,
8371                 (void *)&cmd_set_vf_rxmode_portid,
8372                 (void *)&cmd_set_vf_rxmode_vf,
8373                 (void *)&cmd_set_vf_rxmode_vfid,
8374                 (void *)&cmd_set_vf_rxmode_what,
8375                 (void *)&cmd_set_vf_rxmode_mode,
8376                 (void *)&cmd_set_vf_rxmode_on,
8377                 NULL,
8378         },
8379 };
8380
8381 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8382 struct cmd_vf_mac_addr_result {
8383         cmdline_fixed_string_t mac_addr_cmd;
8384         cmdline_fixed_string_t what;
8385         cmdline_fixed_string_t port;
8386         uint16_t port_num;
8387         cmdline_fixed_string_t vf;
8388         uint8_t vf_num;
8389         struct ether_addr address;
8390 };
8391
8392 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8393                 __attribute__((unused)) struct cmdline *cl,
8394                 __attribute__((unused)) void *data)
8395 {
8396         struct cmd_vf_mac_addr_result *res = parsed_result;
8397         int ret = -ENOTSUP;
8398
8399         if (strcmp(res->what, "add") != 0)
8400                 return;
8401
8402 #ifdef RTE_LIBRTE_I40E_PMD
8403         if (ret == -ENOTSUP)
8404                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8405                                                    &res->address);
8406 #endif
8407 #ifdef RTE_LIBRTE_BNXT_PMD
8408         if (ret == -ENOTSUP)
8409                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8410                                                 res->vf_num);
8411 #endif
8412
8413         if(ret < 0)
8414                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8415
8416 }
8417
8418 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8419         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8420                                 mac_addr_cmd,"mac_addr");
8421 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8422         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8423                                 what,"add");
8424 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8425         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8426                                 port,"port");
8427 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8428         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8429                                 port_num, UINT16);
8430 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8431         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8432                                 vf,"vf");
8433 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8434         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8435                                 vf_num, UINT8);
8436 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8437         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8438                                 address);
8439
8440 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8441         .f = cmd_vf_mac_addr_parsed,
8442         .data = (void *)0,
8443         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8444                 "Add MAC address filtering for a VF on port_id",
8445         .tokens = {
8446                 (void *)&cmd_vf_mac_addr_cmd,
8447                 (void *)&cmd_vf_mac_addr_what,
8448                 (void *)&cmd_vf_mac_addr_port,
8449                 (void *)&cmd_vf_mac_addr_portnum,
8450                 (void *)&cmd_vf_mac_addr_vf,
8451                 (void *)&cmd_vf_mac_addr_vfnum,
8452                 (void *)&cmd_vf_mac_addr_addr,
8453                 NULL,
8454         },
8455 };
8456
8457 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8458 struct cmd_vf_rx_vlan_filter {
8459         cmdline_fixed_string_t rx_vlan;
8460         cmdline_fixed_string_t what;
8461         uint16_t vlan_id;
8462         cmdline_fixed_string_t port;
8463         portid_t port_id;
8464         cmdline_fixed_string_t vf;
8465         uint64_t vf_mask;
8466 };
8467
8468 static void
8469 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8470                           __attribute__((unused)) struct cmdline *cl,
8471                           __attribute__((unused)) void *data)
8472 {
8473         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8474         int ret = -ENOTSUP;
8475
8476         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8477
8478 #ifdef RTE_LIBRTE_IXGBE_PMD
8479         if (ret == -ENOTSUP)
8480                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8481                                 res->vlan_id, res->vf_mask, is_add);
8482 #endif
8483 #ifdef RTE_LIBRTE_I40E_PMD
8484         if (ret == -ENOTSUP)
8485                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8486                                 res->vlan_id, res->vf_mask, is_add);
8487 #endif
8488 #ifdef RTE_LIBRTE_BNXT_PMD
8489         if (ret == -ENOTSUP)
8490                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8491                                 res->vlan_id, res->vf_mask, is_add);
8492 #endif
8493
8494         switch (ret) {
8495         case 0:
8496                 break;
8497         case -EINVAL:
8498                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8499                                 res->vlan_id, res->vf_mask);
8500                 break;
8501         case -ENODEV:
8502                 printf("invalid port_id %d\n", res->port_id);
8503                 break;
8504         case -ENOTSUP:
8505                 printf("function not implemented or supported\n");
8506                 break;
8507         default:
8508                 printf("programming error: (%s)\n", strerror(-ret));
8509         }
8510 }
8511
8512 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8513         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8514                                  rx_vlan, "rx_vlan");
8515 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8516         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8517                                  what, "add#rm");
8518 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8519         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8520                               vlan_id, UINT16);
8521 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8522         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8523                                  port, "port");
8524 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8525         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8526                               port_id, UINT16);
8527 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8528         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8529                                  vf, "vf");
8530 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8531         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8532                               vf_mask, UINT64);
8533
8534 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8535         .f = cmd_vf_rx_vlan_filter_parsed,
8536         .data = NULL,
8537         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8538                 "(vf_mask = hexadecimal VF mask)",
8539         .tokens = {
8540                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8541                 (void *)&cmd_vf_rx_vlan_filter_what,
8542                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8543                 (void *)&cmd_vf_rx_vlan_filter_port,
8544                 (void *)&cmd_vf_rx_vlan_filter_portid,
8545                 (void *)&cmd_vf_rx_vlan_filter_vf,
8546                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8547                 NULL,
8548         },
8549 };
8550
8551 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8552 struct cmd_queue_rate_limit_result {
8553         cmdline_fixed_string_t set;
8554         cmdline_fixed_string_t port;
8555         uint16_t port_num;
8556         cmdline_fixed_string_t queue;
8557         uint8_t queue_num;
8558         cmdline_fixed_string_t rate;
8559         uint16_t rate_num;
8560 };
8561
8562 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8563                 __attribute__((unused)) struct cmdline *cl,
8564                 __attribute__((unused)) void *data)
8565 {
8566         struct cmd_queue_rate_limit_result *res = parsed_result;
8567         int ret = 0;
8568
8569         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8570                 && (strcmp(res->queue, "queue") == 0)
8571                 && (strcmp(res->rate, "rate") == 0))
8572                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8573                                         res->rate_num);
8574         if (ret < 0)
8575                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8576
8577 }
8578
8579 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8580         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8581                                 set, "set");
8582 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8583         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8584                                 port, "port");
8585 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8586         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8587                                 port_num, UINT16);
8588 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8589         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8590                                 queue, "queue");
8591 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8592         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8593                                 queue_num, UINT8);
8594 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8595         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8596                                 rate, "rate");
8597 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8598         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8599                                 rate_num, UINT16);
8600
8601 cmdline_parse_inst_t cmd_queue_rate_limit = {
8602         .f = cmd_queue_rate_limit_parsed,
8603         .data = (void *)0,
8604         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8605                 "Set rate limit for a queue on port_id",
8606         .tokens = {
8607                 (void *)&cmd_queue_rate_limit_set,
8608                 (void *)&cmd_queue_rate_limit_port,
8609                 (void *)&cmd_queue_rate_limit_portnum,
8610                 (void *)&cmd_queue_rate_limit_queue,
8611                 (void *)&cmd_queue_rate_limit_queuenum,
8612                 (void *)&cmd_queue_rate_limit_rate,
8613                 (void *)&cmd_queue_rate_limit_ratenum,
8614                 NULL,
8615         },
8616 };
8617
8618 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8619 struct cmd_vf_rate_limit_result {
8620         cmdline_fixed_string_t set;
8621         cmdline_fixed_string_t port;
8622         uint16_t port_num;
8623         cmdline_fixed_string_t vf;
8624         uint8_t vf_num;
8625         cmdline_fixed_string_t rate;
8626         uint16_t rate_num;
8627         cmdline_fixed_string_t q_msk;
8628         uint64_t q_msk_val;
8629 };
8630
8631 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8632                 __attribute__((unused)) struct cmdline *cl,
8633                 __attribute__((unused)) void *data)
8634 {
8635         struct cmd_vf_rate_limit_result *res = parsed_result;
8636         int ret = 0;
8637
8638         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8639                 && (strcmp(res->vf, "vf") == 0)
8640                 && (strcmp(res->rate, "rate") == 0)
8641                 && (strcmp(res->q_msk, "queue_mask") == 0))
8642                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8643                                         res->rate_num, res->q_msk_val);
8644         if (ret < 0)
8645                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8646
8647 }
8648
8649 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8650         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8651                                 set, "set");
8652 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8653         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8654                                 port, "port");
8655 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8656         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8657                                 port_num, UINT16);
8658 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8659         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8660                                 vf, "vf");
8661 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8662         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8663                                 vf_num, UINT8);
8664 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8665         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8666                                 rate, "rate");
8667 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8668         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8669                                 rate_num, UINT16);
8670 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8671         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8672                                 q_msk, "queue_mask");
8673 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8674         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8675                                 q_msk_val, UINT64);
8676
8677 cmdline_parse_inst_t cmd_vf_rate_limit = {
8678         .f = cmd_vf_rate_limit_parsed,
8679         .data = (void *)0,
8680         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8681                 "queue_mask <queue_mask_value>: "
8682                 "Set rate limit for queues of VF on port_id",
8683         .tokens = {
8684                 (void *)&cmd_vf_rate_limit_set,
8685                 (void *)&cmd_vf_rate_limit_port,
8686                 (void *)&cmd_vf_rate_limit_portnum,
8687                 (void *)&cmd_vf_rate_limit_vf,
8688                 (void *)&cmd_vf_rate_limit_vfnum,
8689                 (void *)&cmd_vf_rate_limit_rate,
8690                 (void *)&cmd_vf_rate_limit_ratenum,
8691                 (void *)&cmd_vf_rate_limit_q_msk,
8692                 (void *)&cmd_vf_rate_limit_q_msk_val,
8693                 NULL,
8694         },
8695 };
8696
8697 /* *** ADD TUNNEL FILTER OF A PORT *** */
8698 struct cmd_tunnel_filter_result {
8699         cmdline_fixed_string_t cmd;
8700         cmdline_fixed_string_t what;
8701         portid_t port_id;
8702         struct ether_addr outer_mac;
8703         struct ether_addr inner_mac;
8704         cmdline_ipaddr_t ip_value;
8705         uint16_t inner_vlan;
8706         cmdline_fixed_string_t tunnel_type;
8707         cmdline_fixed_string_t filter_type;
8708         uint32_t tenant_id;
8709         uint16_t queue_num;
8710 };
8711
8712 static void
8713 cmd_tunnel_filter_parsed(void *parsed_result,
8714                           __attribute__((unused)) struct cmdline *cl,
8715                           __attribute__((unused)) void *data)
8716 {
8717         struct cmd_tunnel_filter_result *res = parsed_result;
8718         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8719         int ret = 0;
8720
8721         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8722
8723         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8724         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8725         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8726
8727         if (res->ip_value.family == AF_INET) {
8728                 tunnel_filter_conf.ip_addr.ipv4_addr =
8729                         res->ip_value.addr.ipv4.s_addr;
8730                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8731         } else {
8732                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8733                         &(res->ip_value.addr.ipv6),
8734                         sizeof(struct in6_addr));
8735                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8736         }
8737
8738         if (!strcmp(res->filter_type, "imac-ivlan"))
8739                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8740         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8741                 tunnel_filter_conf.filter_type =
8742                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8743         else if (!strcmp(res->filter_type, "imac-tenid"))
8744                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8745         else if (!strcmp(res->filter_type, "imac"))
8746                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8747         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8748                 tunnel_filter_conf.filter_type =
8749                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8750         else if (!strcmp(res->filter_type, "oip"))
8751                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8752         else if (!strcmp(res->filter_type, "iip"))
8753                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8754         else {
8755                 printf("The filter type is not supported");
8756                 return;
8757         }
8758
8759         if (!strcmp(res->tunnel_type, "vxlan"))
8760                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8761         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8762                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8763         else if (!strcmp(res->tunnel_type, "nvgre"))
8764                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8765         else if (!strcmp(res->tunnel_type, "ipingre"))
8766                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8767         else {
8768                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8769                 return;
8770         }
8771
8772         tunnel_filter_conf.tenant_id = res->tenant_id;
8773         tunnel_filter_conf.queue_id = res->queue_num;
8774         if (!strcmp(res->what, "add"))
8775                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8776                                         RTE_ETH_FILTER_TUNNEL,
8777                                         RTE_ETH_FILTER_ADD,
8778                                         &tunnel_filter_conf);
8779         else
8780                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8781                                         RTE_ETH_FILTER_TUNNEL,
8782                                         RTE_ETH_FILTER_DELETE,
8783                                         &tunnel_filter_conf);
8784         if (ret < 0)
8785                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8786                                 strerror(-ret));
8787
8788 }
8789 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8790         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8791         cmd, "tunnel_filter");
8792 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8793         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8794         what, "add#rm");
8795 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8796         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8797         port_id, UINT16);
8798 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8799         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8800         outer_mac);
8801 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8802         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8803         inner_mac);
8804 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8805         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8806         inner_vlan, UINT16);
8807 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8808         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8809         ip_value);
8810 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8811         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8812         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8813
8814 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8815         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8816         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8817                 "imac#omac-imac-tenid");
8818 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8819         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8820         tenant_id, UINT32);
8821 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8822         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8823         queue_num, UINT16);
8824
8825 cmdline_parse_inst_t cmd_tunnel_filter = {
8826         .f = cmd_tunnel_filter_parsed,
8827         .data = (void *)0,
8828         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8829                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8830                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8831                 "<queue_id>: Add/Rm tunnel filter of a port",
8832         .tokens = {
8833                 (void *)&cmd_tunnel_filter_cmd,
8834                 (void *)&cmd_tunnel_filter_what,
8835                 (void *)&cmd_tunnel_filter_port_id,
8836                 (void *)&cmd_tunnel_filter_outer_mac,
8837                 (void *)&cmd_tunnel_filter_inner_mac,
8838                 (void *)&cmd_tunnel_filter_ip_value,
8839                 (void *)&cmd_tunnel_filter_innner_vlan,
8840                 (void *)&cmd_tunnel_filter_tunnel_type,
8841                 (void *)&cmd_tunnel_filter_filter_type,
8842                 (void *)&cmd_tunnel_filter_tenant_id,
8843                 (void *)&cmd_tunnel_filter_queue_num,
8844                 NULL,
8845         },
8846 };
8847
8848 /* *** CONFIGURE TUNNEL UDP PORT *** */
8849 struct cmd_tunnel_udp_config {
8850         cmdline_fixed_string_t cmd;
8851         cmdline_fixed_string_t what;
8852         uint16_t udp_port;
8853         portid_t port_id;
8854 };
8855
8856 static void
8857 cmd_tunnel_udp_config_parsed(void *parsed_result,
8858                           __attribute__((unused)) struct cmdline *cl,
8859                           __attribute__((unused)) void *data)
8860 {
8861         struct cmd_tunnel_udp_config *res = parsed_result;
8862         struct rte_eth_udp_tunnel tunnel_udp;
8863         int ret;
8864
8865         tunnel_udp.udp_port = res->udp_port;
8866
8867         if (!strcmp(res->cmd, "rx_vxlan_port"))
8868                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8869
8870         if (!strcmp(res->what, "add"))
8871                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8872                                                       &tunnel_udp);
8873         else
8874                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8875                                                          &tunnel_udp);
8876
8877         if (ret < 0)
8878                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8879 }
8880
8881 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8882         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8883                                 cmd, "rx_vxlan_port");
8884 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8885         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8886                                 what, "add#rm");
8887 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8888         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8889                                 udp_port, UINT16);
8890 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8891         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8892                                 port_id, UINT16);
8893
8894 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8895         .f = cmd_tunnel_udp_config_parsed,
8896         .data = (void *)0,
8897         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8898                 "Add/Remove a tunneling UDP port filter",
8899         .tokens = {
8900                 (void *)&cmd_tunnel_udp_config_cmd,
8901                 (void *)&cmd_tunnel_udp_config_what,
8902                 (void *)&cmd_tunnel_udp_config_udp_port,
8903                 (void *)&cmd_tunnel_udp_config_port_id,
8904                 NULL,
8905         },
8906 };
8907
8908 struct cmd_config_tunnel_udp_port {
8909         cmdline_fixed_string_t port;
8910         cmdline_fixed_string_t config;
8911         portid_t port_id;
8912         cmdline_fixed_string_t udp_tunnel_port;
8913         cmdline_fixed_string_t action;
8914         cmdline_fixed_string_t tunnel_type;
8915         uint16_t udp_port;
8916 };
8917
8918 static void
8919 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8920                                __attribute__((unused)) struct cmdline *cl,
8921                                __attribute__((unused)) void *data)
8922 {
8923         struct cmd_config_tunnel_udp_port *res = parsed_result;
8924         struct rte_eth_udp_tunnel tunnel_udp;
8925         int ret = 0;
8926
8927         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8928                 return;
8929
8930         tunnel_udp.udp_port = res->udp_port;
8931
8932         if (!strcmp(res->tunnel_type, "vxlan")) {
8933                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8934         } else if (!strcmp(res->tunnel_type, "geneve")) {
8935                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8936         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
8937                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8938         } else {
8939                 printf("Invalid tunnel type\n");
8940                 return;
8941         }
8942
8943         if (!strcmp(res->action, "add"))
8944                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8945                                                       &tunnel_udp);
8946         else
8947                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8948                                                          &tunnel_udp);
8949
8950         if (ret < 0)
8951                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8952 }
8953
8954 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8955         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8956                                  "port");
8957 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8958         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8959                                  "config");
8960 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8961         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8962                               UINT16);
8963 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8964         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8965                                  udp_tunnel_port,
8966                                  "udp_tunnel_port");
8967 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8968         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8969                                  "add#rm");
8970 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8971         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8972                                  "vxlan#geneve#vxlan-gpe");
8973 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8974         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8975                               UINT16);
8976
8977 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8978         .f = cmd_cfg_tunnel_udp_port_parsed,
8979         .data = NULL,
8980         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
8981         .tokens = {
8982                 (void *)&cmd_config_tunnel_udp_port_port,
8983                 (void *)&cmd_config_tunnel_udp_port_config,
8984                 (void *)&cmd_config_tunnel_udp_port_port_id,
8985                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8986                 (void *)&cmd_config_tunnel_udp_port_action,
8987                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8988                 (void *)&cmd_config_tunnel_udp_port_value,
8989                 NULL,
8990         },
8991 };
8992
8993 /* *** GLOBAL CONFIG *** */
8994 struct cmd_global_config_result {
8995         cmdline_fixed_string_t cmd;
8996         portid_t port_id;
8997         cmdline_fixed_string_t cfg_type;
8998         uint8_t len;
8999 };
9000
9001 static void
9002 cmd_global_config_parsed(void *parsed_result,
9003                          __attribute__((unused)) struct cmdline *cl,
9004                          __attribute__((unused)) void *data)
9005 {
9006         struct cmd_global_config_result *res = parsed_result;
9007         struct rte_eth_global_cfg conf;
9008         int ret;
9009
9010         memset(&conf, 0, sizeof(conf));
9011         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9012         conf.cfg.gre_key_len = res->len;
9013         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9014                                       RTE_ETH_FILTER_SET, &conf);
9015         if (ret != 0)
9016                 printf("Global config error\n");
9017 }
9018
9019 cmdline_parse_token_string_t cmd_global_config_cmd =
9020         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9021                 "global_config");
9022 cmdline_parse_token_num_t cmd_global_config_port_id =
9023         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9024                                UINT16);
9025 cmdline_parse_token_string_t cmd_global_config_type =
9026         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9027                 cfg_type, "gre-key-len");
9028 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9029         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9030                 len, UINT8);
9031
9032 cmdline_parse_inst_t cmd_global_config = {
9033         .f = cmd_global_config_parsed,
9034         .data = (void *)NULL,
9035         .help_str = "global_config <port_id> gre-key-len <key_len>",
9036         .tokens = {
9037                 (void *)&cmd_global_config_cmd,
9038                 (void *)&cmd_global_config_port_id,
9039                 (void *)&cmd_global_config_type,
9040                 (void *)&cmd_global_config_gre_key_len,
9041                 NULL,
9042         },
9043 };
9044
9045 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9046 struct cmd_set_mirror_mask_result {
9047         cmdline_fixed_string_t set;
9048         cmdline_fixed_string_t port;
9049         portid_t port_id;
9050         cmdline_fixed_string_t mirror;
9051         uint8_t rule_id;
9052         cmdline_fixed_string_t what;
9053         cmdline_fixed_string_t value;
9054         cmdline_fixed_string_t dstpool;
9055         uint8_t dstpool_id;
9056         cmdline_fixed_string_t on;
9057 };
9058
9059 cmdline_parse_token_string_t cmd_mirror_mask_set =
9060         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9061                                 set, "set");
9062 cmdline_parse_token_string_t cmd_mirror_mask_port =
9063         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9064                                 port, "port");
9065 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9066         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9067                                 port_id, UINT16);
9068 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9069         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9070                                 mirror, "mirror-rule");
9071 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9072         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9073                                 rule_id, UINT8);
9074 cmdline_parse_token_string_t cmd_mirror_mask_what =
9075         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9076                                 what, "pool-mirror-up#pool-mirror-down"
9077                                       "#vlan-mirror");
9078 cmdline_parse_token_string_t cmd_mirror_mask_value =
9079         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9080                                 value, NULL);
9081 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9082         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9083                                 dstpool, "dst-pool");
9084 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9085         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9086                                 dstpool_id, UINT8);
9087 cmdline_parse_token_string_t cmd_mirror_mask_on =
9088         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9089                                 on, "on#off");
9090
9091 static void
9092 cmd_set_mirror_mask_parsed(void *parsed_result,
9093                        __attribute__((unused)) struct cmdline *cl,
9094                        __attribute__((unused)) void *data)
9095 {
9096         int ret,nb_item,i;
9097         struct cmd_set_mirror_mask_result *res = parsed_result;
9098         struct rte_eth_mirror_conf mr_conf;
9099
9100         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9101
9102         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9103
9104         mr_conf.dst_pool = res->dstpool_id;
9105
9106         if (!strcmp(res->what, "pool-mirror-up")) {
9107                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9108                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9109         } else if (!strcmp(res->what, "pool-mirror-down")) {
9110                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9111                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9112         } else if (!strcmp(res->what, "vlan-mirror")) {
9113                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9114                 nb_item = parse_item_list(res->value, "vlan",
9115                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9116                 if (nb_item <= 0)
9117                         return;
9118
9119                 for (i = 0; i < nb_item; i++) {
9120                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
9121                                 printf("Invalid vlan_id: must be < 4096\n");
9122                                 return;
9123                         }
9124
9125                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9126                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9127                 }
9128         }
9129
9130         if (!strcmp(res->on, "on"))
9131                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9132                                                 res->rule_id, 1);
9133         else
9134                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9135                                                 res->rule_id, 0);
9136         if (ret < 0)
9137                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9138 }
9139
9140 cmdline_parse_inst_t cmd_set_mirror_mask = {
9141                 .f = cmd_set_mirror_mask_parsed,
9142                 .data = NULL,
9143                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9144                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9145                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9146                 .tokens = {
9147                         (void *)&cmd_mirror_mask_set,
9148                         (void *)&cmd_mirror_mask_port,
9149                         (void *)&cmd_mirror_mask_portid,
9150                         (void *)&cmd_mirror_mask_mirror,
9151                         (void *)&cmd_mirror_mask_ruleid,
9152                         (void *)&cmd_mirror_mask_what,
9153                         (void *)&cmd_mirror_mask_value,
9154                         (void *)&cmd_mirror_mask_dstpool,
9155                         (void *)&cmd_mirror_mask_poolid,
9156                         (void *)&cmd_mirror_mask_on,
9157                         NULL,
9158                 },
9159 };
9160
9161 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9162 struct cmd_set_mirror_link_result {
9163         cmdline_fixed_string_t set;
9164         cmdline_fixed_string_t port;
9165         portid_t port_id;
9166         cmdline_fixed_string_t mirror;
9167         uint8_t rule_id;
9168         cmdline_fixed_string_t what;
9169         cmdline_fixed_string_t dstpool;
9170         uint8_t dstpool_id;
9171         cmdline_fixed_string_t on;
9172 };
9173
9174 cmdline_parse_token_string_t cmd_mirror_link_set =
9175         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9176                                  set, "set");
9177 cmdline_parse_token_string_t cmd_mirror_link_port =
9178         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9179                                 port, "port");
9180 cmdline_parse_token_num_t cmd_mirror_link_portid =
9181         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9182                                 port_id, UINT16);
9183 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9184         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9185                                 mirror, "mirror-rule");
9186 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9187         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9188                             rule_id, UINT8);
9189 cmdline_parse_token_string_t cmd_mirror_link_what =
9190         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9191                                 what, "uplink-mirror#downlink-mirror");
9192 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9193         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9194                                 dstpool, "dst-pool");
9195 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9196         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9197                                 dstpool_id, UINT8);
9198 cmdline_parse_token_string_t cmd_mirror_link_on =
9199         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9200                                 on, "on#off");
9201
9202 static void
9203 cmd_set_mirror_link_parsed(void *parsed_result,
9204                        __attribute__((unused)) struct cmdline *cl,
9205                        __attribute__((unused)) void *data)
9206 {
9207         int ret;
9208         struct cmd_set_mirror_link_result *res = parsed_result;
9209         struct rte_eth_mirror_conf mr_conf;
9210
9211         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9212         if (!strcmp(res->what, "uplink-mirror"))
9213                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9214         else
9215                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9216
9217         mr_conf.dst_pool = res->dstpool_id;
9218
9219         if (!strcmp(res->on, "on"))
9220                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9221                                                 res->rule_id, 1);
9222         else
9223                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9224                                                 res->rule_id, 0);
9225
9226         /* check the return value and print it if is < 0 */
9227         if (ret < 0)
9228                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9229
9230 }
9231
9232 cmdline_parse_inst_t cmd_set_mirror_link = {
9233                 .f = cmd_set_mirror_link_parsed,
9234                 .data = NULL,
9235                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9236                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9237                 .tokens = {
9238                         (void *)&cmd_mirror_link_set,
9239                         (void *)&cmd_mirror_link_port,
9240                         (void *)&cmd_mirror_link_portid,
9241                         (void *)&cmd_mirror_link_mirror,
9242                         (void *)&cmd_mirror_link_ruleid,
9243                         (void *)&cmd_mirror_link_what,
9244                         (void *)&cmd_mirror_link_dstpool,
9245                         (void *)&cmd_mirror_link_poolid,
9246                         (void *)&cmd_mirror_link_on,
9247                         NULL,
9248                 },
9249 };
9250
9251 /* *** RESET VM MIRROR RULE *** */
9252 struct cmd_rm_mirror_rule_result {
9253         cmdline_fixed_string_t reset;
9254         cmdline_fixed_string_t port;
9255         portid_t port_id;
9256         cmdline_fixed_string_t mirror;
9257         uint8_t rule_id;
9258 };
9259
9260 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9261         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9262                                  reset, "reset");
9263 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9264         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9265                                 port, "port");
9266 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9267         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9268                                 port_id, UINT16);
9269 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9270         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9271                                 mirror, "mirror-rule");
9272 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9273         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9274                                 rule_id, UINT8);
9275
9276 static void
9277 cmd_reset_mirror_rule_parsed(void *parsed_result,
9278                        __attribute__((unused)) struct cmdline *cl,
9279                        __attribute__((unused)) void *data)
9280 {
9281         int ret;
9282         struct cmd_set_mirror_link_result *res = parsed_result;
9283         /* check rule_id */
9284         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9285         if(ret < 0)
9286                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9287 }
9288
9289 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9290                 .f = cmd_reset_mirror_rule_parsed,
9291                 .data = NULL,
9292                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9293                 .tokens = {
9294                         (void *)&cmd_rm_mirror_rule_reset,
9295                         (void *)&cmd_rm_mirror_rule_port,
9296                         (void *)&cmd_rm_mirror_rule_portid,
9297                         (void *)&cmd_rm_mirror_rule_mirror,
9298                         (void *)&cmd_rm_mirror_rule_ruleid,
9299                         NULL,
9300                 },
9301 };
9302
9303 /* ******************************************************************************** */
9304
9305 struct cmd_dump_result {
9306         cmdline_fixed_string_t dump;
9307 };
9308
9309 static void
9310 dump_struct_sizes(void)
9311 {
9312 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9313         DUMP_SIZE(struct rte_mbuf);
9314         DUMP_SIZE(struct rte_mempool);
9315         DUMP_SIZE(struct rte_ring);
9316 #undef DUMP_SIZE
9317 }
9318
9319 static void cmd_dump_parsed(void *parsed_result,
9320                             __attribute__((unused)) struct cmdline *cl,
9321                             __attribute__((unused)) void *data)
9322 {
9323         struct cmd_dump_result *res = parsed_result;
9324
9325         if (!strcmp(res->dump, "dump_physmem"))
9326                 rte_dump_physmem_layout(stdout);
9327         else if (!strcmp(res->dump, "dump_memzone"))
9328                 rte_memzone_dump(stdout);
9329         else if (!strcmp(res->dump, "dump_struct_sizes"))
9330                 dump_struct_sizes();
9331         else if (!strcmp(res->dump, "dump_ring"))
9332                 rte_ring_list_dump(stdout);
9333         else if (!strcmp(res->dump, "dump_mempool"))
9334                 rte_mempool_list_dump(stdout);
9335         else if (!strcmp(res->dump, "dump_devargs"))
9336                 rte_devargs_dump(stdout);
9337         else if (!strcmp(res->dump, "dump_log_types"))
9338                 rte_log_dump(stdout);
9339 }
9340
9341 cmdline_parse_token_string_t cmd_dump_dump =
9342         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9343                 "dump_physmem#"
9344                 "dump_memzone#"
9345                 "dump_struct_sizes#"
9346                 "dump_ring#"
9347                 "dump_mempool#"
9348                 "dump_devargs#"
9349                 "dump_log_types");
9350
9351 cmdline_parse_inst_t cmd_dump = {
9352         .f = cmd_dump_parsed,  /* function to call */
9353         .data = NULL,      /* 2nd arg of func */
9354         .help_str = "Dump status",
9355         .tokens = {        /* token list, NULL terminated */
9356                 (void *)&cmd_dump_dump,
9357                 NULL,
9358         },
9359 };
9360
9361 /* ******************************************************************************** */
9362
9363 struct cmd_dump_one_result {
9364         cmdline_fixed_string_t dump;
9365         cmdline_fixed_string_t name;
9366 };
9367
9368 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9369                                 __attribute__((unused)) void *data)
9370 {
9371         struct cmd_dump_one_result *res = parsed_result;
9372
9373         if (!strcmp(res->dump, "dump_ring")) {
9374                 struct rte_ring *r;
9375                 r = rte_ring_lookup(res->name);
9376                 if (r == NULL) {
9377                         cmdline_printf(cl, "Cannot find ring\n");
9378                         return;
9379                 }
9380                 rte_ring_dump(stdout, r);
9381         } else if (!strcmp(res->dump, "dump_mempool")) {
9382                 struct rte_mempool *mp;
9383                 mp = rte_mempool_lookup(res->name);
9384                 if (mp == NULL) {
9385                         cmdline_printf(cl, "Cannot find mempool\n");
9386                         return;
9387                 }
9388                 rte_mempool_dump(stdout, mp);
9389         }
9390 }
9391
9392 cmdline_parse_token_string_t cmd_dump_one_dump =
9393         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9394                                  "dump_ring#dump_mempool");
9395
9396 cmdline_parse_token_string_t cmd_dump_one_name =
9397         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9398
9399 cmdline_parse_inst_t cmd_dump_one = {
9400         .f = cmd_dump_one_parsed,  /* function to call */
9401         .data = NULL,      /* 2nd arg of func */
9402         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9403         .tokens = {        /* token list, NULL terminated */
9404                 (void *)&cmd_dump_one_dump,
9405                 (void *)&cmd_dump_one_name,
9406                 NULL,
9407         },
9408 };
9409
9410 /* *** Add/Del syn filter *** */
9411 struct cmd_syn_filter_result {
9412         cmdline_fixed_string_t filter;
9413         portid_t port_id;
9414         cmdline_fixed_string_t ops;
9415         cmdline_fixed_string_t priority;
9416         cmdline_fixed_string_t high;
9417         cmdline_fixed_string_t queue;
9418         uint16_t queue_id;
9419 };
9420
9421 static void
9422 cmd_syn_filter_parsed(void *parsed_result,
9423                         __attribute__((unused)) struct cmdline *cl,
9424                         __attribute__((unused)) void *data)
9425 {
9426         struct cmd_syn_filter_result *res = parsed_result;
9427         struct rte_eth_syn_filter syn_filter;
9428         int ret = 0;
9429
9430         ret = rte_eth_dev_filter_supported(res->port_id,
9431                                         RTE_ETH_FILTER_SYN);
9432         if (ret < 0) {
9433                 printf("syn filter is not supported on port %u.\n",
9434                                 res->port_id);
9435                 return;
9436         }
9437
9438         memset(&syn_filter, 0, sizeof(syn_filter));
9439
9440         if (!strcmp(res->ops, "add")) {
9441                 if (!strcmp(res->high, "high"))
9442                         syn_filter.hig_pri = 1;
9443                 else
9444                         syn_filter.hig_pri = 0;
9445
9446                 syn_filter.queue = res->queue_id;
9447                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9448                                                 RTE_ETH_FILTER_SYN,
9449                                                 RTE_ETH_FILTER_ADD,
9450                                                 &syn_filter);
9451         } else
9452                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9453                                                 RTE_ETH_FILTER_SYN,
9454                                                 RTE_ETH_FILTER_DELETE,
9455                                                 &syn_filter);
9456
9457         if (ret < 0)
9458                 printf("syn filter programming error: (%s)\n",
9459                                 strerror(-ret));
9460 }
9461
9462 cmdline_parse_token_string_t cmd_syn_filter_filter =
9463         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9464         filter, "syn_filter");
9465 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9466         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9467         port_id, UINT16);
9468 cmdline_parse_token_string_t cmd_syn_filter_ops =
9469         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9470         ops, "add#del");
9471 cmdline_parse_token_string_t cmd_syn_filter_priority =
9472         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9473                                 priority, "priority");
9474 cmdline_parse_token_string_t cmd_syn_filter_high =
9475         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9476                                 high, "high#low");
9477 cmdline_parse_token_string_t cmd_syn_filter_queue =
9478         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9479                                 queue, "queue");
9480 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9481         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9482                                 queue_id, UINT16);
9483
9484 cmdline_parse_inst_t cmd_syn_filter = {
9485         .f = cmd_syn_filter_parsed,
9486         .data = NULL,
9487         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9488                 "<queue_id>: Add/Delete syn filter",
9489         .tokens = {
9490                 (void *)&cmd_syn_filter_filter,
9491                 (void *)&cmd_syn_filter_port_id,
9492                 (void *)&cmd_syn_filter_ops,
9493                 (void *)&cmd_syn_filter_priority,
9494                 (void *)&cmd_syn_filter_high,
9495                 (void *)&cmd_syn_filter_queue,
9496                 (void *)&cmd_syn_filter_queue_id,
9497                 NULL,
9498         },
9499 };
9500
9501 /* *** queue region set *** */
9502 struct cmd_queue_region_result {
9503         cmdline_fixed_string_t set;
9504         cmdline_fixed_string_t port;
9505         portid_t port_id;
9506         cmdline_fixed_string_t cmd;
9507         cmdline_fixed_string_t region;
9508         uint8_t  region_id;
9509         cmdline_fixed_string_t queue_start_index;
9510         uint8_t  queue_id;
9511         cmdline_fixed_string_t queue_num;
9512         uint8_t  queue_num_value;
9513 };
9514
9515 static void
9516 cmd_queue_region_parsed(void *parsed_result,
9517                         __attribute__((unused)) struct cmdline *cl,
9518                         __attribute__((unused)) void *data)
9519 {
9520         struct cmd_queue_region_result *res = parsed_result;
9521         int ret = -ENOTSUP;
9522 #ifdef RTE_LIBRTE_I40E_PMD
9523         struct rte_pmd_i40e_queue_region_conf region_conf;
9524         enum rte_pmd_i40e_queue_region_op op_type;
9525 #endif
9526
9527         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9528                 return;
9529
9530 #ifdef RTE_LIBRTE_I40E_PMD
9531         memset(&region_conf, 0, sizeof(region_conf));
9532         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9533         region_conf.region_id = res->region_id;
9534         region_conf.queue_num = res->queue_num_value;
9535         region_conf.queue_start_index = res->queue_id;
9536
9537         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9538                                 op_type, &region_conf);
9539 #endif
9540
9541         switch (ret) {
9542         case 0:
9543                 break;
9544         case -ENOTSUP:
9545                 printf("function not implemented or supported\n");
9546                 break;
9547         default:
9548                 printf("queue region config error: (%s)\n", strerror(-ret));
9549         }
9550 }
9551
9552 cmdline_parse_token_string_t cmd_queue_region_set =
9553 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9554                 set, "set");
9555 cmdline_parse_token_string_t cmd_queue_region_port =
9556         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9557 cmdline_parse_token_num_t cmd_queue_region_port_id =
9558         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9559                                 port_id, UINT16);
9560 cmdline_parse_token_string_t cmd_queue_region_cmd =
9561         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9562                                  cmd, "queue-region");
9563 cmdline_parse_token_string_t cmd_queue_region_id =
9564         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9565                                 region, "region_id");
9566 cmdline_parse_token_num_t cmd_queue_region_index =
9567         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9568                                 region_id, UINT8);
9569 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9570         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9571                                 queue_start_index, "queue_start_index");
9572 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9573         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9574                                 queue_id, UINT8);
9575 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9576         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9577                                 queue_num, "queue_num");
9578 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9579         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9580                                 queue_num_value, UINT8);
9581
9582 cmdline_parse_inst_t cmd_queue_region = {
9583         .f = cmd_queue_region_parsed,
9584         .data = NULL,
9585         .help_str = "set port <port_id> queue-region region_id <value> "
9586                 "queue_start_index <value> queue_num <value>: Set a queue region",
9587         .tokens = {
9588                 (void *)&cmd_queue_region_set,
9589                 (void *)&cmd_queue_region_port,
9590                 (void *)&cmd_queue_region_port_id,
9591                 (void *)&cmd_queue_region_cmd,
9592                 (void *)&cmd_queue_region_id,
9593                 (void *)&cmd_queue_region_index,
9594                 (void *)&cmd_queue_region_queue_start_index,
9595                 (void *)&cmd_queue_region_queue_id,
9596                 (void *)&cmd_queue_region_queue_num,
9597                 (void *)&cmd_queue_region_queue_num_value,
9598                 NULL,
9599         },
9600 };
9601
9602 /* *** queue region and flowtype set *** */
9603 struct cmd_region_flowtype_result {
9604         cmdline_fixed_string_t set;
9605         cmdline_fixed_string_t port;
9606         portid_t port_id;
9607         cmdline_fixed_string_t cmd;
9608         cmdline_fixed_string_t region;
9609         uint8_t  region_id;
9610         cmdline_fixed_string_t flowtype;
9611         uint8_t  flowtype_id;
9612 };
9613
9614 static void
9615 cmd_region_flowtype_parsed(void *parsed_result,
9616                         __attribute__((unused)) struct cmdline *cl,
9617                         __attribute__((unused)) void *data)
9618 {
9619         struct cmd_region_flowtype_result *res = parsed_result;
9620         int ret = -ENOTSUP;
9621 #ifdef RTE_LIBRTE_I40E_PMD
9622         struct rte_pmd_i40e_queue_region_conf region_conf;
9623         enum rte_pmd_i40e_queue_region_op op_type;
9624 #endif
9625
9626         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9627                 return;
9628
9629 #ifdef RTE_LIBRTE_I40E_PMD
9630         memset(&region_conf, 0, sizeof(region_conf));
9631
9632         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9633         region_conf.region_id = res->region_id;
9634         region_conf.hw_flowtype = res->flowtype_id;
9635
9636         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9637                         op_type, &region_conf);
9638 #endif
9639
9640         switch (ret) {
9641         case 0:
9642                 break;
9643         case -ENOTSUP:
9644                 printf("function not implemented or supported\n");
9645                 break;
9646         default:
9647                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9648         }
9649 }
9650
9651 cmdline_parse_token_string_t cmd_region_flowtype_set =
9652 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9653                                 set, "set");
9654 cmdline_parse_token_string_t cmd_region_flowtype_port =
9655         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9656                                 port, "port");
9657 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9658         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9659                                 port_id, UINT16);
9660 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9661         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9662                                 cmd, "queue-region");
9663 cmdline_parse_token_string_t cmd_region_flowtype_index =
9664         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9665                                 region, "region_id");
9666 cmdline_parse_token_num_t cmd_region_flowtype_id =
9667         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9668                                 region_id, UINT8);
9669 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9670         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9671                                 flowtype, "flowtype");
9672 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9673         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9674                                 flowtype_id, UINT8);
9675 cmdline_parse_inst_t cmd_region_flowtype = {
9676         .f = cmd_region_flowtype_parsed,
9677         .data = NULL,
9678         .help_str = "set port <port_id> queue-region region_id <value> "
9679                 "flowtype <value>: Set a flowtype region index",
9680         .tokens = {
9681                 (void *)&cmd_region_flowtype_set,
9682                 (void *)&cmd_region_flowtype_port,
9683                 (void *)&cmd_region_flowtype_port_index,
9684                 (void *)&cmd_region_flowtype_cmd,
9685                 (void *)&cmd_region_flowtype_index,
9686                 (void *)&cmd_region_flowtype_id,
9687                 (void *)&cmd_region_flowtype_flow_index,
9688                 (void *)&cmd_region_flowtype_flow_id,
9689                 NULL,
9690         },
9691 };
9692
9693 /* *** User Priority (UP) to queue region (region_id) set *** */
9694 struct cmd_user_priority_region_result {
9695         cmdline_fixed_string_t set;
9696         cmdline_fixed_string_t port;
9697         portid_t port_id;
9698         cmdline_fixed_string_t cmd;
9699         cmdline_fixed_string_t user_priority;
9700         uint8_t  user_priority_id;
9701         cmdline_fixed_string_t region;
9702         uint8_t  region_id;
9703 };
9704
9705 static void
9706 cmd_user_priority_region_parsed(void *parsed_result,
9707                         __attribute__((unused)) struct cmdline *cl,
9708                         __attribute__((unused)) void *data)
9709 {
9710         struct cmd_user_priority_region_result *res = parsed_result;
9711         int ret = -ENOTSUP;
9712 #ifdef RTE_LIBRTE_I40E_PMD
9713         struct rte_pmd_i40e_queue_region_conf region_conf;
9714         enum rte_pmd_i40e_queue_region_op op_type;
9715 #endif
9716
9717         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9718                 return;
9719
9720 #ifdef RTE_LIBRTE_I40E_PMD
9721         memset(&region_conf, 0, sizeof(region_conf));
9722         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9723         region_conf.user_priority = res->user_priority_id;
9724         region_conf.region_id = res->region_id;
9725
9726         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9727                                 op_type, &region_conf);
9728 #endif
9729
9730         switch (ret) {
9731         case 0:
9732                 break;
9733         case -ENOTSUP:
9734                 printf("function not implemented or supported\n");
9735                 break;
9736         default:
9737                 printf("user_priority region config error: (%s)\n",
9738                                 strerror(-ret));
9739         }
9740 }
9741
9742 cmdline_parse_token_string_t cmd_user_priority_region_set =
9743         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9744                                 set, "set");
9745 cmdline_parse_token_string_t cmd_user_priority_region_port =
9746         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9747                                 port, "port");
9748 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9749         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9750                                 port_id, UINT16);
9751 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9752         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9753                                 cmd, "queue-region");
9754 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9755         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9756                                 user_priority, "UP");
9757 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9758         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9759                                 user_priority_id, UINT8);
9760 cmdline_parse_token_string_t cmd_user_priority_region_region =
9761         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9762                                 region, "region_id");
9763 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9764         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9765                                 region_id, UINT8);
9766
9767 cmdline_parse_inst_t cmd_user_priority_region = {
9768         .f = cmd_user_priority_region_parsed,
9769         .data = NULL,
9770         .help_str = "set port <port_id> queue-region UP <value> "
9771                 "region_id <value>: Set the mapping of User Priority (UP) "
9772                 "to queue region (region_id) ",
9773         .tokens = {
9774                 (void *)&cmd_user_priority_region_set,
9775                 (void *)&cmd_user_priority_region_port,
9776                 (void *)&cmd_user_priority_region_port_index,
9777                 (void *)&cmd_user_priority_region_cmd,
9778                 (void *)&cmd_user_priority_region_UP,
9779                 (void *)&cmd_user_priority_region_UP_id,
9780                 (void *)&cmd_user_priority_region_region,
9781                 (void *)&cmd_user_priority_region_region_id,
9782                 NULL,
9783         },
9784 };
9785
9786 /* *** flush all queue region related configuration *** */
9787 struct cmd_flush_queue_region_result {
9788         cmdline_fixed_string_t set;
9789         cmdline_fixed_string_t port;
9790         portid_t port_id;
9791         cmdline_fixed_string_t cmd;
9792         cmdline_fixed_string_t flush;
9793         cmdline_fixed_string_t what;
9794 };
9795
9796 static void
9797 cmd_flush_queue_region_parsed(void *parsed_result,
9798                         __attribute__((unused)) struct cmdline *cl,
9799                         __attribute__((unused)) void *data)
9800 {
9801         struct cmd_flush_queue_region_result *res = parsed_result;
9802         int ret = -ENOTSUP;
9803 #ifdef RTE_LIBRTE_I40E_PMD
9804         struct rte_pmd_i40e_queue_region_conf region_conf;
9805         enum rte_pmd_i40e_queue_region_op op_type;
9806 #endif
9807
9808         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9809                 return;
9810
9811 #ifdef RTE_LIBRTE_I40E_PMD
9812         memset(&region_conf, 0, sizeof(region_conf));
9813
9814         if (strcmp(res->what, "on") == 0)
9815                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9816         else
9817                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9818
9819         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9820                                 op_type, &region_conf);
9821 #endif
9822
9823         switch (ret) {
9824         case 0:
9825                 break;
9826         case -ENOTSUP:
9827                 printf("function not implemented or supported\n");
9828                 break;
9829         default:
9830                 printf("queue region config flush error: (%s)\n",
9831                                 strerror(-ret));
9832         }
9833 }
9834
9835 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9836         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9837                                 set, "set");
9838 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9839         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9840                                 port, "port");
9841 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9842         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9843                                 port_id, UINT16);
9844 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9845         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9846                                 cmd, "queue-region");
9847 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9848         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9849                                 flush, "flush");
9850 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9851         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9852                                 what, "on#off");
9853
9854 cmdline_parse_inst_t cmd_flush_queue_region = {
9855         .f = cmd_flush_queue_region_parsed,
9856         .data = NULL,
9857         .help_str = "set port <port_id> queue-region flush on|off"
9858                 ": flush all queue region related configuration",
9859         .tokens = {
9860                 (void *)&cmd_flush_queue_region_set,
9861                 (void *)&cmd_flush_queue_region_port,
9862                 (void *)&cmd_flush_queue_region_port_index,
9863                 (void *)&cmd_flush_queue_region_cmd,
9864                 (void *)&cmd_flush_queue_region_flush,
9865                 (void *)&cmd_flush_queue_region_what,
9866                 NULL,
9867         },
9868 };
9869
9870 /* *** get all queue region related configuration info *** */
9871 struct cmd_show_queue_region_info {
9872         cmdline_fixed_string_t show;
9873         cmdline_fixed_string_t port;
9874         portid_t port_id;
9875         cmdline_fixed_string_t cmd;
9876 };
9877
9878 static void
9879 cmd_show_queue_region_info_parsed(void *parsed_result,
9880                         __attribute__((unused)) struct cmdline *cl,
9881                         __attribute__((unused)) void *data)
9882 {
9883         struct cmd_show_queue_region_info *res = parsed_result;
9884         int ret = -ENOTSUP;
9885 #ifdef RTE_LIBRTE_I40E_PMD
9886         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9887         enum rte_pmd_i40e_queue_region_op op_type;
9888 #endif
9889
9890         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9891                 return;
9892
9893 #ifdef RTE_LIBRTE_I40E_PMD
9894         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9895
9896         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9897
9898         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9899                                         op_type, &rte_pmd_regions);
9900
9901         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9902 #endif
9903
9904         switch (ret) {
9905         case 0:
9906                 break;
9907         case -ENOTSUP:
9908                 printf("function not implemented or supported\n");
9909                 break;
9910         default:
9911                 printf("queue region config info show error: (%s)\n",
9912                                 strerror(-ret));
9913         }
9914 }
9915
9916 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9917 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9918                                 show, "show");
9919 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9920         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9921                                 port, "port");
9922 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9923         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9924                                 port_id, UINT16);
9925 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9926         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9927                                 cmd, "queue-region");
9928
9929 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9930         .f = cmd_show_queue_region_info_parsed,
9931         .data = NULL,
9932         .help_str = "show port <port_id> queue-region"
9933                 ": show all queue region related configuration info",
9934         .tokens = {
9935                 (void *)&cmd_show_queue_region_info_get,
9936                 (void *)&cmd_show_queue_region_info_port,
9937                 (void *)&cmd_show_queue_region_info_port_index,
9938                 (void *)&cmd_show_queue_region_info_cmd,
9939                 NULL,
9940         },
9941 };
9942
9943 /* *** ADD/REMOVE A 2tuple FILTER *** */
9944 struct cmd_2tuple_filter_result {
9945         cmdline_fixed_string_t filter;
9946         portid_t port_id;
9947         cmdline_fixed_string_t ops;
9948         cmdline_fixed_string_t dst_port;
9949         uint16_t dst_port_value;
9950         cmdline_fixed_string_t protocol;
9951         uint8_t protocol_value;
9952         cmdline_fixed_string_t mask;
9953         uint8_t  mask_value;
9954         cmdline_fixed_string_t tcp_flags;
9955         uint8_t tcp_flags_value;
9956         cmdline_fixed_string_t priority;
9957         uint8_t  priority_value;
9958         cmdline_fixed_string_t queue;
9959         uint16_t  queue_id;
9960 };
9961
9962 static void
9963 cmd_2tuple_filter_parsed(void *parsed_result,
9964                         __attribute__((unused)) struct cmdline *cl,
9965                         __attribute__((unused)) void *data)
9966 {
9967         struct rte_eth_ntuple_filter filter;
9968         struct cmd_2tuple_filter_result *res = parsed_result;
9969         int ret = 0;
9970
9971         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9972         if (ret < 0) {
9973                 printf("ntuple filter is not supported on port %u.\n",
9974                         res->port_id);
9975                 return;
9976         }
9977
9978         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9979
9980         filter.flags = RTE_2TUPLE_FLAGS;
9981         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9982         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9983         filter.proto = res->protocol_value;
9984         filter.priority = res->priority_value;
9985         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9986                 printf("nonzero tcp_flags is only meaningful"
9987                         " when protocol is TCP.\n");
9988                 return;
9989         }
9990         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9991                 printf("invalid TCP flags.\n");
9992                 return;
9993         }
9994
9995         if (res->tcp_flags_value != 0) {
9996                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9997                 filter.tcp_flags = res->tcp_flags_value;
9998         }
9999
10000         /* need convert to big endian. */
10001         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10002         filter.queue = res->queue_id;
10003
10004         if (!strcmp(res->ops, "add"))
10005                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10006                                 RTE_ETH_FILTER_NTUPLE,
10007                                 RTE_ETH_FILTER_ADD,
10008                                 &filter);
10009         else
10010                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10011                                 RTE_ETH_FILTER_NTUPLE,
10012                                 RTE_ETH_FILTER_DELETE,
10013                                 &filter);
10014         if (ret < 0)
10015                 printf("2tuple filter programming error: (%s)\n",
10016                         strerror(-ret));
10017
10018 }
10019
10020 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10021         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10022                                  filter, "2tuple_filter");
10023 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10024         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10025                                 port_id, UINT16);
10026 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10027         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10028                                  ops, "add#del");
10029 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10030         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10031                                 dst_port, "dst_port");
10032 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10033         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10034                                 dst_port_value, UINT16);
10035 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10036         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10037                                 protocol, "protocol");
10038 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10039         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10040                                 protocol_value, UINT8);
10041 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10042         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10043                                 mask, "mask");
10044 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10045         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10046                                 mask_value, INT8);
10047 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10048         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10049                                 tcp_flags, "tcp_flags");
10050 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10051         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10052                                 tcp_flags_value, UINT8);
10053 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10054         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10055                                 priority, "priority");
10056 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10057         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10058                                 priority_value, UINT8);
10059 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10060         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10061                                 queue, "queue");
10062 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10063         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10064                                 queue_id, UINT16);
10065
10066 cmdline_parse_inst_t cmd_2tuple_filter = {
10067         .f = cmd_2tuple_filter_parsed,
10068         .data = NULL,
10069         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10070                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10071                 "<queue_id>: Add a 2tuple filter",
10072         .tokens = {
10073                 (void *)&cmd_2tuple_filter_filter,
10074                 (void *)&cmd_2tuple_filter_port_id,
10075                 (void *)&cmd_2tuple_filter_ops,
10076                 (void *)&cmd_2tuple_filter_dst_port,
10077                 (void *)&cmd_2tuple_filter_dst_port_value,
10078                 (void *)&cmd_2tuple_filter_protocol,
10079                 (void *)&cmd_2tuple_filter_protocol_value,
10080                 (void *)&cmd_2tuple_filter_mask,
10081                 (void *)&cmd_2tuple_filter_mask_value,
10082                 (void *)&cmd_2tuple_filter_tcp_flags,
10083                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10084                 (void *)&cmd_2tuple_filter_priority,
10085                 (void *)&cmd_2tuple_filter_priority_value,
10086                 (void *)&cmd_2tuple_filter_queue,
10087                 (void *)&cmd_2tuple_filter_queue_id,
10088                 NULL,
10089         },
10090 };
10091
10092 /* *** ADD/REMOVE A 5tuple FILTER *** */
10093 struct cmd_5tuple_filter_result {
10094         cmdline_fixed_string_t filter;
10095         portid_t port_id;
10096         cmdline_fixed_string_t ops;
10097         cmdline_fixed_string_t dst_ip;
10098         cmdline_ipaddr_t dst_ip_value;
10099         cmdline_fixed_string_t src_ip;
10100         cmdline_ipaddr_t src_ip_value;
10101         cmdline_fixed_string_t dst_port;
10102         uint16_t dst_port_value;
10103         cmdline_fixed_string_t src_port;
10104         uint16_t src_port_value;
10105         cmdline_fixed_string_t protocol;
10106         uint8_t protocol_value;
10107         cmdline_fixed_string_t mask;
10108         uint8_t  mask_value;
10109         cmdline_fixed_string_t tcp_flags;
10110         uint8_t tcp_flags_value;
10111         cmdline_fixed_string_t priority;
10112         uint8_t  priority_value;
10113         cmdline_fixed_string_t queue;
10114         uint16_t  queue_id;
10115 };
10116
10117 static void
10118 cmd_5tuple_filter_parsed(void *parsed_result,
10119                         __attribute__((unused)) struct cmdline *cl,
10120                         __attribute__((unused)) void *data)
10121 {
10122         struct rte_eth_ntuple_filter filter;
10123         struct cmd_5tuple_filter_result *res = parsed_result;
10124         int ret = 0;
10125
10126         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10127         if (ret < 0) {
10128                 printf("ntuple filter is not supported on port %u.\n",
10129                         res->port_id);
10130                 return;
10131         }
10132
10133         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10134
10135         filter.flags = RTE_5TUPLE_FLAGS;
10136         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10137         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10138         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10139         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10140         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10141         filter.proto = res->protocol_value;
10142         filter.priority = res->priority_value;
10143         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10144                 printf("nonzero tcp_flags is only meaningful"
10145                         " when protocol is TCP.\n");
10146                 return;
10147         }
10148         if (res->tcp_flags_value > TCP_FLAG_ALL) {
10149                 printf("invalid TCP flags.\n");
10150                 return;
10151         }
10152
10153         if (res->tcp_flags_value != 0) {
10154                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10155                 filter.tcp_flags = res->tcp_flags_value;
10156         }
10157
10158         if (res->dst_ip_value.family == AF_INET)
10159                 /* no need to convert, already big endian. */
10160                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10161         else {
10162                 if (filter.dst_ip_mask == 0) {
10163                         printf("can not support ipv6 involved compare.\n");
10164                         return;
10165                 }
10166                 filter.dst_ip = 0;
10167         }
10168
10169         if (res->src_ip_value.family == AF_INET)
10170                 /* no need to convert, already big endian. */
10171                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10172         else {
10173                 if (filter.src_ip_mask == 0) {
10174                         printf("can not support ipv6 involved compare.\n");
10175                         return;
10176                 }
10177                 filter.src_ip = 0;
10178         }
10179         /* need convert to big endian. */
10180         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10181         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10182         filter.queue = res->queue_id;
10183
10184         if (!strcmp(res->ops, "add"))
10185                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10186                                 RTE_ETH_FILTER_NTUPLE,
10187                                 RTE_ETH_FILTER_ADD,
10188                                 &filter);
10189         else
10190                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10191                                 RTE_ETH_FILTER_NTUPLE,
10192                                 RTE_ETH_FILTER_DELETE,
10193                                 &filter);
10194         if (ret < 0)
10195                 printf("5tuple filter programming error: (%s)\n",
10196                         strerror(-ret));
10197 }
10198
10199 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10200         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10201                                  filter, "5tuple_filter");
10202 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10203         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10204                                 port_id, UINT16);
10205 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10206         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10207                                  ops, "add#del");
10208 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10209         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10210                                 dst_ip, "dst_ip");
10211 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10212         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10213                                 dst_ip_value);
10214 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10215         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10216                                 src_ip, "src_ip");
10217 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10218         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10219                                 src_ip_value);
10220 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10221         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10222                                 dst_port, "dst_port");
10223 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10224         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10225                                 dst_port_value, UINT16);
10226 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10227         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10228                                 src_port, "src_port");
10229 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10230         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10231                                 src_port_value, UINT16);
10232 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10233         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10234                                 protocol, "protocol");
10235 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10236         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10237                                 protocol_value, UINT8);
10238 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10239         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10240                                 mask, "mask");
10241 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10242         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10243                                 mask_value, INT8);
10244 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10245         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10246                                 tcp_flags, "tcp_flags");
10247 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10248         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10249                                 tcp_flags_value, UINT8);
10250 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10251         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10252                                 priority, "priority");
10253 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10254         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10255                                 priority_value, UINT8);
10256 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10257         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10258                                 queue, "queue");
10259 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10260         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10261                                 queue_id, UINT16);
10262
10263 cmdline_parse_inst_t cmd_5tuple_filter = {
10264         .f = cmd_5tuple_filter_parsed,
10265         .data = NULL,
10266         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10267                 "src_ip <value> dst_port <value> src_port <value> "
10268                 "protocol <value>  mask <value> tcp_flags <value> "
10269                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10270         .tokens = {
10271                 (void *)&cmd_5tuple_filter_filter,
10272                 (void *)&cmd_5tuple_filter_port_id,
10273                 (void *)&cmd_5tuple_filter_ops,
10274                 (void *)&cmd_5tuple_filter_dst_ip,
10275                 (void *)&cmd_5tuple_filter_dst_ip_value,
10276                 (void *)&cmd_5tuple_filter_src_ip,
10277                 (void *)&cmd_5tuple_filter_src_ip_value,
10278                 (void *)&cmd_5tuple_filter_dst_port,
10279                 (void *)&cmd_5tuple_filter_dst_port_value,
10280                 (void *)&cmd_5tuple_filter_src_port,
10281                 (void *)&cmd_5tuple_filter_src_port_value,
10282                 (void *)&cmd_5tuple_filter_protocol,
10283                 (void *)&cmd_5tuple_filter_protocol_value,
10284                 (void *)&cmd_5tuple_filter_mask,
10285                 (void *)&cmd_5tuple_filter_mask_value,
10286                 (void *)&cmd_5tuple_filter_tcp_flags,
10287                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10288                 (void *)&cmd_5tuple_filter_priority,
10289                 (void *)&cmd_5tuple_filter_priority_value,
10290                 (void *)&cmd_5tuple_filter_queue,
10291                 (void *)&cmd_5tuple_filter_queue_id,
10292                 NULL,
10293         },
10294 };
10295
10296 /* *** ADD/REMOVE A flex FILTER *** */
10297 struct cmd_flex_filter_result {
10298         cmdline_fixed_string_t filter;
10299         cmdline_fixed_string_t ops;
10300         portid_t port_id;
10301         cmdline_fixed_string_t len;
10302         uint8_t len_value;
10303         cmdline_fixed_string_t bytes;
10304         cmdline_fixed_string_t bytes_value;
10305         cmdline_fixed_string_t mask;
10306         cmdline_fixed_string_t mask_value;
10307         cmdline_fixed_string_t priority;
10308         uint8_t priority_value;
10309         cmdline_fixed_string_t queue;
10310         uint16_t queue_id;
10311 };
10312
10313 static int xdigit2val(unsigned char c)
10314 {
10315         int val;
10316         if (isdigit(c))
10317                 val = c - '0';
10318         else if (isupper(c))
10319                 val = c - 'A' + 10;
10320         else
10321                 val = c - 'a' + 10;
10322         return val;
10323 }
10324
10325 static void
10326 cmd_flex_filter_parsed(void *parsed_result,
10327                           __attribute__((unused)) struct cmdline *cl,
10328                           __attribute__((unused)) void *data)
10329 {
10330         int ret = 0;
10331         struct rte_eth_flex_filter filter;
10332         struct cmd_flex_filter_result *res = parsed_result;
10333         char *bytes_ptr, *mask_ptr;
10334         uint16_t len, i, j = 0;
10335         char c;
10336         int val;
10337         uint8_t byte = 0;
10338
10339         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10340                 printf("the len exceed the max length 128\n");
10341                 return;
10342         }
10343         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10344         filter.len = res->len_value;
10345         filter.priority = res->priority_value;
10346         filter.queue = res->queue_id;
10347         bytes_ptr = res->bytes_value;
10348         mask_ptr = res->mask_value;
10349
10350          /* translate bytes string to array. */
10351         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10352                 (bytes_ptr[1] == 'X')))
10353                 bytes_ptr += 2;
10354         len = strnlen(bytes_ptr, res->len_value * 2);
10355         if (len == 0 || (len % 8 != 0)) {
10356                 printf("please check len and bytes input\n");
10357                 return;
10358         }
10359         for (i = 0; i < len; i++) {
10360                 c = bytes_ptr[i];
10361                 if (isxdigit(c) == 0) {
10362                         /* invalid characters. */
10363                         printf("invalid input\n");
10364                         return;
10365                 }
10366                 val = xdigit2val(c);
10367                 if (i % 2) {
10368                         byte |= val;
10369                         filter.bytes[j] = byte;
10370                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10371                         j++;
10372                         byte = 0;
10373                 } else
10374                         byte |= val << 4;
10375         }
10376         printf("\n");
10377          /* translate mask string to uint8_t array. */
10378         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10379                 (mask_ptr[1] == 'X')))
10380                 mask_ptr += 2;
10381         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10382         if (len == 0) {
10383                 printf("invalid input\n");
10384                 return;
10385         }
10386         j = 0;
10387         byte = 0;
10388         for (i = 0; i < len; i++) {
10389                 c = mask_ptr[i];
10390                 if (isxdigit(c) == 0) {
10391                         /* invalid characters. */
10392                         printf("invalid input\n");
10393                         return;
10394                 }
10395                 val = xdigit2val(c);
10396                 if (i % 2) {
10397                         byte |= val;
10398                         filter.mask[j] = byte;
10399                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10400                         j++;
10401                         byte = 0;
10402                 } else
10403                         byte |= val << 4;
10404         }
10405         printf("\n");
10406
10407         if (!strcmp(res->ops, "add"))
10408                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10409                                 RTE_ETH_FILTER_FLEXIBLE,
10410                                 RTE_ETH_FILTER_ADD,
10411                                 &filter);
10412         else
10413                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10414                                 RTE_ETH_FILTER_FLEXIBLE,
10415                                 RTE_ETH_FILTER_DELETE,
10416                                 &filter);
10417
10418         if (ret < 0)
10419                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10420 }
10421
10422 cmdline_parse_token_string_t cmd_flex_filter_filter =
10423         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10424                                 filter, "flex_filter");
10425 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10426         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10427                                 port_id, UINT16);
10428 cmdline_parse_token_string_t cmd_flex_filter_ops =
10429         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10430                                 ops, "add#del");
10431 cmdline_parse_token_string_t cmd_flex_filter_len =
10432         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10433                                 len, "len");
10434 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10435         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10436                                 len_value, UINT8);
10437 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10438         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10439                                 bytes, "bytes");
10440 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10441         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10442                                 bytes_value, NULL);
10443 cmdline_parse_token_string_t cmd_flex_filter_mask =
10444         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10445                                 mask, "mask");
10446 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10447         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10448                                 mask_value, NULL);
10449 cmdline_parse_token_string_t cmd_flex_filter_priority =
10450         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10451                                 priority, "priority");
10452 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10453         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10454                                 priority_value, UINT8);
10455 cmdline_parse_token_string_t cmd_flex_filter_queue =
10456         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10457                                 queue, "queue");
10458 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10459         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10460                                 queue_id, UINT16);
10461 cmdline_parse_inst_t cmd_flex_filter = {
10462         .f = cmd_flex_filter_parsed,
10463         .data = NULL,
10464         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10465                 "<value> mask <value> priority <value> queue <queue_id>: "
10466                 "Add/Del a flex filter",
10467         .tokens = {
10468                 (void *)&cmd_flex_filter_filter,
10469                 (void *)&cmd_flex_filter_port_id,
10470                 (void *)&cmd_flex_filter_ops,
10471                 (void *)&cmd_flex_filter_len,
10472                 (void *)&cmd_flex_filter_len_value,
10473                 (void *)&cmd_flex_filter_bytes,
10474                 (void *)&cmd_flex_filter_bytes_value,
10475                 (void *)&cmd_flex_filter_mask,
10476                 (void *)&cmd_flex_filter_mask_value,
10477                 (void *)&cmd_flex_filter_priority,
10478                 (void *)&cmd_flex_filter_priority_value,
10479                 (void *)&cmd_flex_filter_queue,
10480                 (void *)&cmd_flex_filter_queue_id,
10481                 NULL,
10482         },
10483 };
10484
10485 /* *** Filters Control *** */
10486
10487 /* *** deal with ethertype filter *** */
10488 struct cmd_ethertype_filter_result {
10489         cmdline_fixed_string_t filter;
10490         portid_t port_id;
10491         cmdline_fixed_string_t ops;
10492         cmdline_fixed_string_t mac;
10493         struct ether_addr mac_addr;
10494         cmdline_fixed_string_t ethertype;
10495         uint16_t ethertype_value;
10496         cmdline_fixed_string_t drop;
10497         cmdline_fixed_string_t queue;
10498         uint16_t  queue_id;
10499 };
10500
10501 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10502         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10503                                  filter, "ethertype_filter");
10504 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10505         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10506                               port_id, UINT16);
10507 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10508         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10509                                  ops, "add#del");
10510 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10511         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10512                                  mac, "mac_addr#mac_ignr");
10513 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10514         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10515                                      mac_addr);
10516 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10517         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10518                                  ethertype, "ethertype");
10519 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10520         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10521                               ethertype_value, UINT16);
10522 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10523         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10524                                  drop, "drop#fwd");
10525 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10526         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10527                                  queue, "queue");
10528 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10529         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10530                               queue_id, UINT16);
10531
10532 static void
10533 cmd_ethertype_filter_parsed(void *parsed_result,
10534                           __attribute__((unused)) struct cmdline *cl,
10535                           __attribute__((unused)) void *data)
10536 {
10537         struct cmd_ethertype_filter_result *res = parsed_result;
10538         struct rte_eth_ethertype_filter filter;
10539         int ret = 0;
10540
10541         ret = rte_eth_dev_filter_supported(res->port_id,
10542                         RTE_ETH_FILTER_ETHERTYPE);
10543         if (ret < 0) {
10544                 printf("ethertype filter is not supported on port %u.\n",
10545                         res->port_id);
10546                 return;
10547         }
10548
10549         memset(&filter, 0, sizeof(filter));
10550         if (!strcmp(res->mac, "mac_addr")) {
10551                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10552                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10553                         sizeof(struct ether_addr));
10554         }
10555         if (!strcmp(res->drop, "drop"))
10556                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10557         filter.ether_type = res->ethertype_value;
10558         filter.queue = res->queue_id;
10559
10560         if (!strcmp(res->ops, "add"))
10561                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10562                                 RTE_ETH_FILTER_ETHERTYPE,
10563                                 RTE_ETH_FILTER_ADD,
10564                                 &filter);
10565         else
10566                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10567                                 RTE_ETH_FILTER_ETHERTYPE,
10568                                 RTE_ETH_FILTER_DELETE,
10569                                 &filter);
10570         if (ret < 0)
10571                 printf("ethertype filter programming error: (%s)\n",
10572                         strerror(-ret));
10573 }
10574
10575 cmdline_parse_inst_t cmd_ethertype_filter = {
10576         .f = cmd_ethertype_filter_parsed,
10577         .data = NULL,
10578         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10579                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10580                 "Add or delete an ethertype filter entry",
10581         .tokens = {
10582                 (void *)&cmd_ethertype_filter_filter,
10583                 (void *)&cmd_ethertype_filter_port_id,
10584                 (void *)&cmd_ethertype_filter_ops,
10585                 (void *)&cmd_ethertype_filter_mac,
10586                 (void *)&cmd_ethertype_filter_mac_addr,
10587                 (void *)&cmd_ethertype_filter_ethertype,
10588                 (void *)&cmd_ethertype_filter_ethertype_value,
10589                 (void *)&cmd_ethertype_filter_drop,
10590                 (void *)&cmd_ethertype_filter_queue,
10591                 (void *)&cmd_ethertype_filter_queue_id,
10592                 NULL,
10593         },
10594 };
10595
10596 /* *** deal with flow director filter *** */
10597 struct cmd_flow_director_result {
10598         cmdline_fixed_string_t flow_director_filter;
10599         portid_t port_id;
10600         cmdline_fixed_string_t mode;
10601         cmdline_fixed_string_t mode_value;
10602         cmdline_fixed_string_t ops;
10603         cmdline_fixed_string_t flow;
10604         cmdline_fixed_string_t flow_type;
10605         cmdline_fixed_string_t ether;
10606         uint16_t ether_type;
10607         cmdline_fixed_string_t src;
10608         cmdline_ipaddr_t ip_src;
10609         uint16_t port_src;
10610         cmdline_fixed_string_t dst;
10611         cmdline_ipaddr_t ip_dst;
10612         uint16_t port_dst;
10613         cmdline_fixed_string_t verify_tag;
10614         uint32_t verify_tag_value;
10615         cmdline_fixed_string_t tos;
10616         uint8_t tos_value;
10617         cmdline_fixed_string_t proto;
10618         uint8_t proto_value;
10619         cmdline_fixed_string_t ttl;
10620         uint8_t ttl_value;
10621         cmdline_fixed_string_t vlan;
10622         uint16_t vlan_value;
10623         cmdline_fixed_string_t flexbytes;
10624         cmdline_fixed_string_t flexbytes_value;
10625         cmdline_fixed_string_t pf_vf;
10626         cmdline_fixed_string_t drop;
10627         cmdline_fixed_string_t queue;
10628         uint16_t  queue_id;
10629         cmdline_fixed_string_t fd_id;
10630         uint32_t  fd_id_value;
10631         cmdline_fixed_string_t mac;
10632         struct ether_addr mac_addr;
10633         cmdline_fixed_string_t tunnel;
10634         cmdline_fixed_string_t tunnel_type;
10635         cmdline_fixed_string_t tunnel_id;
10636         uint32_t tunnel_id_value;
10637         cmdline_fixed_string_t packet;
10638         char filepath[];
10639 };
10640
10641 static inline int
10642 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10643 {
10644         char s[256];
10645         const char *p, *p0 = q_arg;
10646         char *end;
10647         unsigned long int_fld;
10648         char *str_fld[max_num];
10649         int i;
10650         unsigned size;
10651         int ret = -1;
10652
10653         p = strchr(p0, '(');
10654         if (p == NULL)
10655                 return -1;
10656         ++p;
10657         p0 = strchr(p, ')');
10658         if (p0 == NULL)
10659                 return -1;
10660
10661         size = p0 - p;
10662         if (size >= sizeof(s))
10663                 return -1;
10664
10665         snprintf(s, sizeof(s), "%.*s", size, p);
10666         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10667         if (ret < 0 || ret > max_num)
10668                 return -1;
10669         for (i = 0; i < ret; i++) {
10670                 errno = 0;
10671                 int_fld = strtoul(str_fld[i], &end, 0);
10672                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10673                         return -1;
10674                 flexbytes[i] = (uint8_t)int_fld;
10675         }
10676         return ret;
10677 }
10678
10679 static uint16_t
10680 str2flowtype(char *string)
10681 {
10682         uint8_t i = 0;
10683         static const struct {
10684                 char str[32];
10685                 uint16_t type;
10686         } flowtype_str[] = {
10687                 {"raw", RTE_ETH_FLOW_RAW},
10688                 {"ipv4", RTE_ETH_FLOW_IPV4},
10689                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10690                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10691                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10692                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10693                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10694                 {"ipv6", RTE_ETH_FLOW_IPV6},
10695                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10696                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10697                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10698                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10699                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10700                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10701         };
10702
10703         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10704                 if (!strcmp(flowtype_str[i].str, string))
10705                         return flowtype_str[i].type;
10706         }
10707
10708         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10709                 return (uint16_t)atoi(string);
10710
10711         return RTE_ETH_FLOW_UNKNOWN;
10712 }
10713
10714 static enum rte_eth_fdir_tunnel_type
10715 str2fdir_tunneltype(char *string)
10716 {
10717         uint8_t i = 0;
10718
10719         static const struct {
10720                 char str[32];
10721                 enum rte_eth_fdir_tunnel_type type;
10722         } tunneltype_str[] = {
10723                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10724                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10725         };
10726
10727         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10728                 if (!strcmp(tunneltype_str[i].str, string))
10729                         return tunneltype_str[i].type;
10730         }
10731         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10732 }
10733
10734 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10735 do { \
10736         if ((ip_addr).family == AF_INET) \
10737                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10738         else { \
10739                 printf("invalid parameter.\n"); \
10740                 return; \
10741         } \
10742 } while (0)
10743
10744 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10745 do { \
10746         if ((ip_addr).family == AF_INET6) \
10747                 rte_memcpy(&(ip), \
10748                                  &((ip_addr).addr.ipv6), \
10749                                  sizeof(struct in6_addr)); \
10750         else { \
10751                 printf("invalid parameter.\n"); \
10752                 return; \
10753         } \
10754 } while (0)
10755
10756 static void
10757 cmd_flow_director_filter_parsed(void *parsed_result,
10758                           __attribute__((unused)) struct cmdline *cl,
10759                           __attribute__((unused)) void *data)
10760 {
10761         struct cmd_flow_director_result *res = parsed_result;
10762         struct rte_eth_fdir_filter entry;
10763         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10764         char *end;
10765         unsigned long vf_id;
10766         int ret = 0;
10767
10768         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10769         if (ret < 0) {
10770                 printf("flow director is not supported on port %u.\n",
10771                         res->port_id);
10772                 return;
10773         }
10774         memset(flexbytes, 0, sizeof(flexbytes));
10775         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10776
10777         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10778                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10779                         printf("Please set mode to MAC-VLAN.\n");
10780                         return;
10781                 }
10782         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10783                 if (strcmp(res->mode_value, "Tunnel")) {
10784                         printf("Please set mode to Tunnel.\n");
10785                         return;
10786                 }
10787         } else {
10788                 if (!strcmp(res->mode_value, "raw")) {
10789 #ifdef RTE_LIBRTE_I40E_PMD
10790                         struct rte_pmd_i40e_flow_type_mapping
10791                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10792                         struct rte_pmd_i40e_pkt_template_conf conf;
10793                         uint16_t flow_type = str2flowtype(res->flow_type);
10794                         uint16_t i, port = res->port_id;
10795                         uint8_t add;
10796
10797                         memset(&conf, 0, sizeof(conf));
10798
10799                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10800                                 printf("Invalid flow type specified.\n");
10801                                 return;
10802                         }
10803                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10804                                                                  mapping);
10805                         if (ret)
10806                                 return;
10807                         if (mapping[flow_type].pctype == 0ULL) {
10808                                 printf("Invalid flow type specified.\n");
10809                                 return;
10810                         }
10811                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10812                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10813                                         conf.input.pctype = i;
10814                                         break;
10815                                 }
10816                         }
10817
10818                         conf.input.packet = open_file(res->filepath,
10819                                                 &conf.input.length);
10820                         if (!conf.input.packet)
10821                                 return;
10822                         if (!strcmp(res->drop, "drop"))
10823                                 conf.action.behavior =
10824                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10825                         else
10826                                 conf.action.behavior =
10827                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10828                         conf.action.report_status =
10829                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10830                         conf.action.rx_queue = res->queue_id;
10831                         conf.soft_id = res->fd_id_value;
10832                         add  = strcmp(res->ops, "del") ? 1 : 0;
10833                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10834                                                                         &conf,
10835                                                                         add);
10836                         if (ret < 0)
10837                                 printf("flow director config error: (%s)\n",
10838                                        strerror(-ret));
10839                         close_file(conf.input.packet);
10840 #endif
10841                         return;
10842                 } else if (strcmp(res->mode_value, "IP")) {
10843                         printf("Please set mode to IP or raw.\n");
10844                         return;
10845                 }
10846                 entry.input.flow_type = str2flowtype(res->flow_type);
10847         }
10848
10849         ret = parse_flexbytes(res->flexbytes_value,
10850                                         flexbytes,
10851                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10852         if (ret < 0) {
10853                 printf("error: Cannot parse flexbytes input.\n");
10854                 return;
10855         }
10856
10857         switch (entry.input.flow_type) {
10858         case RTE_ETH_FLOW_FRAG_IPV4:
10859         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10860                 entry.input.flow.ip4_flow.proto = res->proto_value;
10861                 /* fall-through */
10862         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10863         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10864                 IPV4_ADDR_TO_UINT(res->ip_dst,
10865                         entry.input.flow.ip4_flow.dst_ip);
10866                 IPV4_ADDR_TO_UINT(res->ip_src,
10867                         entry.input.flow.ip4_flow.src_ip);
10868                 entry.input.flow.ip4_flow.tos = res->tos_value;
10869                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10870                 /* need convert to big endian. */
10871                 entry.input.flow.udp4_flow.dst_port =
10872                                 rte_cpu_to_be_16(res->port_dst);
10873                 entry.input.flow.udp4_flow.src_port =
10874                                 rte_cpu_to_be_16(res->port_src);
10875                 break;
10876         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10877                 IPV4_ADDR_TO_UINT(res->ip_dst,
10878                         entry.input.flow.sctp4_flow.ip.dst_ip);
10879                 IPV4_ADDR_TO_UINT(res->ip_src,
10880                         entry.input.flow.sctp4_flow.ip.src_ip);
10881                 entry.input.flow.ip4_flow.tos = res->tos_value;
10882                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10883                 /* need convert to big endian. */
10884                 entry.input.flow.sctp4_flow.dst_port =
10885                                 rte_cpu_to_be_16(res->port_dst);
10886                 entry.input.flow.sctp4_flow.src_port =
10887                                 rte_cpu_to_be_16(res->port_src);
10888                 entry.input.flow.sctp4_flow.verify_tag =
10889                                 rte_cpu_to_be_32(res->verify_tag_value);
10890                 break;
10891         case RTE_ETH_FLOW_FRAG_IPV6:
10892         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10893                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10894                 /* fall-through */
10895         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10896         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10897                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10898                         entry.input.flow.ipv6_flow.dst_ip);
10899                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10900                         entry.input.flow.ipv6_flow.src_ip);
10901                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10902                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10903                 /* need convert to big endian. */
10904                 entry.input.flow.udp6_flow.dst_port =
10905                                 rte_cpu_to_be_16(res->port_dst);
10906                 entry.input.flow.udp6_flow.src_port =
10907                                 rte_cpu_to_be_16(res->port_src);
10908                 break;
10909         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10910                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10911                         entry.input.flow.sctp6_flow.ip.dst_ip);
10912                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10913                         entry.input.flow.sctp6_flow.ip.src_ip);
10914                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10915                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10916                 /* need convert to big endian. */
10917                 entry.input.flow.sctp6_flow.dst_port =
10918                                 rte_cpu_to_be_16(res->port_dst);
10919                 entry.input.flow.sctp6_flow.src_port =
10920                                 rte_cpu_to_be_16(res->port_src);
10921                 entry.input.flow.sctp6_flow.verify_tag =
10922                                 rte_cpu_to_be_32(res->verify_tag_value);
10923                 break;
10924         case RTE_ETH_FLOW_L2_PAYLOAD:
10925                 entry.input.flow.l2_flow.ether_type =
10926                         rte_cpu_to_be_16(res->ether_type);
10927                 break;
10928         default:
10929                 break;
10930         }
10931
10932         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10933                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10934                                  &res->mac_addr,
10935                                  sizeof(struct ether_addr));
10936
10937         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10938                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10939                                  &res->mac_addr,
10940                                  sizeof(struct ether_addr));
10941                 entry.input.flow.tunnel_flow.tunnel_type =
10942                         str2fdir_tunneltype(res->tunnel_type);
10943                 entry.input.flow.tunnel_flow.tunnel_id =
10944                         rte_cpu_to_be_32(res->tunnel_id_value);
10945         }
10946
10947         rte_memcpy(entry.input.flow_ext.flexbytes,
10948                    flexbytes,
10949                    RTE_ETH_FDIR_MAX_FLEXLEN);
10950
10951         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10952
10953         entry.action.flex_off = 0;  /*use 0 by default */
10954         if (!strcmp(res->drop, "drop"))
10955                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10956         else
10957                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10958
10959         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10960             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10961                 if (!strcmp(res->pf_vf, "pf"))
10962                         entry.input.flow_ext.is_vf = 0;
10963                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10964                         struct rte_eth_dev_info dev_info;
10965
10966                         memset(&dev_info, 0, sizeof(dev_info));
10967                         rte_eth_dev_info_get(res->port_id, &dev_info);
10968                         errno = 0;
10969                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10970                         if (errno != 0 || *end != '\0' ||
10971                             vf_id >= dev_info.max_vfs) {
10972                                 printf("invalid parameter %s.\n", res->pf_vf);
10973                                 return;
10974                         }
10975                         entry.input.flow_ext.is_vf = 1;
10976                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10977                 } else {
10978                         printf("invalid parameter %s.\n", res->pf_vf);
10979                         return;
10980                 }
10981         }
10982
10983         /* set to report FD ID by default */
10984         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10985         entry.action.rx_queue = res->queue_id;
10986         entry.soft_id = res->fd_id_value;
10987         if (!strcmp(res->ops, "add"))
10988                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10989                                              RTE_ETH_FILTER_ADD, &entry);
10990         else if (!strcmp(res->ops, "del"))
10991                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10992                                              RTE_ETH_FILTER_DELETE, &entry);
10993         else
10994                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10995                                              RTE_ETH_FILTER_UPDATE, &entry);
10996         if (ret < 0)
10997                 printf("flow director programming error: (%s)\n",
10998                         strerror(-ret));
10999 }
11000
11001 cmdline_parse_token_string_t cmd_flow_director_filter =
11002         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11003                                  flow_director_filter, "flow_director_filter");
11004 cmdline_parse_token_num_t cmd_flow_director_port_id =
11005         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11006                               port_id, UINT16);
11007 cmdline_parse_token_string_t cmd_flow_director_ops =
11008         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11009                                  ops, "add#del#update");
11010 cmdline_parse_token_string_t cmd_flow_director_flow =
11011         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11012                                  flow, "flow");
11013 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11014         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11015                 flow_type, NULL);
11016 cmdline_parse_token_string_t cmd_flow_director_ether =
11017         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11018                                  ether, "ether");
11019 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11020         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11021                               ether_type, UINT16);
11022 cmdline_parse_token_string_t cmd_flow_director_src =
11023         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11024                                  src, "src");
11025 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11026         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11027                                  ip_src);
11028 cmdline_parse_token_num_t cmd_flow_director_port_src =
11029         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11030                               port_src, UINT16);
11031 cmdline_parse_token_string_t cmd_flow_director_dst =
11032         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11033                                  dst, "dst");
11034 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11035         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11036                                  ip_dst);
11037 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11038         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11039                               port_dst, UINT16);
11040 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11041         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11042                                   verify_tag, "verify_tag");
11043 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11044         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11045                               verify_tag_value, UINT32);
11046 cmdline_parse_token_string_t cmd_flow_director_tos =
11047         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11048                                  tos, "tos");
11049 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11050         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11051                               tos_value, UINT8);
11052 cmdline_parse_token_string_t cmd_flow_director_proto =
11053         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11054                                  proto, "proto");
11055 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11056         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11057                               proto_value, UINT8);
11058 cmdline_parse_token_string_t cmd_flow_director_ttl =
11059         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11060                                  ttl, "ttl");
11061 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11062         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11063                               ttl_value, UINT8);
11064 cmdline_parse_token_string_t cmd_flow_director_vlan =
11065         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11066                                  vlan, "vlan");
11067 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11068         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11069                               vlan_value, UINT16);
11070 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11071         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11072                                  flexbytes, "flexbytes");
11073 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11074         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11075                               flexbytes_value, NULL);
11076 cmdline_parse_token_string_t cmd_flow_director_drop =
11077         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11078                                  drop, "drop#fwd");
11079 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11080         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11081                               pf_vf, NULL);
11082 cmdline_parse_token_string_t cmd_flow_director_queue =
11083         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11084                                  queue, "queue");
11085 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11086         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11087                               queue_id, UINT16);
11088 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11089         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11090                                  fd_id, "fd_id");
11091 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11092         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11093                               fd_id_value, UINT32);
11094
11095 cmdline_parse_token_string_t cmd_flow_director_mode =
11096         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11097                                  mode, "mode");
11098 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11099         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11100                                  mode_value, "IP");
11101 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11102         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11103                                  mode_value, "MAC-VLAN");
11104 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11105         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11106                                  mode_value, "Tunnel");
11107 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11108         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11109                                  mode_value, "raw");
11110 cmdline_parse_token_string_t cmd_flow_director_mac =
11111         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11112                                  mac, "mac");
11113 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11114         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11115                                     mac_addr);
11116 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11117         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11118                                  tunnel, "tunnel");
11119 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11120         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11121                                  tunnel_type, "NVGRE#VxLAN");
11122 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11123         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11124                                  tunnel_id, "tunnel-id");
11125 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11126         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11127                               tunnel_id_value, UINT32);
11128 cmdline_parse_token_string_t cmd_flow_director_packet =
11129         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11130                                  packet, "packet");
11131 cmdline_parse_token_string_t cmd_flow_director_filepath =
11132         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11133                                  filepath, NULL);
11134
11135 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11136         .f = cmd_flow_director_filter_parsed,
11137         .data = NULL,
11138         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11139                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11140                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11141                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11142                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11143                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11144                 "fd_id <fd_id_value>: "
11145                 "Add or delete an ip flow director entry on NIC",
11146         .tokens = {
11147                 (void *)&cmd_flow_director_filter,
11148                 (void *)&cmd_flow_director_port_id,
11149                 (void *)&cmd_flow_director_mode,
11150                 (void *)&cmd_flow_director_mode_ip,
11151                 (void *)&cmd_flow_director_ops,
11152                 (void *)&cmd_flow_director_flow,
11153                 (void *)&cmd_flow_director_flow_type,
11154                 (void *)&cmd_flow_director_src,
11155                 (void *)&cmd_flow_director_ip_src,
11156                 (void *)&cmd_flow_director_dst,
11157                 (void *)&cmd_flow_director_ip_dst,
11158                 (void *)&cmd_flow_director_tos,
11159                 (void *)&cmd_flow_director_tos_value,
11160                 (void *)&cmd_flow_director_proto,
11161                 (void *)&cmd_flow_director_proto_value,
11162                 (void *)&cmd_flow_director_ttl,
11163                 (void *)&cmd_flow_director_ttl_value,
11164                 (void *)&cmd_flow_director_vlan,
11165                 (void *)&cmd_flow_director_vlan_value,
11166                 (void *)&cmd_flow_director_flexbytes,
11167                 (void *)&cmd_flow_director_flexbytes_value,
11168                 (void *)&cmd_flow_director_drop,
11169                 (void *)&cmd_flow_director_pf_vf,
11170                 (void *)&cmd_flow_director_queue,
11171                 (void *)&cmd_flow_director_queue_id,
11172                 (void *)&cmd_flow_director_fd_id,
11173                 (void *)&cmd_flow_director_fd_id_value,
11174                 NULL,
11175         },
11176 };
11177
11178 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11179         .f = cmd_flow_director_filter_parsed,
11180         .data = NULL,
11181         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11182                 "director entry on NIC",
11183         .tokens = {
11184                 (void *)&cmd_flow_director_filter,
11185                 (void *)&cmd_flow_director_port_id,
11186                 (void *)&cmd_flow_director_mode,
11187                 (void *)&cmd_flow_director_mode_ip,
11188                 (void *)&cmd_flow_director_ops,
11189                 (void *)&cmd_flow_director_flow,
11190                 (void *)&cmd_flow_director_flow_type,
11191                 (void *)&cmd_flow_director_src,
11192                 (void *)&cmd_flow_director_ip_src,
11193                 (void *)&cmd_flow_director_port_src,
11194                 (void *)&cmd_flow_director_dst,
11195                 (void *)&cmd_flow_director_ip_dst,
11196                 (void *)&cmd_flow_director_port_dst,
11197                 (void *)&cmd_flow_director_tos,
11198                 (void *)&cmd_flow_director_tos_value,
11199                 (void *)&cmd_flow_director_ttl,
11200                 (void *)&cmd_flow_director_ttl_value,
11201                 (void *)&cmd_flow_director_vlan,
11202                 (void *)&cmd_flow_director_vlan_value,
11203                 (void *)&cmd_flow_director_flexbytes,
11204                 (void *)&cmd_flow_director_flexbytes_value,
11205                 (void *)&cmd_flow_director_drop,
11206                 (void *)&cmd_flow_director_pf_vf,
11207                 (void *)&cmd_flow_director_queue,
11208                 (void *)&cmd_flow_director_queue_id,
11209                 (void *)&cmd_flow_director_fd_id,
11210                 (void *)&cmd_flow_director_fd_id_value,
11211                 NULL,
11212         },
11213 };
11214
11215 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11216         .f = cmd_flow_director_filter_parsed,
11217         .data = NULL,
11218         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11219                 "director entry on NIC",
11220         .tokens = {
11221                 (void *)&cmd_flow_director_filter,
11222                 (void *)&cmd_flow_director_port_id,
11223                 (void *)&cmd_flow_director_mode,
11224                 (void *)&cmd_flow_director_mode_ip,
11225                 (void *)&cmd_flow_director_ops,
11226                 (void *)&cmd_flow_director_flow,
11227                 (void *)&cmd_flow_director_flow_type,
11228                 (void *)&cmd_flow_director_src,
11229                 (void *)&cmd_flow_director_ip_src,
11230                 (void *)&cmd_flow_director_port_src,
11231                 (void *)&cmd_flow_director_dst,
11232                 (void *)&cmd_flow_director_ip_dst,
11233                 (void *)&cmd_flow_director_port_dst,
11234                 (void *)&cmd_flow_director_verify_tag,
11235                 (void *)&cmd_flow_director_verify_tag_value,
11236                 (void *)&cmd_flow_director_tos,
11237                 (void *)&cmd_flow_director_tos_value,
11238                 (void *)&cmd_flow_director_ttl,
11239                 (void *)&cmd_flow_director_ttl_value,
11240                 (void *)&cmd_flow_director_vlan,
11241                 (void *)&cmd_flow_director_vlan_value,
11242                 (void *)&cmd_flow_director_flexbytes,
11243                 (void *)&cmd_flow_director_flexbytes_value,
11244                 (void *)&cmd_flow_director_drop,
11245                 (void *)&cmd_flow_director_pf_vf,
11246                 (void *)&cmd_flow_director_queue,
11247                 (void *)&cmd_flow_director_queue_id,
11248                 (void *)&cmd_flow_director_fd_id,
11249                 (void *)&cmd_flow_director_fd_id_value,
11250                 NULL,
11251         },
11252 };
11253
11254 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11255         .f = cmd_flow_director_filter_parsed,
11256         .data = NULL,
11257         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11258                 "director entry on NIC",
11259         .tokens = {
11260                 (void *)&cmd_flow_director_filter,
11261                 (void *)&cmd_flow_director_port_id,
11262                 (void *)&cmd_flow_director_mode,
11263                 (void *)&cmd_flow_director_mode_ip,
11264                 (void *)&cmd_flow_director_ops,
11265                 (void *)&cmd_flow_director_flow,
11266                 (void *)&cmd_flow_director_flow_type,
11267                 (void *)&cmd_flow_director_ether,
11268                 (void *)&cmd_flow_director_ether_type,
11269                 (void *)&cmd_flow_director_flexbytes,
11270                 (void *)&cmd_flow_director_flexbytes_value,
11271                 (void *)&cmd_flow_director_drop,
11272                 (void *)&cmd_flow_director_pf_vf,
11273                 (void *)&cmd_flow_director_queue,
11274                 (void *)&cmd_flow_director_queue_id,
11275                 (void *)&cmd_flow_director_fd_id,
11276                 (void *)&cmd_flow_director_fd_id_value,
11277                 NULL,
11278         },
11279 };
11280
11281 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11282         .f = cmd_flow_director_filter_parsed,
11283         .data = NULL,
11284         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11285                 "director entry on NIC",
11286         .tokens = {
11287                 (void *)&cmd_flow_director_filter,
11288                 (void *)&cmd_flow_director_port_id,
11289                 (void *)&cmd_flow_director_mode,
11290                 (void *)&cmd_flow_director_mode_mac_vlan,
11291                 (void *)&cmd_flow_director_ops,
11292                 (void *)&cmd_flow_director_mac,
11293                 (void *)&cmd_flow_director_mac_addr,
11294                 (void *)&cmd_flow_director_vlan,
11295                 (void *)&cmd_flow_director_vlan_value,
11296                 (void *)&cmd_flow_director_flexbytes,
11297                 (void *)&cmd_flow_director_flexbytes_value,
11298                 (void *)&cmd_flow_director_drop,
11299                 (void *)&cmd_flow_director_queue,
11300                 (void *)&cmd_flow_director_queue_id,
11301                 (void *)&cmd_flow_director_fd_id,
11302                 (void *)&cmd_flow_director_fd_id_value,
11303                 NULL,
11304         },
11305 };
11306
11307 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11308         .f = cmd_flow_director_filter_parsed,
11309         .data = NULL,
11310         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11311                 "director entry on NIC",
11312         .tokens = {
11313                 (void *)&cmd_flow_director_filter,
11314                 (void *)&cmd_flow_director_port_id,
11315                 (void *)&cmd_flow_director_mode,
11316                 (void *)&cmd_flow_director_mode_tunnel,
11317                 (void *)&cmd_flow_director_ops,
11318                 (void *)&cmd_flow_director_mac,
11319                 (void *)&cmd_flow_director_mac_addr,
11320                 (void *)&cmd_flow_director_vlan,
11321                 (void *)&cmd_flow_director_vlan_value,
11322                 (void *)&cmd_flow_director_tunnel,
11323                 (void *)&cmd_flow_director_tunnel_type,
11324                 (void *)&cmd_flow_director_tunnel_id,
11325                 (void *)&cmd_flow_director_tunnel_id_value,
11326                 (void *)&cmd_flow_director_flexbytes,
11327                 (void *)&cmd_flow_director_flexbytes_value,
11328                 (void *)&cmd_flow_director_drop,
11329                 (void *)&cmd_flow_director_queue,
11330                 (void *)&cmd_flow_director_queue_id,
11331                 (void *)&cmd_flow_director_fd_id,
11332                 (void *)&cmd_flow_director_fd_id_value,
11333                 NULL,
11334         },
11335 };
11336
11337 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11338         .f = cmd_flow_director_filter_parsed,
11339         .data = NULL,
11340         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11341                 "director entry on NIC",
11342         .tokens = {
11343                 (void *)&cmd_flow_director_filter,
11344                 (void *)&cmd_flow_director_port_id,
11345                 (void *)&cmd_flow_director_mode,
11346                 (void *)&cmd_flow_director_mode_raw,
11347                 (void *)&cmd_flow_director_ops,
11348                 (void *)&cmd_flow_director_flow,
11349                 (void *)&cmd_flow_director_flow_type,
11350                 (void *)&cmd_flow_director_drop,
11351                 (void *)&cmd_flow_director_queue,
11352                 (void *)&cmd_flow_director_queue_id,
11353                 (void *)&cmd_flow_director_fd_id,
11354                 (void *)&cmd_flow_director_fd_id_value,
11355                 (void *)&cmd_flow_director_packet,
11356                 (void *)&cmd_flow_director_filepath,
11357                 NULL,
11358         },
11359 };
11360
11361 struct cmd_flush_flow_director_result {
11362         cmdline_fixed_string_t flush_flow_director;
11363         portid_t port_id;
11364 };
11365
11366 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11367         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11368                                  flush_flow_director, "flush_flow_director");
11369 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11370         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11371                               port_id, UINT16);
11372
11373 static void
11374 cmd_flush_flow_director_parsed(void *parsed_result,
11375                           __attribute__((unused)) struct cmdline *cl,
11376                           __attribute__((unused)) void *data)
11377 {
11378         struct cmd_flow_director_result *res = parsed_result;
11379         int ret = 0;
11380
11381         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11382         if (ret < 0) {
11383                 printf("flow director is not supported on port %u.\n",
11384                         res->port_id);
11385                 return;
11386         }
11387
11388         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11389                         RTE_ETH_FILTER_FLUSH, NULL);
11390         if (ret < 0)
11391                 printf("flow director table flushing error: (%s)\n",
11392                         strerror(-ret));
11393 }
11394
11395 cmdline_parse_inst_t cmd_flush_flow_director = {
11396         .f = cmd_flush_flow_director_parsed,
11397         .data = NULL,
11398         .help_str = "flush_flow_director <port_id>: "
11399                 "Flush all flow director entries of a device on NIC",
11400         .tokens = {
11401                 (void *)&cmd_flush_flow_director_flush,
11402                 (void *)&cmd_flush_flow_director_port_id,
11403                 NULL,
11404         },
11405 };
11406
11407 /* *** deal with flow director mask *** */
11408 struct cmd_flow_director_mask_result {
11409         cmdline_fixed_string_t flow_director_mask;
11410         portid_t port_id;
11411         cmdline_fixed_string_t mode;
11412         cmdline_fixed_string_t mode_value;
11413         cmdline_fixed_string_t vlan;
11414         uint16_t vlan_mask;
11415         cmdline_fixed_string_t src_mask;
11416         cmdline_ipaddr_t ipv4_src;
11417         cmdline_ipaddr_t ipv6_src;
11418         uint16_t port_src;
11419         cmdline_fixed_string_t dst_mask;
11420         cmdline_ipaddr_t ipv4_dst;
11421         cmdline_ipaddr_t ipv6_dst;
11422         uint16_t port_dst;
11423         cmdline_fixed_string_t mac;
11424         uint8_t mac_addr_byte_mask;
11425         cmdline_fixed_string_t tunnel_id;
11426         uint32_t tunnel_id_mask;
11427         cmdline_fixed_string_t tunnel_type;
11428         uint8_t tunnel_type_mask;
11429 };
11430
11431 static void
11432 cmd_flow_director_mask_parsed(void *parsed_result,
11433                           __attribute__((unused)) struct cmdline *cl,
11434                           __attribute__((unused)) void *data)
11435 {
11436         struct cmd_flow_director_mask_result *res = parsed_result;
11437         struct rte_eth_fdir_masks *mask;
11438         struct rte_port *port;
11439
11440         port = &ports[res->port_id];
11441         /** Check if the port is not started **/
11442         if (port->port_status != RTE_PORT_STOPPED) {
11443                 printf("Please stop port %d first\n", res->port_id);
11444                 return;
11445         }
11446
11447         mask = &port->dev_conf.fdir_conf.mask;
11448
11449         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11450                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11451                         printf("Please set mode to MAC-VLAN.\n");
11452                         return;
11453                 }
11454
11455                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11456         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11457                 if (strcmp(res->mode_value, "Tunnel")) {
11458                         printf("Please set mode to Tunnel.\n");
11459                         return;
11460                 }
11461
11462                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11463                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11464                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11465                 mask->tunnel_type_mask = res->tunnel_type_mask;
11466         } else {
11467                 if (strcmp(res->mode_value, "IP")) {
11468                         printf("Please set mode to IP.\n");
11469                         return;
11470                 }
11471
11472                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11473                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11474                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11475                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11476                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11477                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11478                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11479         }
11480
11481         cmd_reconfig_device_queue(res->port_id, 1, 1);
11482 }
11483
11484 cmdline_parse_token_string_t cmd_flow_director_mask =
11485         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11486                                  flow_director_mask, "flow_director_mask");
11487 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11488         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11489                               port_id, UINT16);
11490 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11491         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11492                                  vlan, "vlan");
11493 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11494         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11495                               vlan_mask, UINT16);
11496 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11497         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11498                                  src_mask, "src_mask");
11499 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11500         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11501                                  ipv4_src);
11502 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11503         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11504                                  ipv6_src);
11505 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11506         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11507                               port_src, UINT16);
11508 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11509         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11510                                  dst_mask, "dst_mask");
11511 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11512         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11513                                  ipv4_dst);
11514 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11515         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11516                                  ipv6_dst);
11517 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11518         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11519                               port_dst, UINT16);
11520
11521 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11522         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11523                                  mode, "mode");
11524 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11525         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11526                                  mode_value, "IP");
11527 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11528         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11529                                  mode_value, "MAC-VLAN");
11530 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11531         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11532                                  mode_value, "Tunnel");
11533 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11534         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11535                                  mac, "mac");
11536 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11537         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11538                               mac_addr_byte_mask, UINT8);
11539 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11540         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11541                                  tunnel_type, "tunnel-type");
11542 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11543         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11544                               tunnel_type_mask, UINT8);
11545 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11546         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11547                                  tunnel_id, "tunnel-id");
11548 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11549         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11550                               tunnel_id_mask, UINT32);
11551
11552 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11553         .f = cmd_flow_director_mask_parsed,
11554         .data = NULL,
11555         .help_str = "flow_director_mask ... : "
11556                 "Set IP mode flow director's mask on NIC",
11557         .tokens = {
11558                 (void *)&cmd_flow_director_mask,
11559                 (void *)&cmd_flow_director_mask_port_id,
11560                 (void *)&cmd_flow_director_mask_mode,
11561                 (void *)&cmd_flow_director_mask_mode_ip,
11562                 (void *)&cmd_flow_director_mask_vlan,
11563                 (void *)&cmd_flow_director_mask_vlan_value,
11564                 (void *)&cmd_flow_director_mask_src,
11565                 (void *)&cmd_flow_director_mask_ipv4_src,
11566                 (void *)&cmd_flow_director_mask_ipv6_src,
11567                 (void *)&cmd_flow_director_mask_port_src,
11568                 (void *)&cmd_flow_director_mask_dst,
11569                 (void *)&cmd_flow_director_mask_ipv4_dst,
11570                 (void *)&cmd_flow_director_mask_ipv6_dst,
11571                 (void *)&cmd_flow_director_mask_port_dst,
11572                 NULL,
11573         },
11574 };
11575
11576 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11577         .f = cmd_flow_director_mask_parsed,
11578         .data = NULL,
11579         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11580                 "flow director's mask on NIC",
11581         .tokens = {
11582                 (void *)&cmd_flow_director_mask,
11583                 (void *)&cmd_flow_director_mask_port_id,
11584                 (void *)&cmd_flow_director_mask_mode,
11585                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11586                 (void *)&cmd_flow_director_mask_vlan,
11587                 (void *)&cmd_flow_director_mask_vlan_value,
11588                 NULL,
11589         },
11590 };
11591
11592 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11593         .f = cmd_flow_director_mask_parsed,
11594         .data = NULL,
11595         .help_str = "flow_director_mask ... : Set tunnel mode "
11596                 "flow director's mask on NIC",
11597         .tokens = {
11598                 (void *)&cmd_flow_director_mask,
11599                 (void *)&cmd_flow_director_mask_port_id,
11600                 (void *)&cmd_flow_director_mask_mode,
11601                 (void *)&cmd_flow_director_mask_mode_tunnel,
11602                 (void *)&cmd_flow_director_mask_vlan,
11603                 (void *)&cmd_flow_director_mask_vlan_value,
11604                 (void *)&cmd_flow_director_mask_mac,
11605                 (void *)&cmd_flow_director_mask_mac_value,
11606                 (void *)&cmd_flow_director_mask_tunnel_type,
11607                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11608                 (void *)&cmd_flow_director_mask_tunnel_id,
11609                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11610                 NULL,
11611         },
11612 };
11613
11614 /* *** deal with flow director mask on flexible payload *** */
11615 struct cmd_flow_director_flex_mask_result {
11616         cmdline_fixed_string_t flow_director_flexmask;
11617         portid_t port_id;
11618         cmdline_fixed_string_t flow;
11619         cmdline_fixed_string_t flow_type;
11620         cmdline_fixed_string_t mask;
11621 };
11622
11623 static void
11624 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11625                           __attribute__((unused)) struct cmdline *cl,
11626                           __attribute__((unused)) void *data)
11627 {
11628         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11629         struct rte_eth_fdir_info fdir_info;
11630         struct rte_eth_fdir_flex_mask flex_mask;
11631         struct rte_port *port;
11632         uint64_t flow_type_mask;
11633         uint16_t i;
11634         int ret;
11635
11636         port = &ports[res->port_id];
11637         /** Check if the port is not started **/
11638         if (port->port_status != RTE_PORT_STOPPED) {
11639                 printf("Please stop port %d first\n", res->port_id);
11640                 return;
11641         }
11642
11643         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11644         ret = parse_flexbytes(res->mask,
11645                         flex_mask.mask,
11646                         RTE_ETH_FDIR_MAX_FLEXLEN);
11647         if (ret < 0) {
11648                 printf("error: Cannot parse mask input.\n");
11649                 return;
11650         }
11651
11652         memset(&fdir_info, 0, sizeof(fdir_info));
11653         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11654                                 RTE_ETH_FILTER_INFO, &fdir_info);
11655         if (ret < 0) {
11656                 printf("Cannot get FDir filter info\n");
11657                 return;
11658         }
11659
11660         if (!strcmp(res->flow_type, "none")) {
11661                 /* means don't specify the flow type */
11662                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11663                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11664                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11665                                0, sizeof(struct rte_eth_fdir_flex_mask));
11666                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11667                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11668                                  &flex_mask,
11669                                  sizeof(struct rte_eth_fdir_flex_mask));
11670                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11671                 return;
11672         }
11673         flow_type_mask = fdir_info.flow_types_mask[0];
11674         if (!strcmp(res->flow_type, "all")) {
11675                 if (!flow_type_mask) {
11676                         printf("No flow type supported\n");
11677                         return;
11678                 }
11679                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11680                         if (flow_type_mask & (1ULL << i)) {
11681                                 flex_mask.flow_type = i;
11682                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11683                         }
11684                 }
11685                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11686                 return;
11687         }
11688         flex_mask.flow_type = str2flowtype(res->flow_type);
11689         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11690                 printf("Flow type %s not supported on port %d\n",
11691                                 res->flow_type, res->port_id);
11692                 return;
11693         }
11694         fdir_set_flex_mask(res->port_id, &flex_mask);
11695         cmd_reconfig_device_queue(res->port_id, 1, 1);
11696 }
11697
11698 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11699         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11700                                  flow_director_flexmask,
11701                                  "flow_director_flex_mask");
11702 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11703         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11704                               port_id, UINT16);
11705 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11706         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11707                                  flow, "flow");
11708 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11709         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11710                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11711                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11712 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11713         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11714                                  mask, NULL);
11715
11716 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11717         .f = cmd_flow_director_flex_mask_parsed,
11718         .data = NULL,
11719         .help_str = "flow_director_flex_mask ... : "
11720                 "Set flow director's flex mask on NIC",
11721         .tokens = {
11722                 (void *)&cmd_flow_director_flexmask,
11723                 (void *)&cmd_flow_director_flexmask_port_id,
11724                 (void *)&cmd_flow_director_flexmask_flow,
11725                 (void *)&cmd_flow_director_flexmask_flow_type,
11726                 (void *)&cmd_flow_director_flexmask_mask,
11727                 NULL,
11728         },
11729 };
11730
11731 /* *** deal with flow director flexible payload configuration *** */
11732 struct cmd_flow_director_flexpayload_result {
11733         cmdline_fixed_string_t flow_director_flexpayload;
11734         portid_t port_id;
11735         cmdline_fixed_string_t payload_layer;
11736         cmdline_fixed_string_t payload_cfg;
11737 };
11738
11739 static inline int
11740 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11741 {
11742         char s[256];
11743         const char *p, *p0 = q_arg;
11744         char *end;
11745         unsigned long int_fld;
11746         char *str_fld[max_num];
11747         int i;
11748         unsigned size;
11749         int ret = -1;
11750
11751         p = strchr(p0, '(');
11752         if (p == NULL)
11753                 return -1;
11754         ++p;
11755         p0 = strchr(p, ')');
11756         if (p0 == NULL)
11757                 return -1;
11758
11759         size = p0 - p;
11760         if (size >= sizeof(s))
11761                 return -1;
11762
11763         snprintf(s, sizeof(s), "%.*s", size, p);
11764         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11765         if (ret < 0 || ret > max_num)
11766                 return -1;
11767         for (i = 0; i < ret; i++) {
11768                 errno = 0;
11769                 int_fld = strtoul(str_fld[i], &end, 0);
11770                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11771                         return -1;
11772                 offsets[i] = (uint16_t)int_fld;
11773         }
11774         return ret;
11775 }
11776
11777 static void
11778 cmd_flow_director_flxpld_parsed(void *parsed_result,
11779                           __attribute__((unused)) struct cmdline *cl,
11780                           __attribute__((unused)) void *data)
11781 {
11782         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11783         struct rte_eth_flex_payload_cfg flex_cfg;
11784         struct rte_port *port;
11785         int ret = 0;
11786
11787         port = &ports[res->port_id];
11788         /** Check if the port is not started **/
11789         if (port->port_status != RTE_PORT_STOPPED) {
11790                 printf("Please stop port %d first\n", res->port_id);
11791                 return;
11792         }
11793
11794         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11795
11796         if (!strcmp(res->payload_layer, "raw"))
11797                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11798         else if (!strcmp(res->payload_layer, "l2"))
11799                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11800         else if (!strcmp(res->payload_layer, "l3"))
11801                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11802         else if (!strcmp(res->payload_layer, "l4"))
11803                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11804
11805         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11806                             RTE_ETH_FDIR_MAX_FLEXLEN);
11807         if (ret < 0) {
11808                 printf("error: Cannot parse flex payload input.\n");
11809                 return;
11810         }
11811
11812         fdir_set_flex_payload(res->port_id, &flex_cfg);
11813         cmd_reconfig_device_queue(res->port_id, 1, 1);
11814 }
11815
11816 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11817         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11818                                  flow_director_flexpayload,
11819                                  "flow_director_flex_payload");
11820 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11821         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11822                               port_id, UINT16);
11823 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11824         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11825                                  payload_layer, "raw#l2#l3#l4");
11826 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11827         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11828                                  payload_cfg, NULL);
11829
11830 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11831         .f = cmd_flow_director_flxpld_parsed,
11832         .data = NULL,
11833         .help_str = "flow_director_flexpayload ... : "
11834                 "Set flow director's flex payload on NIC",
11835         .tokens = {
11836                 (void *)&cmd_flow_director_flexpayload,
11837                 (void *)&cmd_flow_director_flexpayload_port_id,
11838                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11839                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11840                 NULL,
11841         },
11842 };
11843
11844 /* Generic flow interface command. */
11845 extern cmdline_parse_inst_t cmd_flow;
11846
11847 /* *** Classification Filters Control *** */
11848 /* *** Get symmetric hash enable per port *** */
11849 struct cmd_get_sym_hash_ena_per_port_result {
11850         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11851         portid_t port_id;
11852 };
11853
11854 static void
11855 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11856                                  __rte_unused struct cmdline *cl,
11857                                  __rte_unused void *data)
11858 {
11859         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11860         struct rte_eth_hash_filter_info info;
11861         int ret;
11862
11863         if (rte_eth_dev_filter_supported(res->port_id,
11864                                 RTE_ETH_FILTER_HASH) < 0) {
11865                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11866                                                         res->port_id);
11867                 return;
11868         }
11869
11870         memset(&info, 0, sizeof(info));
11871         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11872         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11873                                                 RTE_ETH_FILTER_GET, &info);
11874
11875         if (ret < 0) {
11876                 printf("Cannot get symmetric hash enable per port "
11877                                         "on port %u\n", res->port_id);
11878                 return;
11879         }
11880
11881         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11882                                 "enabled" : "disabled", res->port_id);
11883 }
11884
11885 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11886         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11887                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11888 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11889         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11890                 port_id, UINT16);
11891
11892 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11893         .f = cmd_get_sym_hash_per_port_parsed,
11894         .data = NULL,
11895         .help_str = "get_sym_hash_ena_per_port <port_id>",
11896         .tokens = {
11897                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11898                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11899                 NULL,
11900         },
11901 };
11902
11903 /* *** Set symmetric hash enable per port *** */
11904 struct cmd_set_sym_hash_ena_per_port_result {
11905         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11906         cmdline_fixed_string_t enable;
11907         portid_t port_id;
11908 };
11909
11910 static void
11911 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11912                                  __rte_unused struct cmdline *cl,
11913                                  __rte_unused void *data)
11914 {
11915         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11916         struct rte_eth_hash_filter_info info;
11917         int ret;
11918
11919         if (rte_eth_dev_filter_supported(res->port_id,
11920                                 RTE_ETH_FILTER_HASH) < 0) {
11921                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11922                                                         res->port_id);
11923                 return;
11924         }
11925
11926         memset(&info, 0, sizeof(info));
11927         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11928         if (!strcmp(res->enable, "enable"))
11929                 info.info.enable = 1;
11930         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11931                                         RTE_ETH_FILTER_SET, &info);
11932         if (ret < 0) {
11933                 printf("Cannot set symmetric hash enable per port on "
11934                                         "port %u\n", res->port_id);
11935                 return;
11936         }
11937         printf("Symmetric hash has been set to %s on port %u\n",
11938                                         res->enable, res->port_id);
11939 }
11940
11941 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11942         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11943                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11944 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11945         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11946                 port_id, UINT16);
11947 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11948         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11949                 enable, "enable#disable");
11950
11951 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11952         .f = cmd_set_sym_hash_per_port_parsed,
11953         .data = NULL,
11954         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11955         .tokens = {
11956                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11957                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11958                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11959                 NULL,
11960         },
11961 };
11962
11963 /* Get global config of hash function */
11964 struct cmd_get_hash_global_config_result {
11965         cmdline_fixed_string_t get_hash_global_config;
11966         portid_t port_id;
11967 };
11968
11969 static char *
11970 flowtype_to_str(uint16_t ftype)
11971 {
11972         uint16_t i;
11973         static struct {
11974                 char str[16];
11975                 uint16_t ftype;
11976         } ftype_table[] = {
11977                 {"ipv4", RTE_ETH_FLOW_IPV4},
11978                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11979                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11980                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11981                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11982                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11983                 {"ipv6", RTE_ETH_FLOW_IPV6},
11984                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11985                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11986                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11987                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11988                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11989                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11990                 {"port", RTE_ETH_FLOW_PORT},
11991                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11992                 {"geneve", RTE_ETH_FLOW_GENEVE},
11993                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11994                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
11995         };
11996
11997         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11998                 if (ftype_table[i].ftype == ftype)
11999                         return ftype_table[i].str;
12000         }
12001
12002         return NULL;
12003 }
12004
12005 static void
12006 cmd_get_hash_global_config_parsed(void *parsed_result,
12007                                   __rte_unused struct cmdline *cl,
12008                                   __rte_unused void *data)
12009 {
12010         struct cmd_get_hash_global_config_result *res = parsed_result;
12011         struct rte_eth_hash_filter_info info;
12012         uint32_t idx, offset;
12013         uint16_t i;
12014         char *str;
12015         int ret;
12016
12017         if (rte_eth_dev_filter_supported(res->port_id,
12018                         RTE_ETH_FILTER_HASH) < 0) {
12019                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12020                                                         res->port_id);
12021                 return;
12022         }
12023
12024         memset(&info, 0, sizeof(info));
12025         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12026         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12027                                         RTE_ETH_FILTER_GET, &info);
12028         if (ret < 0) {
12029                 printf("Cannot get hash global configurations by port %d\n",
12030                                                         res->port_id);
12031                 return;
12032         }
12033
12034         switch (info.info.global_conf.hash_func) {
12035         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12036                 printf("Hash function is Toeplitz\n");
12037                 break;
12038         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12039                 printf("Hash function is Simple XOR\n");
12040                 break;
12041         default:
12042                 printf("Unknown hash function\n");
12043                 break;
12044         }
12045
12046         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12047                 idx = i / UINT64_BIT;
12048                 offset = i % UINT64_BIT;
12049                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12050                                                 (1ULL << offset)))
12051                         continue;
12052                 str = flowtype_to_str(i);
12053                 if (!str)
12054                         continue;
12055                 printf("Symmetric hash is %s globally for flow type %s "
12056                                                         "by port %d\n",
12057                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12058                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12059                                                         res->port_id);
12060         }
12061 }
12062
12063 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12064         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12065                 get_hash_global_config, "get_hash_global_config");
12066 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12067         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12068                 port_id, UINT16);
12069
12070 cmdline_parse_inst_t cmd_get_hash_global_config = {
12071         .f = cmd_get_hash_global_config_parsed,
12072         .data = NULL,
12073         .help_str = "get_hash_global_config <port_id>",
12074         .tokens = {
12075                 (void *)&cmd_get_hash_global_config_all,
12076                 (void *)&cmd_get_hash_global_config_port_id,
12077                 NULL,
12078         },
12079 };
12080
12081 /* Set global config of hash function */
12082 struct cmd_set_hash_global_config_result {
12083         cmdline_fixed_string_t set_hash_global_config;
12084         portid_t port_id;
12085         cmdline_fixed_string_t hash_func;
12086         cmdline_fixed_string_t flow_type;
12087         cmdline_fixed_string_t enable;
12088 };
12089
12090 static void
12091 cmd_set_hash_global_config_parsed(void *parsed_result,
12092                                   __rte_unused struct cmdline *cl,
12093                                   __rte_unused void *data)
12094 {
12095         struct cmd_set_hash_global_config_result *res = parsed_result;
12096         struct rte_eth_hash_filter_info info;
12097         uint32_t ftype, idx, offset;
12098         int ret;
12099
12100         if (rte_eth_dev_filter_supported(res->port_id,
12101                                 RTE_ETH_FILTER_HASH) < 0) {
12102                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12103                                                         res->port_id);
12104                 return;
12105         }
12106         memset(&info, 0, sizeof(info));
12107         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12108         if (!strcmp(res->hash_func, "toeplitz"))
12109                 info.info.global_conf.hash_func =
12110                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12111         else if (!strcmp(res->hash_func, "simple_xor"))
12112                 info.info.global_conf.hash_func =
12113                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12114         else if (!strcmp(res->hash_func, "default"))
12115                 info.info.global_conf.hash_func =
12116                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12117
12118         ftype = str2flowtype(res->flow_type);
12119         idx = ftype / UINT64_BIT;
12120         offset = ftype % UINT64_BIT;
12121         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12122         if (!strcmp(res->enable, "enable"))
12123                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12124                                                 (1ULL << offset);
12125         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12126                                         RTE_ETH_FILTER_SET, &info);
12127         if (ret < 0)
12128                 printf("Cannot set global hash configurations by port %d\n",
12129                                                         res->port_id);
12130         else
12131                 printf("Global hash configurations have been set "
12132                         "successfully by port %d\n", res->port_id);
12133 }
12134
12135 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12136         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12137                 set_hash_global_config, "set_hash_global_config");
12138 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12139         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12140                 port_id, UINT16);
12141 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12142         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12143                 hash_func, "toeplitz#simple_xor#default");
12144 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12145         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12146                 flow_type,
12147                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12148                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12149 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12150         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12151                 enable, "enable#disable");
12152
12153 cmdline_parse_inst_t cmd_set_hash_global_config = {
12154         .f = cmd_set_hash_global_config_parsed,
12155         .data = NULL,
12156         .help_str = "set_hash_global_config <port_id> "
12157                 "toeplitz|simple_xor|default "
12158                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12159                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12160                 "l2_payload enable|disable",
12161         .tokens = {
12162                 (void *)&cmd_set_hash_global_config_all,
12163                 (void *)&cmd_set_hash_global_config_port_id,
12164                 (void *)&cmd_set_hash_global_config_hash_func,
12165                 (void *)&cmd_set_hash_global_config_flow_type,
12166                 (void *)&cmd_set_hash_global_config_enable,
12167                 NULL,
12168         },
12169 };
12170
12171 /* Set hash input set */
12172 struct cmd_set_hash_input_set_result {
12173         cmdline_fixed_string_t set_hash_input_set;
12174         portid_t port_id;
12175         cmdline_fixed_string_t flow_type;
12176         cmdline_fixed_string_t inset_field;
12177         cmdline_fixed_string_t select;
12178 };
12179
12180 static enum rte_eth_input_set_field
12181 str2inset(char *string)
12182 {
12183         uint16_t i;
12184
12185         static const struct {
12186                 char str[32];
12187                 enum rte_eth_input_set_field inset;
12188         } inset_table[] = {
12189                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12190                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12191                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12192                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12193                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12194                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12195                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12196                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12197                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12198                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12199                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12200                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12201                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12202                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12203                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12204                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12205                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12206                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12207                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12208                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12209                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12210                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12211                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12212                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12213                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12214                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12215                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12216                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12217                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12218                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12219                 {"none", RTE_ETH_INPUT_SET_NONE},
12220         };
12221
12222         for (i = 0; i < RTE_DIM(inset_table); i++) {
12223                 if (!strcmp(string, inset_table[i].str))
12224                         return inset_table[i].inset;
12225         }
12226
12227         return RTE_ETH_INPUT_SET_UNKNOWN;
12228 }
12229
12230 static void
12231 cmd_set_hash_input_set_parsed(void *parsed_result,
12232                               __rte_unused struct cmdline *cl,
12233                               __rte_unused void *data)
12234 {
12235         struct cmd_set_hash_input_set_result *res = parsed_result;
12236         struct rte_eth_hash_filter_info info;
12237
12238         memset(&info, 0, sizeof(info));
12239         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12240         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12241         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12242         info.info.input_set_conf.inset_size = 1;
12243         if (!strcmp(res->select, "select"))
12244                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12245         else if (!strcmp(res->select, "add"))
12246                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12247         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12248                                 RTE_ETH_FILTER_SET, &info);
12249 }
12250
12251 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12252         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12253                 set_hash_input_set, "set_hash_input_set");
12254 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12255         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12256                 port_id, UINT16);
12257 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12258         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12259                 flow_type, NULL);
12260 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12261         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12262                 inset_field,
12263                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12264                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12265                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12266                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12267                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12268                 "fld-8th#none");
12269 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12270         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12271                 select, "select#add");
12272
12273 cmdline_parse_inst_t cmd_set_hash_input_set = {
12274         .f = cmd_set_hash_input_set_parsed,
12275         .data = NULL,
12276         .help_str = "set_hash_input_set <port_id> "
12277         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12278         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12279         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12280         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12281         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12282         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12283         "fld-7th|fld-8th|none select|add",
12284         .tokens = {
12285                 (void *)&cmd_set_hash_input_set_cmd,
12286                 (void *)&cmd_set_hash_input_set_port_id,
12287                 (void *)&cmd_set_hash_input_set_flow_type,
12288                 (void *)&cmd_set_hash_input_set_field,
12289                 (void *)&cmd_set_hash_input_set_select,
12290                 NULL,
12291         },
12292 };
12293
12294 /* Set flow director input set */
12295 struct cmd_set_fdir_input_set_result {
12296         cmdline_fixed_string_t set_fdir_input_set;
12297         portid_t port_id;
12298         cmdline_fixed_string_t flow_type;
12299         cmdline_fixed_string_t inset_field;
12300         cmdline_fixed_string_t select;
12301 };
12302
12303 static void
12304 cmd_set_fdir_input_set_parsed(void *parsed_result,
12305         __rte_unused struct cmdline *cl,
12306         __rte_unused void *data)
12307 {
12308         struct cmd_set_fdir_input_set_result *res = parsed_result;
12309         struct rte_eth_fdir_filter_info info;
12310
12311         memset(&info, 0, sizeof(info));
12312         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12313         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12314         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12315         info.info.input_set_conf.inset_size = 1;
12316         if (!strcmp(res->select, "select"))
12317                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12318         else if (!strcmp(res->select, "add"))
12319                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12320         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12321                 RTE_ETH_FILTER_SET, &info);
12322 }
12323
12324 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12325         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12326         set_fdir_input_set, "set_fdir_input_set");
12327 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12328         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12329         port_id, UINT16);
12330 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12331         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12332         flow_type,
12333         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12334         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12335 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12336         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12337         inset_field,
12338         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12339         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12340         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12341         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12342         "sctp-veri-tag#none");
12343 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12344         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12345         select, "select#add");
12346
12347 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12348         .f = cmd_set_fdir_input_set_parsed,
12349         .data = NULL,
12350         .help_str = "set_fdir_input_set <port_id> "
12351         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12352         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12353         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12354         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12355         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12356         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12357         "sctp-veri-tag|none select|add",
12358         .tokens = {
12359                 (void *)&cmd_set_fdir_input_set_cmd,
12360                 (void *)&cmd_set_fdir_input_set_port_id,
12361                 (void *)&cmd_set_fdir_input_set_flow_type,
12362                 (void *)&cmd_set_fdir_input_set_field,
12363                 (void *)&cmd_set_fdir_input_set_select,
12364                 NULL,
12365         },
12366 };
12367
12368 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12369 struct cmd_mcast_addr_result {
12370         cmdline_fixed_string_t mcast_addr_cmd;
12371         cmdline_fixed_string_t what;
12372         uint16_t port_num;
12373         struct ether_addr mc_addr;
12374 };
12375
12376 static void cmd_mcast_addr_parsed(void *parsed_result,
12377                 __attribute__((unused)) struct cmdline *cl,
12378                 __attribute__((unused)) void *data)
12379 {
12380         struct cmd_mcast_addr_result *res = parsed_result;
12381
12382         if (!is_multicast_ether_addr(&res->mc_addr)) {
12383                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12384                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12385                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12386                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12387                 return;
12388         }
12389         if (strcmp(res->what, "add") == 0)
12390                 mcast_addr_add(res->port_num, &res->mc_addr);
12391         else
12392                 mcast_addr_remove(res->port_num, &res->mc_addr);
12393 }
12394
12395 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12396         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12397                                  mcast_addr_cmd, "mcast_addr");
12398 cmdline_parse_token_string_t cmd_mcast_addr_what =
12399         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12400                                  "add#remove");
12401 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12402         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12403 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12404         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12405
12406 cmdline_parse_inst_t cmd_mcast_addr = {
12407         .f = cmd_mcast_addr_parsed,
12408         .data = (void *)0,
12409         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12410                 "Add/Remove multicast MAC address on port_id",
12411         .tokens = {
12412                 (void *)&cmd_mcast_addr_cmd,
12413                 (void *)&cmd_mcast_addr_what,
12414                 (void *)&cmd_mcast_addr_portnum,
12415                 (void *)&cmd_mcast_addr_addr,
12416                 NULL,
12417         },
12418 };
12419
12420 /* l2 tunnel config
12421  * only support E-tag now.
12422  */
12423
12424 /* Ether type config */
12425 struct cmd_config_l2_tunnel_eth_type_result {
12426         cmdline_fixed_string_t port;
12427         cmdline_fixed_string_t config;
12428         cmdline_fixed_string_t all;
12429         portid_t id;
12430         cmdline_fixed_string_t l2_tunnel;
12431         cmdline_fixed_string_t l2_tunnel_type;
12432         cmdline_fixed_string_t eth_type;
12433         uint16_t eth_type_val;
12434 };
12435
12436 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12437         TOKEN_STRING_INITIALIZER
12438                 (struct cmd_config_l2_tunnel_eth_type_result,
12439                  port, "port");
12440 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12441         TOKEN_STRING_INITIALIZER
12442                 (struct cmd_config_l2_tunnel_eth_type_result,
12443                  config, "config");
12444 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12445         TOKEN_STRING_INITIALIZER
12446                 (struct cmd_config_l2_tunnel_eth_type_result,
12447                  all, "all");
12448 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12449         TOKEN_NUM_INITIALIZER
12450                 (struct cmd_config_l2_tunnel_eth_type_result,
12451                  id, UINT16);
12452 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12453         TOKEN_STRING_INITIALIZER
12454                 (struct cmd_config_l2_tunnel_eth_type_result,
12455                  l2_tunnel, "l2-tunnel");
12456 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12457         TOKEN_STRING_INITIALIZER
12458                 (struct cmd_config_l2_tunnel_eth_type_result,
12459                  l2_tunnel_type, "E-tag");
12460 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12461         TOKEN_STRING_INITIALIZER
12462                 (struct cmd_config_l2_tunnel_eth_type_result,
12463                  eth_type, "ether-type");
12464 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12465         TOKEN_NUM_INITIALIZER
12466                 (struct cmd_config_l2_tunnel_eth_type_result,
12467                  eth_type_val, UINT16);
12468
12469 static enum rte_eth_tunnel_type
12470 str2fdir_l2_tunnel_type(char *string)
12471 {
12472         uint32_t i = 0;
12473
12474         static const struct {
12475                 char str[32];
12476                 enum rte_eth_tunnel_type type;
12477         } l2_tunnel_type_str[] = {
12478                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12479         };
12480
12481         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12482                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12483                         return l2_tunnel_type_str[i].type;
12484         }
12485         return RTE_TUNNEL_TYPE_NONE;
12486 }
12487
12488 /* ether type config for all ports */
12489 static void
12490 cmd_config_l2_tunnel_eth_type_all_parsed
12491         (void *parsed_result,
12492          __attribute__((unused)) struct cmdline *cl,
12493          __attribute__((unused)) void *data)
12494 {
12495         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12496         struct rte_eth_l2_tunnel_conf entry;
12497         portid_t pid;
12498
12499         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12500         entry.ether_type = res->eth_type_val;
12501
12502         RTE_ETH_FOREACH_DEV(pid) {
12503                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12504         }
12505 }
12506
12507 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12508         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12509         .data = NULL,
12510         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12511         .tokens = {
12512                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12513                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12514                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12515                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12516                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12517                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12518                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12519                 NULL,
12520         },
12521 };
12522
12523 /* ether type config for a specific port */
12524 static void
12525 cmd_config_l2_tunnel_eth_type_specific_parsed(
12526         void *parsed_result,
12527         __attribute__((unused)) struct cmdline *cl,
12528         __attribute__((unused)) void *data)
12529 {
12530         struct cmd_config_l2_tunnel_eth_type_result *res =
12531                  parsed_result;
12532         struct rte_eth_l2_tunnel_conf entry;
12533
12534         if (port_id_is_invalid(res->id, ENABLED_WARN))
12535                 return;
12536
12537         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12538         entry.ether_type = res->eth_type_val;
12539
12540         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12541 }
12542
12543 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12544         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12545         .data = NULL,
12546         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12547         .tokens = {
12548                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12549                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12550                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12551                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12552                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12553                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12554                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12555                 NULL,
12556         },
12557 };
12558
12559 /* Enable/disable l2 tunnel */
12560 struct cmd_config_l2_tunnel_en_dis_result {
12561         cmdline_fixed_string_t port;
12562         cmdline_fixed_string_t config;
12563         cmdline_fixed_string_t all;
12564         portid_t id;
12565         cmdline_fixed_string_t l2_tunnel;
12566         cmdline_fixed_string_t l2_tunnel_type;
12567         cmdline_fixed_string_t en_dis;
12568 };
12569
12570 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12571         TOKEN_STRING_INITIALIZER
12572                 (struct cmd_config_l2_tunnel_en_dis_result,
12573                  port, "port");
12574 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12575         TOKEN_STRING_INITIALIZER
12576                 (struct cmd_config_l2_tunnel_en_dis_result,
12577                  config, "config");
12578 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12579         TOKEN_STRING_INITIALIZER
12580                 (struct cmd_config_l2_tunnel_en_dis_result,
12581                  all, "all");
12582 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12583         TOKEN_NUM_INITIALIZER
12584                 (struct cmd_config_l2_tunnel_en_dis_result,
12585                  id, UINT16);
12586 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12587         TOKEN_STRING_INITIALIZER
12588                 (struct cmd_config_l2_tunnel_en_dis_result,
12589                  l2_tunnel, "l2-tunnel");
12590 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12591         TOKEN_STRING_INITIALIZER
12592                 (struct cmd_config_l2_tunnel_en_dis_result,
12593                  l2_tunnel_type, "E-tag");
12594 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12595         TOKEN_STRING_INITIALIZER
12596                 (struct cmd_config_l2_tunnel_en_dis_result,
12597                  en_dis, "enable#disable");
12598
12599 /* enable/disable l2 tunnel for all ports */
12600 static void
12601 cmd_config_l2_tunnel_en_dis_all_parsed(
12602         void *parsed_result,
12603         __attribute__((unused)) struct cmdline *cl,
12604         __attribute__((unused)) void *data)
12605 {
12606         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12607         struct rte_eth_l2_tunnel_conf entry;
12608         portid_t pid;
12609         uint8_t en;
12610
12611         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12612
12613         if (!strcmp("enable", res->en_dis))
12614                 en = 1;
12615         else
12616                 en = 0;
12617
12618         RTE_ETH_FOREACH_DEV(pid) {
12619                 rte_eth_dev_l2_tunnel_offload_set(pid,
12620                                                   &entry,
12621                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12622                                                   en);
12623         }
12624 }
12625
12626 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12627         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12628         .data = NULL,
12629         .help_str = "port config all l2-tunnel E-tag enable|disable",
12630         .tokens = {
12631                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12632                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12633                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12634                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12635                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12636                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12637                 NULL,
12638         },
12639 };
12640
12641 /* enable/disable l2 tunnel for a port */
12642 static void
12643 cmd_config_l2_tunnel_en_dis_specific_parsed(
12644         void *parsed_result,
12645         __attribute__((unused)) struct cmdline *cl,
12646         __attribute__((unused)) void *data)
12647 {
12648         struct cmd_config_l2_tunnel_en_dis_result *res =
12649                 parsed_result;
12650         struct rte_eth_l2_tunnel_conf entry;
12651
12652         if (port_id_is_invalid(res->id, ENABLED_WARN))
12653                 return;
12654
12655         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12656
12657         if (!strcmp("enable", res->en_dis))
12658                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12659                                                   &entry,
12660                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12661                                                   1);
12662         else
12663                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12664                                                   &entry,
12665                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12666                                                   0);
12667 }
12668
12669 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12670         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12671         .data = NULL,
12672         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12673         .tokens = {
12674                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12675                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12676                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12677                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12678                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12679                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12680                 NULL,
12681         },
12682 };
12683
12684 /* E-tag configuration */
12685
12686 /* Common result structure for all E-tag configuration */
12687 struct cmd_config_e_tag_result {
12688         cmdline_fixed_string_t e_tag;
12689         cmdline_fixed_string_t set;
12690         cmdline_fixed_string_t insertion;
12691         cmdline_fixed_string_t stripping;
12692         cmdline_fixed_string_t forwarding;
12693         cmdline_fixed_string_t filter;
12694         cmdline_fixed_string_t add;
12695         cmdline_fixed_string_t del;
12696         cmdline_fixed_string_t on;
12697         cmdline_fixed_string_t off;
12698         cmdline_fixed_string_t on_off;
12699         cmdline_fixed_string_t port_tag_id;
12700         uint32_t port_tag_id_val;
12701         cmdline_fixed_string_t e_tag_id;
12702         uint16_t e_tag_id_val;
12703         cmdline_fixed_string_t dst_pool;
12704         uint8_t dst_pool_val;
12705         cmdline_fixed_string_t port;
12706         portid_t port_id;
12707         cmdline_fixed_string_t vf;
12708         uint8_t vf_id;
12709 };
12710
12711 /* Common CLI fields for all E-tag configuration */
12712 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12713         TOKEN_STRING_INITIALIZER
12714                 (struct cmd_config_e_tag_result,
12715                  e_tag, "E-tag");
12716 cmdline_parse_token_string_t cmd_config_e_tag_set =
12717         TOKEN_STRING_INITIALIZER
12718                 (struct cmd_config_e_tag_result,
12719                  set, "set");
12720 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12721         TOKEN_STRING_INITIALIZER
12722                 (struct cmd_config_e_tag_result,
12723                  insertion, "insertion");
12724 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12725         TOKEN_STRING_INITIALIZER
12726                 (struct cmd_config_e_tag_result,
12727                  stripping, "stripping");
12728 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12729         TOKEN_STRING_INITIALIZER
12730                 (struct cmd_config_e_tag_result,
12731                  forwarding, "forwarding");
12732 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12733         TOKEN_STRING_INITIALIZER
12734                 (struct cmd_config_e_tag_result,
12735                  filter, "filter");
12736 cmdline_parse_token_string_t cmd_config_e_tag_add =
12737         TOKEN_STRING_INITIALIZER
12738                 (struct cmd_config_e_tag_result,
12739                  add, "add");
12740 cmdline_parse_token_string_t cmd_config_e_tag_del =
12741         TOKEN_STRING_INITIALIZER
12742                 (struct cmd_config_e_tag_result,
12743                  del, "del");
12744 cmdline_parse_token_string_t cmd_config_e_tag_on =
12745         TOKEN_STRING_INITIALIZER
12746                 (struct cmd_config_e_tag_result,
12747                  on, "on");
12748 cmdline_parse_token_string_t cmd_config_e_tag_off =
12749         TOKEN_STRING_INITIALIZER
12750                 (struct cmd_config_e_tag_result,
12751                  off, "off");
12752 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12753         TOKEN_STRING_INITIALIZER
12754                 (struct cmd_config_e_tag_result,
12755                  on_off, "on#off");
12756 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12757         TOKEN_STRING_INITIALIZER
12758                 (struct cmd_config_e_tag_result,
12759                  port_tag_id, "port-tag-id");
12760 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12761         TOKEN_NUM_INITIALIZER
12762                 (struct cmd_config_e_tag_result,
12763                  port_tag_id_val, UINT32);
12764 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12765         TOKEN_STRING_INITIALIZER
12766                 (struct cmd_config_e_tag_result,
12767                  e_tag_id, "e-tag-id");
12768 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12769         TOKEN_NUM_INITIALIZER
12770                 (struct cmd_config_e_tag_result,
12771                  e_tag_id_val, UINT16);
12772 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12773         TOKEN_STRING_INITIALIZER
12774                 (struct cmd_config_e_tag_result,
12775                  dst_pool, "dst-pool");
12776 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12777         TOKEN_NUM_INITIALIZER
12778                 (struct cmd_config_e_tag_result,
12779                  dst_pool_val, UINT8);
12780 cmdline_parse_token_string_t cmd_config_e_tag_port =
12781         TOKEN_STRING_INITIALIZER
12782                 (struct cmd_config_e_tag_result,
12783                  port, "port");
12784 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12785         TOKEN_NUM_INITIALIZER
12786                 (struct cmd_config_e_tag_result,
12787                  port_id, UINT16);
12788 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12789         TOKEN_STRING_INITIALIZER
12790                 (struct cmd_config_e_tag_result,
12791                  vf, "vf");
12792 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12793         TOKEN_NUM_INITIALIZER
12794                 (struct cmd_config_e_tag_result,
12795                  vf_id, UINT8);
12796
12797 /* E-tag insertion configuration */
12798 static void
12799 cmd_config_e_tag_insertion_en_parsed(
12800         void *parsed_result,
12801         __attribute__((unused)) struct cmdline *cl,
12802         __attribute__((unused)) void *data)
12803 {
12804         struct cmd_config_e_tag_result *res =
12805                 parsed_result;
12806         struct rte_eth_l2_tunnel_conf entry;
12807
12808         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12809                 return;
12810
12811         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12812         entry.tunnel_id = res->port_tag_id_val;
12813         entry.vf_id = res->vf_id;
12814         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12815                                           &entry,
12816                                           ETH_L2_TUNNEL_INSERTION_MASK,
12817                                           1);
12818 }
12819
12820 static void
12821 cmd_config_e_tag_insertion_dis_parsed(
12822         void *parsed_result,
12823         __attribute__((unused)) struct cmdline *cl,
12824         __attribute__((unused)) void *data)
12825 {
12826         struct cmd_config_e_tag_result *res =
12827                 parsed_result;
12828         struct rte_eth_l2_tunnel_conf entry;
12829
12830         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12831                 return;
12832
12833         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12834         entry.vf_id = res->vf_id;
12835
12836         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12837                                           &entry,
12838                                           ETH_L2_TUNNEL_INSERTION_MASK,
12839                                           0);
12840 }
12841
12842 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12843         .f = cmd_config_e_tag_insertion_en_parsed,
12844         .data = NULL,
12845         .help_str = "E-tag ... : E-tag insertion enable",
12846         .tokens = {
12847                 (void *)&cmd_config_e_tag_e_tag,
12848                 (void *)&cmd_config_e_tag_set,
12849                 (void *)&cmd_config_e_tag_insertion,
12850                 (void *)&cmd_config_e_tag_on,
12851                 (void *)&cmd_config_e_tag_port_tag_id,
12852                 (void *)&cmd_config_e_tag_port_tag_id_val,
12853                 (void *)&cmd_config_e_tag_port,
12854                 (void *)&cmd_config_e_tag_port_id,
12855                 (void *)&cmd_config_e_tag_vf,
12856                 (void *)&cmd_config_e_tag_vf_id,
12857                 NULL,
12858         },
12859 };
12860
12861 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12862         .f = cmd_config_e_tag_insertion_dis_parsed,
12863         .data = NULL,
12864         .help_str = "E-tag ... : E-tag insertion disable",
12865         .tokens = {
12866                 (void *)&cmd_config_e_tag_e_tag,
12867                 (void *)&cmd_config_e_tag_set,
12868                 (void *)&cmd_config_e_tag_insertion,
12869                 (void *)&cmd_config_e_tag_off,
12870                 (void *)&cmd_config_e_tag_port,
12871                 (void *)&cmd_config_e_tag_port_id,
12872                 (void *)&cmd_config_e_tag_vf,
12873                 (void *)&cmd_config_e_tag_vf_id,
12874                 NULL,
12875         },
12876 };
12877
12878 /* E-tag stripping configuration */
12879 static void
12880 cmd_config_e_tag_stripping_parsed(
12881         void *parsed_result,
12882         __attribute__((unused)) struct cmdline *cl,
12883         __attribute__((unused)) void *data)
12884 {
12885         struct cmd_config_e_tag_result *res =
12886                 parsed_result;
12887         struct rte_eth_l2_tunnel_conf entry;
12888
12889         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12890                 return;
12891
12892         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12893
12894         if (!strcmp(res->on_off, "on"))
12895                 rte_eth_dev_l2_tunnel_offload_set
12896                         (res->port_id,
12897                          &entry,
12898                          ETH_L2_TUNNEL_STRIPPING_MASK,
12899                          1);
12900         else
12901                 rte_eth_dev_l2_tunnel_offload_set
12902                         (res->port_id,
12903                          &entry,
12904                          ETH_L2_TUNNEL_STRIPPING_MASK,
12905                          0);
12906 }
12907
12908 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12909         .f = cmd_config_e_tag_stripping_parsed,
12910         .data = NULL,
12911         .help_str = "E-tag ... : E-tag stripping enable/disable",
12912         .tokens = {
12913                 (void *)&cmd_config_e_tag_e_tag,
12914                 (void *)&cmd_config_e_tag_set,
12915                 (void *)&cmd_config_e_tag_stripping,
12916                 (void *)&cmd_config_e_tag_on_off,
12917                 (void *)&cmd_config_e_tag_port,
12918                 (void *)&cmd_config_e_tag_port_id,
12919                 NULL,
12920         },
12921 };
12922
12923 /* E-tag forwarding configuration */
12924 static void
12925 cmd_config_e_tag_forwarding_parsed(
12926         void *parsed_result,
12927         __attribute__((unused)) struct cmdline *cl,
12928         __attribute__((unused)) void *data)
12929 {
12930         struct cmd_config_e_tag_result *res = parsed_result;
12931         struct rte_eth_l2_tunnel_conf entry;
12932
12933         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12934                 return;
12935
12936         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12937
12938         if (!strcmp(res->on_off, "on"))
12939                 rte_eth_dev_l2_tunnel_offload_set
12940                         (res->port_id,
12941                          &entry,
12942                          ETH_L2_TUNNEL_FORWARDING_MASK,
12943                          1);
12944         else
12945                 rte_eth_dev_l2_tunnel_offload_set
12946                         (res->port_id,
12947                          &entry,
12948                          ETH_L2_TUNNEL_FORWARDING_MASK,
12949                          0);
12950 }
12951
12952 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12953         .f = cmd_config_e_tag_forwarding_parsed,
12954         .data = NULL,
12955         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12956         .tokens = {
12957                 (void *)&cmd_config_e_tag_e_tag,
12958                 (void *)&cmd_config_e_tag_set,
12959                 (void *)&cmd_config_e_tag_forwarding,
12960                 (void *)&cmd_config_e_tag_on_off,
12961                 (void *)&cmd_config_e_tag_port,
12962                 (void *)&cmd_config_e_tag_port_id,
12963                 NULL,
12964         },
12965 };
12966
12967 /* E-tag filter configuration */
12968 static void
12969 cmd_config_e_tag_filter_add_parsed(
12970         void *parsed_result,
12971         __attribute__((unused)) struct cmdline *cl,
12972         __attribute__((unused)) void *data)
12973 {
12974         struct cmd_config_e_tag_result *res = parsed_result;
12975         struct rte_eth_l2_tunnel_conf entry;
12976         int ret = 0;
12977
12978         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12979                 return;
12980
12981         if (res->e_tag_id_val > 0x3fff) {
12982                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12983                 return;
12984         }
12985
12986         ret = rte_eth_dev_filter_supported(res->port_id,
12987                                            RTE_ETH_FILTER_L2_TUNNEL);
12988         if (ret < 0) {
12989                 printf("E-tag filter is not supported on port %u.\n",
12990                        res->port_id);
12991                 return;
12992         }
12993
12994         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12995         entry.tunnel_id = res->e_tag_id_val;
12996         entry.pool = res->dst_pool_val;
12997
12998         ret = rte_eth_dev_filter_ctrl(res->port_id,
12999                                       RTE_ETH_FILTER_L2_TUNNEL,
13000                                       RTE_ETH_FILTER_ADD,
13001                                       &entry);
13002         if (ret < 0)
13003                 printf("E-tag filter programming error: (%s)\n",
13004                        strerror(-ret));
13005 }
13006
13007 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13008         .f = cmd_config_e_tag_filter_add_parsed,
13009         .data = NULL,
13010         .help_str = "E-tag ... : E-tag filter add",
13011         .tokens = {
13012                 (void *)&cmd_config_e_tag_e_tag,
13013                 (void *)&cmd_config_e_tag_set,
13014                 (void *)&cmd_config_e_tag_filter,
13015                 (void *)&cmd_config_e_tag_add,
13016                 (void *)&cmd_config_e_tag_e_tag_id,
13017                 (void *)&cmd_config_e_tag_e_tag_id_val,
13018                 (void *)&cmd_config_e_tag_dst_pool,
13019                 (void *)&cmd_config_e_tag_dst_pool_val,
13020                 (void *)&cmd_config_e_tag_port,
13021                 (void *)&cmd_config_e_tag_port_id,
13022                 NULL,
13023         },
13024 };
13025
13026 static void
13027 cmd_config_e_tag_filter_del_parsed(
13028         void *parsed_result,
13029         __attribute__((unused)) struct cmdline *cl,
13030         __attribute__((unused)) void *data)
13031 {
13032         struct cmd_config_e_tag_result *res = parsed_result;
13033         struct rte_eth_l2_tunnel_conf entry;
13034         int ret = 0;
13035
13036         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13037                 return;
13038
13039         if (res->e_tag_id_val > 0x3fff) {
13040                 printf("e-tag-id must be less than 0x3fff.\n");
13041                 return;
13042         }
13043
13044         ret = rte_eth_dev_filter_supported(res->port_id,
13045                                            RTE_ETH_FILTER_L2_TUNNEL);
13046         if (ret < 0) {
13047                 printf("E-tag filter is not supported on port %u.\n",
13048                        res->port_id);
13049                 return;
13050         }
13051
13052         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13053         entry.tunnel_id = res->e_tag_id_val;
13054
13055         ret = rte_eth_dev_filter_ctrl(res->port_id,
13056                                       RTE_ETH_FILTER_L2_TUNNEL,
13057                                       RTE_ETH_FILTER_DELETE,
13058                                       &entry);
13059         if (ret < 0)
13060                 printf("E-tag filter programming error: (%s)\n",
13061                        strerror(-ret));
13062 }
13063
13064 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13065         .f = cmd_config_e_tag_filter_del_parsed,
13066         .data = NULL,
13067         .help_str = "E-tag ... : E-tag filter delete",
13068         .tokens = {
13069                 (void *)&cmd_config_e_tag_e_tag,
13070                 (void *)&cmd_config_e_tag_set,
13071                 (void *)&cmd_config_e_tag_filter,
13072                 (void *)&cmd_config_e_tag_del,
13073                 (void *)&cmd_config_e_tag_e_tag_id,
13074                 (void *)&cmd_config_e_tag_e_tag_id_val,
13075                 (void *)&cmd_config_e_tag_port,
13076                 (void *)&cmd_config_e_tag_port_id,
13077                 NULL,
13078         },
13079 };
13080
13081 /* vf vlan anti spoof configuration */
13082
13083 /* Common result structure for vf vlan anti spoof */
13084 struct cmd_vf_vlan_anti_spoof_result {
13085         cmdline_fixed_string_t set;
13086         cmdline_fixed_string_t vf;
13087         cmdline_fixed_string_t vlan;
13088         cmdline_fixed_string_t antispoof;
13089         portid_t port_id;
13090         uint32_t vf_id;
13091         cmdline_fixed_string_t on_off;
13092 };
13093
13094 /* Common CLI fields for vf vlan anti spoof enable disable */
13095 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13096         TOKEN_STRING_INITIALIZER
13097                 (struct cmd_vf_vlan_anti_spoof_result,
13098                  set, "set");
13099 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13100         TOKEN_STRING_INITIALIZER
13101                 (struct cmd_vf_vlan_anti_spoof_result,
13102                  vf, "vf");
13103 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13104         TOKEN_STRING_INITIALIZER
13105                 (struct cmd_vf_vlan_anti_spoof_result,
13106                  vlan, "vlan");
13107 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13108         TOKEN_STRING_INITIALIZER
13109                 (struct cmd_vf_vlan_anti_spoof_result,
13110                  antispoof, "antispoof");
13111 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13112         TOKEN_NUM_INITIALIZER
13113                 (struct cmd_vf_vlan_anti_spoof_result,
13114                  port_id, UINT16);
13115 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13116         TOKEN_NUM_INITIALIZER
13117                 (struct cmd_vf_vlan_anti_spoof_result,
13118                  vf_id, UINT32);
13119 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13120         TOKEN_STRING_INITIALIZER
13121                 (struct cmd_vf_vlan_anti_spoof_result,
13122                  on_off, "on#off");
13123
13124 static void
13125 cmd_set_vf_vlan_anti_spoof_parsed(
13126         void *parsed_result,
13127         __attribute__((unused)) struct cmdline *cl,
13128         __attribute__((unused)) void *data)
13129 {
13130         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13131         int ret = -ENOTSUP;
13132
13133         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13134
13135         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13136                 return;
13137
13138 #ifdef RTE_LIBRTE_IXGBE_PMD
13139         if (ret == -ENOTSUP)
13140                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13141                                 res->vf_id, is_on);
13142 #endif
13143 #ifdef RTE_LIBRTE_I40E_PMD
13144         if (ret == -ENOTSUP)
13145                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13146                                 res->vf_id, is_on);
13147 #endif
13148 #ifdef RTE_LIBRTE_BNXT_PMD
13149         if (ret == -ENOTSUP)
13150                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13151                                 res->vf_id, is_on);
13152 #endif
13153
13154         switch (ret) {
13155         case 0:
13156                 break;
13157         case -EINVAL:
13158                 printf("invalid vf_id %d\n", res->vf_id);
13159                 break;
13160         case -ENODEV:
13161                 printf("invalid port_id %d\n", res->port_id);
13162                 break;
13163         case -ENOTSUP:
13164                 printf("function not implemented\n");
13165                 break;
13166         default:
13167                 printf("programming error: (%s)\n", strerror(-ret));
13168         }
13169 }
13170
13171 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13172         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13173         .data = NULL,
13174         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13175         .tokens = {
13176                 (void *)&cmd_vf_vlan_anti_spoof_set,
13177                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13178                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13179                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13180                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13181                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13182                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13183                 NULL,
13184         },
13185 };
13186
13187 /* vf mac anti spoof configuration */
13188
13189 /* Common result structure for vf mac anti spoof */
13190 struct cmd_vf_mac_anti_spoof_result {
13191         cmdline_fixed_string_t set;
13192         cmdline_fixed_string_t vf;
13193         cmdline_fixed_string_t mac;
13194         cmdline_fixed_string_t antispoof;
13195         portid_t port_id;
13196         uint32_t vf_id;
13197         cmdline_fixed_string_t on_off;
13198 };
13199
13200 /* Common CLI fields for vf mac anti spoof enable disable */
13201 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13202         TOKEN_STRING_INITIALIZER
13203                 (struct cmd_vf_mac_anti_spoof_result,
13204                  set, "set");
13205 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13206         TOKEN_STRING_INITIALIZER
13207                 (struct cmd_vf_mac_anti_spoof_result,
13208                  vf, "vf");
13209 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13210         TOKEN_STRING_INITIALIZER
13211                 (struct cmd_vf_mac_anti_spoof_result,
13212                  mac, "mac");
13213 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13214         TOKEN_STRING_INITIALIZER
13215                 (struct cmd_vf_mac_anti_spoof_result,
13216                  antispoof, "antispoof");
13217 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13218         TOKEN_NUM_INITIALIZER
13219                 (struct cmd_vf_mac_anti_spoof_result,
13220                  port_id, UINT16);
13221 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13222         TOKEN_NUM_INITIALIZER
13223                 (struct cmd_vf_mac_anti_spoof_result,
13224                  vf_id, UINT32);
13225 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13226         TOKEN_STRING_INITIALIZER
13227                 (struct cmd_vf_mac_anti_spoof_result,
13228                  on_off, "on#off");
13229
13230 static void
13231 cmd_set_vf_mac_anti_spoof_parsed(
13232         void *parsed_result,
13233         __attribute__((unused)) struct cmdline *cl,
13234         __attribute__((unused)) void *data)
13235 {
13236         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13237         int ret = -ENOTSUP;
13238
13239         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13240
13241         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13242                 return;
13243
13244 #ifdef RTE_LIBRTE_IXGBE_PMD
13245         if (ret == -ENOTSUP)
13246                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13247                         res->vf_id, is_on);
13248 #endif
13249 #ifdef RTE_LIBRTE_I40E_PMD
13250         if (ret == -ENOTSUP)
13251                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13252                         res->vf_id, is_on);
13253 #endif
13254 #ifdef RTE_LIBRTE_BNXT_PMD
13255         if (ret == -ENOTSUP)
13256                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13257                         res->vf_id, is_on);
13258 #endif
13259
13260         switch (ret) {
13261         case 0:
13262                 break;
13263         case -EINVAL:
13264                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13265                 break;
13266         case -ENODEV:
13267                 printf("invalid port_id %d\n", res->port_id);
13268                 break;
13269         case -ENOTSUP:
13270                 printf("function not implemented\n");
13271                 break;
13272         default:
13273                 printf("programming error: (%s)\n", strerror(-ret));
13274         }
13275 }
13276
13277 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13278         .f = cmd_set_vf_mac_anti_spoof_parsed,
13279         .data = NULL,
13280         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13281         .tokens = {
13282                 (void *)&cmd_vf_mac_anti_spoof_set,
13283                 (void *)&cmd_vf_mac_anti_spoof_vf,
13284                 (void *)&cmd_vf_mac_anti_spoof_mac,
13285                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13286                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13287                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13288                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13289                 NULL,
13290         },
13291 };
13292
13293 /* vf vlan strip queue configuration */
13294
13295 /* Common result structure for vf mac anti spoof */
13296 struct cmd_vf_vlan_stripq_result {
13297         cmdline_fixed_string_t set;
13298         cmdline_fixed_string_t vf;
13299         cmdline_fixed_string_t vlan;
13300         cmdline_fixed_string_t stripq;
13301         portid_t port_id;
13302         uint16_t vf_id;
13303         cmdline_fixed_string_t on_off;
13304 };
13305
13306 /* Common CLI fields for vf vlan strip enable disable */
13307 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13308         TOKEN_STRING_INITIALIZER
13309                 (struct cmd_vf_vlan_stripq_result,
13310                  set, "set");
13311 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13312         TOKEN_STRING_INITIALIZER
13313                 (struct cmd_vf_vlan_stripq_result,
13314                  vf, "vf");
13315 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13316         TOKEN_STRING_INITIALIZER
13317                 (struct cmd_vf_vlan_stripq_result,
13318                  vlan, "vlan");
13319 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13320         TOKEN_STRING_INITIALIZER
13321                 (struct cmd_vf_vlan_stripq_result,
13322                  stripq, "stripq");
13323 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13324         TOKEN_NUM_INITIALIZER
13325                 (struct cmd_vf_vlan_stripq_result,
13326                  port_id, UINT16);
13327 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13328         TOKEN_NUM_INITIALIZER
13329                 (struct cmd_vf_vlan_stripq_result,
13330                  vf_id, UINT16);
13331 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13332         TOKEN_STRING_INITIALIZER
13333                 (struct cmd_vf_vlan_stripq_result,
13334                  on_off, "on#off");
13335
13336 static void
13337 cmd_set_vf_vlan_stripq_parsed(
13338         void *parsed_result,
13339         __attribute__((unused)) struct cmdline *cl,
13340         __attribute__((unused)) void *data)
13341 {
13342         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13343         int ret = -ENOTSUP;
13344
13345         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13346
13347         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13348                 return;
13349
13350 #ifdef RTE_LIBRTE_IXGBE_PMD
13351         if (ret == -ENOTSUP)
13352                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13353                         res->vf_id, is_on);
13354 #endif
13355 #ifdef RTE_LIBRTE_I40E_PMD
13356         if (ret == -ENOTSUP)
13357                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13358                         res->vf_id, is_on);
13359 #endif
13360 #ifdef RTE_LIBRTE_BNXT_PMD
13361         if (ret == -ENOTSUP)
13362                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13363                         res->vf_id, is_on);
13364 #endif
13365
13366         switch (ret) {
13367         case 0:
13368                 break;
13369         case -EINVAL:
13370                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13371                 break;
13372         case -ENODEV:
13373                 printf("invalid port_id %d\n", res->port_id);
13374                 break;
13375         case -ENOTSUP:
13376                 printf("function not implemented\n");
13377                 break;
13378         default:
13379                 printf("programming error: (%s)\n", strerror(-ret));
13380         }
13381 }
13382
13383 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13384         .f = cmd_set_vf_vlan_stripq_parsed,
13385         .data = NULL,
13386         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13387         .tokens = {
13388                 (void *)&cmd_vf_vlan_stripq_set,
13389                 (void *)&cmd_vf_vlan_stripq_vf,
13390                 (void *)&cmd_vf_vlan_stripq_vlan,
13391                 (void *)&cmd_vf_vlan_stripq_stripq,
13392                 (void *)&cmd_vf_vlan_stripq_port_id,
13393                 (void *)&cmd_vf_vlan_stripq_vf_id,
13394                 (void *)&cmd_vf_vlan_stripq_on_off,
13395                 NULL,
13396         },
13397 };
13398
13399 /* vf vlan insert configuration */
13400
13401 /* Common result structure for vf vlan insert */
13402 struct cmd_vf_vlan_insert_result {
13403         cmdline_fixed_string_t set;
13404         cmdline_fixed_string_t vf;
13405         cmdline_fixed_string_t vlan;
13406         cmdline_fixed_string_t insert;
13407         portid_t port_id;
13408         uint16_t vf_id;
13409         uint16_t vlan_id;
13410 };
13411
13412 /* Common CLI fields for vf vlan insert enable disable */
13413 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13414         TOKEN_STRING_INITIALIZER
13415                 (struct cmd_vf_vlan_insert_result,
13416                  set, "set");
13417 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13418         TOKEN_STRING_INITIALIZER
13419                 (struct cmd_vf_vlan_insert_result,
13420                  vf, "vf");
13421 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13422         TOKEN_STRING_INITIALIZER
13423                 (struct cmd_vf_vlan_insert_result,
13424                  vlan, "vlan");
13425 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13426         TOKEN_STRING_INITIALIZER
13427                 (struct cmd_vf_vlan_insert_result,
13428                  insert, "insert");
13429 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13430         TOKEN_NUM_INITIALIZER
13431                 (struct cmd_vf_vlan_insert_result,
13432                  port_id, UINT16);
13433 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13434         TOKEN_NUM_INITIALIZER
13435                 (struct cmd_vf_vlan_insert_result,
13436                  vf_id, UINT16);
13437 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13438         TOKEN_NUM_INITIALIZER
13439                 (struct cmd_vf_vlan_insert_result,
13440                  vlan_id, UINT16);
13441
13442 static void
13443 cmd_set_vf_vlan_insert_parsed(
13444         void *parsed_result,
13445         __attribute__((unused)) struct cmdline *cl,
13446         __attribute__((unused)) void *data)
13447 {
13448         struct cmd_vf_vlan_insert_result *res = parsed_result;
13449         int ret = -ENOTSUP;
13450
13451         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13452                 return;
13453
13454 #ifdef RTE_LIBRTE_IXGBE_PMD
13455         if (ret == -ENOTSUP)
13456                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13457                         res->vlan_id);
13458 #endif
13459 #ifdef RTE_LIBRTE_I40E_PMD
13460         if (ret == -ENOTSUP)
13461                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13462                         res->vlan_id);
13463 #endif
13464 #ifdef RTE_LIBRTE_BNXT_PMD
13465         if (ret == -ENOTSUP)
13466                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13467                         res->vlan_id);
13468 #endif
13469
13470         switch (ret) {
13471         case 0:
13472                 break;
13473         case -EINVAL:
13474                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13475                 break;
13476         case -ENODEV:
13477                 printf("invalid port_id %d\n", res->port_id);
13478                 break;
13479         case -ENOTSUP:
13480                 printf("function not implemented\n");
13481                 break;
13482         default:
13483                 printf("programming error: (%s)\n", strerror(-ret));
13484         }
13485 }
13486
13487 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13488         .f = cmd_set_vf_vlan_insert_parsed,
13489         .data = NULL,
13490         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13491         .tokens = {
13492                 (void *)&cmd_vf_vlan_insert_set,
13493                 (void *)&cmd_vf_vlan_insert_vf,
13494                 (void *)&cmd_vf_vlan_insert_vlan,
13495                 (void *)&cmd_vf_vlan_insert_insert,
13496                 (void *)&cmd_vf_vlan_insert_port_id,
13497                 (void *)&cmd_vf_vlan_insert_vf_id,
13498                 (void *)&cmd_vf_vlan_insert_vlan_id,
13499                 NULL,
13500         },
13501 };
13502
13503 /* tx loopback configuration */
13504
13505 /* Common result structure for tx loopback */
13506 struct cmd_tx_loopback_result {
13507         cmdline_fixed_string_t set;
13508         cmdline_fixed_string_t tx;
13509         cmdline_fixed_string_t loopback;
13510         portid_t port_id;
13511         cmdline_fixed_string_t on_off;
13512 };
13513
13514 /* Common CLI fields for tx loopback enable disable */
13515 cmdline_parse_token_string_t cmd_tx_loopback_set =
13516         TOKEN_STRING_INITIALIZER
13517                 (struct cmd_tx_loopback_result,
13518                  set, "set");
13519 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13520         TOKEN_STRING_INITIALIZER
13521                 (struct cmd_tx_loopback_result,
13522                  tx, "tx");
13523 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13524         TOKEN_STRING_INITIALIZER
13525                 (struct cmd_tx_loopback_result,
13526                  loopback, "loopback");
13527 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13528         TOKEN_NUM_INITIALIZER
13529                 (struct cmd_tx_loopback_result,
13530                  port_id, UINT16);
13531 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13532         TOKEN_STRING_INITIALIZER
13533                 (struct cmd_tx_loopback_result,
13534                  on_off, "on#off");
13535
13536 static void
13537 cmd_set_tx_loopback_parsed(
13538         void *parsed_result,
13539         __attribute__((unused)) struct cmdline *cl,
13540         __attribute__((unused)) void *data)
13541 {
13542         struct cmd_tx_loopback_result *res = parsed_result;
13543         int ret = -ENOTSUP;
13544
13545         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13546
13547         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13548                 return;
13549
13550 #ifdef RTE_LIBRTE_IXGBE_PMD
13551         if (ret == -ENOTSUP)
13552                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13553 #endif
13554 #ifdef RTE_LIBRTE_I40E_PMD
13555         if (ret == -ENOTSUP)
13556                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13557 #endif
13558 #ifdef RTE_LIBRTE_BNXT_PMD
13559         if (ret == -ENOTSUP)
13560                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13561 #endif
13562 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13563         if (ret == -ENOTSUP)
13564                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13565 #endif
13566
13567         switch (ret) {
13568         case 0:
13569                 break;
13570         case -EINVAL:
13571                 printf("invalid is_on %d\n", is_on);
13572                 break;
13573         case -ENODEV:
13574                 printf("invalid port_id %d\n", res->port_id);
13575                 break;
13576         case -ENOTSUP:
13577                 printf("function not implemented\n");
13578                 break;
13579         default:
13580                 printf("programming error: (%s)\n", strerror(-ret));
13581         }
13582 }
13583
13584 cmdline_parse_inst_t cmd_set_tx_loopback = {
13585         .f = cmd_set_tx_loopback_parsed,
13586         .data = NULL,
13587         .help_str = "set tx loopback <port_id> on|off",
13588         .tokens = {
13589                 (void *)&cmd_tx_loopback_set,
13590                 (void *)&cmd_tx_loopback_tx,
13591                 (void *)&cmd_tx_loopback_loopback,
13592                 (void *)&cmd_tx_loopback_port_id,
13593                 (void *)&cmd_tx_loopback_on_off,
13594                 NULL,
13595         },
13596 };
13597
13598 /* all queues drop enable configuration */
13599
13600 /* Common result structure for all queues drop enable */
13601 struct cmd_all_queues_drop_en_result {
13602         cmdline_fixed_string_t set;
13603         cmdline_fixed_string_t all;
13604         cmdline_fixed_string_t queues;
13605         cmdline_fixed_string_t drop;
13606         portid_t port_id;
13607         cmdline_fixed_string_t on_off;
13608 };
13609
13610 /* Common CLI fields for tx loopback enable disable */
13611 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13612         TOKEN_STRING_INITIALIZER
13613                 (struct cmd_all_queues_drop_en_result,
13614                  set, "set");
13615 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13616         TOKEN_STRING_INITIALIZER
13617                 (struct cmd_all_queues_drop_en_result,
13618                  all, "all");
13619 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13620         TOKEN_STRING_INITIALIZER
13621                 (struct cmd_all_queues_drop_en_result,
13622                  queues, "queues");
13623 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13624         TOKEN_STRING_INITIALIZER
13625                 (struct cmd_all_queues_drop_en_result,
13626                  drop, "drop");
13627 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13628         TOKEN_NUM_INITIALIZER
13629                 (struct cmd_all_queues_drop_en_result,
13630                  port_id, UINT16);
13631 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13632         TOKEN_STRING_INITIALIZER
13633                 (struct cmd_all_queues_drop_en_result,
13634                  on_off, "on#off");
13635
13636 static void
13637 cmd_set_all_queues_drop_en_parsed(
13638         void *parsed_result,
13639         __attribute__((unused)) struct cmdline *cl,
13640         __attribute__((unused)) void *data)
13641 {
13642         struct cmd_all_queues_drop_en_result *res = parsed_result;
13643         int ret = -ENOTSUP;
13644         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13645
13646         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13647                 return;
13648
13649 #ifdef RTE_LIBRTE_IXGBE_PMD
13650         if (ret == -ENOTSUP)
13651                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13652 #endif
13653 #ifdef RTE_LIBRTE_BNXT_PMD
13654         if (ret == -ENOTSUP)
13655                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13656 #endif
13657         switch (ret) {
13658         case 0:
13659                 break;
13660         case -EINVAL:
13661                 printf("invalid is_on %d\n", is_on);
13662                 break;
13663         case -ENODEV:
13664                 printf("invalid port_id %d\n", res->port_id);
13665                 break;
13666         case -ENOTSUP:
13667                 printf("function not implemented\n");
13668                 break;
13669         default:
13670                 printf("programming error: (%s)\n", strerror(-ret));
13671         }
13672 }
13673
13674 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13675         .f = cmd_set_all_queues_drop_en_parsed,
13676         .data = NULL,
13677         .help_str = "set all queues drop <port_id> on|off",
13678         .tokens = {
13679                 (void *)&cmd_all_queues_drop_en_set,
13680                 (void *)&cmd_all_queues_drop_en_all,
13681                 (void *)&cmd_all_queues_drop_en_queues,
13682                 (void *)&cmd_all_queues_drop_en_drop,
13683                 (void *)&cmd_all_queues_drop_en_port_id,
13684                 (void *)&cmd_all_queues_drop_en_on_off,
13685                 NULL,
13686         },
13687 };
13688
13689 /* vf split drop enable configuration */
13690
13691 /* Common result structure for vf split drop enable */
13692 struct cmd_vf_split_drop_en_result {
13693         cmdline_fixed_string_t set;
13694         cmdline_fixed_string_t vf;
13695         cmdline_fixed_string_t split;
13696         cmdline_fixed_string_t drop;
13697         portid_t port_id;
13698         uint16_t vf_id;
13699         cmdline_fixed_string_t on_off;
13700 };
13701
13702 /* Common CLI fields for vf split drop enable disable */
13703 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13704         TOKEN_STRING_INITIALIZER
13705                 (struct cmd_vf_split_drop_en_result,
13706                  set, "set");
13707 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13708         TOKEN_STRING_INITIALIZER
13709                 (struct cmd_vf_split_drop_en_result,
13710                  vf, "vf");
13711 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13712         TOKEN_STRING_INITIALIZER
13713                 (struct cmd_vf_split_drop_en_result,
13714                  split, "split");
13715 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13716         TOKEN_STRING_INITIALIZER
13717                 (struct cmd_vf_split_drop_en_result,
13718                  drop, "drop");
13719 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13720         TOKEN_NUM_INITIALIZER
13721                 (struct cmd_vf_split_drop_en_result,
13722                  port_id, UINT16);
13723 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13724         TOKEN_NUM_INITIALIZER
13725                 (struct cmd_vf_split_drop_en_result,
13726                  vf_id, UINT16);
13727 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13728         TOKEN_STRING_INITIALIZER
13729                 (struct cmd_vf_split_drop_en_result,
13730                  on_off, "on#off");
13731
13732 static void
13733 cmd_set_vf_split_drop_en_parsed(
13734         void *parsed_result,
13735         __attribute__((unused)) struct cmdline *cl,
13736         __attribute__((unused)) void *data)
13737 {
13738         struct cmd_vf_split_drop_en_result *res = parsed_result;
13739         int ret = -ENOTSUP;
13740         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13741
13742         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13743                 return;
13744
13745 #ifdef RTE_LIBRTE_IXGBE_PMD
13746         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13747                         is_on);
13748 #endif
13749         switch (ret) {
13750         case 0:
13751                 break;
13752         case -EINVAL:
13753                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13754                 break;
13755         case -ENODEV:
13756                 printf("invalid port_id %d\n", res->port_id);
13757                 break;
13758         case -ENOTSUP:
13759                 printf("not supported on port %d\n", res->port_id);
13760                 break;
13761         default:
13762                 printf("programming error: (%s)\n", strerror(-ret));
13763         }
13764 }
13765
13766 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13767         .f = cmd_set_vf_split_drop_en_parsed,
13768         .data = NULL,
13769         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13770         .tokens = {
13771                 (void *)&cmd_vf_split_drop_en_set,
13772                 (void *)&cmd_vf_split_drop_en_vf,
13773                 (void *)&cmd_vf_split_drop_en_split,
13774                 (void *)&cmd_vf_split_drop_en_drop,
13775                 (void *)&cmd_vf_split_drop_en_port_id,
13776                 (void *)&cmd_vf_split_drop_en_vf_id,
13777                 (void *)&cmd_vf_split_drop_en_on_off,
13778                 NULL,
13779         },
13780 };
13781
13782 /* vf mac address configuration */
13783
13784 /* Common result structure for vf mac address */
13785 struct cmd_set_vf_mac_addr_result {
13786         cmdline_fixed_string_t set;
13787         cmdline_fixed_string_t vf;
13788         cmdline_fixed_string_t mac;
13789         cmdline_fixed_string_t addr;
13790         portid_t port_id;
13791         uint16_t vf_id;
13792         struct ether_addr mac_addr;
13793
13794 };
13795
13796 /* Common CLI fields for vf split drop enable disable */
13797 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13798         TOKEN_STRING_INITIALIZER
13799                 (struct cmd_set_vf_mac_addr_result,
13800                  set, "set");
13801 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13802         TOKEN_STRING_INITIALIZER
13803                 (struct cmd_set_vf_mac_addr_result,
13804                  vf, "vf");
13805 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13806         TOKEN_STRING_INITIALIZER
13807                 (struct cmd_set_vf_mac_addr_result,
13808                  mac, "mac");
13809 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13810         TOKEN_STRING_INITIALIZER
13811                 (struct cmd_set_vf_mac_addr_result,
13812                  addr, "addr");
13813 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13814         TOKEN_NUM_INITIALIZER
13815                 (struct cmd_set_vf_mac_addr_result,
13816                  port_id, UINT16);
13817 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13818         TOKEN_NUM_INITIALIZER
13819                 (struct cmd_set_vf_mac_addr_result,
13820                  vf_id, UINT16);
13821 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13822         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13823                  mac_addr);
13824
13825 static void
13826 cmd_set_vf_mac_addr_parsed(
13827         void *parsed_result,
13828         __attribute__((unused)) struct cmdline *cl,
13829         __attribute__((unused)) void *data)
13830 {
13831         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13832         int ret = -ENOTSUP;
13833
13834         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13835                 return;
13836
13837 #ifdef RTE_LIBRTE_IXGBE_PMD
13838         if (ret == -ENOTSUP)
13839                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13840                                 &res->mac_addr);
13841 #endif
13842 #ifdef RTE_LIBRTE_I40E_PMD
13843         if (ret == -ENOTSUP)
13844                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13845                                 &res->mac_addr);
13846 #endif
13847 #ifdef RTE_LIBRTE_BNXT_PMD
13848         if (ret == -ENOTSUP)
13849                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13850                                 &res->mac_addr);
13851 #endif
13852
13853         switch (ret) {
13854         case 0:
13855                 break;
13856         case -EINVAL:
13857                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13858                 break;
13859         case -ENODEV:
13860                 printf("invalid port_id %d\n", res->port_id);
13861                 break;
13862         case -ENOTSUP:
13863                 printf("function not implemented\n");
13864                 break;
13865         default:
13866                 printf("programming error: (%s)\n", strerror(-ret));
13867         }
13868 }
13869
13870 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13871         .f = cmd_set_vf_mac_addr_parsed,
13872         .data = NULL,
13873         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13874         .tokens = {
13875                 (void *)&cmd_set_vf_mac_addr_set,
13876                 (void *)&cmd_set_vf_mac_addr_vf,
13877                 (void *)&cmd_set_vf_mac_addr_mac,
13878                 (void *)&cmd_set_vf_mac_addr_addr,
13879                 (void *)&cmd_set_vf_mac_addr_port_id,
13880                 (void *)&cmd_set_vf_mac_addr_vf_id,
13881                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13882                 NULL,
13883         },
13884 };
13885
13886 /* MACsec configuration */
13887
13888 /* Common result structure for MACsec offload enable */
13889 struct cmd_macsec_offload_on_result {
13890         cmdline_fixed_string_t set;
13891         cmdline_fixed_string_t macsec;
13892         cmdline_fixed_string_t offload;
13893         portid_t port_id;
13894         cmdline_fixed_string_t on;
13895         cmdline_fixed_string_t encrypt;
13896         cmdline_fixed_string_t en_on_off;
13897         cmdline_fixed_string_t replay_protect;
13898         cmdline_fixed_string_t rp_on_off;
13899 };
13900
13901 /* Common CLI fields for MACsec offload disable */
13902 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13903         TOKEN_STRING_INITIALIZER
13904                 (struct cmd_macsec_offload_on_result,
13905                  set, "set");
13906 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13907         TOKEN_STRING_INITIALIZER
13908                 (struct cmd_macsec_offload_on_result,
13909                  macsec, "macsec");
13910 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13911         TOKEN_STRING_INITIALIZER
13912                 (struct cmd_macsec_offload_on_result,
13913                  offload, "offload");
13914 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13915         TOKEN_NUM_INITIALIZER
13916                 (struct cmd_macsec_offload_on_result,
13917                  port_id, UINT16);
13918 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13919         TOKEN_STRING_INITIALIZER
13920                 (struct cmd_macsec_offload_on_result,
13921                  on, "on");
13922 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13923         TOKEN_STRING_INITIALIZER
13924                 (struct cmd_macsec_offload_on_result,
13925                  encrypt, "encrypt");
13926 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13927         TOKEN_STRING_INITIALIZER
13928                 (struct cmd_macsec_offload_on_result,
13929                  en_on_off, "on#off");
13930 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13931         TOKEN_STRING_INITIALIZER
13932                 (struct cmd_macsec_offload_on_result,
13933                  replay_protect, "replay-protect");
13934 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13935         TOKEN_STRING_INITIALIZER
13936                 (struct cmd_macsec_offload_on_result,
13937                  rp_on_off, "on#off");
13938
13939 static void
13940 cmd_set_macsec_offload_on_parsed(
13941         void *parsed_result,
13942         __attribute__((unused)) struct cmdline *cl,
13943         __attribute__((unused)) void *data)
13944 {
13945         struct cmd_macsec_offload_on_result *res = parsed_result;
13946         int ret = -ENOTSUP;
13947         portid_t port_id = res->port_id;
13948         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13949         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13950         struct rte_eth_dev_info dev_info;
13951
13952         if (port_id_is_invalid(port_id, ENABLED_WARN))
13953                 return;
13954         if (!port_is_stopped(port_id)) {
13955                 printf("Please stop port %d first\n", port_id);
13956                 return;
13957         }
13958
13959         rte_eth_dev_info_get(port_id, &dev_info);
13960         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13961 #ifdef RTE_LIBRTE_IXGBE_PMD
13962                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13963 #endif
13964         }
13965         RTE_SET_USED(en);
13966         RTE_SET_USED(rp);
13967
13968         switch (ret) {
13969         case 0:
13970                 ports[port_id].dev_conf.txmode.offloads |=
13971                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13972                 cmd_reconfig_device_queue(port_id, 1, 1);
13973                 break;
13974         case -ENODEV:
13975                 printf("invalid port_id %d\n", port_id);
13976                 break;
13977         case -ENOTSUP:
13978                 printf("not supported on port %d\n", port_id);
13979                 break;
13980         default:
13981                 printf("programming error: (%s)\n", strerror(-ret));
13982         }
13983 }
13984
13985 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13986         .f = cmd_set_macsec_offload_on_parsed,
13987         .data = NULL,
13988         .help_str = "set macsec offload <port_id> on "
13989                 "encrypt on|off replay-protect on|off",
13990         .tokens = {
13991                 (void *)&cmd_macsec_offload_on_set,
13992                 (void *)&cmd_macsec_offload_on_macsec,
13993                 (void *)&cmd_macsec_offload_on_offload,
13994                 (void *)&cmd_macsec_offload_on_port_id,
13995                 (void *)&cmd_macsec_offload_on_on,
13996                 (void *)&cmd_macsec_offload_on_encrypt,
13997                 (void *)&cmd_macsec_offload_on_en_on_off,
13998                 (void *)&cmd_macsec_offload_on_replay_protect,
13999                 (void *)&cmd_macsec_offload_on_rp_on_off,
14000                 NULL,
14001         },
14002 };
14003
14004 /* Common result structure for MACsec offload disable */
14005 struct cmd_macsec_offload_off_result {
14006         cmdline_fixed_string_t set;
14007         cmdline_fixed_string_t macsec;
14008         cmdline_fixed_string_t offload;
14009         portid_t port_id;
14010         cmdline_fixed_string_t off;
14011 };
14012
14013 /* Common CLI fields for MACsec offload disable */
14014 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14015         TOKEN_STRING_INITIALIZER
14016                 (struct cmd_macsec_offload_off_result,
14017                  set, "set");
14018 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14019         TOKEN_STRING_INITIALIZER
14020                 (struct cmd_macsec_offload_off_result,
14021                  macsec, "macsec");
14022 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14023         TOKEN_STRING_INITIALIZER
14024                 (struct cmd_macsec_offload_off_result,
14025                  offload, "offload");
14026 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14027         TOKEN_NUM_INITIALIZER
14028                 (struct cmd_macsec_offload_off_result,
14029                  port_id, UINT16);
14030 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14031         TOKEN_STRING_INITIALIZER
14032                 (struct cmd_macsec_offload_off_result,
14033                  off, "off");
14034
14035 static void
14036 cmd_set_macsec_offload_off_parsed(
14037         void *parsed_result,
14038         __attribute__((unused)) struct cmdline *cl,
14039         __attribute__((unused)) void *data)
14040 {
14041         struct cmd_macsec_offload_off_result *res = parsed_result;
14042         int ret = -ENOTSUP;
14043         struct rte_eth_dev_info dev_info;
14044         portid_t port_id = res->port_id;
14045
14046         if (port_id_is_invalid(port_id, ENABLED_WARN))
14047                 return;
14048         if (!port_is_stopped(port_id)) {
14049                 printf("Please stop port %d first\n", port_id);
14050                 return;
14051         }
14052
14053         rte_eth_dev_info_get(port_id, &dev_info);
14054         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14055 #ifdef RTE_LIBRTE_IXGBE_PMD
14056                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14057 #endif
14058         }
14059         switch (ret) {
14060         case 0:
14061                 ports[port_id].dev_conf.txmode.offloads &=
14062                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14063                 cmd_reconfig_device_queue(port_id, 1, 1);
14064                 break;
14065         case -ENODEV:
14066                 printf("invalid port_id %d\n", port_id);
14067                 break;
14068         case -ENOTSUP:
14069                 printf("not supported on port %d\n", port_id);
14070                 break;
14071         default:
14072                 printf("programming error: (%s)\n", strerror(-ret));
14073         }
14074 }
14075
14076 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14077         .f = cmd_set_macsec_offload_off_parsed,
14078         .data = NULL,
14079         .help_str = "set macsec offload <port_id> off",
14080         .tokens = {
14081                 (void *)&cmd_macsec_offload_off_set,
14082                 (void *)&cmd_macsec_offload_off_macsec,
14083                 (void *)&cmd_macsec_offload_off_offload,
14084                 (void *)&cmd_macsec_offload_off_port_id,
14085                 (void *)&cmd_macsec_offload_off_off,
14086                 NULL,
14087         },
14088 };
14089
14090 /* Common result structure for MACsec secure connection configure */
14091 struct cmd_macsec_sc_result {
14092         cmdline_fixed_string_t set;
14093         cmdline_fixed_string_t macsec;
14094         cmdline_fixed_string_t sc;
14095         cmdline_fixed_string_t tx_rx;
14096         portid_t port_id;
14097         struct ether_addr mac;
14098         uint16_t pi;
14099 };
14100
14101 /* Common CLI fields for MACsec secure connection configure */
14102 cmdline_parse_token_string_t cmd_macsec_sc_set =
14103         TOKEN_STRING_INITIALIZER
14104                 (struct cmd_macsec_sc_result,
14105                  set, "set");
14106 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14107         TOKEN_STRING_INITIALIZER
14108                 (struct cmd_macsec_sc_result,
14109                  macsec, "macsec");
14110 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14111         TOKEN_STRING_INITIALIZER
14112                 (struct cmd_macsec_sc_result,
14113                  sc, "sc");
14114 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14115         TOKEN_STRING_INITIALIZER
14116                 (struct cmd_macsec_sc_result,
14117                  tx_rx, "tx#rx");
14118 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14119         TOKEN_NUM_INITIALIZER
14120                 (struct cmd_macsec_sc_result,
14121                  port_id, UINT16);
14122 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14123         TOKEN_ETHERADDR_INITIALIZER
14124                 (struct cmd_macsec_sc_result,
14125                  mac);
14126 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14127         TOKEN_NUM_INITIALIZER
14128                 (struct cmd_macsec_sc_result,
14129                  pi, UINT16);
14130
14131 static void
14132 cmd_set_macsec_sc_parsed(
14133         void *parsed_result,
14134         __attribute__((unused)) struct cmdline *cl,
14135         __attribute__((unused)) void *data)
14136 {
14137         struct cmd_macsec_sc_result *res = parsed_result;
14138         int ret = -ENOTSUP;
14139         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14140
14141 #ifdef RTE_LIBRTE_IXGBE_PMD
14142         ret = is_tx ?
14143                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14144                                 res->mac.addr_bytes) :
14145                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14146                                 res->mac.addr_bytes, res->pi);
14147 #endif
14148         RTE_SET_USED(is_tx);
14149
14150         switch (ret) {
14151         case 0:
14152                 break;
14153         case -ENODEV:
14154                 printf("invalid port_id %d\n", res->port_id);
14155                 break;
14156         case -ENOTSUP:
14157                 printf("not supported on port %d\n", res->port_id);
14158                 break;
14159         default:
14160                 printf("programming error: (%s)\n", strerror(-ret));
14161         }
14162 }
14163
14164 cmdline_parse_inst_t cmd_set_macsec_sc = {
14165         .f = cmd_set_macsec_sc_parsed,
14166         .data = NULL,
14167         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14168         .tokens = {
14169                 (void *)&cmd_macsec_sc_set,
14170                 (void *)&cmd_macsec_sc_macsec,
14171                 (void *)&cmd_macsec_sc_sc,
14172                 (void *)&cmd_macsec_sc_tx_rx,
14173                 (void *)&cmd_macsec_sc_port_id,
14174                 (void *)&cmd_macsec_sc_mac,
14175                 (void *)&cmd_macsec_sc_pi,
14176                 NULL,
14177         },
14178 };
14179
14180 /* Common result structure for MACsec secure connection configure */
14181 struct cmd_macsec_sa_result {
14182         cmdline_fixed_string_t set;
14183         cmdline_fixed_string_t macsec;
14184         cmdline_fixed_string_t sa;
14185         cmdline_fixed_string_t tx_rx;
14186         portid_t port_id;
14187         uint8_t idx;
14188         uint8_t an;
14189         uint32_t pn;
14190         cmdline_fixed_string_t key;
14191 };
14192
14193 /* Common CLI fields for MACsec secure connection configure */
14194 cmdline_parse_token_string_t cmd_macsec_sa_set =
14195         TOKEN_STRING_INITIALIZER
14196                 (struct cmd_macsec_sa_result,
14197                  set, "set");
14198 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14199         TOKEN_STRING_INITIALIZER
14200                 (struct cmd_macsec_sa_result,
14201                  macsec, "macsec");
14202 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14203         TOKEN_STRING_INITIALIZER
14204                 (struct cmd_macsec_sa_result,
14205                  sa, "sa");
14206 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14207         TOKEN_STRING_INITIALIZER
14208                 (struct cmd_macsec_sa_result,
14209                  tx_rx, "tx#rx");
14210 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14211         TOKEN_NUM_INITIALIZER
14212                 (struct cmd_macsec_sa_result,
14213                  port_id, UINT16);
14214 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14215         TOKEN_NUM_INITIALIZER
14216                 (struct cmd_macsec_sa_result,
14217                  idx, UINT8);
14218 cmdline_parse_token_num_t cmd_macsec_sa_an =
14219         TOKEN_NUM_INITIALIZER
14220                 (struct cmd_macsec_sa_result,
14221                  an, UINT8);
14222 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14223         TOKEN_NUM_INITIALIZER
14224                 (struct cmd_macsec_sa_result,
14225                  pn, UINT32);
14226 cmdline_parse_token_string_t cmd_macsec_sa_key =
14227         TOKEN_STRING_INITIALIZER
14228                 (struct cmd_macsec_sa_result,
14229                  key, NULL);
14230
14231 static void
14232 cmd_set_macsec_sa_parsed(
14233         void *parsed_result,
14234         __attribute__((unused)) struct cmdline *cl,
14235         __attribute__((unused)) void *data)
14236 {
14237         struct cmd_macsec_sa_result *res = parsed_result;
14238         int ret = -ENOTSUP;
14239         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14240         uint8_t key[16] = { 0 };
14241         uint8_t xdgt0;
14242         uint8_t xdgt1;
14243         int key_len;
14244         int i;
14245
14246         key_len = strlen(res->key) / 2;
14247         if (key_len > 16)
14248                 key_len = 16;
14249
14250         for (i = 0; i < key_len; i++) {
14251                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14252                 if (xdgt0 == 0xFF)
14253                         return;
14254                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14255                 if (xdgt1 == 0xFF)
14256                         return;
14257                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14258         }
14259
14260 #ifdef RTE_LIBRTE_IXGBE_PMD
14261         ret = is_tx ?
14262                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14263                         res->idx, res->an, res->pn, key) :
14264                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14265                         res->idx, res->an, res->pn, key);
14266 #endif
14267         RTE_SET_USED(is_tx);
14268         RTE_SET_USED(key);
14269
14270         switch (ret) {
14271         case 0:
14272                 break;
14273         case -EINVAL:
14274                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14275                 break;
14276         case -ENODEV:
14277                 printf("invalid port_id %d\n", res->port_id);
14278                 break;
14279         case -ENOTSUP:
14280                 printf("not supported on port %d\n", res->port_id);
14281                 break;
14282         default:
14283                 printf("programming error: (%s)\n", strerror(-ret));
14284         }
14285 }
14286
14287 cmdline_parse_inst_t cmd_set_macsec_sa = {
14288         .f = cmd_set_macsec_sa_parsed,
14289         .data = NULL,
14290         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14291         .tokens = {
14292                 (void *)&cmd_macsec_sa_set,
14293                 (void *)&cmd_macsec_sa_macsec,
14294                 (void *)&cmd_macsec_sa_sa,
14295                 (void *)&cmd_macsec_sa_tx_rx,
14296                 (void *)&cmd_macsec_sa_port_id,
14297                 (void *)&cmd_macsec_sa_idx,
14298                 (void *)&cmd_macsec_sa_an,
14299                 (void *)&cmd_macsec_sa_pn,
14300                 (void *)&cmd_macsec_sa_key,
14301                 NULL,
14302         },
14303 };
14304
14305 /* VF unicast promiscuous mode configuration */
14306
14307 /* Common result structure for VF unicast promiscuous mode */
14308 struct cmd_vf_promisc_result {
14309         cmdline_fixed_string_t set;
14310         cmdline_fixed_string_t vf;
14311         cmdline_fixed_string_t promisc;
14312         portid_t port_id;
14313         uint32_t vf_id;
14314         cmdline_fixed_string_t on_off;
14315 };
14316
14317 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14318 cmdline_parse_token_string_t cmd_vf_promisc_set =
14319         TOKEN_STRING_INITIALIZER
14320                 (struct cmd_vf_promisc_result,
14321                  set, "set");
14322 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14323         TOKEN_STRING_INITIALIZER
14324                 (struct cmd_vf_promisc_result,
14325                  vf, "vf");
14326 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14327         TOKEN_STRING_INITIALIZER
14328                 (struct cmd_vf_promisc_result,
14329                  promisc, "promisc");
14330 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14331         TOKEN_NUM_INITIALIZER
14332                 (struct cmd_vf_promisc_result,
14333                  port_id, UINT16);
14334 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14335         TOKEN_NUM_INITIALIZER
14336                 (struct cmd_vf_promisc_result,
14337                  vf_id, UINT32);
14338 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14339         TOKEN_STRING_INITIALIZER
14340                 (struct cmd_vf_promisc_result,
14341                  on_off, "on#off");
14342
14343 static void
14344 cmd_set_vf_promisc_parsed(
14345         void *parsed_result,
14346         __attribute__((unused)) struct cmdline *cl,
14347         __attribute__((unused)) void *data)
14348 {
14349         struct cmd_vf_promisc_result *res = parsed_result;
14350         int ret = -ENOTSUP;
14351
14352         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14353
14354         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14355                 return;
14356
14357 #ifdef RTE_LIBRTE_I40E_PMD
14358         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14359                                                   res->vf_id, is_on);
14360 #endif
14361
14362         switch (ret) {
14363         case 0:
14364                 break;
14365         case -EINVAL:
14366                 printf("invalid vf_id %d\n", res->vf_id);
14367                 break;
14368         case -ENODEV:
14369                 printf("invalid port_id %d\n", res->port_id);
14370                 break;
14371         case -ENOTSUP:
14372                 printf("function not implemented\n");
14373                 break;
14374         default:
14375                 printf("programming error: (%s)\n", strerror(-ret));
14376         }
14377 }
14378
14379 cmdline_parse_inst_t cmd_set_vf_promisc = {
14380         .f = cmd_set_vf_promisc_parsed,
14381         .data = NULL,
14382         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14383                 "Set unicast promiscuous mode for a VF from the PF",
14384         .tokens = {
14385                 (void *)&cmd_vf_promisc_set,
14386                 (void *)&cmd_vf_promisc_vf,
14387                 (void *)&cmd_vf_promisc_promisc,
14388                 (void *)&cmd_vf_promisc_port_id,
14389                 (void *)&cmd_vf_promisc_vf_id,
14390                 (void *)&cmd_vf_promisc_on_off,
14391                 NULL,
14392         },
14393 };
14394
14395 /* VF multicast promiscuous mode configuration */
14396
14397 /* Common result structure for VF multicast promiscuous mode */
14398 struct cmd_vf_allmulti_result {
14399         cmdline_fixed_string_t set;
14400         cmdline_fixed_string_t vf;
14401         cmdline_fixed_string_t allmulti;
14402         portid_t port_id;
14403         uint32_t vf_id;
14404         cmdline_fixed_string_t on_off;
14405 };
14406
14407 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14408 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14409         TOKEN_STRING_INITIALIZER
14410                 (struct cmd_vf_allmulti_result,
14411                  set, "set");
14412 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14413         TOKEN_STRING_INITIALIZER
14414                 (struct cmd_vf_allmulti_result,
14415                  vf, "vf");
14416 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14417         TOKEN_STRING_INITIALIZER
14418                 (struct cmd_vf_allmulti_result,
14419                  allmulti, "allmulti");
14420 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14421         TOKEN_NUM_INITIALIZER
14422                 (struct cmd_vf_allmulti_result,
14423                  port_id, UINT16);
14424 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14425         TOKEN_NUM_INITIALIZER
14426                 (struct cmd_vf_allmulti_result,
14427                  vf_id, UINT32);
14428 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14429         TOKEN_STRING_INITIALIZER
14430                 (struct cmd_vf_allmulti_result,
14431                  on_off, "on#off");
14432
14433 static void
14434 cmd_set_vf_allmulti_parsed(
14435         void *parsed_result,
14436         __attribute__((unused)) struct cmdline *cl,
14437         __attribute__((unused)) void *data)
14438 {
14439         struct cmd_vf_allmulti_result *res = parsed_result;
14440         int ret = -ENOTSUP;
14441
14442         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14443
14444         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14445                 return;
14446
14447 #ifdef RTE_LIBRTE_I40E_PMD
14448         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14449                                                     res->vf_id, is_on);
14450 #endif
14451
14452         switch (ret) {
14453         case 0:
14454                 break;
14455         case -EINVAL:
14456                 printf("invalid vf_id %d\n", res->vf_id);
14457                 break;
14458         case -ENODEV:
14459                 printf("invalid port_id %d\n", res->port_id);
14460                 break;
14461         case -ENOTSUP:
14462                 printf("function not implemented\n");
14463                 break;
14464         default:
14465                 printf("programming error: (%s)\n", strerror(-ret));
14466         }
14467 }
14468
14469 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14470         .f = cmd_set_vf_allmulti_parsed,
14471         .data = NULL,
14472         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14473                 "Set multicast promiscuous mode for a VF from the PF",
14474         .tokens = {
14475                 (void *)&cmd_vf_allmulti_set,
14476                 (void *)&cmd_vf_allmulti_vf,
14477                 (void *)&cmd_vf_allmulti_allmulti,
14478                 (void *)&cmd_vf_allmulti_port_id,
14479                 (void *)&cmd_vf_allmulti_vf_id,
14480                 (void *)&cmd_vf_allmulti_on_off,
14481                 NULL,
14482         },
14483 };
14484
14485 /* vf broadcast mode configuration */
14486
14487 /* Common result structure for vf broadcast */
14488 struct cmd_set_vf_broadcast_result {
14489         cmdline_fixed_string_t set;
14490         cmdline_fixed_string_t vf;
14491         cmdline_fixed_string_t broadcast;
14492         portid_t port_id;
14493         uint16_t vf_id;
14494         cmdline_fixed_string_t on_off;
14495 };
14496
14497 /* Common CLI fields for vf broadcast enable disable */
14498 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14499         TOKEN_STRING_INITIALIZER
14500                 (struct cmd_set_vf_broadcast_result,
14501                  set, "set");
14502 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14503         TOKEN_STRING_INITIALIZER
14504                 (struct cmd_set_vf_broadcast_result,
14505                  vf, "vf");
14506 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14507         TOKEN_STRING_INITIALIZER
14508                 (struct cmd_set_vf_broadcast_result,
14509                  broadcast, "broadcast");
14510 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14511         TOKEN_NUM_INITIALIZER
14512                 (struct cmd_set_vf_broadcast_result,
14513                  port_id, UINT16);
14514 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14515         TOKEN_NUM_INITIALIZER
14516                 (struct cmd_set_vf_broadcast_result,
14517                  vf_id, UINT16);
14518 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14519         TOKEN_STRING_INITIALIZER
14520                 (struct cmd_set_vf_broadcast_result,
14521                  on_off, "on#off");
14522
14523 static void
14524 cmd_set_vf_broadcast_parsed(
14525         void *parsed_result,
14526         __attribute__((unused)) struct cmdline *cl,
14527         __attribute__((unused)) void *data)
14528 {
14529         struct cmd_set_vf_broadcast_result *res = parsed_result;
14530         int ret = -ENOTSUP;
14531
14532         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14533
14534         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14535                 return;
14536
14537 #ifdef RTE_LIBRTE_I40E_PMD
14538         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14539                                             res->vf_id, is_on);
14540 #endif
14541
14542         switch (ret) {
14543         case 0:
14544                 break;
14545         case -EINVAL:
14546                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14547                 break;
14548         case -ENODEV:
14549                 printf("invalid port_id %d\n", res->port_id);
14550                 break;
14551         case -ENOTSUP:
14552                 printf("function not implemented\n");
14553                 break;
14554         default:
14555                 printf("programming error: (%s)\n", strerror(-ret));
14556         }
14557 }
14558
14559 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14560         .f = cmd_set_vf_broadcast_parsed,
14561         .data = NULL,
14562         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14563         .tokens = {
14564                 (void *)&cmd_set_vf_broadcast_set,
14565                 (void *)&cmd_set_vf_broadcast_vf,
14566                 (void *)&cmd_set_vf_broadcast_broadcast,
14567                 (void *)&cmd_set_vf_broadcast_port_id,
14568                 (void *)&cmd_set_vf_broadcast_vf_id,
14569                 (void *)&cmd_set_vf_broadcast_on_off,
14570                 NULL,
14571         },
14572 };
14573
14574 /* vf vlan tag configuration */
14575
14576 /* Common result structure for vf vlan tag */
14577 struct cmd_set_vf_vlan_tag_result {
14578         cmdline_fixed_string_t set;
14579         cmdline_fixed_string_t vf;
14580         cmdline_fixed_string_t vlan;
14581         cmdline_fixed_string_t tag;
14582         portid_t port_id;
14583         uint16_t vf_id;
14584         cmdline_fixed_string_t on_off;
14585 };
14586
14587 /* Common CLI fields for vf vlan tag enable disable */
14588 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14589         TOKEN_STRING_INITIALIZER
14590                 (struct cmd_set_vf_vlan_tag_result,
14591                  set, "set");
14592 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14593         TOKEN_STRING_INITIALIZER
14594                 (struct cmd_set_vf_vlan_tag_result,
14595                  vf, "vf");
14596 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14597         TOKEN_STRING_INITIALIZER
14598                 (struct cmd_set_vf_vlan_tag_result,
14599                  vlan, "vlan");
14600 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14601         TOKEN_STRING_INITIALIZER
14602                 (struct cmd_set_vf_vlan_tag_result,
14603                  tag, "tag");
14604 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14605         TOKEN_NUM_INITIALIZER
14606                 (struct cmd_set_vf_vlan_tag_result,
14607                  port_id, UINT16);
14608 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14609         TOKEN_NUM_INITIALIZER
14610                 (struct cmd_set_vf_vlan_tag_result,
14611                  vf_id, UINT16);
14612 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14613         TOKEN_STRING_INITIALIZER
14614                 (struct cmd_set_vf_vlan_tag_result,
14615                  on_off, "on#off");
14616
14617 static void
14618 cmd_set_vf_vlan_tag_parsed(
14619         void *parsed_result,
14620         __attribute__((unused)) struct cmdline *cl,
14621         __attribute__((unused)) void *data)
14622 {
14623         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14624         int ret = -ENOTSUP;
14625
14626         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14627
14628         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14629                 return;
14630
14631 #ifdef RTE_LIBRTE_I40E_PMD
14632         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14633                                            res->vf_id, is_on);
14634 #endif
14635
14636         switch (ret) {
14637         case 0:
14638                 break;
14639         case -EINVAL:
14640                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14641                 break;
14642         case -ENODEV:
14643                 printf("invalid port_id %d\n", res->port_id);
14644                 break;
14645         case -ENOTSUP:
14646                 printf("function not implemented\n");
14647                 break;
14648         default:
14649                 printf("programming error: (%s)\n", strerror(-ret));
14650         }
14651 }
14652
14653 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14654         .f = cmd_set_vf_vlan_tag_parsed,
14655         .data = NULL,
14656         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14657         .tokens = {
14658                 (void *)&cmd_set_vf_vlan_tag_set,
14659                 (void *)&cmd_set_vf_vlan_tag_vf,
14660                 (void *)&cmd_set_vf_vlan_tag_vlan,
14661                 (void *)&cmd_set_vf_vlan_tag_tag,
14662                 (void *)&cmd_set_vf_vlan_tag_port_id,
14663                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14664                 (void *)&cmd_set_vf_vlan_tag_on_off,
14665                 NULL,
14666         },
14667 };
14668
14669 /* Common definition of VF and TC TX bandwidth configuration */
14670 struct cmd_vf_tc_bw_result {
14671         cmdline_fixed_string_t set;
14672         cmdline_fixed_string_t vf;
14673         cmdline_fixed_string_t tc;
14674         cmdline_fixed_string_t tx;
14675         cmdline_fixed_string_t min_bw;
14676         cmdline_fixed_string_t max_bw;
14677         cmdline_fixed_string_t strict_link_prio;
14678         portid_t port_id;
14679         uint16_t vf_id;
14680         uint8_t tc_no;
14681         uint32_t bw;
14682         cmdline_fixed_string_t bw_list;
14683         uint8_t tc_map;
14684 };
14685
14686 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14687         TOKEN_STRING_INITIALIZER
14688                 (struct cmd_vf_tc_bw_result,
14689                  set, "set");
14690 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14691         TOKEN_STRING_INITIALIZER
14692                 (struct cmd_vf_tc_bw_result,
14693                  vf, "vf");
14694 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14695         TOKEN_STRING_INITIALIZER
14696                 (struct cmd_vf_tc_bw_result,
14697                  tc, "tc");
14698 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14699         TOKEN_STRING_INITIALIZER
14700                 (struct cmd_vf_tc_bw_result,
14701                  tx, "tx");
14702 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14703         TOKEN_STRING_INITIALIZER
14704                 (struct cmd_vf_tc_bw_result,
14705                  strict_link_prio, "strict-link-priority");
14706 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14707         TOKEN_STRING_INITIALIZER
14708                 (struct cmd_vf_tc_bw_result,
14709                  min_bw, "min-bandwidth");
14710 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14711         TOKEN_STRING_INITIALIZER
14712                 (struct cmd_vf_tc_bw_result,
14713                  max_bw, "max-bandwidth");
14714 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14715         TOKEN_NUM_INITIALIZER
14716                 (struct cmd_vf_tc_bw_result,
14717                  port_id, UINT16);
14718 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14719         TOKEN_NUM_INITIALIZER
14720                 (struct cmd_vf_tc_bw_result,
14721                  vf_id, UINT16);
14722 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14723         TOKEN_NUM_INITIALIZER
14724                 (struct cmd_vf_tc_bw_result,
14725                  tc_no, UINT8);
14726 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14727         TOKEN_NUM_INITIALIZER
14728                 (struct cmd_vf_tc_bw_result,
14729                  bw, UINT32);
14730 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14731         TOKEN_STRING_INITIALIZER
14732                 (struct cmd_vf_tc_bw_result,
14733                  bw_list, NULL);
14734 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14735         TOKEN_NUM_INITIALIZER
14736                 (struct cmd_vf_tc_bw_result,
14737                  tc_map, UINT8);
14738
14739 /* VF max bandwidth setting */
14740 static void
14741 cmd_vf_max_bw_parsed(
14742         void *parsed_result,
14743         __attribute__((unused)) struct cmdline *cl,
14744         __attribute__((unused)) void *data)
14745 {
14746         struct cmd_vf_tc_bw_result *res = parsed_result;
14747         int ret = -ENOTSUP;
14748
14749         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14750                 return;
14751
14752 #ifdef RTE_LIBRTE_I40E_PMD
14753         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14754                                          res->vf_id, res->bw);
14755 #endif
14756
14757         switch (ret) {
14758         case 0:
14759                 break;
14760         case -EINVAL:
14761                 printf("invalid vf_id %d or bandwidth %d\n",
14762                        res->vf_id, res->bw);
14763                 break;
14764         case -ENODEV:
14765                 printf("invalid port_id %d\n", res->port_id);
14766                 break;
14767         case -ENOTSUP:
14768                 printf("function not implemented\n");
14769                 break;
14770         default:
14771                 printf("programming error: (%s)\n", strerror(-ret));
14772         }
14773 }
14774
14775 cmdline_parse_inst_t cmd_vf_max_bw = {
14776         .f = cmd_vf_max_bw_parsed,
14777         .data = NULL,
14778         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14779         .tokens = {
14780                 (void *)&cmd_vf_tc_bw_set,
14781                 (void *)&cmd_vf_tc_bw_vf,
14782                 (void *)&cmd_vf_tc_bw_tx,
14783                 (void *)&cmd_vf_tc_bw_max_bw,
14784                 (void *)&cmd_vf_tc_bw_port_id,
14785                 (void *)&cmd_vf_tc_bw_vf_id,
14786                 (void *)&cmd_vf_tc_bw_bw,
14787                 NULL,
14788         },
14789 };
14790
14791 static int
14792 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14793                            uint8_t *tc_num,
14794                            char *str)
14795 {
14796         uint32_t size;
14797         const char *p, *p0 = str;
14798         char s[256];
14799         char *end;
14800         char *str_fld[16];
14801         uint16_t i;
14802         int ret;
14803
14804         p = strchr(p0, '(');
14805         if (p == NULL) {
14806                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14807                 return -1;
14808         }
14809         p++;
14810         p0 = strchr(p, ')');
14811         if (p0 == NULL) {
14812                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14813                 return -1;
14814         }
14815         size = p0 - p;
14816         if (size >= sizeof(s)) {
14817                 printf("The string size exceeds the internal buffer size\n");
14818                 return -1;
14819         }
14820         snprintf(s, sizeof(s), "%.*s", size, p);
14821         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14822         if (ret <= 0) {
14823                 printf("Failed to get the bandwidth list. ");
14824                 return -1;
14825         }
14826         *tc_num = ret;
14827         for (i = 0; i < ret; i++)
14828                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14829
14830         return 0;
14831 }
14832
14833 /* TC min bandwidth setting */
14834 static void
14835 cmd_vf_tc_min_bw_parsed(
14836         void *parsed_result,
14837         __attribute__((unused)) struct cmdline *cl,
14838         __attribute__((unused)) void *data)
14839 {
14840         struct cmd_vf_tc_bw_result *res = parsed_result;
14841         uint8_t tc_num;
14842         uint8_t bw[16];
14843         int ret = -ENOTSUP;
14844
14845         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14846                 return;
14847
14848         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14849         if (ret)
14850                 return;
14851
14852 #ifdef RTE_LIBRTE_I40E_PMD
14853         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14854                                               tc_num, bw);
14855 #endif
14856
14857         switch (ret) {
14858         case 0:
14859                 break;
14860         case -EINVAL:
14861                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14862                 break;
14863         case -ENODEV:
14864                 printf("invalid port_id %d\n", res->port_id);
14865                 break;
14866         case -ENOTSUP:
14867                 printf("function not implemented\n");
14868                 break;
14869         default:
14870                 printf("programming error: (%s)\n", strerror(-ret));
14871         }
14872 }
14873
14874 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14875         .f = cmd_vf_tc_min_bw_parsed,
14876         .data = NULL,
14877         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14878                     " <bw1, bw2, ...>",
14879         .tokens = {
14880                 (void *)&cmd_vf_tc_bw_set,
14881                 (void *)&cmd_vf_tc_bw_vf,
14882                 (void *)&cmd_vf_tc_bw_tc,
14883                 (void *)&cmd_vf_tc_bw_tx,
14884                 (void *)&cmd_vf_tc_bw_min_bw,
14885                 (void *)&cmd_vf_tc_bw_port_id,
14886                 (void *)&cmd_vf_tc_bw_vf_id,
14887                 (void *)&cmd_vf_tc_bw_bw_list,
14888                 NULL,
14889         },
14890 };
14891
14892 static void
14893 cmd_tc_min_bw_parsed(
14894         void *parsed_result,
14895         __attribute__((unused)) struct cmdline *cl,
14896         __attribute__((unused)) void *data)
14897 {
14898         struct cmd_vf_tc_bw_result *res = parsed_result;
14899         struct rte_port *port;
14900         uint8_t tc_num;
14901         uint8_t bw[16];
14902         int ret = -ENOTSUP;
14903
14904         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14905                 return;
14906
14907         port = &ports[res->port_id];
14908         /** Check if the port is not started **/
14909         if (port->port_status != RTE_PORT_STOPPED) {
14910                 printf("Please stop port %d first\n", res->port_id);
14911                 return;
14912         }
14913
14914         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14915         if (ret)
14916                 return;
14917
14918 #ifdef RTE_LIBRTE_IXGBE_PMD
14919         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14920 #endif
14921
14922         switch (ret) {
14923         case 0:
14924                 break;
14925         case -EINVAL:
14926                 printf("invalid bandwidth\n");
14927                 break;
14928         case -ENODEV:
14929                 printf("invalid port_id %d\n", res->port_id);
14930                 break;
14931         case -ENOTSUP:
14932                 printf("function not implemented\n");
14933                 break;
14934         default:
14935                 printf("programming error: (%s)\n", strerror(-ret));
14936         }
14937 }
14938
14939 cmdline_parse_inst_t cmd_tc_min_bw = {
14940         .f = cmd_tc_min_bw_parsed,
14941         .data = NULL,
14942         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14943         .tokens = {
14944                 (void *)&cmd_vf_tc_bw_set,
14945                 (void *)&cmd_vf_tc_bw_tc,
14946                 (void *)&cmd_vf_tc_bw_tx,
14947                 (void *)&cmd_vf_tc_bw_min_bw,
14948                 (void *)&cmd_vf_tc_bw_port_id,
14949                 (void *)&cmd_vf_tc_bw_bw_list,
14950                 NULL,
14951         },
14952 };
14953
14954 /* TC max bandwidth setting */
14955 static void
14956 cmd_vf_tc_max_bw_parsed(
14957         void *parsed_result,
14958         __attribute__((unused)) struct cmdline *cl,
14959         __attribute__((unused)) void *data)
14960 {
14961         struct cmd_vf_tc_bw_result *res = parsed_result;
14962         int ret = -ENOTSUP;
14963
14964         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14965                 return;
14966
14967 #ifdef RTE_LIBRTE_I40E_PMD
14968         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14969                                             res->tc_no, res->bw);
14970 #endif
14971
14972         switch (ret) {
14973         case 0:
14974                 break;
14975         case -EINVAL:
14976                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14977                        res->vf_id, res->tc_no, res->bw);
14978                 break;
14979         case -ENODEV:
14980                 printf("invalid port_id %d\n", res->port_id);
14981                 break;
14982         case -ENOTSUP:
14983                 printf("function not implemented\n");
14984                 break;
14985         default:
14986                 printf("programming error: (%s)\n", strerror(-ret));
14987         }
14988 }
14989
14990 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14991         .f = cmd_vf_tc_max_bw_parsed,
14992         .data = NULL,
14993         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14994                     " <bandwidth>",
14995         .tokens = {
14996                 (void *)&cmd_vf_tc_bw_set,
14997                 (void *)&cmd_vf_tc_bw_vf,
14998                 (void *)&cmd_vf_tc_bw_tc,
14999                 (void *)&cmd_vf_tc_bw_tx,
15000                 (void *)&cmd_vf_tc_bw_max_bw,
15001                 (void *)&cmd_vf_tc_bw_port_id,
15002                 (void *)&cmd_vf_tc_bw_vf_id,
15003                 (void *)&cmd_vf_tc_bw_tc_no,
15004                 (void *)&cmd_vf_tc_bw_bw,
15005                 NULL,
15006         },
15007 };
15008
15009
15010 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15011
15012 /* *** Set Port default Traffic Management Hierarchy *** */
15013 struct cmd_set_port_tm_hierarchy_default_result {
15014         cmdline_fixed_string_t set;
15015         cmdline_fixed_string_t port;
15016         cmdline_fixed_string_t tm;
15017         cmdline_fixed_string_t hierarchy;
15018         cmdline_fixed_string_t def;
15019         portid_t port_id;
15020 };
15021
15022 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15023         TOKEN_STRING_INITIALIZER(
15024                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15025 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15026         TOKEN_STRING_INITIALIZER(
15027                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15028 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15029         TOKEN_STRING_INITIALIZER(
15030                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15031 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15032         TOKEN_STRING_INITIALIZER(
15033                 struct cmd_set_port_tm_hierarchy_default_result,
15034                         hierarchy, "hierarchy");
15035 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15036         TOKEN_STRING_INITIALIZER(
15037                 struct cmd_set_port_tm_hierarchy_default_result,
15038                         def, "default");
15039 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15040         TOKEN_NUM_INITIALIZER(
15041                 struct cmd_set_port_tm_hierarchy_default_result,
15042                         port_id, UINT16);
15043
15044 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15045         __attribute__((unused)) struct cmdline *cl,
15046         __attribute__((unused)) void *data)
15047 {
15048         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15049         struct rte_port *p;
15050         portid_t port_id = res->port_id;
15051
15052         if (port_id_is_invalid(port_id, ENABLED_WARN))
15053                 return;
15054
15055         p = &ports[port_id];
15056
15057         /* Forward mode: tm */
15058         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15059                 printf("  softnicfwd mode not enabled(error)\n");
15060                 return;
15061         }
15062
15063         /* Set the default tm hierarchy */
15064         p->softport.default_tm_hierarchy_enable = 1;
15065 }
15066
15067 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15068         .f = cmd_set_port_tm_hierarchy_default_parsed,
15069         .data = NULL,
15070         .help_str = "set port tm hierarchy default <port_id>",
15071         .tokens = {
15072                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15073                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15074                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15075                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15076                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15077                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15078                 NULL,
15079         },
15080 };
15081 #endif
15082
15083 /** Set VXLAN encapsulation details */
15084 struct cmd_set_vxlan_result {
15085         cmdline_fixed_string_t set;
15086         cmdline_fixed_string_t vxlan;
15087         cmdline_fixed_string_t pos_token;
15088         cmdline_fixed_string_t ip_version;
15089         uint32_t vlan_present:1;
15090         uint32_t vni;
15091         uint16_t udp_src;
15092         uint16_t udp_dst;
15093         cmdline_ipaddr_t ip_src;
15094         cmdline_ipaddr_t ip_dst;
15095         uint16_t tci;
15096         uint8_t tos;
15097         uint8_t ttl;
15098         struct ether_addr eth_src;
15099         struct ether_addr eth_dst;
15100 };
15101
15102 cmdline_parse_token_string_t cmd_set_vxlan_set =
15103         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15104 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15105         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15106 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15107         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15108                                  "vxlan-tos-ttl");
15109 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15110         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15111                                  "vxlan-with-vlan");
15112 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15113         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15114                                  "ip-version");
15115 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15116         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15117                                  "ipv4#ipv6");
15118 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15119         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15120                                  "vni");
15121 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15122         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15123 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15124         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15125                                  "udp-src");
15126 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15127         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15128 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15129         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15130                                  "udp-dst");
15131 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15132         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15133 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15134         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15135                                  "ip-tos");
15136 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15137         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15138 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15139         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15140                                  "ip-ttl");
15141 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15142         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15143 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15144         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15145                                  "ip-src");
15146 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15147         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15148 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15149         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15150                                  "ip-dst");
15151 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15152         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15153 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15154         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15155                                  "vlan-tci");
15156 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15157         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15158 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15159         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15160                                  "eth-src");
15161 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15162         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15163 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15164         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15165                                  "eth-dst");
15166 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15167         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15168
15169 static void cmd_set_vxlan_parsed(void *parsed_result,
15170         __attribute__((unused)) struct cmdline *cl,
15171         __attribute__((unused)) void *data)
15172 {
15173         struct cmd_set_vxlan_result *res = parsed_result;
15174         union {
15175                 uint32_t vxlan_id;
15176                 uint8_t vni[4];
15177         } id = {
15178                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15179         };
15180
15181         vxlan_encap_conf.select_tos_ttl = 0;
15182         if (strcmp(res->vxlan, "vxlan") == 0)
15183                 vxlan_encap_conf.select_vlan = 0;
15184         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15185                 vxlan_encap_conf.select_vlan = 1;
15186         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15187                 vxlan_encap_conf.select_vlan = 0;
15188                 vxlan_encap_conf.select_tos_ttl = 1;
15189         }
15190         if (strcmp(res->ip_version, "ipv4") == 0)
15191                 vxlan_encap_conf.select_ipv4 = 1;
15192         else if (strcmp(res->ip_version, "ipv6") == 0)
15193                 vxlan_encap_conf.select_ipv4 = 0;
15194         else
15195                 return;
15196         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15197         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15198         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15199         vxlan_encap_conf.ip_tos = res->tos;
15200         vxlan_encap_conf.ip_ttl = res->ttl;
15201         if (vxlan_encap_conf.select_ipv4) {
15202                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15203                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15204         } else {
15205                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15206                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15207         }
15208         if (vxlan_encap_conf.select_vlan)
15209                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15210         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15211                    ETHER_ADDR_LEN);
15212         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15213                    ETHER_ADDR_LEN);
15214 }
15215
15216 cmdline_parse_inst_t cmd_set_vxlan = {
15217         .f = cmd_set_vxlan_parsed,
15218         .data = NULL,
15219         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15220                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15221                 " eth-src <eth-src> eth-dst <eth-dst>",
15222         .tokens = {
15223                 (void *)&cmd_set_vxlan_set,
15224                 (void *)&cmd_set_vxlan_vxlan,
15225                 (void *)&cmd_set_vxlan_ip_version,
15226                 (void *)&cmd_set_vxlan_ip_version_value,
15227                 (void *)&cmd_set_vxlan_vni,
15228                 (void *)&cmd_set_vxlan_vni_value,
15229                 (void *)&cmd_set_vxlan_udp_src,
15230                 (void *)&cmd_set_vxlan_udp_src_value,
15231                 (void *)&cmd_set_vxlan_udp_dst,
15232                 (void *)&cmd_set_vxlan_udp_dst_value,
15233                 (void *)&cmd_set_vxlan_ip_src,
15234                 (void *)&cmd_set_vxlan_ip_src_value,
15235                 (void *)&cmd_set_vxlan_ip_dst,
15236                 (void *)&cmd_set_vxlan_ip_dst_value,
15237                 (void *)&cmd_set_vxlan_eth_src,
15238                 (void *)&cmd_set_vxlan_eth_src_value,
15239                 (void *)&cmd_set_vxlan_eth_dst,
15240                 (void *)&cmd_set_vxlan_eth_dst_value,
15241                 NULL,
15242         },
15243 };
15244
15245 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15246         .f = cmd_set_vxlan_parsed,
15247         .data = NULL,
15248         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15249                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15250                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15251                 " eth-dst <eth-dst>",
15252         .tokens = {
15253                 (void *)&cmd_set_vxlan_set,
15254                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15255                 (void *)&cmd_set_vxlan_ip_version,
15256                 (void *)&cmd_set_vxlan_ip_version_value,
15257                 (void *)&cmd_set_vxlan_vni,
15258                 (void *)&cmd_set_vxlan_vni_value,
15259                 (void *)&cmd_set_vxlan_udp_src,
15260                 (void *)&cmd_set_vxlan_udp_src_value,
15261                 (void *)&cmd_set_vxlan_udp_dst,
15262                 (void *)&cmd_set_vxlan_udp_dst_value,
15263                 (void *)&cmd_set_vxlan_ip_tos,
15264                 (void *)&cmd_set_vxlan_ip_tos_value,
15265                 (void *)&cmd_set_vxlan_ip_ttl,
15266                 (void *)&cmd_set_vxlan_ip_ttl_value,
15267                 (void *)&cmd_set_vxlan_ip_src,
15268                 (void *)&cmd_set_vxlan_ip_src_value,
15269                 (void *)&cmd_set_vxlan_ip_dst,
15270                 (void *)&cmd_set_vxlan_ip_dst_value,
15271                 (void *)&cmd_set_vxlan_eth_src,
15272                 (void *)&cmd_set_vxlan_eth_src_value,
15273                 (void *)&cmd_set_vxlan_eth_dst,
15274                 (void *)&cmd_set_vxlan_eth_dst_value,
15275                 NULL,
15276         },
15277 };
15278
15279 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15280         .f = cmd_set_vxlan_parsed,
15281         .data = NULL,
15282         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15283                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15284                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15285                 " <eth-dst>",
15286         .tokens = {
15287                 (void *)&cmd_set_vxlan_set,
15288                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15289                 (void *)&cmd_set_vxlan_ip_version,
15290                 (void *)&cmd_set_vxlan_ip_version_value,
15291                 (void *)&cmd_set_vxlan_vni,
15292                 (void *)&cmd_set_vxlan_vni_value,
15293                 (void *)&cmd_set_vxlan_udp_src,
15294                 (void *)&cmd_set_vxlan_udp_src_value,
15295                 (void *)&cmd_set_vxlan_udp_dst,
15296                 (void *)&cmd_set_vxlan_udp_dst_value,
15297                 (void *)&cmd_set_vxlan_ip_src,
15298                 (void *)&cmd_set_vxlan_ip_src_value,
15299                 (void *)&cmd_set_vxlan_ip_dst,
15300                 (void *)&cmd_set_vxlan_ip_dst_value,
15301                 (void *)&cmd_set_vxlan_vlan,
15302                 (void *)&cmd_set_vxlan_vlan_value,
15303                 (void *)&cmd_set_vxlan_eth_src,
15304                 (void *)&cmd_set_vxlan_eth_src_value,
15305                 (void *)&cmd_set_vxlan_eth_dst,
15306                 (void *)&cmd_set_vxlan_eth_dst_value,
15307                 NULL,
15308         },
15309 };
15310
15311 /** Set NVGRE encapsulation details */
15312 struct cmd_set_nvgre_result {
15313         cmdline_fixed_string_t set;
15314         cmdline_fixed_string_t nvgre;
15315         cmdline_fixed_string_t pos_token;
15316         cmdline_fixed_string_t ip_version;
15317         uint32_t tni;
15318         cmdline_ipaddr_t ip_src;
15319         cmdline_ipaddr_t ip_dst;
15320         uint16_t tci;
15321         struct ether_addr eth_src;
15322         struct ether_addr eth_dst;
15323 };
15324
15325 cmdline_parse_token_string_t cmd_set_nvgre_set =
15326         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15327 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15328         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15329 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15330         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15331                                  "nvgre-with-vlan");
15332 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15333         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15334                                  "ip-version");
15335 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15336         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15337                                  "ipv4#ipv6");
15338 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15339         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15340                                  "tni");
15341 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15342         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15343 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15344         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15345                                  "ip-src");
15346 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15347         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15348 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15349         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15350                                  "ip-dst");
15351 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15352         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15353 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15354         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15355                                  "vlan-tci");
15356 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15357         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15358 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15359         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15360                                  "eth-src");
15361 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15362         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15363 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15364         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15365                                  "eth-dst");
15366 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15367         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15368
15369 static void cmd_set_nvgre_parsed(void *parsed_result,
15370         __attribute__((unused)) struct cmdline *cl,
15371         __attribute__((unused)) void *data)
15372 {
15373         struct cmd_set_nvgre_result *res = parsed_result;
15374         union {
15375                 uint32_t nvgre_tni;
15376                 uint8_t tni[4];
15377         } id = {
15378                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15379         };
15380
15381         if (strcmp(res->nvgre, "nvgre") == 0)
15382                 nvgre_encap_conf.select_vlan = 0;
15383         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15384                 nvgre_encap_conf.select_vlan = 1;
15385         if (strcmp(res->ip_version, "ipv4") == 0)
15386                 nvgre_encap_conf.select_ipv4 = 1;
15387         else if (strcmp(res->ip_version, "ipv6") == 0)
15388                 nvgre_encap_conf.select_ipv4 = 0;
15389         else
15390                 return;
15391         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15392         if (nvgre_encap_conf.select_ipv4) {
15393                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15394                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15395         } else {
15396                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15397                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15398         }
15399         if (nvgre_encap_conf.select_vlan)
15400                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15401         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15402                    ETHER_ADDR_LEN);
15403         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15404                    ETHER_ADDR_LEN);
15405 }
15406
15407 cmdline_parse_inst_t cmd_set_nvgre = {
15408         .f = cmd_set_nvgre_parsed,
15409         .data = NULL,
15410         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15411                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15412                 " eth-dst <eth-dst>",
15413         .tokens = {
15414                 (void *)&cmd_set_nvgre_set,
15415                 (void *)&cmd_set_nvgre_nvgre,
15416                 (void *)&cmd_set_nvgre_ip_version,
15417                 (void *)&cmd_set_nvgre_ip_version_value,
15418                 (void *)&cmd_set_nvgre_tni,
15419                 (void *)&cmd_set_nvgre_tni_value,
15420                 (void *)&cmd_set_nvgre_ip_src,
15421                 (void *)&cmd_set_nvgre_ip_src_value,
15422                 (void *)&cmd_set_nvgre_ip_dst,
15423                 (void *)&cmd_set_nvgre_ip_dst_value,
15424                 (void *)&cmd_set_nvgre_eth_src,
15425                 (void *)&cmd_set_nvgre_eth_src_value,
15426                 (void *)&cmd_set_nvgre_eth_dst,
15427                 (void *)&cmd_set_nvgre_eth_dst_value,
15428                 NULL,
15429         },
15430 };
15431
15432 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15433         .f = cmd_set_nvgre_parsed,
15434         .data = NULL,
15435         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15436                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15437                 " eth-src <eth-src> eth-dst <eth-dst>",
15438         .tokens = {
15439                 (void *)&cmd_set_nvgre_set,
15440                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15441                 (void *)&cmd_set_nvgre_ip_version,
15442                 (void *)&cmd_set_nvgre_ip_version_value,
15443                 (void *)&cmd_set_nvgre_tni,
15444                 (void *)&cmd_set_nvgre_tni_value,
15445                 (void *)&cmd_set_nvgre_ip_src,
15446                 (void *)&cmd_set_nvgre_ip_src_value,
15447                 (void *)&cmd_set_nvgre_ip_dst,
15448                 (void *)&cmd_set_nvgre_ip_dst_value,
15449                 (void *)&cmd_set_nvgre_vlan,
15450                 (void *)&cmd_set_nvgre_vlan_value,
15451                 (void *)&cmd_set_nvgre_eth_src,
15452                 (void *)&cmd_set_nvgre_eth_src_value,
15453                 (void *)&cmd_set_nvgre_eth_dst,
15454                 (void *)&cmd_set_nvgre_eth_dst_value,
15455                 NULL,
15456         },
15457 };
15458
15459 /** Set L2 encapsulation details */
15460 struct cmd_set_l2_encap_result {
15461         cmdline_fixed_string_t set;
15462         cmdline_fixed_string_t l2_encap;
15463         cmdline_fixed_string_t pos_token;
15464         cmdline_fixed_string_t ip_version;
15465         uint32_t vlan_present:1;
15466         uint16_t tci;
15467         struct ether_addr eth_src;
15468         struct ether_addr eth_dst;
15469 };
15470
15471 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15472         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15473 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15474         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15475 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15476         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15477                                  "l2_encap-with-vlan");
15478 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15479         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15480                                  "ip-version");
15481 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15482         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15483                                  "ipv4#ipv6");
15484 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15485         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15486                                  "vlan-tci");
15487 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15488         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15489 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15490         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15491                                  "eth-src");
15492 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15493         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15494 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15495         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15496                                  "eth-dst");
15497 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15498         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15499
15500 static void cmd_set_l2_encap_parsed(void *parsed_result,
15501         __attribute__((unused)) struct cmdline *cl,
15502         __attribute__((unused)) void *data)
15503 {
15504         struct cmd_set_l2_encap_result *res = parsed_result;
15505
15506         if (strcmp(res->l2_encap, "l2_encap") == 0)
15507                 l2_encap_conf.select_vlan = 0;
15508         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15509                 l2_encap_conf.select_vlan = 1;
15510         if (strcmp(res->ip_version, "ipv4") == 0)
15511                 l2_encap_conf.select_ipv4 = 1;
15512         else if (strcmp(res->ip_version, "ipv6") == 0)
15513                 l2_encap_conf.select_ipv4 = 0;
15514         else
15515                 return;
15516         if (l2_encap_conf.select_vlan)
15517                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15518         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15519                    ETHER_ADDR_LEN);
15520         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15521                    ETHER_ADDR_LEN);
15522 }
15523
15524 cmdline_parse_inst_t cmd_set_l2_encap = {
15525         .f = cmd_set_l2_encap_parsed,
15526         .data = NULL,
15527         .help_str = "set l2_encap ip-version ipv4|ipv6"
15528                 " eth-src <eth-src> eth-dst <eth-dst>",
15529         .tokens = {
15530                 (void *)&cmd_set_l2_encap_set,
15531                 (void *)&cmd_set_l2_encap_l2_encap,
15532                 (void *)&cmd_set_l2_encap_ip_version,
15533                 (void *)&cmd_set_l2_encap_ip_version_value,
15534                 (void *)&cmd_set_l2_encap_eth_src,
15535                 (void *)&cmd_set_l2_encap_eth_src_value,
15536                 (void *)&cmd_set_l2_encap_eth_dst,
15537                 (void *)&cmd_set_l2_encap_eth_dst_value,
15538                 NULL,
15539         },
15540 };
15541
15542 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15543         .f = cmd_set_l2_encap_parsed,
15544         .data = NULL,
15545         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15546                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15547         .tokens = {
15548                 (void *)&cmd_set_l2_encap_set,
15549                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15550                 (void *)&cmd_set_l2_encap_ip_version,
15551                 (void *)&cmd_set_l2_encap_ip_version_value,
15552                 (void *)&cmd_set_l2_encap_vlan,
15553                 (void *)&cmd_set_l2_encap_vlan_value,
15554                 (void *)&cmd_set_l2_encap_eth_src,
15555                 (void *)&cmd_set_l2_encap_eth_src_value,
15556                 (void *)&cmd_set_l2_encap_eth_dst,
15557                 (void *)&cmd_set_l2_encap_eth_dst_value,
15558                 NULL,
15559         },
15560 };
15561
15562 /** Set L2 decapsulation details */
15563 struct cmd_set_l2_decap_result {
15564         cmdline_fixed_string_t set;
15565         cmdline_fixed_string_t l2_decap;
15566         cmdline_fixed_string_t pos_token;
15567         uint32_t vlan_present:1;
15568 };
15569
15570 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15571         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15572 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15573         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15574                                  "l2_decap");
15575 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15576         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15577                                  "l2_decap-with-vlan");
15578
15579 static void cmd_set_l2_decap_parsed(void *parsed_result,
15580         __attribute__((unused)) struct cmdline *cl,
15581         __attribute__((unused)) void *data)
15582 {
15583         struct cmd_set_l2_decap_result *res = parsed_result;
15584
15585         if (strcmp(res->l2_decap, "l2_decap") == 0)
15586                 l2_decap_conf.select_vlan = 0;
15587         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15588                 l2_decap_conf.select_vlan = 1;
15589 }
15590
15591 cmdline_parse_inst_t cmd_set_l2_decap = {
15592         .f = cmd_set_l2_decap_parsed,
15593         .data = NULL,
15594         .help_str = "set l2_decap",
15595         .tokens = {
15596                 (void *)&cmd_set_l2_decap_set,
15597                 (void *)&cmd_set_l2_decap_l2_decap,
15598                 NULL,
15599         },
15600 };
15601
15602 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15603         .f = cmd_set_l2_decap_parsed,
15604         .data = NULL,
15605         .help_str = "set l2_decap-with-vlan",
15606         .tokens = {
15607                 (void *)&cmd_set_l2_decap_set,
15608                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15609                 NULL,
15610         },
15611 };
15612
15613 /** Set MPLSoGRE encapsulation details */
15614 struct cmd_set_mplsogre_encap_result {
15615         cmdline_fixed_string_t set;
15616         cmdline_fixed_string_t mplsogre;
15617         cmdline_fixed_string_t pos_token;
15618         cmdline_fixed_string_t ip_version;
15619         uint32_t vlan_present:1;
15620         uint32_t label;
15621         cmdline_ipaddr_t ip_src;
15622         cmdline_ipaddr_t ip_dst;
15623         uint16_t tci;
15624         struct ether_addr eth_src;
15625         struct ether_addr eth_dst;
15626 };
15627
15628 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15629         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15630                                  "set");
15631 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15632         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15633                                  "mplsogre_encap");
15634 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15635         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15636                                  mplsogre, "mplsogre_encap-with-vlan");
15637 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15638         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15639                                  pos_token, "ip-version");
15640 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15641         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15642                                  ip_version, "ipv4#ipv6");
15643 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15644         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15645                                  pos_token, "label");
15646 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15647         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15648                               UINT32);
15649 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15650         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15651                                  pos_token, "ip-src");
15652 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15653         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15654 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15655         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15656                                  pos_token, "ip-dst");
15657 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15658         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15659 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15660         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15661                                  pos_token, "vlan-tci");
15662 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15663         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15664                               UINT16);
15665 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15666         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15667                                  pos_token, "eth-src");
15668 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15669         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15670                                     eth_src);
15671 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15672         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15673                                  pos_token, "eth-dst");
15674 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15675         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15676                                     eth_dst);
15677
15678 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15679         __attribute__((unused)) struct cmdline *cl,
15680         __attribute__((unused)) void *data)
15681 {
15682         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15683         union {
15684                 uint32_t mplsogre_label;
15685                 uint8_t label[4];
15686         } id = {
15687                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15688         };
15689
15690         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15691                 mplsogre_encap_conf.select_vlan = 0;
15692         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15693                 mplsogre_encap_conf.select_vlan = 1;
15694         if (strcmp(res->ip_version, "ipv4") == 0)
15695                 mplsogre_encap_conf.select_ipv4 = 1;
15696         else if (strcmp(res->ip_version, "ipv6") == 0)
15697                 mplsogre_encap_conf.select_ipv4 = 0;
15698         else
15699                 return;
15700         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15701         if (mplsogre_encap_conf.select_ipv4) {
15702                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15703                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15704         } else {
15705                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15706                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15707         }
15708         if (mplsogre_encap_conf.select_vlan)
15709                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15710         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15711                    ETHER_ADDR_LEN);
15712         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15713                    ETHER_ADDR_LEN);
15714 }
15715
15716 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15717         .f = cmd_set_mplsogre_encap_parsed,
15718         .data = NULL,
15719         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15720                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15721                 " eth-dst <eth-dst>",
15722         .tokens = {
15723                 (void *)&cmd_set_mplsogre_encap_set,
15724                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15725                 (void *)&cmd_set_mplsogre_encap_ip_version,
15726                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15727                 (void *)&cmd_set_mplsogre_encap_label,
15728                 (void *)&cmd_set_mplsogre_encap_label_value,
15729                 (void *)&cmd_set_mplsogre_encap_ip_src,
15730                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15731                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15732                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15733                 (void *)&cmd_set_mplsogre_encap_eth_src,
15734                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15735                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15736                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15737                 NULL,
15738         },
15739 };
15740
15741 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15742         .f = cmd_set_mplsogre_encap_parsed,
15743         .data = NULL,
15744         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15745                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15746                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15747         .tokens = {
15748                 (void *)&cmd_set_mplsogre_encap_set,
15749                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15750                 (void *)&cmd_set_mplsogre_encap_ip_version,
15751                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15752                 (void *)&cmd_set_mplsogre_encap_label,
15753                 (void *)&cmd_set_mplsogre_encap_label_value,
15754                 (void *)&cmd_set_mplsogre_encap_ip_src,
15755                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15756                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15757                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15758                 (void *)&cmd_set_mplsogre_encap_vlan,
15759                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15760                 (void *)&cmd_set_mplsogre_encap_eth_src,
15761                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15762                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15763                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15764                 NULL,
15765         },
15766 };
15767
15768 /** Set MPLSoGRE decapsulation details */
15769 struct cmd_set_mplsogre_decap_result {
15770         cmdline_fixed_string_t set;
15771         cmdline_fixed_string_t mplsogre;
15772         cmdline_fixed_string_t pos_token;
15773         cmdline_fixed_string_t ip_version;
15774         uint32_t vlan_present:1;
15775 };
15776
15777 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15778         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15779                                  "set");
15780 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15781         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15782                                  "mplsogre_decap");
15783 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15784         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15785                                  mplsogre, "mplsogre_decap-with-vlan");
15786 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15787         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15788                                  pos_token, "ip-version");
15789 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15790         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15791                                  ip_version, "ipv4#ipv6");
15792
15793 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15794         __attribute__((unused)) struct cmdline *cl,
15795         __attribute__((unused)) void *data)
15796 {
15797         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15798
15799         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15800                 mplsogre_decap_conf.select_vlan = 0;
15801         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15802                 mplsogre_decap_conf.select_vlan = 1;
15803         if (strcmp(res->ip_version, "ipv4") == 0)
15804                 mplsogre_decap_conf.select_ipv4 = 1;
15805         else if (strcmp(res->ip_version, "ipv6") == 0)
15806                 mplsogre_decap_conf.select_ipv4 = 0;
15807 }
15808
15809 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15810         .f = cmd_set_mplsogre_decap_parsed,
15811         .data = NULL,
15812         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15813         .tokens = {
15814                 (void *)&cmd_set_mplsogre_decap_set,
15815                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15816                 (void *)&cmd_set_mplsogre_decap_ip_version,
15817                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15818                 NULL,
15819         },
15820 };
15821
15822 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15823         .f = cmd_set_mplsogre_decap_parsed,
15824         .data = NULL,
15825         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15826         .tokens = {
15827                 (void *)&cmd_set_mplsogre_decap_set,
15828                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15829                 (void *)&cmd_set_mplsogre_decap_ip_version,
15830                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15831                 NULL,
15832         },
15833 };
15834
15835 /** Set MPLSoUDP encapsulation details */
15836 struct cmd_set_mplsoudp_encap_result {
15837         cmdline_fixed_string_t set;
15838         cmdline_fixed_string_t mplsoudp;
15839         cmdline_fixed_string_t pos_token;
15840         cmdline_fixed_string_t ip_version;
15841         uint32_t vlan_present:1;
15842         uint32_t label;
15843         uint16_t udp_src;
15844         uint16_t udp_dst;
15845         cmdline_ipaddr_t ip_src;
15846         cmdline_ipaddr_t ip_dst;
15847         uint16_t tci;
15848         struct ether_addr eth_src;
15849         struct ether_addr eth_dst;
15850 };
15851
15852 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15853         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15854                                  "set");
15855 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15856         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15857                                  "mplsoudp_encap");
15858 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15859         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15860                                  mplsoudp, "mplsoudp_encap-with-vlan");
15861 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15862         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15863                                  pos_token, "ip-version");
15864 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15865         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15866                                  ip_version, "ipv4#ipv6");
15867 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15868         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15869                                  pos_token, "label");
15870 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15871         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15872                               UINT32);
15873 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15874         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15875                                  pos_token, "udp-src");
15876 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
15877         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
15878                               UINT16);
15879 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
15880         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15881                                  pos_token, "udp-dst");
15882 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
15883         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
15884                               UINT16);
15885 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
15886         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15887                                  pos_token, "ip-src");
15888 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
15889         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
15890 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
15891         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15892                                  pos_token, "ip-dst");
15893 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
15894         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
15895 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
15896         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15897                                  pos_token, "vlan-tci");
15898 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
15899         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
15900                               UINT16);
15901 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
15902         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15903                                  pos_token, "eth-src");
15904 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
15905         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15906                                     eth_src);
15907 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
15908         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15909                                  pos_token, "eth-dst");
15910 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
15911         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15912                                     eth_dst);
15913
15914 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
15915         __attribute__((unused)) struct cmdline *cl,
15916         __attribute__((unused)) void *data)
15917 {
15918         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
15919         union {
15920                 uint32_t mplsoudp_label;
15921                 uint8_t label[4];
15922         } id = {
15923                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
15924         };
15925
15926         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
15927                 mplsoudp_encap_conf.select_vlan = 0;
15928         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
15929                 mplsoudp_encap_conf.select_vlan = 1;
15930         if (strcmp(res->ip_version, "ipv4") == 0)
15931                 mplsoudp_encap_conf.select_ipv4 = 1;
15932         else if (strcmp(res->ip_version, "ipv6") == 0)
15933                 mplsoudp_encap_conf.select_ipv4 = 0;
15934         else
15935                 return;
15936         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
15937         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15938         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15939         if (mplsoudp_encap_conf.select_ipv4) {
15940                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
15941                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
15942         } else {
15943                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
15944                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
15945         }
15946         if (mplsoudp_encap_conf.select_vlan)
15947                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15948         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
15949                    ETHER_ADDR_LEN);
15950         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15951                    ETHER_ADDR_LEN);
15952 }
15953
15954 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
15955         .f = cmd_set_mplsoudp_encap_parsed,
15956         .data = NULL,
15957         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
15958                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
15959                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
15960         .tokens = {
15961                 (void *)&cmd_set_mplsoudp_encap_set,
15962                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
15963                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15964                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15965                 (void *)&cmd_set_mplsoudp_encap_label,
15966                 (void *)&cmd_set_mplsoudp_encap_label_value,
15967                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15968                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15969                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15970                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15971                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15972                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15973                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15974                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15975                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15976                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15977                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15978                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15979                 NULL,
15980         },
15981 };
15982
15983 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
15984         .f = cmd_set_mplsoudp_encap_parsed,
15985         .data = NULL,
15986         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
15987                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
15988                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15989                 " eth-src <eth-src> eth-dst <eth-dst>",
15990         .tokens = {
15991                 (void *)&cmd_set_mplsoudp_encap_set,
15992                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
15993                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15994                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15995                 (void *)&cmd_set_mplsoudp_encap_label,
15996                 (void *)&cmd_set_mplsoudp_encap_label_value,
15997                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15998                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15999                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16000                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16001                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16002                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16003                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16004                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16005                 (void *)&cmd_set_mplsoudp_encap_vlan,
16006                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16007                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16008                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16009                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16010                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16011                 NULL,
16012         },
16013 };
16014
16015 /** Set MPLSoUDP decapsulation details */
16016 struct cmd_set_mplsoudp_decap_result {
16017         cmdline_fixed_string_t set;
16018         cmdline_fixed_string_t mplsoudp;
16019         cmdline_fixed_string_t pos_token;
16020         cmdline_fixed_string_t ip_version;
16021         uint32_t vlan_present:1;
16022 };
16023
16024 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16025         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16026                                  "set");
16027 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16028         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16029                                  "mplsoudp_decap");
16030 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16031         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16032                                  mplsoudp, "mplsoudp_decap-with-vlan");
16033 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16034         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16035                                  pos_token, "ip-version");
16036 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16037         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16038                                  ip_version, "ipv4#ipv6");
16039
16040 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16041         __attribute__((unused)) struct cmdline *cl,
16042         __attribute__((unused)) void *data)
16043 {
16044         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16045
16046         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16047                 mplsoudp_decap_conf.select_vlan = 0;
16048         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16049                 mplsoudp_decap_conf.select_vlan = 1;
16050         if (strcmp(res->ip_version, "ipv4") == 0)
16051                 mplsoudp_decap_conf.select_ipv4 = 1;
16052         else if (strcmp(res->ip_version, "ipv6") == 0)
16053                 mplsoudp_decap_conf.select_ipv4 = 0;
16054 }
16055
16056 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16057         .f = cmd_set_mplsoudp_decap_parsed,
16058         .data = NULL,
16059         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16060         .tokens = {
16061                 (void *)&cmd_set_mplsoudp_decap_set,
16062                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16063                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16064                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16065                 NULL,
16066         },
16067 };
16068
16069 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16070         .f = cmd_set_mplsoudp_decap_parsed,
16071         .data = NULL,
16072         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16073         .tokens = {
16074                 (void *)&cmd_set_mplsoudp_decap_set,
16075                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16076                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16077                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16078                 NULL,
16079         },
16080 };
16081
16082 /* Strict link priority scheduling mode setting */
16083 static void
16084 cmd_strict_link_prio_parsed(
16085         void *parsed_result,
16086         __attribute__((unused)) struct cmdline *cl,
16087         __attribute__((unused)) void *data)
16088 {
16089         struct cmd_vf_tc_bw_result *res = parsed_result;
16090         int ret = -ENOTSUP;
16091
16092         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16093                 return;
16094
16095 #ifdef RTE_LIBRTE_I40E_PMD
16096         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16097 #endif
16098
16099         switch (ret) {
16100         case 0:
16101                 break;
16102         case -EINVAL:
16103                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16104                 break;
16105         case -ENODEV:
16106                 printf("invalid port_id %d\n", res->port_id);
16107                 break;
16108         case -ENOTSUP:
16109                 printf("function not implemented\n");
16110                 break;
16111         default:
16112                 printf("programming error: (%s)\n", strerror(-ret));
16113         }
16114 }
16115
16116 cmdline_parse_inst_t cmd_strict_link_prio = {
16117         .f = cmd_strict_link_prio_parsed,
16118         .data = NULL,
16119         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16120         .tokens = {
16121                 (void *)&cmd_vf_tc_bw_set,
16122                 (void *)&cmd_vf_tc_bw_tx,
16123                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16124                 (void *)&cmd_vf_tc_bw_port_id,
16125                 (void *)&cmd_vf_tc_bw_tc_map,
16126                 NULL,
16127         },
16128 };
16129
16130 /* Load dynamic device personalization*/
16131 struct cmd_ddp_add_result {
16132         cmdline_fixed_string_t ddp;
16133         cmdline_fixed_string_t add;
16134         portid_t port_id;
16135         char filepath[];
16136 };
16137
16138 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16139         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16140 cmdline_parse_token_string_t cmd_ddp_add_add =
16141         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16142 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16143         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16144 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16145         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16146
16147 static void
16148 cmd_ddp_add_parsed(
16149         void *parsed_result,
16150         __attribute__((unused)) struct cmdline *cl,
16151         __attribute__((unused)) void *data)
16152 {
16153         struct cmd_ddp_add_result *res = parsed_result;
16154         uint8_t *buff;
16155         uint32_t size;
16156         char *filepath;
16157         char *file_fld[2];
16158         int file_num;
16159         int ret = -ENOTSUP;
16160
16161         if (!all_ports_stopped()) {
16162                 printf("Please stop all ports first\n");
16163                 return;
16164         }
16165
16166         filepath = strdup(res->filepath);
16167         if (filepath == NULL) {
16168                 printf("Failed to allocate memory\n");
16169                 return;
16170         }
16171         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16172
16173         buff = open_file(file_fld[0], &size);
16174         if (!buff) {
16175                 free((void *)filepath);
16176                 return;
16177         }
16178
16179 #ifdef RTE_LIBRTE_I40E_PMD
16180         if (ret == -ENOTSUP)
16181                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16182                                                buff, size,
16183                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16184 #endif
16185
16186         if (ret == -EEXIST)
16187                 printf("Profile has already existed.\n");
16188         else if (ret < 0)
16189                 printf("Failed to load profile.\n");
16190         else if (file_num == 2)
16191                 save_file(file_fld[1], buff, size);
16192
16193         close_file(buff);
16194         free((void *)filepath);
16195 }
16196
16197 cmdline_parse_inst_t cmd_ddp_add = {
16198         .f = cmd_ddp_add_parsed,
16199         .data = NULL,
16200         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16201         .tokens = {
16202                 (void *)&cmd_ddp_add_ddp,
16203                 (void *)&cmd_ddp_add_add,
16204                 (void *)&cmd_ddp_add_port_id,
16205                 (void *)&cmd_ddp_add_filepath,
16206                 NULL,
16207         },
16208 };
16209
16210 /* Delete dynamic device personalization*/
16211 struct cmd_ddp_del_result {
16212         cmdline_fixed_string_t ddp;
16213         cmdline_fixed_string_t del;
16214         portid_t port_id;
16215         char filepath[];
16216 };
16217
16218 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16219         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16220 cmdline_parse_token_string_t cmd_ddp_del_del =
16221         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16222 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16223         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16224 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16225         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16226
16227 static void
16228 cmd_ddp_del_parsed(
16229         void *parsed_result,
16230         __attribute__((unused)) struct cmdline *cl,
16231         __attribute__((unused)) void *data)
16232 {
16233         struct cmd_ddp_del_result *res = parsed_result;
16234         uint8_t *buff;
16235         uint32_t size;
16236         int ret = -ENOTSUP;
16237
16238         if (!all_ports_stopped()) {
16239                 printf("Please stop all ports first\n");
16240                 return;
16241         }
16242
16243         buff = open_file(res->filepath, &size);
16244         if (!buff)
16245                 return;
16246
16247 #ifdef RTE_LIBRTE_I40E_PMD
16248         if (ret == -ENOTSUP)
16249                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16250                                                buff, size,
16251                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16252 #endif
16253
16254         if (ret == -EACCES)
16255                 printf("Profile does not exist.\n");
16256         else if (ret < 0)
16257                 printf("Failed to delete profile.\n");
16258
16259         close_file(buff);
16260 }
16261
16262 cmdline_parse_inst_t cmd_ddp_del = {
16263         .f = cmd_ddp_del_parsed,
16264         .data = NULL,
16265         .help_str = "ddp del <port_id> <backup_profile_path>",
16266         .tokens = {
16267                 (void *)&cmd_ddp_del_ddp,
16268                 (void *)&cmd_ddp_del_del,
16269                 (void *)&cmd_ddp_del_port_id,
16270                 (void *)&cmd_ddp_del_filepath,
16271                 NULL,
16272         },
16273 };
16274
16275 /* Get dynamic device personalization profile info */
16276 struct cmd_ddp_info_result {
16277         cmdline_fixed_string_t ddp;
16278         cmdline_fixed_string_t get;
16279         cmdline_fixed_string_t info;
16280         char filepath[];
16281 };
16282
16283 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16284         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16285 cmdline_parse_token_string_t cmd_ddp_info_get =
16286         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16287 cmdline_parse_token_string_t cmd_ddp_info_info =
16288         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16289 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16290         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16291
16292 static void
16293 cmd_ddp_info_parsed(
16294         void *parsed_result,
16295         __attribute__((unused)) struct cmdline *cl,
16296         __attribute__((unused)) void *data)
16297 {
16298         struct cmd_ddp_info_result *res = parsed_result;
16299         uint8_t *pkg;
16300         uint32_t pkg_size;
16301         int ret = -ENOTSUP;
16302 #ifdef RTE_LIBRTE_I40E_PMD
16303         uint32_t i, j, n;
16304         uint8_t *buff;
16305         uint32_t buff_size = 0;
16306         struct rte_pmd_i40e_profile_info info;
16307         uint32_t dev_num = 0;
16308         struct rte_pmd_i40e_ddp_device_id *devs;
16309         uint32_t proto_num = 0;
16310         struct rte_pmd_i40e_proto_info *proto = NULL;
16311         uint32_t pctype_num = 0;
16312         struct rte_pmd_i40e_ptype_info *pctype;
16313         uint32_t ptype_num = 0;
16314         struct rte_pmd_i40e_ptype_info *ptype;
16315         uint8_t proto_id;
16316
16317 #endif
16318
16319         pkg = open_file(res->filepath, &pkg_size);
16320         if (!pkg)
16321                 return;
16322
16323 #ifdef RTE_LIBRTE_I40E_PMD
16324         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16325                                 (uint8_t *)&info, sizeof(info),
16326                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16327         if (!ret) {
16328                 printf("Global Track id:       0x%x\n", info.track_id);
16329                 printf("Global Version:        %d.%d.%d.%d\n",
16330                         info.version.major,
16331                         info.version.minor,
16332                         info.version.update,
16333                         info.version.draft);
16334                 printf("Global Package name:   %s\n\n", info.name);
16335         }
16336
16337         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16338                                 (uint8_t *)&info, sizeof(info),
16339                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16340         if (!ret) {
16341                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16342                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16343                         info.version.major,
16344                         info.version.minor,
16345                         info.version.update,
16346                         info.version.draft);
16347                 printf("i40e Profile name:     %s\n\n", info.name);
16348         }
16349
16350         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16351                                 (uint8_t *)&buff_size, sizeof(buff_size),
16352                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16353         if (!ret && buff_size) {
16354                 buff = (uint8_t *)malloc(buff_size);
16355                 if (buff) {
16356                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16357                                                 buff, buff_size,
16358                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16359                         if (!ret)
16360                                 printf("Package Notes:\n%s\n\n", buff);
16361                         free(buff);
16362                 }
16363         }
16364
16365         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16366                                 (uint8_t *)&dev_num, sizeof(dev_num),
16367                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16368         if (!ret && dev_num) {
16369                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16370                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16371                 if (devs) {
16372                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16373                                                 (uint8_t *)devs, buff_size,
16374                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16375                         if (!ret) {
16376                                 printf("List of supported devices:\n");
16377                                 for (i = 0; i < dev_num; i++) {
16378                                         printf("  %04X:%04X %04X:%04X\n",
16379                                                 devs[i].vendor_dev_id >> 16,
16380                                                 devs[i].vendor_dev_id & 0xFFFF,
16381                                                 devs[i].sub_vendor_dev_id >> 16,
16382                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16383                                 }
16384                                 printf("\n");
16385                         }
16386                         free(devs);
16387                 }
16388         }
16389
16390         /* get information about protocols and packet types */
16391         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16392                 (uint8_t *)&proto_num, sizeof(proto_num),
16393                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16394         if (ret || !proto_num)
16395                 goto no_print_return;
16396
16397         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16398         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16399         if (!proto)
16400                 goto no_print_return;
16401
16402         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16403                                         buff_size,
16404                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16405         if (!ret) {
16406                 printf("List of used protocols:\n");
16407                 for (i = 0; i < proto_num; i++)
16408                         printf("  %2u: %s\n", proto[i].proto_id,
16409                                proto[i].name);
16410                 printf("\n");
16411         }
16412         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16413                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16414                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16415         if (ret || !pctype_num)
16416                 goto no_print_pctypes;
16417
16418         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16419         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16420         if (!pctype)
16421                 goto no_print_pctypes;
16422
16423         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16424                                         buff_size,
16425                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16426         if (ret) {
16427                 free(pctype);
16428                 goto no_print_pctypes;
16429         }
16430
16431         printf("List of defined packet classification types:\n");
16432         for (i = 0; i < pctype_num; i++) {
16433                 printf("  %2u:", pctype[i].ptype_id);
16434                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16435                         proto_id = pctype[i].protocols[j];
16436                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16437                                 for (n = 0; n < proto_num; n++) {
16438                                         if (proto[n].proto_id == proto_id) {
16439                                                 printf(" %s", proto[n].name);
16440                                                 break;
16441                                         }
16442                                 }
16443                         }
16444                 }
16445                 printf("\n");
16446         }
16447         printf("\n");
16448         free(pctype);
16449
16450 no_print_pctypes:
16451
16452         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16453                                         sizeof(ptype_num),
16454                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16455         if (ret || !ptype_num)
16456                 goto no_print_return;
16457
16458         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16459         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16460         if (!ptype)
16461                 goto no_print_return;
16462
16463         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16464                                         buff_size,
16465                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16466         if (ret) {
16467                 free(ptype);
16468                 goto no_print_return;
16469         }
16470         printf("List of defined packet types:\n");
16471         for (i = 0; i < ptype_num; i++) {
16472                 printf("  %2u:", ptype[i].ptype_id);
16473                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16474                         proto_id = ptype[i].protocols[j];
16475                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16476                                 for (n = 0; n < proto_num; n++) {
16477                                         if (proto[n].proto_id == proto_id) {
16478                                                 printf(" %s", proto[n].name);
16479                                                 break;
16480                                         }
16481                                 }
16482                         }
16483                 }
16484                 printf("\n");
16485         }
16486         free(ptype);
16487         printf("\n");
16488
16489         ret = 0;
16490 no_print_return:
16491         if (proto)
16492                 free(proto);
16493 #endif
16494         if (ret == -ENOTSUP)
16495                 printf("Function not supported in PMD driver\n");
16496         close_file(pkg);
16497 }
16498
16499 cmdline_parse_inst_t cmd_ddp_get_info = {
16500         .f = cmd_ddp_info_parsed,
16501         .data = NULL,
16502         .help_str = "ddp get info <profile_path>",
16503         .tokens = {
16504                 (void *)&cmd_ddp_info_ddp,
16505                 (void *)&cmd_ddp_info_get,
16506                 (void *)&cmd_ddp_info_info,
16507                 (void *)&cmd_ddp_info_filepath,
16508                 NULL,
16509         },
16510 };
16511
16512 /* Get dynamic device personalization profile info list*/
16513 #define PROFILE_INFO_SIZE 48
16514 #define MAX_PROFILE_NUM 16
16515
16516 struct cmd_ddp_get_list_result {
16517         cmdline_fixed_string_t ddp;
16518         cmdline_fixed_string_t get;
16519         cmdline_fixed_string_t list;
16520         portid_t port_id;
16521 };
16522
16523 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16524         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16525 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16526         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16527 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16528         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16529 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16530         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16531
16532 static void
16533 cmd_ddp_get_list_parsed(
16534         __attribute__((unused)) void *parsed_result,
16535         __attribute__((unused)) struct cmdline *cl,
16536         __attribute__((unused)) void *data)
16537 {
16538 #ifdef RTE_LIBRTE_I40E_PMD
16539         struct cmd_ddp_get_list_result *res = parsed_result;
16540         struct rte_pmd_i40e_profile_list *p_list;
16541         struct rte_pmd_i40e_profile_info *p_info;
16542         uint32_t p_num;
16543         uint32_t size;
16544         uint32_t i;
16545 #endif
16546         int ret = -ENOTSUP;
16547
16548 #ifdef RTE_LIBRTE_I40E_PMD
16549         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16550         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16551         if (!p_list)
16552                 printf("%s: Failed to malloc buffer\n", __func__);
16553
16554         if (ret == -ENOTSUP)
16555                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16556                                                 (uint8_t *)p_list, size);
16557
16558         if (!ret) {
16559                 p_num = p_list->p_count;
16560                 printf("Profile number is: %d\n\n", p_num);
16561
16562                 for (i = 0; i < p_num; i++) {
16563                         p_info = &p_list->p_info[i];
16564                         printf("Profile %d:\n", i);
16565                         printf("Track id:     0x%x\n", p_info->track_id);
16566                         printf("Version:      %d.%d.%d.%d\n",
16567                                p_info->version.major,
16568                                p_info->version.minor,
16569                                p_info->version.update,
16570                                p_info->version.draft);
16571                         printf("Profile name: %s\n\n", p_info->name);
16572                 }
16573         }
16574
16575         free(p_list);
16576 #endif
16577
16578         if (ret < 0)
16579                 printf("Failed to get ddp list\n");
16580 }
16581
16582 cmdline_parse_inst_t cmd_ddp_get_list = {
16583         .f = cmd_ddp_get_list_parsed,
16584         .data = NULL,
16585         .help_str = "ddp get list <port_id>",
16586         .tokens = {
16587                 (void *)&cmd_ddp_get_list_ddp,
16588                 (void *)&cmd_ddp_get_list_get,
16589                 (void *)&cmd_ddp_get_list_list,
16590                 (void *)&cmd_ddp_get_list_port_id,
16591                 NULL,
16592         },
16593 };
16594
16595 /* Configure input set */
16596 struct cmd_cfg_input_set_result {
16597         cmdline_fixed_string_t port;
16598         cmdline_fixed_string_t cfg;
16599         portid_t port_id;
16600         cmdline_fixed_string_t pctype;
16601         uint8_t pctype_id;
16602         cmdline_fixed_string_t inset_type;
16603         cmdline_fixed_string_t opt;
16604         cmdline_fixed_string_t field;
16605         uint8_t field_idx;
16606 };
16607
16608 static void
16609 cmd_cfg_input_set_parsed(
16610         __attribute__((unused)) void *parsed_result,
16611         __attribute__((unused)) struct cmdline *cl,
16612         __attribute__((unused)) void *data)
16613 {
16614 #ifdef RTE_LIBRTE_I40E_PMD
16615         struct cmd_cfg_input_set_result *res = parsed_result;
16616         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16617         struct rte_pmd_i40e_inset inset;
16618 #endif
16619         int ret = -ENOTSUP;
16620
16621         if (!all_ports_stopped()) {
16622                 printf("Please stop all ports first\n");
16623                 return;
16624         }
16625
16626 #ifdef RTE_LIBRTE_I40E_PMD
16627         if (!strcmp(res->inset_type, "hash_inset"))
16628                 inset_type = INSET_HASH;
16629         else if (!strcmp(res->inset_type, "fdir_inset"))
16630                 inset_type = INSET_FDIR;
16631         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16632                 inset_type = INSET_FDIR_FLX;
16633         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16634                                      &inset, inset_type);
16635         if (ret) {
16636                 printf("Failed to get input set.\n");
16637                 return;
16638         }
16639
16640         if (!strcmp(res->opt, "get")) {
16641                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16642                                                    res->field_idx);
16643                 if (ret)
16644                         printf("Field index %d is enabled.\n", res->field_idx);
16645                 else
16646                         printf("Field index %d is disabled.\n", res->field_idx);
16647                 return;
16648         } else if (!strcmp(res->opt, "set"))
16649                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16650                                                    res->field_idx);
16651         else if (!strcmp(res->opt, "clear"))
16652                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16653                                                      res->field_idx);
16654         if (ret) {
16655                 printf("Failed to configure input set field.\n");
16656                 return;
16657         }
16658
16659         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16660                                      &inset, inset_type);
16661         if (ret) {
16662                 printf("Failed to set input set.\n");
16663                 return;
16664         }
16665 #endif
16666
16667         if (ret == -ENOTSUP)
16668                 printf("Function not supported\n");
16669 }
16670
16671 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16672         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16673                                  port, "port");
16674 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16675         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16676                                  cfg, "config");
16677 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16678         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16679                               port_id, UINT16);
16680 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16681         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16682                                  pctype, "pctype");
16683 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16684         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16685                               pctype_id, UINT8);
16686 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16687         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16688                                  inset_type,
16689                                  "hash_inset#fdir_inset#fdir_flx_inset");
16690 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16691         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16692                                  opt, "get#set#clear");
16693 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16694         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16695                                  field, "field");
16696 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16697         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16698                               field_idx, UINT8);
16699
16700 cmdline_parse_inst_t cmd_cfg_input_set = {
16701         .f = cmd_cfg_input_set_parsed,
16702         .data = NULL,
16703         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16704                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16705         .tokens = {
16706                 (void *)&cmd_cfg_input_set_port,
16707                 (void *)&cmd_cfg_input_set_cfg,
16708                 (void *)&cmd_cfg_input_set_port_id,
16709                 (void *)&cmd_cfg_input_set_pctype,
16710                 (void *)&cmd_cfg_input_set_pctype_id,
16711                 (void *)&cmd_cfg_input_set_inset_type,
16712                 (void *)&cmd_cfg_input_set_opt,
16713                 (void *)&cmd_cfg_input_set_field,
16714                 (void *)&cmd_cfg_input_set_field_idx,
16715                 NULL,
16716         },
16717 };
16718
16719 /* Clear input set */
16720 struct cmd_clear_input_set_result {
16721         cmdline_fixed_string_t port;
16722         cmdline_fixed_string_t cfg;
16723         portid_t port_id;
16724         cmdline_fixed_string_t pctype;
16725         uint8_t pctype_id;
16726         cmdline_fixed_string_t inset_type;
16727         cmdline_fixed_string_t clear;
16728         cmdline_fixed_string_t all;
16729 };
16730
16731 static void
16732 cmd_clear_input_set_parsed(
16733         __attribute__((unused)) void *parsed_result,
16734         __attribute__((unused)) struct cmdline *cl,
16735         __attribute__((unused)) void *data)
16736 {
16737 #ifdef RTE_LIBRTE_I40E_PMD
16738         struct cmd_clear_input_set_result *res = parsed_result;
16739         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16740         struct rte_pmd_i40e_inset inset;
16741 #endif
16742         int ret = -ENOTSUP;
16743
16744         if (!all_ports_stopped()) {
16745                 printf("Please stop all ports first\n");
16746                 return;
16747         }
16748
16749 #ifdef RTE_LIBRTE_I40E_PMD
16750         if (!strcmp(res->inset_type, "hash_inset"))
16751                 inset_type = INSET_HASH;
16752         else if (!strcmp(res->inset_type, "fdir_inset"))
16753                 inset_type = INSET_FDIR;
16754         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16755                 inset_type = INSET_FDIR_FLX;
16756
16757         memset(&inset, 0, sizeof(inset));
16758
16759         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16760                                      &inset, inset_type);
16761         if (ret) {
16762                 printf("Failed to clear input set.\n");
16763                 return;
16764         }
16765
16766 #endif
16767
16768         if (ret == -ENOTSUP)
16769                 printf("Function not supported\n");
16770 }
16771
16772 cmdline_parse_token_string_t cmd_clear_input_set_port =
16773         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16774                                  port, "port");
16775 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16776         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16777                                  cfg, "config");
16778 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16779         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16780                               port_id, UINT16);
16781 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16782         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16783                                  pctype, "pctype");
16784 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16785         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16786                               pctype_id, UINT8);
16787 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16788         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16789                                  inset_type,
16790                                  "hash_inset#fdir_inset#fdir_flx_inset");
16791 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16792         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16793                                  clear, "clear");
16794 cmdline_parse_token_string_t cmd_clear_input_set_all =
16795         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16796                                  all, "all");
16797
16798 cmdline_parse_inst_t cmd_clear_input_set = {
16799         .f = cmd_clear_input_set_parsed,
16800         .data = NULL,
16801         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16802                     "fdir_inset|fdir_flx_inset clear all",
16803         .tokens = {
16804                 (void *)&cmd_clear_input_set_port,
16805                 (void *)&cmd_clear_input_set_cfg,
16806                 (void *)&cmd_clear_input_set_port_id,
16807                 (void *)&cmd_clear_input_set_pctype,
16808                 (void *)&cmd_clear_input_set_pctype_id,
16809                 (void *)&cmd_clear_input_set_inset_type,
16810                 (void *)&cmd_clear_input_set_clear,
16811                 (void *)&cmd_clear_input_set_all,
16812                 NULL,
16813         },
16814 };
16815
16816 /* show vf stats */
16817
16818 /* Common result structure for show vf stats */
16819 struct cmd_show_vf_stats_result {
16820         cmdline_fixed_string_t show;
16821         cmdline_fixed_string_t vf;
16822         cmdline_fixed_string_t stats;
16823         portid_t port_id;
16824         uint16_t vf_id;
16825 };
16826
16827 /* Common CLI fields show vf stats*/
16828 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16829         TOKEN_STRING_INITIALIZER
16830                 (struct cmd_show_vf_stats_result,
16831                  show, "show");
16832 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16833         TOKEN_STRING_INITIALIZER
16834                 (struct cmd_show_vf_stats_result,
16835                  vf, "vf");
16836 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16837         TOKEN_STRING_INITIALIZER
16838                 (struct cmd_show_vf_stats_result,
16839                  stats, "stats");
16840 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16841         TOKEN_NUM_INITIALIZER
16842                 (struct cmd_show_vf_stats_result,
16843                  port_id, UINT16);
16844 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16845         TOKEN_NUM_INITIALIZER
16846                 (struct cmd_show_vf_stats_result,
16847                  vf_id, UINT16);
16848
16849 static void
16850 cmd_show_vf_stats_parsed(
16851         void *parsed_result,
16852         __attribute__((unused)) struct cmdline *cl,
16853         __attribute__((unused)) void *data)
16854 {
16855         struct cmd_show_vf_stats_result *res = parsed_result;
16856         struct rte_eth_stats stats;
16857         int ret = -ENOTSUP;
16858         static const char *nic_stats_border = "########################";
16859
16860         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16861                 return;
16862
16863         memset(&stats, 0, sizeof(stats));
16864
16865 #ifdef RTE_LIBRTE_I40E_PMD
16866         if (ret == -ENOTSUP)
16867                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16868                                                 res->vf_id,
16869                                                 &stats);
16870 #endif
16871 #ifdef RTE_LIBRTE_BNXT_PMD
16872         if (ret == -ENOTSUP)
16873                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16874                                                 res->vf_id,
16875                                                 &stats);
16876 #endif
16877
16878         switch (ret) {
16879         case 0:
16880                 break;
16881         case -EINVAL:
16882                 printf("invalid vf_id %d\n", res->vf_id);
16883                 break;
16884         case -ENODEV:
16885                 printf("invalid port_id %d\n", res->port_id);
16886                 break;
16887         case -ENOTSUP:
16888                 printf("function not implemented\n");
16889                 break;
16890         default:
16891                 printf("programming error: (%s)\n", strerror(-ret));
16892         }
16893
16894         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
16895                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
16896
16897         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
16898                "%-"PRIu64"\n",
16899                stats.ipackets, stats.imissed, stats.ibytes);
16900         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
16901         printf("  RX-nombuf:  %-10"PRIu64"\n",
16902                stats.rx_nombuf);
16903         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
16904                "%-"PRIu64"\n",
16905                stats.opackets, stats.oerrors, stats.obytes);
16906
16907         printf("  %s############################%s\n",
16908                                nic_stats_border, nic_stats_border);
16909 }
16910
16911 cmdline_parse_inst_t cmd_show_vf_stats = {
16912         .f = cmd_show_vf_stats_parsed,
16913         .data = NULL,
16914         .help_str = "show vf stats <port_id> <vf_id>",
16915         .tokens = {
16916                 (void *)&cmd_show_vf_stats_show,
16917                 (void *)&cmd_show_vf_stats_vf,
16918                 (void *)&cmd_show_vf_stats_stats,
16919                 (void *)&cmd_show_vf_stats_port_id,
16920                 (void *)&cmd_show_vf_stats_vf_id,
16921                 NULL,
16922         },
16923 };
16924
16925 /* clear vf stats */
16926
16927 /* Common result structure for clear vf stats */
16928 struct cmd_clear_vf_stats_result {
16929         cmdline_fixed_string_t clear;
16930         cmdline_fixed_string_t vf;
16931         cmdline_fixed_string_t stats;
16932         portid_t port_id;
16933         uint16_t vf_id;
16934 };
16935
16936 /* Common CLI fields clear vf stats*/
16937 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
16938         TOKEN_STRING_INITIALIZER
16939                 (struct cmd_clear_vf_stats_result,
16940                  clear, "clear");
16941 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
16942         TOKEN_STRING_INITIALIZER
16943                 (struct cmd_clear_vf_stats_result,
16944                  vf, "vf");
16945 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
16946         TOKEN_STRING_INITIALIZER
16947                 (struct cmd_clear_vf_stats_result,
16948                  stats, "stats");
16949 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
16950         TOKEN_NUM_INITIALIZER
16951                 (struct cmd_clear_vf_stats_result,
16952                  port_id, UINT16);
16953 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
16954         TOKEN_NUM_INITIALIZER
16955                 (struct cmd_clear_vf_stats_result,
16956                  vf_id, UINT16);
16957
16958 static void
16959 cmd_clear_vf_stats_parsed(
16960         void *parsed_result,
16961         __attribute__((unused)) struct cmdline *cl,
16962         __attribute__((unused)) void *data)
16963 {
16964         struct cmd_clear_vf_stats_result *res = parsed_result;
16965         int ret = -ENOTSUP;
16966
16967         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16968                 return;
16969
16970 #ifdef RTE_LIBRTE_I40E_PMD
16971         if (ret == -ENOTSUP)
16972                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
16973                                                   res->vf_id);
16974 #endif
16975 #ifdef RTE_LIBRTE_BNXT_PMD
16976         if (ret == -ENOTSUP)
16977                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
16978                                                   res->vf_id);
16979 #endif
16980
16981         switch (ret) {
16982         case 0:
16983                 break;
16984         case -EINVAL:
16985                 printf("invalid vf_id %d\n", res->vf_id);
16986                 break;
16987         case -ENODEV:
16988                 printf("invalid port_id %d\n", res->port_id);
16989                 break;
16990         case -ENOTSUP:
16991                 printf("function not implemented\n");
16992                 break;
16993         default:
16994                 printf("programming error: (%s)\n", strerror(-ret));
16995         }
16996 }
16997
16998 cmdline_parse_inst_t cmd_clear_vf_stats = {
16999         .f = cmd_clear_vf_stats_parsed,
17000         .data = NULL,
17001         .help_str = "clear vf stats <port_id> <vf_id>",
17002         .tokens = {
17003                 (void *)&cmd_clear_vf_stats_clear,
17004                 (void *)&cmd_clear_vf_stats_vf,
17005                 (void *)&cmd_clear_vf_stats_stats,
17006                 (void *)&cmd_clear_vf_stats_port_id,
17007                 (void *)&cmd_clear_vf_stats_vf_id,
17008                 NULL,
17009         },
17010 };
17011
17012 /* port config pctype mapping reset */
17013
17014 /* Common result structure for port config pctype mapping reset */
17015 struct cmd_pctype_mapping_reset_result {
17016         cmdline_fixed_string_t port;
17017         cmdline_fixed_string_t config;
17018         portid_t port_id;
17019         cmdline_fixed_string_t pctype;
17020         cmdline_fixed_string_t mapping;
17021         cmdline_fixed_string_t reset;
17022 };
17023
17024 /* Common CLI fields for port config pctype mapping reset*/
17025 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17026         TOKEN_STRING_INITIALIZER
17027                 (struct cmd_pctype_mapping_reset_result,
17028                  port, "port");
17029 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17030         TOKEN_STRING_INITIALIZER
17031                 (struct cmd_pctype_mapping_reset_result,
17032                  config, "config");
17033 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17034         TOKEN_NUM_INITIALIZER
17035                 (struct cmd_pctype_mapping_reset_result,
17036                  port_id, UINT16);
17037 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17038         TOKEN_STRING_INITIALIZER
17039                 (struct cmd_pctype_mapping_reset_result,
17040                  pctype, "pctype");
17041 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17042         TOKEN_STRING_INITIALIZER
17043                 (struct cmd_pctype_mapping_reset_result,
17044                  mapping, "mapping");
17045 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17046         TOKEN_STRING_INITIALIZER
17047                 (struct cmd_pctype_mapping_reset_result,
17048                  reset, "reset");
17049
17050 static void
17051 cmd_pctype_mapping_reset_parsed(
17052         void *parsed_result,
17053         __attribute__((unused)) struct cmdline *cl,
17054         __attribute__((unused)) void *data)
17055 {
17056         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17057         int ret = -ENOTSUP;
17058
17059         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17060                 return;
17061
17062 #ifdef RTE_LIBRTE_I40E_PMD
17063         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17064 #endif
17065
17066         switch (ret) {
17067         case 0:
17068                 break;
17069         case -ENODEV:
17070                 printf("invalid port_id %d\n", res->port_id);
17071                 break;
17072         case -ENOTSUP:
17073                 printf("function not implemented\n");
17074                 break;
17075         default:
17076                 printf("programming error: (%s)\n", strerror(-ret));
17077         }
17078 }
17079
17080 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17081         .f = cmd_pctype_mapping_reset_parsed,
17082         .data = NULL,
17083         .help_str = "port config <port_id> pctype mapping reset",
17084         .tokens = {
17085                 (void *)&cmd_pctype_mapping_reset_port,
17086                 (void *)&cmd_pctype_mapping_reset_config,
17087                 (void *)&cmd_pctype_mapping_reset_port_id,
17088                 (void *)&cmd_pctype_mapping_reset_pctype,
17089                 (void *)&cmd_pctype_mapping_reset_mapping,
17090                 (void *)&cmd_pctype_mapping_reset_reset,
17091                 NULL,
17092         },
17093 };
17094
17095 /* show port pctype mapping */
17096
17097 /* Common result structure for show port pctype mapping */
17098 struct cmd_pctype_mapping_get_result {
17099         cmdline_fixed_string_t show;
17100         cmdline_fixed_string_t port;
17101         portid_t port_id;
17102         cmdline_fixed_string_t pctype;
17103         cmdline_fixed_string_t mapping;
17104 };
17105
17106 /* Common CLI fields for pctype mapping get */
17107 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17108         TOKEN_STRING_INITIALIZER
17109                 (struct cmd_pctype_mapping_get_result,
17110                  show, "show");
17111 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17112         TOKEN_STRING_INITIALIZER
17113                 (struct cmd_pctype_mapping_get_result,
17114                  port, "port");
17115 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17116         TOKEN_NUM_INITIALIZER
17117                 (struct cmd_pctype_mapping_get_result,
17118                  port_id, UINT16);
17119 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17120         TOKEN_STRING_INITIALIZER
17121                 (struct cmd_pctype_mapping_get_result,
17122                  pctype, "pctype");
17123 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17124         TOKEN_STRING_INITIALIZER
17125                 (struct cmd_pctype_mapping_get_result,
17126                  mapping, "mapping");
17127
17128 static void
17129 cmd_pctype_mapping_get_parsed(
17130         void *parsed_result,
17131         __attribute__((unused)) struct cmdline *cl,
17132         __attribute__((unused)) void *data)
17133 {
17134         struct cmd_pctype_mapping_get_result *res = parsed_result;
17135         int ret = -ENOTSUP;
17136 #ifdef RTE_LIBRTE_I40E_PMD
17137         struct rte_pmd_i40e_flow_type_mapping
17138                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17139         int i, j, first_pctype;
17140 #endif
17141
17142         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17143                 return;
17144
17145 #ifdef RTE_LIBRTE_I40E_PMD
17146         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17147 #endif
17148
17149         switch (ret) {
17150         case 0:
17151                 break;
17152         case -ENODEV:
17153                 printf("invalid port_id %d\n", res->port_id);
17154                 return;
17155         case -ENOTSUP:
17156                 printf("function not implemented\n");
17157                 return;
17158         default:
17159                 printf("programming error: (%s)\n", strerror(-ret));
17160                 return;
17161         }
17162
17163 #ifdef RTE_LIBRTE_I40E_PMD
17164         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17165                 if (mapping[i].pctype != 0ULL) {
17166                         first_pctype = 1;
17167
17168                         printf("pctype: ");
17169                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17170                                 if (mapping[i].pctype & (1ULL << j)) {
17171                                         printf(first_pctype ?
17172                                                "%02d" : ",%02d", j);
17173                                         first_pctype = 0;
17174                                 }
17175                         }
17176                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17177                 }
17178         }
17179 #endif
17180 }
17181
17182 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17183         .f = cmd_pctype_mapping_get_parsed,
17184         .data = NULL,
17185         .help_str = "show port <port_id> pctype mapping",
17186         .tokens = {
17187                 (void *)&cmd_pctype_mapping_get_show,
17188                 (void *)&cmd_pctype_mapping_get_port,
17189                 (void *)&cmd_pctype_mapping_get_port_id,
17190                 (void *)&cmd_pctype_mapping_get_pctype,
17191                 (void *)&cmd_pctype_mapping_get_mapping,
17192                 NULL,
17193         },
17194 };
17195
17196 /* port config pctype mapping update */
17197
17198 /* Common result structure for port config pctype mapping update */
17199 struct cmd_pctype_mapping_update_result {
17200         cmdline_fixed_string_t port;
17201         cmdline_fixed_string_t config;
17202         portid_t port_id;
17203         cmdline_fixed_string_t pctype;
17204         cmdline_fixed_string_t mapping;
17205         cmdline_fixed_string_t update;
17206         cmdline_fixed_string_t pctype_list;
17207         uint16_t flow_type;
17208 };
17209
17210 /* Common CLI fields for pctype mapping update*/
17211 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17212         TOKEN_STRING_INITIALIZER
17213                 (struct cmd_pctype_mapping_update_result,
17214                  port, "port");
17215 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17216         TOKEN_STRING_INITIALIZER
17217                 (struct cmd_pctype_mapping_update_result,
17218                  config, "config");
17219 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17220         TOKEN_NUM_INITIALIZER
17221                 (struct cmd_pctype_mapping_update_result,
17222                  port_id, UINT16);
17223 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17224         TOKEN_STRING_INITIALIZER
17225                 (struct cmd_pctype_mapping_update_result,
17226                  pctype, "pctype");
17227 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17228         TOKEN_STRING_INITIALIZER
17229                 (struct cmd_pctype_mapping_update_result,
17230                  mapping, "mapping");
17231 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17232         TOKEN_STRING_INITIALIZER
17233                 (struct cmd_pctype_mapping_update_result,
17234                  update, "update");
17235 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17236         TOKEN_STRING_INITIALIZER
17237                 (struct cmd_pctype_mapping_update_result,
17238                  pctype_list, NULL);
17239 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17240         TOKEN_NUM_INITIALIZER
17241                 (struct cmd_pctype_mapping_update_result,
17242                  flow_type, UINT16);
17243
17244 static void
17245 cmd_pctype_mapping_update_parsed(
17246         void *parsed_result,
17247         __attribute__((unused)) struct cmdline *cl,
17248         __attribute__((unused)) void *data)
17249 {
17250         struct cmd_pctype_mapping_update_result *res = parsed_result;
17251         int ret = -ENOTSUP;
17252 #ifdef RTE_LIBRTE_I40E_PMD
17253         struct rte_pmd_i40e_flow_type_mapping mapping;
17254         unsigned int i;
17255         unsigned int nb_item;
17256         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17257 #endif
17258
17259         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17260                 return;
17261
17262 #ifdef RTE_LIBRTE_I40E_PMD
17263         nb_item = parse_item_list(res->pctype_list, "pctypes",
17264                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17265         mapping.flow_type = res->flow_type;
17266         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17267                 mapping.pctype |= (1ULL << pctype_list[i]);
17268         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17269                                                 &mapping,
17270                                                 1,
17271                                                 0);
17272 #endif
17273
17274         switch (ret) {
17275         case 0:
17276                 break;
17277         case -EINVAL:
17278                 printf("invalid pctype or flow type\n");
17279                 break;
17280         case -ENODEV:
17281                 printf("invalid port_id %d\n", res->port_id);
17282                 break;
17283         case -ENOTSUP:
17284                 printf("function not implemented\n");
17285                 break;
17286         default:
17287                 printf("programming error: (%s)\n", strerror(-ret));
17288         }
17289 }
17290
17291 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17292         .f = cmd_pctype_mapping_update_parsed,
17293         .data = NULL,
17294         .help_str = "port config <port_id> pctype mapping update"
17295         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17296         .tokens = {
17297                 (void *)&cmd_pctype_mapping_update_port,
17298                 (void *)&cmd_pctype_mapping_update_config,
17299                 (void *)&cmd_pctype_mapping_update_port_id,
17300                 (void *)&cmd_pctype_mapping_update_pctype,
17301                 (void *)&cmd_pctype_mapping_update_mapping,
17302                 (void *)&cmd_pctype_mapping_update_update,
17303                 (void *)&cmd_pctype_mapping_update_pc_type,
17304                 (void *)&cmd_pctype_mapping_update_flow_type,
17305                 NULL,
17306         },
17307 };
17308
17309 /* ptype mapping get */
17310
17311 /* Common result structure for ptype mapping get */
17312 struct cmd_ptype_mapping_get_result {
17313         cmdline_fixed_string_t ptype;
17314         cmdline_fixed_string_t mapping;
17315         cmdline_fixed_string_t get;
17316         portid_t port_id;
17317         uint8_t valid_only;
17318 };
17319
17320 /* Common CLI fields for ptype mapping get */
17321 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17322         TOKEN_STRING_INITIALIZER
17323                 (struct cmd_ptype_mapping_get_result,
17324                  ptype, "ptype");
17325 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17326         TOKEN_STRING_INITIALIZER
17327                 (struct cmd_ptype_mapping_get_result,
17328                  mapping, "mapping");
17329 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17330         TOKEN_STRING_INITIALIZER
17331                 (struct cmd_ptype_mapping_get_result,
17332                  get, "get");
17333 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17334         TOKEN_NUM_INITIALIZER
17335                 (struct cmd_ptype_mapping_get_result,
17336                  port_id, UINT16);
17337 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17338         TOKEN_NUM_INITIALIZER
17339                 (struct cmd_ptype_mapping_get_result,
17340                  valid_only, UINT8);
17341
17342 static void
17343 cmd_ptype_mapping_get_parsed(
17344         void *parsed_result,
17345         __attribute__((unused)) struct cmdline *cl,
17346         __attribute__((unused)) void *data)
17347 {
17348         struct cmd_ptype_mapping_get_result *res = parsed_result;
17349         int ret = -ENOTSUP;
17350 #ifdef RTE_LIBRTE_I40E_PMD
17351         int max_ptype_num = 256;
17352         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17353         uint16_t count;
17354         int i;
17355 #endif
17356
17357         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17358                 return;
17359
17360 #ifdef RTE_LIBRTE_I40E_PMD
17361         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17362                                         mapping,
17363                                         max_ptype_num,
17364                                         &count,
17365                                         res->valid_only);
17366 #endif
17367
17368         switch (ret) {
17369         case 0:
17370                 break;
17371         case -ENODEV:
17372                 printf("invalid port_id %d\n", res->port_id);
17373                 break;
17374         case -ENOTSUP:
17375                 printf("function not implemented\n");
17376                 break;
17377         default:
17378                 printf("programming error: (%s)\n", strerror(-ret));
17379         }
17380
17381 #ifdef RTE_LIBRTE_I40E_PMD
17382         if (!ret) {
17383                 for (i = 0; i < count; i++)
17384                         printf("%3d\t0x%08x\n",
17385                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17386         }
17387 #endif
17388 }
17389
17390 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17391         .f = cmd_ptype_mapping_get_parsed,
17392         .data = NULL,
17393         .help_str = "ptype mapping get <port_id> <valid_only>",
17394         .tokens = {
17395                 (void *)&cmd_ptype_mapping_get_ptype,
17396                 (void *)&cmd_ptype_mapping_get_mapping,
17397                 (void *)&cmd_ptype_mapping_get_get,
17398                 (void *)&cmd_ptype_mapping_get_port_id,
17399                 (void *)&cmd_ptype_mapping_get_valid_only,
17400                 NULL,
17401         },
17402 };
17403
17404 /* ptype mapping replace */
17405
17406 /* Common result structure for ptype mapping replace */
17407 struct cmd_ptype_mapping_replace_result {
17408         cmdline_fixed_string_t ptype;
17409         cmdline_fixed_string_t mapping;
17410         cmdline_fixed_string_t replace;
17411         portid_t port_id;
17412         uint32_t target;
17413         uint8_t mask;
17414         uint32_t pkt_type;
17415 };
17416
17417 /* Common CLI fields for ptype mapping replace */
17418 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17419         TOKEN_STRING_INITIALIZER
17420                 (struct cmd_ptype_mapping_replace_result,
17421                  ptype, "ptype");
17422 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17423         TOKEN_STRING_INITIALIZER
17424                 (struct cmd_ptype_mapping_replace_result,
17425                  mapping, "mapping");
17426 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17427         TOKEN_STRING_INITIALIZER
17428                 (struct cmd_ptype_mapping_replace_result,
17429                  replace, "replace");
17430 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17431         TOKEN_NUM_INITIALIZER
17432                 (struct cmd_ptype_mapping_replace_result,
17433                  port_id, UINT16);
17434 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17435         TOKEN_NUM_INITIALIZER
17436                 (struct cmd_ptype_mapping_replace_result,
17437                  target, UINT32);
17438 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17439         TOKEN_NUM_INITIALIZER
17440                 (struct cmd_ptype_mapping_replace_result,
17441                  mask, UINT8);
17442 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17443         TOKEN_NUM_INITIALIZER
17444                 (struct cmd_ptype_mapping_replace_result,
17445                  pkt_type, UINT32);
17446
17447 static void
17448 cmd_ptype_mapping_replace_parsed(
17449         void *parsed_result,
17450         __attribute__((unused)) struct cmdline *cl,
17451         __attribute__((unused)) void *data)
17452 {
17453         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17454         int ret = -ENOTSUP;
17455
17456         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17457                 return;
17458
17459 #ifdef RTE_LIBRTE_I40E_PMD
17460         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17461                                         res->target,
17462                                         res->mask,
17463                                         res->pkt_type);
17464 #endif
17465
17466         switch (ret) {
17467         case 0:
17468                 break;
17469         case -EINVAL:
17470                 printf("invalid ptype 0x%8x or 0x%8x\n",
17471                                 res->target, res->pkt_type);
17472                 break;
17473         case -ENODEV:
17474                 printf("invalid port_id %d\n", res->port_id);
17475                 break;
17476         case -ENOTSUP:
17477                 printf("function not implemented\n");
17478                 break;
17479         default:
17480                 printf("programming error: (%s)\n", strerror(-ret));
17481         }
17482 }
17483
17484 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17485         .f = cmd_ptype_mapping_replace_parsed,
17486         .data = NULL,
17487         .help_str =
17488                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17489         .tokens = {
17490                 (void *)&cmd_ptype_mapping_replace_ptype,
17491                 (void *)&cmd_ptype_mapping_replace_mapping,
17492                 (void *)&cmd_ptype_mapping_replace_replace,
17493                 (void *)&cmd_ptype_mapping_replace_port_id,
17494                 (void *)&cmd_ptype_mapping_replace_target,
17495                 (void *)&cmd_ptype_mapping_replace_mask,
17496                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17497                 NULL,
17498         },
17499 };
17500
17501 /* ptype mapping reset */
17502
17503 /* Common result structure for ptype mapping reset */
17504 struct cmd_ptype_mapping_reset_result {
17505         cmdline_fixed_string_t ptype;
17506         cmdline_fixed_string_t mapping;
17507         cmdline_fixed_string_t reset;
17508         portid_t port_id;
17509 };
17510
17511 /* Common CLI fields for ptype mapping reset*/
17512 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17513         TOKEN_STRING_INITIALIZER
17514                 (struct cmd_ptype_mapping_reset_result,
17515                  ptype, "ptype");
17516 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17517         TOKEN_STRING_INITIALIZER
17518                 (struct cmd_ptype_mapping_reset_result,
17519                  mapping, "mapping");
17520 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17521         TOKEN_STRING_INITIALIZER
17522                 (struct cmd_ptype_mapping_reset_result,
17523                  reset, "reset");
17524 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17525         TOKEN_NUM_INITIALIZER
17526                 (struct cmd_ptype_mapping_reset_result,
17527                  port_id, UINT16);
17528
17529 static void
17530 cmd_ptype_mapping_reset_parsed(
17531         void *parsed_result,
17532         __attribute__((unused)) struct cmdline *cl,
17533         __attribute__((unused)) void *data)
17534 {
17535         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17536         int ret = -ENOTSUP;
17537
17538         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17539                 return;
17540
17541 #ifdef RTE_LIBRTE_I40E_PMD
17542         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17543 #endif
17544
17545         switch (ret) {
17546         case 0:
17547                 break;
17548         case -ENODEV:
17549                 printf("invalid port_id %d\n", res->port_id);
17550                 break;
17551         case -ENOTSUP:
17552                 printf("function not implemented\n");
17553                 break;
17554         default:
17555                 printf("programming error: (%s)\n", strerror(-ret));
17556         }
17557 }
17558
17559 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17560         .f = cmd_ptype_mapping_reset_parsed,
17561         .data = NULL,
17562         .help_str = "ptype mapping reset <port_id>",
17563         .tokens = {
17564                 (void *)&cmd_ptype_mapping_reset_ptype,
17565                 (void *)&cmd_ptype_mapping_reset_mapping,
17566                 (void *)&cmd_ptype_mapping_reset_reset,
17567                 (void *)&cmd_ptype_mapping_reset_port_id,
17568                 NULL,
17569         },
17570 };
17571
17572 /* ptype mapping update */
17573
17574 /* Common result structure for ptype mapping update */
17575 struct cmd_ptype_mapping_update_result {
17576         cmdline_fixed_string_t ptype;
17577         cmdline_fixed_string_t mapping;
17578         cmdline_fixed_string_t reset;
17579         portid_t port_id;
17580         uint8_t hw_ptype;
17581         uint32_t sw_ptype;
17582 };
17583
17584 /* Common CLI fields for ptype mapping update*/
17585 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17586         TOKEN_STRING_INITIALIZER
17587                 (struct cmd_ptype_mapping_update_result,
17588                  ptype, "ptype");
17589 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17590         TOKEN_STRING_INITIALIZER
17591                 (struct cmd_ptype_mapping_update_result,
17592                  mapping, "mapping");
17593 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17594         TOKEN_STRING_INITIALIZER
17595                 (struct cmd_ptype_mapping_update_result,
17596                  reset, "update");
17597 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17598         TOKEN_NUM_INITIALIZER
17599                 (struct cmd_ptype_mapping_update_result,
17600                  port_id, UINT16);
17601 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17602         TOKEN_NUM_INITIALIZER
17603                 (struct cmd_ptype_mapping_update_result,
17604                  hw_ptype, UINT8);
17605 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17606         TOKEN_NUM_INITIALIZER
17607                 (struct cmd_ptype_mapping_update_result,
17608                  sw_ptype, UINT32);
17609
17610 static void
17611 cmd_ptype_mapping_update_parsed(
17612         void *parsed_result,
17613         __attribute__((unused)) struct cmdline *cl,
17614         __attribute__((unused)) void *data)
17615 {
17616         struct cmd_ptype_mapping_update_result *res = parsed_result;
17617         int ret = -ENOTSUP;
17618 #ifdef RTE_LIBRTE_I40E_PMD
17619         struct rte_pmd_i40e_ptype_mapping mapping;
17620 #endif
17621         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17622                 return;
17623
17624 #ifdef RTE_LIBRTE_I40E_PMD
17625         mapping.hw_ptype = res->hw_ptype;
17626         mapping.sw_ptype = res->sw_ptype;
17627         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17628                                                 &mapping,
17629                                                 1,
17630                                                 0);
17631 #endif
17632
17633         switch (ret) {
17634         case 0:
17635                 break;
17636         case -EINVAL:
17637                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17638                 break;
17639         case -ENODEV:
17640                 printf("invalid port_id %d\n", res->port_id);
17641                 break;
17642         case -ENOTSUP:
17643                 printf("function not implemented\n");
17644                 break;
17645         default:
17646                 printf("programming error: (%s)\n", strerror(-ret));
17647         }
17648 }
17649
17650 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17651         .f = cmd_ptype_mapping_update_parsed,
17652         .data = NULL,
17653         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17654         .tokens = {
17655                 (void *)&cmd_ptype_mapping_update_ptype,
17656                 (void *)&cmd_ptype_mapping_update_mapping,
17657                 (void *)&cmd_ptype_mapping_update_update,
17658                 (void *)&cmd_ptype_mapping_update_port_id,
17659                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17660                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17661                 NULL,
17662         },
17663 };
17664
17665 /* Common result structure for file commands */
17666 struct cmd_cmdfile_result {
17667         cmdline_fixed_string_t load;
17668         cmdline_fixed_string_t filename;
17669 };
17670
17671 /* Common CLI fields for file commands */
17672 cmdline_parse_token_string_t cmd_load_cmdfile =
17673         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17674 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17675         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17676
17677 static void
17678 cmd_load_from_file_parsed(
17679         void *parsed_result,
17680         __attribute__((unused)) struct cmdline *cl,
17681         __attribute__((unused)) void *data)
17682 {
17683         struct cmd_cmdfile_result *res = parsed_result;
17684
17685         cmdline_read_from_file(res->filename);
17686 }
17687
17688 cmdline_parse_inst_t cmd_load_from_file = {
17689         .f = cmd_load_from_file_parsed,
17690         .data = NULL,
17691         .help_str = "load <filename>",
17692         .tokens = {
17693                 (void *)&cmd_load_cmdfile,
17694                 (void *)&cmd_load_cmdfile_filename,
17695                 NULL,
17696         },
17697 };
17698
17699 /* Get Rx offloads capabilities */
17700 struct cmd_rx_offload_get_capa_result {
17701         cmdline_fixed_string_t show;
17702         cmdline_fixed_string_t port;
17703         portid_t port_id;
17704         cmdline_fixed_string_t rx_offload;
17705         cmdline_fixed_string_t capabilities;
17706 };
17707
17708 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17709         TOKEN_STRING_INITIALIZER
17710                 (struct cmd_rx_offload_get_capa_result,
17711                  show, "show");
17712 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17713         TOKEN_STRING_INITIALIZER
17714                 (struct cmd_rx_offload_get_capa_result,
17715                  port, "port");
17716 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17717         TOKEN_NUM_INITIALIZER
17718                 (struct cmd_rx_offload_get_capa_result,
17719                  port_id, UINT16);
17720 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17721         TOKEN_STRING_INITIALIZER
17722                 (struct cmd_rx_offload_get_capa_result,
17723                  rx_offload, "rx_offload");
17724 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17725         TOKEN_STRING_INITIALIZER
17726                 (struct cmd_rx_offload_get_capa_result,
17727                  capabilities, "capabilities");
17728
17729 static void
17730 print_rx_offloads(uint64_t offloads)
17731 {
17732         uint64_t single_offload;
17733         int begin;
17734         int end;
17735         int bit;
17736
17737         if (offloads == 0)
17738                 return;
17739
17740         begin = __builtin_ctzll(offloads);
17741         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17742
17743         single_offload = 1 << begin;
17744         for (bit = begin; bit < end; bit++) {
17745                 if (offloads & single_offload)
17746                         printf(" %s",
17747                                rte_eth_dev_rx_offload_name(single_offload));
17748                 single_offload <<= 1;
17749         }
17750 }
17751
17752 static void
17753 cmd_rx_offload_get_capa_parsed(
17754         void *parsed_result,
17755         __attribute__((unused)) struct cmdline *cl,
17756         __attribute__((unused)) void *data)
17757 {
17758         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17759         struct rte_eth_dev_info dev_info;
17760         portid_t port_id = res->port_id;
17761         uint64_t queue_offloads;
17762         uint64_t port_offloads;
17763
17764         rte_eth_dev_info_get(port_id, &dev_info);
17765         queue_offloads = dev_info.rx_queue_offload_capa;
17766         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17767
17768         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17769         printf("  Per Queue :");
17770         print_rx_offloads(queue_offloads);
17771
17772         printf("\n");
17773         printf("  Per Port  :");
17774         print_rx_offloads(port_offloads);
17775         printf("\n\n");
17776 }
17777
17778 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17779         .f = cmd_rx_offload_get_capa_parsed,
17780         .data = NULL,
17781         .help_str = "show port <port_id> rx_offload capabilities",
17782         .tokens = {
17783                 (void *)&cmd_rx_offload_get_capa_show,
17784                 (void *)&cmd_rx_offload_get_capa_port,
17785                 (void *)&cmd_rx_offload_get_capa_port_id,
17786                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17787                 (void *)&cmd_rx_offload_get_capa_capabilities,
17788                 NULL,
17789         }
17790 };
17791
17792 /* Get Rx offloads configuration */
17793 struct cmd_rx_offload_get_configuration_result {
17794         cmdline_fixed_string_t show;
17795         cmdline_fixed_string_t port;
17796         portid_t port_id;
17797         cmdline_fixed_string_t rx_offload;
17798         cmdline_fixed_string_t configuration;
17799 };
17800
17801 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17802         TOKEN_STRING_INITIALIZER
17803                 (struct cmd_rx_offload_get_configuration_result,
17804                  show, "show");
17805 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17806         TOKEN_STRING_INITIALIZER
17807                 (struct cmd_rx_offload_get_configuration_result,
17808                  port, "port");
17809 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17810         TOKEN_NUM_INITIALIZER
17811                 (struct cmd_rx_offload_get_configuration_result,
17812                  port_id, UINT16);
17813 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17814         TOKEN_STRING_INITIALIZER
17815                 (struct cmd_rx_offload_get_configuration_result,
17816                  rx_offload, "rx_offload");
17817 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17818         TOKEN_STRING_INITIALIZER
17819                 (struct cmd_rx_offload_get_configuration_result,
17820                  configuration, "configuration");
17821
17822 static void
17823 cmd_rx_offload_get_configuration_parsed(
17824         void *parsed_result,
17825         __attribute__((unused)) struct cmdline *cl,
17826         __attribute__((unused)) void *data)
17827 {
17828         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17829         struct rte_eth_dev_info dev_info;
17830         portid_t port_id = res->port_id;
17831         struct rte_port *port = &ports[port_id];
17832         uint64_t port_offloads;
17833         uint64_t queue_offloads;
17834         uint16_t nb_rx_queues;
17835         int q;
17836
17837         printf("Rx Offloading Configuration of port %d :\n", port_id);
17838
17839         port_offloads = port->dev_conf.rxmode.offloads;
17840         printf("  Port :");
17841         print_rx_offloads(port_offloads);
17842         printf("\n");
17843
17844         rte_eth_dev_info_get(port_id, &dev_info);
17845         nb_rx_queues = dev_info.nb_rx_queues;
17846         for (q = 0; q < nb_rx_queues; q++) {
17847                 queue_offloads = port->rx_conf[q].offloads;
17848                 printf("  Queue[%2d] :", q);
17849                 print_rx_offloads(queue_offloads);
17850                 printf("\n");
17851         }
17852         printf("\n");
17853 }
17854
17855 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17856         .f = cmd_rx_offload_get_configuration_parsed,
17857         .data = NULL,
17858         .help_str = "show port <port_id> rx_offload configuration",
17859         .tokens = {
17860                 (void *)&cmd_rx_offload_get_configuration_show,
17861                 (void *)&cmd_rx_offload_get_configuration_port,
17862                 (void *)&cmd_rx_offload_get_configuration_port_id,
17863                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17864                 (void *)&cmd_rx_offload_get_configuration_configuration,
17865                 NULL,
17866         }
17867 };
17868
17869 /* Enable/Disable a per port offloading */
17870 struct cmd_config_per_port_rx_offload_result {
17871         cmdline_fixed_string_t port;
17872         cmdline_fixed_string_t config;
17873         portid_t port_id;
17874         cmdline_fixed_string_t rx_offload;
17875         cmdline_fixed_string_t offload;
17876         cmdline_fixed_string_t on_off;
17877 };
17878
17879 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
17880         TOKEN_STRING_INITIALIZER
17881                 (struct cmd_config_per_port_rx_offload_result,
17882                  port, "port");
17883 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
17884         TOKEN_STRING_INITIALIZER
17885                 (struct cmd_config_per_port_rx_offload_result,
17886                  config, "config");
17887 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
17888         TOKEN_NUM_INITIALIZER
17889                 (struct cmd_config_per_port_rx_offload_result,
17890                  port_id, UINT16);
17891 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
17892         TOKEN_STRING_INITIALIZER
17893                 (struct cmd_config_per_port_rx_offload_result,
17894                  rx_offload, "rx_offload");
17895 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
17896         TOKEN_STRING_INITIALIZER
17897                 (struct cmd_config_per_port_rx_offload_result,
17898                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17899                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17900                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17901                            "crc_strip#scatter#timestamp#security#keep_crc");
17902 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
17903         TOKEN_STRING_INITIALIZER
17904                 (struct cmd_config_per_port_rx_offload_result,
17905                  on_off, "on#off");
17906
17907 static uint64_t
17908 search_rx_offload(const char *name)
17909 {
17910         uint64_t single_offload;
17911         const char *single_name;
17912         int found = 0;
17913         unsigned int bit;
17914
17915         single_offload = 1;
17916         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17917                 single_name = rte_eth_dev_rx_offload_name(single_offload);
17918                 if (!strcasecmp(single_name, name)) {
17919                         found = 1;
17920                         break;
17921                 }
17922                 single_offload <<= 1;
17923         }
17924
17925         if (found)
17926                 return single_offload;
17927
17928         return 0;
17929 }
17930
17931 static void
17932 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
17933                                 __attribute__((unused)) struct cmdline *cl,
17934                                 __attribute__((unused)) void *data)
17935 {
17936         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
17937         portid_t port_id = res->port_id;
17938         struct rte_eth_dev_info dev_info;
17939         struct rte_port *port = &ports[port_id];
17940         uint64_t single_offload;
17941         uint16_t nb_rx_queues;
17942         int q;
17943
17944         if (port->port_status != RTE_PORT_STOPPED) {
17945                 printf("Error: Can't config offload when Port %d "
17946                        "is not stopped\n", port_id);
17947                 return;
17948         }
17949
17950         single_offload = search_rx_offload(res->offload);
17951         if (single_offload == 0) {
17952                 printf("Unknown offload name: %s\n", res->offload);
17953                 return;
17954         }
17955
17956         rte_eth_dev_info_get(port_id, &dev_info);
17957         nb_rx_queues = dev_info.nb_rx_queues;
17958         if (!strcmp(res->on_off, "on")) {
17959                 port->dev_conf.rxmode.offloads |= single_offload;
17960                 for (q = 0; q < nb_rx_queues; q++)
17961                         port->rx_conf[q].offloads |= single_offload;
17962         } else {
17963                 port->dev_conf.rxmode.offloads &= ~single_offload;
17964                 for (q = 0; q < nb_rx_queues; q++)
17965                         port->rx_conf[q].offloads &= ~single_offload;
17966         }
17967
17968         cmd_reconfig_device_queue(port_id, 1, 1);
17969 }
17970
17971 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
17972         .f = cmd_config_per_port_rx_offload_parsed,
17973         .data = NULL,
17974         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
17975                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17976                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17977                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
17978                     "on|off",
17979         .tokens = {
17980                 (void *)&cmd_config_per_port_rx_offload_result_port,
17981                 (void *)&cmd_config_per_port_rx_offload_result_config,
17982                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
17983                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
17984                 (void *)&cmd_config_per_port_rx_offload_result_offload,
17985                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
17986                 NULL,
17987         }
17988 };
17989
17990 /* Enable/Disable a per queue offloading */
17991 struct cmd_config_per_queue_rx_offload_result {
17992         cmdline_fixed_string_t port;
17993         portid_t port_id;
17994         cmdline_fixed_string_t rxq;
17995         uint16_t queue_id;
17996         cmdline_fixed_string_t rx_offload;
17997         cmdline_fixed_string_t offload;
17998         cmdline_fixed_string_t on_off;
17999 };
18000
18001 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18002         TOKEN_STRING_INITIALIZER
18003                 (struct cmd_config_per_queue_rx_offload_result,
18004                  port, "port");
18005 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18006         TOKEN_NUM_INITIALIZER
18007                 (struct cmd_config_per_queue_rx_offload_result,
18008                  port_id, UINT16);
18009 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18010         TOKEN_STRING_INITIALIZER
18011                 (struct cmd_config_per_queue_rx_offload_result,
18012                  rxq, "rxq");
18013 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18014         TOKEN_NUM_INITIALIZER
18015                 (struct cmd_config_per_queue_rx_offload_result,
18016                  queue_id, UINT16);
18017 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18018         TOKEN_STRING_INITIALIZER
18019                 (struct cmd_config_per_queue_rx_offload_result,
18020                  rx_offload, "rx_offload");
18021 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18022         TOKEN_STRING_INITIALIZER
18023                 (struct cmd_config_per_queue_rx_offload_result,
18024                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18025                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18026                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18027                            "crc_strip#scatter#timestamp#security#keep_crc");
18028 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18029         TOKEN_STRING_INITIALIZER
18030                 (struct cmd_config_per_queue_rx_offload_result,
18031                  on_off, "on#off");
18032
18033 static void
18034 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18035                                 __attribute__((unused)) struct cmdline *cl,
18036                                 __attribute__((unused)) void *data)
18037 {
18038         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18039         struct rte_eth_dev_info dev_info;
18040         portid_t port_id = res->port_id;
18041         uint16_t queue_id = res->queue_id;
18042         struct rte_port *port = &ports[port_id];
18043         uint64_t single_offload;
18044
18045         if (port->port_status != RTE_PORT_STOPPED) {
18046                 printf("Error: Can't config offload when Port %d "
18047                        "is not stopped\n", port_id);
18048                 return;
18049         }
18050
18051         rte_eth_dev_info_get(port_id, &dev_info);
18052         if (queue_id >= dev_info.nb_rx_queues) {
18053                 printf("Error: input queue_id should be 0 ... "
18054                        "%d\n", dev_info.nb_rx_queues - 1);
18055                 return;
18056         }
18057
18058         single_offload = search_rx_offload(res->offload);
18059         if (single_offload == 0) {
18060                 printf("Unknown offload name: %s\n", res->offload);
18061                 return;
18062         }
18063
18064         if (!strcmp(res->on_off, "on"))
18065                 port->rx_conf[queue_id].offloads |= single_offload;
18066         else
18067                 port->rx_conf[queue_id].offloads &= ~single_offload;
18068
18069         cmd_reconfig_device_queue(port_id, 1, 1);
18070 }
18071
18072 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18073         .f = cmd_config_per_queue_rx_offload_parsed,
18074         .data = NULL,
18075         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18076                     "vlan_strip|ipv4_cksum|"
18077                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18078                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18079                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18080                     "on|off",
18081         .tokens = {
18082                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18083                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18084                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18085                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18086                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18087                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18088                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18089                 NULL,
18090         }
18091 };
18092
18093 /* Get Tx offloads capabilities */
18094 struct cmd_tx_offload_get_capa_result {
18095         cmdline_fixed_string_t show;
18096         cmdline_fixed_string_t port;
18097         portid_t port_id;
18098         cmdline_fixed_string_t tx_offload;
18099         cmdline_fixed_string_t capabilities;
18100 };
18101
18102 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18103         TOKEN_STRING_INITIALIZER
18104                 (struct cmd_tx_offload_get_capa_result,
18105                  show, "show");
18106 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18107         TOKEN_STRING_INITIALIZER
18108                 (struct cmd_tx_offload_get_capa_result,
18109                  port, "port");
18110 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18111         TOKEN_NUM_INITIALIZER
18112                 (struct cmd_tx_offload_get_capa_result,
18113                  port_id, UINT16);
18114 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18115         TOKEN_STRING_INITIALIZER
18116                 (struct cmd_tx_offload_get_capa_result,
18117                  tx_offload, "tx_offload");
18118 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18119         TOKEN_STRING_INITIALIZER
18120                 (struct cmd_tx_offload_get_capa_result,
18121                  capabilities, "capabilities");
18122
18123 static void
18124 print_tx_offloads(uint64_t offloads)
18125 {
18126         uint64_t single_offload;
18127         int begin;
18128         int end;
18129         int bit;
18130
18131         if (offloads == 0)
18132                 return;
18133
18134         begin = __builtin_ctzll(offloads);
18135         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18136
18137         single_offload = 1 << begin;
18138         for (bit = begin; bit < end; bit++) {
18139                 if (offloads & single_offload)
18140                         printf(" %s",
18141                                rte_eth_dev_tx_offload_name(single_offload));
18142                 single_offload <<= 1;
18143         }
18144 }
18145
18146 static void
18147 cmd_tx_offload_get_capa_parsed(
18148         void *parsed_result,
18149         __attribute__((unused)) struct cmdline *cl,
18150         __attribute__((unused)) void *data)
18151 {
18152         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18153         struct rte_eth_dev_info dev_info;
18154         portid_t port_id = res->port_id;
18155         uint64_t queue_offloads;
18156         uint64_t port_offloads;
18157
18158         rte_eth_dev_info_get(port_id, &dev_info);
18159         queue_offloads = dev_info.tx_queue_offload_capa;
18160         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18161
18162         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18163         printf("  Per Queue :");
18164         print_tx_offloads(queue_offloads);
18165
18166         printf("\n");
18167         printf("  Per Port  :");
18168         print_tx_offloads(port_offloads);
18169         printf("\n\n");
18170 }
18171
18172 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18173         .f = cmd_tx_offload_get_capa_parsed,
18174         .data = NULL,
18175         .help_str = "show port <port_id> tx_offload capabilities",
18176         .tokens = {
18177                 (void *)&cmd_tx_offload_get_capa_show,
18178                 (void *)&cmd_tx_offload_get_capa_port,
18179                 (void *)&cmd_tx_offload_get_capa_port_id,
18180                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18181                 (void *)&cmd_tx_offload_get_capa_capabilities,
18182                 NULL,
18183         }
18184 };
18185
18186 /* Get Tx offloads configuration */
18187 struct cmd_tx_offload_get_configuration_result {
18188         cmdline_fixed_string_t show;
18189         cmdline_fixed_string_t port;
18190         portid_t port_id;
18191         cmdline_fixed_string_t tx_offload;
18192         cmdline_fixed_string_t configuration;
18193 };
18194
18195 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18196         TOKEN_STRING_INITIALIZER
18197                 (struct cmd_tx_offload_get_configuration_result,
18198                  show, "show");
18199 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18200         TOKEN_STRING_INITIALIZER
18201                 (struct cmd_tx_offload_get_configuration_result,
18202                  port, "port");
18203 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18204         TOKEN_NUM_INITIALIZER
18205                 (struct cmd_tx_offload_get_configuration_result,
18206                  port_id, UINT16);
18207 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18208         TOKEN_STRING_INITIALIZER
18209                 (struct cmd_tx_offload_get_configuration_result,
18210                  tx_offload, "tx_offload");
18211 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18212         TOKEN_STRING_INITIALIZER
18213                 (struct cmd_tx_offload_get_configuration_result,
18214                  configuration, "configuration");
18215
18216 static void
18217 cmd_tx_offload_get_configuration_parsed(
18218         void *parsed_result,
18219         __attribute__((unused)) struct cmdline *cl,
18220         __attribute__((unused)) void *data)
18221 {
18222         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18223         struct rte_eth_dev_info dev_info;
18224         portid_t port_id = res->port_id;
18225         struct rte_port *port = &ports[port_id];
18226         uint64_t port_offloads;
18227         uint64_t queue_offloads;
18228         uint16_t nb_tx_queues;
18229         int q;
18230
18231         printf("Tx Offloading Configuration of port %d :\n", port_id);
18232
18233         port_offloads = port->dev_conf.txmode.offloads;
18234         printf("  Port :");
18235         print_tx_offloads(port_offloads);
18236         printf("\n");
18237
18238         rte_eth_dev_info_get(port_id, &dev_info);
18239         nb_tx_queues = dev_info.nb_tx_queues;
18240         for (q = 0; q < nb_tx_queues; q++) {
18241                 queue_offloads = port->tx_conf[q].offloads;
18242                 printf("  Queue[%2d] :", q);
18243                 print_tx_offloads(queue_offloads);
18244                 printf("\n");
18245         }
18246         printf("\n");
18247 }
18248
18249 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18250         .f = cmd_tx_offload_get_configuration_parsed,
18251         .data = NULL,
18252         .help_str = "show port <port_id> tx_offload configuration",
18253         .tokens = {
18254                 (void *)&cmd_tx_offload_get_configuration_show,
18255                 (void *)&cmd_tx_offload_get_configuration_port,
18256                 (void *)&cmd_tx_offload_get_configuration_port_id,
18257                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18258                 (void *)&cmd_tx_offload_get_configuration_configuration,
18259                 NULL,
18260         }
18261 };
18262
18263 /* Enable/Disable a per port offloading */
18264 struct cmd_config_per_port_tx_offload_result {
18265         cmdline_fixed_string_t port;
18266         cmdline_fixed_string_t config;
18267         portid_t port_id;
18268         cmdline_fixed_string_t tx_offload;
18269         cmdline_fixed_string_t offload;
18270         cmdline_fixed_string_t on_off;
18271 };
18272
18273 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18274         TOKEN_STRING_INITIALIZER
18275                 (struct cmd_config_per_port_tx_offload_result,
18276                  port, "port");
18277 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18278         TOKEN_STRING_INITIALIZER
18279                 (struct cmd_config_per_port_tx_offload_result,
18280                  config, "config");
18281 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18282         TOKEN_NUM_INITIALIZER
18283                 (struct cmd_config_per_port_tx_offload_result,
18284                  port_id, UINT16);
18285 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18286         TOKEN_STRING_INITIALIZER
18287                 (struct cmd_config_per_port_tx_offload_result,
18288                  tx_offload, "tx_offload");
18289 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18290         TOKEN_STRING_INITIALIZER
18291                 (struct cmd_config_per_port_tx_offload_result,
18292                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18293                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18294                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18295                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18296                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18297                           "match_metadata");
18298 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18299         TOKEN_STRING_INITIALIZER
18300                 (struct cmd_config_per_port_tx_offload_result,
18301                  on_off, "on#off");
18302
18303 static uint64_t
18304 search_tx_offload(const char *name)
18305 {
18306         uint64_t single_offload;
18307         const char *single_name;
18308         int found = 0;
18309         unsigned int bit;
18310
18311         single_offload = 1;
18312         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18313                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18314                 if (!strcasecmp(single_name, name)) {
18315                         found = 1;
18316                         break;
18317                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18318                         break;
18319                 else if (single_name == NULL)
18320                         break;
18321                 single_offload <<= 1;
18322         }
18323
18324         if (found)
18325                 return single_offload;
18326
18327         return 0;
18328 }
18329
18330 static void
18331 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18332                                 __attribute__((unused)) struct cmdline *cl,
18333                                 __attribute__((unused)) void *data)
18334 {
18335         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18336         portid_t port_id = res->port_id;
18337         struct rte_eth_dev_info dev_info;
18338         struct rte_port *port = &ports[port_id];
18339         uint64_t single_offload;
18340         uint16_t nb_tx_queues;
18341         int q;
18342
18343         if (port->port_status != RTE_PORT_STOPPED) {
18344                 printf("Error: Can't config offload when Port %d "
18345                        "is not stopped\n", port_id);
18346                 return;
18347         }
18348
18349         single_offload = search_tx_offload(res->offload);
18350         if (single_offload == 0) {
18351                 printf("Unknown offload name: %s\n", res->offload);
18352                 return;
18353         }
18354
18355         rte_eth_dev_info_get(port_id, &dev_info);
18356         nb_tx_queues = dev_info.nb_tx_queues;
18357         if (!strcmp(res->on_off, "on")) {
18358                 port->dev_conf.txmode.offloads |= single_offload;
18359                 for (q = 0; q < nb_tx_queues; q++)
18360                         port->tx_conf[q].offloads |= single_offload;
18361         } else {
18362                 port->dev_conf.txmode.offloads &= ~single_offload;
18363                 for (q = 0; q < nb_tx_queues; q++)
18364                         port->tx_conf[q].offloads &= ~single_offload;
18365         }
18366
18367         cmd_reconfig_device_queue(port_id, 1, 1);
18368 }
18369
18370 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18371         .f = cmd_config_per_port_tx_offload_parsed,
18372         .data = NULL,
18373         .help_str = "port config <port_id> tx_offload "
18374                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18375                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18376                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18377                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18378                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18379                     "match_metadata on|off",
18380         .tokens = {
18381                 (void *)&cmd_config_per_port_tx_offload_result_port,
18382                 (void *)&cmd_config_per_port_tx_offload_result_config,
18383                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18384                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18385                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18386                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18387                 NULL,
18388         }
18389 };
18390
18391 /* Enable/Disable a per queue offloading */
18392 struct cmd_config_per_queue_tx_offload_result {
18393         cmdline_fixed_string_t port;
18394         portid_t port_id;
18395         cmdline_fixed_string_t txq;
18396         uint16_t queue_id;
18397         cmdline_fixed_string_t tx_offload;
18398         cmdline_fixed_string_t offload;
18399         cmdline_fixed_string_t on_off;
18400 };
18401
18402 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18403         TOKEN_STRING_INITIALIZER
18404                 (struct cmd_config_per_queue_tx_offload_result,
18405                  port, "port");
18406 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18407         TOKEN_NUM_INITIALIZER
18408                 (struct cmd_config_per_queue_tx_offload_result,
18409                  port_id, UINT16);
18410 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18411         TOKEN_STRING_INITIALIZER
18412                 (struct cmd_config_per_queue_tx_offload_result,
18413                  txq, "txq");
18414 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18415         TOKEN_NUM_INITIALIZER
18416                 (struct cmd_config_per_queue_tx_offload_result,
18417                  queue_id, UINT16);
18418 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18419         TOKEN_STRING_INITIALIZER
18420                 (struct cmd_config_per_queue_tx_offload_result,
18421                  tx_offload, "tx_offload");
18422 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18423         TOKEN_STRING_INITIALIZER
18424                 (struct cmd_config_per_queue_tx_offload_result,
18425                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18426                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18427                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18428                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18429                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18430 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18431         TOKEN_STRING_INITIALIZER
18432                 (struct cmd_config_per_queue_tx_offload_result,
18433                  on_off, "on#off");
18434
18435 static void
18436 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18437                                 __attribute__((unused)) struct cmdline *cl,
18438                                 __attribute__((unused)) void *data)
18439 {
18440         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18441         struct rte_eth_dev_info dev_info;
18442         portid_t port_id = res->port_id;
18443         uint16_t queue_id = res->queue_id;
18444         struct rte_port *port = &ports[port_id];
18445         uint64_t single_offload;
18446
18447         if (port->port_status != RTE_PORT_STOPPED) {
18448                 printf("Error: Can't config offload when Port %d "
18449                        "is not stopped\n", port_id);
18450                 return;
18451         }
18452
18453         rte_eth_dev_info_get(port_id, &dev_info);
18454         if (queue_id >= dev_info.nb_tx_queues) {
18455                 printf("Error: input queue_id should be 0 ... "
18456                        "%d\n", dev_info.nb_tx_queues - 1);
18457                 return;
18458         }
18459
18460         single_offload = search_tx_offload(res->offload);
18461         if (single_offload == 0) {
18462                 printf("Unknown offload name: %s\n", res->offload);
18463                 return;
18464         }
18465
18466         if (!strcmp(res->on_off, "on"))
18467                 port->tx_conf[queue_id].offloads |= single_offload;
18468         else
18469                 port->tx_conf[queue_id].offloads &= ~single_offload;
18470
18471         cmd_reconfig_device_queue(port_id, 1, 1);
18472 }
18473
18474 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18475         .f = cmd_config_per_queue_tx_offload_parsed,
18476         .data = NULL,
18477         .help_str = "port <port_id> txq <queue_id> tx_offload "
18478                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18479                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18480                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18481                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18482                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18483                     "on|off",
18484         .tokens = {
18485                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18486                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18487                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18488                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18489                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18490                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18491                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18492                 NULL,
18493         }
18494 };
18495
18496 /* *** configure tx_metadata for specific port *** */
18497 struct cmd_config_tx_metadata_specific_result {
18498         cmdline_fixed_string_t port;
18499         cmdline_fixed_string_t keyword;
18500         uint16_t port_id;
18501         cmdline_fixed_string_t item;
18502         uint32_t value;
18503 };
18504
18505 static void
18506 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18507                                 __attribute__((unused)) struct cmdline *cl,
18508                                 __attribute__((unused)) void *data)
18509 {
18510         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18511
18512         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18513                 return;
18514         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18515         /* Add/remove callback to insert valid metadata in every Tx packet. */
18516         if (ports[res->port_id].tx_metadata)
18517                 add_tx_md_callback(res->port_id);
18518         else
18519                 remove_tx_md_callback(res->port_id);
18520 }
18521
18522 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18523         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18524                         port, "port");
18525 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18526         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18527                         keyword, "config");
18528 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18529         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18530                         port_id, UINT16);
18531 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18532         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18533                         item, "tx_metadata");
18534 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18535         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18536                         value, UINT32);
18537
18538 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18539         .f = cmd_config_tx_metadata_specific_parsed,
18540         .data = NULL,
18541         .help_str = "port config <port_id> tx_metadata <value>",
18542         .tokens = {
18543                 (void *)&cmd_config_tx_metadata_specific_port,
18544                 (void *)&cmd_config_tx_metadata_specific_keyword,
18545                 (void *)&cmd_config_tx_metadata_specific_id,
18546                 (void *)&cmd_config_tx_metadata_specific_item,
18547                 (void *)&cmd_config_tx_metadata_specific_value,
18548                 NULL,
18549         },
18550 };
18551
18552 /* *** display tx_metadata per port configuration *** */
18553 struct cmd_show_tx_metadata_result {
18554         cmdline_fixed_string_t cmd_show;
18555         cmdline_fixed_string_t cmd_port;
18556         cmdline_fixed_string_t cmd_keyword;
18557         portid_t cmd_pid;
18558 };
18559
18560 static void
18561 cmd_show_tx_metadata_parsed(void *parsed_result,
18562                 __attribute__((unused)) struct cmdline *cl,
18563                 __attribute__((unused)) void *data)
18564 {
18565         struct cmd_show_tx_metadata_result *res = parsed_result;
18566
18567         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18568                 printf("invalid port id %u\n", res->cmd_pid);
18569                 return;
18570         }
18571         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18572                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18573                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18574         }
18575 }
18576
18577 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18578         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18579                         cmd_show, "show");
18580 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18581         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18582                         cmd_port, "port");
18583 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18584         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18585                         cmd_pid, UINT16);
18586 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18587         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18588                         cmd_keyword, "tx_metadata");
18589
18590 cmdline_parse_inst_t cmd_show_tx_metadata = {
18591         .f = cmd_show_tx_metadata_parsed,
18592         .data = NULL,
18593         .help_str = "show port <port_id> tx_metadata",
18594         .tokens = {
18595                 (void *)&cmd_show_tx_metadata_show,
18596                 (void *)&cmd_show_tx_metadata_port,
18597                 (void *)&cmd_show_tx_metadata_pid,
18598                 (void *)&cmd_show_tx_metadata_keyword,
18599                 NULL,
18600         },
18601 };
18602
18603 /* ******************************************************************************** */
18604
18605 /* list of instructions */
18606 cmdline_parse_ctx_t main_ctx[] = {
18607         (cmdline_parse_inst_t *)&cmd_help_brief,
18608         (cmdline_parse_inst_t *)&cmd_help_long,
18609         (cmdline_parse_inst_t *)&cmd_quit,
18610         (cmdline_parse_inst_t *)&cmd_load_from_file,
18611         (cmdline_parse_inst_t *)&cmd_showport,
18612         (cmdline_parse_inst_t *)&cmd_showqueue,
18613         (cmdline_parse_inst_t *)&cmd_showportall,
18614         (cmdline_parse_inst_t *)&cmd_showcfg,
18615         (cmdline_parse_inst_t *)&cmd_showfwdall,
18616         (cmdline_parse_inst_t *)&cmd_start,
18617         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18618         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18619         (cmdline_parse_inst_t *)&cmd_set_link_up,
18620         (cmdline_parse_inst_t *)&cmd_set_link_down,
18621         (cmdline_parse_inst_t *)&cmd_reset,
18622         (cmdline_parse_inst_t *)&cmd_set_numbers,
18623         (cmdline_parse_inst_t *)&cmd_set_log,
18624         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18625         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18626         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18627         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18628         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18629         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18630         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18631         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18632         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18633         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18634         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18635         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18636         (cmdline_parse_inst_t *)&cmd_set_link_check,
18637         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18638         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18639         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18640         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18641 #ifdef RTE_LIBRTE_PMD_BOND
18642         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18643         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18644         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18645         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18646         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18647         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18648         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18649         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18650         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18651         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18652         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18653 #endif
18654         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18655         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18656         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18657         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18658         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18659         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18660         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18661         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18662         (cmdline_parse_inst_t *)&cmd_csum_set,
18663         (cmdline_parse_inst_t *)&cmd_csum_show,
18664         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18665         (cmdline_parse_inst_t *)&cmd_tso_set,
18666         (cmdline_parse_inst_t *)&cmd_tso_show,
18667         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18668         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18669         (cmdline_parse_inst_t *)&cmd_gro_enable,
18670         (cmdline_parse_inst_t *)&cmd_gro_flush,
18671         (cmdline_parse_inst_t *)&cmd_gro_show,
18672         (cmdline_parse_inst_t *)&cmd_gso_enable,
18673         (cmdline_parse_inst_t *)&cmd_gso_size,
18674         (cmdline_parse_inst_t *)&cmd_gso_show,
18675         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18676         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18677         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18678         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18679         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18680         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18681         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18682         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18683         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18684         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18685         (cmdline_parse_inst_t *)&cmd_config_dcb,
18686         (cmdline_parse_inst_t *)&cmd_read_reg,
18687         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18688         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18689         (cmdline_parse_inst_t *)&cmd_write_reg,
18690         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18691         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18692         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18693         (cmdline_parse_inst_t *)&cmd_stop,
18694         (cmdline_parse_inst_t *)&cmd_mac_addr,
18695         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18696         (cmdline_parse_inst_t *)&cmd_set_qmap,
18697         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18698         (cmdline_parse_inst_t *)&cmd_operate_port,
18699         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18700         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18701         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18702         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18703         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18704         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18705         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18706         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18707         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18708         (cmdline_parse_inst_t *)&cmd_config_mtu,
18709         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18710         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18711         (cmdline_parse_inst_t *)&cmd_config_rss,
18712         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18713         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18714         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18715         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18716         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18717         (cmdline_parse_inst_t *)&cmd_showport_reta,
18718         (cmdline_parse_inst_t *)&cmd_config_burst,
18719         (cmdline_parse_inst_t *)&cmd_config_thresh,
18720         (cmdline_parse_inst_t *)&cmd_config_threshold,
18721         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18722         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18723         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18724         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18725         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18726         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18727         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18728         (cmdline_parse_inst_t *)&cmd_global_config,
18729         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18730         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18731         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18732         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18733         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18734         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18735         (cmdline_parse_inst_t *)&cmd_dump,
18736         (cmdline_parse_inst_t *)&cmd_dump_one,
18737         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18738         (cmdline_parse_inst_t *)&cmd_syn_filter,
18739         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18740         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18741         (cmdline_parse_inst_t *)&cmd_flex_filter,
18742         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18743         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18744         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18745         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18746         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18747         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18748         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18749         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18750         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18751         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18752         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18753         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18754         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18755         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18756         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18757         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18758         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18759         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18760         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18761         (cmdline_parse_inst_t *)&cmd_flow,
18762         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18763         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18764         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18765         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18766         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18767         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18768         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18769         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18770         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18771         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18772         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18773         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18774         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18775         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18776         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18777         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18778         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18779         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18780         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18781         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18782         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18783         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18784         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18785         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18786         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18787         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18788         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18789         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18790         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18791         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18792         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18793         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18794         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18795         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18796         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18797         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18798         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18799         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18800         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18801         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18802         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18803         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18804         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18805         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18806         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18807         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18808         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18809         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18810         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18811 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
18812         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
18813 #endif
18814         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18815         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18816         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18817         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18818         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18819         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18820         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18821         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18822         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18823         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18824         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18825         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18826         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18827         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18828         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18829         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18830         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18831         (cmdline_parse_inst_t *)&cmd_ddp_add,
18832         (cmdline_parse_inst_t *)&cmd_ddp_del,
18833         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18834         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18835         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18836         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18837         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18838         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18839         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18840         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18841         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18842         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18843
18844         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18845         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18846         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18847         (cmdline_parse_inst_t *)&cmd_queue_region,
18848         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18849         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18850         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18851         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18852         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18853         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18854         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18855         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18856         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18857         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18858         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18859         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18860         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18861         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18862         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18863         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18864         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18865         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18866         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18867         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18868         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18869         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18870         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18871         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18872         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18873         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18874         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18875         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18876         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18877         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18878         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18879         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18880         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18881         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18882         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18883 #ifdef RTE_LIBRTE_BPF
18884         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18885         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18886 #endif
18887         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18888         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18889         NULL,
18890 };
18891
18892 /* read cmdline commands from file */
18893 void
18894 cmdline_read_from_file(const char *filename)
18895 {
18896         struct cmdline *cl;
18897
18898         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18899         if (cl == NULL) {
18900                 printf("Failed to create file based cmdline context: %s\n",
18901                        filename);
18902                 return;
18903         }
18904
18905         cmdline_interact(cl);
18906         cmdline_quit(cl);
18907
18908         cmdline_free(cl);
18909
18910         printf("Read CLI commands from %s\n", filename);
18911 }
18912
18913 /* prompt function, called from main on MASTER lcore */
18914 void
18915 prompt(void)
18916 {
18917         /* initialize non-constant commands */
18918         cmd_set_fwd_mode_init();
18919         cmd_set_fwd_retry_mode_init();
18920
18921         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18922         if (testpmd_cl == NULL)
18923                 return;
18924         cmdline_interact(testpmd_cl);
18925         cmdline_stdin_exit(testpmd_cl);
18926 }
18927
18928 void
18929 prompt_exit(void)
18930 {
18931         if (testpmd_cl != NULL)
18932                 cmdline_quit(testpmd_cl);
18933 }
18934
18935 static void
18936 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18937 {
18938         if (id == (portid_t)RTE_PORT_ALL) {
18939                 portid_t pid;
18940
18941                 RTE_ETH_FOREACH_DEV(pid) {
18942                         /* check if need_reconfig has been set to 1 */
18943                         if (ports[pid].need_reconfig == 0)
18944                                 ports[pid].need_reconfig = dev;
18945                         /* check if need_reconfig_queues has been set to 1 */
18946                         if (ports[pid].need_reconfig_queues == 0)
18947                                 ports[pid].need_reconfig_queues = queue;
18948                 }
18949         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18950                 /* check if need_reconfig has been set to 1 */
18951                 if (ports[id].need_reconfig == 0)
18952                         ports[id].need_reconfig = dev;
18953                 /* check if need_reconfig_queues has been set to 1 */
18954                 if (ports[id].need_reconfig_queues == 0)
18955                         ports[id].need_reconfig_queues = queue;
18956         }
18957 }